1 | <?php |
||
19 | class Generic |
||
20 | { |
||
21 | /** @var array Collection of all supported entity fields */ |
||
22 | protected static $parentFields = array( |
||
23 | Material::F_PRIORITY => Material::F_PRIORITY, |
||
24 | Material::F_IDENTIFIER => Material::F_IDENTIFIER, |
||
25 | Material::F_DELETION => Material::F_DELETION, |
||
26 | Material::F_PUBLISHED => Material::F_PUBLISHED, |
||
27 | Material::F_PARENT => Material::F_PARENT, |
||
28 | Material::F_CREATED => Material::F_CREATED, |
||
29 | ); |
||
30 | |||
31 | /** @var string Entity identifier */ |
||
32 | protected static $identifier; |
||
33 | |||
34 | /** @var string Entity navigation identifiers */ |
||
35 | protected static $navigationIDs = array(); |
||
36 | |||
37 | /** @var QueryInterface Database query instance */ |
||
38 | protected $query; |
||
39 | |||
40 | /** @var array Collection of entity fields to retrieved from database */ |
||
41 | protected $selectedFields; |
||
42 | |||
43 | /** @var Condition Query conditions */ |
||
44 | protected $conditions; |
||
45 | |||
46 | /** |
||
47 | * Convert date value to database format. |
||
48 | * TODO: Must implement at database layer |
||
49 | * |
||
50 | * @param string $date Date value for conversion |
||
51 | * @return string Converted date to correct format |
||
52 | */ |
||
53 | protected function convertToDateTime($date) |
||
57 | |||
58 | /** |
||
59 | * Add condition to current query. |
||
60 | * |
||
61 | * @param string $fieldName Entity field name |
||
62 | * @param string $fieldValue Value |
||
63 | * @return self Chaining |
||
64 | */ |
||
65 | public function where($fieldName, $fieldValue = null, $fieldRelation = ArgumentInterface::EQUAL) |
||
71 | |||
72 | /** |
||
73 | * Add primary field query condition. |
||
74 | * |
||
75 | * @param string $value Field value |
||
76 | * @return self Chaining |
||
77 | * @see Material::where() |
||
78 | */ |
||
79 | public function primary($value) |
||
83 | |||
84 | /** |
||
85 | * Add identifier field query condition. |
||
86 | * |
||
87 | * @param string $value Field value |
||
88 | * @return self Chaining |
||
89 | * @see Material::where() |
||
90 | */ |
||
91 | public function identifier($value) |
||
95 | |||
96 | /** |
||
97 | * Add entity published field query condition. |
||
98 | * |
||
99 | * @param string $value Field value |
||
100 | * @return self Chaining |
||
101 | * @see Material::where() |
||
102 | */ |
||
103 | public function published($value) |
||
107 | |||
108 | /** |
||
109 | * Add entity creation field query condition. |
||
110 | * |
||
111 | * @param string $value Field value |
||
112 | * @param string $relation @see ArgumentInterface types |
||
113 | * @return self Chaining |
||
114 | * @see Material::where() |
||
115 | */ |
||
116 | public function created($value, $relation = ArgumentInterface::EQUAL) |
||
120 | |||
121 | /** |
||
122 | * Add entity modification field query condition. |
||
123 | * |
||
124 | * @param string $value Field value |
||
125 | * @param string $relation @see ArgumentInterface types |
||
126 | * @return self Chaining |
||
127 | * @see Material::where() |
||
128 | */ |
||
129 | public function modified($value, $relation = ArgumentInterface::EQUAL) |
||
133 | |||
134 | /** |
||
135 | * Perform SamsonCMS query and get entities collection. |
||
136 | * |
||
137 | * @return \samsoncms\api\Entity[] Collection of found entities |
||
138 | */ |
||
139 | public function find() |
||
147 | |||
148 | /** |
||
149 | * Perform SamsonCMS query and get collection of entities fields. |
||
150 | * |
||
151 | * @param string $fieldName Entity field name |
||
152 | * @return array Collection of entity fields |
||
153 | */ |
||
154 | public function fields($fieldName) |
||
162 | |||
163 | /** |
||
164 | * Perform SamsonCMS query and get first matching entity. |
||
165 | * |
||
166 | * @return \samsoncms\api\Entity Firt matching entity |
||
167 | */ |
||
168 | public function first() |
||
179 | |||
180 | /** |
||
181 | * Generic constructor. |
||
182 | * |
||
183 | * @param QueryInterface $query Database query instance |
||
184 | */ |
||
185 | public function __construct(QueryInterface $query) |
||
190 | } |
||
191 |