diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php index d54f185fcd6da7ac3a15779a265287f1bc25bee1..d7c98e3ecdd1d4ef17e9703d7594f859746e19fc 100644 --- a/application/modules/admin/controllers/CmsController.php +++ b/application/modules/admin/controllers/CmsController.php @@ -65,7 +65,8 @@ class Admin_CmsController extends ZendAfi_Controller_Action { protected function _renderList() { $bibs = $this->_getBibs(); - $ids = array_map(function($model) {return $model->getId();}, $bibs); + $ids = array_map(function($model) { return $model->getId(); }, $bibs); + $search = $this->_getParam('title_search', ''); $id_bib = $this->_getParam('id_bib', $this->identity->isRoleLibraryLimited() @@ -73,30 +74,33 @@ class Admin_CmsController extends ZendAfi_Controller_Action { : null); $id_cat = $this->_getParam('id_cat', 0); - $params = ($id_bib && in_array($id_bib, $ids)) || $id_cat || ($id_bib == '0') || ($search) - ? ['model' => Class_ArticleCategorie::find($id_cat), - 'strategy_label' => 'article'] - : ['model' => null, - 'strategy_label' => 'bib', - 'bibs' => $bibs]; + $params = ['page' => $this->_getParam('page', 0), + 'search_value' => $search, + 'bib' => $this->_bib, + 'id_bib' => $id_bib, + 'id_cat' => $id_cat]; + + if (($id_bib && in_array($id_bib, $ids)) || $id_cat || ($id_bib == '0') || ($search)) { + $params['model'] = Class_ArticleCategorie::find($id_cat); + $params['strategy_label'] = 'article'; + $this->view->list = $this->_helper->listViewMode($params); - $this->view->list = $this->_helper->listViewMode(array_merge(['page' => $this->_getParam('page', 0), - 'search_value' => $search, - 'bib' => $this->_bib, - 'id_bib' => $id_bib, - 'id_cat' => $id_cat], - $params)); + return $this->renderScript('admin/listViewMode.phtml'); + } - return $this->getHelper('ViewRenderer')->renderScript('admin/listViewMode.phtml'); + $params['model'] = null; + $params['bibs'] = $bibs; + $this->view->list = $this->_helper->bibListViewMode($params); + + return $this->renderScript('admin/listViewMode.phtml'); } public function indexAction() { $this->view->titre = $this->view->_('Articles'); - if (Class_AdminVar::isArticlesListMode()) { + if (Class_AdminVar::isArticlesListMode()) return $this->_renderList(); - } $bibs = $this->_getBibs(); diff --git a/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php b/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php index d051495d8c83e5138fca4a5d304e4585d8a7e5c1..6802e5fd633745a464ece88b172271354a933226 100644 --- a/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php +++ b/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php @@ -21,13 +21,7 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zend_Controller_Action_Helper_Abstract { protected - $_model, $_params, - $_page, - $_search, - $_strategy, - $_categories = [], - $_items = [], $_items_paginator, $_breadcrumb, $_items_by_page = 25; @@ -58,13 +52,15 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen public function getUrlParams($model) { - $params = ($start_cat = $this->getRequestParam('start_cat')) ? - ['start_cat'=> $start_cat] : []; - - return array_merge($params, + return array_merge($this->getStartParams(), $this->getBaseUrl(), [$this->getParamKey() => $model->getId()]); + } + + protected function getStartParams() { + return ($start_cat = $this->getRequestParam('start_cat')) ? + ['start_cat'=> $start_cat] : []; } @@ -78,6 +74,11 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen } + public function getCategoriesGroupBy() { + return null; + } + + public function getItems() { return []; } @@ -115,7 +116,9 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen && $parent = $model->getParentCategorie()) $breadcrumb = $this->getBreadcrumbFor($parent, $breadcrumb, $start_key); - $breadcrumb[] = ['url' => array_merge($this->getBreadcrumbUrl(),[$this->getParamKey() => $model->getId()]), + $breadcrumb[] = ['url' => array_merge($this->getBreadcrumbUrl(), + $this->getStartParams(), + [$this->getParamKey() => $model->getId()]), 'label' => $model->getLibelle(), 'options' => []]; @@ -174,7 +177,7 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen public function getModel() { - return $this->_model; + return $this->getParam('model'); } @@ -183,23 +186,29 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen } + public function getParam($name, $default=null) { + return array_key_exists($name, $this->_params) ? + $this->_params[$name] : $default; + } + + public function getPage() { - return $this->_page; + return $this->getParam('page'); } public function getSearch() { - return $this->_search; + return $this->getSearchValue(); } public function getModelId() { - return $this->_model ? $this->_model->getId() : 0; + return ($model = $this->getModel()) ? $model->getId() : 0; } public function getSearchValue() { - return $this->_search; + return $this->getParam('search_value'); } diff --git a/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy/Bib.php b/library/ZendAfi/Controller/Action/Helper/BibListViewMode.php similarity index 77% rename from library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy/Bib.php rename to library/ZendAfi/Controller/Action/Helper/BibListViewMode.php index f2f3acbfcc14bce3c9c222ae7e2e7b77e3c9f365..3e2618fc281baceecc2429276ca1b4ff894b5bfd 100644 --- a/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy/Bib.php +++ b/library/ZendAfi/Controller/Action/Helper/BibListViewMode.php @@ -20,7 +20,20 @@ */ -class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Bib extends ZendAfi_Controller_Action_Helper_ListViewMode_Strategy { +class ZendAfi_Controller_Action_Helper_BibListViewMode extends ZendAfi_Controller_Action_Helper_AbstractListViewMode { + use Trait_Translator; + + public function bibListViewMode($params) { + $this->_params = $params; + return $this; + } + + + public function direct($params) { + return $this->bibListViewMode($params); + } + + public function getBaseUrl() { return ['module' => 'admin', 'controller' => 'cms']; @@ -32,14 +45,13 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Bib extends ZendAfi } - public function getParamKey() { return 'id_bib'; } public function getCategories() { - return $this->_visitor->getParams()['bibs']; + return $this->getParam('bibs', []); } @@ -59,8 +71,7 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Bib extends ZendAfi } - public function getItemsPaginator() { - return null; + public function getStrategyLabel() { + return 'bib'; } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/Helper/SitothequeListViewMode.php b/library/ZendAfi/Controller/Action/Helper/SitothequeListViewMode.php index bfc07d69f630b3c32ffeb6882d52437bb37cfb65..ec3be7dd4aa8d4416492c64a34d9f72234d73c30 100644 --- a/library/ZendAfi/Controller/Action/Helper/SitothequeListViewMode.php +++ b/library/ZendAfi/Controller/Action/Helper/SitothequeListViewMode.php @@ -21,12 +21,9 @@ class ZendAfi_Controller_Action_Helper_SitothequeListViewMode extends ZendAfi_Controller_Action_Helper_AbstractListViewMode { + public function sitothequeListViewMode($params) { - $this->_model = $params['model']; - $this->_page = $params['page']; - $this->_search = $params['search_value']; $this->_params = $params; - return $this; } @@ -49,9 +46,10 @@ class ZendAfi_Controller_Action_Helper_SitothequeListViewMode extends ZendAfi_Co public function getCategories() { - return (!$id_cat = $this->getRequestParam('id_cat')) - ? Class_SitothequeCategorie::findAll() - : Class_SitothequeCategorie::findAllBy(['id_cat_mere' => $id_cat]); + $params = ($id_cat = $this->getRequestParam('id_cat')) ? + ['id_cat_mere' => $id_cat] : []; + + return Class_SitothequeCategorie::findAllBy($params); } diff --git a/tests/application/modules/admin/controllers/CmsControllerListModeTest.php b/tests/application/modules/admin/controllers/CmsControllerListModeTest.php index ae65e0b082c057226a73ada0d1df549514a73764..331043c7cde03ea11ae171705184b120a681c48a 100644 --- a/tests/application/modules/admin/controllers/CmsControllerListModeTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerListModeTest.php @@ -53,7 +53,6 @@ class CmsControllerListModeAdminRootTest extends CmsControllerListModeTestCase { } - /** @test */ public function portalShouldHaveDefaultPermissionsAction() { $this->assertXPath('//td//a[contains(@href, "bib/permissions/id/0")]', @@ -191,7 +190,6 @@ class CmsControllerListModeAdminBibSubCategoryTest $this->assertXPath('//td//a[contains(@href, "cms/add/id_cat/23")]', $this->_response->getBody()); } - }