|
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 CustomColumnTypeBool extends CustomColumnType |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
// PHP pre 5.6 does not support const arrays |
|
12
|
|
|
private $BOOLEAN_NAMES = array( |
|
13
|
|
|
-1 => "customcolumn.boolean.unknown", // localize("customcolumn.boolean.unknown") |
|
|
|
|
|
|
14
|
|
|
00 => "customcolumn.boolean.no", // localize("customcolumn.boolean.no") |
|
|
|
|
|
|
15
|
|
|
+1 => "customcolumn.boolean.yes", // localize("customcolumn.boolean.yes") |
|
|
|
|
|
|
16
|
|
|
); |
|
17
|
|
|
|
|
18
|
1 |
|
protected function __construct($pcustomId) |
|
19
|
|
|
{ |
|
20
|
1 |
|
parent::__construct($pcustomId, self::CUSTOM_TYPE_BOOL); |
|
21
|
1 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Get the name of the sqlite table for this column |
|
25
|
|
|
* |
|
26
|
|
|
* @return string|null |
|
27
|
|
|
*/ |
|
28
|
5 |
|
private function getTableName() |
|
29
|
|
|
{ |
|
30
|
5 |
|
return "custom_column_{$this->customId}"; |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
3 |
|
public function getQuery($id) |
|
34
|
|
|
{ |
|
35
|
3 |
|
if ($id == -1) { |
|
36
|
2 |
|
$query = str_format(Book::SQL_BOOKS_BY_CUSTOM_BOOL_NULL, "{0}", "{1}", $this->getTableName()); |
|
|
|
|
|
|
37
|
2 |
|
return array($query, array()); |
|
38
|
3 |
|
} else if ($id == 0) { |
|
39
|
3 |
|
$query = str_format(Book::SQL_BOOKS_BY_CUSTOM_BOOL_FALSE, "{0}", "{1}", $this->getTableName()); |
|
|
|
|
|
|
40
|
3 |
|
return array($query, array()); |
|
41
|
2 |
|
} else if ($id == 1) { |
|
42
|
2 |
|
$query = str_format(Book::SQL_BOOKS_BY_CUSTOM_BOOL_TRUE, "{0}", "{1}", $this->getTableName()); |
|
|
|
|
|
|
43
|
2 |
|
return array($query, array()); |
|
44
|
|
|
} else { |
|
45
|
|
|
return NULL; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
3 |
|
public function getCustom($id) |
|
50
|
|
|
{ |
|
51
|
3 |
|
return new CustomColumn($id, localize($this->BOOLEAN_NAMES[$id]), $this); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
View Code Duplication |
protected function getAllCustomValuesFromDatabase() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
1 |
|
$queryFormat = "SELECT coalesce({0}.value, -1) AS id, count(*) AS count FROM books LEFT JOIN {0} ON books.id = {0}.book GROUP BY {0}.value ORDER BY {0}.value"; |
|
|
|
|
|
|
57
|
1 |
|
$query = str_format($queryFormat, $this->getTableName()); |
|
58
|
1 |
|
$result = Base::getDb()->query($query); |
|
59
|
|
|
|
|
60
|
1 |
|
$entryArray = array(); |
|
61
|
1 |
|
while ($post = $result->fetchObject()) { |
|
62
|
1 |
|
$entryPContent = str_format(localize("bookword", $post->count), $post->count); |
|
|
|
|
|
|
63
|
1 |
|
$entryPLinkArray = array(new LinkNavigation ($this->getUri($post->id))); |
|
64
|
|
|
|
|
65
|
1 |
|
$entry = new Entry(localize($this->BOOLEAN_NAMES[$post->id]), $this->getEntryId($post->id), $entryPContent, $this->datatype, $entryPLinkArray, "", $post->count); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
1 |
|
array_push($entryArray, $entry); |
|
68
|
1 |
|
} |
|
69
|
1 |
|
return $entryArray; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
3 |
|
public function getDescription() |
|
73
|
|
|
{ |
|
74
|
3 |
|
return localize("customcolumn.description.bool"); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
2 |
|
public function getCustomByBook($book) |
|
78
|
|
|
{ |
|
79
|
2 |
|
$queryFormat = "SELECT {0}.value AS boolvalue FROM {0} WHERE {0}.book = {1}"; |
|
|
|
|
|
|
80
|
2 |
|
$query = str_format($queryFormat, $this->getTableName(), $book->id); |
|
81
|
|
|
|
|
82
|
2 |
|
$result = Base::getDb()->query($query); |
|
83
|
2 |
|
if ($post = $result->fetchObject()) { |
|
84
|
2 |
|
return new CustomColumn($post->boolvalue, localize($this->BOOLEAN_NAMES[$post->boolvalue]), $this); |
|
85
|
|
|
} else { |
|
86
|
|
|
return new CustomColumn(-1, localize($this->BOOLEAN_NAMES[-1]), $this); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
3 |
|
public function isSearchable() |
|
91
|
|
|
{ |
|
92
|
3 |
|
return true; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.