|
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
|
|
View Code Duplication |
class Serie extends Base { |
|
|
|
|
|
|
10
|
|
|
const ALL_SERIES_ID = "cops:series"; |
|
|
|
|
|
|
11
|
|
|
const SERIES_COLUMNS = "series.id as id, series.name as name, series.sort as sort, count(*) as count"; |
|
|
|
|
|
|
12
|
|
|
const SQL_ALL_SERIES = "select {0} from series, books_series_link where series.id = series group by series.id, series.name, series.sort order by series.sort"; |
|
|
|
|
|
|
13
|
|
|
const SQL_SERIES_FOR_SEARCH = "select {0} from series, books_series_link where series.id = series and upper (series.name) like ? group by series.id, series.name, series.sort order by series.sort"; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
public $id; |
|
16
|
|
|
public $name; |
|
17
|
|
|
|
|
18
|
46 |
|
public function __construct($post) { |
|
19
|
46 |
|
$this->id = $post->id; |
|
20
|
46 |
|
$this->name = $post->name; |
|
21
|
46 |
|
} |
|
22
|
|
|
|
|
23
|
46 |
|
public function getUri () { |
|
24
|
46 |
|
return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id"; |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
7 |
|
public function getEntryId () { |
|
28
|
7 |
|
return self::ALL_SERIES_ID.":".$this->id; |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
7 |
|
public static function getCount() { |
|
32
|
|
|
// str_format (localize("series.alphabetical", count(array)) |
|
|
|
|
|
|
33
|
7 |
|
return parent::getCountGeneric ("series", self::ALL_SERIES_ID, parent::PAGE_ALL_SERIES); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
45 |
|
public static function getSerieByBookId ($bookId) { |
|
37
|
45 |
|
$result = parent::getDb ()->prepare('select series.id as id, name |
|
|
|
|
|
|
38
|
|
|
from books_series_link, series |
|
39
|
45 |
|
where series.id = series and book = ?'); |
|
40
|
45 |
|
$result->execute (array ($bookId)); |
|
41
|
45 |
|
if ($post = $result->fetchObject ()) { |
|
42
|
40 |
|
return new Serie ($post); |
|
43
|
|
|
} |
|
44
|
19 |
|
return NULL; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public static function getSerieById ($serieId) { |
|
48
|
1 |
|
$result = parent::getDb ()->prepare('select id, name from series where id = ?'); |
|
|
|
|
|
|
49
|
1 |
|
$result->execute (array ($serieId)); |
|
50
|
1 |
|
if ($post = $result->fetchObject ()) { |
|
51
|
1 |
|
return new Serie ($post); |
|
52
|
|
|
} |
|
53
|
|
|
return NULL; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
2 |
|
public static function getAllSeries() { |
|
57
|
2 |
|
return Base::getEntryArrayWithBookNumber (self::SQL_ALL_SERIES, self::SERIES_COLUMNS, array (), "Serie"); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
22 |
|
public static function getAllSeriesByQuery($query) { |
|
61
|
22 |
|
return Base::getEntryArrayWithBookNumber (self::SQL_SERIES_FOR_SEARCH, self::SERIES_COLUMNS, array ('%' . $query . '%'), "Serie"); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.