* initial api stuff

This commit is contained in:
Danyi Dávid
2018-05-11 10:46:00 +02:00
parent 77325b8e94
commit be7bc7279d
48 changed files with 3793 additions and 325 deletions

View File

@@ -17,6 +17,13 @@ class AwardeeManager
$this->entityManager = $entityManager;
}
public function getAwardees(): ?array
{
return $this->entityManager->getRepository(Awardee::class)->findBy([], [
'year' => 'DESC',
]);
}
/**
* @param int $year
* @return Awardee[]
@@ -28,6 +35,13 @@ class AwardeeManager
]);
}
public function getAwardee(int $id): ?Awardee
{
/** @var Awardee $awardee */
$awardee = $this->entityManager->getRepository(Awardee::class)->find($id);
return $awardee;
}
/**
* @param string $slug
* @return Awardee|null

View File

@@ -4,146 +4,89 @@ namespace App\Service;
use App\Entity\Judge;
use Doctrine\ORM\EntityManager;
use DoctrineExpressiveModule\Hydrator\DoctrineObject;
class JudgeManager
{
/** @var EntityManager */
private $entityManager;
public function __construct(EntityManager $entityManager)
{
private $hydrator;
public function __construct(
EntityManager $entityManager,
DoctrineObject $hydrator
) {
$this->entityManager = $entityManager;
$this->hydrator = $hydrator;
}
public function getJudges()
{
// return [
// [
// 'image' => 'agnes_soos',
// 'name' => 'Dr Ágnes Soós',
// 'desc' => 'National Institute for Sports Medicine, Director General',
// ], [
// 'image' => 'balazs_nagy_lantos',
// 'name' => 'Balázs Nagy Lantos',
// 'desc' => 'Mensa HungarIQa, Former President',
// ], [
// 'image' => 'bertalan_mesko',
// 'name' => 'Dr Bertalan Meskó',
// 'desc' => 'Winner of GRAN PRIZE 2013, medical futurist, founder of Webicina',
// ], [
// 'image' => 'edit_nemeth',
// 'name' => 'Dr Edit Németh',
// 'desc' => 'ELTE Institute of Business Economics, Management and Business Law Faculty',
// ], [
// 'image' => 'erno_keszei',
// 'name' => 'Prof. Ernő Keszei',
// 'desc' => 'Eötvös Loránd University, Former Vice-Rector for Science, Research, and Innovation',
// ], [
// 'image' => 'gabor_kopek',
// 'name' => 'Gábor Kopek',
// 'desc' => 'Moholy-Nagy University of Art and Design Budapest, Former Rector',
// ], [
// 'image' => 'gabor_nemeth',
// 'name' => 'Dr Gábor Németh',
// 'desc' => 'Hungarian Intellectual Property Office, Director',
// ], [
// 'image' => 'gabor_szabo',
// 'name' => 'Dr Gábor Szabó',
// 'desc' => 'University of Szeged, Rector; Hungarian Association for Innovation, President',
// ], [
// 'image' => 'gyorgy_nagy',
// 'name' => 'György Nagy',
// 'desc' => 'Sigma Technology, Managing Director; Swedish Chamber of Commerce in Hungary, Vice-President',
// ], [
// 'image' => 'gyula_patko',
// 'name' => 'Dr Gyula Patkó',
// 'desc' => 'University of Miskolc, Former Rector',
// ], [
// 'image' => 'ildiko_csejtei',
// 'name' => 'Ildikó B. Csejtei',
// 'desc' => 'Independent Media Group, Owner, Director',
// ], [
// 'image' => 'istvan_salgo',
// 'name' => 'István Salgó',
// 'desc' => 'Business Council for Sustainable Development in Hungary, Honorary President',
// ], [
// 'image' => 'janos_durr',
// 'name' => 'János Dürr',
// 'desc' => 'Club of Hungarian Science Journalists, President',
// ], [
// 'image' => 'janos_takacs',
// 'name' => 'János Takács',
// 'desc' => 'Swedish Chamber of Commerce, President',
// ], [
// 'image' => 'jozsef_fulop',
// 'name' => 'József Fülöp',
// 'desc' => 'Moholy-Nagy University of Art and Design Budapest, Rector',
// ], [
// 'image' => 'jozsef_peter_martin',
// 'name' => 'Dr József Péter Martin',
// 'desc' => 'Transparency International Hungary, Managing Director',
// ], [
// 'image' => 'maria_judit_molnar',
// 'name' => 'Dr Mária Judit Molnár',
// 'desc' => 'SOTE Institute of Genomic Medicine and Rare Disorders, Head of the Institute',
// ], [
// 'image' => 'melinda_kamasz',
// 'name' => 'Melinda Kamasz',
// 'desc' => 'Figyelő, Deputy Editor in Chief, Figyelő Trend, Editor in Chief',
// ], [
// 'image' => 'miklos_antalovits',
// 'name' => 'Dr Miklós Antalovits',
// 'desc' => 'Budapest University of Technology and Economics, Professor Emeritus',
// ], [
// 'image' => 'miklos_bendzsel',
// 'name' => 'Dr Miklós Bendzsel',
// 'desc' => 'Hungarian Academy of Engineers, Vice-President; Hungarian Intellectual Property Office, Former President',
// ], [
// 'image' => 'peter_szauer',
// 'name' => 'Péter Szauer',
// 'desc' => 'HVG, President and Chief Executive Officer',
// ], [
// 'image' => 'richard_bogdan',
// 'name' => 'Richárd Bogdán',
// 'desc' => 'Mensa HungarIQa, President',
// ], [
// 'image' => 'rita_istivan',
// 'name' => 'Rita Istiván',
// 'desc' => 'BME, Honorary Associate Professor; Swedish Chamber of Commerce, Secretary General',
// ], [
// 'image' => 'roland_jakab',
// 'name' => 'Roland Jakab',
// 'desc' => 'Ericsson Hungary, Managing Director; Swedish Chamber of Commerce, Member of the Board',
// ], [
// 'image' => 'szabolcs_farkas',
// 'name' => 'Dr Szabolcs Farkas',
// 'desc' => 'Hungarian Intellectual Property Office, Vice-President',
// ], [
// 'image' => 'zoltan_bruckner',
// 'name' => 'Zoltán Bruckner',
// 'desc' => 'Primus Capital Management, Investment Director, Managing Partner',
// ], [
// 'image' => 'viktor_luszcz',
// 'name' => 'Dr Viktor Łuszcz',
// 'desc' => 'Hungarian Intellectual Property Office, President',
// ]
// ];
$qb = $this->entityManager->createQueryBuilder();
return $qb->select('j, t')
->from(Judge::class, 'j')
->leftJoin('j.titles', 't')
->getQuery()
->getArrayResult();
}
/**
* @param int $year
* @return array
* @todo implement real filter by year
*/
public function getJudgesByYear(int $year)
{
$qb = $this->entityManager->createQueryBuilder();
return $qb->select('j')
->from(Judge::class, 'j')
->innerJoin('j.years', 'y')
->where('y.year = :year')
->innerJoin('j.titles', 't')
->where('t.year = :year')
->setParameter('year', $year)
->getQuery()
->getArrayResult();
}
/**
* @param int $id
* @return Judge|null
*/
public function getJudge(int $id): ?Judge
{
/** @var Judge $judge */
$judge = $this->entityManager->getRepository(Judge::class)->find($id);
return $judge;
}
/**
* @param $data
* @return Judge
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function create($data): Judge
{
/** @var Judge $judge */
$judge = $this->hydrator->hydrate($data, new Judge());
$this->entityManager->persist($judge);
$this->entityManager->flush();
return $judge;
}
/**
* @param int $id
* @param $data
* @return Judge
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function update(int $id, $data): Judge
{
$judge = $this->entityManager->getRepository(Judge::class)->find($id);
/** @var Judge $judge */
$judge = $this->hydrator->hydrate($data, $judge);
$this->entityManager->persist($judge);
$this->entityManager->flush();
return $judge;
}
}

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Service;
use Doctrine\ORM\EntityManager;
use DoctrineExpressiveModule\Hydrator\DoctrineObject;
use Psr\Container\ContainerInterface;
class JudgeManagerFactory
@@ -12,6 +13,7 @@ class JudgeManagerFactory
public function __invoke(ContainerInterface $container): JudgeManager
{
$entityManager = $container->get(EntityManager::class);
return new JudgeManager($entityManager);
$hydrator = $container->get(DoctrineObject::class);
return new JudgeManager($entityManager, $hydrator);
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Service;
use App\Entity\JudgeTitle;
use Doctrine\ORM\EntityManager;
class YearManager
{
/** @var EntityManager */
private $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function getYears()
{
$qb = $this->entityManager->createQueryBuilder();
$years = $qb->select('jt.year')
->from(JudgeTitle::class, 'jt')
->orderBy('jt.year', 'DESC')
->distinct()
->getQuery()
->getArrayResult();
$filteredYears = array_map(function($year) {
return $year['year'];
}, $years);
$thisYear = date("Y");
if (!in_array($thisYear, $filteredYears)) {
array_unshift($filteredYears, $thisYear);
}
return $filteredYears;
}
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace App\Service;
use Doctrine\ORM\EntityManager;
use Psr\Container\ContainerInterface;
class YearManagerFactory
{
public function __invoke(ContainerInterface $container): YearManager
{
$entityManager = $container->get(EntityManager::class);
return new YearManager($entityManager);
}
}