Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
globalconst.php
1<?php
2
4
8
9\Bitrix\Bizproc\Workflow\Type\GlobalsManager::loadLanguageFile();
10
30{
34 public static function getTableName()
35 {
36 return 'b_bp_global_const';
37 }
38
42 public static function getMap()
43 {
44 return [
45 'ID' => [
46 'data_type' => 'string',
47 'primary' => true,
48 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_ID_TITLE'),
49 ],
50 'NAME' => [
51 'data_type' => 'string',
52 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_NAME_TITLE'),
53 ],
54 'DESCRIPTION' => [
55 'data_type' => 'string',
56 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_DESCRIPTION_TITLE'),
57 ],
58 'PROPERTY_TYPE' => [
59 'data_type' => 'string',
60 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_PROPERTY_TYPE_TITLE'),
61 ],
62 'IS_REQUIRED' => [
63 'data_type' => 'boolean',
64 'values' => ['N', 'Y'],
65 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_IS_REQUIRED_TITLE'),
66 ],
67 'IS_MULTIPLE' => [
68 'data_type' => 'boolean',
69 'values' => ['N', 'Y'],
70 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_IS_MULTIPLE_TITLE'),
71 ],
72 'PROPERTY_OPTIONS' => [
73 'data_type' => 'string',
74 'serialized' => true,
75 'validation' => [__CLASS__, 'validateTextField'],
76 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_PROPERTY_OPTIONS_TITLE'),
77 ],
78 'PROPERTY_SETTINGS' => [
79 'data_type' => 'string',
80 'serialized' => true,
81 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_PROPERTY_SETTINGS_TITLE'),
82 ],
83 'PROPERTY_VALUE' => [
84 'data_type' => 'string',
85 'serialized' => true,
86 'validation' => [__CLASS__, 'validateTextField'],
87 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_PROPERTY_VALUE_TITLE'),
88 ],
89 'CREATED_DATE' => [
90 'data_type' => 'datetime',
91 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_CREATED_DATE_TITLE'),
92 ],
93 'CREATED_BY' => [
94 'data_type' => 'integer',
95 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_CREATED_BY_TITLE'),
96 ],
97 'VISIBILITY' => [
98 'data_type' => 'string',
99 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_VISIBILITY_TITLE'),
100 ],
101 'MODIFIED_DATE' => [
102 'data_type' => 'datetime',
103 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_MODIFIED_DATE_TITLE'),
104 ],
105 'MODIFIED_BY' => [
106 'data_type' => 'integer',
107 'title' => Main\Localization\Loc::getMessage('BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_MODIFIED_BY_TITLE'),
108 ],
109 ];
110 }
111
112 public static function validateTextField()
113 {
114 return [
115 function($value, $primary, $row, \Bitrix\Main\ORM\Fields\Field $field)
116 {
117 $errorMsg = Main\Localization\Loc::getMessage(
118 'BIZPROC_WF_TYPE_GLOBALS_MANAGER_COLUMN_PROPERTIES_TEXT_FIELD_LENGTH_ERROR',
119 ['#FIELD_TITLE#' => $field->getTitle()]
120 );
121
122 return strlen(serialize($value)) < 65535 ? true : $errorMsg;
123 }
124 ];
125 }
126
127 public static function upsertByProperty($constId, array $property, int $userId = null)
128 {
129 $property = static::normalizePropertyForUpsert($property, $userId);
130
131 // PROPERTY_SETTINGS ?
132 $fields = [
133 'NAME' => trim($property['Name']),
134 'DESCRIPTION' => $property['Description'],
135 'PROPERTY_TYPE' => $property['Type'],
136 'IS_REQUIRED' => $property['Required'] ? 'Y' : 'N',
137 'IS_MULTIPLE' => $property['Multiple'] ? 'Y' : 'N',
138 'PROPERTY_OPTIONS' => $property['Options'],
139 'PROPERTY_VALUE' => $property['Default'],
140 'VISIBILITY' => $property['Visibility'],
141 'CREATED_BY' => $property['CreatedBy'],
142 'CREATED_DATE' => $property['CreatedDate'],
143 'MODIFIED_DATE' => $property['ModifiedDate'],
144 'MODIFIED_BY' => $property['ModifiedBy'],
145 ];
146
147 if ($userId === null)
148 {
149 unset($fields['CREATED_BY'], $fields['CREATED_DATE'], $fields['MODIFIED_BY'], $fields['MODIFIED_DATE']);
150 }
151
152 $oldProperty = static::getByPrimary((string)$constId)->fetch();
153 if ($oldProperty)
154 {
155 if (isset($oldProperty['CREATED_BY']))
156 {
157 unset($fields['CREATED_BY'], $fields['CREATED_DATE']);
158 }
159
160 $result = static::update($constId, $fields);
161 }
162 else
163 {
164 $fields['ID'] = $constId;
165 $result = static::add($fields);
166 }
167
168 return $result;
169 }
170
171 public static function convertToProperty(array $fields)
172 {
173 // Settings ?
174 return [
175 'Name' => $fields['NAME'],
176 'Description' => $fields['DESCRIPTION'],
177 'Type' => $fields['PROPERTY_TYPE'],
178 'Required' => \CBPHelper::getBool($fields['IS_REQUIRED']),
179 'Multiple' => \CBPHelper::getBool($fields['IS_MULTIPLE']),
180 'Options' => $fields['PROPERTY_OPTIONS'],
181 'Default' => $fields['PROPERTY_VALUE'],
182 'CreatedBy' => (int)$fields['CREATED_BY'],
183 'CreatedDate' => $fields['CREATED_DATE'],
184 'Visibility' => $fields['VISIBILITY'],
185 'ModifiedBy' => (int)$fields['MODIFIED_BY'],
186 'ModifiedDate' => $fields['MODIFIED_DATE'],
187 ];
188 }
189
190 private static function normalizePropertyForUpsert($property, int $userId = null): array
191 {
192 $normalized = [];
193 $normalizedAsField = FieldType::normalizeProperty($property);
194
195 $normalized['Visibility'] = isset($property['Visibility']) ? (string)$property['Visibility'] : 'GLOBAL';
196 $normalized['ModifiedBy'] = $userId;
197 $normalized['CreatedBy'] = $userId;
198 $normalized['ModifiedDate'] = new Main\Type\DateTime();
199 $normalized['CreatedDate'] = $normalized['ModifiedDate'];
200
201 return array_merge($normalized, $normalizedAsField);
202 }
203
204 public static function onBeforeUpdate(Event $event)
205 {
206 $result = new Main\ORM\EventResult();
207 $result->unsetFields(['PROPERTY_TYPE', 'IS_REQUIRED', 'IS_MULTIPLE', 'VISIBILITY']);
208
209 return $result;
210 }
211}
static normalizeProperty($property)
static upsertByProperty($constId, array $property, int $userId=null)