From 11eef6dfb21629df15b619419ae3f4617ba0f1fe Mon Sep 17 00:00:00 2001 From: lbrun <leo@sandbox.pergame.net> Date: Wed, 4 Nov 2015 16:16:53 +0100 Subject: [PATCH] dev#23223_sito_widget_pagination : add pagination and remove pagination on random affichage --- .../opac/controllers/SitoController.php | 17 +++++++++ .../opac/views/scripts/pagination.phtml | 2 +- .../opac/views/scripts/sito/widget-page.phtml | 3 ++ library/ZendAfi/View/Helper/Accueil/Sito.php | 38 ++++++++++++++----- .../View/Helper/PublicListViewMode.php | 2 +- .../opac/controllers/SitoControllerTest.php | 34 ++++++++++++++++- 6 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 application/modules/opac/views/scripts/sito/widget-page.phtml diff --git a/application/modules/opac/controllers/SitoController.php b/application/modules/opac/controllers/SitoController.php index a6edf0648e4..b5a0a6eb072 100644 --- a/application/modules/opac/controllers/SitoController.php +++ b/application/modules/opac/controllers/SitoController.php @@ -95,4 +95,21 @@ class SitoController extends Zend_Controller_Action { $this->_helper->renderRss($id_profil, $id_module, $this->view, 'SITO'); } + + public function widgetPageAction() { + $id_module = (int)$this->_getParam('id_module'); + $id_division = (int)$this->_getParam('id_division'); + $page = (int)$this->_getParam('page'); + + $module_params = Class_Profil::getCurrentProfil() + ->getBoitesDivision($id_division)[$id_module]; + + $helper = new ZendAfi_View_Helper_Accueil_Sito($id_module, $module_params); + $helper->setPage($page); + $helper->setView($this->view); + + $this->view->sito_helper = $helper; + $viewRenderer = $this->getHelper('ViewRenderer'); + $viewRenderer->setLayoutScript('empty.phtml'); + } } \ No newline at end of file diff --git a/application/modules/opac/views/scripts/pagination.phtml b/application/modules/opac/views/scripts/pagination.phtml index b1a45a765be..eae47faa233 100644 --- a/application/modules/opac/views/scripts/pagination.phtml +++ b/application/modules/opac/views/scripts/pagination.phtml @@ -15,7 +15,7 @@ if (1 >= $this->pageCount) return;?> <!-- Numbered page links --> <?php foreach ($this->pagesInRange as $page): ?> <?php if ($page != $this->current): ?> - <a href="<?php echo $this->url(['page' => $page]); ?>"><?php echo $page; ?></a> | + <a href="<?php echo $this->url(array_merge($this->url_link, ['page' => $page])); ?>"><?php echo $page; ?></a> | <?php else: ?> <?= $page; ?> | <?php endif; ?> diff --git a/application/modules/opac/views/scripts/sito/widget-page.phtml b/application/modules/opac/views/scripts/sito/widget-page.phtml new file mode 100644 index 00000000000..eeda9cb638d --- /dev/null +++ b/application/modules/opac/views/scripts/sito/widget-page.phtml @@ -0,0 +1,3 @@ +<?php +echo $this->sito_helper->getBoite(); +?> diff --git a/library/ZendAfi/View/Helper/Accueil/Sito.php b/library/ZendAfi/View/Helper/Accueil/Sito.php index c9be0b873bd..9be15520cad 100644 --- a/library/ZendAfi/View/Helper/Accueil/Sito.php +++ b/library/ZendAfi/View/Helper/Accueil/Sito.php @@ -27,7 +27,7 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base const DISPLAY_NOVELTY = 2; const DISPLAY_HIERARCHY = 3; - protected $strategy; + protected $strategy, $page; protected function _renderHeadScriptsOn($script_loader) { $this->getStrategy()->getHeadScript(); @@ -51,7 +51,8 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base ->setPreferences($this->preferences) ->setIdModule($this->id_module) ->setAccueilSito($this) - ->setDivision($this->division); + ->setDivision($this->division) + ->setPage($this->page); } @@ -91,6 +92,12 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base return (array_isset('group_by_categorie', $this->preferences) && true == $this->getPreference('group_by_categorie')); } + + + public function setPage($page) { + $this->page = $page; + return $this; + } } @@ -103,7 +110,8 @@ class SitoDisplayStrategy { $view, $preferences, $id_module, - $divisionm; + $division, + $page; public function setView($view) { @@ -136,6 +144,12 @@ class SitoDisplayStrategy { } + public function setPage($page) { + $this->page = $page; + return $this; + } + + public function getTitle() { $widget_title = isset($this->preferences['titre']) ? $this->preferences['titre'] @@ -146,7 +160,8 @@ class SitoDisplayStrategy { $this->view->url(['module' => 'opac', 'controller' => 'sito', 'action' => 'viewselection', - 'id_module' => $this->id_module], null, true)); + 'id_module' => $this->id_module, + 'id_division' => $this->division], null, true)); } @@ -183,7 +198,8 @@ class SitoDisplayStrategy { if (!$sites) return ''; - $sites = array_slice($sites, 0, $nb_aff); + $start = $this->page ? $this->page - 1 : 0; + $sites = array_slice($sites, $start, $nb_aff); if (!$this->getPreference('group_by_categorie')) return $this->_renderSites($sites); @@ -243,10 +259,10 @@ class SelectedStrategy extends SitoDisplayStrategy { if (static::ORDER_RANDOM == $this->getPreference('display_order')) { shuffle($sites); - return $this->renderSitesWithPagination($sites, $this->getPreference('nb_aff')); - } + return $this->renderSitesSlice($sites, $this->getPreference('nb_aff')); - return $this->renderSitesSlice($sites, count($sites)); + } + return $this->renderSitesWithPagination($sites, $this->getPreference('nb_aff')); } @@ -254,7 +270,7 @@ class SelectedStrategy extends SitoDisplayStrategy { if(count($sites) <= $nb_sites_by_pages) return $this->renderSitesSlice($sites, $nb_sites_by_pages); - return $this->renderSitesSlice($sites, $nb_sites_by_pages) . $this->getPaginator($sites, $nb_sites_by_pages); + return $this->renderSitesSlice($sites, $nb_sites_by_pages) . $this->getPaginator($sites, $nb_sites_by_pages, $this->page); } @@ -264,7 +280,9 @@ class SelectedStrategy extends SitoDisplayStrategy { ->setCurrentPageNumber($page); return $this->view->paginationControl($paginator, null, null, ['url_link' => ['module' => 'opac', 'controller' => 'sito', - 'action' => 'widget-page']]); + 'action' => 'widget-page', + 'id_module' => $this->id_module, + 'id_division' => $this->division]]); } } diff --git a/library/ZendAfi/View/Helper/PublicListViewMode.php b/library/ZendAfi/View/Helper/PublicListViewMode.php index ef9dd9a4338..ab50e2c2447 100644 --- a/library/ZendAfi/View/Helper/PublicListViewMode.php +++ b/library/ZendAfi/View/Helper/PublicListViewMode.php @@ -25,7 +25,7 @@ class ZendAfi_View_Helper_PublicListViewMode extends ZendAfi_View_Helper_Admin_ public function publicListViewMode($list, $item_renderer=null) { $default_item_renderer = function($item) { - return $this->view->getHelper('SitoTree')->renderSite($item); + return $this->view->renderSito($item); }; $this->_item_renderer = $item_renderer ? diff --git a/tests/application/modules/opac/controllers/SitoControllerTest.php b/tests/application/modules/opac/controllers/SitoControllerTest.php index 8cc5b3fccb1..4877ca29e79 100644 --- a/tests/application/modules/opac/controllers/SitoControllerTest.php +++ b/tests/application/modules/opac/controllers/SitoControllerTest.php @@ -50,7 +50,9 @@ abstract class SitoControllerTestCase extends AbstractControllerTestCase { 'type_module' => 'SITO', 'preferences' => ['id_categorie' => '3', 'id_items' => '25-28', - 'rss_status' => 1] + 'rss_status' => 1, + 'nb_aff' => 1, + 'display_order' => 'Selection'] ] ], 'options' => []]); @@ -437,4 +439,34 @@ class SitoControllerRssWithoutProfileTest extends AbstractControllerTestCase { $this->assertXPathContentContains('//channel/title', 'Flux indisponible', $this->_response->getBody()); } } + + + + +class SitoControllerPaginationTest extends SitoControllerTestCase { + public function setUp() { + parent::setUp(); + + $this->dispatch('/sito/widget-page/id_module/1/id_division/2/page/2', true); + } + + + /** @test */ + public function linuxFrShouldBeVisible() { + $this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]', + $this->_response->getBody()); + } + + + /** @test */ + public function page1LinkShouldBePresent() { + $this->assertXPathContentContains('//div[@class="paginationControl"]//a[contains(@href, "/page/1")]', '1', $this->_response->getBody()); + } + + + /** @test */ + public function suivantLinkShouldNotBePresent() { + $this->assertXPathContentContains('//div[@class="paginationControl"]//span[@class="disabled"]', 'Suivant', $this->_response->getBody()); + } +} ?> -- GitLab