Commit 5ba79d541915a04b5a169e3bd8c595af7acde11b
1 parent
1f8b2b88
Exists in
master
and in
1 other branch
Tri automatique de TOUTES les (sous-)listes associées
(dans les 'Autres listes') v4.105.4-3.7.9 (EP)
Showing
4 changed files
with
92 additions
and
33 deletions
Show diff stats
CHANGES.txt
... | ... | @@ -120,7 +120,8 @@ Outre ces changements, voici d'autres changements importants : |
120 | 120 | ======= CHANGES ======= |
121 | 121 | |
122 | 122 | ------- |
123 | -07/10/2020 v4.105.3-3.7.9 (EP) | |
123 | +07/10/2020 v4.105.4-3.7.9 (EP) | |
124 | + - (e) Tri automatique de TOUTES les (sous-)listes associées (dans les 'Autres listes') | |
124 | 125 | - (e) Ajout de sections dans la vue du matériel (+ joli) |
125 | 126 | - (b) Bugfixed configuration |
126 | 127 | - (b) Bugfixed tests de l'entité Projets | ... | ... |
README.md
... | ... | @@ -43,7 +43,7 @@ Logiciel testé et validé sur les configurations suivantes : |
43 | 43 | -------------------------------------------------------------------------------------------- |
44 | 44 | |
45 | 45 | Date: 07/10/2020 |
46 | -Version: 4.105.3-3.7.9 | |
46 | +Version: 4.105.4-3.7.9 | |
47 | 47 | |
48 | 48 | |
49 | 49 | HISTORIQUE DES CHANGEMENTS DE VERSION : voir le fichier CHANGES.txt (ou la page web /pages/changes) | ... | ... |
src/Controller/AppController.php
... | ... | @@ -445,6 +445,11 @@ class AppController extends Controller |
445 | 445 | return $controller_name.'s'; |
446 | 446 | } |
447 | 447 | |
448 | + protected function getControllerInstanceForName($controller_name) { | |
449 | + $c = 'App\\Controller\\'.$controller_name.'Controller'; | |
450 | + return new $c(); | |
451 | + } | |
452 | + | |
448 | 453 | protected function getRealControllerNameForAlias($alias_name) { |
449 | 454 | return $alias_name; |
450 | 455 | } |
... | ... | @@ -2182,7 +2187,6 @@ class AppController extends Controller |
2182 | 2187 | //public function view_generic($id, $associated_entity_types, $containavirer=[]) { |
2183 | 2188 | public function view_generic($id, $child_entity_types=[]) { |
2184 | 2189 | |
2185 | - $contain_children = $child_entity_types; | |
2186 | 2190 | //debug($contain_children); |
2187 | 2191 | // ex: SurCategories |
2188 | 2192 | $controller_name = $this->getName(); |
... | ... | @@ -2197,10 +2201,42 @@ class AppController extends Controller |
2197 | 2201 | //$entity = $this->getTableLocator()->get('Categories'); |
2198 | 2202 | //$entity = $this->$controller_name->newEntity(); |
2199 | 2203 | //debug($entity->getSchema()); |
2204 | + | |
2205 | + /* On transforme le $contain_children pour lui ajouter des clés de tri (croissant) sur le nom des entités. | |
2206 | + * On va obtenir qqch comme ceci : | |
2207 | + [ | |
2208 | + 'SousCategories' => [ | |
2209 | + 'sort' => [ | |
2210 | + 'SousCategories.nom' => 'ASC' | |
2211 | + ] | |
2212 | + ], | |
2213 | + 'Materiels' => [ | |
2214 | + 'sort' => [ | |
2215 | + 'Materiels.designation' => 'ASC' | |
2216 | + ] | |
2217 | + ] | |
2218 | + ] | |
2219 | + */ | |
2220 | + $contain_children_sorted = []; | |
2221 | + $children_controller_instances = []; | |
2222 | + foreach ($child_entity_types as $child_controller_name) { | |
2223 | + $c = $this->getControllerInstanceForName($child_controller_name); | |
2224 | + // (optimisation) on stocke l'instance pour plus tard | |
2225 | + $children_controller_instances[$child_controller_name] = $c; | |
2226 | + //$fname_label = 'nom'; | |
2227 | + $fname_label = $c->getNameFieldLabel(); | |
2228 | + $contain_children_sorted[$child_controller_name] = [ | |
2229 | + 'sort' => ["$child_controller_name.$fname_label" => 'ASC'] | |
2230 | + ]; | |
2231 | + } | |
2232 | + //debug($children_controller_instances); | |
2233 | + //debug($contain_children_sorted); | |
2234 | + //exit; | |
2235 | + | |
2200 | 2236 | $entity = $this->$controller_name->get($id, [ |
2201 | 2237 | //'contain' => ['SurCategories'] |
2202 | 2238 | //'contain' => $parent_entity_controller_name |
2203 | - 'contain' => $contain_children | |
2239 | + 'contain' => $contain_children_sorted | |
2204 | 2240 | ]); |
2205 | 2241 | //debug($entity); exit; |
2206 | 2242 | |
... | ... | @@ -2211,8 +2247,8 @@ class AppController extends Controller |
2211 | 2247 | * I - Entités PARENTES => $parent_entities_infos |
2212 | 2248 | */ |
2213 | 2249 | |
2214 | - // On regarde si l'entité contient des fk | |
2215 | - // Si oui, on recharge l'entité AVEC toutes les entités associées | |
2250 | + // On regarde si l'entité contient des fk (parents car belongsTo) | |
2251 | + // Si oui, on recharge l'entité AVEC toutes les entités (parentes) associées | |
2216 | 2252 | $fks = []; |
2217 | 2253 | foreach ($entity->toArray() as $fname=>$fval) { |
2218 | 2254 | if ( strpos($fname,'_id') === strlen($fname)-3 ) |
... | ... | @@ -2220,12 +2256,15 @@ class AppController extends Controller |
2220 | 2256 | } |
2221 | 2257 | //debug($fks); exit; |
2222 | 2258 | $contain_parents = array_values($fks); |
2223 | - if ($contain_parents) | |
2259 | + if ($contain_parents) { | |
2260 | + $contain_all = array_merge($contain_parents, $contain_children_sorted); | |
2261 | + //debug($contain_all); | |
2224 | 2262 | $entity = $this->$controller_name->get($id, [ |
2225 | 2263 | //'contain' => ['SurCategories'] |
2226 | 2264 | //'contain' => $parent_entity_controller_name |
2227 | - 'contain' => array_merge($contain_parents, $contain_children) | |
2265 | + 'contain' => $contain_all | |
2228 | 2266 | ]); |
2267 | + } | |
2229 | 2268 | //debug($entity); //exit; |
2230 | 2269 | |
2231 | 2270 | // S'il y a des entités associées (parentes ou enfants), |
... | ... | @@ -2245,8 +2284,11 @@ class AppController extends Controller |
2245 | 2284 | foreach ($fks as $fk_name => $parent_entity_controller_name) { |
2246 | 2285 | //if ($fk_name=='groupes_thematique_id') continue; |
2247 | 2286 | $parent_entity_real_controller_name = $this->getRealControllerNameForAlias($parent_entity_controller_name); |
2287 | + $c = $this->getControllerInstanceForName($parent_entity_real_controller_name); | |
2288 | + /* | |
2248 | 2289 | $c = 'App\\Controller\\'.$parent_entity_real_controller_name.'Controller'; |
2249 | 2290 | $c = new $c(); |
2291 | + */ | |
2250 | 2292 | // 'Domaine' |
2251 | 2293 | $parent_entity_type_name=$c->getTypeNameSingular($parent_entity_controller_name); |
2252 | 2294 | //debug($parent_entity_type_name); |
... | ... | @@ -2332,16 +2374,20 @@ class AppController extends Controller |
2332 | 2374 | 'sur_categorie_id =' => $id |
2333 | 2375 | ]); |
2334 | 2376 | */ |
2335 | - foreach ($child_entity_types as $entity_type) { | |
2336 | - $child_entities_list[$entity_type] = []; | |
2377 | + foreach ($child_entity_types as $child_entity_type) { | |
2378 | + $child_entities_list[$child_entity_type] = []; | |
2337 | 2379 | // shortcut |
2338 | - $et = &$child_entities_list[$entity_type]; | |
2339 | - $et['fk_contained_name'] = $this->getFkContainedNameForControllerName($entity_type); | |
2380 | + $et = &$child_entities_list[$child_entity_type]; | |
2381 | + $et['fk_contained_name'] = $this->getFkContainedNameForControllerName($child_entity_type); | |
2340 | 2382 | //$et['controller_name'] = $entity_type; |
2341 | 2383 | // ex: 'App\Controller\CategoriesController' |
2342 | - $c = 'App\\Controller\\'.$entity_type.'Controller'; | |
2343 | 2384 | // instance du controleur |
2385 | + //$c = $this->getControllerInstanceForName($child_entity_type); | |
2386 | + $c = $children_controller_instances[$child_entity_type]; | |
2387 | + /* | |
2388 | + $c = 'App\\Controller\\'.$entity_type.'Controller'; | |
2344 | 2389 | $c = new $c(); |
2390 | + */ | |
2345 | 2391 | // ex: 'catégorie' |
2346 | 2392 | $et['entity_type_name_singular'] = $c->getTypeNameSingular(); |
2347 | 2393 | // ex: 'catégories' |
... | ... | @@ -2366,7 +2412,8 @@ class AppController extends Controller |
2366 | 2412 | "$fk_name =" => $id |
2367 | 2413 | ]); |
2368 | 2414 | */ |
2369 | - } | |
2415 | + } // foreach child | |
2416 | + | |
2370 | 2417 | //debug($child_entities_list); exit; |
2371 | 2418 | |
2372 | 2419 | //$controller_name = $this->SurCategories->get($id, [ | ... | ... |
src/Template/Pages/tools.ctp
... | ... | @@ -20,8 +20,11 @@ |
20 | 20 | 'action' => 'stats', |
21 | 21 | ]); |
22 | 22 | echo '</td></tr>'; |
23 | - | |
24 | 23 | |
24 | + echo '<tr><td></td></tr>'; | |
25 | + | |
26 | + | |
27 | + | |
25 | 28 | // - Page configuration |
26 | 29 | //if ($role == 'Super Administrateur') : |
27 | 30 | if ($role == 'Super Administrateur') { |
... | ... | @@ -34,6 +37,30 @@ |
34 | 37 | echo '</td></tr>'; |
35 | 38 | } |
36 | 39 | //endif; |
40 | + | |
41 | + echo '<tr><td>'; | |
42 | + echo $this->Html->link('Voir les Notifications', [ | |
43 | + 'controller' => 'pages', | |
44 | + 'action' => 'notifications' | |
45 | + ]); | |
46 | + echo '</td></tr>'; | |
47 | + | |
48 | + echo '<tr><td>'; | |
49 | + echo $this->Html->link('Voir les Autorisations des profils utilisateurs (ACLs)', [ | |
50 | + 'controller' => 'pages', | |
51 | + 'action' => 'acls' | |
52 | + ]); | |
53 | + echo '</td></tr>'; | |
54 | + | |
55 | + echo '<tr><td>'; | |
56 | + echo $this->Html->link('Etiqueteuse', [ | |
57 | + 'controller' => 'pages', | |
58 | + 'action' => 'printers' | |
59 | + ]); | |
60 | + echo '</td></tr>'; | |
61 | + | |
62 | + echo '<tr><td></td></tr>'; | |
63 | + | |
37 | 64 | |
38 | 65 | // - Page "Gérer le contenu variable" |
39 | 66 | if (in_array($role, [ |
... | ... | @@ -73,26 +100,10 @@ echo $this->Html->link('Export de la liste des materiels actifs (format CSV)', [ |
73 | 100 | ]); |
74 | 101 | echo '</td></tr>'; |
75 | 102 | |
76 | -echo '<tr><td>'; | |
77 | -echo $this->Html->link('Voir les Notifications', [ | |
78 | - 'controller' => 'pages', | |
79 | - 'action' => 'notifications' | |
80 | -]); | |
81 | -echo '</td></tr>'; | |
103 | +echo '<tr><td></td></tr>'; | |
104 | + | |
82 | 105 | |
83 | -echo '<tr><td>'; | |
84 | -echo $this->Html->link('Voir les Autorisations des profils utilisateurs (ACLs)', [ | |
85 | - 'controller' => 'pages', | |
86 | - 'action' => 'acls' | |
87 | -]); | |
88 | -echo '</td></tr>'; | |
89 | 106 | |
90 | -echo '<tr><td>'; | |
91 | -echo $this->Html->link('Etiqueteuse', [ | |
92 | - 'controller' => 'pages', | |
93 | - 'action' => 'printers' | |
94 | -]); | |
95 | -echo '</td></tr>'; | |
96 | 107 | |
97 | 108 | if ($role == 'Super Administrateur') : |
98 | 109 | ... | ... |