From 17cf1088fae855fdcfeaacc66c5494f7679285ee Mon Sep 17 00:00:00 2001 From: Patrick Barroca <pbarroca@afi-sa.fr> Date: Thu, 14 Jun 2018 10:05:52 +0200 Subject: [PATCH] dev #75882 refacto flat codification list view mode --- ...p => AbstractCodificationListViewMode.php} | 57 +++++++++++-------- .../Helper/FlatCodificationListViewMode.php | 36 ++++++++++++ .../Action/Helper/LocationListViewMode.php | 3 +- .../Plugin/ResourceDefinition/Abstract.php | 12 +++- .../Plugin/ResourceDefinition/Section.php | 4 +- 5 files changed, 86 insertions(+), 26 deletions(-) rename library/ZendAfi/Controller/Action/Helper/{SectionListViewMode.php => AbstractCodificationListViewMode.php} (70%) create mode 100644 library/ZendAfi/Controller/Action/Helper/FlatCodificationListViewMode.php diff --git a/library/ZendAfi/Controller/Action/Helper/SectionListViewMode.php b/library/ZendAfi/Controller/Action/Helper/AbstractCodificationListViewMode.php similarity index 70% rename from library/ZendAfi/Controller/Action/Helper/SectionListViewMode.php rename to library/ZendAfi/Controller/Action/Helper/AbstractCodificationListViewMode.php index 22a1ed2a558..dfedcff9817 100644 --- a/library/ZendAfi/Controller/Action/Helper/SectionListViewMode.php +++ b/library/ZendAfi/Controller/Action/Helper/AbstractCodificationListViewMode.php @@ -20,18 +20,25 @@ */ -class ZendAfi_Controller_Action_Helper_SectionListViewMode +abstract class ZendAfi_Controller_Action_Helper_AbstractCodificationListViewMode extends ZendAfi_Controller_Action_Helper_AbstractListViewMode { + protected $_model_class; - public function sectionListViewMode($params) { + + protected function _initParams($params) { $this->_params = $params; - return $this; + $this->_model_class = get_class($this->getModel()); + } + + + protected function _getBreadcrumbLabel() { + return $this->_params['label']; } - public function direct($params) { - return $this->sectionListViewMode($params); + protected function _getControllerName() { + return $this->_params['controller']; } @@ -40,6 +47,11 @@ class ZendAfi_Controller_Action_Helper_SectionListViewMode } + protected function _callOnLoader($method, $params=[]) { + return call_user_func_array([$this->_model_class, $method], $params); + } + + protected function _describeItemsIn($description) { return $description ->addColumn($this->_('Libellé'), ['attribute' => 'libelle', @@ -47,8 +59,9 @@ class ZendAfi_Controller_Action_Helper_SectionListViewMode { return $this->_renderItem($model, $attrib); }]) - ->addColumn($this->_('Code facette'), ['attribute' => 'facet_code', - 'sort_attribute' => 'id_section']) + ->addColumn($this->_('Code facette'), + ['attribute' => 'facet_code', + 'sort_attribute' => $this->_callOnLoader('getIdField')]) ->setSorterServer(); } @@ -60,21 +73,12 @@ class ZendAfi_Controller_Action_Helper_SectionListViewMode 'label' => $this->_('Racine'), 'options' => []], - ['url' => ['module' => 'admin', - 'controller' => 'section-browser', - 'action' => 'index'], - 'label' => $this->_('Sections'), + ['url' => $this->getBaseUrl(), + 'label' => $this->_getBreadcrumbLabel(), 'options' => []]]; } - public function getBaseUrl() { - return ['module' => 'admin', - 'controller' => 'section-browser', - 'action' => 'index']; - } - - public function getItems() { $default_params = ['limitPage' => [$this->getPage(), $this->_items_by_page], 'order' => $this->getOrder()]; @@ -83,13 +87,12 @@ class ZendAfi_Controller_Action_Helper_SectionListViewMode ? $this->getSearchParams() : []; - return Class_CodifSection::findAllBy(array_merge($params, $default_params)); + return $this->_callOnLoader('findAllBy', [array_merge($params, $default_params)]); } public function getSearchColumns() { - return ['libelle', - 'id_section']; + return ['libelle', $this->_callOnLoader('getIdField')]; } @@ -99,7 +102,7 @@ class ZendAfi_Controller_Action_Helper_SectionListViewMode public function countItemsFor($model) { - return Class_CodifSection::count(); + return $this->_callOnLoader('count'); } @@ -107,11 +110,19 @@ class ZendAfi_Controller_Action_Helper_SectionListViewMode $params = array_merge($this->getItemsParams(), $this->getSearchParams()); unset($params['limitPage']); - return Class_CodifSection::countBy($params); + + return $this->_callOnLoader('countBy', [$params]); } public function getOrder() { return $this->getParam('order', 'libelle'); } + + + public function getBaseUrl() { + return ['module' => 'admin', + 'controller' => $this->_getControllerName(), + 'action' => 'index']; + } } \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/Helper/FlatCodificationListViewMode.php b/library/ZendAfi/Controller/Action/Helper/FlatCodificationListViewMode.php new file mode 100644 index 00000000000..9c50141ec51 --- /dev/null +++ b/library/ZendAfi/Controller/Action/Helper/FlatCodificationListViewMode.php @@ -0,0 +1,36 @@ +<?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_FlatCodificationListViewMode + extends ZendAfi_Controller_Action_Helper_AbstractCodificationListViewMode { + + + public function flatCodificationListViewMode($params) { + $this->_initParams($params); + return $this; + } + + + public function direct($params) { + return $this->flatCodificationListViewMode($params); + } +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/Helper/LocationListViewMode.php b/library/ZendAfi/Controller/Action/Helper/LocationListViewMode.php index 421024b7167..49d57b0d9b4 100644 --- a/library/ZendAfi/Controller/Action/Helper/LocationListViewMode.php +++ b/library/ZendAfi/Controller/Action/Helper/LocationListViewMode.php @@ -20,7 +20,8 @@ */ -class ZendAfi_Controller_Action_Helper_LocationListViewMode extends ZendAfi_Controller_Action_Helper_AbstractListViewMode { +class ZendAfi_Controller_Action_Helper_LocationListViewMode + extends ZendAfi_Controller_Action_Helper_AbstractListViewMode { public function locationListViewMode($params) { diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php index 22cb953b84a..ec7b6961b84 100644 --- a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php @@ -307,10 +307,20 @@ abstract class ZendAfi_Controller_Plugin_ResourceDefinition_Abstract extends Zen ? call_user_func($this->_attribs['listViewMode']['model']) : new $model_class; + $controller_name = (isset($this->_attribs['listViewMode']['controller'])) + ? $this->_attribs['listViewMode']['controller'] + : ''; + + $breadcrumb_label = (isset($this->_attribs['listViewMode']['label'])) + ? $this->_attribs['listViewMode']['label'] + : ''; + return $this->_helper->$listViewMode(['model' => $model, 'order' => $this->_getParam('order'), 'page' => $this->_getParam('page', 0), - 'search_value' => $this->_getParam('title_search', '')]); + 'search_value' => $this->_getParam('title_search', ''), + 'controller' => $controller_name, + 'label' => $breadcrumb_label]); } diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php index a4ad419222a..280f17bd1dd 100644 --- a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php @@ -28,7 +28,9 @@ class ZendAfi_Controller_Plugin_ResourceDefinition_Section extends ZendAfi_Contr 'order' => 'libelle', 'model_id' => 'id_section'], - 'listViewMode' => ['helper_method' => 'sectionListViewMode'], + 'listViewMode' => ['helper_method' => 'flatCodificationListViewMode', + 'label' => $this->_('Sections'), + 'controller' => 'section-browser'], 'messages' => ['successful_save' => $this->_('La section "%s" a été modifée'), 'successful_add' => $this->_('La section "%s" a été ajoutée'), -- GitLab