-
Notifications
You must be signed in to change notification settings - Fork 1
/
serie.php
179 lines (131 loc) · 5.46 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
* COPS (Calibre OPDS PHP Server) class file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
*/
require_once('base.php');
define(
'SERIES_SQL',
"SELECT n.SeqId AS id, SeqName AS sort, SeqName AS name "
." FROM libseqname n"
);
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 libseqname')->fetchColumn();
$entry = new Entry (localize("series.title"), self::ALL_SERIES_ID,
str_format (localize("series.alphabetical"), $nSeries), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_SERIES)));
return $entry;
}
public static function getAllSeriesByFirstLetter() {
$query ='SELECT SUBSTRING(UPPER(SeqName), 1, 1) as title, count(*) as count'
.' FROM libseqname'
.' GROUP BY SUBSTRING(UPPER(SeqName), 1, 1)'
.' ORDER BY SUBSTRING(UPPER(SeqName), 1, 1)'
;
$result = parent::getDb()->query($query);
$entryArray = array();
while ( $post = $result->fetchObject () )
{
array_push ($entryArray, new Entry ($post->title, self::getEntryIdByLetter ($post->title),
str_format (localize("seriesword", $post->count), $post->count), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_SERIES_FIRST_LETTER."&id=". rawurlencode ($post->title)))));
}
return $entryArray;
}
public static function getSeriesByStartingLetter($letter) {
$SQL_AUTHORS_BY_FIRST_LETTER= "SELECT {0} FROM libseqname "
." JOIN libseq ON libseq.SeqId= libseqname.SeqId"
." WHERE UPPER(libseqname.SeqName) like ? "
." GROUP BY libseq.SeqId, libseqname.SeqName"
." ORDER BY libseqname.SeqName";
return self::getEntryArray ($SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%"));
}
public static function getEntryArray ($query, $params) {
$COLUMNS = "libseqname.SeqId, libseqname.SeqName, COUNT(*)";
$entryArray = array();
list ($totalNumber, $result) = parent::getDb()->executeQuery($query, $COLUMNS, "", $params, -1);
$aid =null;
$aname =null;
$count =null;
$result->bind_result($aid, $aname, $count);
while ($result->fetch())
{
$serie = new Serie ($aid, $aname);
array_push ($entryArray, new Entry ($aname, $serie->getEntryId (),
str_format (localize("bookword", $count), $count), "text",
array ( new LinkNavigation ($serie->getUri ()))));
}
$result->close();
return $entryArray;
}
public static function getEntryIdByLetter ($startingLetter) {
return self::ALL_SERIES_ID.":letter:".$startingLetter;
}
public static function getSerieByBookId ($bookId) {
$query = "SELECT a.SeqId AS id, SeqName AS name"
." FROM libseq a, libseqname n"
." WHERE a.BookId = ?"
." AND a.SeqId = n.SeqId"
;
$params = array ($bookId);
list ($totalNumber, $stmt) = parent::getDb()->executeQuery($query, '', '', $params);
$result = $stmt->get_result();
$post = $result->fetch_object();
if ($post)
return new Serie ($post->id, $post->name);
else
return NULL;
}
public static function getSerieById ($serieId) {
$query = 'SELECT SeqId AS id, SeqName AS name'
." FROM libseqname "
." WHERE SeqId = ?"
;
$params = array ($serieId);
list ($totalNumber, $stmt) = parent::getDb()->executeQuery($query, '', '', $params);
$result = $stmt->get_result();
$post = $result->fetch_object();
if ($post)
return new Serie ($post->id, $post->name);
else
return NULL;
}
//TODO
public static function getAllSeries() {
$query = "SELECT n.SeqId AS id, SeqName AS sort, SeqName AS name, count(*) as count"
." FROM libseqname n"
." JOIN libseq a ON a.SeqId = n.SeqId"
." GROUP BY n.SeqId, n.SeqName"
." ORDER BY n.SeqName"
;
$params = array ();
list ($totalNumber, $stmt) = parent::getDb()->executeQuery($query, '', '', $params);
$result = $stmt->get_result();
$entryArray = array();
while ($post = $result->fetch_object())
{
$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;
}
}
?>