Commit ef83712a authored by lbrun's avatar lbrun

dev#23223_sito_widget_pagination : add reload picto for random paged config

parent 5daf38c2
......@@ -102,3 +102,21 @@ See _Class\_Users>>registerNotificationsOn_ for notifications usage.
## ILS Web services
Add _Class\_WebService\_SIGB\_Reservation>>isWaitingToBePulled_ that returns _true_ when holded document is available in library. Works for: Nanook, Koha, Microbib, Aloes, Carthame, Orphée, Pergame.
# Reload module content with AJAX
On module ajax link, add tag attributes: 'data-reload-module = true'.
For example:
```php
$this->view->tagAnchor($reload_link,
'',
['data-ajax-reload' => 'true',
'class' => 'reload-module',
'title' => $this->view->_('Recharger')]);
```
See public/opac/js/reload_module.js
\ No newline at end of file
......@@ -23,7 +23,7 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base
const ORDER_RANDOM = 'Random';
const ORDER_SELECTION = 'Selection';
const DISPLAY_SELECTION = 1;
const DISPLAY_PAGED = 1;
const DISPLAY_GROUPED = 2;
const DISPLAY_HIERARCHY = 3;
......@@ -38,10 +38,10 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base
if($this->strategy)
return $this->strategy;
$strategy = new SelectedStrategy();
$strategy = new PagedStrategy();
if($this->isHierarchicalDisplay())
$strategy = new HierrachicalStrategy();
$strategy = new HierachicalStrategy();
if($this->isTypeAffichageGrouped())
$strategy = new GroupedStrategy();
......@@ -68,8 +68,8 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base
}
public function isTypeAffichageSelection() {
return $this->_isDisplayType(static::DISPLAY_SELECTION);
public function isTypeAffichagePaged() {
return $this->_isDisplayType(static::DISPLAY_PAGED);
}
......@@ -218,17 +218,18 @@ class SitoDisplayStrategy {
class SelectedStrategy extends SitoDisplayStrategy {
class PagedStrategy extends SitoDisplayStrategy {
public function getContent() {
$nb_aff = $this->getPreference('nb_aff') ? $this->getPreference('nb_aff') : $this->_getDefaultNbAff();
$sites = $this->_loadSites();
if (static::ORDER_RANDOM == $this->getPreference('display_order')) {
if (static::ORDER_RANDOM == $this->getPreference('display_order'))
shuffle($sites);
return $this->renderSitesSlice($sites, $nb_aff);
}
return $this->renderSitesWithPagination($sites, $nb_aff);
return
$this->renderSitesSlice($sites, $nb_aff)
. $this->getPaginator($sites, $nb_aff, $this->page);
}
protected function _getDefaultNbAff() {
......@@ -237,25 +238,33 @@ class SelectedStrategy extends SitoDisplayStrategy {
}
protected function renderSitesWithPagination($sites, $nb_sites_by_pages) {
if(count($sites) <= $nb_sites_by_pages)
return $this->renderSitesSlice($sites, $nb_sites_by_pages);
protected function getPaginator($items, $items_by_page, $page = 1) {
if (count($items) <= $items_by_page)
return '';
return $this->renderSitesSlice($sites, $nb_sites_by_pages) . $this->getPaginator($sites, $nb_sites_by_pages, $this->page);
}
$reload_link = ['module' => 'opac',
'controller' => 'sito',
'action' => 'widget-page',
'id_module' => $this->id_module,
'id_division' => $this->division];
if (static::ORDER_RANDOM == $this->getPreference('display_order'))
return $this->view->tagAnchor($reload_link,
'',
['data-ajax-reload' => 'true',
'class' => 'reload-module',
'title' => $this->view->_('Recharger')]);
protected function getPaginator($items, $items_by_page, $page = 1) {
$paginator = (new Zend_Paginator(new Zend_Paginator_Adapter_Null(count($items))))
->setItemCountPerPage(max($items_by_page, 1))
->setCurrentPageNumber($page);
return $this->view->paginationControl($paginator, null, null, ['url_link' => ['module' => 'opac',
'controller' => 'sito',
'action' => 'widget-page',
'id_module' => $this->id_module,
'id_division' => $this->division],
'link_attribs' => [ 'data-ajax-reload' => 'true' ]
]);
return $this->view->paginationControl($paginator,
null,
null,
['url_link' => $reload_link,
'link_attribs' => [ 'data-ajax-reload' => 'true' ]
]);
}
}
......@@ -314,7 +323,7 @@ class GroupedStrategy extends SitoDisplayStrategy {
class HierrachicalStrategy extends SitoDisplayStrategy {
class HierachicalStrategy extends SitoDisplayStrategy {
public function getContent() {
return $this->view->sitoTree($this->getPreference('id_categorie'));
}
......
......@@ -727,6 +727,12 @@ select{color:#666666;font-family:Arial;font-size:1em;}
padding-top: 10px;
}
.boite.sito a.reload-module {
background: url('../../admin/images/picto/reload.png') no-repeat;
display: block;
width: 16px;
height: 16px;
}
ul.sitotheque,
ul.sitotheque ul {
......
......@@ -205,6 +205,30 @@ class SitoViewHelperSelectItemsByRandomOrderTest extends SitoViewHelperTestCase
$this->assertEquals(2, count(array_unique($htmls)));
}
/** @test */
public function pageShouldNotContainsLinkToReloadModule() {
$this->assertNotXPath($this->html, '//a[contains(@href, "sito/widget-page/id_module/2/id_division/1")]');
}
}
class SitoViewHelperSelectItemsByRandomOrderWithOneSiteTest extends SitoViewHelperTestCase {
protected $_preferences = ['titre' => 'Ma sito',
'type_aff' => 1,
'id_items' => '12-15',
'id_categorie' => '',
'nb_aff' => 1,
'display_order' => 'Random'];
/** @test */
public function pageShouldContainsLinkToReloadModule() {
$this->assertXPath($this->html, '//a[@class="reload-module"][contains(@href, "sito/widget-page/id_module/2/id_division/1")]');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment