Commit a998c9079a9c83e5ce865ecd68d6e6897bedd6f8
1 parent
64904ba2
Exists in
master
and in
3 other branches
Refactorisation de code dans AppController et MaterielController pour
(grandement) simplifier les vues => (voir par exemple à quel point la vue Materiels/view est maintenant bien plus lisible)
Showing
3 changed files
with
215 additions
and
35 deletions
Show diff stats
src/Controller/AppController.php
@@ -32,6 +32,21 @@ use PhpParser\Node\Expr\Include_; | @@ -32,6 +32,21 @@ use PhpParser\Node\Expr\Include_; | ||
32 | class AppController extends Controller { | 32 | class AppController extends Controller { |
33 | 33 | ||
34 | public $confLabinvent; | 34 | public $confLabinvent; |
35 | + | ||
36 | + const PROFILE_USER = 1; | ||
37 | + const PROFILE_RESPONSABLE = 2; | ||
38 | + const PROFILE_ADMIN = 3; | ||
39 | + const PROFILE_ADMINPLUS = 4; | ||
40 | + const PROFILE_SUPERADMIN = 5; | ||
41 | + | ||
42 | + private $allProfiles = [ | ||
43 | + 'Utilisateur' => self::PROFILE_USER, | ||
44 | + 'Responsable' => self::PROFILE_RESPONSABLE, | ||
45 | + 'Administration' => self::PROFILE_ADMIN, | ||
46 | + 'Administration Plus' => self::PROFILE_ADMINPLUS, | ||
47 | + 'Super Administrateur' => self::PROFILE_SUPERADMIN | ||
48 | + ]; | ||
49 | + | ||
35 | 50 | ||
36 | /** | 51 | /** |
37 | * Initialization hook method. | 52 | * Initialization hook method. |
@@ -205,7 +220,15 @@ class AppController extends Controller { | @@ -205,7 +220,15 @@ class AppController extends Controller { | ||
205 | * @return void | 220 | * @return void |
206 | */ | 221 | */ |
207 | public function beforeRender(Event $event) { | 222 | public function beforeRender(Event $event) { |
208 | - if (! array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), [ | 223 | + |
224 | + $this->set('PROFILE_USER', self::PROFILE_USER); | ||
225 | + $this->set('PROFILE_ADMIN', self::PROFILE_ADMIN); | ||
226 | + $this->set('PROFILE_RESPONSABLE', self::PROFILE_RESPONSABLE); | ||
227 | + $this->set('PROFILE_ADMINPLUS', self::PROFILE_ADMINPLUS); | ||
228 | + $this->set('PROFILE_SUPERADMIN', self::PROFILE_SUPERADMIN); | ||
229 | + $this->set('allProfiles', $this->allProfiles); | ||
230 | + | ||
231 | + if (! array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), [ | ||
209 | 'application/json', | 232 | 'application/json', |
210 | 'application/xml' | 233 | 'application/xml' |
211 | ])) { | 234 | ])) { |
@@ -227,6 +250,23 @@ class AppController extends Controller { | @@ -227,6 +250,23 @@ class AppController extends Controller { | ||
227 | if ($role == null) | 250 | if ($role == null) |
228 | $role = 'Utilisateur'; | 251 | $role = 'Utilisateur'; |
229 | $this->set('role', $role); | 252 | $this->set('role', $role); |
253 | + | ||
254 | + $profile = $this->allProfiles["$role"]; | ||
255 | + $this->set('profile', $profile); | ||
256 | + | ||
257 | + $USER_IS_UTILISATEUR = ($profile == self::PROFILE_USER); | ||
258 | + $USER_IS_RESPONSABLE = ($profile == self::PROFILE_RESPONSABLE); | ||
259 | + $USER_IS_ADMIN = ($profile == self::PROFILE_ADMIN); | ||
260 | + $USER_IS_ADMINPLUS = ($profile == self::PROFILE_ADMINPLUS); | ||
261 | + $USER_IS_SUPERADMIN = ($profile == self::PROFILE_SUPERADMIN); | ||
262 | + $USER_IS_ADMIN_OR_MORE = ($profile >= self::PROFILE_ADMIN); | ||
263 | + | ||
264 | + $this->set('USER_IS_UTILISATEUR', $USER_IS_UTILISATEUR); | ||
265 | + $this->set('USER_IS_RESPONSABLE', $USER_IS_RESPONSABLE); | ||
266 | + $this->set('USER_IS_ADMIN', $USER_IS_ADMIN); | ||
267 | + $this->set('USER_IS_ADMINPLUS', $USER_IS_ADMINPLUS); | ||
268 | + $this->set('USER_IS_SUPERADMIN', $USER_IS_SUPERADMIN); | ||
269 | + $this->set('USER_IS_ADMIN_OR_MORE', $USER_IS_ADMIN_OR_MORE); | ||
230 | 270 | ||
231 | $this->set('userConnected', $user); | 271 | $this->set('userConnected', $user); |
232 | 272 |
src/Controller/MaterielsController.php
@@ -12,6 +12,18 @@ use Cake\Mailer\Email; | @@ -12,6 +12,18 @@ use Cake\Mailer\Email; | ||
12 | */ | 12 | */ |
13 | class MaterielsController extends AppController { | 13 | class MaterielsController extends AppController { |
14 | 14 | ||
15 | + const CREATED = 1; | ||
16 | + const VALIDATED = 2; | ||
17 | + const TOBEARCHIVED = 3; | ||
18 | + const ARCHIVED = 4; | ||
19 | + | ||
20 | + private $allStatus = [ | ||
21 | + 'CREATED' => self::CREATED, | ||
22 | + 'VALIDATED' => self::VALIDATED, | ||
23 | + 'TOBEARCHIVED' => self::TOBEARCHIVED, | ||
24 | + 'ARCHIVED' => self::ARCHIVED, | ||
25 | + ]; | ||
26 | + | ||
15 | private $NOTARCHIVED = [ | 27 | private $NOTARCHIVED = [ |
16 | 'CREATED', | 28 | 'CREATED', |
17 | 'VALIDATED', | 29 | 'VALIDATED', |
@@ -19,7 +31,22 @@ class MaterielsController extends AppController { | @@ -19,7 +31,22 @@ class MaterielsController extends AppController { | ||
19 | ]; | 31 | ]; |
20 | 32 | ||
21 | public $role; | 33 | public $role; |
22 | - | 34 | + |
35 | + /* | ||
36 | + * EP added 13/6/17 | ||
37 | + * Set some useful global variables for all (Materiel) views | ||
38 | + * Overload beforeRender() | ||
39 | + */ | ||
40 | + public function beforeRender(\Cake\Event\Event $event){ | ||
41 | + parent::beforeRender($event); | ||
42 | + | ||
43 | + //$this->layout = 'default'; | ||
44 | + $this->set('CREATED', self::CREATED); | ||
45 | + $this->set('VALIDATED', self::VALIDATED); | ||
46 | + $this->set('TOBEARCHIVED', self::TOBEARCHIVED); | ||
47 | + $this->set('ARCHIVED', self::ARCHIVED); | ||
48 | + } | ||
49 | + | ||
23 | /** | 50 | /** |
24 | * | 51 | * |
25 | * @param $user Give | 52 | * @param $user Give |
@@ -327,6 +354,7 @@ class MaterielsController extends AppController { | @@ -327,6 +354,7 @@ class MaterielsController extends AppController { | ||
327 | * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | 354 | * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. |
328 | */ | 355 | */ |
329 | public function view($id = null) { | 356 | public function view($id = null) { |
357 | + | ||
330 | $materiel = $this->Materiels->get($id, [ | 358 | $materiel = $this->Materiels->get($id, [ |
331 | 'contain' => [ | 359 | 'contain' => [ |
332 | 'SurCategories', | 360 | 'SurCategories', |
@@ -342,7 +370,18 @@ class MaterielsController extends AppController { | @@ -342,7 +370,18 @@ class MaterielsController extends AppController { | ||
342 | 'Fournisseurs' | 370 | 'Fournisseurs' |
343 | ] | 371 | ] |
344 | ]); | 372 | ]); |
345 | - | 373 | + |
374 | + $IS_CREATED = ( $materiel->status == 'CREATED' ); | ||
375 | + $IS_VALIDATED = ( $materiel->status == 'VALIDATED' ); | ||
376 | + $IS_TOBEARCHIVED = ( $materiel->status == 'TOBEARCHIVED' ); | ||
377 | + $IS_ARCHIVED = ( $materiel->status == 'ARCHIVED' ); | ||
378 | + $status = $this->allStatus[$materiel->status]; | ||
379 | + $this->set('IS_CREATED', $IS_CREATED); | ||
380 | + $this->set('IS_VALIDATED', $IS_VALIDATED); | ||
381 | + $this->set('IS_TOBEARCHIVED', $IS_TOBEARCHIVED); | ||
382 | + $this->set('IS_ARCHIVED', $IS_ARCHIVED); | ||
383 | + $this->set('status', $status); | ||
384 | + | ||
346 | $sites = TableRegistry::get('Sites'); | 385 | $sites = TableRegistry::get('Sites'); |
347 | $typeSuivis = TableRegistry::get('TypeSuivis'); | 386 | $typeSuivis = TableRegistry::get('TypeSuivis'); |
348 | $typeDocuments = TableRegistry::get('TypeDocuments'); | 387 | $typeDocuments = TableRegistry::get('TypeDocuments'); |
@@ -357,6 +396,7 @@ class MaterielsController extends AppController { | @@ -357,6 +396,7 @@ class MaterielsController extends AppController { | ||
357 | $this->set('typeSuivis', $typeSuivis); | 396 | $this->set('typeSuivis', $typeSuivis); |
358 | $this->set('typeDocuments', $typeDocuments); | 397 | $this->set('typeDocuments', $typeDocuments); |
359 | $this->set('fournisseurs', $fournisseurs); | 398 | $this->set('fournisseurs', $fournisseurs); |
399 | + | ||
360 | $this->set('materiel', $materiel); | 400 | $this->set('materiel', $materiel); |
361 | $this->set('_serialize', [ | 401 | $this->set('_serialize', [ |
362 | 'materiel' | 402 | 'materiel' |
src/Template/Materiels/view.ctp
@@ -2,13 +2,80 @@ | @@ -2,13 +2,80 @@ | ||
2 | use Cake\I18n\Time; | 2 | use Cake\I18n\Time; |
3 | use Cake\I18n\Date; | 3 | use Cake\I18n\Date; |
4 | use Cake\ORM\TableRegistry; | 4 | use Cake\ORM\TableRegistry; |
5 | + | ||
6 | +// EP | ||
7 | +// Set some useful global variables for this view | ||
8 | + | ||
9 | +// 1) Materiel settings | ||
10 | +/* | ||
11 | +const CREATED = 1; | ||
12 | +const VALIDATED = 2; | ||
13 | +const TOBEARCHIVED = 3; | ||
14 | +const ARCHIVED = 4; | ||
15 | +$allStatus = [ | ||
16 | + 'CREATED' => CREATED, | ||
17 | + 'VALIDATED' => VALIDATED, | ||
18 | + 'TOBEARCHIVED' => TOBEARCHIVED, | ||
19 | + 'ARCHIVED' => ARCHIVED, | ||
20 | +]; | ||
21 | +$IS_CREATED = ( $materiel->status == 'CREATED' ); | ||
22 | +$IS_VALIDATED = ( $materiel->status == 'VALIDATED' ); | ||
23 | +$IS_TOBEARCHIVED = ( $materiel->status == 'TOBEARCHIVED' ); | ||
24 | +$IS_ARCHIVED = ( $materiel->status == 'ARCHIVED' ); | ||
25 | +$status = $allStatus[$materiel->status]; | ||
26 | + | ||
27 | +// 2) User settings | ||
28 | +const PROFILE_USER = 1; | ||
29 | +const PROFILE_RESPONSABLE = 2; | ||
30 | +const PROFILE_ADMIN = 3; | ||
31 | +const PROFILE_ADMINPLUS = 4; | ||
32 | +const PROFILE_SUPERADMIN = 5; | ||
33 | +$allProfiles = [ | ||
34 | + 'Utilisateur' => PROFILE_USER, | ||
35 | + 'Responsable' => PROFILE_RESPONSABLE, | ||
36 | + 'Administration' => PROFILE_ADMIN, | ||
37 | + 'Administration Plus' => PROFILE_ADMINPLUS, | ||
38 | + 'Super Administrateur' => PROFILE_SUPERADMIN | ||
39 | +]; | ||
40 | + | ||
41 | +$profile = $allProfiles["$role"]; | ||
42 | +echo $profile; | ||
43 | + | ||
44 | +$USER_IS_UTILISATEUR = ($profile == $PROFILE_USER); | ||
45 | +$USER_IS_RESPONSABLE = ($profile == $PROFILE_RESPONSABLE); | ||
46 | +$USER_IS_ADMIN = ($profile == $PROFILE_ADMIN); | ||
47 | +$USER_IS_ADMINPLUS = ($profile == $PROFILE_ADMINPLUS); | ||
48 | +$USER_IS_SUPERADMIN = ($profile == $PROFILE_SUPERADMIN); | ||
49 | + | ||
50 | +$USER_IS_ADMIN_OR_MORE = $profile >= $PROFILE_ADMIN; | ||
51 | +*/ | ||
52 | + | ||
53 | +$USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER = $USER_IS_UTILISATEUR && in_array($username, [$materiel->nom_createur, $materiel->nom_responsable]); | ||
54 | + | ||
55 | +$USER_IS_RESPONSABLE_AND_SAME_GROUP = | ||
56 | + $USER_IS_RESPONSABLE | ||
57 | + && | ||
58 | + ( | ||
59 | + ( | ||
60 | + isset($userConnected->groupes_metier_id) | ||
61 | + && $userConnected->groupes_metier_id != $idGmNa | ||
62 | + && $materiel->groupes_metier_id == $userConnected->groupes_metier_id | ||
63 | + ) | ||
64 | + || | ||
65 | + ( | ||
66 | + isset($userConnected->groupe_thematique_id) | ||
67 | + && $userConnected->groupe_thematique_id != $idGtNa | ||
68 | + && $materiel->groupes_thematique_id == $userConnected->groupe_thematique_id | ||
69 | + ) | ||
70 | + ); | ||
5 | ?> | 71 | ?> |
6 | 72 | ||
7 | <div class="materiels view"> | 73 | <div class="materiels view"> |
8 | 74 | ||
9 | <h2> | 75 | <h2> |
10 | <?php | 76 | <?php |
11 | - if (h($materiel->status) == 'ARCHIVED') echo '<i class="icon-inbox"></i> '; | 77 | + //if (h($materiel->status) == 'ARCHIVED') echo '<i class="icon-inbox"></i> '; |
78 | + if ($IS_ARCHIVED) echo '<i class="icon-inbox"></i> '; | ||
12 | $panne = h($materiel->hors_service) ? ' (HORS SERVICE)' : ''; | 79 | $panne = h($materiel->hors_service) ? ' (HORS SERVICE)' : ''; |
13 | ?> | 80 | ?> |
14 | <?=h($materiel->designation) . $panne?> | 81 | <?=h($materiel->designation) . $panne?> |
@@ -16,8 +83,9 @@ use Cake\ORM\TableRegistry; | @@ -16,8 +83,9 @@ use Cake\ORM\TableRegistry; | ||
16 | <span style="font-size: 70%; color: grey;"> | 83 | <span style="font-size: 70%; color: grey;"> |
17 | <?=h($materiel->numero_laboratoire)?> | 84 | <?=h($materiel->numero_laboratoire)?> |
18 | <?php | 85 | <?php |
19 | - if (h($materiel->status) == 'ARCHIVED') echo ' (Archivé)'; | ||
20 | - ?> | 86 | + //if (h($materiel->status) == 'ARCHIVED') echo ' (Archivé)'; |
87 | + if ($IS_ARCHIVED) echo ' (Archivé)'; | ||
88 | + ?> | ||
21 | </span> | 89 | </span> |
22 | </h2> | 90 | </h2> |
23 | <br/> | 91 | <br/> |
@@ -41,21 +109,26 @@ use Cake\ORM\TableRegistry; | @@ -41,21 +109,26 @@ use Cake\ORM\TableRegistry; | ||
41 | </div> | 109 | </div> |
42 | <br/> | 110 | <br/> |
43 | 111 | ||
112 | + | ||
113 | + <!-- BOUTONS --> | ||
114 | + | ||
44 | <div id="boutons" class="actions" style="margin-bottom: 20px; width: 100%; float: none; padding: 10px 0;"> | 115 | <div id="boutons" class="actions" style="margin-bottom: 20px; width: 100%; float: none; padding: 10px 0;"> |
45 | 116 | ||
46 | <?php | 117 | <?php |
47 | // CREATED or VALIDATED | 118 | // CREATED or VALIDATED |
48 | - if ( in_array($materiel->status, ['CREATED','VALIDATED']) ) { | ||
49 | - if ( | ||
50 | - in_array($role, ['Administration','Administration Plus','Super Administrateur']) | 119 | + //if ( in_array($materiel->status, ['CREATED','VALIDATED']) ) { |
120 | + if ( $IS_CREATED || $IS_VALIDATED ) { | ||
121 | + if ( $USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP ) | ||
122 | + /* | ||
123 | + //in_array($role, ['Administration','Administration Plus','Super Administrateur']) | ||
51 | || | 124 | || |
52 | ( | 125 | ( |
53 | - $role == 'Utilisateur' | ||
54 | - && in_array($username, [$materiel->nom_createur, $materiel->nom_responsable]) | 126 | + //$role == 'Utilisateur' |
127 | + //&& in_array($username, [$materiel->nom_createur, $materiel->nom_responsable]) | ||
55 | ) | 128 | ) |
56 | || | 129 | || |
57 | ( | 130 | ( |
58 | - $role == 'Responsable' | 131 | + $role == 'Responsable' |
59 | && ( | 132 | && ( |
60 | ( | 133 | ( |
61 | isset($userConnected->groupes_metier_id) | 134 | isset($userConnected->groupes_metier_id) |
@@ -70,7 +143,7 @@ use Cake\ORM\TableRegistry; | @@ -70,7 +143,7 @@ use Cake\ORM\TableRegistry; | ||
70 | ) | 143 | ) |
71 | ) | 144 | ) |
72 | ) | 145 | ) |
73 | - ) | 146 | + */ |
74 | echo $this->Html->link( | 147 | echo $this->Html->link( |
75 | __('<i class="icon-pencil"></i> Editer ce matériel'), | 148 | __('<i class="icon-pencil"></i> Editer ce matériel'), |
76 | [ 'action' => 'edit', $materiel->id ], | 149 | [ 'action' => 'edit', $materiel->id ], |
@@ -80,7 +153,8 @@ use Cake\ORM\TableRegistry; | @@ -80,7 +153,8 @@ use Cake\ORM\TableRegistry; | ||
80 | 153 | ||
81 | // TOBEARCHIVED+ | 154 | // TOBEARCHIVED+ |
82 | else { | 155 | else { |
83 | - if (in_array($role, ['Administration Plus','Super Administrateur'])) { | 156 | + //if (in_array($role, ['Administration Plus','Super Administrateur'])) { |
157 | + if ($USER_IS_ADMIN_OR_MORE) { | ||
84 | echo $this->Html->link( | 158 | echo $this->Html->link( |
85 | __('<i class="icon-pencil"></i> Editer ce matériel'), | 159 | __('<i class="icon-pencil"></i> Editer ce matériel'), |
86 | ['action' => 'edit', $materiel->id], | 160 | ['action' => 'edit', $materiel->id], |
@@ -90,7 +164,8 @@ use Cake\ORM\TableRegistry; | @@ -90,7 +164,8 @@ use Cake\ORM\TableRegistry; | ||
90 | } | 164 | } |
91 | 165 | ||
92 | // VALIDATED | 166 | // VALIDATED |
93 | - if ($materiel->status == 'VALIDATED') { | 167 | + //if ($materiel->status == 'VALIDATED') { |
168 | + if ($IS_VALIDATED) { | ||
94 | 169 | ||
95 | // BOUTON NOUVEAU SUIVI | 170 | // BOUTON NOUVEAU SUIVI |
96 | echo $this->Html->link( | 171 | echo $this->Html->link( |
@@ -112,6 +187,8 @@ use Cake\ORM\TableRegistry; | @@ -112,6 +187,8 @@ use Cake\ORM\TableRegistry; | ||
112 | } | 187 | } |
113 | 188 | ||
114 | // BOUTON "Lier un Doc" | 189 | // BOUTON "Lier un Doc" |
190 | + if ( $USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP ) { | ||
191 | + /* | ||
115 | if ( | 192 | if ( |
116 | in_array($role, ['Administration','Administration Plus','Super Administrateur']) | 193 | in_array($role, ['Administration','Administration Plus','Super Administrateur']) |
117 | || | 194 | || |
@@ -136,6 +213,7 @@ use Cake\ORM\TableRegistry; | @@ -136,6 +213,7 @@ use Cake\ORM\TableRegistry; | ||
136 | ) | 213 | ) |
137 | ) | 214 | ) |
138 | ) { | 215 | ) { |
216 | + */ | ||
139 | echo $this->Html->link('<i class="icon-file"></i> Lier un Doc.', [ | 217 | echo $this->Html->link('<i class="icon-file"></i> Lier un Doc.', [ |
140 | 'controller' => 'documents', | 218 | 'controller' => 'documents', |
141 | 'action' => 'add', | 219 | 'action' => 'add', |
@@ -178,10 +256,12 @@ use Cake\ORM\TableRegistry; | @@ -178,10 +256,12 @@ use Cake\ORM\TableRegistry; | ||
178 | 256 | ||
179 | 257 | ||
180 | // Doc admission et sortie (admin+) | 258 | // Doc admission et sortie (admin+) |
181 | - if (in_array($role, ['Administration','Administration Plus','Super Administrateur'])) { | 259 | + if ($USER_IS_ADMIN_OR_MORE) { |
260 | + //if (in_array($role, ['Administration','Administration Plus','Super Administrateur'])) { | ||
182 | 261 | ||
183 | // Doc admission (admin only) | 262 | // Doc admission (admin only) |
184 | - if (($materiel->status == 'VALIDATED') || ($materiel->status == 'CREATED')) { | 263 | + if ( $IS_CREATED || $IS_VALIDATED ) { |
264 | + //if (($materiel->status == 'VALIDATED') || ($materiel->status == 'CREATED')) { | ||
185 | echo $this->Html->link('<i class="icon-file"></i> Doc. admission', [ | 265 | echo $this->Html->link('<i class="icon-file"></i> Doc. admission', [ |
186 | 'controller' => 'documents', | 266 | 'controller' => 'documents', |
187 | 'action' => 'admission', | 267 | 'action' => 'admission', |
@@ -194,7 +274,8 @@ use Cake\ORM\TableRegistry; | @@ -194,7 +274,8 @@ use Cake\ORM\TableRegistry; | ||
194 | } | 274 | } |
195 | 275 | ||
196 | // Doc sortie (admin only) | 276 | // Doc sortie (admin only) |
197 | - else if (($materiel->status == 'ARCHIVED') || ($materiel->status == 'TOBEARCHIVED')) { | 277 | + else if ( $IS_ARCHIVED || $IS_TOBEARCHIVED ) { |
278 | + //else if (($materiel->status == 'ARCHIVED') || ($materiel->status == 'TOBEARCHIVED')) { | ||
198 | echo $this->Html->link('<i class="icon-file"></i> Doc. sortie', [ | 279 | echo $this->Html->link('<i class="icon-file"></i> Doc. sortie', [ |
199 | 'controller' => 'documents', | 280 | 'controller' => 'documents', |
200 | 'action' => 'sortie', | 281 | 'action' => 'sortie', |
@@ -209,6 +290,8 @@ use Cake\ORM\TableRegistry; | @@ -209,6 +290,8 @@ use Cake\ORM\TableRegistry; | ||
209 | 290 | ||
210 | 291 | ||
211 | // BOUTON changement statut | 292 | // BOUTON changement statut |
293 | + if ( $USER_IS_ADMIN_OR_MORE || $USER_IS_RESPONSABLE_AND_SAME_GROUP ) { | ||
294 | + /* | ||
212 | if ( | 295 | if ( |
213 | in_array($role, ['Administration','Administration Plus','Super Administrateur']) | 296 | in_array($role, ['Administration','Administration Plus','Super Administrateur']) |
214 | || ( | 297 | || ( |
@@ -228,9 +311,12 @@ use Cake\ORM\TableRegistry; | @@ -228,9 +311,12 @@ use Cake\ORM\TableRegistry; | ||
228 | ) | 311 | ) |
229 | ) | 312 | ) |
230 | ) { | 313 | ) { |
314 | + */ | ||
231 | // 2) Bouton de changement de statut : Valider, Demander archivage, ou Archiver | 315 | // 2) Bouton de changement de statut : Valider, Demander archivage, ou Archiver |
232 | - switch ($materiel->status) { | ||
233 | - case "CREATED" : | 316 | + //switch ($materiel->status) { |
317 | + switch ($status) { | ||
318 | + //case "CREATED" : | ||
319 | + case $CREATED : | ||
234 | echo $this->Html->link('<i class="icon-ok-sign"></i> Valider', [ | 320 | echo $this->Html->link('<i class="icon-ok-sign"></i> Valider', [ |
235 | 'action' => 'statusValidated', | 321 | 'action' => 'statusValidated', |
236 | $materiel->id, | 322 | $materiel->id, |
@@ -241,7 +327,7 @@ use Cake\ORM\TableRegistry; | @@ -241,7 +327,7 @@ use Cake\ORM\TableRegistry; | ||
241 | 'escape' => false | 327 | 'escape' => false |
242 | ]); | 328 | ]); |
243 | break; | 329 | break; |
244 | - case "VALIDATED" : | 330 | + case $VALIDATED : |
245 | echo $this->Html->link('<i class="icon-ok-sign"></i> Demander sortie', [ | 331 | echo $this->Html->link('<i class="icon-ok-sign"></i> Demander sortie', [ |
246 | 'action' => 'statusToBeArchived', | 332 | 'action' => 'statusToBeArchived', |
247 | $materiel->id, | 333 | $materiel->id, |
@@ -252,7 +338,7 @@ use Cake\ORM\TableRegistry; | @@ -252,7 +338,7 @@ use Cake\ORM\TableRegistry; | ||
252 | 'escape' => false | 338 | 'escape' => false |
253 | ]); | 339 | ]); |
254 | break; | 340 | break; |
255 | - case "TOBEARCHIVED" : | 341 | + case $TOBEARCHIVED : |
256 | if ($role != 'Responsable' && $role != 'Super Administrateur') { | 342 | if ($role != 'Responsable' && $role != 'Super Administrateur') { |
257 | echo $this->Html->link('<i class="icon-ok-sign"></i> Sortie inventaire', [ | 343 | echo $this->Html->link('<i class="icon-ok-sign"></i> Sortie inventaire', [ |
258 | 'action' => 'statusArchived', | 344 | 'action' => 'statusArchived', |
@@ -430,8 +516,10 @@ use Cake\ORM\TableRegistry; | @@ -430,8 +516,10 @@ use Cake\ORM\TableRegistry; | ||
430 | 516 | ||
431 | 517 | ||
432 | <!-- PARTIE ADMIN --> | 518 | <!-- PARTIE ADMIN --> |
519 | + | ||
433 | <?php | 520 | <?php |
434 | - if (in_array($role, ['Administration','Administration Plus','Super Administrateur'])) { | 521 | + if ( $USER_IS_ADMIN_OR_MORE ) { |
522 | + //if (in_array($role, ['Administration','Administration Plus','Super Administrateur'])) { | ||
435 | echo '<h3 id="t_informations_admin" style="cursor: pointer;">'; | 523 | echo '<h3 id="t_informations_admin" style="cursor: pointer;">'; |
436 | echo '<i class="icon-chevron-down" style="font-size: 14px;" id="i_informations_admin"></i>'; | 524 | echo '<i class="icon-chevron-down" style="font-size: 14px;" id="i_informations_admin"></i>'; |
437 | echo '<span style="text-decoration: underline;"> Informations administratives</span>'; | 525 | echo '<span style="text-decoration: underline;"> Informations administratives</span>'; |
@@ -451,6 +539,7 @@ use Cake\ORM\TableRegistry; | @@ -451,6 +539,7 @@ use Cake\ORM\TableRegistry; | ||
451 | 539 | ||
452 | 540 | ||
453 | <!-- SUIVIS --> | 541 | <!-- SUIVIS --> |
542 | + | ||
454 | <h3 id="t_suivis" style="cursor: pointer;"> | 543 | <h3 id="t_suivis" style="cursor: pointer;"> |
455 | <i class="icon-chevron-down" style="font-size: 14px;" id="i_suivis"></i> | 544 | <i class="icon-chevron-down" style="font-size: 14px;" id="i_suivis"></i> |
456 | <span style="text-decoration: underline;">Suivi(s) du matériel (<?=count($materiel->suivis)?>)</span> | 545 | <span style="text-decoration: underline;">Suivi(s) du matériel (<?=count($materiel->suivis)?>)</span> |
@@ -471,6 +560,8 @@ use Cake\ORM\TableRegistry; | @@ -471,6 +560,8 @@ use Cake\ORM\TableRegistry; | ||
471 | <tr> | 560 | <tr> |
472 | <td class="actions" style="padding: 6px 0; text-align: left;"> | 561 | <td class="actions" style="padding: 6px 0; text-align: left;"> |
473 | <?php | 562 | <?php |
563 | + if ( $USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP ) { | ||
564 | + /* | ||
474 | if ( | 565 | if ( |
475 | in_array($role, ['Administration','Administration Plus','Super Administrateur']) | 566 | in_array($role, ['Administration','Administration Plus','Super Administrateur']) |
476 | || | 567 | || |
@@ -495,6 +586,7 @@ use Cake\ORM\TableRegistry; | @@ -495,6 +586,7 @@ use Cake\ORM\TableRegistry; | ||
495 | ) | 586 | ) |
496 | ) | 587 | ) |
497 | ) { | 588 | ) { |
589 | + */ | ||
498 | echo $this->Html->link(__('<i class="icon-pencil"></i>'), ['controller' => 'Suivis','action' => 'edit',$suivis->id], ['escape' => false,'style' => 'margin:0']); | 590 | echo $this->Html->link(__('<i class="icon-pencil"></i>'), ['controller' => 'Suivis','action' => 'edit',$suivis->id], ['escape' => false,'style' => 'margin:0']); |
499 | echo $this->Form->postLink(__('<i class="icon-trash"></i>'), ['controller' => 'Suivis','action' => 'delete',$suivis->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $suivis->id)]); | 591 | echo $this->Form->postLink(__('<i class="icon-trash"></i>'), ['controller' => 'Suivis','action' => 'delete',$suivis->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $suivis->id)]); |
500 | } | 592 | } |
@@ -518,6 +610,7 @@ use Cake\ORM\TableRegistry; | @@ -518,6 +610,7 @@ use Cake\ORM\TableRegistry; | ||
518 | 610 | ||
519 | 611 | ||
520 | <!-- EMPRUNTS --> | 612 | <!-- EMPRUNTS --> |
613 | + | ||
521 | <h3 id="t_emprunts" style="cursor: pointer;"> | 614 | <h3 id="t_emprunts" style="cursor: pointer;"> |
522 | <i class="icon-chevron-down" style="font-size: 14px;" id="i_emprunts"></i> | 615 | <i class="icon-chevron-down" style="font-size: 14px;" id="i_emprunts"></i> |
523 | <span style="text-decoration: underline;">Emprunt(s) du matériel (<?=count($materiel->emprunts)?>)</span> | 616 | <span style="text-decoration: underline;">Emprunt(s) du matériel (<?=count($materiel->emprunts)?>)</span> |
@@ -534,19 +627,21 @@ use Cake\ORM\TableRegistry; | @@ -534,19 +627,21 @@ use Cake\ORM\TableRegistry; | ||
534 | <th><?=__('Date de l\'emprunt')?></th> | 627 | <th><?=__('Date de l\'emprunt')?></th> |
535 | <th><?=__('Date de retour')?></th> | 628 | <th><?=__('Date de retour')?></th> |
536 | </tr> | 629 | </tr> |
537 | - <?php foreach ($materiel->emprunts as $emprunts) : | 630 | + <?php foreach ($materiel->emprunts as $emprunt) : |
538 | $type = 'Externe'; | 631 | $type = 'Externe'; |
539 | - $lieu = $emprunts['laboratoire']; | ||
540 | - if ($emprunts['emprunt_interne'] == 1) { | 632 | + $lieu = $emprunt['laboratoire']; |
633 | + if ($emprunt['emprunt_interne'] == 1) { | ||
541 | $type = 'Interne'; | 634 | $type = 'Interne'; |
542 | $lieu = $sites->find()->where([ | 635 | $lieu = $sites->find()->where([ |
543 | - 'id =' => h($emprunts->site_id) | ||
544 | - ])->first()['nom'] . '-' . h($emprunts->e_lieu_detail); | 636 | + 'id =' => h($emprunt->site_id) |
637 | + ])->first()['nom'] . '-' . h($emprunt->e_lieu_detail); | ||
545 | } | 638 | } |
546 | ?> | 639 | ?> |
547 | <tr> | 640 | <tr> |
548 | <td class="actions" style="padding: 6px 0; text-align: left;"> | 641 | <td class="actions" style="padding: 6px 0; text-align: left;"> |
549 | <?php | 642 | <?php |
643 | + if ( $USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP ) { | ||
644 | + /* | ||
550 | if ( | 645 | if ( |
551 | in_array($role, ['Administration','Administration Plus','Super Administrateur']) | 646 | in_array($role, ['Administration','Administration Plus','Super Administrateur']) |
552 | || | 647 | || |
@@ -571,17 +666,18 @@ use Cake\ORM\TableRegistry; | @@ -571,17 +666,18 @@ use Cake\ORM\TableRegistry; | ||
571 | ) | 666 | ) |
572 | ) | 667 | ) |
573 | ) { | 668 | ) { |
574 | - echo $this->Html->link(__('<i class="icon-pencil"></i>'), ['controller' => 'Emprunts','action' => 'edit',$emprunts->id], ['escape' => false,'style' => 'margin:0']); | ||
575 | - echo $this->Form->postLink(__('<i class="icon-trash"></i>'), ['controller' => 'Emprunts','action' => 'delete',$emprunts->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $emprunts->id)]); | 669 | + */ |
670 | + echo $this->Html->link(__('<i class="icon-pencil"></i>'), ['controller' => 'Emprunts','action' => 'edit',$emprunt->id], ['escape' => false,'style' => 'margin:0']); | ||
671 | + echo $this->Form->postLink(__('<i class="icon-trash"></i>'), ['controller' => 'Emprunts','action' => 'delete',$emprunt->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $emprunt->id)]); | ||
576 | } | 672 | } |
577 | ?> | 673 | ?> |
578 | </td> | 674 | </td> |
579 | - <td><?=$this->Html->link('Emprunt ' . $emprunts->id, ['controller' => 'emprunts','action' => 'view',$emprunts->id])?></td> | ||
580 | - <td><?=h($emprunts->nom_emprunteur)?></td> | 675 | + <td><?=$this->Html->link('Emprunt ' . $emprunt->id, ['controller' => 'emprunts','action' => 'view',$emprunt->id])?></td> |
676 | + <td><?=h($emprunt->nom_emprunteur)?></td> | ||
581 | <td><?=h($type)?></td> | 677 | <td><?=h($type)?></td> |
582 | <td><?=h($lieu)?></td> | 678 | <td><?=h($lieu)?></td> |
583 | - <td><?=h($emprunts->date_emprunt)?></td> | ||
584 | - <td><?=h($emprunts->date_retour_emprunt)?></td> | 679 | + <td><?=h($emprunt->date_emprunt)?></td> |
680 | + <td><?=h($emprunt->date_retour_emprunt)?></td> | ||
585 | </tr> | 681 | </tr> |
586 | <?php endforeach;?> | 682 | <?php endforeach;?> |
587 | </table> | 683 | </table> |
@@ -594,6 +690,7 @@ use Cake\ORM\TableRegistry; | @@ -594,6 +690,7 @@ use Cake\ORM\TableRegistry; | ||
594 | 690 | ||
595 | 691 | ||
596 | <!-- FICHIERS liés --> | 692 | <!-- FICHIERS liés --> |
693 | + | ||
597 | <?php $nbFic = count($materiel->documents); ?> | 694 | <?php $nbFic = count($materiel->documents); ?> |
598 | <h3 id="t_fichiers" style="cursor: pointer;"> | 695 | <h3 id="t_fichiers" style="cursor: pointer;"> |
599 | <i class="icon-chevron-down" style="font-size: 14px;" id="i_fichiers"></i> | 696 | <i class="icon-chevron-down" style="font-size: 14px;" id="i_fichiers"></i> |
@@ -631,6 +728,8 @@ use Cake\ORM\TableRegistry; | @@ -631,6 +728,8 @@ use Cake\ORM\TableRegistry; | ||
631 | 'escape' => false | 728 | 'escape' => false |
632 | ]); | 729 | ]); |
633 | } | 730 | } |
731 | + if ( $USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP ) { | ||
732 | + /* | ||
634 | if ( | 733 | if ( |
635 | in_array($role, ['Administration','Administration Plus','Super Administrateur']) | 734 | in_array($role, ['Administration','Administration Plus','Super Administrateur']) |
636 | || | 735 | || |
@@ -656,6 +755,7 @@ use Cake\ORM\TableRegistry; | @@ -656,6 +755,7 @@ use Cake\ORM\TableRegistry; | ||
656 | ) | 755 | ) |
657 | ) | 756 | ) |
658 | ) { | 757 | ) { |
758 | + */ | ||
659 | echo $this->Html->link(__('<i class="icon-pencil"></i>'), ['controller' => 'Documents','action' => 'edit',$documents->id], ['escape' => false,'style' => 'margin:0']); | 759 | echo $this->Html->link(__('<i class="icon-pencil"></i>'), ['controller' => 'Documents','action' => 'edit',$documents->id], ['escape' => false,'style' => 'margin:0']); |
660 | echo $this->Form->postLink(__('<i class="icon-trash"></i>'), ['controller' => 'Documents','action' => 'delete',$documents->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $documents->id)]); | 760 | echo $this->Form->postLink(__('<i class="icon-trash"></i>'), ['controller' => 'Documents','action' => 'delete',$documents->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $documents->id)]); |
661 | } | 761 | } |
@@ -666,7 +766,7 @@ use Cake\ORM\TableRegistry; | @@ -666,7 +766,7 @@ use Cake\ORM\TableRegistry; | ||
666 | <td><?=$p?></td> | 766 | <td><?=$p?></td> |
667 | </tr> | 767 | </tr> |
668 | <?php | 768 | <?php |
669 | - endforeach; | 769 | + endforeach; |
670 | ?> | 770 | ?> |
671 | </table> | 771 | </table> |
672 | <?php } else echo 'Aucun fichier pour ce matériel.'; ?> | 772 | <?php } else echo 'Aucun fichier pour ce matériel.'; ?> |