Completed
Pull Request — master (#233)
by
unknown
05:24
created

Book::getBookByDataId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0023
Metric Value
dl 0
loc 15
ccs 11
cts 12
cp 0.9167
rs 9.4286
cc 2
eloc 11
nc 2
nop 1
crap 2.0023
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))) {
126
        	$urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
127
        	$urlParam = addURLParameter ($urlParam, VL, GetUrlParam (VL, 0));
128
        }
129 3
        return 'index.php' . $urlParam;
130
    }
131
132 41
    public function getTitle () {
133 41
        return $this->title;
134
    }
135
136
    /* Other class (author, series, tag, ...) initialization and accessors */
137
138 46
    public function getAuthors () {
139 46
        if (is_null ($this->authors)) {
140 46
            $this->authors = Author::getAuthorByBookId ($this->id);
141 46
        }
142 46
        return $this->authors;
143
    }
144
145
    public function getAuthorsName () {
146
        return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ()));
147
    }
148
149
    public function getAuthorsSort () {
150
        return implode (", ", array_map (function ($author) { return $author->sort; }, $this->getAuthors ()));
151
    }
152
153 4
    public function getPublisher () {
154 4
        if (is_null ($this->publisher)) {
155 4
            $this->publisher = Publisher::getPublisherByBookId ($this->id);
156 4
        }
157 4
        return $this->publisher;
158
    }
159
160 45
    public function getSerie () {
161 45
        if (is_null ($this->serie)) {
162 45
            $this->serie = Serie::getSerieByBookId ($this->id);
163 45
        }
164 45
        return $this->serie;
165
    }
166
167 9
    public function getLanguages () {
168 9
        $lang = array ();
169 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...
170
                from books_languages_link, languages
171
                where books_languages_link.lang_code = languages.id
172
                and book = ?
173 9
                order by item_order');
174 9
        $result->execute (array ($this->id));
175 9
        while ($post = $result->fetchObject ())
176
        {
177 9
            array_push ($lang, Language::getLanguageString($post->lang_code));
178 9
        }
179 9
        return implode (", ", $lang);
180
    }
181
182 9
    public function getTags () {
183 9
        if (is_null ($this->tags)) {
184 9
            $this->tags = array ();
185
186 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...
187
                from books_tags_link, tags
188
                where tag = tags.id
189
                and book = ?
190 9
                order by name');
191 9
            $result->execute (array ($this->id));
192 9
            while ($post = $result->fetchObject ())
193
            {
194 9
                array_push ($this->tags, new Tag ($post));
195 9
            }
196 9
        }
197 9
        return $this->tags;
198
    }
199
200
    public function getTagsName () {
201
        return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ()));
202
    }
203
204 59
    public function getDatas ()
205
    {
206 59
        if (is_null ($this->datas)) {
207 59
            $this->datas = Data::getDataByBook ($this);
208 59
        }
209 59
        return $this->datas;
210
    }
211
212
    /* End of other class (author, series, tag, ...) initialization and accessors */
213
214 56
    public static function getFilterString () {
215 56
        $filter = getURLParam ("tag", NULL);
216 56
        if (empty ($filter)) return "";
217
218 3
        $exists = true;
219 3
        if (preg_match ("/^!(.*)$/", $filter, $matches)) {
220 1
            $exists = false;
221 1
            $filter = $matches[1];
222 1
        }
223
224 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 . "')";
225
226 3
        if (!$exists) {
227 1
            $result = "not " . $result;
228 1
        }
229
230 3
        return "and " . $result;
231
    }
232
233 4
    public function GetMostInterestingDataToSendToKindle ()
234
    {
235 4
        $bestFormatForKindle = array ("EPUB", "PDF", "AZW3", "MOBI");
236 4
        $bestRank = -1;
237 4
        $bestData = NULL;
238 4
        foreach ($this->getDatas () as $data) {
239 4
            $key = array_search ($data->format, $bestFormatForKindle);
240 4
            if ($key !== false && $key > $bestRank) {
241 4
                $bestRank = $key;
242 4
                $bestData = $data;
243 4
            }
244 4
        }
245 4
        return $bestData;
246
    }
247
248 3
    public function getDataById ($idData)
249
    {
250
        $reduced = array_filter ($this->getDatas (), function ($data) use ($idData) {
251 3
            return $data->id == $idData;
252 3
        });
253 3
        return reset ($reduced);
254
    }
255
256 7
    public function getRating () {
257 7
        if (is_null ($this->rating) || $this->rating == 0) {
258 2
            return "";
259
        }
260 5
        $retour = "";
261 5
        for ($i = 0; $i < $this->rating / 2; $i++) {
262 5
            $retour .= "&#9733;";
263 5
        }
264 5
        for ($i = 0; $i < 5 - $this->rating / 2; $i++) {
265 3
            $retour .= "&#9734;";
266 3
        }
267 5
        return $retour;
268
    }
269
270 8
    public function getPubDate () {
271 8
        if (is_null ($this->pubdate) || ($this->pubdate <= -58979923200)) {
272
            return "";
273
        }
274
        else {
275 8
            return date ("Y", $this->pubdate);
276
        }
277
    }
