Passed
Push — developer ( 3a47f7...154d89 )
by Mariusz
171:00 queued 135:56
created

DetailView::summary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
use YF\Modules\Base\Model\Record;
19
20
/**
21
 * Base detail view class.
22
 */
23
class DetailView extends \App\Controller\View
24
{
25
	use \App\Controller\ExposeMethodTrait;
26
27
	/** @var \YF\Modules\Base\Model\Record Record model instance. */
28
	protected $recordModel;
29
30
	/** @var \YF\Modules\Base\Model\DetailView Record model instance. */
31
	protected $detailViewModel;
32
33
	/** {@inheritdoc} */
34
	public function __construct(\App\Request $request)
35
	{
36
		parent::__construct($request);
37
		$this->exposeMethod('details');
38
		$this->exposeMethod('summary');
39
		$this->exposeMethod('comments');
40
		$this->exposeMethod('updates');
41
		$this->exposeMethod('relatedList');
42
	}
43
44
	/** {@inheritdoc} */
45
	public function checkPermission(): void
46
	{
47
		parent::checkPermission();
48
		$this->recordModel = \YF\Modules\Base\Model\Record::getInstanceById($this->request->getModule(), $this->request->getByType('record', Purifier::INTEGER), [
0 ignored issues
show
Documentation Bug introduced by
It seems like \YF\Modules\Base\Model\R...x-header-fields' => 1)) of type object<self> is incompatible with the declared type object<YF\Modules\Base\Model\Record> of property $recordModel.

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..

Loading history...
49
			'x-header-fields' => 1,
50
		]);
51
	}
52
53
	/** {@inheritdoc} */
54
	public function process()
55
	{
56
		$mode = $this->request->getMode() ?: 'details';
57
		$this->detailViewModel = DetailViewModel::getInstance($this->recordModel->getModuleName());
0 ignored issues
show
Documentation Bug introduced by
It seems like \YF\Modules\Base\Model\D...Model->getModuleName()) of type object<self> is incompatible with the declared type object<YF\Modules\Base\Model\DetailView> of property $detailViewModel.

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..

Loading history...
58
		$this->detailViewModel->setRecordModel($this->recordModel);
59
60
		$this->loadHeader();
61
		$this->invokeExposedMethod($mode);
62
	}
63
64
	/**
65
	 * Gets header.
66
	 *
67
	 * @return void
68
	 */
69
	public function loadHeader()
70
	{
71
		$moduleName = $this->request->getModule();
72
		$fieldsForm = $fields = [];
73
		$moduleModel = $this->recordModel->getModuleModel();
74
		$moduleStructure = $moduleModel->getFieldsFromApi();
75
		foreach ($moduleStructure['fields'] as $field) {
76
			$fieldInstance = $moduleModel->getFieldModel($field['name']);
77
			if ($this->recordModel->has($field['name'])) {
78
				$fieldInstance->setDisplayValue($this->recordModel->get($field['name']));
79
			}
80
			if ($field['isViewable']) {
81
				$fieldsForm[$field['blockId']][] = $fieldInstance;
82
			}
83
			$fields[$field['name']] = $fieldInstance;
84
		}
85
		$this->viewer->assign('RECORD', $this->recordModel);
86
		$this->viewer->assign('FIELDS', $fields);
87
		$this->viewer->assign('FIELDS_FORM', $fieldsForm);
88
		$this->viewer->assign('FIELDS_HEADER', $this->recordModel->getCustomData()['headerFields'] ?? []);
89
		$this->viewer->assign('DETAIL_LINKS', $this->detailViewModel->getLinksHeader());
90
		$this->viewer->assign('BREADCRUMB_TITLE', $this->recordModel->getName());
91
		$this->viewer->assign('TABS_GROUP', $this->detailViewModel->getTabsFromApi());
92
		$this->viewer->assign('MENU_ID', $this->request->has('tabId') ? $this->request->getByType('tabId', Purifier::ALNUM) : 'details');
93
		$this->viewer->view('Detail/Header.tpl', $moduleName);
94
	}
95
96
	/**
97
	 * Details tab.
98
	 *
99
	 * @return void
100
	 */
101
	public function details(): void
102
	{
103
		$moduleName = $this->request->getModule();
104
		$moduleStructure = $this->recordModel->getModuleModel()->getFieldsFromApi();
105
		$inventoryFields = [];
106
		if (!empty($moduleStructure['inventory'])) {
107
			$columns = \Conf\Inventory::$columnsByModule[$moduleName] ?? \Conf\Inventory::$columns ?? [];
108
			$columnsIsActive = !empty($columns);
109
			foreach ($moduleStructure['inventory'] as $fieldType => $fieldsInventory) {
110
				if (1 === $fieldType) {
111
					foreach ($fieldsInventory as $field) {
112
						if ($field['isVisibleInDetail'] && (!$columnsIsActive || \in_array($field['columnname'], $columns))) {
113
							$inventoryFields[] = InventoryField::getInstance($moduleName, $field);
114
						}
115
					}
116
				}
117
			}
118
		}
119
		$this->viewer->assign('BLOCKS', $moduleStructure['blocks']);
120
		$this->viewer->assign('INVENTORY_FIELDS', $inventoryFields);
121
		$this->viewer->assign('SHOW_INVENTORY_RIGHT_COLUMN', \Conf\Inventory::$showInventoryRightColumn);
122
		$this->viewer->assign('SUMMARY_INVENTORY', $this->recordModel->getInventorySummary());
123
		$this->viewer->view('Detail/DetailView.tpl', $moduleName);
124
	}
125
126
	/**
127
	 * Summary tab.
128
	 *
129
	 * @return void
130
	 */
131
	public function summary()
132
	{
133
		// TODO add data
134
	}
135
136
	/**
137
	 * Comments tab.
138
	 *
139
	 * @return void
140
	 */
141
	public function comments()
142
	{
143
		// TODO add data
144
	}
145
146
	/**
147
	 * Updates tab.
148
	 *
149
	 * @return void
150
	 */
151
	public function updates()
152
	{
153
		// TODO add data
154
	}
155
156
	/**
157
	 * Related list tab.
158
	 *
159
	 * @return void
160
	 */
161
	public function relatedList()
162
	{
163
		// TODO add data
164
	}
165
}
166