diff --git a/application/modules/opac/controllers/SitoController.php b/application/modules/opac/controllers/SitoController.php index d1cbfb51ea43c5cea3c0c3a90236c089f4e1ee08..6f2b37a070f4db45316709868ca5e430d3a13d7c 100644 --- a/application/modules/opac/controllers/SitoController.php +++ b/application/modules/opac/controllers/SitoController.php @@ -69,7 +69,6 @@ class SitoController extends Zend_Controller_Action { 'search_value' => $search, 'id_cat'=>$this->view->id_category, 'page' => $this->_getParam('page',1)]); -// return $this->getHelper('ViewRenderer')->renderScript('admin/listViewMode.phtml'); } diff --git a/library/ZendAfi/Controller/Action/Helper/ListViewMode/List.php b/library/ZendAfi/Controller/Action/Helper/ListViewMode/List.php index a9fb5b50b2746d4b2d9026c7d011894850a49e38..de34816f7ddcd45934fd9ca30a952dd0d6ddc8d6 100644 --- a/library/ZendAfi/Controller/Action/Helper/ListViewMode/List.php +++ b/library/ZendAfi/Controller/Action/Helper/ListViewMode/List.php @@ -176,6 +176,11 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_List { } + public function countRecursiveItemsFor($model) { + return $this->_strategy->countRecursiveItemsFor($model); + } + + public function getBreadcrumbFor($model) { return $this->_strategy->getBreadcrumbFor($model); } @@ -231,4 +236,11 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_List { public function isSearchEnabled() { return $this->_strategy->isSearchEnabled(); } + + + public function getUrlParams($model) { + return $this->_strategy->getUrlParams($model); + + } + } diff --git a/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy.php b/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy.php index d9e2f5fa7fbf97b9c7d803c189f7a2b499290c5b..c77c8025de6a5c40395f83f9c6a2afcc466ee432 100644 --- a/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy.php +++ b/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy.php @@ -49,13 +49,17 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy { 'title_search' => '']; } + protected function _shouldCheckParent($start_key,$model) { + return ($start_key && ($this->getRequestParam($start_key,'')==$model->getId())); + } + - public function getBreadcrumbFor($model, $breadcrumb = []) { + public function getBreadcrumbFor($model, $breadcrumb = [],$start_key='') { if(!$model) return $breadcrumb; - if($parent = $model->getParentCategorie()) - $breadcrumb = $this->getBreadcrumbFor($parent, $breadcrumb); + if (!$this->_shouldCheckParent($start_key,$model) && $parent = $model->getParentCategorie()) + $breadcrumb = $this->getBreadcrumbFor($parent, $breadcrumb,$start_key); $breadcrumb[] = ['url' => array_merge($this->getBreadcrumbUrl(),[$this->getParamKey() => $model->getId()]), 'label' => $model->getLibelle(), @@ -164,5 +168,15 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy { public function getRequestParam($key, $default = null) { return $this->_helper->getRequest()->getParam($key, $default); } + + public function countRecursiveItemsFor($model) { + return $this->countItemsFor($model); + } + + public function getUrlParams($model) { + return array_merge($params,$this->getBaseUrl(), + [ $this->getParamKey() => $model->getId()]); + + } } ?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy/Sitotheque.php b/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy/Sitotheque.php index 138d6ee6fbb314282d538a72990fb394cb8cac5d..08a248461f921e98d090ecd6a3aaa7ca9fd4d311 100644 --- a/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy/Sitotheque.php +++ b/library/ZendAfi/Controller/Action/Helper/ListViewMode/Strategy/Sitotheque.php @@ -51,6 +51,13 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Sitotheque extends return 'id_cat'; } + public function getUrlParams($model) { + $params= ($start_cat=$this->getRequestParam('start_cat')) ? + ['start_cat'=> $start_cat] : []; + return array_merge($params,$this->getBaseUrl(), + [ $this->getParamKey() => $model->getId()]); + + } public function getCategories() { $categories = []; @@ -73,23 +80,23 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Sitotheque extends return Class_Article::countBy(parent::getSearchParams()); } - public function getBreadcrumb() { $breadcrumb = []; if($this->_visitor->getSearchValue()) return $breadcrumb; - $breadcrumb = array_merge($breadcrumb, $this->getBreadcrumbFor($this->_visitor->getModel())); + $breadcrumb = array_merge($breadcrumb, $this->getBreadcrumbFor($this->_visitor->getModel(),[],'start_cat')); - return $this->_shiftBreadcrumb($breadcrumb); + return $breadcrumb; } protected function _shiftBreadcrumb($breadcrumb = []) { $start_cat = $this->getRequestParam('start_cat'); foreach ($breadcrumb as $cat) { - if ($cat['url']['id_cat'] != $start_cat) + if ($cat['url']['id_cat'] != $start_cat) { array_shift($breadcrumb); + return $breadcrumb;} } return $breadcrumb; @@ -107,6 +114,17 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Strategy_Sitotheque extends return Class_Sitotheque::countBy([$this->getParamKey() => $id]); } + public function countRecursiveItemsFor($model) { + if (!$model) + return Class_Sitotheque::count(); + + $ids=array_map(function($cat) {return $cat->getId();}, + $model->getRecursiveSousCategories()); + + $ids[]=$model->getId(); + return Class_Sitotheque::countBy([$this->getParamKey() => $ids]); + } + public function getCategoriesCols() { return [$this->_('Catégories d\'articles')]; diff --git a/library/ZendAfi/View/Helper/PublicListViewMode.php b/library/ZendAfi/View/Helper/PublicListViewMode.php index 2759f31b076eebdc4d521aad479095bf193027fd..4346a4fc92089a45b0709938cf55246529eb85d3 100644 --- a/library/ZendAfi/View/Helper/PublicListViewMode.php +++ b/library/ZendAfi/View/Helper/PublicListViewMode.php @@ -40,10 +40,9 @@ class ZendAfi_View_Helper_PublicListViewMode extends ZendAfi_View_Helper_Admin_ return ''; $labelWithCount = function($model, $attrib) { - return $this->view->tagAnchor($this->view->url(array_merge($this->_list->getBaseUrl(), - [ $this->_list->getParamKey() => $model->getId()]), null, true), + return $this->view->tagAnchor($this->view->url($this->_list->getUrlParams($model),null, true), $model->$attrib - . ' (' . $this->_list->countItemsFor($model) . ')');}; + . ' (' . $this->_list->countRecursiveItemsFor($model) . ')');}; return $this->view->tagList($this->_list->getCategories(), $this->_list->getCategoriesAttribs(), @@ -61,12 +60,11 @@ class ZendAfi_View_Helper_PublicListViewMode extends ZendAfi_View_Helper_Admin_ $labelWithThumbnail = function($model, $attrib) { $html=''; if ($img_url = $this->getThumbnail($model->getUrl())) - $html.= $this->view->tagImg($img_url,['alt' => $this->_('vignette site '.$model->$attrib)]); + $html.= $this->view->tagImg($img_url,['alt' => ""]); return $html.$this->view->tagAnchor($model->getUrl(),$model->$attrib, ['title' => 'Aller sur le site']); }; - return $this->view->tagList($this->_list->getItems(), $this->_list->getItemsAttribs(), $this->_list->getItemsId(), diff --git a/tests/application/modules/admin/controllers/SitothequeControllerTest.php b/tests/application/modules/admin/controllers/SitothequeControllerTest.php index b07d08fc6ce1c9ac62a25bb9487bffc8714f5ed0..59dd1f60caabcce03a89cd258bb28a63bee8b6fe 100644 --- a/tests/application/modules/admin/controllers/SitothequeControllerTest.php +++ b/tests/application/modules/admin/controllers/SitothequeControllerTest.php @@ -30,7 +30,7 @@ abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTest Class_Exemplaire::beVolatile(); Class_Notice::beVolatile(); Class_CodifThesaurus::beVolatile(); - + Storm_Model_Loader::defaultToVolatile(); $categorie_informations = $this->fixture('Class_SitothequeCategorie', ['id' => 2, 'libelle' => 'Informations', @@ -59,6 +59,12 @@ abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTest Class_Bib::getPortail()->setSitothequeCategories([]); } + public function tearDown() { + Storm_Model_Loader::defaultToDb(); + parent::tearDown(); + } + + public function setupDomaines() { $this->fixture('Class_Catalogue', ['id' => 10, diff --git a/tests/application/modules/opac/controllers/SitoControllerTest.php b/tests/application/modules/opac/controllers/SitoControllerTest.php index 4e9bd5ac4a9df982579922e854296a8843798bc2..f903325fd816c3458ff742b4bd45cf7ee3875feb 100644 --- a/tests/application/modules/opac/controllers/SitoControllerTest.php +++ b/tests/application/modules/opac/controllers/SitoControllerTest.php @@ -61,19 +61,39 @@ abstract class SitoControllerTestCase extends AbstractControllerTestCase { class SitoControllerHierarchicViewTest extends SitoControllerTestCase { public function setUp() { parent::setUp(); - $this->fixture('Class_SitothequeCategorie', + $collectif=$this->fixture('Class_SitothequeCategorie', ['id' => 12, 'parent_categorie' => $this->hackers, 'libelle' => 'Collectifs' ]); + + $this->fixture('Class_SitothequeCategorie', + ['id' => 19, + 'parent_categorie' => $this->fixture('Class_SitothequeCategorie', + ['id' => 17, + 'parent_categorie' => $collectif, + 'libelle' => 'Associations' ]), + + 'libelle' => 'Libre' ]); + + $this->fixture('Class_Sitotheque', ['id' => 280, - 'id_cat' => 12, + 'id_cat' => 19, 'titre' => 'La quadrature du net', 'description' => 'Internet et libertés', 'url' => 'http://laquadrature.net']); + + $this->fixture('Class_Sitotheque', + ['id' => 282, + 'id_cat' => 17, + 'titre' => 'April', + 'description' => 'Promouvoir le logiciel libre', + 'url' => 'http://april.org']); + + $this->fixture('Class_Sitotheque', ['id' => 281, 'id_cat' => 12, @@ -114,6 +134,13 @@ class SitoControllerHierarchicViewTest extends SitoControllerTestCase { } + /** @test */ + public function catAssocShouldContains2sites() { + $this->assertXPathContentContains('//div//a[@href="/sito/viewcategory/start_cat/12/id_cat/17"]','Associations (2)', + $this->_response->getBody()); + } + + /** @test */ public function breadCrumbShouldStartWithCollectifs() { $this->assertXPath('//div/a[1][@href="/sito/viewcategory/id_cat/12"]'); diff --git a/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php b/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php index fabdf2a7ee582d4d1641d9e733c1a5cd465378c9..e7bea0d2d7a85942c1ff1d17d40145da0a5afd83 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php @@ -294,7 +294,7 @@ class SitoViewHelperHierarchicalCategoryTest extends SitoViewHelperTestCase { /** @test */ public function urlShouldRedirectToViewPage() { $this->assertXPathContentContains($this->html, - '//h2//a[contains(@href, "/sito/viewcategory/id_cat/23")]', + '//h2//a[contains(@href, "/sito/viewcategory/id_cat/23/start_cat/23")]', 'La Creuse'); }