These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * COPS (Calibre OPDS PHP Server) class file |
||
4 | * |
||
5 | * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
||
6 | * @author S�bastien Lucas <[email protected]> |
||
7 | */ |
||
8 | |||
9 | require_once('base.php'); |
||
10 | require_once('serie.php'); |
||
11 | require_once('author.php'); |
||
12 | require_once('rating.php'); |
||
13 | require_once('publisher.php'); |
||
14 | require_once('tag.php'); |
||
15 | require_once('language.php'); |
||
16 | require_once("customcolumn.php"); |
||
17 | require_once('data.php'); |
||
18 | require_once('resources/php-epub-meta/epub.php'); |
||
19 | |||
20 | // Silly thing because PHP forbid string concatenation in class const |
||
21 | define ('SQL_BOOKS_LEFT_JOIN', "left outer join comments on comments.book = books.id |
||
22 | left outer join books_ratings_link on books_ratings_link.book = books.id |
||
23 | left outer join ratings on books_ratings_link.rating = ratings.id "); |
||
24 | define ('SQL_BOOKS_ALL', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " order by books.sort "); |
||
25 | define ('SQL_BOOKS_BY_PUBLISHER', "select {0} from books_publishers_link, books " . SQL_BOOKS_LEFT_JOIN . " |
||
26 | where books_publishers_link.book = books.id and publisher = ? {1} order by publisher"); |
||
27 | define ('SQL_BOOKS_BY_FIRST_LETTER', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
28 | where upper (books.sort) like ? order by books.sort"); |
||
29 | define ('SQL_BOOKS_BY_AUTHOR', "select {0} from books_authors_link, books " . SQL_BOOKS_LEFT_JOIN . " |
||
30 | left outer join books_series_link on books_series_link.book = books.id |
||
31 | where books_authors_link.book = books.id and author = ? {1} order by series desc, series_index asc, pubdate asc"); |
||
32 | define ('SQL_BOOKS_BY_SERIE', "select {0} from books_series_link, books " . SQL_BOOKS_LEFT_JOIN . " |
||
33 | where books_series_link.book = books.id and series = ? {1} order by series_index"); |
||
34 | define ('SQL_BOOKS_BY_TAG', "select {0} from books_tags_link, books " . SQL_BOOKS_LEFT_JOIN . " |
||
35 | where books_tags_link.book = books.id and tag = ? {1} order by sort"); |
||
36 | define ('SQL_BOOKS_BY_LANGUAGE', "select {0} from books_languages_link, books " . SQL_BOOKS_LEFT_JOIN . " |
||
37 | where books_languages_link.book = books.id and lang_code = ? {1} order by sort"); |
||
38 | define ('SQL_BOOKS_BY_CUSTOM', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . " |
||
39 | where {2}.book = books.id and {2}.{3} = ? {1} order by sort"); |
||
40 | define ('SQL_BOOKS_QUERY', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
41 | where ( |
||
42 | exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or |
||
43 | exists (select null from tags, books_tags_link where book = books.id and tag = tags.id and tags.name like ?) or |
||
44 | exists (select null from series, books_series_link on book = books.id and books_series_link.series = series.id and series.name like ?) or |
||
45 | exists (select null from publishers, books_publishers_link where book = books.id and books_publishers_link.publisher = publishers.id and publishers.name like ?) or |
||
46 | title like ?) {1} order by books.sort"); |
||
47 | define ('SQL_BOOKS_RECENT', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
48 | where 1=1 {1} order by timestamp desc limit "); |
||
49 | define ('SQL_BOOKS_BY_RATING', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
50 | where books_ratings_link.book = books.id and ratings.id = ? {1} order by sort"); |
||
51 | |||
52 | class Book extends Base { |
||
53 | const ALL_BOOKS_UUID = "urn:uuid"; |
||
54 | const ALL_BOOKS_ID = "cops:books"; |
||
55 | const ALL_RECENT_BOOKS_ID = "cops:recentbooks"; |
||
56 | const BOOK_COLUMNS = "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid, has_cover, ratings.rating"; |
||
57 | |||
58 | const SQL_BOOKS_LEFT_JOIN = SQL_BOOKS_LEFT_JOIN; |
||
59 | const SQL_BOOKS_ALL = SQL_BOOKS_ALL; |
||
60 | const SQL_BOOKS_BY_PUBLISHER = SQL_BOOKS_BY_PUBLISHER; |
||
61 | const SQL_BOOKS_BY_FIRST_LETTER = SQL_BOOKS_BY_FIRST_LETTER; |
||
62 | const SQL_BOOKS_BY_AUTHOR = SQL_BOOKS_BY_AUTHOR; |
||
63 | const SQL_BOOKS_BY_SERIE = SQL_BOOKS_BY_SERIE; |
||
64 | const SQL_BOOKS_BY_TAG = SQL_BOOKS_BY_TAG; |
||
65 | const SQL_BOOKS_BY_LANGUAGE = SQL_BOOKS_BY_LANGUAGE; |
||
66 | const SQL_BOOKS_BY_CUSTOM = SQL_BOOKS_BY_CUSTOM; |
||
67 | const SQL_BOOKS_QUERY = SQL_BOOKS_QUERY; |
||
68 | const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT; |
||
69 | const SQL_BOOKS_BY_RATING = SQL_BOOKS_BY_RATING; |
||
70 | |||
71 | const BAD_SEARCH = "QQQQQ"; |
||
72 | |||
73 | public $id; |
||
74 | public $title; |
||
75 | public $timestamp; |
||
76 | public $pubdate; |
||
77 | public $path; |
||
78 | public $uuid; |
||
79 | public $hasCover; |
||
80 | public $relativePath; |
||
81 | public $seriesIndex; |
||
82 | public $comment; |
||
83 | public $rating; |
||
84 | public $datas = NULL; |
||
85 | public $authors = NULL; |
||
86 | public $publisher = NULL; |
||
87 | public $serie = NULL; |
||
88 | public $tags = NULL; |
||
89 | public $languages = NULL; |
||
90 | public $format = array (); |
||
91 | |||
92 | |||
93 | 69 | public function __construct($line) { |
|
94 | 69 | $this->id = $line->id; |
|
95 | 69 | $this->title = $line->title; |
|
96 | 69 | $this->timestamp = strtotime ($line->timestamp); |
|
97 | 69 | $this->pubdate = strtotime ($line->pubdate); |
|
98 | 69 | $this->path = Base::getDbDirectory () . $line->path; |
|
99 | 69 | $this->relativePath = $line->path; |
|
100 | 69 | $this->seriesIndex = $line->series_index; |
|
101 | 69 | $this->comment = $line->comment; |
|
102 | 69 | $this->uuid = $line->uuid; |
|
103 | 69 | $this->hasCover = $line->has_cover; |
|
104 | 69 | if (!file_exists ($this->getFilePath ("jpg"))) { |
|
105 | // double check |
||
106 | 41 | $this->hasCover = 0; |
|
107 | 41 | } |
|
108 | 69 | $this->rating = $line->rating; |
|
109 | 69 | } |
|
110 | |||
111 | 40 | public function getEntryId () { |
|
112 | 40 | return self::ALL_BOOKS_UUID.":".$this->uuid; |
|
113 | } |
||
114 | |||
115 | 4 | public static function getEntryIdByLetter ($startingLetter) { |
|
116 | 4 | return self::ALL_BOOKS_ID.":letter:".$startingLetter; |
|
117 | } |
||
118 | |||
119 | 3 | public function getUri () { |
|
120 | 3 | return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id"; |
|
121 | } |
||
122 | |||
123 | 3 | public function getDetailUrl () { |
|
124 | 3 | $urlParam = $this->getUri (); |
|
125 | 3 | if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
126 | 3 | return 'index.php' . $urlParam; |
|
127 | } |
||
128 | |||
129 | 41 | public function getTitle () { |
|
130 | 41 | return $this->title; |
|
131 | } |
||
132 | |||
133 | /* Other class (author, series, tag, ...) initialization and accessors */ |
||
134 | |||
135 | 46 | public function getAuthors () { |
|
136 | 46 | if (is_null ($this->authors)) { |
|
137 | 46 | $this->authors = Author::getAuthorByBookId ($this->id); |
|
138 | 46 | } |
|
139 | 46 | return $this->authors; |
|
140 | } |
||
141 | |||
142 | public function getAuthorsName () { |
||
143 | return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ())); |
||
144 | } |
||
145 | |||
146 | public function getAuthorsSort () { |
||
147 | return implode (", ", array_map (function ($author) { return $author->sort; }, $this->getAuthors ())); |
||
148 | } |
||
149 | |||
150 | 4 | public function getPublisher () { |
|
151 | 4 | if (is_null ($this->publisher)) { |
|
152 | 4 | $this->publisher = Publisher::getPublisherByBookId ($this->id); |
|
153 | 4 | } |
|
154 | 4 | return $this->publisher; |
|
155 | } |
||
156 | |||
157 | 45 | public function getSerie () { |
|
158 | 45 | if (is_null ($this->serie)) { |
|
159 | 45 | $this->serie = Serie::getSerieByBookId ($this->id); |
|
160 | 45 | } |
|
161 | 45 | return $this->serie; |
|
162 | } |
||
163 | |||
164 | 9 | public function getLanguages () { |
|
165 | 9 | $lang = array (); |
|
166 | 9 | $result = parent::getDb ()->prepare('select languages.lang_code |
|
167 | from books_languages_link, languages |
||
168 | where books_languages_link.lang_code = languages.id |
||
169 | and book = ? |
||
170 | 9 | order by item_order'); |
|
171 | 9 | $result->execute (array ($this->id)); |
|
172 | 9 | while ($post = $result->fetchObject ()) |
|
173 | { |
||
174 | 9 | array_push ($lang, Language::getLanguageString($post->lang_code)); |
|
175 | 9 | } |
|
176 | 9 | return implode (", ", $lang); |
|
177 | } |
||
178 | |||
179 | 9 | public function getTags () { |
|
180 | 9 | if (is_null ($this->tags)) { |
|
181 | 9 | $this->tags = array (); |
|
182 | |||
183 | 9 | $result = parent::getDb ()->prepare('select tags.id as id, name |
|
184 | from books_tags_link, tags |
||
185 | where tag = tags.id |
||
186 | and book = ? |
||
187 | 9 | order by name'); |
|
188 | 9 | $result->execute (array ($this->id)); |
|
189 | 9 | while ($post = $result->fetchObject ()) |
|
190 | { |
||
191 | 9 | array_push ($this->tags, new Tag ($post)); |
|
192 | 9 | } |
|
193 | 9 | } |
|
194 | 9 | return $this->tags; |
|
195 | } |
||
196 | |||
197 | public function getTagsName () { |
||
198 | return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ())); |
||
199 | } |
||
200 | |||
201 | 59 | public function getDatas () |
|
202 | { |
||
203 | 59 | if (is_null ($this->datas)) { |
|
204 | 59 | $this->datas = Data::getDataByBook ($this); |
|
205 | 59 | } |
|
206 | 59 | return $this->datas; |
|
207 | } |
||
208 | |||
209 | /* End of other class (author, series, tag, ...) initialization and accessors */ |
||
210 | |||
211 | 56 | public static function getFilterString () { |
|
212 | 56 | $filter = getURLParam ("tag", NULL); |
|
213 | 56 | if (empty ($filter)) return ""; |
|
214 | |||
215 | 3 | $exists = true; |
|
216 | 3 | if (preg_match ("/^!(.*)$/", $filter, $matches)) { |
|
217 | 1 | $exists = false; |
|
218 | 1 | $filter = $matches[1]; |
|
219 | 1 | } |
|
220 | |||
221 | 3 | $result = "exists (select null from books_tags_link, tags where books_tags_link.book = books.id and books_tags_link.tag = tags.id and tags.name = '" . $filter . "')"; |
|
222 | |||
223 | 3 | if (!$exists) { |
|
224 | 1 | $result = "not " . $result; |
|
225 | 1 | } |
|
226 | |||
227 | 3 | return "and " . $result; |
|
228 | } |
||
229 | |||
230 | 4 | public function GetMostInterestingDataToSendToKindle () |
|
231 | { |
||
232 | 4 | $bestFormatForKindle = array ("EPUB", "PDF", "AZW3", "MOBI"); |
|
233 | 4 | $bestRank = -1; |
|
234 | 4 | $bestData = NULL; |
|
235 | 4 | foreach ($this->getDatas () as $data) { |
|
236 | 4 | $key = array_search ($data->format, $bestFormatForKindle); |
|
237 | 4 | if ($key !== false && $key > $bestRank) { |
|
238 | 4 | $bestRank = $key; |
|
239 | 4 | $bestData = $data; |
|
240 | 4 | } |
|
241 | 4 | } |
|
242 | 4 | return $bestData; |
|
243 | } |
||
244 | |||
245 | 3 | public function getDataById ($idData) |
|
246 | { |
||
247 | $reduced = array_filter ($this->getDatas (), function ($data) use ($idData) { |
||
248 | 3 | return $data->id == $idData; |
|
249 | 3 | }); |
|
250 | 3 | return reset ($reduced); |
|
251 | } |
||
252 | |||
253 | 7 | public function getRating () { |
|
254 | 7 | if (is_null ($this->rating) || $this->rating == 0) { |
|
255 | 2 | return ""; |
|
256 | } |
||
257 | 5 | $retour = ""; |
|
258 | 5 | for ($i = 0; $i < $this->rating / 2; $i++) { |
|
259 | 5 | $retour .= "★"; |
|
260 | 5 | } |
|
261 | 5 | for ($i = 0; $i < 5 - $this->rating / 2; $i++) { |
|
262 | 3 | $retour .= "☆"; |
|
263 | 3 | } |
|
264 | 5 | return $retour; |
|
265 | } |
||
266 | |||
267 | 8 | public function getPubDate () { |
|
268 | 8 | if (is_null ($this->pubdate) || ($this->pubdate <= -58979923200)) { |
|
269 | return ""; |
||
270 | } |
||
271 | else { |
||
272 | 8 | return date ("Y", $this->pubdate); |
|
273 | } |
||
274 | } |
||
275 | |||
276 | 41 | public function getComment ($withSerie = true) { |
|
277 | 41 | $addition = ""; |
|
278 | 41 | $se = $this->getSerie (); |
|
279 | 41 | if (!is_null ($se) && $withSerie) { |
|
280 | 36 | $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format (localize ("content.series.data"), $this->seriesIndex, htmlspecialchars ($se->name)) . "<br />\n"; |
|
281 | 36 | } |
|
282 | 41 | if (preg_match ("/<\/(div|p|a|span)>/", $this->comment)) |
|
283 | 41 | { |
|
284 | 35 | return $addition . html2xhtml ($this->comment); |
|
285 | } |
||
286 | else |
||
287 | { |
||
288 | 29 | return $addition . htmlspecialchars ($this->comment); |
|
289 | } |
||
290 | } |
||
291 | |||
292 | public function getDataFormat ($format) { |
||
293 | 11 | $reduced = array_filter ($this->getDatas (), function ($data) use ($format) { |
|
294 | 11 | return $data->format == $format; |
|
295 | 11 | }); |
|
296 | 11 | return reset ($reduced); |
|
297 | } |
||
298 | |||
299 | 69 | public function getFilePath ($extension, $idData = NULL, $relative = false) |
|
300 | { |
||
301 | 69 | if ($extension == "jpg") |
|
302 | 69 | { |
|
303 | 69 | $file = "cover.jpg"; |
|
304 | 69 | } |
|
305 | else |
||
306 | { |
||
307 | 2 | $data = $this->getDataById ($idData); |
|
308 | 2 | if (!$data) return NULL; |
|
309 | 2 | $file = $data->name . "." . strtolower ($data->format); |
|
310 | } |
||
311 | |||
312 | if ($relative) |
||
313 | 69 | { |
|
314 | 3 | return $this->relativePath."/".$file; |
|
315 | } |
||
316 | else |
||
317 | { |
||
318 | 69 | return $this->path."/".$file; |
|
319 | } |
||
320 | } |
||
321 | |||
322 | public function getUpdatedEpub ($idData) |
||
323 | { |
||
324 | global $config; |
||
325 | $data = $this->getDataById ($idData); |
||
326 | |||
327 | try |
||
328 | { |
||
329 | $epub = new EPub ($data->getLocalPath ()); |
||
330 | |||
331 | $epub->Title ($this->title); |
||
332 | $authorArray = array (); |
||
333 | foreach ($this->getAuthors() as $author) { |
||
334 | $authorArray [$author->sort] = $author->name; |
||
335 | } |
||
336 | $epub->Authors ($authorArray); |
||
337 | $epub->Language ($this->getLanguages ()); |
||
338 | $epub->Description ($this->getComment (false)); |
||
339 | $epub->Subjects ($this->getTagsName ()); |
||
340 | $epub->Cover2 ($this->getFilePath ("jpg"), "image/jpeg"); |
||
341 | $epub->Calibre ($this->uuid); |
||
342 | $se = $this->getSerie (); |
||
343 | if (!is_null ($se)) { |
||
344 | $epub->Serie ($se->name); |
||
345 | $epub->SerieIndex ($this->seriesIndex); |
||
346 | } |
||
347 | if ($config['cops_provide_kepub'] == "1" && preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) { |
||
348 | $epub->updateForKepub (); |
||
349 | } |
||
350 | $epub->download ($data->getUpdatedFilenameEpub ()); |
||
351 | } |
||
352 | catch (Exception $e) |
||
353 | { |
||
354 | echo "Exception : " . $e->getMessage(); |
||
355 | } |
||
356 | } |
||
357 | |||
358 | 3 | public function getThumbnail ($width, $height, $outputfile = NULL) { |
|
359 | 3 | if (is_null ($width) && is_null ($height)) { |
|
360 | 1 | return false; |
|
361 | } |
||
362 | |||
363 | 3 | $file = $this->getFilePath ("jpg"); |
|
364 | // get image size |
||
365 | 3 | if ($size = GetImageSize($file)) { |
|
366 | 3 | $w = $size[0]; |
|
367 | 3 | $h = $size[1]; |
|
368 | //set new size |
||
369 | 3 | if (!is_null ($width)) { |
|
370 | 2 | $nw = $width; |
|
371 | 2 | if ($nw >= $w) { return false; } |
|
372 | 1 | $nh = ($nw*$h)/$w; |
|
373 | 1 | } else { |
|
374 | 2 | $nh = $height; |
|
375 | 2 | if ($nh >= $h) { return false; } |
|
376 | 1 | $nw = ($nh*$w)/$h; |
|
377 | } |
||
378 | 2 | } else { |
|
379 | return false; |
||
380 | } |
||
381 | |||
382 | //draw the image |
||
383 | 2 | $src_img = imagecreatefromjpeg($file); |
|
384 | 2 | $dst_img = imagecreatetruecolor($nw,$nh); |
|
385 | 2 | imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image |
|
386 | 2 | imagejpeg($dst_img,$outputfile,80); |
|
387 | 2 | imagedestroy($src_img); |
|
388 | 2 | imagedestroy($dst_img); |
|
389 | |||
390 | 2 | return true; |
|
391 | } |
||
392 | |||
393 | 42 | public function getLinkArray () |
|
394 | { |
||
395 | 42 | $linkArray = array(); |
|
396 | |||
397 | 42 | if ($this->hasCover) |
|
398 | 42 | { |
|
399 | 18 | array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)); |
|
400 | |||
401 | 18 | array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL)); |
|
402 | 18 | } |
|
403 | |||
404 | 42 | foreach ($this->getDatas () as $data) |
|
405 | { |
||
406 | 42 | if ($data->isKnownType ()) |
|
407 | 42 | { |
|
408 | 42 | array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format)); |
|
409 | 42 | } |
|
410 | 42 | } |
|
411 | |||
412 | 42 | foreach ($this->getAuthors () as $author) { |
|
413 | 42 | array_push ($linkArray, new LinkNavigation ($author->getUri (), "related", str_format (localize ("bookentry.author"), localize ("splitByLetter.book.other"), $author->name))); |
|
414 | 42 | } |
|
415 | |||
416 | 42 | $serie = $this->getSerie (); |
|
417 | 42 | if (!is_null ($serie)) { |
|
418 | 39 | array_push ($linkArray, new LinkNavigation ($serie->getUri (), "related", str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name))); |
|
419 | 39 | } |
|
420 | |||
421 | 42 | return $linkArray; |
|
422 | } |
||
423 | |||
424 | |||
425 | 39 | public function getEntry () { |
|
426 | 39 | return new EntryBook ($this->getTitle (), $this->getEntryId (), |
|
427 | 39 | $this->getComment (), "text/html", |
|
428 | 39 | $this->getLinkArray (), $this); |
|
429 | } |
||
430 | |||
431 | 3 | public static function getBookCount($database = NULL) { |
|
432 | 3 | return parent::executeQuerySingle ('select count(*) from books', $database); |
|
0 ignored issues
–
show
|
|||
433 | } |
||
434 | |||
435 | 10 | public static function getCount() { |
|
436 | 10 | global $config; |
|
437 | 10 | $nBooks = parent::executeQuerySingle ('select count(*) from books'); |
|
0 ignored issues
–
show
It seems like you call parent on a different method (
executeQuerySingle() instead of getCount() ). Are you sure this is correct? If so, you might want to change this to $this->executeQuerySingle() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
438 | 10 | $result = array(); |
|
439 | 10 | $entry = new Entry (localize ("allbooks.title"), |
|
440 | 10 | self::ALL_BOOKS_ID, |
|
441 | 10 | str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text", |
|
442 | 10 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS)), "", $nBooks); |
|
443 | 10 | array_push ($result, $entry); |
|
444 | 10 | if ($config['cops_recentbooks_limit'] > 0) { |
|
445 | 10 | $entry = new Entry (localize ("recent.title"), |
|
446 | 10 | self::ALL_RECENT_BOOKS_ID, |
|
447 | 10 | str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text", |
|
448 | 10 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS)), "", $config['cops_recentbooks_limit']); |
|
449 | 10 | array_push ($result, $entry); |
|
450 | 10 | } |
|
451 | 10 | return $result; |
|
452 | } |
||
453 | |||
454 | 8 | public static function getBooksByAuthor($authorId, $n) { |
|
455 | 8 | return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n); |
|
456 | } |
||
457 | |||
458 | 1 | public static function getBooksByRating($ratingId, $n) { |
|
459 | 1 | return self::getEntryArray (self::SQL_BOOKS_BY_RATING, array ($ratingId), $n); |
|
460 | } |
||
461 | |||
462 | 2 | public static function getBooksByPublisher($publisherId, $n) { |
|
463 | 2 | return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n); |
|
464 | } |
||
465 | |||
466 | 2 | public static function getBooksBySeries($serieId, $n) { |
|
467 | 2 | return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n); |
|
468 | } |
||
469 | |||
470 | 2 | public static function getBooksByTag($tagId, $n) { |
|
471 | 2 | return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n); |
|
472 | } |
||
473 | |||
474 | 2 | public static function getBooksByLanguage($languageId, $n) { |
|
475 | 2 | return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n); |
|
476 | } |
||
477 | |||
478 | 3 | public static function getBooksByCustom($customId, $id, $n) { |
|
479 | 3 | $query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId)); |
|
480 | 3 | return self::getEntryArray ($query, array ($id), $n); |
|
481 | } |
||
482 | |||
483 | 30 | public static function getBookById($bookId) { |
|
484 | 30 | $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' |
|
485 | 30 | from books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
|
486 | 30 | where books.id = ?'); |
|
487 | 30 | $result->execute (array ($bookId)); |
|
488 | 30 | while ($post = $result->fetchObject ()) |
|
489 | { |
||
490 | 29 | $book = new Book ($post); |
|
491 | 29 | return $book; |
|
492 | } |
||
493 | 1 | return NULL; |
|
494 | } |
||
495 | |||
496 | 1 | public static function getBookByDataId($dataId) { |
|
497 | 1 | $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format |
|
498 | 1 | from data, books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
|
499 | 1 | where data.book = books.id and data.id = ?'); |
|
500 | 1 | $result->execute (array ($dataId)); |
|
501 | 1 | while ($post = $result->fetchObject ()) |
|
502 | { |
||
503 | 1 | $book = new Book ($post); |
|
504 | 1 | $data = new Data ($post, $book); |
|
505 | 1 | $data->id = $dataId; |
|
506 | 1 | $book->datas = array ($data); |
|
507 | 1 | return $book; |
|
508 | } |
||
509 | return NULL; |
||
510 | } |
||
511 | |||
512 | 2 | public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
513 | 2 | $i = 0; |
|
514 | 2 | $critArray = array (); |
|
515 | 2 | foreach (array (PageQueryResult::SCOPE_AUTHOR, |
|
516 | 2 | PageQueryResult::SCOPE_TAG, |
|
517 | 2 | PageQueryResult::SCOPE_SERIES, |
|
518 | 2 | PageQueryResult::SCOPE_PUBLISHER, |
|
519 | 2 | PageQueryResult::SCOPE_BOOK) as $key) { |
|
520 | 2 | if (in_array($key, getCurrentOption ('ignored_categories')) || |
|
521 | 2 | (!array_key_exists ($key, $query) && !array_key_exists ("all", $query))) { |
|
522 | $critArray [$i] = self::BAD_SEARCH; |
||
523 | } |
||
524 | else { |
||
525 | 2 | if (array_key_exists ($key, $query)) { |
|
526 | $critArray [$i] = $query [$key]; |
||
527 | } else { |
||
528 | 2 | $critArray [$i] = $query ["all"]; |
|
529 | } |
||
530 | } |
||
531 | 2 | $i++; |
|
532 | 2 | } |
|
533 | 2 | return self::getEntryArray (self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage); |
|
534 | } |
||
535 | |||
536 | 1 | public static function getBooks($n) { |
|
537 | 1 | list ($entryArray, $totalNumber) = self::getEntryArray (self::SQL_BOOKS_ALL , array (), $n); |
|
538 | 1 | return array ($entryArray, $totalNumber); |
|
539 | } |
||
540 | |||
541 | 3 | public static function getAllBooks() { |
|
542 | 3 | list (, $result) = parent::executeQuery ("select {0} |
|
0 ignored issues
–
show
It seems like you call parent on a different method (
executeQuery() instead of getAllBooks() ). Are you sure this is correct? If so, you might want to change this to $this->executeQuery() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
543 | from books |
||
544 | group by substr (upper (sort), 1, 1) |
||
545 | 3 | order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", self::getFilterString (), array (), -1); |
|
546 | 3 | $entryArray = array(); |
|
547 | 3 | while ($post = $result->fetchObject ()) |
|
548 | { |
||
549 | 3 | array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title), |
|
550 | 3 | str_format (localize("bookword", $post->count), $post->count), "text", |
|
551 | 3 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
|
552 | 3 | } |
|
553 | 3 | return $entryArray; |
|
554 | } |
||
555 | |||
556 | 25 | public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
|
557 | 25 | return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage); |
|
558 | } |
||
559 | |||
560 | 53 | public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
561 | 53 | list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage); |
|
0 ignored issues
–
show
It seems like you call parent on a different method (
executeQuery() instead of getEntryArray() ). Are you sure this is correct? If so, you might want to change this to $this->executeQuery() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
562 | 53 | $entryArray = array(); |
|
563 | 53 | while ($post = $result->fetchObject ()) |
|
564 | { |
||
565 | 39 | $book = new Book ($post); |
|
566 | 39 | array_push ($entryArray, $book->getEntry ()); |
|
567 | 39 | } |
|
568 | 53 | return array ($entryArray, $totalNumber); |
|
569 | } |
||
570 | |||
571 | |||
572 | 5 | public static function getAllRecentBooks() { |
|
573 | 5 | global $config; |
|
574 | 5 | list ($entryArray, ) = self::getEntryArray (self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array (), -1); |
|
575 | 5 | return $entryArray; |
|
576 | } |
||
577 | |||
578 | } |
||
579 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.