diff --git a/VERSIONS_WIP/25569 b/VERSIONS_WIP/25569 new file mode 100644 index 0000000000000000000000000000000000000000..c94f8bded989f66326903a4aca9260e71cca6e6d --- /dev/null +++ b/VERSIONS_WIP/25569 @@ -0,0 +1 @@ + - ticket #25569 : Boite sitothèque : afficher les derniers sites d'une catégorie \ No newline at end of file diff --git a/application/modules/admin/views/scripts/accueil/sitotheque.phtml b/application/modules/admin/views/scripts/accueil/sitotheque.phtml index 184e770125d3e7b67a6f2a93faaa80f0f6188914..1e275938f040b9e9107d946ad5d5baf6568252c8 100644 --- a/application/modules/admin/views/scripts/accueil/sitotheque.phtml +++ b/application/modules/admin/views/scripts/accueil/sitotheque.phtml @@ -4,12 +4,15 @@ Class_ScriptLoader::getInstance() function toggleDisplayTypeDependents() { var dependents = $(".group_cat, #option_display_order, #option_nb_aff"); ("3" == $("#type_aff").val()) ? dependents.hide() : dependents.show(); + + var recentDependents = $("#option_display_order"); + ("2" == $("#type_aff").val()) ? recentDependents.hide() : recentDependents.show(); + } $("#type_aff").change(function () { toggleDisplayTypeDependents(); var value = $("#type_aff").val(); - $(".treeselect").treeselect("toggleVisibility", (value == "1" || value == "3")); }); toggleDisplayTypeDependents(); @@ -74,7 +77,7 @@ formSelectToggleVisibilityForElement("input[name=display_order]", "#option_nb_af <?php echo $this->treeSelect($this->preferences['id_items'], $this->preferences['id_categorie'], - ($this->preferences['type_aff'] != '2'), + true, BASE_URL . '/admin/bib/allitems?id_bib=' . $this->id_bib . '&type=sito', "form"); ?> diff --git a/application/modules/opac/controllers/SitoController.php b/application/modules/opac/controllers/SitoController.php index f556c8b28882780835d3a7368fe51a5e5a0dab3b..a6edf0648e429eaaab409628d98b27431319d0ec 100644 --- a/application/modules/opac/controllers/SitoController.php +++ b/application/modules/opac/controllers/SitoController.php @@ -38,14 +38,15 @@ class SitoController extends Zend_Controller_Action { public function viewrecentAction() { - $class_sito = new Class_Sitotheque(); - $nb_sito = (int)$this->_request->getParam('nb', 10); - $limit = ($nb_sito < 1) ? 10 : $nb_sito; - - $sites = Class_Sitotheque::findAllBy(['order' => 'date_maj desc', - 'limit' => $limit]); - $this->view->sitos = $sites; - $this->view->title = $this->view->_('Derniers Sites'); + $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'); + + $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 357b97b6943636b10742e89c02ef23ef69e67b88..f6196568a08bd824f9cfa641ba34b56ae1de13f1 100644 --- a/library/Class/Sitotheque.php +++ b/library/Class/Sitotheque.php @@ -42,7 +42,7 @@ class SitothequeLoader extends Storm_Model_Loader { * @param array $id_categories * @return array */ - public function getSitesFromIdsAndCategories($id_sites, $id_categories) { + public function getSitesFromIdsAndCategories($id_sites, $id_categories, $sorted = false) { $sites = []; $feeds = []; @@ -65,10 +65,29 @@ class SitothequeLoader extends Storm_Model_Loader { $feeds = array_merge($feeds, $categorie->getSitotheques()); } + if ($feeds && $sorted == true) { + usort($feeds, function($a, $b) { + if ($a->getDateMaj() == $b->getDateMaj()) return 0; + return ($a->getDateMaj() < $b->getDateMaj() ? 1 : -1); + }); + } return $this->_filterOnId(array_filter($feeds)); } + 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 e541de0328efc121bb3f8d8b51aadac4a26bcafd..b86146b6c8bbd456f93c9f29dcaaa8623323c1db 100644 --- a/library/ZendAfi/View/Helper/Accueil/Sito.php +++ b/library/ZendAfi/View/Helper/Accueil/Sito.php @@ -81,16 +81,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 02420da50b23171a1d1496490daea7dbccd211ed..1663c1f936ec04d60c37bfae3b280fc3823e3d34 100644 --- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php +++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php @@ -2523,4 +2523,88 @@ 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'])] + ]); + + } + + /** @test */ + public function sitothequeShouldContainsLinkToCursus() { + $this->dispatch('/opac/index/index/clef/zork?id_profil=12', true); + $this->assertXPathContentContains('//a[@href="http://cursus.edu/"]', 'Thot cursus'); + } + + + /** @test */ + public function sitothequeShouldNotContainsLinkToPharo() { + $this->dispatch('/opac/index/index/clef/zork?id_profil=12', true); + $this->assertNotXPathContentContains('//a[@href="http://pharo.org/"]', 'Pharo'); + } + + + /** @test */ + public function withoutCategoryShouldDisplay2Sitos() { + $this->page_jeux->setCfgAccueil(['modules' => [ + '10' => ['division' => '2', + 'type_module' => 'SITO', + 'preferences' => ['id_categorie' => '', + 'type_aff' => '2']]], + 'options' => []]); + + $this->dispatch('/opac/index/index/clef/zork?id_profil=12', true); + $this->assertXPathCount('//div[@class="sitotheque"]', 2); + } + + + /** @test */ + public function with1CategoryAnd1ItemShouldDisplay2Sitos() { + $this->page_jeux->setCfgAccueil(['modules' => [ + '10' => ['division' => '2', + 'type_module' => 'SITO', + 'preferences' => ['id_categorie' => '2', + 'id_items' => '35', + 'type_aff' => '2']]], + 'options' => []]); + + $this->dispatch('/opac/index/index/clef/zork?id_profil=12', true); + $this->assertXPathCount('//div[@class="sitotheque"]', 2); + } } \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/SitoControllerTest.php b/tests/application/modules/opac/controllers/SitoControllerTest.php index fbc10f5a6953767fa1de424936e7e212abecd4ea..8cc5b3fccb112a61df25f53911d66dc52a901f2d 100644 --- a/tests/application/modules/opac/controllers/SitoControllerTest.php +++ b/tests/application/modules/opac/controllers/SitoControllerTest.php @@ -59,9 +59,7 @@ abstract class SitoControllerTestCase extends AbstractControllerTestCase { } - - -abstract class SitoControllerViewCategoryTestCase extends SitoControllerTestCase { +abstract class SitoControllerViewCategoryAndRecentTestCase extends SitoControllerTestCase { public function setUp() { parent::setUp(); $collectif = $this->fixture('Class_SitothequeCategorie', @@ -79,12 +77,13 @@ abstract class SitoControllerViewCategoryTestCase extends SitoControllerTestCase 'parent_categorie' => $associations, 'libelle' => 'Libre' ]); - $this->fixture('Class_Sitotheque', + $quadrature = $this->fixture('Class_Sitotheque', ['id' => 280, 'categorie' => $libre, 'titre' => 'La quadrature du net', 'description' => 'Internet et libertés', 'url' => 'http://laquadrature.net']); + $quadrature->setDateMaj('1970-01-01 00:00:00'); $this->fixture('Class_Sitotheque', ['id' => 282, @@ -93,13 +92,20 @@ abstract class SitoControllerViewCategoryTestCase extends SitoControllerTestCase 'description' => 'Promouvoir le logiciel libre', 'url' => 'http://april.org']); - $this->fixture('Class_Sitotheque', + $framasoft = $this->fixture('Class_Sitotheque', ['id' => 281, 'categorie' => $collectif, 'titre' => 'Framasoft', 'description' => 'Degooglisons internet', 'url' => 'http://framasoft.org']); + $framasoft->setDateMaj('9999-12-12 00:00:00'); + } +} + +abstract class SitoControllerViewCategoryTestCase extends SitoControllerViewCategoryAndRecentTestCase { + public function setUp() { + parent::setUp(); Class_Profil::getCurrentProfil() ->setCfgAccueil(['modules' => ['1' => ['division' => '2', 'type_module' => 'SITO', @@ -108,12 +114,12 @@ abstract class SitoControllerViewCategoryTestCase extends SitoControllerTestCase 'id_items' => '280-281', 'rss' => 1]]], 'options' => []]); + } } - class SitoControllerViewCategoryTest extends SitoControllerViewCategoryTestCase { public function setUp() { parent::setUp(); @@ -150,8 +156,6 @@ class SitoControllerViewCategoryTest extends SitoControllerViewCategoryTestCase } - - class SitoControllerViewRecentTest extends SitoControllerTestCase { public function setUp() { parent::setUp(); @@ -165,10 +169,58 @@ class SitoControllerViewRecentTest extends SitoControllerTestCase { $this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]', $this->_response->getBody()); } + +} + + +abstract class SitoControllerViewRecentTestCase extends SitoControllerViewCategoryAndRecentTestCase { + public function setUp() { + parent::setUp(); + + Class_Profil::getCurrentProfil() + ->setCfgAccueil(['modules' => ['1' => ['division' => '2', + 'type_module' => 'SITO', + 'preferences' => ['id_categorie' => '12', + 'type_aff' => '2', + 'id_items' => '280-281']]], + 'options' => []]); + } } +class SitoControllerViewRecentWithCategoryTest extends SitoControllerViewRecentTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/sito/viewrecent/nb/10/id_cat/12', true); + } + + /** @test */ + public function linuxFrShouldNotBeShown() { + $this->assertNotXPath('//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]', + $this->_response->getBody()); + } + + /** @test */ + public function framasoftShouldBeShownFirst() { + $this->assertXPath('(//div[@class="sitotheque"])[1]//a[@href="http://framasoft.org"]', + $this->_response->getBody()); + } + + /** @test */ + public function aprilShouldBeShownSecond() { + $this->assertXPath('(//div[@class="sitotheque"])[2]//a[@href="http://april.org"]', + $this->_response->getBody()); + } + + /** @test */ + public function quadratureShouldBeShownLast() { + $this->assertXPath('(//div[@class="sitotheque"])[3]//a[@href="http://laquadrature.net"]', + $this->_response->getBody()); + } +} + + class SitoControllerViewCategorySearchTest extends SitoControllerViewCategoryTestCase { public function setUp() { @@ -288,7 +340,6 @@ class SitoControllerSitoViewIdTest extends SitoControllerTestCase { } - class SitoControllerSitoWebThumbnailUrl extends SitoControllerTestCase { public function setup() { parent::setUp(); diff --git a/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php b/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php index 02201180a2974e6a6b8b6724a0a03eb26afa831c..8106c8bd27ea650862f35690c78f53055353e1b7 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php @@ -205,12 +205,12 @@ class SitoViewHelperLastTest extends SitoViewHelperTestCase { /** @test */ - public function itemsShouldBeShuffled() { + public function itemsShouldNotBeShuffled() { $htmls = []; for ($i=0; $i<10; $i++) $htmls[] = $this->_helper->getBoite(); - $this->assertTrue(1 < count(array_unique($htmls))); + $this->assertCount(1, array_unique($htmls)); } }