Complex classes like Book often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Book, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 72 | class Book extends Base { |
||
| 73 | const ALL_BOOKS_UUID = "urn:uuid"; |
||
| 74 | const ALL_BOOKS_ID = "cops:books"; |
||
| 75 | const ALL_RECENT_BOOKS_ID = "cops:recentbooks"; |
||
| 76 | const BOOK_COLUMNS = "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid, has_cover, ratings.rating"; |
||
| 77 | |||
| 78 | const SQL_BOOKS_LEFT_JOIN = SQL_BOOKS_LEFT_JOIN; |
||
| 79 | const SQL_BOOKS_ALL = SQL_BOOKS_ALL; |
||
| 80 | const SQL_BOOKS_BY_PUBLISHER = SQL_BOOKS_BY_PUBLISHER; |
||
| 81 | const SQL_BOOKS_BY_FIRST_LETTER = SQL_BOOKS_BY_FIRST_LETTER; |
||
| 82 | const SQL_BOOKS_BY_AUTHOR = SQL_BOOKS_BY_AUTHOR; |
||
| 83 | const SQL_BOOKS_BY_SERIE = SQL_BOOKS_BY_SERIE; |
||
| 84 | const SQL_BOOKS_BY_TAG = SQL_BOOKS_BY_TAG; |
||
| 85 | const SQL_BOOKS_BY_LANGUAGE = SQL_BOOKS_BY_LANGUAGE; |
||
| 86 | const SQL_BOOKS_BY_CUSTOM = SQL_BOOKS_BY_CUSTOM; |
||
| 87 | const SQL_BOOKS_BY_CUSTOM_BOOL_TRUE = SQL_BOOKS_BY_CUSTOM_BOOL_TRUE; |
||
| 88 | const SQL_BOOKS_BY_CUSTOM_BOOL_FALSE = SQL_BOOKS_BY_CUSTOM_BOOL_FALSE; |
||
| 89 | const SQL_BOOKS_BY_CUSTOM_BOOL_NULL = SQL_BOOKS_BY_CUSTOM_BOOL_NULL; |
||
| 90 | const SQL_BOOKS_BY_CUSTOM_RATING = SQL_BOOKS_BY_CUSTOM_RATING; |
||
| 91 | const SQL_BOOKS_BY_CUSTOM_RATING_NULL = SQL_BOOKS_BY_CUSTOM_RATING_NULL; |
||
| 92 | const SQL_BOOKS_BY_CUSTOM_DATE = SQL_BOOKS_BY_CUSTOM_DATE; |
||
| 93 | const SQL_BOOKS_BY_CUSTOM_DIRECT = SQL_BOOKS_BY_CUSTOM_DIRECT; |
||
| 94 | const SQL_BOOKS_BY_CUSTOM_DIRECT_ID = SQL_BOOKS_BY_CUSTOM_DIRECT_ID; |
||
| 95 | const SQL_BOOKS_QUERY = SQL_BOOKS_QUERY; |
||
| 96 | const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT; |
||
| 97 | const SQL_BOOKS_BY_RATING = SQL_BOOKS_BY_RATING; |
||
| 98 | |||
| 99 | const BAD_SEARCH = "QQQQQ"; |
||
| 100 | |||
| 101 | public $id; |
||
| 102 | public $title; |
||
| 103 | public $timestamp; |
||
| 104 | public $pubdate; |
||
| 105 | public $path; |
||
| 106 | public $uuid; |
||
| 107 | public $hasCover; |
||
| 108 | public $relativePath; |
||
| 109 | public $seriesIndex; |
||
| 110 | public $comment; |
||
| 111 | public $rating; |
||
| 112 | public $datas = NULL; |
||
| 113 | public $authors = NULL; |
||
| 114 | public $publisher = NULL; |
||
| 115 | public $serie = NULL; |
||
| 116 | public $tags = NULL; |
||
| 117 | public $languages = NULL; |
||
| 118 | public $format = array (); |
||
| 119 | |||
| 120 | |||
| 121 | 78 | public function __construct($line) { |
|
| 122 | 78 | $this->id = $line->id; |
|
| 123 | 78 | $this->title = $line->title; |
|
| 124 | 78 | $this->timestamp = strtotime ($line->timestamp); |
|
| 125 | 78 | $this->pubdate = $line->pubdate; |
|
| 126 | 78 | $this->path = Base::getDbDirectory () . $line->path; |
|
| 127 | 78 | $this->relativePath = $line->path; |
|
| 128 | 78 | $this->seriesIndex = $line->series_index; |
|
| 129 | 78 | $this->comment = $line->comment; |
|
| 130 | 78 | $this->uuid = $line->uuid; |
|
| 131 | 78 | $this->hasCover = $line->has_cover; |
|
| 132 | 78 | if (!file_exists ($this->getFilePath ("jpg"))) { |
|
| 133 | // double check |
||
| 134 | 44 | $this->hasCover = 0; |
|
| 135 | 44 | } |
|
| 136 | 78 | $this->rating = $line->rating; |
|
| 137 | 78 | } |
|
| 138 | |||
| 139 | 42 | public function getEntryId () { |
|
| 140 | 42 | return self::ALL_BOOKS_UUID.":".$this->uuid; |
|
| 141 | } |
||
| 142 | |||
| 143 | 4 | public static function getEntryIdByLetter ($startingLetter) { |
|
| 144 | 4 | return self::ALL_BOOKS_ID.":letter:".$startingLetter; |
|
| 145 | } |
||
| 146 | |||
| 147 | 3 | public function getUri () { |
|
| 148 | 3 | return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id"; |
|
| 149 | } |
||
| 150 | |||
| 151 | 3 | public function getDetailUrl () { |
|
| 156 | |||
| 157 | 43 | public function getTitle () { |
|
| 158 | 43 | return $this->title; |
|
| 159 | } |
||
| 160 | |||
| 161 | /* Other class (author, series, tag, ...) initialization and accessors */ |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @return Author[] |
||
| 165 | */ |
||
| 166 | 49 | public function getAuthors () { |
|
| 167 | 49 | if (is_null ($this->authors)) { |
|
| 168 | 49 | $this->authors = Author::getAuthorByBookId ($this->id); |
|
| 169 | 49 | } |
|
| 170 | 49 | return $this->authors; |
|
| 171 | } |
||
| 172 | |||
| 173 | public function getAuthorsName () { |
||
| 174 | return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ())); |
||
| 175 | } |
||
| 176 | |||
| 177 | public function getAuthorsSort () { |
||
| 178 | return implode (", ", array_map (function ($author) { return $author->sort; }, $this->getAuthors ())); |
||
| 179 | } |
||
| 180 | |||
| 181 | 5 | public function getPublisher () { |
|
| 182 | 5 | if (is_null ($this->publisher)) { |
|
| 183 | 5 | $this->publisher = Publisher::getPublisherByBookId ($this->id); |
|
| 184 | 5 | } |
|
| 185 | 5 | return $this->publisher; |
|
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @return Serie |
||
| 190 | */ |
||
| 191 | 48 | public function getSerie () { |
|
| 192 | 48 | if (is_null ($this->serie)) { |
|
| 193 | 48 | $this->serie = Serie::getSerieByBookId ($this->id); |
|
| 194 | 48 | } |
|
| 195 | 48 | return $this->serie; |
|
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @return string |
||
| 200 | */ |
||
| 201 | 10 | public function getLanguages () { |
|
| 202 | 10 | $lang = array (); |
|
| 203 | 10 | $result = parent::getDb ()->prepare('select languages.lang_code |
|
|
|
|||
| 204 | from books_languages_link, languages |
||
| 205 | where books_languages_link.lang_code = languages.id |
||
| 206 | and book = ? |
||
| 207 | 10 | order by item_order'); |
|
| 208 | 10 | $result->execute (array ($this->id)); |
|
| 209 | 10 | while ($post = $result->fetchObject ()) |
|
| 210 | { |
||
| 211 | 10 | array_push ($lang, Language::getLanguageString($post->lang_code)); |
|
| 212 | 10 | } |
|
| 213 | 10 | return implode (", ", $lang); |
|
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @return Tag[] |
||
| 218 | */ |
||
| 219 | 10 | public function getTags () { |
|
| 220 | 10 | if (is_null ($this->tags)) { |
|
| 221 | 10 | $this->tags = array (); |
|
| 222 | |||
| 223 | 10 | $result = parent::getDb ()->prepare('select tags.id as id, name |
|
| 224 | from books_tags_link, tags |
||
| 225 | where tag = tags.id |
||
| 226 | and book = ? |
||
| 227 | 10 | order by name'); |
|
| 228 | 10 | $result->execute (array ($this->id)); |
|
| 229 | 10 | while ($post = $result->fetchObject ()) |
|
| 230 | { |
||
| 231 | 9 | array_push ($this->tags, new Tag ($post)); |
|
| 232 | 9 | } |
|
| 233 | 10 | } |
|
| 234 | 10 | return $this->tags; |
|
| 235 | } |
||
| 236 | |||
| 237 | public function getTagsName () { |
||
| 238 | return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ())); |
||
| 239 | } |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @return Data[] |
||
| 243 | */ |
||
| 244 | 62 | public function getDatas () |
|
| 245 | { |
||
| 246 | 62 | if (is_null ($this->datas)) { |
|
| 247 | 62 | $this->datas = Data::getDataByBook ($this); |
|
| 248 | 62 | } |
|
| 249 | 62 | return $this->datas; |
|
| 250 | } |
||
| 251 | |||
| 252 | /* End of other class (author, series, tag, ...) initialization and accessors */ |
||
| 253 | |||
| 254 | 58 | public static function getFilterString () { |
|
| 255 | 58 | $filter = getURLParam ("tag", NULL); |
|
| 256 | 58 | if (empty ($filter)) return ""; |
|
| 257 | |||
| 258 | 3 | $exists = true; |
|
| 259 | 3 | if (preg_match ("/^!(.*)$/", $filter, $matches)) { |
|
| 260 | 1 | $exists = false; |
|
| 261 | 1 | $filter = $matches[1]; |
|
| 262 | 1 | } |
|
| 263 | |||
| 264 | 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 . "')"; |
|
| 265 | |||
| 266 | 3 | if (!$exists) { |
|
| 267 | 1 | $result = "not " . $result; |
|
| 268 | 1 | } |
|
| 269 | |||
| 270 | 3 | return "and " . $result; |
|
| 271 | } |
||
| 272 | |||
| 273 | 4 | public function GetMostInterestingDataToSendToKindle () |
|
| 274 | { |
||
| 275 | 4 | $bestFormatForKindle = array ("EPUB", "PDF", "AZW3", "MOBI"); |
|
| 276 | 4 | $bestRank = -1; |
|
| 277 | 4 | $bestData = NULL; |
|
| 278 | 4 | foreach ($this->getDatas () as $data) { |
|
| 279 | 4 | $key = array_search ($data->format, $bestFormatForKindle); |
|
| 280 | 4 | if ($key !== false && $key > $bestRank) { |
|
| 281 | 4 | $bestRank = $key; |
|
| 282 | 4 | $bestData = $data; |
|
| 283 | 4 | } |
|
| 284 | 4 | } |
|
| 285 | 4 | return $bestData; |
|
| 286 | } |
||
| 287 | |||
| 288 | 3 | public function getDataById ($idData) |
|
| 289 | { |
||
| 290 | $reduced = array_filter ($this->getDatas (), function ($data) use ($idData) { |
||
| 291 | 3 | return $data->id == $idData; |
|
| 292 | 3 | }); |
|
| 293 | 3 | return reset ($reduced); |
|
| 294 | } |
||
| 295 | |||
| 296 | 8 | public function getRating () { |
|
| 297 | 8 | if (is_null ($this->rating) || $this->rating == 0) { |
|
| 298 | 3 | return ""; |
|
| 299 | } |
||
| 300 | 5 | $retour = ""; |
|
| 301 | 5 | for ($i = 0; $i < $this->rating / 2; $i++) { |
|
| 302 | 5 | $retour .= "★"; |
|
| 303 | 5 | } |
|
| 304 | 5 | for ($i = 0; $i < 5 - $this->rating / 2; $i++) { |
|
| 305 | 3 | $retour .= "☆"; |
|
| 306 | 3 | } |
|
| 307 | 5 | return $retour; |
|
| 308 | } |
||
| 309 | |||
| 310 | 15 | public function getPubDate () { |
|
| 311 | 15 | if (empty ($this->pubdate)) { |
|
| 312 | 2 | return ""; |
|
| 313 | } |
||
| 314 | 13 | $dateY = (int) substr($this->pubdate, 0, 4); |
|
| 315 | 13 | if ($dateY > 102) { |
|
| 316 | 12 | return str_pad($dateY, 4, "0", STR_PAD_LEFT); |
|
| 317 | } |
||
| 318 | 1 | return ""; |
|
| 319 | } |
||
| 320 | |||
| 321 | 43 | public function getComment ($withSerie = true) { |
|
| 322 | 43 | $addition = ""; |
|
| 323 | 43 | $se = $this->getSerie (); |
|
| 324 | 43 | if (!is_null ($se) && $withSerie) { |
|
| 325 | 38 | $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format (localize ("content.series.data"), $this->seriesIndex, htmlspecialchars ($se->name)) . "<br />\n"; |
|
| 326 | 38 | } |
|
| 327 | 43 | if (preg_match ("/<\/(div|p|a|span)>/", $this->comment)) |
|
| 328 | 43 | { |
|
| 329 | 37 | return $addition . html2xhtml ($this->comment); |
|
| 330 | } |
||
| 331 | else |
||
| 332 | { |
||
| 333 | 31 | return $addition . htmlspecialchars ($this->comment); |
|
| 334 | } |
||
| 335 | } |
||
| 336 | |||
| 337 | public function getDataFormat ($format) { |
||
| 338 | 12 | $reduced = array_filter ($this->getDatas (), function ($data) use ($format) { |
|
| 339 | 12 | return $data->format == $format; |
|
| 340 | 12 | }); |
|
| 341 | 12 | return reset ($reduced); |
|
| 342 | } |
||
| 343 | |||
| 344 | 78 | public function getFilePath ($extension, $idData = NULL, $relative = false) |
|
| 345 | { |
||
| 346 | 78 | if ($extension == "jpg") |
|
| 347 | 78 | { |
|
| 348 | 78 | $file = "cover.jpg"; |
|
| 349 | 78 | } |
|
| 350 | else |
||
| 351 | { |
||
| 352 | 2 | $data = $this->getDataById ($idData); |
|
| 353 | 2 | if (!$data) return NULL; |
|
| 354 | 2 | $file = $data->name . "." . strtolower ($data->format); |
|
| 355 | } |
||
| 356 | |||
| 357 | if ($relative) |
||
| 358 | 78 | { |
|
| 359 | 3 | return $this->relativePath."/".$file; |
|
| 360 | } |
||
| 361 | else |
||
| 362 | { |
||
| 363 | 78 | return $this->path."/".$file; |
|
| 364 | } |
||
| 365 | } |
||
| 366 | |||
| 367 | public function getUpdatedEpub ($idData) |
||
| 368 | { |
||
| 369 | global $config; |
||
| 370 | $data = $this->getDataById ($idData); |
||
| 371 | |||
| 372 | try |
||
| 373 | { |
||
| 374 | $epub = new EPub ($data->getLocalPath ()); |
||
| 375 | |||
| 376 | $epub->Title ($this->title); |
||
| 377 | $authorArray = array (); |
||
| 378 | foreach ($this->getAuthors() as $author) { |
||
| 379 | $authorArray [$author->sort] = $author->name; |
||
| 380 | } |
||
| 381 | $epub->Authors ($authorArray); |
||
| 382 | $epub->Language ($this->getLanguages ()); |
||
| 383 | $epub->Description ($this->getComment (false)); |
||
| 384 | $epub->Subjects ($this->getTagsName ()); |
||
| 385 | $epub->Cover2 ($this->getFilePath ("jpg"), "image/jpeg"); |
||
| 386 | $epub->Calibre ($this->uuid); |
||
| 387 | $se = $this->getSerie (); |
||
| 388 | if (!is_null ($se)) { |
||
| 389 | $epub->Serie ($se->name); |
||
| 390 | $epub->SerieIndex ($this->seriesIndex); |
||
| 391 | } |
||
| 392 | if ($config['cops_provide_kepub'] == "1" && preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) { |
||
| 393 | $epub->updateForKepub (); |
||
| 394 | } |
||
| 395 | $epub->download ($data->getUpdatedFilenameEpub ()); |
||
| 396 | } |
||
| 397 | catch (Exception $e) |
||
| 398 | { |
||
| 399 | echo "Exception : " . $e->getMessage(); |
||
| 400 | } |
||
| 401 | } |
||
| 402 | |||
| 403 | 3 | public function getThumbnail ($width, $height, $outputfile = NULL) { |
|
| 404 | 3 | if (is_null ($width) && is_null ($height)) { |
|
| 405 | 1 | return false; |
|
| 406 | } |
||
| 407 | |||
| 408 | 3 | $file = $this->getFilePath ("jpg"); |
|
| 409 | // get image size |
||
| 410 | 3 | if ($size = GetImageSize($file)) { |
|
| 411 | 3 | $w = $size[0]; |
|
| 412 | 3 | $h = $size[1]; |
|
| 413 | //set new size |
||
| 414 | 3 | if (!is_null ($width)) { |
|
| 415 | 2 | $nw = $width; |
|
| 416 | 2 | if ($nw >= $w) { return false; } |
|
| 417 | 1 | $nh = ($nw*$h)/$w; |
|
| 418 | 1 | } else { |
|
| 419 | 2 | $nh = $height; |
|
| 420 | 2 | if ($nh >= $h) { return false; } |
|
| 421 | 1 | $nw = ($nh*$w)/$h; |
|
| 422 | } |
||
| 423 | 2 | } else { |
|
| 424 | return false; |
||
| 425 | } |
||
| 426 | |||
| 427 | //draw the image |
||
| 428 | 2 | $src_img = imagecreatefromjpeg($file); |
|
| 429 | 2 | $dst_img = imagecreatetruecolor($nw,$nh); |
|
| 430 | 2 | imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image |
|
| 431 | 2 | imagejpeg($dst_img,$outputfile,80); |
|
| 432 | 2 | imagedestroy($src_img); |
|
| 433 | 2 | imagedestroy($dst_img); |
|
| 434 | |||
| 435 | 2 | return true; |
|
| 436 | } |
||
| 437 | |||
| 438 | 44 | public function getLinkArray () |
|
| 439 | { |
||
| 440 | 44 | $linkArray = array(); |
|
| 441 | |||
| 442 | 44 | if ($this->hasCover) |
|
| 443 | 44 | { |
|
| 444 | 18 | array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)); |
|
| 445 | |||
| 446 | 18 | array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL)); |
|
| 447 | 18 | } |
|
| 448 | |||
| 449 | 44 | foreach ($this->getDatas () as $data) |
|
| 450 | { |
||
| 451 | 44 | if ($data->isKnownType ()) |
|
| 452 | 44 | { |
|
| 453 | 44 | array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format)); |
|
| 454 | 44 | } |
|
| 455 | 44 | } |
|
| 456 | |||
| 457 | 44 | foreach ($this->getAuthors () as $author) { |
|
| 458 | /* @var $author Author */ |
||
| 459 | 44 | array_push ($linkArray, new LinkNavigation ($author->getUri (), "related", str_format (localize ("bookentry.author"), localize ("splitByLetter.book.other"), $author->name))); |
|
| 460 | 44 | } |
|
| 461 | |||
| 462 | 44 | $serie = $this->getSerie (); |
|
| 463 | 44 | if (!is_null ($serie)) { |
|
| 464 | 41 | array_push ($linkArray, new LinkNavigation ($serie->getUri (), "related", str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name))); |
|
| 465 | 41 | } |
|
| 466 | |||
| 467 | 44 | return $linkArray; |
|
| 468 | } |
||
| 469 | |||
| 470 | |||
| 471 | 41 | public function getEntry () { |
|
| 472 | 41 | return new EntryBook ($this->getTitle (), $this->getEntryId (), |
|
| 473 | 41 | $this->getComment (), "text/html", |
|
| 474 | 41 | $this->getLinkArray (), $this); |
|
| 475 | } |
||
| 476 | |||
| 477 | 3 | public static function getBookCount($database = NULL) { |
|
| 478 | 3 | return parent::executeQuerySingle ('select count(*) from books', $database); |
|
| 479 | } |
||
| 480 | |||
| 481 | 21 | public static function getCount() { |
|
| 482 | 21 | global $config; |
|
| 483 | 21 | $nBooks = parent::executeQuerySingle ('select count(*) from books'); |
|
| 484 | 21 | $result = array(); |
|
| 485 | 21 | $entry = new Entry (localize ("allbooks.title"), |
|
| 486 | 21 | self::ALL_BOOKS_ID, |
|
| 487 | 21 | str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text", |
|
| 488 | 21 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS)), "", $nBooks); |
|
| 489 | 21 | array_push ($result, $entry); |
|
| 490 | 21 | if ($config['cops_recentbooks_limit'] > 0) { |
|
| 491 | 21 | $entry = new Entry (localize ("recent.title"), |
|
| 492 | 21 | self::ALL_RECENT_BOOKS_ID, |
|
| 493 | 21 | str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text", |
|
| 494 | 21 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS)), "", $config['cops_recentbooks_limit']); |
|
| 495 | 21 | array_push ($result, $entry); |
|
| 496 | 21 | } |
|
| 497 | 21 | return $result; |
|
| 498 | } |
||
| 499 | |||
| 500 | 8 | public static function getBooksByAuthor($authorId, $n) { |
|
| 501 | 8 | return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n); |
|
| 502 | } |
||
| 503 | |||
| 504 | 1 | public static function getBooksByRating($ratingId, $n) { |
|
| 507 | |||
| 508 | 2 | public static function getBooksByPublisher($publisherId, $n) { |
|
| 511 | |||
| 512 | 2 | public static function getBooksBySeries($serieId, $n) { |
|
| 513 | 2 | return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n); |
|
| 514 | } |
||
| 515 | |||
| 516 | 2 | public static function getBooksByTag($tagId, $n) { |
|
| 517 | 2 | return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n); |
|
| 518 | } |
||
| 519 | |||
| 520 | 2 | public static function getBooksByLanguage($languageId, $n) { |
|
| 521 | 2 | return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n); |
|
| 522 | } |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @param $customColumn CustomColumn |
||
| 526 | * @param $id integer |
||
| 527 | * @param $n integer |
||
| 528 | * @return array |
||
| 529 | */ |
||
| 530 | 4 | public static function getBooksByCustom($customColumn, $id, $n) { |
|
| 531 | 4 | list($query, $params) = $customColumn->getQuery($id); |
|
| 532 | |||
| 533 | 4 | return self::getEntryArray ($query, $params, $n); |
|
| 534 | } |
||
| 535 | |||
| 536 | 37 | public static function getBookById($bookId) { |
|
| 537 | 37 | $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' |
|
| 538 | 37 | from books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
|
| 539 | 37 | where books.id = ?'); |
|
| 548 | |||
| 549 | 1 | public static function getBookByDataId($dataId) { |
|
| 564 | |||
| 565 | 2 | public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 588 | |||
| 589 | 1 | public static function getBooks($n) { |
|
| 593 | |||
| 594 | 3 | public static function getAllBooks() { |
|
| 595 | /* @var $result PDOStatement */ |
||
| 596 | |||
| 597 | 3 | list (, $result) = parent::executeQuery ("select {0} |
|
| 598 | from books |
||
| 599 | group by substr (upper (sort), 1, 1) |
||
| 600 | 3 | order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", self::getFilterString (), array (), -1); |
|
| 601 | |||
| 602 | 3 | $entryArray = array(); |
|
| 603 | 3 | while ($post = $result->fetchObject ()) |
|
| 604 | { |
||
| 605 | 3 | array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title), |
|
| 606 | 3 | str_format (localize("bookword", $post->count), $post->count), "text", |
|
| 607 | 3 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
|
| 608 | 3 | } |
|
| 609 | 3 | return $entryArray; |
|
| 610 | } |
||
| 611 | |||
| 612 | 25 | public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 615 | |||
| 616 | 55 | public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 617 | /* @var $totalNumber integer */ |
||
| 618 | /* @var $result PDOStatement */ |
||
| 619 | 55 | list($totalNumber, $result) = parent::executeQuery($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage); |
|
| 620 | |||
| 621 | 55 | $entryArray = array(); |
|
| 622 | 55 | while ($post = $result->fetchObject()) |
|
| 623 | { |
||
| 624 | 41 | $book = new Book ($post); |
|
| 625 | 41 | array_push ($entryArray, $book->getEntry()); |
|
| 626 | 41 | } |
|
| 627 | 55 | return array ($entryArray, $totalNumber); |
|
| 628 | } |
||
| 629 | |||
| 630 | 5 | public static function getAllRecentBooks() { |
|
| 635 | |||
| 636 | /** |
||
| 637 | * The values of all the specified columns |
||
| 638 | * |
||
| 639 | * @param string[] $columns |
||
| 640 | * @return CustomColumn[] |
||
| 641 | */ |
||
| 642 | 5 | public function getCustomColumnValues($columns, $asArray = false) { |
|
| 661 | } |
||
| 662 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.