2012-05-28 08:01:33 +03:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* COPS (Calibre OPDS PHP Server) class file
|
|
|
|
|
*
|
|
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
|
|
|
|
* @author S<EFBFBD>bastien Lucas <sebastien@slucas.fr>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
require_once('base.php');
|
|
|
|
|
|
|
|
|
|
class Serie extends Base {
|
2013-10-25 08:59:27 +03:00
|
|
|
|
const ALL_SERIES_ID = "cops:series";
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
public $id;
|
|
|
|
|
public $name;
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
public function __construct($pid, $pname) {
|
|
|
|
|
$this->id = $pid;
|
|
|
|
|
$this->name = $pname;
|
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
public function getUri () {
|
2012-05-28 08:06:12 +03:00
|
|
|
|
return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id";
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-28 08:07:49 +03:00
|
|
|
|
public function getEntryId () {
|
|
|
|
|
return self::ALL_SERIES_ID.":".$this->id;
|
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
|
|
|
|
|
public static function getCount() {
|
|
|
|
|
$nSeries = parent::getDb ()->query('select count(*) from series')->fetchColumn();
|
2013-05-21 10:10:05 +03:00
|
|
|
|
if ($nSeries == 0) return NULL;
|
2013-12-05 11:52:51 +02:00
|
|
|
|
$entry = new Entry (localize("series.title"), self::ALL_SERIES_ID,
|
|
|
|
|
str_format (localize("series.alphabetical", $nSeries), $nSeries), "text",
|
2012-05-28 08:06:12 +03:00
|
|
|
|
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_SERIES)));
|
2012-05-28 08:05:05 +03:00
|
|
|
|
return $entry;
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
public static function getSerieByBookId ($bookId) {
|
|
|
|
|
$result = parent::getDb ()->prepare('select series.id as id, name
|
|
|
|
|
from books_series_link, series
|
|
|
|
|
where series.id = series and book = ?');
|
|
|
|
|
$result->execute (array ($bookId));
|
|
|
|
|
if ($post = $result->fetchObject ()) {
|
|
|
|
|
return new Serie ($post->id, $post->name);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
public static function getSerieById ($serieId) {
|
|
|
|
|
$result = parent::getDb ()->prepare('select id, name from series where id = ?');
|
|
|
|
|
$result->execute (array ($serieId));
|
|
|
|
|
if ($post = $result->fetchObject ()) {
|
|
|
|
|
return new Serie ($post->id, $post->name);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
public static function getAllSeries() {
|
|
|
|
|
$result = parent::getDb ()->query('select series.id as id, series.name as name, series.sort as sort, count(*) as count
|
|
|
|
|
from series, books_series_link
|
|
|
|
|
where series.id = series
|
|
|
|
|
group by series.id, series.name, series.sort
|
|
|
|
|
order by series.sort');
|
2012-05-28 08:05:05 +03:00
|
|
|
|
$entryArray = array();
|
2012-05-28 08:01:33 +03:00
|
|
|
|
while ($post = $result->fetchObject ())
|
|
|
|
|
{
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$serie = new Serie ($post->id, $post->sort);
|
2013-12-05 11:52:51 +02:00
|
|
|
|
array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (),
|
|
|
|
|
str_format (localize("bookword", $post->count), $post->count), "text",
|
2012-05-28 08:07:49 +03:00
|
|
|
|
array ( new LinkNavigation ($serie->getUri ()))));
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
2012-05-28 08:05:05 +03:00
|
|
|
|
return $entryArray;
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2013-09-27 18:10:07 +03:00
|
|
|
|
public static function getAllSeriesByQuery($query) {
|
2014-05-12 23:15:51 +03:00
|
|
|
|
$columns = "series.id as id, series.name as name, series.sort as sort, count(*) as count";
|
|
|
|
|
$sql = 'select {0} from series, books_series_link
|
|
|
|
|
where series.id = series and upper (series.name) like ?
|
2013-09-27 18:10:07 +03:00
|
|
|
|
group by series.id, series.name, series.sort
|
2014-05-12 23:15:51 +03:00
|
|
|
|
order by series.sort';
|
2014-05-16 16:09:18 +03:00
|
|
|
|
list (, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), -1);
|
2013-09-27 18:10:07 +03:00
|
|
|
|
$entryArray = array();
|
|
|
|
|
while ($post = $result->fetchObject ())
|
|
|
|
|
{
|
|
|
|
|
$serie = new Serie ($post->id, $post->sort);
|
2013-12-05 11:52:51 +02:00
|
|
|
|
array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (),
|
|
|
|
|
str_format (localize("bookword", $post->count), $post->count), "text",
|
2013-09-27 18:10:07 +03:00
|
|
|
|
array ( new LinkNavigation ($serie->getUri ()))));
|
|
|
|
|
}
|
|
|
|
|
return $entryArray;
|
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|