1 | <?php |
||
19 | class Material extends \samson\activerecord\Material |
||
20 | { |
||
21 | /** Store entity name */ |
||
22 | const ENTITY = __CLASS__; |
||
23 | |||
24 | /** Entity field names constants for using in code */ |
||
25 | const F_PRIMARY = 'MaterialID'; |
||
26 | const F_IDENTIFIER = 'Url'; |
||
27 | const F_DELETION = 'Active'; |
||
28 | const F_PUBLISHED = 'Published'; |
||
29 | const F_PARENT = 'parent_id'; |
||
30 | const F_PRIORITY = 'priority'; |
||
31 | const F_CREATED = 'Created'; |
||
32 | const F_MODIFIED = 'Modyfied'; |
||
33 | |||
34 | /** |
||
35 | * Get material entity by URL(s). |
||
36 | * |
||
37 | * @param QueryInterface $query Object for performing database queries |
||
38 | * @param array|string $url Material URL or collection of material URLs |
||
39 | * @param self|array|null $return Variable where request result would be returned |
||
40 | * @return bool|self True if material entities has been found |
||
41 | */ |
||
42 | public static function byUrl(QueryInterface $query, $url, & $return = array()) |
||
43 | { |
||
44 | // Get entities by filtered identifiers |
||
45 | $return = $query->entity(get_called_class()) |
||
46 | ->where('Url', $url) |
||
47 | ->where('Active', 1) |
||
48 | ->first(); |
||
49 | |||
50 | // If only one argument is passed - return null, otherwise bool |
||
51 | return func_num_args() > 2 ? $return !== null : $return; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Set additional material field value by field identifier |
||
56 | * @param string $fieldID Field identifier |
||
57 | * @param string $value Value to be stored |
||
58 | * @param string $locale Locale identifier |
||
59 | */ |
||
60 | public function setFieldByID($fieldID, $value, $locale = null) |
||
61 | { |
||
62 | /** @var Field $fieldRecord Try to find this additional field */ |
||
63 | $fieldRecord = null; |
||
64 | if (Field::byID($this->query, $fieldID, $fieldRecord)) { |
||
|
|||
65 | /** @var MaterialField $materialFieldRecord Try to find additional field value */ |
||
66 | $materialFieldRecord = null; |
||
67 | if (!MaterialField::byFieldIDAndMaterialID($this->query, $this->id, $fieldRecord->id, $materialFieldRecord, $locale)) { |
||
68 | // Create new additional field value record if it does not exists |
||
69 | $materialFieldRecord = new MaterialField(); |
||
70 | $materialFieldRecord->FieldID = $fieldRecord->id; |
||
71 | $materialFieldRecord->MaterialID = $this->id; |
||
72 | $materialFieldRecord->Active = 1; |
||
73 | |||
74 | // Add locale if field needs it |
||
75 | if ($fieldRecord->localized()) { |
||
76 | $materialFieldRecord->locale = $locale; |
||
77 | } |
||
78 | } else { // Get first record(actually it should be only one) |
||
79 | $materialFieldRecord = array_shift($materialFieldRecord); |
||
80 | } |
||
81 | |||
82 | // At this point we already have database record instance |
||
83 | $valueFieldName = $fieldRecord->valueFieldName(); |
||
84 | $materialFieldRecord->$valueFieldName = $value; |
||
85 | $materialFieldRecord->save(); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Add new row to table of entity |
||
91 | * @param $row |
||
92 | */ |
||
93 | public function addTableRow(Row $row) |
||
146 | |||
147 | /** |
||
148 | * Get select additional field text value. |
||
149 | * |
||
150 | * @param string $fieldID Field identifier |
||
151 | * @return string Select field text |
||
152 | */ |
||
153 | public function selectText($fieldID) |
||
167 | |||
168 | /** |
||
169 | * Get collection of images for material by gallery additional field selector. If none is passed |
||
170 | * all images from gallery table would be returned for this material entity. |
||
171 | * |
||
172 | * @param string|null $fieldSelector Additional field selector value |
||
173 | * @param string $selector Additional field field name to search for |
||
174 | * @return \samsonframework\orm\RecordInterface[] Collection of images in this gallery additional field for material |
||
175 | */ |
||
176 | public function &gallery($fieldSelector = null, $selector = 'FieldID') |
||
205 | |||
206 | /** |
||
207 | * Copy this material related entities. |
||
208 | * |
||
209 | * @param string $entity Entity identifier |
||
210 | * @param string $newIdentifier Copied material idetifier |
||
211 | * @param array $excludedIDs Collection of related entity identifier to exclude from copying |
||
212 | */ |
||
213 | protected function copyRelatedEntity($entity, $newIdentifier, $excludedIDs = array()) |
||
226 | |||
227 | /** |
||
228 | * Create copy of current object. |
||
229 | * |
||
230 | * @param mixed $clone Material for cloning |
||
231 | * @param array $excludedFields Additional fields identifiers not copied |
||
232 | * @returns self New copied instance |
||
233 | */ |
||
234 | public function ©(&$clone = null, $excludedFields = array()) |
||
245 | |||
246 | /** |
||
247 | * Remove current object. |
||
248 | */ |
||
249 | public function remove() |
||
262 | |||
263 | /** |
||
264 | * Remove this material related entities. |
||
265 | * |
||
266 | * @param string $entity Entity identifier |
||
267 | */ |
||
268 | protected function removeRelatedEntity($entity) |
||
277 | } |
||
278 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.