Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
agentcontractdataprovider.php
1<?php
2
4
7use Bitrix\Crm;
8
10{
12 private ?Catalog\v2\Contractor\Provider\IProvider $contractorsProvider;
13
14 private static array $fieldsOrder = [
15 'ID',
16 'TITLE',
17 'CONTRACTOR_ID',
18 'DATE_MODIFY',
19 'DATE_CREATE',
20 'MODIFIED_BY',
21 'CREATED_BY',
22 ];
23
24 private static array $fields;
25
26 public function __construct()
27 {
28 $this->contractorsProvider = Catalog\v2\Contractor\Provider\Manager::getActiveProvider(
29 Catalog\v2\Contractor\Provider\Manager::PROVIDER_STORE_DOCUMENT
30 );
31
32 static::$fields = [
33 'ID' => [
34 'id' => 'ID',
35 'name' => Main\Localization\Loc::getMessage('AGENT_CATALOG_CONTRACT_DATA_PROVIDER_ID'),
36 'default' => false,
37 'type' => 'number',
38 'sort' => 'ID',
39 ],
40 'TITLE' => [
41 'id' => 'TITLE',
42 'name' => Main\Localization\Loc::getMessage('AGENT_CATALOG_CONTRACT_DATA_PROVIDER_TITLE'),
43 'default' => true,
44 'sort' => 'TITLE',
45 ],
46 'CONTRACTOR_ID' => [
47 'id' => 'CONTRACTOR_ID',
48 'name' => Main\Localization\Loc::getMessage('AGENT_CATALOG_CONTRACT_DATA_PROVIDER_CONTRACTOR_ID'),
49 'partial' => true,
50 'type' => 'entity_selector',
51 'default' => true,
52 ],
53 'DATE_MODIFY' => [
54 'id' => 'DATE_MODIFY',
55 'name' => Main\Localization\Loc::getMessage('AGENT_CATALOG_CONTRACT_DATA_PROVIDER_DATE_MODIFY'),
56 'default' => true,
57 'type' => 'date',
58 'data' => [
59 'exclude' => [
60 Main\UI\Filter\DateType::TOMORROW,
61 Main\UI\Filter\DateType::NEXT_DAYS,
62 Main\UI\Filter\DateType::NEXT_WEEK,
63 Main\UI\Filter\DateType::NEXT_MONTH,
64 ],
65 ],
66 'sort' => 'DATE_MODIFY',
67 ],
68 'DATE_CREATE' => [
69 'id' => 'DATE_CREATE',
70 'name' => Main\Localization\Loc::getMessage('AGENT_CATALOG_CONTRACT_DATA_PROVIDER_DATE_CREATE'),
71 'default' => true,
72 'type' => 'date',
73 'data' => [
74 'exclude' => [
75 Main\UI\Filter\DateType::TOMORROW,
76 Main\UI\Filter\DateType::NEXT_DAYS,
77 Main\UI\Filter\DateType::NEXT_WEEK,
78 Main\UI\Filter\DateType::NEXT_MONTH,
79 ],
80 ],
81 'sort' => 'DATE_CREATE',
82 ],
83 'MODIFIED_BY' => [
84 'id' => 'MODIFIED_BY',
85 'name' => Main\Localization\Loc::getMessage('AGENT_CATALOG_CONTRACT_DATA_PROVIDER_MODIFIED_BY'),
86 'default' => true,
87 'type' => 'entity_selector',
88 'partial' => true,
89 ],
90 'CREATED_BY' => [
91 'id' => 'CREATED_BY',
92 'name' => Main\Localization\Loc::getMessage('AGENT_CATALOG_CONTRACT_DATA_PROVIDER_CREATED_BY'),
93 'default' => true,
94 'type' => 'entity_selector',
95 'partial' => true,
96 ],
97 ];
98 }
99
100 public function getSettings()
101 {
102 // TODO: Implement getSettings() method.
103 }
104
105 public function prepareFields()
106 {
107 $fields = [
108 'ID' => $this->createField('ID', [
109 'default' => false,
110 'type' => 'number',
111 ]),
112 'TITLE' => $this->createField('TITLE', [
113 'default' => true,
114 ]),
115 'DATE_MODIFY' => $this->createField('DATE_MODIFY', [
116 'default' => true,
117 'type' => 'date',
118 'data' => [
119 'exclude' => [
120 Main\UI\Filter\DateType::TOMORROW,
121 Main\UI\Filter\DateType::NEXT_DAYS,
122 Main\UI\Filter\DateType::NEXT_WEEK,
123 Main\UI\Filter\DateType::NEXT_MONTH,
124 ],
125 ],
126 ]),
127 'DATE_CREATE' => $this->createField('DATE_CREATE', [
128 'default' => true,
129 'type' => 'date',
130 'data' => [
131 'exclude' => [
132 Main\UI\Filter\DateType::TOMORROW,
133 Main\UI\Filter\DateType::NEXT_DAYS,
134 Main\UI\Filter\DateType::NEXT_WEEK,
135 Main\UI\Filter\DateType::NEXT_MONTH,
136 ],
137 ],
138 ]),
139 'MODIFIED_BY' => $this->createField('MODIFIED_BY', [
140 'default' => true,
141 'type' => 'entity_selector',
142 'partial' => true,
143 ]),
144 'CREATED_BY' => $this->createField('CREATED_BY', [
145 'default' => true,
146 'type' => 'entity_selector',
147 'partial' => true,
148 ]),
149 ];
150
151 if (Main\Loader::includeModule('crm'))
152 {
153 $fields['PRODUCTS'] = $this->createField('PRODUCTS', [
154 'partial' => true,
155 'type' => 'entity_selector',
156 ]);
157
158 $fields['SECTIONS'] = $this->createField('SECTIONS', [
159 'partial' => true,
160 'type' => 'entity_selector',
161 ]);
162 }
163
164 if ($this->contractorsProvider)
165 {
166 $contractorsFields = $this->contractorsProvider::getDocumentsGridFilterFields();
167 foreach ($contractorsFields as $contractorsField)
168 {
169 $fields[$contractorsField['CODE']] = $this->createField(
170 $contractorsField['CODE'],
171 $contractorsField['PARAMS']
172 );
173 }
174 }
175 else
176 {
177 $fields['CONTRACTOR_ID'] = $this->createField('CONTRACTOR_ID', [
178 'partial' => true,
179 'type' => 'entity_selector',
180 'default' => true,
181 ]);
182 }
183
184 return $fields;
185 }
186
187 protected function getFieldName($fieldID)
188 {
189 return Main\Localization\Loc::getMessage("AGENT_CATALOG_CONTRACT_DATA_PROVIDER_{$fieldID}");
190 }
191
192 public function prepareFieldData($fieldID)
193 {
194 $userFields = ['MODIFIED_BY', 'CREATED_BY'];
195 if (in_array($fieldID, $userFields, true))
196 {
197 return $this->getUserEntitySelectorParams($fieldID . '_filter', ['fieldName' => $fieldID]);
198 }
199
200 if ($fieldID === 'CONTRACTOR_ID')
201 {
202 return [
203 'params' => [
204 'multiple' => 'Y',
205 'dialogOptions' => [
206 'height' => 200,
207 'context' => 'agent_contract_contractor_filter',
208 'entities' => [
209 [
210 'id' => 'contractor',
211 'dynamicLoad' => true,
212 'dynamicSearch' => true,
213 ]
214 ],
215 'dropdownMode' => false,
216 ],
217 ],
218 ];
219 }
220
221 if (
222 $this->contractorsProvider
223 && $this->contractorsProvider::isDocumentsGridFilterFieldSupported($fieldID)
224 )
225 {
226 return $this->contractorsProvider::getDocumentsGridFilterFieldData($fieldID);
227 }
228
229 if ($fieldID === 'PRODUCTS')
230 {
231 $options = [
232 'iblockId' => Crm\Product\Catalog::getDefaultId(),
233 'basePriceId' => Crm\Product\Price::getBaseId(),
234 ];
235
236 return [
237 'params' => [
238 'multiple' => 'Y',
239 'dialogOptions' => [
240 'height' => 200,
241 'context' => 'agent_contract_product_filter',
242 'entities' => [
243 [
244 'id' => 'agent-contractor-product',
245 'options' => $options,
246 ],
247 [
248 'id' => 'agent-contractor-product-variation',
249 'options' => $options,
250 ],
251 ],
252 'dropdownMode' => false,
253 ],
254 ],
255 ];
256 }
257
258 if ($fieldID === 'SECTIONS')
259 {
260 $options = [
261 'iblockId' => Crm\Product\Catalog::getDefaultId(),
262 'basePriceId' => Crm\Product\Price::getBaseId(),
263 ];
264
265 return [
266 'params' => [
267 'multiple' => 'Y',
268 'dialogOptions' => [
269 'height' => 200,
270 'context' => 'agent_contract_section_filter',
271 'entities' => [
272 [
273 'id' => 'agent-contractor-section',
274 'options' => $options,
275 ],
276 ],
277 'dropdownMode' => false,
278 ],
279 ],
280 ];
281 }
282
283 return null;
284 }
285
286 public function getGridColumns(): array
287 {
288 $columns = [];
289 $fieldsOrder = self::$fieldsOrder;
290 foreach ($fieldsOrder as $field)
291 {
292 $columns[] = self::$fields[$field];
293 }
294
295 return $columns;
296 }
297}
getUserEntitySelectorParams(string $context, array $params)
createField($fieldID, array $params=null)