First attempt to add paging in the OPDS side.
Need more polishing before being used everywhere. --HG-- extra : rebase_source : 0fb3a4b12cf83d4b450a1fca81f82addd8d58c14
This commit is contained in:
parent
43f489051d
commit
4c9e8c67d0
|
@ -200,18 +200,27 @@ class OPDSRenderer
|
|||
}
|
||||
|
||||
public function render ($page) {
|
||||
global $config;
|
||||
self::startXmlDocument ($page->title, $page->idPage);
|
||||
if ($page->query)
|
||||
if ($config['cops_max_item_per_page'] != -1 && $page->totalNumber != -1)
|
||||
{
|
||||
self::getXmlStream ()->startElement ("opensearch:totalResults");
|
||||
self::getXmlStream ()->text (count($page->entryArray));
|
||||
self::getXmlStream ()->text ($page->totalNumber);
|
||||
self::getXmlStream ()->endElement ();
|
||||
self::getXmlStream ()->startElement ("opensearch:itemsPerPage");
|
||||
self::getXmlStream ()->text (count($page->entryArray));
|
||||
self::getXmlStream ()->text ($config['cops_max_item_per_page']);
|
||||
self::getXmlStream ()->endElement ();
|
||||
self::getXmlStream ()->startElement ("opensearch:startIndex");
|
||||
self::getXmlStream ()->text ("1");
|
||||
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"));
|
||||
}
|
||||
if (($page->n + 1) * $config['cops_max_item_per_page'] < $page->totalNumber) {
|
||||
self::renderLink (new LinkNavigation ($currentUrl . "&n=" . ($page->n + 1), "next", "Page suivante"));
|
||||
}
|
||||
}
|
||||
foreach ($page->entryArray as $entry) {
|
||||
self::getXmlStream ()->startElement ("entry");
|
||||
|
|
58
base.php
58
base.php
|
@ -80,6 +80,7 @@ class Link
|
|||
const OPDS_IMAGE_TYPE = "http://opds-spec.org/image";
|
||||
const OPDS_ACQUISITION_TYPE = "http://opds-spec.org/acquisition";
|
||||
const OPDS_NAVIGATION_TYPE = "application/atom+xml;profile=opds-catalog;kind=navigation";
|
||||
const OPDS_PAGING_TYPE = "application/atom+xml;profile=opds-catalog;kind=acquisition";
|
||||
|
||||
public $href;
|
||||
public $type;
|
||||
|
@ -190,43 +191,46 @@ class Page
|
|||
public $idPage;
|
||||
public $idGet;
|
||||
public $query;
|
||||
public $n;
|
||||
public $totalNumber = -1;
|
||||
public $entryArray = array();
|
||||
|
||||
public static function getPage ($pageId, $id, $query)
|
||||
public static function getPage ($pageId, $id, $query, $n)
|
||||
{
|
||||
switch ($pageId) {
|
||||
case Base::PAGE_ALL_AUTHORS :
|
||||
return new PageAllAuthors ($id, $query);
|
||||
return new PageAllAuthors ($id, $query, $n);
|
||||
case Base::PAGE_AUTHOR_DETAIL :
|
||||
return new PageAuthorDetail ($id, $query);
|
||||
return new PageAuthorDetail ($id, $query, $n);
|
||||
case Base::PAGE_ALL_TAGS :
|
||||
return new PageAllTags ($id, $query);
|
||||
return new PageAllTags ($id, $query, $n);
|
||||
case Base::PAGE_TAG_DETAIL :
|
||||
return new PageTagDetail ($id, $query);
|
||||
return new PageTagDetail ($id, $query, $n);
|
||||
case Base::PAGE_ALL_SERIES :
|
||||
return new PageAllSeries ($id, $query);
|
||||
return new PageAllSeries ($id, $query, $n);
|
||||
case Base::PAGE_ALL_BOOKS :
|
||||
return new PageAllBooks ($id, $query);
|
||||
return new PageAllBooks ($id, $query, $n);
|
||||
case Base::PAGE_ALL_BOOKS_LETTER:
|
||||
return new PageAllBooksLetter ($id, $query);
|
||||
return new PageAllBooksLetter ($id, $query, $n);
|
||||
case Base::PAGE_ALL_RECENT_BOOKS :
|
||||
return new PageRecentBooks ($id, $query);
|
||||
return new PageRecentBooks ($id, $query, $n);
|
||||
case Base::PAGE_SERIE_DETAIL :
|
||||
return new PageSerieDetail ($id, $query);
|
||||
return new PageSerieDetail ($id, $query, $n);
|
||||
case Base::PAGE_OPENSEARCH_QUERY :
|
||||
return new PageQueryResult ($id, $query);
|
||||
return new PageQueryResult ($id, $query, $n);
|
||||
break;
|
||||
default:
|
||||
$page = new Page ($id, $query);
|
||||
$page = new Page ($id, $query, $n);
|
||||
$page->idPage = "cops:catalog";
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct($pid, $pquery) {
|
||||
public function __construct($pid, $pquery, $pn) {
|
||||
$this->idGet = $pid;
|
||||
$this->query = $pquery;
|
||||
}
|
||||
$this->n = $pn;
|
||||
}
|
||||
|
||||
public function InitializeContent ()
|
||||
{
|
||||
|
@ -318,7 +322,7 @@ class PageAllBooksLetter extends Page
|
|||
public function InitializeContent ()
|
||||
{
|
||||
$this->title = str_format (localize ("splitByLetter.letter"), localize ("bookword.title"), $this->idGet);
|
||||
$this->entryArray = Book::getBooksByStartingLetter ($this->idGet);
|
||||
list ($this->entryArray, $this->totalNumber) = Book::getBooksByStartingLetter ($this->idGet, $this->n);
|
||||
$this->idPage = Book::getEntryIdByLetter ($this->idGet);
|
||||
}
|
||||
}
|
||||
|
@ -373,6 +377,28 @@ abstract class Base
|
|||
}
|
||||
}
|
||||
return self::$db;
|
||||
}
|
||||
}
|
||||
|
||||
public static function executeQuery($query, $columns, $params, $n) {
|
||||
global $config;
|
||||
$totalResult = -1;
|
||||
|
||||
if ($config['cops_max_item_per_page'] != -1)
|
||||
{
|
||||
// First check total number of results
|
||||
$result = self::getDb ()->prepare (str_format ($query, "count(*)"));
|
||||
$result->execute ($params);
|
||||
$totalResult = $result->fetchColumn ();
|
||||
|
||||
// Next modify the query and params
|
||||
$query .= " limit ?, ?";
|
||||
array_push ($params, ($n - 1) * $config['cops_max_item_per_page'], $config['cops_max_item_per_page']);
|
||||
}
|
||||
|
||||
$result = self::getDb ()->prepare(str_format ($query, $columns));
|
||||
$result->execute ($params);
|
||||
return array ($totalResult, $result);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
10
book.php
10
book.php
|
@ -363,19 +363,17 @@ order by substr (upper (sort), 1, 1)");
|
|||
return $entryArray;
|
||||
}
|
||||
|
||||
public static function getBooksByStartingLetter($letter) {
|
||||
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
|
||||
public static function getBooksByStartingLetter($letter, $n) {
|
||||
list ($totalNumber, $result) = parent::executeQuery ('select {0}
|
||||
from books left outer join comments on book = books.id
|
||||
where upper (books.sort) like ?');
|
||||
where upper (books.sort) like ?', self::BOOK_COLUMNS, array ($letter . "%"), $n);
|
||||
$entryArray = array();
|
||||
$queryLike = $letter . "%";
|
||||
$result->execute (array ($queryLike));
|
||||
while ($post = $result->fetchObject ())
|
||||
{
|
||||
$book = new Book ($post);
|
||||
array_push ($entryArray, $book->getEntry ());
|
||||
}
|
||||
return $entryArray;
|
||||
return array ($entryArray, $totalNumber);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -97,5 +97,11 @@
|
|||
* 0 : always generate valid OPDS code
|
||||
*/
|
||||
$config['cops_generate_invalid_opds_stream'] = "0";
|
||||
|
||||
/*
|
||||
* Max number of items per page
|
||||
*/
|
||||
$config['cops_max_item_per_page'] = "2";
|
||||
|
||||
|
||||
?>
|
3
feed.php
3
feed.php
|
@ -18,6 +18,7 @@
|
|||
header ("Content-Type:application/xml");
|
||||
$page = getURLParam ("page", Base::PAGE_INDEX);
|
||||
$query = getURLParam ("query");
|
||||
$n = getURLParam ("n", "1");
|
||||
if ($query)
|
||||
$page = Base::PAGE_OPENSEARCH_QUERY;
|
||||
$qid = getURLParam ("id");
|
||||
|
@ -29,7 +30,7 @@
|
|||
echo $OPDSRender->getOpenSearch ();
|
||||
return;
|
||||
default:
|
||||
$currentPage = Page::getPage ($page, $qid, $query);
|
||||
$currentPage = Page::getPage ($page, $qid, $query, $n);
|
||||
$currentPage->InitializeContent ();
|
||||
echo $OPDSRender->render ($currentPage);
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue