Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PropertyGridProvider.php
1<?php
2
4
10
11use CIBlockProperty;
12
14{
15 private int $iblockId;
16 private LinksBuilder $linksBuilder;
17
22 public function __construct(int $iblockId, LinksBuilder $linksBuilder)
23 {
24 $this->iblockId = $iblockId;
25 $this->linksBuilder = $linksBuilder;
26 }
27
31 public function getId(): string
32 {
33 return "iblock_property_{$this->iblockId}";
34 }
35
43 public function getFieldName(string $fieldId): ?string
44 {
45 $columns = $this->getColumns();
46 foreach ($columns as $item)
47 {
48 if ($item['id'] === $fieldId)
49 {
50 return (string)$item['name'];
51 }
52 }
53
54 return null;
55 }
56
60 public function getColumns(): array
61 {
62 return [
63 [
64 'id' => 'ID',
65 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ID'),
66 'sort' => 'ID',
67 ],
68 [
69 'id' => 'NAME',
70 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_NAME'),
71 'sort' => 'NAME',
72 'default' => true,
73 'editable' => true,
74 ],
75 [
76 'id' => 'CODE',
77 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_CODE'),
78 'sort' => 'CODE',
79 'editable' => true,
80 ],
81 [
82 'id' => 'PROPERTY_TYPE',
83 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_PROPERTY_TYPE'),
84 'sort' => 'PROPERTY_TYPE',
85 'type' => 'list',
86 'default' => true,
87 'editable' => false,
88 ],
89 [
90 'id' => 'SORT',
91 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_SORT'),
92 'sort' => 'SORT',
93 'default' => true,
94 'editable' => true,
95 ],
96 [
97 'id' => 'ACTIVE',
98 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ACTIVE'),
99 'sort' => 'ACTIVE',
100 'type' => 'checkbox',
101 'default' => true,
102 'editable' => true,
103 ],
104 [
105 'id' => 'IS_REQUIRED',
106 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_IS_REQUIRED'),
107 'sort' => 'IS_REQUIRED',
108 'type' => 'checkbox',
109 'default' => true,
110 'editable' => true,
111 ],
112 [
113 'id' => 'MULTIPLE',
114 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_MULTIPLE'),
115 'sort' => 'MULTIPLE',
116 'type' => 'checkbox',
117 'default' => true,
118 'editable' => true,
119 ],
120 [
121 'id' => 'SEARCHABLE',
122 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_SEARCHABLE'),
123 'sort' => 'SEARCHABLE',
124 'type' => 'checkbox',
125 'default' => true,
126 'editable' => true,
127 ],
128 [
129 'id' => 'FILTRABLE',
130 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_FILTRABLE'),
131 'sort' => 'FILTRABLE',
132 'type' => 'checkbox',
133 'editable' => true,
134 ],
135 [
136 'id' => 'XML_ID',
137 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_XML_ID'),
138 'sort' => 'XML_ID',
139 'editable' => true,
140 ],
141 [
142 'id' => 'WITH_DESCRIPTION',
143 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_WITH_DESCRIPTION'),
144 'sort' => 'WITH_DESCRIPTION',
145 'type' => 'checkbox',
146 'editable' => true,
147 ],
148 [
149 'id' => 'HINT',
150 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_HINT'),
151 ],
152 ];
153 }
154
158 protected function getRowActions(array $row, bool $isEditable): array
159 {
160 $id = (int)$row['ID'];
161
162 $result = [
163 [
164 'TEXT' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ACTION_OPEN'),
165 'HREF' => $this->linksBuilder->getActionOpenLink($id),
166 'ONCLICK' => $this->linksBuilder->getActionOpenClick($id),
167 'DEFAULT' => true,
168 ],
169 ];
170
171 if ($isEditable)
172 {
173 $result[] = [
174 'TEXT' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ACTION_DELETE'),
175 'HREF' => $this->linksBuilder->getActionDeleteLink($id),
176 'ONCLICK' => $this->linksBuilder->getActionDeleteClick($id),
177 ];
178 }
179
180 return $result;
181 }
182
188 private function getPropertyTypeItems(): array
189 {
190 $result = Property::getBaseTypeList(true);
191
192 $userTypes = CIBlockProperty::GetUserType();
193 Collection::sortByColumn($userTypes, [
194 'DESCRIPTION' => SORT_STRING,
195 ]);
196
197 foreach ($userTypes as $type => $item)
198 {
199 $key = "{$item['PROPERTY_TYPE']}:{$type}";
200 $result[$key] = $item['DESCRIPTION'];
201 }
202
203 return $result;
204 }
205
209 protected function getRowColumns(array $row): array
210 {
211 $result = parent::getRowColumns($row);
212
213 // prepare property type
214 if (isset($result['PROPERTY_TYPE']))
215 {
216 $type = $row['PROPERTY_TYPE'] ?? null;
217 if ($type)
218 {
219 $userType = $row['USER_TYPE'] ?? null;
220 if ($userType)
221 {
222 $type .= ':' . $userType;
223 }
224
225 $typeNames = $this->getPropertyTypeItems();
226 $result['PROPERTY_TYPE'] = $typeNames[$type] ?? null;
227 }
228 }
229
230 return $result;
231 }
232
240 public function prepareRow(array $rawRow): array
241 {
242 if (isset($rawRow['NAME']))
243 {
244 $rawRow['NAME'] = HtmlFilter::encode($rawRow['NAME']);
245 }
246
247 return parent::prepareRow($rawRow);
248 }
249}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static encode($string, $flags=ENT_COMPAT, $doubleEncode=true)