1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Related list view model file. |
4
|
|
|
* |
5
|
|
|
* @package Model |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce Sp. z o.o |
8
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
9
|
|
|
* @author Radosław Skrzypczak <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace YF\Modules\ModComments\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Related list view model class. |
16
|
|
|
*/ |
17
|
|
|
class RelatedList extends \YF\Modules\Base\Model\RelatedList |
18
|
|
|
{ |
19
|
|
|
/** {@inheritdoc} */ |
20
|
|
|
protected $order = 'DESC'; |
21
|
|
|
|
22
|
|
|
/** {@inheritdoc} */ |
23
|
|
|
protected $orderField = 'createdtime'; |
24
|
|
|
|
25
|
|
|
/** {@inheritdoc} */ |
26
|
|
|
protected $rawData = true; |
27
|
|
|
|
28
|
|
|
/** {@inheritdoc} */ |
29
|
|
|
protected $relatedModuleName = 'ModComments'; |
30
|
|
|
|
31
|
|
|
/** {@inheritdoc} */ |
32
|
|
|
protected $actionName = 'RecordRelatedList'; |
33
|
|
|
|
34
|
|
|
/** {@inheritdoc} */ |
35
|
|
|
protected $fields = ['parent_comments', 'createdtime', 'modifiedtime', 'related_to', 'id', |
36
|
|
|
'assigned_user_id', 'commentcontent', 'creator', 'customer', 'reasontoedit', 'userid', 'parents']; |
37
|
|
|
|
38
|
|
|
/** @var int Record ID */ |
39
|
|
|
protected $recordId; |
40
|
|
|
|
41
|
|
|
/** @var array Records Models */ |
42
|
|
|
protected $recordsModel = []; |
43
|
|
|
|
44
|
|
|
/** {@inheritdoc} */ |
45
|
|
|
public static function getInstance(string $moduleName, string $viewName = 'ListView') |
46
|
|
|
{ |
47
|
|
|
$self = new self(); |
48
|
|
|
$self->moduleName = $moduleName; |
49
|
|
|
$self->limit = 100; |
50
|
|
|
return $self; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Set record ID. |
55
|
|
|
* |
56
|
|
|
* @param int $recordId |
57
|
|
|
* |
58
|
|
|
* @return $this |
59
|
|
|
*/ |
60
|
|
|
public function setRecordId(int $recordId) |
61
|
|
|
{ |
62
|
|
|
$this->recordId = $recordId; |
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** {@inheritdoc} */ |
67
|
|
|
protected function getFromApi(array $headers): array |
68
|
|
|
{ |
69
|
|
|
$api = \App\Api::getInstance(); |
70
|
|
|
$api->setCustomHeaders($headers); |
71
|
|
|
return $api->call("{$this->getModuleName()}/RecordRelatedList/{$this->recordId}/{$this->relatedModuleName}"); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Gets records tree. |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function getRecordsTree(): array |
80
|
|
|
{ |
81
|
|
|
$recordsModel = []; |
82
|
|
|
if (!empty($this->recordsList['records'])) { |
83
|
|
|
foreach ($this->recordsList['records'] as $id => $value) { |
84
|
|
|
$recordModel = $this->getRecordById($id); |
|
|
|
|
85
|
|
|
|
86
|
|
|
if (!($parentId = $recordModel->getRawValue('parent_comments'))) { |
|
|
|
|
87
|
|
|
$recordsModel[$id] = $recordModel; |
88
|
|
|
} elseif ($parentRecord = $this->getRecordById($parentId)) { |
|
|
|
|
89
|
|
|
$parentRecord->setChild($recordModel); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
return $recordsModel; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Gets record model. |
98
|
|
|
* |
99
|
|
|
* @param int $recordId |
100
|
|
|
* |
101
|
|
|
* @return \YF\Modules\Base\Model\Record|null |
102
|
|
|
*/ |
103
|
|
|
public function getRecordById(int $recordId) |
104
|
|
|
{ |
105
|
|
|
if (!isset($this->recordModels[$recordId]) && ($value = $this->recordsList['records'][$recordId] ?? null)) { |
|
|
|
|
106
|
|
|
$recordModel = Record::getInstance($this->relatedModuleName); |
107
|
|
|
if (isset($value['recordLabel'])) { |
108
|
|
|
$recordModel->setName($value['recordLabel']); |
109
|
|
|
unset($value['recordLabel']); |
110
|
|
|
} |
111
|
|
|
if (isset($this->recordsList['rawData'][$recordId])) { |
112
|
|
|
$recordModel->setRawData($this->recordsList['rawData'][$recordId]); |
113
|
|
|
} |
114
|
|
|
$recordModel->setData($value)->setId($recordId)->setPrivileges($this->recordsList['permissions'][$recordId]); |
115
|
|
|
$this->recordModels[$recordId] = $recordModel; |
|
|
|
|
116
|
|
|
} |
117
|
|
|
return $this->recordModels[$recordId] ?? null; |
|
|
|
|
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.