1
|
|
|
<?php |
2
|
|
|
/* +*********************************************************************************** |
3
|
|
|
* The contents of this file are subject to the vtiger CRM Public License Version 1.0 |
4
|
|
|
* ("License"); You may not use this file except in compliance with the License |
5
|
|
|
* The Original Code is: vtiger CRM Open Source |
6
|
|
|
* The Initial Developer of the Original Code is vtiger. |
7
|
|
|
* Portions created by vtiger are Copyright (C) vtiger. |
8
|
|
|
* All Rights Reserved. |
9
|
|
|
* *********************************************************************************** */ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Vtiger Edit View Record Structure Model. |
13
|
|
|
*/ |
14
|
|
|
class Vtiger_EditRecordStructure_Model extends Vtiger_RecordStructure_Model |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Function to get the values in structured format. |
18
|
|
|
* |
19
|
|
|
* @return array - values in structure array('block'=>array(fieldinfo)); |
20
|
|
|
*/ |
21
|
|
|
public function getStructure() |
22
|
|
|
{ |
23
|
|
|
if (!empty($this->structuredValues)) { |
24
|
|
|
return $this->structuredValues; |
25
|
|
|
} |
26
|
|
|
$values = []; |
27
|
|
|
$recordModel = $this->getRecord(); |
28
|
|
|
$recordId = $recordModel->getId(); |
29
|
|
|
$fieldsDependency = \App\FieldsDependency::getByRecordModel($recordModel->isNew() ? 'Create' : 'Edit', $recordModel); |
30
|
|
|
$blockModelList = $this->getModule()->getBlocks(); |
31
|
|
|
foreach ($blockModelList as $blockLabel => $blockModel) { |
32
|
|
|
if ($fieldModelList = $blockModel->getFields()) { |
33
|
|
|
$values[$blockLabel] = []; |
34
|
|
|
foreach ($fieldModelList as $fieldName => $fieldModel) { |
35
|
|
|
if ($fieldModel->isEditable() && (!$fieldsDependency['hide']['backend'] || !\in_array($fieldName, $fieldsDependency['hide']['backend']))) { |
36
|
|
|
if ('' !== $recordModel->get($fieldName)) { |
37
|
|
|
$fieldModel->set('fieldvalue', $recordModel->get($fieldName)); |
38
|
|
|
} else { |
39
|
|
|
$defaultValue = $fieldModel->getDefaultFieldValue(); |
40
|
|
|
if ('' !== $defaultValue && !$recordId) { |
41
|
|
|
$fieldModel->set('fieldvalue', $defaultValue); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
if ($fieldsDependency['hide']['frontend'] && \in_array($fieldName, $fieldsDependency['hide']['frontend'])) { |
45
|
|
|
$fieldModel->set('hideField', true); |
46
|
|
|
} |
47
|
|
|
if ($fieldsDependency['mandatory'] && \in_array($fieldName, $fieldsDependency['mandatory'])) { |
48
|
|
|
$fieldModel->set('isMandatory', true); |
49
|
|
|
} |
50
|
|
|
$values[$blockLabel][$fieldName] = $fieldModel; |
51
|
|
|
if ($fieldModel->get('tabindex') > Vtiger_Field_Model::$tabIndexLastSeq) { |
52
|
|
|
Vtiger_Field_Model::$tabIndexLastSeq = $fieldModel->get('tabindex'); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
++Vtiger_Field_Model::$tabIndexLastSeq; |
59
|
|
|
return $this->structuredValues = $values; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|