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

View file

@ -242,6 +242,12 @@ class Page
$this->entryArray = array_merge ($this->entryArray, Book::getCount()); $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 () public function getNextLink ()
{ {
global $config; global $config;

View file

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