Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 110 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
Evaluation | |
0.00% |
0 / 110 |
|
0.00% |
0 / 7 |
756 | |
0.00% |
0 / 1 |
getModelClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
findAllByActiveOrganisationWithHasModuleConformiteOrganisationAndOrderedByDate | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
12 | |||
findLastByOrganisation | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |||
count | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 | |||
findPaginated | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
addTableOrder | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
30 | |||
addTableSearches | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | |
3 | namespace App\Infrastructure\ORM\Registry\Repository\ConformiteOrganisation; |
4 | |
5 | use App\Application\Doctrine\Repository\CRUDRepository; |
6 | use App\Application\Traits\RepositoryUtils; |
7 | use App\Domain\Registry\Model; |
8 | use App\Domain\Registry\Repository; |
9 | use App\Domain\User\Model\Collectivity; |
10 | use Doctrine\Common\Collections\Collection; |
11 | use Doctrine\ORM\QueryBuilder; |
12 | use Doctrine\ORM\Tools\Pagination\Paginator; |
13 | |
14 | class Evaluation extends CRUDRepository implements Repository\ConformiteOrganisation\Evaluation |
15 | { |
16 | use RepositoryUtils; |
17 | |
18 | protected function getModelClass(): string |
19 | { |
20 | return Model\ConformiteOrganisation\Evaluation::class; |
21 | } |
22 | |
23 | public function findAllByActiveOrganisationWithHasModuleConformiteOrganisationAndOrderedByDate($organisation = null) |
24 | { |
25 | $qBuilder = $this |
26 | ->createQueryBuilder() |
27 | ->leftJoin('o.collectivity', 'c') |
28 | ; |
29 | if (null !== $organisation) { |
30 | if (\is_array($organisation)) { |
31 | $qBuilder |
32 | ->andWhere( |
33 | $qBuilder->expr()->in('o.collectivity', ':collectivities') |
34 | ) |
35 | ->setParameter('collectivities', $organisation) |
36 | ; |
37 | } else { |
38 | $qBuilder |
39 | ->andWhere('o.collectivity = :organisation_id') |
40 | ->setParameter('organisation_id', $organisation->getId()); |
41 | } |
42 | } else { |
43 | $qBuilder |
44 | ->addSelect('c'); |
45 | } |
46 | |
47 | $qBuilder |
48 | ->addSelect('conformites') |
49 | ->leftJoin('o.conformites', 'conformites') |
50 | ->andWhere($qBuilder->expr()->eq('c.hasModuleConformiteOrganisation', ':true')) |
51 | ->setParameter('true', true) |
52 | ->addOrderBy('o.date', 'DESC') |
53 | ->addOrderBy('o.createdAt', 'DESC') |
54 | ; |
55 | |
56 | return $qBuilder |
57 | ->getQuery() |
58 | ->getResult() |
59 | ; |
60 | } |
61 | |
62 | public function findLastByOrganisation(Collectivity $organisation): ?Model\ConformiteOrganisation\Evaluation |
63 | { |
64 | $results = $this->createQueryBuilder() |
65 | ->addSelect('conformites, processus, reponses, questions, actionProtections') |
66 | ->andWhere('o.collectivity = :organisation') |
67 | ->setParameter('organisation', $organisation) |
68 | ->andWhere('o.isDraft = 0') |
69 | ->leftJoin('o.conformites', 'conformites') |
70 | ->leftJoin('conformites.processus', 'processus') |
71 | ->leftJoin('conformites.reponses', 'reponses') |
72 | ->leftJoin('conformites.actionProtections', 'actionProtections') |
73 | ->leftJoin('processus.questions', 'questions') |
74 | ->addOrderBy('o.date', 'DESC') |
75 | ->addOrderBy('o.createdAt', 'DESC') |
76 | ->getQuery() |
77 | ->getResult() |
78 | ; |
79 | |
80 | return isset($results[0]) ? $results[0] : null; |
81 | } |
82 | |
83 | public function count(array $criteria = []) |
84 | { |
85 | $qb = $this->createQueryBuilder(); |
86 | $qb->leftJoin('o.collectivity', 'collectivite') |
87 | ->andWhere('collectivite.hasModuleConformiteOrganisation=1') |
88 | ; |
89 | |
90 | if (isset($criteria['collectivity']) && $criteria['collectivity'] instanceof Collection) { |
91 | $this->addInClauseCollectivities($qb, $criteria['collectivity']->toArray()); |
92 | unset($criteria['collectivity']); |
93 | } |
94 | foreach ($criteria as $key => $value) { |
95 | $this->addWhereClause($qb, $key, $value); |
96 | } |
97 | $qb->select('COUNT(o.id)'); |
98 | |
99 | foreach ($criteria as $key => $value) { |
100 | $this->addWhereClause($qb, $key, $value); |
101 | } |
102 | |
103 | return $qb->getQuery()->getSingleScalarResult(); |
104 | } |
105 | |
106 | public function findPaginated($firstResult, $maxResults, $orderColumn, $orderDir, $searches, $criteria = []) |
107 | { |
108 | $qb = $this->createQueryBuilder() |
109 | ->leftJoin('o.collectivity', 'collectivite') |
110 | ->leftJoin('o.participants', 'participants') |
111 | ->andWhere('collectivite.hasModuleConformiteOrganisation=1') |
112 | ; |
113 | |
114 | if (isset($criteria['collectivity']) && $criteria['collectivity'] instanceof Collection) { |
115 | $this->addInClauseCollectivities($qb, $criteria['collectivity']->toArray()); |
116 | unset($criteria['collectivity']); |
117 | } |
118 | foreach ($criteria as $key => $value) { |
119 | $this->addWhereClause($qb, $key, $value); |
120 | } |
121 | // todo filtres et tri sur les participants |
122 | |
123 | $this->addTableSearches($qb, $searches); |
124 | $this->addTableOrder($qb, $orderColumn, $orderDir); |
125 | |
126 | $query = $qb->getQuery(); |
127 | $query->setFirstResult($firstResult); |
128 | $query->setMaxResults($maxResults); |
129 | |
130 | return new Paginator($query); |
131 | } |
132 | |
133 | private function addTableOrder(QueryBuilder $queryBuilder, $orderColumn, $orderDir) |
134 | { |
135 | switch ($orderColumn) { |
136 | case 'created_at': |
137 | $queryBuilder->addOrderBy('o.createdAt', $orderDir); |
138 | break; |
139 | case 'collectivite': |
140 | $queryBuilder->addOrderBy('collectivite.name', $orderDir); |
141 | break; |
142 | case 'participant': |
143 | $queryBuilder->addSelect('count(participants.id) as participantsCount'); |
144 | $queryBuilder->addOrderBy('participantsCount', $orderDir); |
145 | $queryBuilder->groupBy('o.id'); |
146 | break; |
147 | case 'draft': |
148 | $queryBuilder->addOrderBy('o.isDraft', $orderDir); |
149 | break; |
150 | } |
151 | } |
152 | |
153 | private function addTableSearches(QueryBuilder $queryBuilder, $searches) |
154 | { |
155 | foreach ($searches as $columnName => $search) { |
156 | switch ($columnName) { |
157 | case 'created_at': |
158 | if (is_string($search)) { |
159 | $queryBuilder->andWhere('o.createdAt BETWEEN :create_start_date AND :create_finish_date') |
160 | ->setParameter('create_start_date', date_create_from_format('d/m/y', substr($search, 0, 8))->format('Y-m-d 00:00:00')) |
161 | ->setParameter('create_finish_date', date_create_from_format('d/m/y', substr($search, 11, 8))->format('Y-m-d 23:59:59')); |
162 | } |
163 | break; |
164 | case 'collectivite': |
165 | $queryBuilder->andWhere('collectivite.name LIKE :collectivity') |
166 | ->setParameter('collectivity', '%' . $search . '%'); |
167 | break; |
168 | case 'participant': |
169 | $queryBuilder->addSelect('count(participants.id) as participantsCount2'); |
170 | $queryBuilder->andHaving('participantsCount2 = :partcnt') |
171 | ->setParameter('partcnt', $search); |
172 | $queryBuilder->groupBy('o.id'); |
173 | break; |
174 | case 'draft': |
175 | $queryBuilder->andWhere('o.isDraft = :draft') |
176 | ->setParameter('draft', $search); |
177 | break; |
178 | } |
179 | } |
180 | } |
181 | } |