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\Field; |
18
|
|
|
use YF\Modules\Base\Model\InventoryField; |
19
|
|
|
use YF\Modules\Base\Model\Record; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Base detail view class. |
23
|
|
|
*/ |
24
|
|
|
class DetailView extends \App\Controller\View |
25
|
|
|
{ |
26
|
|
|
use \App\Controller\ExposeMethodTrait; |
27
|
|
|
|
28
|
|
|
/** {@inheritdoc} */ |
29
|
|
|
public function __construct(\App\Request $request) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($request); |
32
|
|
|
$this->exposeMethod('details'); |
33
|
|
|
$this->exposeMethod('summary'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** {@inheritdoc} */ |
37
|
|
|
public function process() |
38
|
|
|
{ |
39
|
|
|
$mode = $this->request->getMode() ?: 'details'; |
40
|
|
|
$this->invokeExposedMethod($mode); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Details tab. |
45
|
|
|
* |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
|
public function details() |
49
|
|
|
{ |
50
|
|
|
$moduleName = $this->request->getModule(); |
51
|
|
|
$record = $this->request->getByType('record', Purifier::INTEGER); |
52
|
|
|
$recordModel = Record::getInstanceById($moduleName, $record, ['x-header-fields' => 1]); |
53
|
|
|
$moduleStructure = $recordModel->getModuleModel()->getFieldsFromApi(); |
54
|
|
|
$inventoryFields = $fieldsForm = $fields = []; |
55
|
|
|
foreach ($moduleStructure['fields'] as $field) { |
56
|
|
|
$fieldInstance = Field::getInstance($moduleName, $field); |
57
|
|
|
if ($recordModel->has($field['name'])) { |
58
|
|
|
$fieldInstance->setDisplayValue($recordModel->get($field['name'])); |
59
|
|
|
} |
60
|
|
|
if ($field['isViewable']) { |
61
|
|
|
$fieldsForm[$field['blockId']][] = $fieldInstance; |
62
|
|
|
} |
63
|
|
|
$fields[$field['name']] = $fieldInstance; |
64
|
|
|
} |
65
|
|
|
if (!empty($moduleStructure['inventory'])) { |
66
|
|
|
$columns = \Conf\Inventory::$columnsByModule[$moduleName] ?? \Conf\Inventory::$columns ?? []; |
67
|
|
|
$columnsIsActive = !empty($columns); |
68
|
|
|
foreach ($moduleStructure['inventory'] as $fieldType => $fieldsInventory) { |
69
|
|
|
if (1 === $fieldType) { |
70
|
|
|
foreach ($fieldsInventory as $field) { |
71
|
|
|
if ($field['isVisibleInDetail'] && (!$columnsIsActive || \in_array($field['columnname'], $columns))) { |
72
|
|
|
$inventoryFields[] = InventoryField::getInstance($moduleName, $field); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
$detailViewModel = DetailViewModel::getInstance($moduleName); |
79
|
|
|
$detailViewModel->setRecordModel($recordModel); |
80
|
|
|
$this->viewer->assign('BREADCRUMB_TITLE', $recordModel->getName()); |
81
|
|
|
$this->viewer->assign('RECORD', $recordModel); |
82
|
|
|
$this->viewer->assign('FIELDS', $fields); |
83
|
|
|
$this->viewer->assign('FIELDS_FORM', $fieldsForm); |
84
|
|
|
$this->viewer->assign('BLOCKS', $moduleStructure['blocks']); |
85
|
|
|
$this->viewer->assign('INVENTORY_FIELDS', $inventoryFields); |
86
|
|
|
$this->viewer->assign('SHOW_INVENTORY_RIGHT_COLUMN', \Conf\Inventory::$showInventoryRightColumn); |
87
|
|
|
$this->viewer->assign('SUMMARY_INVENTORY', $recordModel->getInventorySummary()); |
88
|
|
|
$this->viewer->assign('DETAIL_LINKS', $detailViewModel->getLinksHeader()); |
89
|
|
|
$this->viewer->assign('FIELDS_HEADER', $recordModel->getCustomData()['headerFields'] ?? []); |
90
|
|
|
$this->viewer->view('Detail/DetailView.tpl', $moduleName); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Summary tab. |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
public function summary() |
99
|
|
|
{ |
100
|
|
|
// TODO add data |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|