Completed
Pull Request — master (#233)
by
unknown
11:00
created

Upgrade to new PHP Analysis Engine

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 ('BOOK_COLUMNS', "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid, has_cover, ratings.rating as rating");
22
define ('SQL_BOOKS_LEFT_JOIN', "left outer join comments on comments.book = books.id
23
                                left outer join books_ratings_link on books_ratings_link.book = books.id
24
                                left outer join ratings on books_ratings_link.rating = ratings.id ");
25
define ('SQL_BOOKS_FILTER_JOIN', "inner join ({0}) as filter on filter.id = books.id " . SQL_BOOKS_LEFT_JOIN);
26
define ('SQL_BOOKS_ALL', "select ". BOOK_COLUMNS ." from books " . SQL_BOOKS_FILTER_JOIN . " order by books.sort ");
27
define ('SQL_BOOKS_BY_PUBLISHER', "select ". BOOK_COLUMNS ." from books_publishers_link, books " . SQL_BOOKS_FILTER_JOIN . "
28
                                                    where books_publishers_link.book = books.id and publisher = ? order by publisher");
29
define ('SQL_BOOKS_BY_FIRST_LETTER', "select ". BOOK_COLUMNS ." from books " . SQL_BOOKS_FILTER_JOIN . "
30
                                                    where upper (books.sort) like ? order by books.sort");
31
define ('SQL_BOOKS_BY_AUTHOR', "select ". BOOK_COLUMNS ." from books_authors_link, books " . SQL_BOOKS_FILTER_JOIN . "
32
                                                    left outer join books_series_link on books_series_link.book = books.id
33
                                                    where books_authors_link.book = books.id and author = ? order by series desc, series_index asc, pubdate asc");
34
define ('SQL_BOOKS_BY_SERIE', "select ". BOOK_COLUMNS ." from books_series_link, books " . SQL_BOOKS_FILTER_JOIN . "
35
                                                    where books_series_link.book = books.id and series = ? order by series_index");
36
define ('SQL_BOOKS_BY_TAG', "select ". BOOK_COLUMNS ." from books_tags_link, books " . SQL_BOOKS_FILTER_JOIN . "
37
                                                    where books_tags_link.book = books.id and tag = ? order by sort");
38
define ('SQL_BOOKS_BY_LANGUAGE', "select ". BOOK_COLUMNS ." from books_languages_link, books " . SQL_BOOKS_FILTER_JOIN . "
39
                                                    where books_languages_link.book = books.id and lang_code = ? order by sort");
40
define ('SQL_BOOKS_BY_CUSTOM', "select ". BOOK_COLUMNS ." from {1}, books " . SQL_BOOKS_FILTER_JOIN . "
41
                                                    where {1}.book = books.id and {1}.{2} = ? order by sort");
42
define ('SQL_BOOKS_QUERY', "select ". BOOK_COLUMNS ." from books " . SQL_BOOKS_FILTER_JOIN . "
43
                                                    where (
44
                                                    exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or
45
                                                    exists (select null from tags, books_tags_link where book = books.id and tag = tags.id and tags.name like ?) or
46
                                                    exists (select null from series, books_series_link on book = books.id and books_series_link.series = series.id and series.name like ?) or
47
                                                    exists (select null from publishers, books_publishers_link where book = books.id and books_publishers_link.publisher = publishers.id and publishers.name like ?) or
48
                                                    title like ?) order by books.sort");
49
define ('SQL_BOOKS_RECENT', "select " . BOOK_COLUMNS . " from books " . SQL_BOOKS_FILTER_JOIN . "
50
                                                    order by timestamp desc limit ");
51
define ('SQL_BOOKS_BY_RATING', "select ". BOOK_COLUMNS ." from books " . SQL_BOOKS_FILTER_JOIN . "
52
                                                    where books_ratings_link.book = books.id and ratings.id = ? order by sort");
53
54
class Book extends Base {
55
    const ALL_BOOKS_UUID = "urn:uuid";
56
    const ALL_BOOKS_ID = "cops:books";
57
    const ALL_RECENT_BOOKS_ID = "cops:recentbooks";
58
    const BOOK_COLUMNS = BOOK_COLUMNS;
59
60
    const SQL_BOOKS_LEFT_JOIN = SQL_BOOKS_LEFT_JOIN;
61
    const SQL_BOOKS_ALL = SQL_BOOKS_ALL;
62
    const SQL_BOOKS_BY_PUBLISHER = SQL_BOOKS_BY_PUBLISHER;
63
    const SQL_BOOKS_BY_FIRST_LETTER = SQL_BOOKS_BY_FIRST_LETTER;
64
    const SQL_BOOKS_BY_AUTHOR = SQL_BOOKS_BY_AUTHOR;
65
    const SQL_BOOKS_BY_SERIE = SQL_BOOKS_BY_SERIE;
66
    const SQL_BOOKS_BY_TAG = SQL_BOOKS_BY_TAG;
67
    const SQL_BOOKS_BY_LANGUAGE = SQL_BOOKS_BY_LANGUAGE;
68
    const SQL_BOOKS_BY_CUSTOM = SQL_BOOKS_BY_CUSTOM;
69
    const SQL_BOOKS_QUERY = SQL_BOOKS_QUERY;
70
    const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT;
71
    const SQL_BOOKS_BY_RATING = SQL_BOOKS_BY_RATING;
72
73
    const BAD_SEARCH = "QQQQQ";
74
75
    public $id;
76
    public $title;
77
    public $timestamp;
78
    public $pubdate;
79
    public $path;
80
    public $uuid;
81
    public $hasCover;
82
    public $relativePath;
83
    public $seriesIndex;
84
    public $comment;
85
    public $rating;
86
    public $datas = NULL;
87
    public $authors = NULL;
88
    public $publisher = NULL;
89
    public $serie = NULL;
90
    public $tags = NULL;
91
    public $languages = NULL;
92
    public $format = array ();
93 69
94 69
95 69
    public function __construct($line) {
96 69
        $this->id = $line->id;
97 69
        $this->title = $line->title;
98 69
        $this->timestamp = strtotime ($line->timestamp);
99 69
        $this->pubdate = strtotime ($line->pubdate);
100 69
        $this->path = Base::getDbDirectory () . $line->path;
101 69
        $this->relativePath = $line->path;
102 69
        $this->seriesIndex = $line->series_index;
103 69
        $this->comment = $line->comment;
104 69
        $this->uuid = $line->uuid;
105
        $this->hasCover = $line->has_cover;
106 41
        if (!file_exists ($this->getFilePath ("jpg"))) {
107 41
            // double check
108 69
            $this->hasCover = 0;
109 69
        }
110
        $this->rating = $line->rating;
111 40
    }
112 40
113
    public function getEntryId () {
114
        return self::ALL_BOOKS_UUID.":".$this->uuid;
115 4
    }
116 4
117
    public static function getEntryIdByLetter ($startingLetter) {
118
        return self::ALL_BOOKS_ID.":letter:".$startingLetter;
119 3
    }
120 3
121
    public function getUri () {
122
        return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id";
123 3
    }
124 3
125 3
    public function getDetailUrl () {
126 3
        $urlParam = $this->getUri ();
127
        if (!is_null (GetUrlParam (DB))) {
128
        	$urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
129 41
        	$urlParam = addURLParameter ($urlParam, VL, GetUrlParam (VL, 0));
130 41
        }
131
        return 'index.php' . $urlParam;
132
    }
133
134
    public function getTitle () {
135 46
        return $this->title;
136 46
    }
137 46
138 46
    /* Other class (author, series, tag, ...) initialization and accessors */
139 46
140
    public function getAuthors () {
141
        if (is_null ($this->authors)) {
142
            $this->authors = Author::getAuthorByBookId ($this->id);
143
        }
144
        return $this->authors;
145
    }
146
147
    public function getAuthorsName () {
148
        return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ()));
149
    }
150 4
151 4
    public function getAuthorsSort () {
152 4
        return implode (", ", array_map (function ($author) { return $author->sort; }, $this->getAuthors ()));
153 4
    }
154 4
155
    public function getPublisher () {
156
        if (is_null ($this->publisher)) {
157 45
            $this->publisher = Publisher::getPublisherByBookId ($this->id);
158 45
        }
159 45
        return $this->publisher;
160 45
    }
161 45
162
    public function getSerie () {
163
        if (is_null ($this->serie)) {
164 9
            $this->serie = Serie::getSerieByBookId ($this->id);
165 9
        }
166 9
        return $this->serie;
167
    }
168
169
    public function getLanguages () {
170 9
        $lang = array ();
171 9
        $result = parent::getDb ()->prepare('select languages.lang_code
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getLanguages()). Are you sure this is correct? If so, you might want to change this to $this->getDb().

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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
172 9
                from books_languages_link, languages
173
                where books_languages_link.lang_code = languages.id
174 9
                and book = ?
175 9
                order by item_order');
176 9
        $result->execute (array ($this->id));
177
        while ($post = $result->fetchObject ())
178
        {
179 9
            array_push ($lang, Language::getLanguageString($post->lang_code));
180 9
        }
181 9
        return implode (", ", $lang);
182
    }
183 9
184
    public function getTags () {
185
        if (is_null ($this->tags)) {
186
            $this->tags = array ();
187 9
188 9
            $result = parent::getDb ()->prepare('select tags.id as id, name
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getTags()). Are you sure this is correct? If so, you might want to change this to $this->getDb().

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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
189 9
                from books_tags_link, tags
190
                where tag = tags.id
191 9
                and book = ?
192 9
                order by name');
193 9
            $result->execute (array ($this->id));
194 9
            while ($post = $result->fetchObject ())
195
            {
196
                array_push ($this->tags, new Tag ($post));
197
            }
198
        }
199
        return $this->tags;
200
    }
201 59
202
    public function getTagsName () {
203 59
        return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ()));
204 59
    }
205 59
206 59
    public function getDatas ()
207
    {
208
        if (is_null ($this->datas)) {
209
            $this->datas = Data::getDataByBook ($this);
210
        }
211 56
        return $this->datas;
212 56
    }
213 56
214
    /* End of other class (author, series, tag, ...) initialization and accessors */
215 3
216 3
    public static function getFilterString () {
217 1
        $filter = getURLParam ("tag", NULL);
218 1
        if (empty ($filter)) return "";
219 1
220
        $exists = true;
221 3
        if (preg_match ("/^!(.*)$/", $filter, $matches)) {
222
            $exists = false;
223 3
            $filter = $matches[1];
224 1
        }
225 1
226
        $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 . "')";
227 3
228
        if (!$exists) {
229
            $result = "not " . $result;
230 4
        }
231
232 4
        return "and " . $result;
233 4
    }
234 4
235 4
    public function GetMostInterestingDataToSendToKindle ()
236 4
    {
237 4
        $bestFormatForKindle = array ("EPUB", "PDF", "AZW3", "MOBI");
238 4
        $bestRank = -1;
239 4
        $bestData = NULL;
240 4
        foreach ($this->getDatas () as $data) {
241 4
            $key = array_search ($data->format, $bestFormatForKindle);
242 4
            if ($key !== false && $key > $bestRank) {
243
                $bestRank = $key;
244
                $bestData = $data;
245 3
            }
246
        }
247
        return $bestData;
248 3
    }
249 3
250 3
    public function getDataById ($idData)
251
    {
252
        $reduced = array_filter ($this->getDatas (), function ($data) use ($idData) {
253 7
            return $data->id == $idData;
254 7
        });
255 2
        return reset ($reduced);
256
    }
257 5
258 5
    public function getRating () {
259 5
        if (is_null ($this->rating) || $this->rating == 0) {
260 5
            return "";
261 5
        }
262 3
        $retour = "";
263 3
        for ($i = 0; $i < $this->rating / 2; $i++) {
264 5
            $retour .= "&#9733;";
265
        }
266
        for ($i = 0; $i < 5 - $this->rating / 2; $i++) {
267 8
            $retour .= "&#9734;";
268 8
        }
269
        return $retour;
270
    }
271
272 8
    public function getPubDate () {
273
        if (is_null ($this->pubdate) || ($this->pubdate <= -58979923200)) {
274
            return "";
275
        }
276 41
        else {
277 41
            return date ("Y", $this->pubdate);
278 41
        }
279 41
    }
280 36
281 36
    public function getComment ($withSerie = true) {
282 41
        $addition = "";
283 41
        $se = $this->getSerie ();
284 35
        if (!is_null ($se) && $withSerie) {
285
            $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format (localize ("content.series.data"), $this->seriesIndex, htmlspecialchars ($se->name)) . "<br />\n";
286
        }
287
        if (preg_match ("/<\/(div|p|a|span)>/", $this->comment))
288 29
        {
289
            return $addition . html2xhtml ($this->comment);
290
        }
291
        else
292
        {
293 11
            return $addition . htmlspecialchars ($this->comment);
294 11
        }
295 11
    }
296 11
297
    public function getDataFormat ($format) {
298
        $reduced = array_filter ($this->getDatas (), function ($data) use ($format) {
299 69
            return $data->format == $format;
300
        });
301 69
        return reset ($reduced);
302 69
    }
303 69
304 69
    public function getFilePath ($extension, $idData = NULL, $relative = false)
305
    {
306
        if ($extension == "jpg")
307 2
        {
308 2
            $file = "cover.jpg";
309 2
        }
310
        else
311
        {
312
            $data = $this->getDataById ($idData);
313 69
            if (!$data) return NULL;
314 3
            $file = $data->name . "." . strtolower ($data->format);
315
        }
316
317
        if ($relative)
318 69
        {
319
            return $this->relativePath."/".$file;
320
        }
321
        else
322
        {
323
            return $this->path."/".$file;
324
        }
325
    }
326
327
    public function getUpdatedEpub ($idData)
328
    {
329
        global $config;
330
        $data = $this->getDataById ($idData);
331
332
        try
333
        {
334
            $epub = new EPub ($data->getLocalPath ());
335
336
            $epub->Title ($this->title);
337
            $authorArray = array ();
338
            foreach ($this->getAuthors() as $author) {
339
                $authorArray [$author->sort] = $author->name;
340
            }
341
            $epub->Authors ($authorArray);
342
            $epub->Language ($this->getLanguages ());
343
            $epub->Description ($this->getComment (false));
344
            $epub->Subjects ($this->getTagsName ());
345
            $epub->Cover2 ($this->getFilePath ("jpg"), "image/jpeg");
346
            $epub->Calibre ($this->uuid);
347
            $se = $this->getSerie ();
348
            if (!is_null ($se)) {
349
                $epub->Serie ($se->name);
350
                $epub->SerieIndex ($this->seriesIndex);
351
            }
352
            if ($config['cops_provide_kepub'] == "1"  && preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) {
353
                $epub->updateForKepub ();
354
            }
355
            $epub->download ($data->getUpdatedFilenameEpub ());
356
        }
357
        catch (Exception $e)
358 3
        {
359 3
            echo "Exception : " . $e->getMessage();
360 1
        }
361
    }
362
363 3
    public function getThumbnail ($width, $height, $outputfile = NULL) {
364
        if (is_null ($width) && is_null ($height)) {
365 3
            return false;
366 3
        }
367 3
368
        $file = $this->getFilePath ("jpg");
369 3
        // get image size
370 2
        if ($size = GetImageSize($file)) {
371 2
            $w = $size[0];
372 1
            $h = $size[1];
373 1
            //set new size
374 2
            if (!is_null ($width)) {
375 2
                $nw = $width;
376 1
                if ($nw >= $w) { return false; }
377
                $nh = ($nw*$h)/$w;
378 2
            } else {
379
                $nh = $height;
380
                if ($nh >= $h) { return false; }
381
                $nw = ($nh*$w)/$h;
382
            }
383 2
        } else {
384 2
            return false;
385 2
        }
386 2
387 2
        //draw the image
388 2
        $src_img = imagecreatefromjpeg($file);
389
        $dst_img = imagecreatetruecolor($nw,$nh);
390 2
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image
391
        imagejpeg($dst_img,$outputfile,80);
392
        imagedestroy($src_img);
393 42
        imagedestroy($dst_img);
394
395 42
        return true;
396
    }
397 42
398 42
    public function getLinkArray ()
399 18
    {
400
        $linkArray = array();
401 18
402 18
        if ($this->hasCover)
403
        {
404 42
            array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL));
405
406 42
            array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL));
407 42
        }
408 42
409 42
        foreach ($this->getDatas () as $data)
410 42
        {
411
            if ($data->isKnownType ())
412 42
            {
413 42
                array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format));
414 42
            }
415
        }
416 42
417 42
        foreach ($this->getAuthors () as $author) {
418 39
            array_push ($linkArray, new LinkNavigation ($author->getUri (), "related", str_format (localize ("bookentry.author"), localize ("splitByLetter.book.other"), $author->name)));
419 39
        }
420
421 42
        $serie = $this->getSerie ();
422
        if (!is_null ($serie)) {
423
            array_push ($linkArray, new LinkNavigation ($serie->getUri (), "related", str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name)));
424
        }
425 39
426 39
        return $linkArray;
427 39
    }
428 39
429
430
    public function getEntry () {
431 3
        return new EntryBook ($this->getTitle (), $this->getEntryId (),
432 3
            $this->getComment (), "text/html",
433
            $this->getLinkArray (), $this);
434
    }
435 10
436 10
    public static function getBookCount($database = NULL, $virtualLib = NULL) {
437 10
        return parent::executeFilteredQuerySingle('select count(*) from ({0}) as filter', $database, $virtualLib);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (executeFilteredQuerySingle() instead of getBookCount()). Are you sure this is correct? If so, you might want to change this to $this->executeFilteredQuerySingle().

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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
438 10
    }
439 10
440 10
    public static function getCount() {
441 10
        global $config;
442 10
        $nBooks = self::getBookCount();
443 10
        $result = array();
444 10
        $entry = new Entry (localize ("allbooks.title"),
445 10
                          self::ALL_BOOKS_ID,
446 10
                          str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text",
447 10
                          array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS)), "", $nBooks);
448 10
        array_push ($result, $entry);
449 10
        if ($config['cops_recentbooks_limit'] > 0) {
450 10
            $entry = new Entry (localize ("recent.title"),
451 10
                              self::ALL_RECENT_BOOKS_ID,
452
                              str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text",
453
                              array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS)), "", $config['cops_recentbooks_limit']);
