Completed
Pull Request — master (#233)
by
unknown
11:31
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
        $urlParam = $this->getUri ();
127
        if (!is_null (GetUrlParam (DB))) {
128
        	$urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
129 3
        	$urlParam = addURLParameter ($urlParam, VL, GetUrlParam (VL, 0));
130
        }
131
        return 'index.php' . $urlParam;
132 41
    }
133 41
134
    public function getTitle () {
135
        return $this->title;
136
    }
137
138 46
    /* Other class (author, series, tag, ...) initialization and accessors */
139 46
140 46
    public function getAuthors () {
141 46
        if (is_null ($this->authors)) {
142 46
            $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
151
    public function getAuthorsSort () {
152
        return implode (", ", array_map (function ($author) { return $author->sort; }, $this->getAuthors ()));
153 4
    }
154 4
155 4
    public function getPublisher () {
156 4
        if (is_null ($this->publisher)) {
157 4
            $this->publisher = Publisher::getPublisherByBookId ($this->id);
158
        }
159
        return $this->publisher;
160 45
    }
161 45
162 45
    public function getSerie () {
163 45
        if (is_null ($this->serie)) {
164 45
            $this->serie = Serie::getSerieByBookId ($this->id);
165
        }
166
        return $this->serie;
167 9
    }
168 9
169 9
    public function getLanguages () {
170
        $lang = array ();
171
        $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
                from books_languages_link, languages
173 9
                where books_languages_link.lang_code = languages.id
174 9
                and book = ?
175 9
                order by item_order');
176
        $result->execute (array ($this->id));
177 9
        while ($post = $result->fetchObject ())
178 9
        {
179 9
            array_push ($lang, Language::getLanguageString($post->lang_code));
180
        }
181
        return implode (", ", $lang);
182 9
    }
183 9
184 9
    public function getTags () {
185
        if (is_null ($this->tags)) {
186 9
            $this->tags = array ();
187
188
            $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
                from books_tags_link, tags
190 9
                where tag = tags.id
191 9
                and book = ?
192 9
                order by name');
193
            $result->execute (array ($this->id));
194 9
            while ($post = $result->fetchObject ())
195 9
            {
196 9
                array_push ($this->tags, new Tag ($post));
197 9
            }
198
        }
199
        return $this->tags;
200
    }
201
202
    public function getTagsName () {
203
        return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ()));
204 59
    }
205
206 59
    public function getDatas ()
207 59
    {
208 59
        if (is_null ($this->datas)) {
209 59
            $this->datas = Data::getDataByBook ($this);
210
        }
211
        return $this->datas;
212
    }
213
214 56
    /* End of other class (author, series, tag, ...) initialization and accessors */
215 56
216 56
    public static function getFilterString () {
217
        $filter = getURLParam ("tag", NULL);
218 3
        if (empty ($filter)) return "";
219 3
220 1
        $exists = true;
221 1
        if (preg_match ("/^!(.*)$/", $filter, $matches)) {
222 1
            $exists = false;
223
            $filter = $matches[1];
224 3
        }
225
226 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 . "')";
227 1
228 1
        if (!$exists) {
229
            $result = "not " . $result;
230 3
        }
231
232
        return "and " . $result;
233 4
    }
234
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 4
                $bestRank = $key;
244 4
                $bestData = $data;
245 4
            }
246
        }
247
        return $bestData;
248 3
    }
249
250
    public function getDataById ($idData)
251 3
    {
252 3
        $reduced = array_filter ($this->getDatas (), function ($data) use ($idData) {
253 3
            return $data->id == $idData;
254
        });
255
        return reset ($reduced);
256 7
    }
257 7
258 2
    public function getRating () {
259
        if (is_null ($this->rating) || $this->rating == 0) {
260 5
            return "";
261 5
        }
262 5
        $retour = "";
263 5
        for ($i = 0; $i < $this->rating / 2; $i++) {
264 5
            $retour .= "&#9733;";
265 3
        }
266 3
        for ($i = 0; $i < 5 - $this->rating / 2; $i++) {
267 5
            $retour .= "&#9734;";
268
        }
269
        return $retour;
270 8
    }
