Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
propertyenumerationconfig.php
1<?php
2
4
8
10{
11 private bool $multiple;
12 private string $listMode;
13
14 private string $compiledType;
15
16 private array $items;
17
18 public function __construct(string $name, array $property, array $items)
19 {
20 $this->multiple = ($property['MULTIPLE'] ?? 'N') === 'Y';
21 $this->listMode = (string)($property['LIST_TYPE'] ?? PropertyTable::LISTBOX);
22
23 $this->compileType();
24
25 parent::__construct($name, $this->getCompiledType());
26
27 $this->items = $items;
28 }
29
30 private function compileType(): void
31 {
32 if (!isset($this->compiledType))
33 {
34 $this->compiledType = match ($this->listMode)
35 {
37 ? Grid\Editor\Types::MULTISELECT
38 : Grid\Editor\Types::DROPDOWN
39 ,
40 default => Grid\Editor\Types::CUSTOM,
41 };
42 }
43 }
44
45 private function getCompiledType(): string
46 {
47 return $this->compiledType;
48 }
49
50 private function isSelectMode(): bool
51 {
52 $compiledType = $this->getCompiledType();
53
54 return
55 $compiledType === Grid\Editor\Types::MULTISELECT
56 || $compiledType === Grid\Editor\Types::DROPDOWN
57 ;
58 }
59
63 public function toArray(): array
64 {
65 $result = parent::toArray();
66
67 if ($this->isSelectMode())
68 {
69 $result['DATA'] = [
70 'ITEMS' => $this->getItemsAsDropdown(),
71 ];
72 }
73
74 return $result;
75 }
76
82 private function getItemsAsDropdown(): array
83 {
84 $result = [];
85
86 if (!$this->multiple)
87 {
88 $result[] = [
89 'VALUE' => '',
90 'NAME' => Loc::getMessage('PROPERTY_ENUM_CONFIG_EMPTY_VALUE'),
91 ];
92 }
93
94 foreach ($this->items as $value)
95 {
96 $result[] = [
97 'VALUE' => $value['ID'],
98 'NAME' => $value['VALUE'],
99 ];
100 }
101
102 return $result;
103 }
104}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29