Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
documentdataprovider.php
1<?php
2
4
12
13\CBitrixComponent::includeComponentClass('bitrix:catalog.store.document.list');
14
16{
17 private $mode;
18
19 private static $fieldsOrder = [
20 \CatalogStoreDocumentListComponent::ARRIVAL_MODE => [
21 'ID',
22 'TITLE',
23 'DOC_NUMBER',
24 'DOC_TYPE',
25 'DATE_DOCUMENT',
26 'STATUS',
27 'DATE_CREATE',
28 'DATE_MODIFY',
29 'DATE_STATUS',
30 'STATUS_BY',
31 'RESPONSIBLE_ID',
32 'CREATED_BY',
33 'MODIFIED_BY',
34 'CONTRACTOR_ID',
35 'TOTAL',
36 'STORES',
37 ],
38 \CatalogStoreDocumentListComponent::MOVING_MODE => [
39 'ID',
40 'TITLE',
41 'DOC_NUMBER',
42 'DOC_TYPE',
43 'DATE_DOCUMENT',
44 'STATUS',
45 'DATE_CREATE',
46 'DATE_MODIFY',
47 'DATE_STATUS',
48 'STATUS_BY',
49 'RESPONSIBLE_ID',
50 'CREATED_BY',
51 'MODIFIED_BY',
52 'TOTAL',
53 'STORES_FROM',
54 'STORES_TO',
55 ],
56 \CatalogStoreDocumentListComponent::DEDUCT_MODE => [
57 'ID',
58 'TITLE',
59 'DOC_NUMBER',
60 'DOC_TYPE',
61 'DATE_DOCUMENT',
62 'STATUS',
63 'DATE_CREATE',
64 'DATE_MODIFY',
65 'DATE_STATUS',
66 'STATUS_BY',
67 'RESPONSIBLE_ID',
68 'CREATED_BY',
69 'MODIFIED_BY',
70 'TOTAL',
71 'STORES',
72 ],
73 \CatalogStoreDocumentListComponent::OTHER_MODE => [
74 'ID',
75 'TITLE',
76 'DATE_DOCUMENT',
77 'STATUS',
78 'DATE_CREATE',
79 'DATE_MODIFY',
80 'DATE_STATUS',
81 'STATUS_BY',
82 'CREATED_BY',
83 'MODIFIED_BY',
84 ],
85 ];
86
87 private static $fields;
88
90 private ?IProvider $contractorsProvider;
91
92 public function __construct($mode)
93 {
94 $this->contractorsProvider = Manager::getActiveProvider();
95
96 $this->mode = $mode;
97 self::$fields = [
98 'ID' => [
99 'id' => 'ID',
100 'name' => Loc::getMessage('DOCUMENT_ID_NAME'),
101 'default' => false,
102 'sort' => 'ID',
103 ],
104 'TITLE' => [
105 'id' => 'TITLE',
106 'name' => Loc::getMessage('DOCUMENT_TITLE_NAME'),
107 'default' => true,
108 'sort' => 'TITLE',
109 'width' => '215',
110 ],
111 'DOC_NUMBER' => [
112 'id' => 'DOC_NUMBER',
113 'name' => Loc::getMessage('DOCUMENT_DOC_NUMBER_NAME'),
114 'default' => $this->mode === \CatalogStoreDocumentListComponent::ARRIVAL_MODE,
115 'sort' => 'DOC_NUMBER',
116 ],
117 'DOC_TYPE' => [
118 'id' => 'DOC_TYPE',
119 'name' => Loc::getMessage('DOCUMENT_TYPE_NAME'),
120 'default' => $this->mode === \CatalogStoreDocumentListComponent::ARRIVAL_MODE,
121 'sort' => 'DOC_TYPE',
122 'type' => Column\Type::LABELS,
123 ],
124 'DATE_DOCUMENT' => [
125 'id' => 'DATE_DOCUMENT',
126 'name' => Loc::getMessage('DOCUMENT_DATE_DOCUMENT_NAME'),
127 'default' => false,
128 'sort' => 'DATE_DOCUMENT',
129 ],
130 'STATUS' => [
131 'id' => 'STATUS',
132 'name' => Loc::getMessage('DOCUMENT_STATUS_NAME'),
133 'default' => true,
134 'sort' => 'STATUS',
135 'type' => Column\Type::LABELS,
136 ],
137 'DATE_CREATE' => [
138 'id' => 'DATE_CREATE',
139 'name' => Loc::getMessage('DOCUMENT_DATE_CREATE_NAME'),
140 'default' => false,
141 'sort' => 'DATE_CREATE',
142 ],
143 'DATE_MODIFY' => [
144 'id' => 'DATE_MODIFY',
145 'name' => Loc::getMessage('DOCUMENT_DATE_MODIFY_NAME'),
146 'default' => true,
147 'sort' => 'DATE_MODIFY',
148 ],
149 'DATE_STATUS' => [
150 'id' => 'DATE_STATUS',
151 'name' => Loc::getMessage('DOCUMENT_DATE_STATUS_NAME'),
152 'default' => false,
153 'sort' => 'DATE_STATUS',
154 ],
155 'STATUS_BY' => [
156 'id' => 'STATUS_BY',
157 'name' => Loc::getMessage('DOCUMENT_STATUS_BY_NAME'),
158 'default' => false,
159 'sort' => 'STATUS_BY',
160 ],
161 'RESPONSIBLE_ID' => [
162 'id' => 'RESPONSIBLE_ID',
163 'name' => Loc::getMessage('DOCUMENT_RESPONSIBLE_ID_NAME'),
164 'default' => true,
165 'sort' => 'RESPONSIBLE_ID',
166 ],
167 'CREATED_BY' => [
168 'id' => 'CREATED_BY',
169 'name' => Loc::getMessage('DOCUMENT_CREATED_BY_NAME'),
170 'default' => false,
171 'sort' => 'CREATED_BY',
172 ],
173 'MODIFIED_BY' => [
174 'id' => 'MODIFIED_BY',
175 'name' => Loc::getMessage('DOCUMENT_MODIFIED_BY_NAME'),
176 'default' => false,
177 'sort' => 'MODIFIED_BY',
178 ],
179 'CONTRACTOR_ID' => [
180 'id' => 'CONTRACTOR_ID',
181 'name' => Loc::getMessage('DOCUMENT_CONTRACTOR_ID_NAME'),
182 'default' => true,
183 'sort' => 'CONTRACTOR_ID',
184 ],
185 'TOTAL' => [
186 'id' => 'TOTAL',
187 'name' => Loc::getMessage('DOCUMENT_TOTAL_NAME'),
188 'default' => true,
189 'sort' => 'TOTAL',
190 ],
191 'STORES' => [
192 'id' => 'STORES',
193 'name' => Loc::getMessage('DOCUMENT_STORES_NAME'),
194 'default' => true,
195 'sort' => false,
196 'type' => Column\Type::LABELS,
197 ],
198 'STORES_FROM' => [
199 'id' => 'STORES_FROM',
200 'name' => Loc::getMessage('DOCUMENT_STORES_FROM_NAME'),
201 'default' => true,
202 'sort' => false,
203 'type' => Column\Type::LABELS,
204 ],
205 'STORES_TO' => [
206 'id' => 'STORES_TO',
207 'name' => Loc::getMessage('DOCUMENT_STORES_TO_NAME'),
208 'default' => true,
209 'sort' => false,
210 'type' => Column\Type::LABELS,
211 ],
212 ];
213 }
214
215 public function getSettings()
216 {
217 // TODO: Implement getSettings() method.
218 }
219
220 public function prepareFields()
221 {
222 $fields = [
223 'TITLE' => $this->createField('TITLE', [
224 'default' => true,
225 ]),
226 'ID' => $this->createField('ID', [
227 'type' => 'number',
228 ]),
229 'STATUS' => $this->createField('STATUS', [
230 'default' => true,
231 'type' => 'list',
232 'partial' => true,
233 ]),
234 'DATE_DOCUMENT' => $this->createField('DATE_DOCUMENT', [
235 'default' => true,
236 'type' => 'date',
237 ]),
238 'DATE_CREATE' => $this->createField('DATE_CREATE', [
239 'type' => 'date',
240 ]),
241 'DATE_MODIFY' => $this->createField('DATE_MODIFY', [
242 'type' => 'date',
243 ]),
244 'DATE_STATUS' => $this->createField('DATE_STATUS', [
245 'type' => 'date',
246 ]),
247 'STATUS_BY' => $this->createField('STATUS_BY', [
248 'partial' => true,
249 'type' => 'entity_selector',
250 ]),
251 'RESPONSIBLE_ID' => $this->createField('RESPONSIBLE_ID', [
252 'default' => true,
253 'partial' => true,
254 'type' => 'entity_selector',
255 ]),
256 'CREATED_BY' => $this->createField('CREATED_BY', [
257 'partial' => true,
258 'type' => 'entity_selector',
259 ]),
260 'MODIFIED_BY' => $this->createField('MODIFIED_BY', [
261 'partial' => true,
262 'type' => 'entity_selector',
263 ]),
264 ];
265
266 if (Loader::includeModule('crm'))
267 {
268 $fields['PRODUCTS'] = $this->createField('PRODUCTS', [
269 'partial' => true,
270 'type' => 'entity_selector',
271 ]);
272 }
273
274 if ($this->mode !== \CatalogStoreDocumentListComponent::OTHER_MODE)
275 {
276 $fields['DOC_NUMBER'] = $this->createField('DOC_NUMBER');
277
278 if ($this->mode === \CatalogStoreDocumentListComponent::MOVING_MODE)
279 {
280 $fields['STORES_FROM'] = $this->createField('STORES_FROM', [
281 'partial' => true,
282 'default' => true,
283 'type' => 'entity_selector',
284 ]);
285 $fields['STORES_TO'] = $this->createField('STORES_TO', [
286 'partial' => true,
287 'default' => true,
288 'type' => 'entity_selector',
289 ]);
290 }
291 else
292 {
293 $fields['STORES'] = $this->createField('STORES', [
294 'partial' => true,
295 'type' => 'entity_selector',
296 ]);
297 }
298 }
299
300 if ($this->mode === \CatalogStoreDocumentListComponent::ARRIVAL_MODE)
301 {
302 if ($this->contractorsProvider)
303 {
304 $contractorsFields = $this->contractorsProvider::getDocumentsGridFilterFields();
305 foreach ($contractorsFields as $contractorsField)
306 {
307 $fields[$contractorsField['CODE']] = $this->createField(
308 $contractorsField['CODE'],
309 $contractorsField['PARAMS']
310 );
311 }
312 }
313 else
314 {
315 $fields['CONTRACTOR_ID'] = $this->createField('CONTRACTOR_ID', [
316 'partial' => true,
317 'type' => 'entity_selector',
318 'default' => true,
319 ]);
320 }
321
322 $fields['DOC_TYPE'] = $this->createField('DOC_TYPE', [
323 'default' => true,
324 'type' => 'list',
325 'partial' => 'true'
326 ]);
327 }
328
329 return $fields;
330 }
331
332 protected function getFieldName($fieldID)
333 {
334 return Loc::getMessage("DOCUMENT_{$fieldID}_NAME");
335 }
336
340 public function prepareFieldData($fieldID)
341 {
342 if ($fieldID === 'STATUS')
343 {
344 return [
345 'params' => [
346 'multiple' => 'Y',
347 ],
349 ];
350 }
351
352 if ($fieldID === 'DOC_TYPE')
353 {
354 if ($this->mode === \CatalogStoreDocumentListComponent::ARRIVAL_MODE)
355 {
356 return [
357 'params' => [
358 'multiple' => 'Y',
359 ],
360 'items' => [
363 ]
364 ];
365 }
366 }
367
368 $userFields = ['RESPONSIBLE_ID', 'STATUS_BY', 'CREATED_BY', 'MODIFIED_BY'];
369 if (in_array($fieldID, $userFields))
370 {
371 return $this->getUserEntitySelectorParams($this->mode . '_' . $fieldID . '_filter', ['fieldName' => $fieldID]);
372 }
373
374 if (in_array($fieldID, ['STORES', 'STORES_FROM', 'STORES_TO'], true))
375 {
376 return [
377 'params' => [
378 'multiple' => 'Y',
379 'dialogOptions' => [
380 'height' => 200,
381 'context' => $this->mode . '_store_filter',
382 'entities' => [
383 [
384 'id' => 'store',
385 'dynamicLoad' => true,
386 'dynamicSearch' => true,
387 ]
388 ],
389 'dropdownMode' => false,
390 ],
391 ],
392 ];
393 }
394
395 if ($fieldID === 'CONTRACTOR_ID')
396 {
397 return [
398 'params' => [
399 'multiple' => 'Y',
400 'dialogOptions' => [
401 'height' => 200,
402 'context' => $this->mode . '_contractor_filter',
403 'entities' => [
404 [
405 'id' => 'contractor',
406 'dynamicLoad' => true,
407 'dynamicSearch' => true,
408 ]
409 ],
410 'dropdownMode' => false,
411 ],
412 ],
413 ];
414 }
415
416 if (
417 $this->contractorsProvider
418 && $this->contractorsProvider::isDocumentsGridFilterFieldSupported($fieldID)
419 )
420 {
421 return $this->contractorsProvider::getDocumentsGridFilterFieldData($fieldID);
422 }
423
424 if ($fieldID === 'PRODUCTS')
425 {
426 return [
427 'params' => [
428 'multiple' => 'Y',
429 'dialogOptions' => [
430 'height' => 200,
431 'context' => $this->mode . '_product_filter',
432 'entities' => [
433 [
434 'id' => 'product',
435 'options' => [
436 'iblockId' => \Bitrix\Crm\Product\Catalog::getDefaultId(),
437 'basePriceId' => \Bitrix\Crm\Product\Price::getBaseId(),
438 ],
439 ]
440 ],
441 'dropdownMode' => false,
442 ],
443 ],
444 ];
445 }
446
447 return null;
448 }
449
450 public function getGridColumns()
451 {
452 $columns = [];
453 $fieldsOrder = self::$fieldsOrder[$this->mode];
454 foreach ($fieldsOrder as $field)
455 {
456 $columns[] = self::$fields[$field];
457 }
458
459 return $columns;
460 }
461}
getUserEntitySelectorParams(string $context, array $params)
createField($fieldID, array $params=null)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29