278
279 41
    public function getComment ($withSerie = true) {
280 41
        $addition = "";
281 41
        $se = $this->getSerie ();
282 41
        if (!is_null ($se) && $withSerie) {
283 36
            $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format (localize ("content.series.data"), $this->seriesIndex, htmlspecialchars ($se->name)) . "<br />\n";
284 36
        }
285 41
        if (preg_match ("/<\/(div|p|a|span)>/", $this->comment))
286 41
        {
287 35
            return $addition . html2xhtml ($this->comment);
288
        }
289
        else
290
        {
291 29
            return $addition . htmlspecialchars ($this->comment);
292
        }
293
    }
294
295
    public function getDataFormat ($format) {
296 11
        $reduced = array_filter ($this->getDatas (), function ($data) use ($format) {
297 11
            return $data->format == $format;
298 11
        });
299 11
        return reset ($reduced);
300
    }
301
302 69
    public function getFilePath ($extension, $idData = NULL, $relative = false)
303
    {
304 69
        if ($extension == "jpg")
305 69
        {
306 69
            $file = "cover.jpg";
307 69
        }
308
        else
309
        {
310 2
            $data = $this->getDataById ($idData);
311 2
            if (!$data) return NULL;
312 2
            $file = $data->name . "." . strtolower ($data->format);
313
        }
314
315
        if ($relative)
316 69
        {
317 3
            return $this->relativePath."/".$file;
318
        }
319
        else
320
        {
321 69
            return $this->path."/".$file;
322
        }
323
    }
324
325
    public function getUpdatedEpub ($idData)
326
    {
327
        global $config;
328
        $data = $this->getDataById ($idData);
329
330
        try
331
        {
332
            $epub = new EPub ($data->getLocalPath ());
333
334
            $epub->Title ($this->title);
335
            $authorArray = array ();
336
            foreach ($this->getAuthors() as $author) {
337
                $authorArray [$author->sort] = $author->name;
338
            }
339
            $epub->Authors ($authorArray);
340
            $epub->Language ($this->getLanguages ());
341
            $epub->Description ($this->getComment (false));
342
            $epub->Subjects ($this->getTagsName ());
343
            $epub->Cover2 ($this->getFilePath ("jpg"), "image/jpeg");
344
            $epub->Calibre ($this->uuid);
345
            $se = $this->getSerie ();
346
            if (!is_null ($se)) {
347
                $epub->Serie ($se->name);
348
                $epub->SerieIndex ($this->seriesIndex);
349
            }
350
            if ($config['cops_provide_kepub'] == "1"  && preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) {
351
                $epub->updateForKepub ();
352
            }
353
            $epub->download ($data->getUpdatedFilenameEpub ());
354
        }
355
        catch (Exception $e)
356
        {
357
            echo "Exception : " . $e->getMessage();
358
        }
359
    }
360
361 3
    public function getThumbnail ($width, $height, $outputfile = NULL) {
362 3
        if (is_null ($width) && is_null ($height)) {
363 1
            return false;
364
        }
365
366 3
        $file = $this->getFilePath ("jpg");
367
        // get image size
368 3
        if ($size = GetImageSize($file)) {
369 3
            $w = $size[0];
370 3
            $h = $size[1];
371
            //set new size
372 3
            if (!is_null ($width)) {
373 2
                $nw = $width;
374 2
                if ($nw >= $w) { return false; }
375 1
                $nh = ($nw*$h)/$w;
376 1
            } else {
377 2
                $nh = $height;
378 2
                if ($nh >= $h) { return false; }
379 1
                $nw = ($nh*$w)/$h;
380
            }
381 2
        } else {
382
            return false;
383
        }
384
385
        //draw the image
386 2
        $src_img = imagecreatefromjpeg($file);
387 2
        $dst_img = imagecreatetruecolor($nw,$nh);
388 2
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image
389 2
        imagejpeg($dst_img,$outputfile,80);
390 2
        imagedestroy($src_img);
391 2
        imagedestroy($dst_img);
392
393 2
        return true;
394
    }
395
396 42
    public function getLinkArray ()
397
    {
398 42
        $linkArray = array();
399
400 42
        if ($this->hasCover)
401 42
        {
402 18
            array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL));
403
404 18
            array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL));
405 18
        }
406
407 42
        foreach ($this->getDatas () as $data)
408
        {
409 42
            if ($data->isKnownType ())
410 42
            {
411 42
                array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format));
412 42
            }
413 42
        }
414
415 42
        foreach ($this->getAuthors () as $author) {
416 42
            array_push ($linkArray, new LinkNavigation ($author->getUri (), "related", str_format (localize ("bookentry.author"), localize ("splitByLetter.book.other"), $author->name)));
417 42
        }
418
419 42
        $serie = $this->getSerie ();
420 42
        if (!is_null ($serie)) {
421 39
            array_push ($linkArray, new LinkNavigation ($serie->getUri (), "related", str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name)));
422 39
        }
423
424 42
        return $linkArray;
425
    }
426
427
428 39
    public function getEntry () {
429 39
        return new EntryBook ($this->getTitle (), $this->getEntryId (),
430 39
            $this->getComment (), "text/html",
431 39
            $this->getLinkArray (), $this);
432
    }
