|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Settings search Module model class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright YetiForce S.A. |
|
7
|
|
|
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com) |
|
8
|
|
|
*/ |
|
9
|
|
|
class Settings_Search_Module_Model extends Settings_Vtiger_Module_Model |
|
10
|
|
|
{ |
|
11
|
|
|
/** @var string */ |
|
12
|
|
|
public $name = 'Search'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Get entity modules. |
|
16
|
|
|
* |
|
17
|
|
|
* @param int $tabId |
|
18
|
|
|
* @param bool $onlyActive |
|
19
|
|
|
* |
|
20
|
|
|
* @return array |
|
21
|
|
|
*/ |
|
22
|
|
|
public static function getModulesEntity($tabId = false, $onlyActive = false) |
|
23
|
|
|
{ |
|
24
|
|
|
$query = (new \App\Db\Query()); |
|
25
|
|
|
if ($onlyActive) { |
|
26
|
|
|
$query->select(['vtiger_entityname.*'])->from('vtiger_entityname')->leftJoin('vtiger_tab', 'vtiger_entityname.tabid = vtiger_tab.tabid') |
|
27
|
|
|
->where(['vtiger_tab.presence' => 0]); |
|
28
|
|
|
} else { |
|
29
|
|
|
$query->from(('vtiger_entityname')); |
|
30
|
|
|
|
|
31
|
|
|
if ($tabId) { |
|
|
|
|
|
|
32
|
|
|
$query->where(['tabid' => $tabId]); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
$query->orderBy('vtiger_entityname.sequence'); |
|
36
|
|
|
$dataReader = $query->createCommand()->query(); |
|
37
|
|
|
$moduleEntity = []; |
|
38
|
|
|
while ($row = $dataReader->read()) { |
|
39
|
|
|
$moduleEntity[$row['tabid']] = $row; |
|
40
|
|
|
} |
|
41
|
|
|
$dataReader->close(); |
|
42
|
|
|
return $moduleEntity; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get fields. |
|
47
|
|
|
* |
|
48
|
|
|
* @param mixed $blocks |
|
49
|
|
|
* |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
|
|
public static function getFieldFromModule($blocks = true) |
|
53
|
|
|
{ |
|
54
|
|
|
$fields = []; |
|
55
|
|
|
$dataReader = (new \App\Db\Query())->select(['vtiger_field.tabid', 'vtiger_field.columnname', 'vtiger_field.fieldlabel', 'vtiger_blocks.blocklabel']) |
|
56
|
|
|
->from('vtiger_field') |
|
57
|
|
|
->innerJoin('vtiger_blocks', 'vtiger_blocks.blockid = vtiger_field.block') |
|
58
|
|
|
->where(['not in', 'uitype', [15, 16, 52, 53, 56, 70, 99, 120]]) |
|
59
|
|
|
->andWhere(['presence' => [0, 2]]) |
|
60
|
|
|
->createCommand() |
|
61
|
|
|
->query(); |
|
62
|
|
|
while ($row = $dataReader->read()) { |
|
63
|
|
|
if ($blocks) { |
|
64
|
|
|
$fields[$row['tabid']][$row['blocklabel']][$row['columnname']] = $row; |
|
65
|
|
|
} else { |
|
66
|
|
|
$fields[$row['tabid']][$row['columnname']] = $row; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
$dataReader->close(); |
|
70
|
|
|
|
|
71
|
|
|
return $fields; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Save parameters. |
|
76
|
|
|
* |
|
77
|
|
|
* @param array $params |
|
78
|
|
|
* |
|
79
|
|
|
* @return bool |
|
80
|
|
|
*/ |
|
81
|
|
|
public function save($params) |
|
82
|
|
|
{ |
|
83
|
|
|
$db = App\Db::getInstance(); |
|
84
|
|
|
$name = $params['name']; |
|
85
|
|
|
$tabId = (int) $params['tabid']; |
|
86
|
|
|
$value = $params['value']; |
|
87
|
|
|
|
|
88
|
|
|
if (('searchcolumn' === $name || 'fieldname' === $name) && (empty($value) || array_diff($value, array_keys(self::getFieldFromModule(false)[$tabId])))) { |
|
89
|
|
|
throw new \App\Exceptions\AppException('ERR_NOT_ALLOWED_VALUE'); |
|
90
|
|
|
} |
|
91
|
|
|
$value = \is_array($value) ? implode(',', $value) : $value; |
|
92
|
|
|
$fieldModel = $this->getFieldInstanceByName($name); |
|
93
|
|
|
$fieldModel->getUITypeModel()->validate($value, true); |
|
94
|
|
|
$value = $fieldModel->getUITypeModel()->getDBValue($value); |
|
95
|
|
|
|
|
96
|
|
|
$db->createCommand() |
|
97
|
|
|
->update('vtiger_entityname', [$name => $value], ['tabid' => $tabId]) |
|
98
|
|
|
->execute(); |
|
99
|
|
|
|
|
100
|
|
|
\App\Cache::delete('ModuleEntityInfo', ''); |
|
101
|
|
|
|
|
102
|
|
|
return true; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Update labels. |
|
107
|
|
|
* |
|
108
|
|
|
* @param array $params |
|
109
|
|
|
* |
|
110
|
|
|
* @return void |
|
111
|
|
|
*/ |
|
112
|
|
|
public static function updateLabels($params): void |
|
113
|
|
|
{ |
|
114
|
|
|
$moduleName = App\Module::getModuleName((int) $params['tabid']); |
|
115
|
|
|
$db = App\Db::getInstance(); |
|
116
|
|
|
if ('Users' === $moduleName) { |
|
117
|
|
|
(new \App\BatchMethod(['method' => '\App\User::updateLabels', 'params' => [0]]))->save(); |
|
118
|
|
|
} else { |
|
119
|
|
|
$db->createCommand()->delete('u_#__crmentity_search_label', ['tabid' => $params['tabid']])->execute(); |
|
120
|
|
|
$subQuery = (new \App\Db\Query())->select(['crmid'])->from('vtiger_crmentity')->where(['setype' => $moduleName]); |
|
121
|
|
|
$db->createCommand()->delete('u_#__crmentity_label', ['crmid' => $subQuery])->execute(); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Update sequence number. |
|
127
|
|
|
* |
|
128
|
|
|
* @param array $modulesSequence |
|
129
|
|
|
*/ |
|
130
|
|
|
public static function updateSequenceNumber($modulesSequence) |
|
131
|
|
|
{ |
|
132
|
|
|
\App\Log::trace('Entering Settings_Search_Module_Model::updateSequenceNumber() method ...'); |
|
133
|
|
|
$tabIdList = []; |
|
134
|
|
|
$db = App\Db::getInstance(); |
|
135
|
|
|
$case = ' CASE '; |
|
136
|
|
|
foreach ($modulesSequence as $newModuleSequence) { |
|
137
|
|
|
$tabId = $newModuleSequence['tabid']; |
|
138
|
|
|
$tabIdList[] = $tabId; |
|
139
|
|
|
$case .= " WHEN tabid = {$db->quoteValue($tabId)} THEN {$db->quoteValue($newModuleSequence['sequence'])}"; |
|
140
|
|
|
} |
|
141
|
|
|
$case .= ' END '; |
|
142
|
|
|
$db->createCommand()->update('vtiger_entityname', ['sequence' => new yii\db\Expression($case)], ['tabid' => $tabIdList])->execute(); |
|
143
|
|
|
\App\Log::trace('Exiting Settings_Search_Module_Model::updateSequenceNumber() method ...'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Function determines fields available in edition view. |
|
148
|
|
|
* |
|
149
|
|
|
* @param string $name |
|
150
|
|
|
* |
|
151
|
|
|
* @return \Vtiger_Field_Model |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getFieldInstanceByName($name) |
|
154
|
|
|
{ |
|
155
|
|
|
$moduleName = $this->getName(true); |
|
156
|
|
|
$params = ['column' => $name, 'name' => $name, 'displaytype' => 1, 'typeofdata' => 'V~M', 'presence' => 0, 'isEditableReadOnly' => false]; |
|
157
|
|
|
switch ($name) { |
|
158
|
|
|
case 'searchcolumn': |
|
159
|
|
|
$params['uitype'] = 33; |
|
160
|
|
|
$params['picklistValues'] = []; |
|
161
|
|
|
$params['purifyType'] = \App\Purifier::ALNUM; |
|
162
|
|
|
$params['maximumlength'] = '150'; |
|
163
|
|
|
break; |
|
164
|
|
|
case 'fieldname': |
|
165
|
|
|
$params['uitype'] = 33; |
|
166
|
|
|
$params['picklistValues'] = []; |
|
167
|
|
|
$params['purifyType'] = \App\Purifier::ALNUM; |
|
168
|
|
|
$params['maximumlength'] = '100'; |
|
169
|
|
|
break; |
|
170
|
|
|
case 'turn_off': |
|
171
|
|
|
$params['uitype'] = 56; |
|
172
|
|
|
$params['purifyType'] = \App\Purifier::BOOL; |
|
173
|
|
|
$params['maximumlength'] = '1'; |
|
174
|
|
|
$params['typeofdata'] = 'C~O'; |
|
175
|
|
|
break; |
|
176
|
|
|
default: |
|
177
|
|
|
break; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
return Settings_Vtiger_Field_Model::init($moduleName, $params); |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: