1 | <?php |
||
18 | class Record extends \App\BaseModel |
||
19 | { |
||
20 | /** @var string Record ID. */ |
||
21 | protected $id; |
||
22 | |||
23 | /** @var string Record name. */ |
||
24 | protected $name = ''; |
||
25 | |||
26 | /** @var string Module name. */ |
||
27 | protected $moduleName; |
||
28 | |||
29 | /** @var array Information about inventory. */ |
||
30 | protected $inventoryData = []; |
||
31 | |||
32 | /** @var array Information about summary inventory. */ |
||
33 | protected $inventorySummaryData = []; |
||
34 | |||
35 | /** @var string Privileges. */ |
||
36 | protected $privileges = []; |
||
37 | |||
38 | /** @var array Custom data. */ |
||
39 | protected $customData = []; |
||
40 | |||
41 | /** @var \YF\Modules\Base\Model\Module Module model instance. */ |
||
42 | protected $moduleModel; |
||
43 | |||
44 | /** |
||
45 | * Static Function to get the instance of a clean Record for the given module name. |
||
46 | * |
||
47 | * @param string $module |
||
48 | * |
||
49 | * @return \self |
||
50 | */ |
||
51 | public static function getInstance(string $module): self |
||
52 | { |
||
53 | $handlerModule = \App\Loader::getModuleClassName($module, 'Model', 'Record'); |
||
54 | $instance = new $handlerModule(); |
||
55 | return $instance->setModuleName($module); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Static function to get the instance of record. |
||
60 | * |
||
61 | * @param string $moduleName |
||
62 | * @param int $recordId |
||
63 | * @param array $headers |
||
64 | * |
||
65 | * @return \self |
||
66 | */ |
||
67 | public static function getInstanceById(string $moduleName, int $recordId, array $headers = []): self |
||
68 | { |
||
69 | $api = \App\Api::getInstance(); |
||
70 | if ($headers) { |
||
|
|||
71 | $api->setCustomHeaders($headers); |
||
72 | } |
||
73 | $result = $api->call("{$moduleName}/Record/{$recordId}"); |
||
74 | $instance = self::getInstance($moduleName); |
||
75 | $instance->setData($result['data'] ?? []); |
||
76 | $instance->setInventoryData($result['inventory'] ?? [], $result['summaryInventory'] ?? []); |
||
77 | $instance->setPrivileges($result['privileges'] ?? []); |
||
78 | $instance->name = $result['name'] ?? ''; |
||
79 | unset($result['data'], $result['inventory'], $result['summaryInventory'], $result['privileges'], $result['name']); |
||
80 | $instance->customData = $result; |
||
81 | $instance->setId($recordId); |
||
82 | return $instance; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Sets information about inventory. |
||
87 | * |
||
88 | * @param array $values |
||
89 | * @param array $summary |
||
90 | * |
||
91 | * @return void |
||
92 | */ |
||
93 | public function setInventoryData(array $values, array $summary = []) |
||
98 | |||
99 | /** |
||
100 | * Returns information about inventory. |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | public function getInventoryData() |
||
108 | |||
109 | /** |
||
110 | * Returns information about summary inventory. |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | public function getInventorySummary() |
||
118 | |||
119 | public function isInventory() |
||
123 | |||
124 | /** |
||
125 | * Function to get the id of the record. |
||
126 | * |
||
127 | * @return int|null |
||
128 | */ |
||
129 | public function getId(): ?int |
||
133 | |||
134 | /** |
||
135 | * Function to set the id of the record. |
||
136 | * |
||
137 | * @param int $value |
||
138 | * |
||
139 | * @return self |
||
140 | */ |
||
141 | public function setId(int $value): self |
||
146 | |||
147 | /** |
||
148 | * Function to get the raw value. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | public function getRawData(): array |
||
156 | |||
157 | /** |
||
158 | * Set raw data. |
||
159 | * |
||
160 | * @param array $rawData |
||
161 | * |
||
162 | * @return self |
||
163 | */ |
||
164 | public function setRawData(array $rawData): self |
||
169 | |||
170 | /** |
||
171 | * Function to get the raw value for a given key. |
||
172 | * |
||
173 | * @param string $key |
||
174 | * |
||
175 | * @return mixed |
||
176 | */ |
||
177 | public function getRawValue(string $key) |
||
181 | |||
182 | /** |
||
183 | * Function to set the raw value for a given key. |
||
184 | * |
||
185 | * @param string $key |
||
186 | * @param mixed $value |
||
187 | * |
||
188 | * @return self |
||
189 | */ |
||
190 | public function setRawValue(string $key, $value): self |
||
195 | |||
196 | /** |
||
197 | * Function to get the name of the module to which the record belongs. |
||
198 | * |
||
199 | * @return string - Record Module Name |
||
200 | */ |
||
201 | public function getModuleName(): string |
||
205 | |||
206 | /** |
||
207 | * Get record module model instance. |
||
208 | * |
||
209 | * @return \YF\Modules\Base\Model\Module - Record module model instance |
||
210 | */ |
||
211 | public function getModuleModel(): Module |
||
215 | |||
216 | /** |
||
217 | * Set record name. |
||
218 | * |
||
219 | * @param string $name |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | public function setName(string $name) |
||
227 | |||
228 | /** |
||
229 | * Record name. |
||
230 | * |
||
231 | * @return string |
||
232 | */ |
||
233 | public function getName() |
||
237 | |||
238 | /** |
||
239 | * Get custom data. |
||
240 | * |
||
241 | * @return array |
||
242 | */ |
||
243 | public function getCustomData(): array |
||
247 | |||
248 | /** |
||
249 | * Set privileges. |
||
250 | * |
||
251 | * @param bool[] $privileges |
||
252 | * |
||
253 | * @return self |
||
254 | */ |
||
255 | public function setPrivileges(array $privileges): self |
||
260 | |||
261 | /** |
||
262 | * Function to get the raw value for a given key. |
||
263 | * |
||
264 | * @param string $key |
||
265 | * |
||
266 | * @return string |
||
267 | */ |
||
268 | public function getDisplayValue(string $key): string |
||
272 | |||
273 | /** |
||
274 | * Get list display value. |
||
275 | * |
||
276 | * @param string $key |
||
277 | * |
||
278 | * @return string |
||
279 | */ |
||
280 | public function getListDisplayValue(string $key): string |
||
289 | |||
290 | /** |
||
291 | * Function to set the name of the module to which the record belongs. |
||
292 | * |
||
293 | * @param string $moduleName |
||
294 | * |
||
295 | * @return \self |
||
296 | */ |
||
297 | public function setModuleName(string $moduleName): self |
||
303 | |||
304 | /** |
||
305 | * Function checks if there are permissions to preview record. |
||
306 | * |
||
307 | * @return bool |
||
308 | */ |
||
309 | public function isViewable() |
||
313 | |||
314 | /** |
||
315 | * Function checks if there are permissions to edit record. |
||
316 | * |
||
317 | * @return bool |
||
318 | */ |
||
319 | public function isEditable(): bool |
||
323 | |||
324 | /** |
||
325 | * Function checks if there are permissions to delete record. |
||
326 | * |
||
327 | * @return bool |
||
328 | */ |
||
329 | public function isDeletable(): bool |
||
333 | |||
334 | /** |
||
335 | * Function checks permissions to action. |
||
336 | * |
||
337 | * @param string $actionName |
||
338 | * |
||
339 | * @return bool |
||
340 | */ |
||
341 | public function isPermitted(string $actionName): bool |
||
345 | |||
346 | /** |
||
347 | * Function to get the list view actions for the record. |
||
348 | * |
||
349 | * @return string |
||
350 | */ |
||
351 | public function getListViewActions(): string |
||
383 | |||
384 | /** |
||
385 | * Function to get the list view actions for the record. |
||
386 | * |
||
387 | * @return string |
||
388 | */ |
||
389 | public function getRelatedListActions(): string |
||
412 | |||
413 | /** |
||
414 | * Function to get the Detail View url for the record. |
||
415 | * |
||
416 | * @return string - Record Detail View Url |
||
417 | */ |
||
418 | public function getDetailViewUrl() |
||
422 | |||
423 | /** |
||
424 | * Function to get the Edit View url for the record. |
||
425 | * |
||
426 | * @return string - Record Edit View Url |
||
427 | */ |
||
428 | public function getEditViewUrl() |
||
432 | |||
433 | /** |
||
434 | * Function to get the delete action url for the record. |
||
435 | * |
||
436 | * @return string |
||
437 | */ |
||
438 | public function getDeleteUrl() |
||
442 | } |
||
443 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.