From 01cdc0e9397062c43d7fd43e2007da4c8192c054 Mon Sep 17 00:00:00 2001 From: Patrick Barroca <pbarroca@afi-sa.fr> Date: Wed, 13 Jun 2018 15:38:50 +0200 Subject: [PATCH] dev #75882 add codif section --- .../controllers/SectionBrowserController.php | 27 ++++ .../cosmo/controllers/SectionController.php | 3 +- library/Class/CodifSection.php | 7 +- .../Helper/CodificationListViewMode.php | 8 ++ .../Action/Helper/SectionListViewMode.php | 117 ++++++++++++++++++ .../Controller/Plugin/Manager/Section.php | 3 +- .../Plugin/ResourceDefinition/Abstract.php | 4 +- .../Plugin/ResourceDefinition/Section.php | 24 +++- .../CodificationBrowserTest.php | 14 ++- 9 files changed, 197 insertions(+), 10 deletions(-) create mode 100644 application/modules/admin/controllers/SectionBrowserController.php create mode 100644 library/ZendAfi/Controller/Action/Helper/SectionListViewMode.php diff --git a/application/modules/admin/controllers/SectionBrowserController.php b/application/modules/admin/controllers/SectionBrowserController.php new file mode 100644 index 00000000000..bab89876c21 --- /dev/null +++ b/application/modules/admin/controllers/SectionBrowserController.php @@ -0,0 +1,27 @@ +<?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 Admin_SectionBrowserController extends ZendAfi_Controller_Action { + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Section']; + } +} \ No newline at end of file diff --git a/cosmogramme/cosmozend/application/modules/cosmo/controllers/SectionController.php b/cosmogramme/cosmozend/application/modules/cosmo/controllers/SectionController.php index 12e8d870e21..020c64a76ac 100644 --- a/cosmogramme/cosmozend/application/modules/cosmo/controllers/SectionController.php +++ b/cosmogramme/cosmozend/application/modules/cosmo/controllers/SectionController.php @@ -25,5 +25,4 @@ class Cosmo_SectionController extends ZendAfi_Controller_Action { return ['ZendAfi_Controller_Plugin_ResourceDefinition_Section', 'ZendAfi_Controller_Plugin_Manager_Section']; } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/Class/CodifSection.php b/library/Class/CodifSection.php index 44668b6b3ea..455b21229d8 100644 --- a/library/Class/CodifSection.php +++ b/library/Class/CodifSection.php @@ -56,4 +56,9 @@ class Class_CodifSection extends Storm_Model_Abstract { protected $_table_primary = 'id_section'; protected $_default_attribute_values = ['invisible' => 0]; -} + + + public function getCategorie() { + return; + } +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php b/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php index 9381c4b6aa9..c6c46cc56c2 100644 --- a/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php +++ b/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php @@ -31,15 +31,23 @@ class ZendAfi_Controller_Action_Helper_CodificationListViewMode $this->_categories = [(new Class_CodifAnnexe) ->setLibelle($this->_('Annexes')) ->setController('site-browser'), + (new Class_CodifAuteur) ->setLibelle($this->_('Auteurs')) ->setController('author-browser'), + (new Class_CodifEmplacement) ->setLibelle($this->_('Emplacements')) ->setController('location-browser'), + (new Class_CodifLangue) ->setLibelle($this->_('Langues')) ->setController('language-browser'), + + (new Class_CodifSection) + ->setLibelle($this->_('Sections')) + ->setController('section-browser'), + (new Class_CodifThesaurus) ->setLibelle($this->_('Thesaurus')) ->setController('thesauri')]; diff --git a/library/ZendAfi/Controller/Action/Helper/SectionListViewMode.php b/library/ZendAfi/Controller/Action/Helper/SectionListViewMode.php new file mode 100644 index 00000000000..22a1ed2a558 --- /dev/null +++ b/library/ZendAfi/Controller/Action/Helper/SectionListViewMode.php @@ -0,0 +1,117 @@ +<?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_SectionListViewMode + extends ZendAfi_Controller_Action_Helper_AbstractListViewMode { + + + public function sectionListViewMode($params) { + $this->_params = $params; + return $this; + } + + + public function direct($params) { + return $this->sectionListViewMode($params); + } + + + protected function _describeCategoriesIn($description) { + return $description; + } + + + 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_section']) + ->setSorterServer(); + } + + + public function getBreadcrumb() { + return [['url' => ['module' => 'admin', + 'controller' => 'codification-browser', + 'action' => 'index'], + 'label' => $this->_('Racine'), + 'options' => []], + + ['url' => ['module' => 'admin', + 'controller' => 'section-browser', + 'action' => 'index'], + 'label' => $this->_('Sections'), + '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()]; + + $params = $this->isSearching() + ? $this->getSearchParams() + : []; + + return Class_CodifSection::findAllBy(array_merge($params, $default_params)); + } + + + public function getSearchColumns() { + return ['libelle', + 'id_section']; + } + + + protected function enabledSorter() { + return false; + } + + + public function countItemsFor($model) { + return Class_CodifSection::count(); + } + + + public function getCountSearchResult() { + $params = array_merge($this->getItemsParams(), + $this->getSearchParams()); + unset($params['limitPage']); + return Class_CodifSection::countBy($params); + } + + + public function getOrder() { + return $this->getParam('order', 'libelle'); + } +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Section.php b/library/ZendAfi/Controller/Plugin/Manager/Section.php index f9b4ade6e03..2d6b5f38e7b 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Section.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Section.php @@ -32,5 +32,4 @@ class ZendAfi_Controller_Plugin_Manager_Section extends ZendAfi_Controller_Plugi 'icon' => 'delete', 'label' => $this->_('Supprimer')]]; } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php index ba5a03a9fc4..22cb953b84a 100644 --- a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php @@ -315,7 +315,9 @@ abstract class ZendAfi_Controller_Plugin_ResourceDefinition_Abstract extends Zen protected function _isListViewModeEnabled() { - return isset($this->_attribs['listViewMode']) && $this->_attribs['listViewMode']; + return isset($this->_attribs['listViewMode']) + && $this->_attribs['listViewMode'] + && ('cosmo' != $this->_request->getModuleName()); } diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php index a9000b9070d..a4ad419222a 100644 --- a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php @@ -28,11 +28,31 @@ class ZendAfi_Controller_Plugin_ResourceDefinition_Section extends ZendAfi_Contr 'order' => 'libelle', 'model_id' => 'id_section'], + 'listViewMode' => ['helper_method' => 'sectionListViewMode'], + 'messages' => ['successful_save' => $this->_('La section "%s" a été modifée'), 'successful_add' => $this->_('La section "%s" a été ajoutée'), 'successful_delete' => $this->_('La section "%s" a été suppriméee')], 'form_class_name' => 'ZendAfi_Form_Admin_Section']; } -} -?> \ No newline at end of file + + + public function getActions($model) { + if( (!$model) || ('cosmo' == $this->_request->getModuleName())) + return []; + + return [ + ['url' => $this->_view->url(['module' => 'opac', + 'controller' => 'recherche', + 'action' => 'simple', + 'facette' => $model->getFacetCode() + ], + null, + true), + 'icon' => 'view', + 'label' => $this->_('Voir les documents qui ont la facette "%s"',$model->getFacetCode()), + 'anchorOptions' => ['target' => '_blank'] + ]]; + } +} \ No newline at end of file diff --git a/tests/scenarios/CodificationBrowser/CodificationBrowserTest.php b/tests/scenarios/CodificationBrowser/CodificationBrowserTest.php index 21ac4785335..a82df21899d 100644 --- a/tests/scenarios/CodificationBrowser/CodificationBrowserTest.php +++ b/tests/scenarios/CodificationBrowser/CodificationBrowserTest.php @@ -36,7 +36,8 @@ class CodificationBrowserIndexDispatchTest extends Admin_AbstractControllerTestC ['author-browser', 'Auteurs'], ['location-browser', 'Emplacements'], ['site-browser', 'Annexes'], - ['language-browser', 'Langues']]; + ['language-browser', 'Langues'], + ['section-browser', 'Sections']]; } @@ -141,5 +142,14 @@ class CodificationBrowserLanguageSimpleIndexTest extends CodificationBrowserSimp protected $_controller = 'language-browser', $_model = 'Class_CodifLangue', - $_attribs = ['id' => 6, 'libelle' => 'MySuperLangue', 'regles' => '784$v=TOTO']; + $_attribs = ['id' => 6, 'libelle' => 'MySuperLangue']; +} + + + +class CodificationBrowserSectionSimpleIndexTest extends CodificationBrowserSimpleIndexTestCase { + protected + $_controller = 'section-browser', + $_model = 'Class_CodifSection', + $_attribs = ['id' => 6, 'libelle' => 'MySuperSection', 'regles' => '784$v=TOTO']; } -- GitLab