Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
StoreProvider.php
1<?php
2
4
11use Bitrix\UI\EntityEditor\ProviderWithUserFieldsTrait;
12
17{
18 use ProviderWithUserFieldsTrait {
19 getUfComponentFields as getUfComponentFieldsParent;
20 }
21
22 private ?string $userFieldCreatePageUrl;
23
27 public function getUfEntityId(): string
28 {
29 return StoreTable::getUfId();
30 }
31
32 public function getUfPrefix(): string
33 {
34 return $this->getUfEntityId();
35 }
36
42 private array $entity;
43
48 public function __construct(array $entityFields, ?string $userFieldCreatePageUrl = null)
49 {
50 $this->entity = $entityFields;
51 $this->userFieldCreatePageUrl = $userFieldCreatePageUrl;
52 }
53
57 public function getEntityId(): ?int
58 {
59 return $this->entity['ID'] ?? null;
60 }
61
65 public function getGUID(): string
66 {
67 $id = $this->getEntityId() ?? 0;
68
69 return "store_{$id}_details";
70 }
71
77 public function getConfigId(): string
78 {
79 return 'store_details';
80 }
81
85 public function getEntityTypeName(): string
86 {
87 return 'store';
88 }
89
93 public function getEntityFields(): array
94 {
95 $isDefaultStore = isset($this->entity['IS_DEFAULT']) && $this->entity['IS_DEFAULT'] === 'Y';
96
97 $fields = [
98 [
99 'name' => 'TITLE',
100 'title' => static::getFieldTitle('TITLE'),
101 'type' => 'text',
102 'showAlways' => true,
103 ],
104 [
105 'name' => 'CODE',
106 'title' => static::getFieldTitle('CODE'),
107 'type' => 'text',
108 'visibilityPolicy' => 'edit',
109 ],
110 [
111 'name' => 'ADDRESS',
112 'title' => static::getFieldTitle('ADDRESS'),
113 'type' => 'textarea',
114 'required' => true,
115 'showAlways' => true,
116 ],
117 [
118 'name' => 'DESCRIPTION',
119 'title' => static::getFieldTitle('DESCRIPTION'),
120 'type' => 'textarea',
121 'visibilityPolicy' => 'edit',
122 ],
123 [
124 'name' => 'PHONE',
125 'title' => static::getFieldTitle('PHONE'),
126 'type' => 'text',
127 'showAlways' => true,
128 ],
129 [
130 'name' => 'SCHEDULE',
131 'title' => static::getFieldTitle('SCHEDULE'),
132 'type' => 'text',
133 'showAlways' => true,
134 ],
135 [
136 'name' => 'EMAIL',
137 'title' => static::getFieldTitle('EMAIL'),
138 'type' => 'email',
139 'visibilityPolicy' => 'edit',
140 ],
141 [
142 'name' => 'GPS_N',
143 'title' => static::getFieldTitle('GPS_N'),
144 'type' => 'text',
145 'visibilityPolicy' => 'edit',
146 ],
147 [
148 'name' => 'GPS_S',
149 'title' => static::getFieldTitle('GPS_S'),
150 'type' => 'text',
151 'visibilityPolicy' => 'edit',
152 ],
153 [
154 'name' => 'XML_ID',
155 'title' => static::getFieldTitle('XML_ID'),
156 'type' => 'text',
157 'visibilityPolicy' => 'edit',
158 ],
159 [
160 'name' => 'SORT',
161 'title' => static::getFieldTitle('SORT'),
162 'type' => 'number',
163 'default_value' => 100,
164 'visibilityPolicy' => 'edit',
165 ],
166 [
167 'name' => 'ACTIVE',
168 'title' => static::getFieldTitle('ACTIVE'),
169 'type' => 'boolean',
170 'default_value' => 'Y',
171 'editable' => !$isDefaultStore,
172 'showAlways' => true,
173 ],
174 [
175 'name' => 'ISSUING_CENTER',
176 'title' => static::getFieldTitle('ISSUING_CENTER'),
177 'type' => 'boolean',
178 'visibilityPolicy' => 'edit',
179 ],
180 [
181 'name' => 'IMAGE_ID',
182 'title' => static::getFieldTitle('IMAGE_ID'),
183 'type' => 'file',
184 'showAlways' => true,
185 'data' => [
186 'multiple' => false,
187 'maxFileSize' => Ini::unformatInt(ini_get('upload_max_filesize')),
188 ],
189 ],
190 ];
191
192 $fields = $this->fillUfEntityFields($fields);
193
194 return $fields;
195 }
196
200 public function getEntityConfig(): array
201 {
202 $elements = [];
203 foreach ($this->getEntityFields() as $item)
204 {
205 $elements[] = [
206 'name' => $item['name'],
207 ];
208 }
209
210 $sectionElements = [
211 [
212 'name' => 'main',
213 'title' => Loc::getMessage('CATALOG_STORE_DETAIL_MAIN_SECTION'),
214 'type' => 'section',
215 'elements' => $elements,
216 'data' => [
217 'isRemovable' => 'false',
218 ],
219 'sort' => 100,
220 ],
221 ];
222
223 return [
224 [
225 'name' => 'left',
226 'type' => 'column',
227 'elements' => $sectionElements,
228 ],
229 ];
230 }
231
237 protected function getUfComponentFields(): array
238 {
239 $result = $this->getUfComponentFieldsParent();
240
241 if (isset($this->userFieldCreatePageUrl))
242 {
243 $result['USER_FIELD_CREATE_PAGE_URL'] = $this->userFieldCreatePageUrl;
244 }
245
246 return $result;
247 }
248
252 public function getEntityData(): array
253 {
254 $result = [];
255
256 foreach ($this->getEntityFields() as $item)
257 {
258 $field = $item['name'];
259 $type = $item['type'] ?? 'text';
260 $value = $this->entity[$field] ?? $item['default_value'] ?? null;
261 $result[$field] = $this->prepareValue($type, $value);
262 }
263
264 $result = $this->fillUfEntityData($result);
265
266 return $result;
267 }
268
272 public function getEntityControllers(): array
273 {
274 return [];
275 }
276
280 public function isReadOnly(): bool
281 {
282 return ! AccessController::getCurrent()->check(ActionDictionary::ACTION_STORE_MODIFY);
283 }
284
292 private static function getFieldTitle(string $fieldName): string
293 {
294 static $managerFields;
295
296 if (!isset($managerFields))
297 {
298 $managerFields = [];
299 foreach (StoreTable::getMap() as $field)
300 {
305 $name = $field->getName();
306 $managerFields[$name] =
307 Loc::getMessage("CATALOG_STORE_DETAIL_FIELD_TITLE_{$name}")
308 ?? $field->getTitle()
309 ;
310 }
311 }
312
313 return $managerFields[$fieldName] ?? $fieldName;
314 }
315
316 private function prepareValue(string $type, $value)
317 {
318 if (!isset($value))
319 {
320 return null;
321 }
322
323 return (string)$value;
324 }
325}
__construct(array $entityFields, ?string $userFieldCreatePageUrl=null)
static unformatInt(string $str)
Definition ini.php:19
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29