271 8
272
    public function getPubDate () {
273
        if (is_null ($this->pubdate) || ($this->pubdate <= -58979923200)) {
274
            return "";
275 8
        }
276
        else {
277
            return date ("Y", $this->pubdate);
278
        }
279 41
    }
280 41
281 41
    public function getComment ($withSerie = true) {
282 41
        $addition = "";
283 36
        $se = $this->getSerie ();
284 36
        if (!is_null ($se) && $withSerie) {
285 41
            $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format (localize ("content.series.data"), $this->seriesIndex, htmlspecialchars ($se->name)) . "<br />\n";
286 41
        }
287 35
        if (preg_match ("/<\/(div|p|a|span)>/", $this->comment))
288
        {
289
            return $addition . html2xhtml ($this->comment);
290
        }
291 29
        else
292
        {
293
            return $addition . htmlspecialchars ($this->comment);
294
        }
295
    }
296 11
297 11
    public function getDataFormat ($format) {
298 11
        $reduced = array_filter ($this->getDatas (), function ($data) use ($format) {
299 11
            return $data->format == $format;
300
        });
301
        return reset ($reduced);
302 69
    }
303
304 69
    public function getFilePath ($extension, $idData = NULL, $relative = false)
305 69
    {
306 69
        if ($extension == "jpg")
307 69
        {
308
            $file = "cover.jpg";
309
        }
310 2
        else
311 2
        {
312 2
            $data = $this->getDataById ($idData);
313
            if (!$data) return NULL;
314
            $file = $data->name . "." . strtolower ($data->format);
315
        }
316 69
317 3
        if ($relative)
318
        {
319
            return $this->relativePath."/".$file;
320
        }
321 69
        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
        {
359
            echo "Exception : " . $e->getMessage();
360
        }
361 3
    }
362 3
363 1
    public function getThumbnail ($width, $height, $outputfile = NULL) {
364
        if (is_null ($width) && is_null ($height)) {
365
            return false;
366 3
        }
367
368 3
        $file = $this->getFilePath ("jpg");
369 3
        // get image size
370 3
        if ($size = GetImageSize($file)) {
371
            $w = $size[0];
372 3
            $h = $size[1];
373 2
            //set new size
374 2
            if (!is_null ($width)) {
375 1
                $nw = $width;
376 1
                if ($nw >= $w) { return false; }
377 2
                $nh = ($nw*$h)/$w;
378 2
            } else {
379 1
                $nh = $height;
380
                if ($nh >= $h) { return false; }
381 2
                $nw = ($nh*$w)/$h;
382
            }
383
        } else {
384
            return false;
385
        }
386 2
387 2
        //draw the image
388 2
        $src_img = imagecreatefromjpeg($file);
389 2
        $dst_img = imagecreatetruecolor($nw,$nh);
390 2
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image
391 2
        imagejpeg($dst_img,$outputfile,80);
392
        imagedestroy($src_img);
393 2
        imagedestroy($dst_img);
394
395
        return true;
396 42
    }
397
398 42
    public function getLinkArray ()
399
    {
400 42
        $linkArray = array();
401 42
402 18
        if ($this->hasCover)
403
        {
404 18
            array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL));
405 18
406
            array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL));
407 42
        }
408
409 42
        foreach ($this->getDatas () as $data)
410 42
        {
411 42
            if ($data->isKnownType ())
412 42
            {
413 42
                array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format));
414
            }
415 42
        }
416 42
417 42
        foreach ($this->getAuthors () as $author) {
418
            array_push ($linkArray, new LinkNavigation ($author->getUri (), "related", str_format (localize ("bookentry.author"), localize ("splitByLetter.book.other"), $author->name)));
419 42
        }
420 42
421 39
        $serie = $this->getSerie ();
422 39
        if (!is_null ($serie)) {
423
            array_push ($linkArray, new LinkNavigation ($serie->getUri (), "related", str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name)));
424 42
        }
425
426
        return $linkArray;
427
    }
