Completed
Push — master ( df592e...2bd024 )
by Sébastien
02:12
created

Book::getLanguages()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

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