From 51a61a62c8587fb36edf55535d4d5ac51b79016f Mon Sep 17 00:00:00 2001 From: lbrun <leo@sandbox.pergame.net> Date: Thu, 29 Oct 2015 15:24:21 +0100 Subject: [PATCH] dev#25569 : fix last display sito in home page --- .../opac/controllers/SitoController.php | 25 +++------ library/Class/Sitotheque.php | 13 +++++ library/ZendAfi/View/Helper/Accueil/Sito.php | 8 +-- .../ProfilOptionsControllerTest.php | 55 +++++++++++++++++++ 4 files changed, 80 insertions(+), 21 deletions(-) diff --git a/application/modules/opac/controllers/SitoController.php b/application/modules/opac/controllers/SitoController.php index 4782309d816..9b3f7fd32fc 100644 --- a/application/modules/opac/controllers/SitoController.php +++ b/application/modules/opac/controllers/SitoController.php @@ -37,25 +37,16 @@ class SitoController extends Zend_Controller_Action { } - protected function getRecentSitos() { - if ($id_category = $this->_getParam('id_cat')) { - $ids = $this->_getParam('id', $this->_getParam('id_items')); - $sitos = Class_Sitotheque::getSitesFromIdsAndCategories( - explode('-', $ids), - explode('-', $id_category), - true); - $this->view->title = $this->view->_('Derniers Sites de catégorie'); - return $sitos; - } - $sitos = Class_Sitotheque::findAllBy(['order' => 'date_maj desc', - 'limit' => (int)$this->_request->getParam('nb', 10)]); - return $sitos; - } + public function viewrecentAction() { + $id_category = $this->_getParam('id_cat'); + $id_items = $this->_getParam('id', $this->_getParam('id_items')); + $limit = (int)$this->_request->getParam('nb', 10); + $this->view->title = $id_category + ? $this->view->_('Derniers Sites de catégorie') + : $this->view->_('Derniers Sites'); - public function viewrecentAction() { - $this->view->title = $this->view->_('Derniers Sites'); - $this->view->sitos = $this->getRecentSitos(); + $this->view->sitos = Class_Sitotheque::getLastSitos($id_category, $id_items, $limit); $this->renderScript('sito/viewsitos.phtml'); } diff --git a/library/Class/Sitotheque.php b/library/Class/Sitotheque.php index 34b1f44858d..f6196568a08 100644 --- a/library/Class/Sitotheque.php +++ b/library/Class/Sitotheque.php @@ -75,6 +75,19 @@ class SitothequeLoader extends Storm_Model_Loader { } + public function getLastSitos($id_category, $id_items, $limit) { + if ($id_category) { + $sitos = Class_Sitotheque::getSitesFromIdsAndCategories( + explode('-', $id_items), + explode('-', $id_category), + true); + return $sitos; + } + $sitos = Class_Sitotheque::findAllBy(['order' => 'date_maj desc', + 'limit' => $limit]); + return $sitos; + } + /** * @param array $items * @return array diff --git a/library/ZendAfi/View/Helper/Accueil/Sito.php b/library/ZendAfi/View/Helper/Accueil/Sito.php index f440aab07c9..2111561884f 100644 --- a/library/ZendAfi/View/Helper/Accueil/Sito.php +++ b/library/ZendAfi/View/Helper/Accueil/Sito.php @@ -78,16 +78,16 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base } if ($this->isTypeAffichagePlusRecents() && $nb_aff > 0) { - $sites = Class_Sitotheque::findAllBy(['order' => 'date_maj desc', - 'limit' => 50]); - if (static::ORDER_RANDOM == $this->getPreference('display_order')) - shuffle($sites); + $sites = Class_Sitotheque::getLastSitos($this->getPreference('id_categorie'), + $this->getPreference('id_items'), + $nb_aff); $this->titre = $this->renderTitleLink($box_title, $this->_('Liste des derniers sites ajoutés'), $this->view->url(['controller' => 'sito', 'action' => 'viewrecent', + 'id_cat' => $this->getPreference('id_categorie'), 'nb' => 50], null,true)); } diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php index b87bdc6d4b4..9b63ad86fe9 100644 --- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php +++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php @@ -2516,4 +2516,59 @@ class ProfilOptionControllerWithHeritedPagesTest extends ProfilOptionControllerH public function profilShouldIncrementCfgIdsAndDeleteOldIdAndKeepPosition() { $this->assertEquals([11,10], array_keys(Class_Profil::find(2)->getCfgAccueilAsArray()['modules'])); } +} + + + +class ProfilOptionsControllerRecentSitoTest extends ProfilOptionsControllerProfilJeunesseWithPagesJeuxMusiqueTestCase { + + + public function setUp() { + parent::setUp(); + + $this->page_jeux->setCfgAccueil(['modules' => [ + '10' => ['division' => '2', + 'type_module' => 'SITO', + 'preferences' => ['id_categorie' => '2', + 'type_aff' => '2']]], + 'options' => []]); + + $this->fixture('Class_SitothequeCategorie', + ['id' => 2, + 'libelle' => 'Jeunesse', + 'sitotheques' => [ + $this->fixture('Class_Sitotheque', + ['id' => 34, + 'titre' => 'Thot cursus', + 'url' => 'http://cursus.edu/', + 'description' => 'Top notch site', + 'tags' => 'VOD']) + ]]); + + $this->fixture('Class_SitothequeCategorie', + ['id' => 3, + 'libelle' => 'Informatique', + 'sitotheques' => [ + $this->fixture('Class_Sitotheque', + ['id' => 35, + 'titre' => 'Pharo', + 'url' => 'http://pharo.org/', + 'description' => 'Cool programming language', + 'tags' => 'Smalltalk'])] + ]); + + + $this->dispatch('/opac/index/index/clef/zork?id_profil=12', true); + } + + /** @test */ + public function sitothequeShouldContainsLinkToCursus() { + $this->assertXPathContentContains('//a[@href="http://cursus.edu/"]', 'Thot cursus'); + } + + + /** @test */ + public function sitothequeShouldNotContainsLinkToPharo() { + $this->assertNotXPathContentContains('//a[@href="http://pharo.org/"]', 'Pharo'); + } } \ No newline at end of file -- GitLab