forked from seblucas/cops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomColumnTypeComment.php
70 lines (60 loc) · 1.85 KB
/
CustomColumnTypeComment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* COPS (Calibre OPDS PHP Server) class file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <[email protected]>
*/
class CustomColumnTypeComment extends CustomColumnType
{
protected function __construct($pcustomId)
{
parent::__construct($pcustomId, self::CUSTOM_TYPE_COMMENT);
}
/**
* Get the name of the sqlite table for this column
*
* @return string|null
*/
private function getTableName()
{
return "custom_column_{$this->customId}";
}
public function getQuery($id)
{
$query = str_format(Book::SQL_BOOKS_BY_CUSTOM_DIRECT_ID, "{0}", "{1}", $this->getTableName());
return array($query, array($id));
}
public function getCustom($id)
{
return new CustomColumn($id, $id, $this);
}
public function encodeHTMLValue($value)
{
return "<div>" . $value . "</div>"; // no htmlspecialchars, this is already HTML
}
protected function getAllCustomValuesFromDatabase()
{
return NULL;
}
public function getDescription()
{
$desc = $this->getDatabaseDescription();
if ($desc === NULL || empty($desc)) $desc = str_format(localize("customcolumn.description"), $this->getTitle());
return $desc;
}
public function getCustomByBook($book)
{
$queryFormat = "SELECT {0}.id AS id, {0}.value AS value FROM {0} WHERE {0}.book = {1}";
$query = str_format($queryFormat, $this->getTableName(), $book->id);
$result = $this->getDb()->query($query);
if ($post = $result->fetchObject()) {
return new CustomColumn($post->id, $post->value, $this);
}
return new CustomColumn(NULL, localize("customcolumn.float.unknown"), $this);
}
public function isSearchable()
{
return false;
}
}