diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index 7b0f4b7db62178337fc04661ffea68fbe414fa23..6d822fe0d1030d4f00d2b21fa2672ad6fa913ebb 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -1342,13 +1342,42 @@ class Class_Catalogue extends Storm_Model_Abstract { } - public function getCategorie() { - return $this->getParent(); + public function getNodes() { + return $this->getLoader()->findParentChildrenOf($this); } - public function getParentChildren() { - return Class_Catalogue::getLoader()->findParentChildrenOf($this); + public function getLeaves($params) { + $params['parent_id'] = $this->isNew() ? null : $this->getId(); + $models = $this->getLoader()->findAllBy($params); + + return array_filter($models, + function($model) { return !$model->hasSousDomaines(); }); + } + + + public function numberOfLeaves() { + $models = $this->getSousDomaines(); + + $models = array_filter($models, + function($model) { return !$model->hasSousDomaines(); }); + + return count($models); + } + + + public function recursiveNumberOfChildren() { + return $this->numberOfSousDomaines() + + $this->countItemsInChildrenOf($this); + } + + + public function countItemsInChildrenOf($model) { + $count = 0; + foreach($model->getSousDomaines() as $domain) + $count += $domain->recursiveNumberOfChildren(); + + return $count; } } diff --git a/library/Class/CodifThesaurus.php b/library/Class/CodifThesaurus.php index ec9cd14fc9054e4a990471846b40bf3ff7c62595..5d137cb52aa595d4a20776ae9907cf720b82ce69 100644 --- a/library/Class/CodifThesaurus.php +++ b/library/Class/CodifThesaurus.php @@ -140,14 +140,13 @@ class CodifThesaurusLoader extends Storm_Model_Loader { } - public function findChildrenOfWith($id_thesaurus, $page, $items_by_page, $order) { + public function findChildrenOfWith($id_thesaurus, $limit, $order) { $where = sprintf('id_thesaurus like "%s%%" and LENGTH(id_thesaurus) = %s', $id_thesaurus, (strlen($id_thesaurus) + 4)); return Class_CodifThesaurus::findAllBy(['where' => $where, - 'limitPage' => [$page, - $items_by_page], + 'limitPage' => $limit, 'order' => $order]); } @@ -668,9 +667,8 @@ class Class_CodifThesaurus extends Storm_Model_Abstract { return []; return $this->getLoader()->findChildrenOfWith($this->getIdThesaurus(), - $params[0], - $params[1], - $params[2]); + $params['limitPage'], + $params['order']); } diff --git a/library/Class/ListViewModeDescription.php b/library/Class/ListViewModeDescription.php new file mode 100644 index 0000000000000000000000000000000000000000..7554196647a0c37230cdcfec75049719201036ec --- /dev/null +++ b/library/Class/ListViewModeDescription.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +abstract class Class_ListViewModeDescription { + use Trait_Translator; + + protected $_context; + + public function __construct($context) { + $this->_context = $context; + } + + + public function render() { + $helper = $this->_context->getHelper(); + $params = ['order' => $this->_context->getOrder(), + 'page' => $this->_context->getPage(), + 'search_value' => $this->_context->getSearchValue(), + + 'controller' => $this->_getController(), + 'label' => $this->_getLabel(), + + 'model' => $this->_getModel(), + 'search_columns' => $this->_getSearchColumns(), + 'categories_description' => [$this, 'describeCategoriesIn'], + 'items_description' => [$this, 'describeItemsIn']]; + + return $helper->treeCodificationListViewMode($params); + } + + + abstract protected function _getModel(); + abstract protected function _getLabel(); + abstract protected function _getController(); + abstract protected function _getSearchColumns(); + abstract public function describeCategoriesIn($description, $list_view_mode); + abstract public function describeItemsIn($description, $list_view_mode); +} diff --git a/library/Class/ListViewModeDescription/Domain.php b/library/Class/ListViewModeDescription/Domain.php new file mode 100644 index 0000000000000000000000000000000000000000..19d5ef3ff7d29e1d129b95efd455759b9a1dbac3 --- /dev/null +++ b/library/Class/ListViewModeDescription/Domain.php @@ -0,0 +1,65 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_ListViewModeDescription_Domain extends Class_ListViewModeDescription { + + protected function _getLabel() { + return $this->_('Domaines pour sélections'); + } + + + protected function _getController() { + return 'domain-browser'; + } + + + protected function _getModel() { + return ($parent_id = $this->_context->getParentId()) + ? Class_Catalogue::find($parent_id) + : new Class_Catalogue; + } + + + protected function _getSearchColumns() { + return ['libelle', + 'id_catalogue']; + } + + + public function describeCategoriesIn($description, $list_view_mode) { + return $description + ->addColumn($this->_('Libellé'), ['attribute' => 'libelle', + 'callback' => $list_view_mode->renderCategoryClosure()]) + ->addColumn($this->_('Code facette'), ['attribute' => 'facet_code', + 'sort_attribute' => 'id_catalogue']); + } + + + public function describeItemsIn($description, $list_view_mode) { + return $description + ->addColumn($this->_('Libellé'), ['attribute' => 'libelle', + 'callback' => $list_view_mode->renderItemClosure()]) + ->addColumn($this->_('Code facette'), ['attribute' => 'facet_code', + 'sort_attribute' => 'id_catalogue']) + ->setSorterServer(); + } +} \ No newline at end of file diff --git a/library/Class/ListViewModeDescription/Thesauri.php b/library/Class/ListViewModeDescription/Thesauri.php index c175457defd48f06bb6be7ff3ebd0ca2d56c9744..f3b71ba93517f4649aee499cd6d7430a6ac0597c 100644 --- a/library/Class/ListViewModeDescription/Thesauri.php +++ b/library/Class/ListViewModeDescription/Thesauri.php @@ -1,4 +1,4 @@ -2<?php +<?php /** * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. * @@ -20,31 +20,15 @@ */ -class Class_ListViewModeDescription_Thesauri { - use Trait_Translator; +class Class_ListViewModeDescription_Thesauri extends Class_ListViewModeDescription { - protected $_context; - - public function __construct($context) { - $this->_context = $context; + protected function _getLabel() { + return $this->_('Thesaurus'); } - public function render() { - $helper = $this->_context->getHelper(); - $params = ['order' => $this->_context->getOrder(), - 'page' => $this->_context->getPage(), - 'search_value' => $this->_context->getSearchValue(), - - 'controller' => 'thesauri', - 'label' => $this->_('Thesaurus'), - - 'model' => $this->_getModel(), - 'search_columns' => $this->_getSearchColumns(), - 'categories_description' => [$this, 'describeCategoriesIn'], - 'items_description' => [$this, 'describeItemsIn']]; - - return $helper->treeCodificationListViewMode($params); + protected function _getController() { + return 'thesauri'; } diff --git a/library/ZendAfi/Controller/Action/Helper/DomainListViewMode.php b/library/ZendAfi/Controller/Action/Helper/DomainListViewMode.php deleted file mode 100644 index ddfa81b579a8fdf2b17147619128b69387cb9b4c..0000000000000000000000000000000000000000 --- a/library/ZendAfi/Controller/Action/Helper/DomainListViewMode.php +++ /dev/null @@ -1,165 +0,0 @@ -<?php -/** - * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. - * - * BOKEH is free software; you can redistribute it and/or modify - * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by - * the Free Software Foundation. - * - * There are special exceptions to the terms and conditions of the AGPL as it - * is applied to this software (see README file). - * - * BOKEH is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE - * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -class ZendAfi_Controller_Action_Helper_DomainListViewMode - extends ZendAfi_Controller_Action_Helper_AbstractListViewMode { - - - public function domainListViewMode($params) { - $this->_params = $params; - return $this; - } - - - public function direct($params) { - return $this->domainListViewMode($params); - } - - - protected function _describeCategoriesIn($description) { - return $description - ->addColumn($this->_('Libellé'), ['attribute' => 'libelle', - 'callback' => function($model, $attrib) - { - return $this->_renderCategory($model, $attrib); - }]) - ->addColumn($this->_('Code facette'), ['attribute' => 'facet_code', - 'sort_attribute' => 'id_catalogue']) - ; - } - - - protected function _describeItemsIn($description) { - return $description - ->addColumn($this->_('Libellé'), ['attribute' => 'libelle', - 'callback' => function($model, $attrib) - { - return $this->_renderItem($model, $attrib); - }]) - ->addColumn($this->_('Code facette'), ['attribute' => 'facet_code', - 'sort_attribute' => 'id_catalogue']) - ->setSorterServer(); - } - - - public function getBreadcrumb() { - $breadcrumb = [['url' => ['module' => 'admin', - 'controller' => 'codification-browser', - 'action' => 'index'], - 'label' => $this->_('Racine'), - 'options' => []], - - ['url' => ['module' => 'admin', - 'controller' => 'domain-browser', - 'action' => 'index'], - 'label' => $this->_('Domains'), - 'options' => []]]; - - if($this->getModel()->isNew()) - return $breadcrumb; - - return array_merge($breadcrumb, - $this->getBreadcrumbFor($this->getModel())); - } - - - public function getBaseUrl() { - return ['module' => 'admin', - 'controller' => 'domain-browser', - 'action' => 'index']; - } - - - public function getCategories() { - return $this->getModel()->getParentChildren(); - } - - - public function getItems() { - $default_params = ['limitPage' => [$this->getPage(), $this->_items_by_page], - 'order' => $this->getOrder()]; - - if ($this->isSearching()) - return Class_Catalogue::findAllBy(array_merge($this->getSearchParams(), $default_params)); - - $params = []; - - $params['parent_id'] = $this->getModel()->isNew() - ? null - : $this->getModel()->getId(); - - $models = Class_Catalogue::findAllBy(array_merge($params, $default_params)); - - return array_filter($models, - function($model) { return !$model->hasSousDomaines(); }); - } - - - public function getSearchColumns() { - return ['libelle', - 'id_catalogue']; - } - - - protected function enabledSorter() { - return false; - } - - - public function countItemsFor($model) { - return $model->numberOfSousDomaines(); - } - - - public function countItemsInTreeFrom($model) { - if (!$model) - return 0; - - return $model->numberOfSousDomaines() - + $this->countItemsInChildrenOf($model); - } - - - protected function countItemsInChildrenOf($model) { - if (!$model) - return 0; - - $count = 0; - foreach($model->getSousDomaines() as $child) - $count += $this->countItemsInTreeFrom($child); - - return $count; - } - - - public function getCountSearchResult() { - $params = array_merge($this->getItemsParams(), - $this->getSearchParams()); - unset($params['limitPage']); - return Class_Catalogue::countBy($params); - } - - - public function getOrder() { - return $this->getParam('order', 'libelle'); - } -} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/Helper/TreeCodificationListViewMode.php b/library/ZendAfi/Controller/Action/Helper/TreeCodificationListViewMode.php index 2b0233783aacbbbee43de47c7a78595997900ba9..5f05cd0f4090cce59a853ae7de0f8ae8a4829335 100644 --- a/library/ZendAfi/Controller/Action/Helper/TreeCodificationListViewMode.php +++ b/library/ZendAfi/Controller/Action/Helper/TreeCodificationListViewMode.php @@ -47,9 +47,8 @@ class ZendAfi_Controller_Action_Helper_TreeCodificationListViewMode extends Zend public function getItems() { $model = $this->getModel(); - $params = [$this->getPage(), - $this->_items_by_page, - $this->getOrder()]; + $params = ['limitPage' => [$this->getPage(), $this->_items_by_page], + 'order' => $this->getOrder()]; return $this->isSearching() ? $this->_callOnLoader('findAllBy', [$this->getItemsParams()]) diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Domain.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Domain.php index cf1ab6644d798e2cad258b6ccc1e81458be36671..838a0283cd2986170d6bb43302c3c518d03ace54 100644 --- a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Domain.php +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Domain.php @@ -28,13 +28,7 @@ class ZendAfi_Controller_Plugin_ResourceDefinition_Domain 'name' => 'domain', 'order' => 'libelle'], - 'listViewMode' => ['helper_method' => 'domainListViewMode', - 'model' => function() - { - return $this->_getParam('id') - ? Class_Catalogue::find($this->_getParam('id')) - : new Class_Catalogue; - }]]; + 'listViewMode' => 'Class_ListViewModeDescription_Domain']; }