1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Edit 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
|
|
|
/** |
16
|
|
|
* Edit view class. |
17
|
|
|
*/ |
18
|
|
|
class EditView extends \App\Controller\View |
19
|
|
|
{ |
20
|
|
|
/** {@inheritdoc} */ |
21
|
|
View Code Duplication |
public function checkPermission(): void |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
parent::checkPermission(); |
24
|
|
|
$actionName = 'EditView'; |
25
|
|
|
if ($this->request->isEmpty('record')) { |
26
|
|
|
$actionName = 'CreateView'; |
27
|
|
|
} |
28
|
|
|
if (!\YF\Modules\Base\Model\Module::isPermitted($this->request->getModule(), $actionName)) { |
29
|
|
|
throw new \App\Exceptions\AppException('ERR_MODULE_PERMISSION_DENIED'); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** {@inheritdoc} */ |
34
|
|
|
public function process() |
35
|
|
|
{ |
36
|
|
|
$moduleName = $this->request->getModule(); |
37
|
|
|
if ($this->request->isEmpty('record')) { |
38
|
|
|
$recordModel = \YF\Modules\Base\Model\Record::getInstance($moduleName); |
39
|
|
|
} else { |
40
|
|
|
$recordModel = \YF\Modules\Base\Model\Record::getInstanceById($moduleName, $this->request->getInteger('record'), ['x-raw-data' => 1]); |
41
|
|
|
} |
42
|
|
|
$moduleModel = $recordModel->getModuleModel(); |
43
|
|
|
$moduleStructure = $moduleModel->getFieldsFromApi(); |
44
|
|
|
$fields = $fieldsForm = []; |
45
|
|
|
foreach ($moduleStructure['fields'] as $field) { |
46
|
|
|
$fieldName = $field['name']; |
47
|
|
|
$fieldInstance = $moduleModel->getFieldModel($fieldName); |
48
|
|
|
if ($field['isEditable']) { |
49
|
|
|
$fieldsForm[$field['blockId']][$fieldInstance->getName()] = $fieldInstance; |
50
|
|
|
} |
51
|
|
|
$fields[$fieldName] = $fieldInstance; |
52
|
|
|
} |
53
|
|
|
$this->viewer->assign('RECORD', $recordModel); |
54
|
|
|
$this->viewer->assign('FIELDS', $fields); |
55
|
|
|
$this->viewer->assign('FIELDS_FORM', $fieldsForm); |
56
|
|
|
$this->viewer->assign('BREADCRUMB_TITLE', $recordModel->getName()); |
57
|
|
|
$this->viewer->assign('BLOCKS', $moduleStructure['blocks']); |
58
|
|
|
$this->viewer->view('Edit/EditView.tpl', $moduleName); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** {@inheritdoc} */ |
62
|
|
|
public function getFooterScripts(bool $loadForModule = true): array |
63
|
|
|
{ |
64
|
|
|
return array_merge( |
65
|
|
|
parent::getFooterScripts(), |
66
|
|
|
$this->convertScripts([ |
67
|
|
|
['layouts/' . \App\Viewer::getLayoutName() . '/modules/Base/resources/EditView.js'], |
68
|
|
|
], 'js') |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.