433
434 3
    public static function getBookCount($database = NULL) {
435 3
        return parent::executeQuerySingle ('select count(*) from books', $database);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (executeQuerySingle() instead of getBookCount()). 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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
436
    }
437
438 10
    public static function getCount() {
439 10
        global $config;
440 10
        $nBooks = parent::executeQuerySingle ('select count(*) from books');
0 ignored issues
show
Comprehensibility Bug introduced by
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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
441 10
        $result = array();
442 10
        $entry = new Entry (localize ("allbooks.title"),
443 10
                          self::ALL_BOOKS_ID,
444 10
                          str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text",
445 10
                          array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS)), "", $nBooks);
446 10
        array_push ($result, $entry);
447 10
        if ($config['cops_recentbooks_limit'] > 0) {
448 10
            $entry = new Entry (localize ("recent.title"),
449 10
                              self::ALL_RECENT_BOOKS_ID,
450 10
                              str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text",
451 10
                              array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS)), "", $config['cops_recentbooks_limit']);
452 10
            array_push ($result, $entry);
453 10
        }
454 10
        return $result;
455
    }
456
457 8
    public static function getBooksByAuthor($authorId, $n) {
458 8
        return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n);
459
    }
460
461 1
    public static function getBooksByRating($ratingId, $n) {
462 1
        return self::getEntryArray (self::SQL_BOOKS_BY_RATING, array ($ratingId), $n);
463
    }
464
465 2
    public static function getBooksByPublisher($publisherId, $n) {
466 2
        return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n);
467
    }
468
469 2
    public static function getBooksBySeries($serieId, $n) {
470 2
        return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n);
471
    }
472
473 2
    public static function getBooksByTag($tagId, $n) {
474 2
        return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n);
475
    }
476
477 2
    public static function getBooksByLanguage($languageId, $n) {
478 2
        return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n);
479
    }
480
481 3
    public static function getBooksByCustom($customId, $id, $n) {
482 3
        $query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId));
483 3
        return self::getEntryArray ($query, array ($id), $n);
484
    }
485
486 30
    public static function getBookById($bookId) {
487 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...
488 30
from books ' . self::SQL_BOOKS_LEFT_JOIN . '
489 30
where books.id = ?');
490 30
        $result->execute (array ($bookId));
491 30
        while ($post = $result->fetchObject ())
492
        {
493 29
            $book = new Book ($post);
494 29
            return $book;
495
        }
496 1
        return NULL;
497
    }
498
499 1
    public static function getBookByDataId($dataId) {
500 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...
501 1
from data, books ' . self::SQL_BOOKS_LEFT_JOIN . '
502 1
where data.book = books.id and data.id = ?');
503 1
        $result->execute (array ($dataId));
504 1
        while ($post = $result->fetchObject ())
505
        {
506 1
            $book = new Book ($post);
507 1
            $data = new Data ($post, $book);
508 1
            $data->id = $dataId;
509 1
            $book->datas = array ($data);
510 1
            return $book;
511
        }
512
        return NULL;
513
    }
514
515 2
    public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
516 2
        $i = 0;
517 2
        $critArray = array ();
518 2
        foreach (array (PageQueryResult::SCOPE_AUTHOR,
519 2
                        PageQueryResult::SCOPE_TAG,
520 2
                        PageQueryResult::SCOPE_SERIES,
521 2
                        PageQueryResult::SCOPE_PUBLISHER,
522 2
                        PageQueryResult::SCOPE_BOOK) as $key) {
523 2
            if (in_array($key, getCurrentOption ('ignored_categories')) ||
524 2
                (!array_key_exists ($key, $query) && !array_key_exists ("all", $query))) {
525
                $critArray [$i] = self::BAD_SEARCH;
526
            }
527
            else {
528 2
                if (array_key_exists ($key, $query)) {
529
                    $critArray [$i] = $query [$key];
530
                } else {
531 2
                    $critArray [$i] = $query ["all"];
532
                }
533
            }
534 2
            $i++;
535 2
        }
536 2
        return self::getEntryArray (self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage);
537
    }
538
539 1
    public static function getBooks($n) {
540 1
        list ($entryArray, $totalNumber) = self::getEntryArray (self::SQL_BOOKS_ALL , array (), $n);
541 1
        return array ($entryArray, $totalNumber);
542
    }
543
544 3
    public static function getAllBooks() {
545 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...
546
from books
547
group by substr (upper (sort), 1, 1)
548 3
order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", self::getFilterString (), array (), -1);
549 3
        $entryArray = array();
550 3
        while ($post = $result->fetchObject ())
551
        {
552 3
            array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title),
553 3
                str_format (localize("bookword", $post->count), $post->count), "text",
554 3
                array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))), "", $post->count));
555 3
        }
556 3
        return $entryArray;
557
    }
558
559 25
    public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) {
560 25
        return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage);
561
    }
562
563 53
    public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) {
564 53
        list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage);
0 ignored issues
show
Comprehensibility Bug introduced by
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 getFirstName() method in the Son calls the wrong method in the parent class.

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