454 8
            array_push ($result, $entry);
455 8
        }
456
        return $result;
457
    }
458 1
459 1
    public static function getBooksByAuthor($authorId, $n) {
460
        return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n);
461
    }
462 2
463 2
    public static function getBooksByRating($ratingId, $n) {
464
        return self::getEntryArray (self::SQL_BOOKS_BY_RATING, array ($ratingId), $n);
465
    }
466 2
467 2
    public static function getBooksByPublisher($publisherId, $n) {
468
        return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n);
469
    }
470 2
471 2
    public static function getBooksBySeries($serieId, $n) {
472
        return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n);
473
    }
474 2
475 2
    public static function getBooksByTag($tagId, $n) {
476
        return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n);
477
    }
478 3
479 3
    public static function getBooksByLanguage($languageId, $n) {
480 3
        return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n);
481
    }
482
483 30
    public static function getBooksByCustom($customId, $id, $n) {
484 30
        $query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId));
485 30
        return self::getEntryArray ($query, array ($id), $n);
486 30
    }
487 30
488 30
    public static function getBookById($bookId) {
489
        $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getBookById()). Are you sure this is correct? If so, you might want to change this to $this->getDb().

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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
490 29
from books ' . self::SQL_BOOKS_LEFT_JOIN . '
491 29
where books.id = ?');
492
        $result->execute (array ($bookId));
