Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PropertyFilterProvider.php
1<?php
2
4
11use CIBlockProperty;
12
14{
15 private Settings $settings;
16 private PropertyGridProvider $gridProvider;
17 private int $iblockId;
18
23 public function __construct(int $iblockId, PropertyGridProvider $gridProvider)
24 {
25 $this->iblockId = $iblockId;
26 $this->gridProvider = $gridProvider;
27 }
28
32 public function getSettings()
33 {
34 $this->settings ??= new Settings([
35 'ID' => "iblock_property_{$this->iblockId}",
36 ]);
37
38 return $this->settings;
39 }
40
44 protected function getFieldName($fieldID)
45 {
46 return $fieldID;
47 }
48
52 public function prepareFields()
53 {
54 return [
55 'NAME' => $this->createField('NAME', [
56 'name' => $this->gridProvider->getFieldName('NAME'),
57 'default' => true,
58 ]),
59 'CODE' => $this->createField('CODE', [
60 'name' => $this->gridProvider->getFieldName('CODE'),
61 ]),
62 'ACTIVE' => $this->createField('ACTIVE', [
63 'name' => $this->gridProvider->getFieldName('ACTIVE'),
64 'type' => 'list',
65 'default' => true,
66 'data' => [
67 'items' => [
68 'Y' => Loc::getMessage('IBLOCK_YES'),
69 'N' => Loc::getMessage('IBLOCK_NO')
70 ],
71 ],
72 ]),
73 'SEARCHABLE' => $this->createField('SEARCHABLE', [
74 'name' => $this->gridProvider->getFieldName('SEARCHABLE'),
75 'type' => 'list',
76 'data' => [
77 'items' => [
78 'Y' => Loc::getMessage('IBLOCK_YES'),
79 'N' => Loc::getMessage('IBLOCK_NO')
80 ],
81 ],
82 ]),
83 'FILTRABLE' => $this->createField('FILTRABLE', [
84 'name' => $this->gridProvider->getFieldName('FILTRABLE'),
85 'type' => 'list',
86 'data' => [
87 'items' => [
88 'Y' => Loc::getMessage('IBLOCK_YES'),
89 'N' => Loc::getMessage('IBLOCK_NO')
90 ],
91 ],
92 ]),
93 'IS_REQUIRED' => $this->createField('IS_REQUIRED', [
94 'name' => $this->gridProvider->getFieldName('IS_REQUIRED'),
95 'type' => 'list',
96 'data' => [
97 'items' => [
98 'Y' => Loc::getMessage('IBLOCK_YES'),
99 'N' => Loc::getMessage('IBLOCK_NO')
100 ],
101 ],
102 ]),
103 'MULTIPLE' => $this->createField('MULTIPLE', [
104 'name' => $this->gridProvider->getFieldName('MULTIPLE'),
105 'type' => 'list',
106 'data' => [
107 'items' => [
108 'Y' => Loc::getMessage('IBLOCK_YES'),
109 'N' => Loc::getMessage('IBLOCK_NO')
110 ],
111 ],
112 ]),
113 'XML_ID' => $this->createField('XML_ID', [
114 'name' => $this->gridProvider->getFieldName('XML_ID'),
115 ]),
116 'PROPERTY_TYPE' => $this->createField('PROPERTY_TYPE', [
117 'name' => $this->gridProvider->getFieldName('PROPERTY_TYPE'),
118 'type' => 'list',
119 'default' => true,
120 'data' => [
121 'items' => $this->getPropertyTypes(),
122 ],
123 ]),
124 ];
125 }
126
132 private function getPropertyTypes(): array
133 {
134 $result = [];
135
136 $baseTypes = Property::getBaseTypeList(true);
137 foreach ($baseTypes as $type => $name)
138 {
139 $result[$type] = $name;
140 }
141
142 $userTypes = CIBlockProperty::GetUserType();
143 Collection::sortByColumn($userTypes, [
144 'DESCRIPTION' => SORT_STRING,
145 ]);
146
147 foreach ($userTypes as $type => $item)
148 {
149 $key = "{$item['PROPERTY_TYPE']}:{$type}";
150 $result[$key] = $item['DESCRIPTION'];
151 }
152
153 return $result;
154 }
155
159 public function prepareFieldData($fieldID)
160 {
161 return null;
162 }
163
167 public function prepareFilterValue(array $rawFilterValue): array
168 {
169 $isEmpty = empty($rawFilterValue);
170 $rawFilterValue['=IBLOCK_ID'] = $this->iblockId;
171
172 if ($isEmpty)
173 {
174 return $rawFilterValue;
175 }
176
177 // parse property type
178 if (isset($rawFilterValue['PROPERTY_TYPE']))
179 {
180 $parts = explode(':', $rawFilterValue['PROPERTY_TYPE']);
181 if (count($parts) === 2)
182 {
183 $rawFilterValue['PROPERTY_TYPE'] = $parts[0];
184 $rawFilterValue['USER_TYPE'] = $parts[1];
185 }
186 }
187
188 // process fields operations
189 $filterOperations = [
190 'NAME' => '?',
191 'CODE' => '?',
192 'ACTIVE' => '=',
193 'SEARCHABLE' => '=',
194 'FILTRABLE' => '=',
195 'IS_REQUIRED' => '=',
196 'MULTIPLE' => '=',
197 'XML_ID' => '=',
198 'PROPERTY_TYPE' => '=',
199 'USER_TYPE' => '=',
200 ];
201 foreach ($rawFilterValue as $field => $value)
202 {
203 $operator = $filterOperations[$field] ?? null;
204 if (isset($operator))
205 {
206 $rawFilterValue[$operator . $field] = $value;
207 unset($rawFilterValue[$field]);
208 }
209 }
210
211 // searchable
212 if (isset($rawFilterValue['FIND']))
213 {
214 $rawFilterValue[] = [
215 '?NAME' => $rawFilterValue['FIND'],
216 ];
217 }
218
219 return $rawFilterValue;
220 }
221}
createField($fieldID, array $params=null)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29