428 39
429 39
430 39
    public function getEntry () {
431 39
        return new EntryBook ($this->getTitle (), $this->getEntryId (),
432
            $this->getComment (), "text/html",
433
            $this->getLinkArray (), $this);
434 3
    }
435 3
436
    public static function getBookCount($database = NULL, $virtualLib = NULL) {
437
        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 10
                              str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text",
453 10
                              array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS)), "", $config['cops_recentbooks_limit']);
454 10
            array_push ($result, $entry);
455
        }
456
        return $result;
457 8
    }
458 8
459
    public static function getBooksByAuthor($authorId, $n) {
460
        return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n);
461 1
    }
462 1
463
    public static function getBooksByRating($ratingId, $n) {
464
        return self::getEntryArray (self::SQL_BOOKS_BY_RATING, array ($ratingId), $n);
465 2
    }
466 2
467
    public static function getBooksByPublisher($publisherId, $n) {
468
        return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n);
469 2
    }
470 2
471
    public static function getBooksBySeries($serieId, $n) {
472
        return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n);
473 2
    }
474 2
475
    public static function getBooksByTag($tagId, $n) {
476
        return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n);
477 2
    }
478 2
479
    public static function getBooksByLanguage($languageId, $n) {
480
        return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n);
481 3
    }
482 3
483 3
    public static function getBooksByCustom($customId, $id, $n) {
484
        $query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId));
485
        return self::getEntryArray ($query, array ($id), $n);
486 30
    }
487 30
488 30
    public static function getBookById($bookId) {
489 30
        $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 30
from books ' . self::SQL_BOOKS_LEFT_JOIN . '
491 30
where books.id = ?');
492
        $result->execute (array ($bookId));
493 29
        while ($post = $result->fetchObject ())
494 29
        {
495
            $book = new Book ($post);
496 1
            return $book;
497
        }
498
        return NULL;
499 1
    }
500 1
501 1
    public static function getBookByDataId($dataId) {
502 1
        $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
        $result->execute (array ($dataId));
506 1
        while ($post = $result->fetchObject ())
507 1
        {
508 1
            $book = new Book ($post);
509 1
            $data = new Data ($post, $book);
510 1
            $data->id = $dataId;
511
            $book->datas = array ($data);
512
            return $book;
513
        }
514
        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 2
                        PageQueryResult::SCOPE_SERIES,
523 2
                        PageQueryResult::SCOPE_PUBLISHER,
524 2
                        PageQueryResult::SCOPE_BOOK) as $key) {
525
            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
                } else {
533
                    $critArray [$i] = $query ["all"];
534 2
                }
535 2
            }
536 2
            $i++;
537
        }
538
        return self::getEntryArray (self::SQL_BOOKS_QUERY, $critArray, $n, $database, $virtualLib, $numberPerPage);
539 1
    }
540 1
541 1
    public static function getBooks($n) {
542
        list ($entryArray, $totalNumber) = self::getEntryArray (self::SQL_BOOKS_ALL , array (), $n);
543
        return array ($entryArray, $totalNumber);
544 3
    }
545 3
546
    public static function getAllBooks() {
547
        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 3
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
        $entryArray = array();
552 3
        while ($post = $result->fetchObject ())
553 3
        {
554 3
            array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title),
555 3
                str_format (localize("bookword", $post->count), $post->count), "text",
556 3
                array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))), "", $post->count));
557
        }
558
        return $entryArray;
559 25
    }
560 25
561
    public static function getBooksByStartingLetter($letter, $n, $database = NULL, $virtualLib = NULL, $numberPerPage = NULL) {
562
        return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $virtualLib, $numberPerPage);
563 53
    }
564 53
565 53
    public static function getEntryArray ($query, $params, $n, $database = NULL, $virtualLib = NULL, $numberPerPage = NULL) {
566 53
    	// TODO: include getFilterString() again.
567
        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 39
        $entryArray = array();
569 39
        while ($post = $result->fetchObject ())
570 39
        {
571 53
            $book = new Book ($post);
572
            array_push ($entryArray, $book->getEntry ());
573
        }
574
        return array ($entryArray, $totalNumber);
575 5
    }
576 5
577 5
578 5
    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