Passed
Push — developer ( 9daaa0...7262d5 )
by Mariusz
107:10 queued 72:05
created

DetailView::checkPermission()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
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
	}
40
41
	/** {@inheritdoc} */
42
	public function checkPermission(): void
43
	{
44
		parent::checkPermission();
45
		$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...
46
			'x-header-fields' => 1,
47
		]);
48
	}
49
50
	/** {@inheritdoc} */
51
	public function process()
52
	{
53
		$mode = $this->request->getMode() ?: 'details';
54
		$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...
55
		$this->detailViewModel->setRecordModel($this->recordModel);
56
57
		$this->loadHeder();
58
		$this->invokeExposedMethod($mode);
59
	}
60
61
	public function loadHeder()
62
	{
63
		$moduleName = $this->request->getModule();
64
		$fieldsForm = $fields = [];
65
		$moduleModel = $this->recordModel->getModuleModel();
66
		$moduleStructure = $moduleModel->getFieldsFromApi();
67
		foreach ($moduleStructure['fields'] as $field) {
68
			$fieldInstance = $moduleModel->getFieldModel($field['name']);
69
			if ($this->recordModel->has($field['name'])) {
70
				$fieldInstance->setDisplayValue($this->recordModel->get($field['name']));
71
			}
72
			if ($field['isViewable']) {
73
				$fieldsForm[$field['blockId']][] = $fieldInstance;
74
			}
75
			$fields[$field['name']] = $fieldInstance;
76
		}
77
		$this->viewer->assign('FIELDS', $fields);
78
		$this->viewer->assign('FIELDS_FORM', $fieldsForm);
79
		$this->viewer->assign('FIELDS_HEADER', $this->recordModel->getCustomData()['headerFields'] ?? []);
80
		$this->viewer->assign('DETAIL_LINKS', $this->detailViewModel->getLinksHeader());
81
		$this->viewer->assign('BREADCRUMB_TITLE', $this->recordModel->getName());
82
		$this->viewer->view('Detail/Header.tpl', $moduleName);
83
	}
84
85
	/**
86
	 * Details tab.
87
	 *
88
	 * @return void
89
	 */
90
	public function details(): void
91
	{
92
		$moduleName = $this->request->getModule();
93
		$moduleStructure = $this->recordModel->getModuleModel()->getFieldsFromApi();
94
		$inventoryFields = [];
95
		if (!empty($moduleStructure['inventory'])) {
96
			$columns = \Conf\Inventory::$columnsByModule[$moduleName] ?? \Conf\Inventory::$columns ?? [];
97
			$columnsIsActive = !empty($columns);
98
			foreach ($moduleStructure['inventory'] as $fieldType => $fieldsInventory) {
99
				if (1 === $fieldType) {
100
					foreach ($fieldsInventory as $field) {
101
						if ($field['isVisibleInDetail'] && (!$columnsIsActive || \in_array($field['columnname'], $columns))) {
102
							$inventoryFields[] = InventoryField::getInstance($moduleName, $field);
103
						}
104
					}
105
				}
106
			}
107
		}
108
		$this->viewer->assign('RECORD', $this->recordModel);
109
		$this->viewer->assign('BLOCKS', $moduleStructure['blocks']);
110
		$this->viewer->assign('INVENTORY_FIELDS', $inventoryFields);
111
		$this->viewer->assign('SHOW_INVENTORY_RIGHT_COLUMN', \Conf\Inventory::$showInventoryRightColumn);
112
		$this->viewer->assign('SUMMARY_INVENTORY', $this->recordModel->getInventorySummary());
113
		$this->viewer->view('Detail/DetailView.tpl', $moduleName);
114
	}
115
116
	/**
117
	 * Summary tab.
118
	 *
119
	 * @return void
120
	 */
121
	public function summary()
122
	{
123
		// TODO add data
124
	}
125
}
126