forked from seblucas/cops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserie.php
76 lines (66 loc) · 2.47 KB
/
serie.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* COPS (Calibre OPDS PHP Server) class file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <[email protected]>
*/
require_once('base.php');
class Serie extends Base {
const ALL_SERIES_ID = "calibre:series";
public $id;
public $name;
public function __construct($pid, $pname) {
$this->id = $pid;
$this->name = $pname;
}
public function getUri () {
return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id";
}
public function getEntryId () {
return self::ALL_SERIES_ID.":".$this->id;
}
public static function getCount() {
$nSeries = parent::getDb ()->query('select count(*) from series')->fetchColumn();
if ($nSeries == 0) return NULL;
$entry = new Entry (localize("series.title"), self::ALL_SERIES_ID,
str_format (localize("series.alphabetical", $nSeries), $nSeries), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_SERIES)));
return $entry;
}
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;
}
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;
}
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');
$entryArray = array();
while ($post = $result->fetchObject ())
{
$serie = new Serie ($post->id, $post->sort);
array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($serie->getUri ()))));
}
return $entryArray;
}
}
?>