diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php index d7c98e3ecdd1d4ef17e9703d7594f859746e19fc..4dd0ffdc261b059725b80a7c527c4a408f0a8901 100644 --- a/application/modules/admin/controllers/CmsController.php +++ b/application/modules/admin/controllers/CmsController.php @@ -82,8 +82,7 @@ class Admin_CmsController extends ZendAfi_Controller_Action { 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->articleListViewMode($params); return $this->renderScript('admin/listViewMode.phtml'); } diff --git a/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php b/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php index 6802e5fd633745a464ece88b172271354a933226..ccf603736922db81dc9774fc566df7d2ad87ec22 100644 --- a/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php +++ b/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php @@ -176,6 +176,16 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen } + public function getItemsGroupBy() { + return null; + } + + + public function getCategoryFor($model) { + return $model->getCategorie(); + } + + public function getModel() { return $this->getParam('model'); } diff --git a/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy/Article.php b/library/ZendAfi/Controller/Action/Helper/ArticleListViewMode.php similarity index 57% rename from library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy/Article.php rename to library/ZendAfi/Controller/Action/Helper/ArticleListViewMode.php index 50d203059dc5355f6d2860a69f6bc067c86bbdc6..8abf111f1fcc961e024c6fc2db00cbb420c4fdcf 100644 --- a/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy/Article.php +++ b/library/ZendAfi/Controller/Action/Helper/ArticleListViewMode.php @@ -20,10 +20,21 @@ */ -class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Article extends ZendAfi_Controller_Action_Helper_ListViewMode_Strategy { - protected $_filtred_categories, - $_filtred_categories_ids, - $_current_bib; +class ZendAfi_Controller_Action_Helper_ArticleListViewMode extends ZendAfi_Controller_Action_Helper_AbstractListViewMode { + use Trait_Translator; + + protected $_filtred_categories_ids = []; + + public function articleListViewMode($params) { + $this->_params = $params; + return $this; + } + + + public function direct($params) { + return $this->articleListViewMode($params); + } + public function getBaseUrl() { return ['module' => 'admin', @@ -49,9 +60,7 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Article extends Zen public function getCategories() { - $categories = []; - - $categories = (!$id_cat = $this->_visitor->getParams()['id_cat']) + $categories = (!$id_cat = $this->getParam('id_cat')) ? $this->getBib()->getArticleCategories() : Class_ArticleCategorie::findAllBy(['id_cat_mere' => $id_cat]); @@ -60,10 +69,10 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Article extends Zen protected function getCurrentBib() { - if($this->_current_bib) + if ($this->_current_bib) return $this->_current_bib; - if(!$this->_current_bib = Class_Bib::find($this->_visitor->getParams()['id_bib'])) + if (!$this->_current_bib = Class_Bib::find($this->getParam('id_bib'))) $this->_current_bib = Class_Bib::getPortail(); return $this->_current_bib; @@ -73,14 +82,13 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Article extends Zen protected function getFiltredCategories($categories) { $cms_permissions = Class_Permission::getCmsPermissions(); - $categories_filter = function($category) use ($cms_permissions){ + $categories_filter = function($category) use ($cms_permissions) { $user = Class_Users::getIdentity(); return $user->hasAnyPermissionUnder($category, $cms_permissions) || $user->hasAnyPermissionOn($category, $cms_permissions); }; return array_filter($categories, $categories_filter); - } @@ -89,20 +97,28 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Article extends Zen } + protected function getItemsParams() { + return array_merge(parent::getItemsParams(), + ['order' => 'titre']); + } + + protected function getSearchParams() { - $filtred_categories = $this->_filtred_categories_ids - ? null - : $this->getFiltredCategories($this->getCategoriesForUser()); + return ['where' => 'titre like \'%' . trim($this->getSearch()) . '%\'', + 'id_cat' => $this->getFilteredCategoriesIds(), + 'order' => 'titre']; + } - $this->_filtred_categories_ids = $this->_filtred_categories_ids - ? $this->_filtred_categories_ids - : array_map(function($model) {return $model->getId();}, $filtred_categories); - $filtred_categories = null; + protected function getFilteredCategoriesIds() { + if ($this->_filtred_categories_ids) + return $this->_filtred_categories_ids; - $params = parent::getSearchParams(); - $params->offsetSet('id_cat', $this->_filtred_categories_ids); - return $params; + $categories = $this->getFiltredCategories($this->getCategoriesForUser()); + $this->_filtred_categories_ids = array_map(function($model) { return $model->getId(); }, + $categories); + + return $this->_filtred_categories_ids; } @@ -117,31 +133,31 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Article extends Zen public function getBreadcrumb() { - $breadcrumb = []; - $breadcrumb[] = ['url' => ['module' => 'admin', - 'controller' => 'cms', - 'action' => 'index'], - 'label' => $this->_('Racine'), - 'options' => []]; - - $breadcrumb[] = ['url' => ['module' => 'admin', - 'controller' => 'cms', - 'action' => 'index', - 'id_bib' => $this->getBibId()], - 'label' => $this->getBibLabel(), - 'options' => []]; - - if($this->_visitor->getSearchValue()) + $breadcrumb = [['url' => ['module' => 'admin', + 'controller' => 'cms', + 'action' => 'index'], + 'label' => $this->_('Racine'), + 'options' => []], + + ['url' => ['module' => 'admin', + 'controller' => 'cms', + 'action' => 'index', + 'id_bib' => $this->getBibId()], + 'label' => $this->getBibLabel(), + 'options' => []]]; + + if ($this->getSearchValue()) return $breadcrumb; - if(Class_Users::getIdentity()->isRoleLibraryLimited()) - $breadcrumb = [ ['url' => ['module' => 'admin', - 'controller' => 'cms', - 'action' => 'index'], - 'label' => $this->_visitor->getParams()['bib']->getLibelle(), - 'options' => []]]; + if (Class_Users::getIdentity()->isRoleLibraryLimited()) + $breadcrumb = [['url' => ['module' => 'admin', + 'controller' => 'cms', + 'action' => 'index'], + 'label' => $this->getParam('bib')->getLibelle(), + 'options' => []]]; - return array_merge($breadcrumb, $this->getBreadcrumbFor($this->_visitor->getModel())); + return array_merge($breadcrumb, + $this->getBreadcrumbFor($this->getModel())); } @@ -156,24 +172,23 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Article extends Zen protected function getBib() { - if($bib = Class_Bib::find($this->_visitor->getParams()['id_bib'])) + if ($bib = Class_Bib::find($this->getParam('id_bib'))) return $bib; - if($id_cat = $this->_visitor->getParams()['id_cat']) - return $this->_visitor->getModel()->getBib(); + if ($id_cat = $this->getParam('id_cat')) + return $this->getModel()->getBib(); return Class_Bib::getPortail(); } public function getDefaultModel() { - return $this->_visitor->getModel() ? $this->_visitor->getModel() : $this->getBib(); + return $this->getModel() ? $this->getModel() : $this->getBib(); } public function countItemsFor($model) { - $id = $model ? $model->getId() : 0; - return Class_Article::countBy([$this->getParamKey() => $id]); + return $model ? $model->numberOfArticles() : 0; } @@ -195,5 +210,9 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Article extends Zen public function getItemsLabelAttrib() { return 'titre'; } -} -?> \ No newline at end of file + + + public function getStrategyLabel() { + return 'article'; + } +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Admin/ListViewMode.php b/library/ZendAfi/View/Helper/Admin/ListViewMode.php index 32f451b8131301990fbd94ebbcccd11b48fe56c3..5e07eda90cb76072bf9d26cf28e568b5ade0124d 100644 --- a/library/ZendAfi/View/Helper/Admin/ListViewMode.php +++ b/library/ZendAfi/View/Helper/Admin/ListViewMode.php @@ -39,24 +39,27 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel protected function getSearchFormHTML() { - if(!$this->_list->isSearchEnabled()) + if (!$this->_list->isSearchEnabled()) return ''; $url = $this->view->url($this->_list->getSearchUrl(), null, true); $submit = "$('#list_search_form').submit(function(event) {event.preventDefault(); event.stopImmediatePropagation(); var search = $('#list_title_search').val();var url = '". $url ."' + search; document.location.href = url;});"; - $search_input = $this->view->tag('input', '', ['type' => 'text', - 'name' => 'title_search', - 'id' => 'list_title_search', - 'placeholder' => $this->view->_('titre du document'), - 'value' => $this->_list->getSearchValue()]); + $search_input = $this->_tag('input', '', + ['type' => 'text', + 'name' => 'title_search', + 'id' => 'list_title_search', + 'placeholder' => $this->_('titre du document'), + 'value' => $this->_list->getSearchValue()]); Class_ScriptLoader::getInstance()->addJQueryReady($submit); - $search_button = $this->view->tag('button', $this->view->_('Filtrer'), ['id' => 'list_filter_button']); + $search_button = $this->_tag('button', $this->_('Filtrer'), + ['id' => 'list_filter_button']); - return $this->view->tag('form', $search_input . $search_button, ['style' => 'text-align: right;', - 'id' => 'list_search_form']); + return $this->_tag('form', $search_input . $search_button, + ['style' => 'text-align: right;', + 'id' => 'list_search_form']); } @@ -64,8 +67,8 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel $html = $this->getBreadcrumbHTMLFor($this->_list->getBreadcrumb()) . ' ' . $this->view->modelActions($this->_list->getDefaultModel(), $this->getCategoriesActions($this->_list->getModel()), true); - return $this->view->tag('div', $html, - ['style' => 'font-size:140%;']); + return $this->_tag('div', $html, + ['style' => 'font-size:140%;']); } @@ -73,7 +76,9 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel $breadcrumb_html = []; foreach($breadcrumb as $loc) { - $breadcrumb_html[] = $this->view->tagAnchor($this->view->url($loc['url'], null, true), $loc['label'], $loc['options']); + $breadcrumb_html[] = $this->view->tagAnchor($this->view->url($loc['url'], null, true), + $loc['label'], + $loc['options']); } return implode(' > ',$breadcrumb_html); @@ -81,7 +86,7 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel protected function getCategoriesHTML() { - if($this->_list->getSearchValue()) + if ($this->_list->getSearchValue()) return ''; $labelWithCount = function($model, $attrib) { @@ -105,24 +110,25 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel protected function getItemsHTML() { - if(!$this->_list->getModel() && !$this->_list->getSearchValue()) + if (!$this->_list->getModel() && !$this->_list->getSearchValue()) return ''; $labelWithBreadcrumb = function($model, $attrib) { - return $this->view->tag('span', $model->$attrib ) - . $this->view->tag('p', $this->getBreadcrumbHTMLFor($this->_list->getBreadcrumbFor($this->_list->getCategoryFor($model))), - ['style' => 'font-size:0.9em;']); -}; - - - return $this->view->tagModelTable($this->_list->getItems(), - $this->_list->getItemsCols(), - $this->_list->getItemsAttribs(), - [function($model) { - return $this->view->modelActions($model, $this->getItemsActions($model));}], - $this->_list->getItemsId(), - $this->_list->getItemsGroupBy(), - $this->_list->getSearchValue() ? [$this->_list->getItemsLabelAttrib() => $labelWithBreadcrumb] : []); + return $this->_tag('span', $model->$attrib) + . $this->_tag('p', + $this->getBreadcrumbHTMLFor($this->_list->getBreadcrumbFor($this->_list->getCategoryFor($model))), + ['style' => 'font-size:0.9em;']); + }; + + return $this + ->view->tagModelTable($this->_list->getItems(), + $this->_list->getItemsCols(), + $this->_list->getItemsAttribs(), + [function($model) { + return $this->view->modelActions($model, $this->getItemsActions($model));}], + $this->_list->getItemsId(), + $this->_list->getItemsGroupBy(), + $this->_list->getSearchValue() ? [$this->_list->getItemsLabelAttrib() => $labelWithBreadcrumb] : []); } @@ -139,5 +145,4 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel protected function getItemsActions($model) { return $this->view->itemsActions($model, $this->_list->getStrategyLabel()); } -} -?> \ No newline at end of file +} \ No newline at end of file