diff --git a/application/modules/admin/controllers/LocationBrowserController.php b/application/modules/admin/controllers/LocationBrowserController.php new file mode 100644 index 0000000000000000000000000000000000000000..a24e22fb1e6b6311f4726fc92a567981f32d8fdf --- /dev/null +++ b/application/modules/admin/controllers/LocationBrowserController.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_LocationBrowserController extends ZendAfi_Controller_Action { + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Location']; + } +} \ No newline at end of file diff --git a/library/Class/CodifEmplacement.php b/library/Class/CodifEmplacement.php index 6a41ed65f4885669503a5e454291ed1d226f5cc6..32bbeacbf6ad89bf165c2c2e61f4fbcd75325915 100644 --- a/library/Class/CodifEmplacement.php +++ b/library/Class/CodifEmplacement.php @@ -23,10 +23,13 @@ class Class_CodifEmplacement extends Storm_Model_Abstract { use Trait_Facetable; const CODE_FACETTE = 'E'; + protected $_table_name = 'codif_emplacement'; protected $_table_primary = 'id_emplacement'; - protected $_default_attribute_values = ['ne_pas_afficher' => 0]; + protected $_default_attribute_values = ['libelle' => '', + 'ne_pas_afficher' => 0, + 'regles' => '',]; public function isVisible() { @@ -64,5 +67,9 @@ class Class_CodifEmplacement extends Storm_Model_Abstract { 'Signe de comparaison incorrect pour la règle ' . $regle); } } -} -?> + + + public function getCategorie() { + return; + } +} \ No newline at end of file diff --git a/library/Class/CodifThesaurus.php b/library/Class/CodifThesaurus.php index 54a39f794fcd63e3d82c62c3cb1b24cddf4f2b1e..664251d272804d027efda61a2f75fb9b2ace86ff 100644 --- a/library/Class/CodifThesaurus.php +++ b/library/Class/CodifThesaurus.php @@ -457,7 +457,7 @@ class CodifThesaurusLoader extends Storm_Model_Loader { class Class_CodifThesaurus extends Storm_Model_Abstract { - use Trait_Translator, Trait_MemoryCleaner; + use Trait_Translator, Trait_MemoryCleaner, Trait_Facetable; const CODE_ROOT = 'root', @@ -488,6 +488,11 @@ class Class_CodifThesaurus extends Storm_Model_Abstract { } + public function asFacet() { + return $this->getFacetteIndex(); + } + + public function getFacetteIndex() { return self::CODE_FACETTE . $this->getIdThesaurus(); } diff --git a/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php b/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php index d70b4010a5dc7848355bf1c2244ecee332cff822..c026246b7ec0b66d300e9cdb08f29ce262f14242 100644 --- a/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php +++ b/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php @@ -64,8 +64,11 @@ class ZendAfi_Controller_Action_Helper_CodificationListViewMode extends ZendAfi_ public function getCategories() { - return [(new Class_CodifThesaurus)->setLibelle($this->_('Thesaurus')), - (new Class_CodifAuteur)->setLibelle($this->_('Auteurs'))]; + return [ + (new Class_CodifAuteur)->setLibelle($this->_('Auteurs')), + (new Class_CodifEmplacement)->setLibelle($this->_('Emplacements')), + (new Class_CodifThesaurus)->setLibelle($this->_('Thesaurus')), + ]; } @@ -86,6 +89,10 @@ class ZendAfi_Controller_Action_Helper_CodificationListViewMode extends ZendAfi_ return ['module' => 'admin', 'controller' => 'author-browser']; + if($model instanceof Class_CodifEmplacement) + return ['module' => 'admin', + 'controller' => 'location-browser']; + return []; } } \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/Helper/LocationListViewMode.php b/library/ZendAfi/Controller/Action/Helper/LocationListViewMode.php new file mode 100644 index 0000000000000000000000000000000000000000..421024b7167158e90a6a9019379fbd1ebd4cc4bb --- /dev/null +++ b/library/ZendAfi/Controller/Action/Helper/LocationListViewMode.php @@ -0,0 +1,116 @@ +<?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_LocationListViewMode extends ZendAfi_Controller_Action_Helper_AbstractListViewMode { + + + public function locationListViewMode($params) { + $this->_params = $params; + return $this; + } + + + public function direct($params) { + return $this->locationListViewMode($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_emplacement']) + ->setSorterServer(); + } + + + public function getBreadcrumb() { + return [['url' => ['module' => 'admin', + 'controller' => 'codification-browser', + 'action' => 'index'], + 'label' => $this->_('Racine'), + 'options' => []], + + ['url' => ['module' => 'admin', + 'controller' => 'location-browser', + 'action' => 'index'], + 'label' => $this->_('Emplacements'), + 'options' => []]]; + } + + + public function getBaseUrl() { + return ['module' => 'admin', + 'controller' => 'location-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_CodifEmplacement::findAllBy(array_merge($params, $default_params)); + } + + + public function getSearchColumns() { + return ['libelle', + 'id_emplacement']; + } + + + protected function enabledSorter() { + return false; + } + + + public function countItemsFor($model) { + return Class_CodifEmplacement::count(); + } + + + public function getCountSearchResult() { + $params = array_merge($this->getItemsParams(), + $this->getSearchParams()); + unset($params['limitPage']); + return Class_CodifEmplacement::countBy($params); + } + + + public function getOrder() { + return $this->getParam('order', 'libelle'); + } +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Location.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Location.php new file mode 100644 index 0000000000000000000000000000000000000000..6507d607b625fa06f665faf77c43067f5b6a48be --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Location.php @@ -0,0 +1,53 @@ +<?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_Plugin_ResourceDefinition_Location extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return + ['model' => ['class' => 'Class_CodifEmplacement', + 'name' => 'location', + 'order' => 'libelle'], + + 'listViewMode' => ['helper_method' => 'locationListViewMode'], + + 'actions' => ['index' => ['title' => $this->_('Parcourir les emplacements')]]]; + } + + + public function getActions($model) { + if(!$model) + 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 9210835c9e89977748f4943eb17d036654264918..ec82586ee12e2bc3a73759690106c1b4aca000b4 100644 --- a/tests/scenarios/CodificationBrowser/CodificationBrowserTest.php +++ b/tests/scenarios/CodificationBrowser/CodificationBrowserTest.php @@ -31,20 +31,88 @@ class CodificationBrowserIndexDispatchTest extends Admin_AbstractControllerTestC } + public function datas() { + return [['thesauri', 'Thesaurus'], + ['author-browser', 'Auteurs'], + ['location-browser', 'Emplacements']]; + } + + + /** + * @test + * @dataProvider datas + */ + public function categoriesShouldBeInTable($controller, $label) { + $this->assertXPathContentContains('//td//a[@href="/admin/' . $controller . '"]', $label); + } + + /** @test */ public function rootShouldBeInBreadcrumb() { $this->assertXPathContentContains('//a[@href="/admin/codification-browser"]', 'Racine'); } +} + + + +abstract class CodificationBrowserSimpleIndexTestCase extends Admin_AbstractControllerTestCase { + + protected + $_storm_default_to_volatile = true, + $_item, + $_model, $_attribs, $_controller; + + public function setUp() { + parent::setUp(); + Class_AdminVar::set('THESAURI_BROWSER', 1); + + $this->_item = $this->fixture($this->_model, $this->_attribs); + $this->dispatch('/admin/' . $this->_controller, true); + } /** @test */ - public function thesaurusShouldBeInTable() { - $this->assertXPathContentContains('//td//a[@href="/admin/thesauri"]', 'Thesaurus'); + public function rootShouldBeInBreadcrumb() { + $this->assertXPathContentContains('//a[@href="/admin/codification-browser"]', 'Racine'); } /** @test */ - public function authorsShouldBeInTable() { - $this->assertXPathContentContains('//td//a[@href="/admin/author-browser"]', 'Auteurs'); + public function itemShouldBeInTable() { + $this->assertXPathContentContains('//td', $this->_item->getFacetCode(), $this->_response->getBody()); } -} \ No newline at end of file + + + /** @test */ + public function itemHasMethodGetCategorie() { + $this->_item->getCategorie(); + } +} + + + +class CodificationBrowserAuthorSimpleIndexTest extends CodificationBrowserSimpleIndexTestCase { + protected + $_controller = 'author-browser', + $_model = 'Class_CodifAuteur', + $_attribs = ['id' => 3]; +} + + + +class CodificationBrowserThesauriSimpleIndexTest extends CodificationBrowserSimpleIndexTestCase { + protected + $_controller = 'thesauri', + $_model = 'Class_CodifThesaurus', + $_attribs = ['id' => 4, + 'libelle' => 'MySuperDomain', + 'id_thesaurus' => 'CCCC0004']; +} + + +class CodificationBrowserLocationSimpleIndexTest extends CodificationBrowserSimpleIndexTestCase { + protected + $_controller = 'location-browser', + $_model = 'Class_CodifEmplacement', + $_attribs = ['id' => 5, 'libelle' => 'MySuperLocation', 'regles' => '784$v=TOTO']; +}