493 1
        while ($post = $result->fetchObject ())
494
        {
495
            $book = new Book ($post);
496 1
            return $book;
497 1
        }
498 1
        return NULL;
499 1
    }
500 1
501 1
    public static function getBookByDataId($dataId) {
502
        $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getBookByDataId()). Are you sure this is correct? If so, you might want to change this to $this->getDb().

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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
503 1
from data, books ' . self::SQL_BOOKS_LEFT_JOIN . '
504 1
where data.book = books.id and data.id = ?');
505 1
        $result->execute (array ($dataId));
506 1
        while ($post = $result->fetchObject ())
507 1
        {
508
            $book = new Book ($post);
509
            $data = new Data ($post, $book);
510
            $data->id = $dataId;
511
            $book->datas = array ($data);
512 2
            return $book;
513 2
        }
514 2
        return NULL;
515 2
    }
516 2
517 2
    public static function getBooksByQuery($query, $n, $database = NULL, $virtualLib = NULL, $numberPerPage = NULL) {
518 2
        $i = 0;
519 2
        $critArray = array ();
520 2
        foreach (array (PageQueryResult::SCOPE_AUTHOR,
521 2
                        PageQueryResult::SCOPE_TAG,
522
                        PageQueryResult::SCOPE_SERIES,
523
                        PageQueryResult::SCOPE_PUBLISHER,
524
                        PageQueryResult::SCOPE_BOOK) as $key) {
525 2
            if (in_array($key, getCurrentOption ('ignored_categories')) ||
526
                (!array_key_exists ($key, $query) && !array_key_exists ("all", $query))) {
527
                $critArray [$i] = self::BAD_SEARCH;
528 2
            }
529
            else {
530
                if (array_key_exists ($key, $query)) {
531 2
                    $critArray [$i] = $query [$key];
532 2
                } else {
533 2
                    $critArray [$i] = $query ["all"];
534
                }
535
            }
536 1
            $i++;
537 1
        }
538 1
        return self::getEntryArray (self::SQL_BOOKS_QUERY, $critArray, $n, $database, $virtualLib, $numberPerPage);
539
    }
