|
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 CustomColumnTypeComment extends CustomColumnType |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
1 |
|
protected function __construct($pcustomId) |
|
12
|
|
|
{ |
|
13
|
1 |
|
parent::__construct($pcustomId, self::CUSTOM_TYPE_COMMENT); |
|
14
|
1 |
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get the name of the sqlite table for this column |
|
18
|
|
|
* |
|
19
|
|
|
* @return string|null |
|
20
|
|
|
*/ |
|
21
|
4 |
|
private function getTableName() |
|
22
|
|
|
{ |
|
23
|
4 |
|
return "custom_column_{$this->customId}"; |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
2 |
|
public function getQuery($id) |
|
27
|
|
|
{ |
|
28
|
2 |
|
$query = str_format(Book::SQL_BOOKS_BY_CUSTOM_DIRECT_ID, "{0}", "{1}", $this->getTableName()); |
|
|
|
|
|
|
29
|
2 |
|
return array($query, array($id)); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
2 |
|
public function getCustom($id) |
|
33
|
|
|
{ |
|
34
|
2 |
|
return new CustomColumn($id, $id, $this); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
4 |
|
public function encodeHTMLValue($value) |
|
38
|
|
|
{ |
|
39
|
4 |
|
return "<div>" . $value . "</div>"; // no htmlspecialchars, this is already HTML |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function getAllCustomValuesFromDatabase() |
|
43
|
|
|
{ |
|
44
|
|
|
return NULL; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public function getDescription() |
|
48
|
|
|
{ |
|
49
|
1 |
|
$desc = $this->getDatabaseDescription(); |
|
50
|
1 |
|
if ($desc === NULL || empty($desc)) $desc = str_format(localize("customcolumn.description"), $this->getTitle()); |
|
|
|
|
|
|
51
|
1 |
|
return $desc; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
2 |
|
public function getCustomByBook($book) |
|
55
|
|
|
{ |
|
56
|
2 |
|
$queryFormat = "SELECT {0}.id AS id, {0}.value AS value FROM {0} WHERE {0}.book = {1}"; |
|
|
|
|
|
|
57
|
2 |
|
$query = str_format($queryFormat, $this->getTableName(), $book->id); |
|
58
|
|
|
|
|
59
|
2 |
|
$result = Base::getDb()->query($query); |
|
60
|
2 |
|
if ($post = $result->fetchObject()) { |
|
61
|
1 |
|
return new CustomColumn($post->id, $post->value, $this); |
|
62
|
|
|
} |
|
63
|
1 |
|
return new CustomColumn(NULL, localize("customcolumn.float.unknown"), $this); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
3 |
|
public function isSearchable() |
|
67
|
|
|
{ |
|
68
|
3 |
|
return false; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
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.