1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Base detail view file. |
4
|
|
|
* |
5
|
|
|
* @package View |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce Sp. z o.o. |
8
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
9
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
10
|
|
|
* @author Radosław Skrzypczak <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace YF\Modules\Base\View; |
14
|
|
|
|
15
|
|
|
use App\Purifier; |
16
|
|
|
use YF\Modules\Base\Model\DetailView as DetailViewModel; |
17
|
|
|
use YF\Modules\Base\Model\InventoryField; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Base detail view class. |
21
|
|
|
*/ |
22
|
|
|
class DetailView extends \App\Controller\View |
23
|
|
|
{ |
24
|
|
|
use \App\Controller\ExposeMethodTrait; |
25
|
|
|
|
26
|
|
|
/** @var \YF\Modules\Base\Model\Record Record model instance. */ |
27
|
|
|
protected $recordModel; |
28
|
|
|
|
29
|
|
|
/** @var \YF\Modules\Base\Model\DetailView Record view model. */ |
30
|
|
|
protected $detailViewModel; |
31
|
|
|
|
32
|
|
|
/** {@inheritdoc} */ |
33
|
|
|
public function __construct(\App\Request $request) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($request); |
36
|
|
|
$this->exposeMethod('details'); |
37
|
|
|
$this->exposeMethod('summary'); |
38
|
|
|
$this->exposeMethod('comments'); |
39
|
|
|
$this->exposeMethod('updates'); |
40
|
|
|
$this->exposeMethod('relatedList'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** {@inheritdoc} */ |
44
|
|
|
public function checkPermission(): void |
45
|
|
|
{ |
46
|
|
|
parent::checkPermission(); |
47
|
|
|
$this->recordModel = \YF\Modules\Base\Model\Record::getInstanceById($this->request->getModule(), $this->request->getInteger('record'), [ |
|
|
|
|
48
|
|
|
'x-header-fields' => 1, |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** {@inheritdoc} */ |
53
|
|
|
public function process() |
54
|
|
|
{ |
55
|
|
|
$mode = $this->request->getMode() ?: 'details'; |
56
|
|
|
$this->detailViewModel = DetailViewModel::getInstance($this->recordModel->getModuleName()); |
|
|
|
|
57
|
|
|
$this->detailViewModel->setRecordModel($this->recordModel); |
58
|
|
|
|
59
|
|
|
$this->loadHeader(); |
60
|
|
|
$this->invokeExposedMethod($mode); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Gets header. |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function loadHeader(): void |
69
|
|
|
{ |
70
|
|
|
$moduleName = $this->request->getModule(); |
71
|
|
|
$fieldsForm = $fields = []; |
72
|
|
|
$moduleModel = $this->recordModel->getModuleModel(); |
73
|
|
|
$moduleStructure = $moduleModel->getFieldsFromApi(); |
74
|
|
View Code Duplication |
foreach ($moduleStructure['fields'] as $field) { |
|
|
|
|
75
|
|
|
$fieldModel = $moduleModel->getFieldModel($field['name']); |
76
|
|
|
if ($field['isViewable']) { |
77
|
|
|
$fieldsForm[$field['blockId']][$fieldModel->getName()] = $fieldModel; |
78
|
|
|
} |
79
|
|
|
$fields[$field['name']] = $fieldModel; |
80
|
|
|
} |
81
|
|
|
$this->viewer->assign('RECORD', $this->recordModel); |
82
|
|
|
$this->viewer->assign('FIELDS', $fields); |
83
|
|
|
$this->viewer->assign('FIELDS_FORM', $fieldsForm); |
84
|
|
|
$this->viewer->assign('FIELDS_HEADER', $this->recordModel->getCustomData()['headerFields'] ?? []); |
85
|
|
|
$this->viewer->assign('DETAIL_LINKS', $this->detailViewModel->getLinksHeader()); |
86
|
|
|
$this->viewer->assign('BREADCRUMB_TITLE', $this->recordModel->getName()); |
87
|
|
|
$this->viewer->assign('TABS_GROUP', $this->detailViewModel->getTabsFromApi()); |
88
|
|
|
$this->viewer->assign('MENU_ID', $this->request->has('tabId') ? $this->request->getByType('tabId', Purifier::ALNUM) : 'details'); |
89
|
|
|
$this->viewer->assign('MODE', $this->request->getMode() ?: 'details'); |
90
|
|
|
$this->viewer->view('Detail/Header.tpl', $moduleName); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Details tab. |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
public function details(): void |
99
|
|
|
{ |
100
|
|
|
$moduleName = $this->request->getModule(); |
101
|
|
|
$moduleStructure = $this->recordModel->getModuleModel()->getFieldsFromApi(); |
102
|
|
|
$inventoryFields = []; |
103
|
|
|
if (!empty($moduleStructure['inventory'])) { |
104
|
|
|
$columns = \Conf\Inventory::$columnsByModule[$moduleName] ?? \Conf\Inventory::$columns ?? []; |
105
|
|
|
$columnsIsActive = !empty($columns); |
106
|
|
|
foreach ($moduleStructure['inventory'] as $fieldType => $fieldsInventory) { |
107
|
|
|
if (1 === $fieldType) { |
108
|
|
|
foreach ($fieldsInventory as $field) { |
109
|
|
|
if ($field['isVisibleInDetail'] && (!$columnsIsActive || \in_array($field['columnname'], $columns))) { |
110
|
|
|
$inventoryFields[] = InventoryField::getInstance($moduleName, $field); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
$this->viewer->assign('BLOCKS', $moduleStructure['blocks']); |
117
|
|
|
$this->viewer->assign('INVENTORY_FIELDS', $inventoryFields); |
118
|
|
|
$this->viewer->assign('SHOW_INVENTORY_RIGHT_COLUMN', \Conf\Inventory::$showInventoryRightColumn); |
119
|
|
|
$this->viewer->assign('RECORD', $this->recordModel); |
120
|
|
|
$this->viewer->assign('SUMMARY_INVENTORY', $this->recordModel->getInventorySummary()); |
121
|
|
|
$this->viewer->view('Detail/DetailView.tpl', $moduleName); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Summary tab. |
126
|
|
|
* |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
public function summary(): void |
130
|
|
|
{ |
131
|
|
|
$moduleName = $this->request->getModule(); |
132
|
|
|
$widgets = []; |
133
|
|
|
foreach ($this->detailViewModel->getWidgets() as $widget) { |
134
|
|
|
if ($scripts = $widget->getScripts()) { |
135
|
|
|
$widget->setScriptsObject($this->convertScripts($scripts, 'js')); |
136
|
|
|
} |
137
|
|
|
$widgets[$widget->get('wcol')][] = $widget; |
138
|
|
|
} |
139
|
|
|
$this->viewer->assign('DETAIL_VIEW_WIDGETS', $widgets); |
140
|
|
|
$this->viewer->view('Detail/Summary.tpl', $moduleName); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Comments tab. |
145
|
|
|
* |
146
|
|
|
* @return void |
147
|
|
|
*/ |
148
|
|
|
public function comments(): void |
149
|
|
|
{ |
150
|
|
|
// TODO add data |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Updates tab. |
155
|
|
|
* |
156
|
|
|
* @return void |
157
|
|
|
*/ |
158
|
|
|
public function updates(): void |
159
|
|
|
{ |
160
|
|
|
$moduleName = $this->request->getModule(); |
161
|
|
|
$recordHistory = \YF\Modules\Base\Model\RecordHistory::getInstanceById($moduleName, $this->recordModel->getId()); |
162
|
|
|
$this->viewer->assign('HISTORY_MODEL', $recordHistory); |
163
|
|
|
$this->viewer->view('Detail/History.tpl', $moduleName); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Related list tab. |
168
|
|
|
* |
169
|
|
|
* @return void |
170
|
|
|
*/ |
171
|
|
|
public function relatedList(): void |
172
|
|
|
{ |
173
|
|
|
$relatedListModel = \YF\Modules\Base\Model\RelatedList::getInstance($this->moduleName, 'RelatedList'); |
174
|
|
|
$relatedListModel->setRequest($this->request); |
175
|
|
|
$this->viewer->assign('HEADERS', $relatedListModel->getHeaders()); |
176
|
|
|
$this->viewer->assign('RELATION_ID', $this->request->getInteger('relationId')); |
177
|
|
|
$this->viewer->assign('RELATED_MODULE_NAME', $this->request->getByType('relatedModuleName', Purifier::ALNUM)); |
178
|
|
|
$this->viewer->view('Detail/RelatedList.tpl', $this->request->getModule()); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** {@inheritdoc} */ |
182
|
|
|
public function getFooterScripts(bool $loadForModule = true): array |
183
|
|
|
{ |
184
|
|
|
$moduleName = $this->request->getModule(); |
185
|
|
|
return array_merge( |
186
|
|
|
parent::getFooterScripts(), |
187
|
|
|
$this->convertScripts([ |
188
|
|
|
['layouts/' . \App\Viewer::getLayoutName() . '/modules/Base/resources/RelatedListView.js', true], |
189
|
|
|
['layouts/' . \App\Viewer::getLayoutName() . "/modules/{$moduleName}/resources/RelatedListView.js"], |
190
|
|
|
], 'js')); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..