diff --git a/CHANGES.txt b/CHANGES.txt index e50b31b..69b101f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -120,7 +120,8 @@ Outre ces changements, voici d'autres changements importants : ======= CHANGES ======= ------- -07/10/2020 v4.105.3-3.7.9 (EP) +07/10/2020 v4.105.4-3.7.9 (EP) + - (e) Tri automatique de TOUTES les (sous-)listes associées (dans les 'Autres listes') - (e) Ajout de sections dans la vue du matériel (+ joli) - (b) Bugfixed configuration - (b) Bugfixed tests de l'entité Projets diff --git a/README.md b/README.md index 8a888d1..17aa16b 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Logiciel testé et validé sur les configurations suivantes : -------------------------------------------------------------------------------------------- Date: 07/10/2020 -Version: 4.105.3-3.7.9 +Version: 4.105.4-3.7.9 HISTORIQUE DES CHANGEMENTS DE VERSION : voir le fichier CHANGES.txt (ou la page web /pages/changes) diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index c3f4428..749fec9 100755 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -445,6 +445,11 @@ class AppController extends Controller return $controller_name.'s'; } + protected function getControllerInstanceForName($controller_name) { + $c = 'App\\Controller\\'.$controller_name.'Controller'; + return new $c(); + } + protected function getRealControllerNameForAlias($alias_name) { return $alias_name; } @@ -2182,7 +2187,6 @@ class AppController extends Controller //public function view_generic($id, $associated_entity_types, $containavirer=[]) { public function view_generic($id, $child_entity_types=[]) { - $contain_children = $child_entity_types; //debug($contain_children); // ex: SurCategories $controller_name = $this->getName(); @@ -2197,10 +2201,42 @@ class AppController extends Controller //$entity = $this->getTableLocator()->get('Categories'); //$entity = $this->$controller_name->newEntity(); //debug($entity->getSchema()); + + /* On transforme le $contain_children pour lui ajouter des clés de tri (croissant) sur le nom des entités. + * On va obtenir qqch comme ceci : + [ + 'SousCategories' => [ + 'sort' => [ + 'SousCategories.nom' => 'ASC' + ] + ], + 'Materiels' => [ + 'sort' => [ + 'Materiels.designation' => 'ASC' + ] + ] + ] + */ + $contain_children_sorted = []; + $children_controller_instances = []; + foreach ($child_entity_types as $child_controller_name) { + $c = $this->getControllerInstanceForName($child_controller_name); + // (optimisation) on stocke l'instance pour plus tard + $children_controller_instances[$child_controller_name] = $c; + //$fname_label = 'nom'; + $fname_label = $c->getNameFieldLabel(); + $contain_children_sorted[$child_controller_name] = [ + 'sort' => ["$child_controller_name.$fname_label" => 'ASC'] + ]; + } + //debug($children_controller_instances); + //debug($contain_children_sorted); + //exit; + $entity = $this->$controller_name->get($id, [ //'contain' => ['SurCategories'] //'contain' => $parent_entity_controller_name - 'contain' => $contain_children + 'contain' => $contain_children_sorted ]); //debug($entity); exit; @@ -2211,8 +2247,8 @@ class AppController extends Controller * I - Entités PARENTES => $parent_entities_infos */ - // On regarde si l'entité contient des fk - // Si oui, on recharge l'entité AVEC toutes les entités associées + // On regarde si l'entité contient des fk (parents car belongsTo) + // Si oui, on recharge l'entité AVEC toutes les entités (parentes) associées $fks = []; foreach ($entity->toArray() as $fname=>$fval) { if ( strpos($fname,'_id') === strlen($fname)-3 ) @@ -2220,12 +2256,15 @@ class AppController extends Controller } //debug($fks); exit; $contain_parents = array_values($fks); - if ($contain_parents) + if ($contain_parents) { + $contain_all = array_merge($contain_parents, $contain_children_sorted); + //debug($contain_all); $entity = $this->$controller_name->get($id, [ //'contain' => ['SurCategories'] //'contain' => $parent_entity_controller_name - 'contain' => array_merge($contain_parents, $contain_children) + 'contain' => $contain_all ]); + } //debug($entity); //exit; // S'il y a des entités associées (parentes ou enfants), @@ -2245,8 +2284,11 @@ class AppController extends Controller foreach ($fks as $fk_name => $parent_entity_controller_name) { //if ($fk_name=='groupes_thematique_id') continue; $parent_entity_real_controller_name = $this->getRealControllerNameForAlias($parent_entity_controller_name); + $c = $this->getControllerInstanceForName($parent_entity_real_controller_name); + /* $c = 'App\\Controller\\'.$parent_entity_real_controller_name.'Controller'; $c = new $c(); + */ // 'Domaine' $parent_entity_type_name=$c->getTypeNameSingular($parent_entity_controller_name); //debug($parent_entity_type_name); @@ -2332,16 +2374,20 @@ class AppController extends Controller 'sur_categorie_id =' => $id ]); */ - foreach ($child_entity_types as $entity_type) { - $child_entities_list[$entity_type] = []; + foreach ($child_entity_types as $child_entity_type) { + $child_entities_list[$child_entity_type] = []; // shortcut - $et = &$child_entities_list[$entity_type]; - $et['fk_contained_name'] = $this->getFkContainedNameForControllerName($entity_type); + $et = &$child_entities_list[$child_entity_type]; + $et['fk_contained_name'] = $this->getFkContainedNameForControllerName($child_entity_type); //$et['controller_name'] = $entity_type; // ex: 'App\Controller\CategoriesController' - $c = 'App\\Controller\\'.$entity_type.'Controller'; // instance du controleur + //$c = $this->getControllerInstanceForName($child_entity_type); + $c = $children_controller_instances[$child_entity_type]; + /* + $c = 'App\\Controller\\'.$entity_type.'Controller'; $c = new $c(); + */ // ex: 'catégorie' $et['entity_type_name_singular'] = $c->getTypeNameSingular(); // ex: 'catégories' @@ -2366,7 +2412,8 @@ class AppController extends Controller "$fk_name =" => $id ]); */ - } + } // foreach child + //debug($child_entities_list); exit; //$controller_name = $this->SurCategories->get($id, [ diff --git a/src/Template/Pages/tools.ctp b/src/Template/Pages/tools.ctp index 2fa99cb..f4d4749 100755 --- a/src/Template/Pages/tools.ctp +++ b/src/Template/Pages/tools.ctp @@ -20,8 +20,11 @@ 'action' => 'stats', ]); echo ''; - + echo '