540
541 3
    public static function getBooks($n) {
542 3
        list ($entryArray, $totalNumber) = self::getEntryArray (self::SQL_BOOKS_ALL , array (), $n);
543
        return array ($entryArray, $totalNumber);
544
    }
545 3
546 3
    public static function getAllBooks() {
547 3
        list (, $result) = parent::executeQuery ("select {0}
0 ignored issues
show
Comprehensibility Bug introduced by
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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
548
from books
549 3
group by substr (upper (sort), 1, 1)
550 3
order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", self::getFilterString (), array (), -1);
551 3
        $entryArray = array();
552 3
        while ($post = $result->fetchObject ())
553 3
        {
554
            array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title),
555
                str_format (localize("bookword", $post->count), $post->count), "text",
556 25
                array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))), "", $post->count));
557 25
        }
558
        return $entryArray;
559
    }
560 53
561 53
    public static function getBooksByStartingLetter($letter, $n, $database = NULL, $virtualLib = NULL, $numberPerPage = NULL) {
562 53
        return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $virtualLib, $numberPerPage);
563 53
    }
564
565 39
    public static function getEntryArray ($query, $params, $n, $database = NULL, $virtualLib = NULL, $numberPerPage = NULL) {
566 39
    	// TODO: include getFilterString() again.
567 39
        list ($totalNumber, $result) = parent::executeFilteredQuery ($query, $params, $n, $database, $virtualLib, $numberPerPage);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (executeFilteredQuery() instead of getEntryArray()). Are you sure this is correct? If so, you might want to change this to $this->executeFilteredQuery().

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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
568 53
        $entryArray = array();
569
        while ($post = $result->fetchObject ())
570
        {
571
            $book = new Book ($post);
572 5
            array_push ($entryArray, $book->getEntry ());
573 5
        }
574 5
        return array ($entryArray, $totalNumber);
575 5
    }
576
577
578
    public static function getAllRecentBooks() {
579
        global $config;
580
        list ($entryArray, ) = self::getEntryArray (self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array (), -1);
581
        return $entryArray;
582
    }
583
584
}
585