|
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 CustomColumnTypeDate extends CustomColumnType |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
1 |
|
protected function __construct($pcustomId) |
|
12
|
|
|
{ |
|
13
|
1 |
|
parent::__construct($pcustomId, self::CUSTOM_TYPE_DATE); |
|
14
|
1 |
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get the name of the sqlite table for this column |
|
18
|
|
|
* |
|
19
|
|
|
* @return string|null |
|
20
|
|
|
*/ |
|
21
|
5 |
|
private function getTableName() |
|
22
|
|
|
{ |
|
23
|
5 |
|
return "custom_column_{$this->customId}"; |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
2 |
|
public function getQuery($id) |
|
27
|
|
|
{ |
|
28
|
2 |
|
$date = new DateTime($id); |
|
29
|
2 |
|
$query = str_format(Book::SQL_BOOKS_BY_CUSTOM_DATE, "{0}", "{1}", $this->getTableName()); |
|
|
|
|
|
|
30
|
2 |
|
return array($query, array($date->format("Y-m-d"))); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
2 |
|
public function getCustom($id) |
|
34
|
|
|
{ |
|
35
|
2 |
|
$date = new DateTime($id); |
|
36
|
|
|
|
|
37
|
2 |
|
return new CustomColumn($id, $date->format(localize("customcolumn.date.format")), $this); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
protected function getAllCustomValuesFromDatabase() |
|
41
|
|
|
{ |
|
42
|
1 |
|
$queryFormat = "SELECT date(value) AS datevalue, count(*) AS count FROM {0} GROUP BY datevalue"; |
|
|
|
|
|
|
43
|
1 |
|
$query = str_format($queryFormat, $this->getTableName()); |
|
44
|
1 |
|
$result = Base::getDb()->query($query); |
|
45
|
|
|
|
|
46
|
1 |
|
$entryArray = array(); |
|
47
|
1 |
|
while ($post = $result->fetchObject()) { |
|
48
|
1 |
|
$date = new DateTime($post->datevalue); |
|
49
|
1 |
|
$id = $date->format("Y-m-d"); |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
1 |
|
$entryPContent = str_format(localize("bookword", $post->count), $post->count); |
|
|
|
|
|
|
52
|
1 |
|
$entryPLinkArray = array(new LinkNavigation ($this->getUri($id))); |
|
53
|
|
|
|
|
54
|
1 |
|
$entry = new Entry($date->format(localize("customcolumn.date.format")), $this->getEntryId($id), $entryPContent, $this->datatype, $entryPLinkArray, "", $post->count); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
1 |
|
array_push($entryArray, $entry); |
|
57
|
1 |
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
return $entryArray; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
3 |
|
public function getDescription() |
|
63
|
|
|
{ |
|
64
|
3 |
|
$desc = $this->getDatabaseDescription(); |
|
65
|
3 |
|
if ($desc === NULL || empty($desc)) $desc = str_format(localize("customcolumn.description"), $this->getTitle()); |
|
|
|
|
|
|
66
|
3 |
|
return $desc; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
2 |
|
public function getCustomByBook($book) |
|
70
|
|
|
{ |
|
71
|
2 |
|
$queryFormat = "SELECT date({0}.value) AS datevalue FROM {0} WHERE {0}.book = {1}"; |
|
|
|
|
|
|
72
|
2 |
|
$query = str_format($queryFormat, $this->getTableName(), $book->id); |
|
73
|
|
|
|
|
74
|
2 |
|
$result = Base::getDb()->query($query); |
|
75
|
2 |
|
if ($post = $result->fetchObject()) { |
|
76
|
1 |
|
$date = new DateTime($post->datevalue); |
|
77
|
|
|
|
|
78
|
1 |
|
return new CustomColumn($date->format("Y-m-d"), $date->format(localize("customcolumn.date.format")), $this); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
1 |
|
return new CustomColumn(NULL, localize("customcolumn.date.unknown"), $this); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
3 |
|
public function isSearchable() |
|
84
|
|
|
{ |
|
85
|
3 |
|
return true; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
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.