|
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
|
|
|
/** |
|
10
|
|
|
* A CustomColumn with an value |
|
11
|
|
|
*/ |
|
12
|
|
|
class CustomColumn extends Base |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
/* @var string|integer the ID of the value */ |
|
15
|
|
|
public $valueID; |
|
16
|
|
|
/* @var string the (string) representation of the value */ |
|
17
|
|
|
public $value; |
|
18
|
|
|
/* @var CustomColumnType the custom column that contains the value */ |
|
19
|
|
|
public $customColumnType; |
|
20
|
|
|
/* @var string the value encoded for HTML displaying */ |
|
21
|
|
|
public $htmlvalue; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* CustomColumn constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param integer $pid id of the chosen value |
|
27
|
|
|
* @param string $pvalue string representation of the value |
|
28
|
|
|
* @param CustomColumnType $pcustomColumnType the CustomColumn this value lives in |
|
29
|
|
|
*/ |
|
30
|
7 |
|
public function __construct($pid, $pvalue, $pcustomColumnType) |
|
31
|
|
|
{ |
|
32
|
7 |
|
$this->valueID = $pid; |
|
33
|
7 |
|
$this->value = $pvalue; |
|
34
|
7 |
|
$this->customColumnType = $pcustomColumnType; |
|
35
|
7 |
|
$this->htmlvalue = $this->customColumnType->encodeHTMLValue($this->value); |
|
36
|
7 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get the URI to show all books with this value |
|
40
|
|
|
* |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getUri() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->customColumnType->getUri($this->valueID); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Get the EntryID to show all books with this value |
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
4 |
|
public function getEntryId() |
|
54
|
|
|
{ |
|
55
|
4 |
|
return $this->customColumnType->getEntryId($this->valueID); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Get the query to find all books with this value |
|
60
|
|
|
* the returning array has two values: |
|
61
|
|
|
* - first the query (string) |
|
62
|
|
|
* - second an array of all PreparedStatement parameters |
|
63
|
|
|
* |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
6 |
|
public function getQuery() |
|
67
|
|
|
{ |
|
68
|
6 |
|
return $this->customColumnType->getQuery($this->valueID); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Return the value of this column as an HTML snippet |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getHTMLEncodedValue() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->htmlvalue; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Create an CustomColumn by CustomColumnID and ValueID |
|
83
|
|
|
* |
|
84
|
|
|
* @param integer $customId the id of the customColumn |
|
85
|
|
|
* @param integer $id the id of the chosen value |
|
86
|
|
|
* @return CustomColumn|null |
|
87
|
|
|
*/ |
|
88
|
4 |
|
public static function createCustom($customId, $id) |
|
89
|
|
|
{ |
|
90
|
4 |
|
$columnType = CustomColumnType::createByCustomID($customId); |
|
91
|
|
|
|
|
92
|
4 |
|
return $columnType->getCustom($id); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Return this object as an array |
|
97
|
|
|
* |
|
98
|
|
|
* @return array |
|
99
|
|
|
*/ |
|
100
|
1 |
|
public function toArray() |
|
101
|
|
|
{ |
|
102
|
|
|
return array( |
|
103
|
1 |
|
'valueID' => $this->valueID, |
|
104
|
1 |
|
'value' => $this->value, |
|
105
|
1 |
|
'customColumnType' => (array)$this->customColumnType, |
|
106
|
1 |
|
'htmlvalue' => $this->htmlvalue, |
|
107
|
1 |
|
); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
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.