1 | <?php |
||
28 | class RaLocationRepository extends EntityRepository |
||
29 | { |
||
30 | /** |
||
31 | * @param RaLocationQuery $query |
||
32 | * @return null|RaLocation[] |
||
33 | */ |
||
34 | public function search(RaLocationQuery $query) |
||
35 | { |
||
36 | if (!in_array($query->orderBy, ['name', 'location', 'contact_information'])) { |
||
37 | throw new RuntimeException(sprintf('Unknown order by column "%s"', $query->orderBy)); |
||
38 | } |
||
39 | |||
40 | $orderBy = 'rl.'.$query->orderBy; |
||
41 | $orderDirection = $query->orderDirection === 'asc' ? 'ASC' : 'DESC'; |
||
42 | |||
43 | return $this->getEntityManager()->createQueryBuilder() |
||
44 | ->select('rl') |
||
45 | ->from('Surfnet\StepupMiddleware\ApiBundle\Configuration\Entity\RaLocation', 'rl') |
||
46 | ->where('rl.institution = :institution') |
||
47 | ->setParameter('institution', $query->institution->getInstitution()) |
||
48 | ->orderBy($orderBy, $orderDirection) |
||
49 | ->getQuery() |
||
50 | ->getResult(); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param RaLocationId $raLocationId |
||
55 | * @return RaLocation[] |
||
56 | */ |
||
57 | public function findByRaLocationId(RaLocationId $raLocationId) |
||
58 | { |
||
59 | return $this->createQueryBuilder('rl') |
||
60 | ->where('rl.id = :id') |
||
61 | ->setParameter('id', $raLocationId->getRaLocationId()) |
||
62 | ->getQuery() |
||
63 | ->getOneOrNullResult(); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @param RaLocation $raLocation |
||
68 | */ |
||
69 | public function save(RaLocation $raLocation) |
||
75 | |||
76 | /** |
||
77 | * @param RaLocation $raLocation |
||
78 | */ |
||
79 | public function remove(RaLocation $raLocation) |
||
80 | { |
||
81 | $entityManager = $this->getEntityManager(); |
||
82 | $entityManager->remove($raLocation); |
||
83 | $entityManager->flush(); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param Institution $institution |
||
88 | * @return RaLocation[] |
||
89 | */ |
||
90 | public function findByInstitution(Institution $institution) |
||
98 | |||
99 | /** |
||
100 | * @param Institution $institution |
||
101 | */ |
||
102 | public function removeRaLocationsFor(Institution $institution) |
||
111 | } |
||
112 |