1 | <?php |
||
38 | class RaCandidateRepository extends EntityRepository |
||
39 | { |
||
40 | /** |
||
41 | * @var InstitutionAuthorizationRepositoryFilter |
||
42 | */ |
||
43 | private $authorizationRepositoryFilter; |
||
44 | |||
45 | public function __construct( |
||
53 | |||
54 | /** |
||
55 | * @param RaCandidateQuery $query |
||
56 | * @return \Doctrine\ORM\Query |
||
57 | */ |
||
58 | public function createSearchQuery(RaCandidateQuery $query) |
||
59 | { |
||
60 | $queryBuilder = $this->getBaseQuery(); |
||
61 | |||
62 | // Modify query to filter on authorization: |
||
63 | // For the RA candidates we want the identities that we could make RA. Because we then need to look at the |
||
64 | // select_raa's we have to look at the institution of the candidate because that's the institution we could |
||
65 | // select RA's from. Hence the 'rac.institution'. |
||
66 | $this->authorizationRepositoryFilter->filter( |
||
67 | $queryBuilder, |
||
68 | $query->authorizationContext, |
||
69 | 'i.institution', |
||
70 | 'iac' |
||
71 | ); |
||
72 | |||
73 | if ($query->institution) { |
||
74 | $queryBuilder |
||
75 | ->andWhere('i.institution = :institution') |
||
76 | ->setParameter('institution', $query->institution); |
||
77 | } |
||
78 | |||
79 | if ($query->commonName) { |
||
80 | $queryBuilder |
||
81 | ->andWhere('i.commonName LIKE :commonName') |
||
82 | ->setParameter('commonName', sprintf('%%%s%%', $query->commonName)); |
||
83 | } |
||
84 | |||
85 | if ($query->email) { |
||
86 | $queryBuilder |
||
87 | ->andWhere('i.email LIKE :email') |
||
88 | ->setParameter('email', sprintf('%%%s%%', $query->email)); |
||
89 | } |
||
90 | |||
91 | if (!empty($query->secondFactorTypes)) { |
||
92 | $queryBuilder |
||
93 | ->andWhere('vsf.type IN (:secondFactorTypes)') |
||
94 | ->setParameter('secondFactorTypes', $query->secondFactorTypes); |
||
95 | } |
||
96 | |||
97 | if (!empty($query->raInstitution)) { |
||
98 | $queryBuilder |
||
99 | ->andWhere('a.raInstitution = :raInstitution') |
||
100 | ->setParameter('raInstitution', $query->raInstitution); |
||
101 | } |
||
102 | |||
103 | $queryBuilder->groupBy('i.id'); |
||
104 | |||
105 | return $queryBuilder->getQuery(); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @param RaCandidateQuery $query |
||
110 | * @return \Doctrine\ORM\Query |
||
111 | */ |
||
112 | public function createOptionsQuery(RaCandidateQuery $query) |
||
113 | { |
||
114 | $queryBuilder = $this->getEntityManager()->createQueryBuilder() |
||
115 | ->select('a.institution') |
||
116 | ->from(InstitutionAuthorization::class, 'a') |
||
117 | ->where("a.institutionRole = 'select_raa'"); |
||
118 | |||
119 | // Modify query to filter on authorization: |
||
120 | // For the RA candidates we want the identities that we could make RA. Because we then need to look at the |
||
121 | // select_raa's we have to look at the institution of the candidate because that's the institution we could |
||
122 | // select RA's from. Hence the 'rac.institution'. |
||
123 | $this->authorizationRepositoryFilter->filter( |
||
124 | $queryBuilder, |
||
125 | $query->authorizationContext, |
||
126 | 'a.institution', |
||
127 | 'iac' |
||
128 | ); |
||
129 | |||
130 | return $queryBuilder->getQuery(); |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @param string $identityId |
||
135 | * @param InstitutionAuthorizationContextInterface $authorizationContext |
||
136 | * @return RaCandidate[] |
||
137 | */ |
||
138 | public function findAllRaasByIdentityId($identityId, InstitutionAuthorizationContextInterface $authorizationContext) |
||
158 | |||
159 | /** |
||
160 | * @return \Doctrine\ORM\QueryBuilder |
||
161 | */ |
||
162 | private function getBaseQuery() |
||
187 | } |
||
188 |