Refactoring

This commit is contained in:
Sébastien Lucas 2012-09-21 14:19:11 +02:00
parent be4bcf3e9f
commit 14b06905d5
3 changed files with 14 additions and 8 deletions

View file

@ -202,7 +202,7 @@ class OPDSRenderer
public function render ($page) {
global $config;
self::startXmlDocument ($page->title, $page->idPage);
if ($config['cops_max_item_per_page'] != -1 && $page->totalNumber != -1)
if ($page->isPaginated ())
{
self::getXmlStream ()->startElement ("opensearch:totalResults");
self::getXmlStream ()->text ($page->totalNumber);
@ -213,13 +213,13 @@ class OPDSRenderer
self::getXmlStream ()->startElement ("opensearch:startIndex");
self::getXmlStream ()->text (($page->n - 1) * $config['cops_max_item_per_page'] + 1);
self::getXmlStream ()->endElement ();
$currentUrl = $_SERVER['QUERY_STRING'];
$currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . $_SERVER['QUERY_STRING']);
if ($page->n > 1) {
self::renderLink (new LinkNavigation ($currentUrl . "&n=" . ($page->n - 1), "previous", "Page precedente"));
$prevLink = $page->getPrevLink ();
$nextLink = $page->getNextLink ();
if (!is_null ($prevLink)) {
self::renderLink ($prevLink);
}
if (($page->n + 1) * $config['cops_max_item_per_page'] < $page->totalNumber) {
self::renderLink (new LinkNavigation ($currentUrl . "&n=" . ($page->n + 1), "next", "Page suivante"));
if (!is_null ($nextLink)) {
self::renderLink ($nextLink);
}
}
foreach ($page->entryArray as $entry) {

View file

@ -242,6 +242,12 @@ class Page
$this->entryArray = array_merge ($this->entryArray, Book::getCount());
}
public function isPaginated ()
{
global $config;
return ($config['cops_max_item_per_page'] != -1 && $this->totalNumber != -1);
}
public function getNextLink ()
{
global $config;

View file

@ -219,7 +219,7 @@
?>
</div>
<?php
if ($config['cops_max_item_per_page'] != -1 && $currentPage->totalNumber != -1) {
if ($currentPage->isPaginated ()) {
$prevLink = $currentPage->getPrevLink ();
$nextLink = $currentPage->getNextLink ();
?>