3 * COPS (Calibre OPDS PHP Server) class file
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Sébastien Lucas <sebastien@slucas.fr>
9 require_once('base.php');
11 class Serie extends Base {
12 const ALL_SERIES_ID = "calibre:series";
17 public function __construct($pid, $pname) {
22 public function getUri () {
23 return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id";
26 public function getEntryId () {
27 return self::ALL_SERIES_ID.":".$this->id;
30 public function getEntryIdByLetters ($letters) {
31 return self::ALL_SERIES_ID.":letters:".$letters;
34 public static function getCount() {
35 $nSeries = parent::getDb ()->query('select count(*) from series')->fetchColumn(0);
36 if ($nSeries == 0) return NULL;
37 $entry = new Entry (localize("series.title"), self::ALL_SERIES_ID,
38 str_format (localize("series.alphabetical", $nSeries), $nSeries), "text",
39 array ( new LinkNavigation ("?page=".parent::PAGE_ALL_SERIES)));
43 public static function getSerieByBookId ($bookId) {
44 $result = parent::getDb ()->prepare('select series.id as id, name
45 from books_series_link, series
46 where series.id = series and book = ?');
47 $result->execute (array ($bookId));
48 if ($post = $result->fetchObject ()) {
49 return new Serie ($post->id, $post->name);
54 public static function getSerieById ($serieId) {
55 $result = parent::getDb ()->prepare('select id, name from series where id = ?');
56 $result->execute (array ($serieId));
57 if ($post = $result->fetchObject ()) {
58 return new Serie ($post->id, $post->name);
63 public static function getAllSeries($letters) {
64 if (!$letters) { $letters=''; }
65 $len = mb_strlen($letters,'UTF-8')+1;
66 $result = parent::getDb ()->query('select
67 substr(series.sort,1,'.$len.') as sort,
69 count(distinct series.id) ser_count,
70 count(distinct series.sort) sort_cnt,
71 min(series.id) min_id, min(series.sort) min_sort
73 (select series,count(*) as count from books_series_link group by series) link
74 where series.id = link.series and series.sort like "'.$letters.'%"
75 group by substr(series.sort,1,'.$len.')
76 order by substr(series.sort,1,'.$len.')');
77 $entryArray = array();
78 while ($post = $result->fetchObject ())
80 if ($post->ser_count==1) {
81 $serie = new Serie ($post->min_id, $post->min_sort);
82 $title = $serie->name;
83 $link = array ( new LinkNavigation ($serie->getUri ()));
84 } elseif ($post->ser_count > parent::maxItemsPerPage() && $post->sort_cnt>1) {
85 $page = parent::PAGE_ALL_SERIES;
86 $title = $post->sort.'...';
87 $link = array ( new LinkNavigation ("?page=".$page."&id=". rawurlencode ($post->sort)));
89 $page = parent::PAGE_SERIES_STARTING_LETTERS;
90 $title = $post->sort.'...';
91 $link = array ( new LinkNavigation ("?page=".$page."&id=". rawurlencode ($post->sort)));
93 array_push ($entryArray, new Entry ($title, Serie::getEntryIdByLetters($post->sort),
94 str_format (localize("bookword", $post->count), $post->count), "text",
102 public static function getAllSeriesStartingLetters($letters) {
103 $result = parent::getDb ()->query('
105 series.id as id, series.name as name, series.sort as sort,
108 (select series,count(*) as count from books_series_link group by series) link
109 where series.id = link.series and series.sort like "'.$letters.'%"
110 group by series.id, series.name, series.sort
111 order by series.sort');
112 $entryArray = array();
113 while ($post = $result->fetchObject ())
115 $serie = new Serie ($post->id, $post->sort);
116 array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (),
117 str_format (localize("bookword", $post->count), $post->count), "text",
118 array ( new LinkNavigation ($serie->getUri ()))));