|
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
|
|
|
class CustomColumnTypeSeries extends CustomColumnType |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
2 |
|
protected function __construct($pcustomId) |
|
12
|
|
|
{ |
|
13
|
2 |
|
parent::__construct($pcustomId, self::CUSTOM_TYPE_SERIES); |
|
14
|
2 |
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get the name of the sqlite table for this column |
|
18
|
|
|
* |
|
19
|
|
|
* @return string|null |
|
20
|
|
|
*/ |
|
21
|
7 |
|
private function getTableName() |
|
22
|
|
|
{ |
|
23
|
7 |
|
return "custom_column_{$this->customId}"; |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Get the name of the linking sqlite table for this column |
|
28
|
|
|
* (or NULL if there is no linktable) |
|
29
|
|
|
* |
|
30
|
|
|
* @return string|null |
|
31
|
|
|
*/ |
|
32
|
7 |
|
private function getTableLinkName() |
|
33
|
|
|
{ |
|
34
|
7 |
|
return "books_custom_column_{$this->customId}_link"; |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get the name of the linking column in the linktable |
|
39
|
|
|
* |
|
40
|
|
|
* @return string|null |
|
41
|
|
|
*/ |
|
42
|
7 |
|
private function getTableLinkColumn() |
|
43
|
|
|
{ |
|
44
|
7 |
|
return "value"; |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
3 |
|
public function getQuery($id) |
|
48
|
|
|
{ |
|
49
|
3 |
|
$query = str_format(Book::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", $this->getTableLinkName(), $this->getTableLinkColumn()); |
|
|
|
|
|
|
50
|
3 |
|
return array($query, array($id)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
3 |
|
public function getCustom($id) |
|
54
|
|
|
{ |
|
55
|
3 |
|
$result = Base::getDb()->prepare(str_format("SELECT id, value AS name FROM {0} WHERE id = ?", $this->getTableName())); |
|
|
|
|
|
|
56
|
3 |
|
$result->execute(array($id)); |
|
57
|
3 |
|
if ($post = $result->fetchObject()) { |
|
58
|
3 |
|
return new CustomColumn($id, $post->name, $this); |
|
59
|
|
|
} |
|
60
|
|
|
return NULL; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
View Code Duplication |
protected function getAllCustomValuesFromDatabase() |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
2 |
|
$queryFormat = "SELECT {0}.id AS id, {0}.value AS name, count(*) AS count FROM {0}, {1} WHERE {0}.id = {1}.{2} GROUP BY {0}.id, {0}.value ORDER BY {0}.value"; |
|
|
|
|
|
|
66
|
2 |
|
$query = str_format($queryFormat, $this->getTableName(), $this->getTableLinkName(), $this->getTableLinkColumn()); |
|
67
|
|
|
|
|
68
|
2 |
|
$result = Base::getDb()->query($query); |
|
69
|
2 |
|
$entryArray = array(); |
|
70
|
2 |
|
while ($post = $result->fetchObject()) { |
|
71
|
2 |
|
$entryPContent = str_format(localize("bookword", $post->count), $post->count); |
|
|
|
|
|
|
72
|
2 |
|
$entryPLinkArray = array(new LinkNavigation($this->getUri($post->id))); |
|
73
|
|
|
|
|
74
|
2 |
|
$entry = new Entry($post->name, $this->getEntryId($post->id), $entryPContent, $this->datatype, $entryPLinkArray, "", $post->count); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
2 |
|
array_push($entryArray, $entry); |
|
77
|
2 |
|
} |
|
78
|
2 |
|
return $entryArray; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
5 |
|
public function getDescription() |
|
82
|
|
|
{ |
|
83
|
5 |
|
return str_format(localize("customcolumn.description.series", $this->getDistinctValueCount()), $this->getDistinctValueCount()); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
2 |
|
public function getCustomByBook($book) |
|
87
|
|
|
{ |
|
88
|
2 |
|
$queryFormat = "SELECT {0}.id AS id, {1}.{2} AS name, {1}.extra AS extra FROM {0}, {1} WHERE {0}.id = {1}.{2} AND {1}.book = {3}"; |
|
|
|
|
|
|
89
|
2 |
|
$query = str_format($queryFormat, $this->getTableName(), $this->getTableLinkName(), $this->getTableLinkColumn(), $book->id); |
|
90
|
|
|
|
|
91
|
2 |
|
$result = Base::getDb()->query($query); |
|
92
|
2 |
|
if ($post = $result->fetchObject()) { |
|
93
|
1 |
|
return new CustomColumn($post->id, $post->name . " [" . $post->extra . "]", $this); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
1 |
|
return new CustomColumn(NULL, "", $this); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
5 |
|
public function isSearchable() |
|
99
|
|
|
{ |
|
100
|
5 |
|
return true; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.