From: Raphaƫl Gertz Date: Mon, 19 Oct 2020 07:44:35 +0000 (+0200) Subject: Add location repository with fetchTranslatedLocationByDatePeriod X-Git-Url: https://git.rapsys.eu/airbundle/commitdiff_plain/ad50ac76c788693925aa4d30fa5ebad4beca62db Add location repository with fetchTranslatedLocationByDatePeriod Enable it in doctrine orm config --- diff --git a/Repository/LocationRepository.php b/Repository/LocationRepository.php new file mode 100644 index 0000000..80e0996 --- /dev/null +++ b/Repository/LocationRepository.php @@ -0,0 +1,37 @@ +getEntityManager() + ->createQuery('SELECT l.id, l.title FROM RapsysAirBundle:Session s JOIN RapsysAirBundle:Location l WHERE '.($granted?'s.application IS NOT NULL AND ':'').'l.id = s.location AND s.date BETWEEN :begin AND :end GROUP BY l.id ORDER BY l.id') + ->setParameter('begin', $period->getStartDate()) + ->setParameter('end', $period->getEndDate()) + ->getResult(); + + //Rekey array + $ret = array_column($ret, 'title', 'id'); + + //Filter array + foreach($ret as $k => $v) { + $ret[$k] = $translator->trans($v); + } + + //Send result + return $ret; + } +} diff --git a/Resources/config/doctrine/Location.orm.yml b/Resources/config/doctrine/Location.orm.yml index 0b276fa..abed5dd 100644 --- a/Resources/config/doctrine/Location.orm.yml +++ b/Resources/config/doctrine/Location.orm.yml @@ -1,6 +1,6 @@ Rapsys\AirBundle\Entity\Location: type: entity - #repositoryClass: Rapsys\AirBundle\Repository\LocationRepository + repositoryClass: Rapsys\AirBundle\Repository\LocationRepository table: locations id: id: