diff --git a/application/modules/opac/controllers/SitoController.php b/application/modules/opac/controllers/SitoController.php index a6edf0648e429eaaab409628d98b27431319d0ec..b5a0a6eb072928990bb8d1f7128d910ed3f76d76 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 b1a45a765be81cc80bfe11a1bbdd2daea57ed292..eae47faa233b27e5e091e9f319f3bcb5ca224f3c 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 0000000000000000000000000000000000000000..eeda9cb638de385248d5ddbbb0240b88276e2fdc --- /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 c9be0b873bd4163ba8454de1e1d347f1ebab3a85..9be15520cadccf164d2b6e409cdcdd134b992160 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 ef9dd9a4338b4c5cd812f776ab5b100ca2168cce..ab50e2c2447439a142ed8d92ae5df82a9705299b 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 8cc5b3fccb112a61df25f53911d66dc52a901f2d..4877ca29e79844d774d15ec40e607280795b3a17 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()); + } +} ?>