Skip to content
Snippets Groups Projects
Commit ac44cb68 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #21245: fix items count in articles list view mode

parent 3ee305fa
Branches
Tags
4 merge requests!896Master,!893Master,!885Dev#21425 user comments by domains,!871Dev#21425 user comments by domains
......@@ -171,6 +171,11 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen
}
public function countItemsInTreeFrom($model) {
return $this->countItemsFor($model);
}
public function getCategoriesLabelAttrib() {
return 'libelle';
}
......
......@@ -192,6 +192,27 @@ class ZendAfi_Controller_Action_Helper_ArticleListViewMode extends ZendAfi_Contr
}
public function countItemsInTreeFrom($model) {
if (!$model)
return 0;
return $model->numberOfArticles()
+ $this->countItemsInChildrenOf($model);
}
protected function countItemsInChildrenOf($model) {
if (!$model)
return 0;
$count = 0;
foreach($model->getChildren() as $child)
$count += $this->countItemsInTreeFrom($child);
return $count;
}
public function getCategoriesCols() {
return [$this->_('Catégories d\'articles')];
}
......
......@@ -45,6 +45,11 @@ class ZendAfi_Controller_Action_Helper_BibListViewMode extends ZendAfi_Controlle
}
public function isCountEnabled() {
return false;
}
public function getParamKey() {
return 'id_bib';
}
......
......@@ -90,28 +90,40 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel
return '';
$labelWithCount = function($model, $attrib) {
return $this->view->tagAnchor($this->view->url(array_merge($this->_list->getBaseUrl(),
['action' => 'index',
$this->_list->getParamKey() => $model->getId()]), null, true),
$this->view->tagImg(URL_ADMIN_IMG . 'ico/cat.gif')
. $model->$attrib
. ' (' . $this->_list->countItemsFor($model) . ')');};
return $this->view->tagModelTable($this->_list->getCategories(),
$this->_list->getCategoriesCols(),
$this->_list->getCategoriesAttribs(),
[function($model) {
return $this->view->modelActions($model, $this->getCategoriesActions($model));}],
$this->_list->getCategoriesId(),
$this->_list->getCategoriesGroupBy(),
[$this->_list->getCategoriesLabelAttrib() => $labelWithCount]);
return $this->_renderCategory($model, $attrib);
};
return $this->view
->tagModelTable($this->_list->getCategories(),
$this->_list->getCategoriesCols(),
$this->_list->getCategoriesAttribs(),
[function($model) {
return $this->view->modelActions($model, $this->getCategoriesActions($model));}],
$this->_list->getCategoriesId(),
$this->_list->getCategoriesGroupBy(),
[$this->_list->getCategoriesLabelAttrib() => $labelWithCount]);
}
protected function _renderCategory($model, $attrib) {
$url = $this->view->url(array_merge($this->_list->getBaseUrl(),
['action' => 'index',
$this->_list->getParamKey() => $model->getId()]),
null, true);
$label = $this->view->tagImg(URL_ADMIN_IMG . 'ico/cat.gif')
. $model->$attrib;
if ($this->_list->isCountEnabled())
$label .= ' (' . $this->_list->countItemsInTreeFrom($model) . ')';
return $this->view->tagAnchor($url, $label);
}
protected function getItemsHTML() {
if (!$this->_list->getModel() && !$this->_list->getSearchValue())
return '';
return '';
$labelWithBreadcrumb = function($model, $attrib) {
return $this->_tag('span', $model->$attrib)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment