Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
client.php
1<?php
9
10use Bitrix\Crm\Category\DealCategory;
11use Bitrix\Crm\CompanyTable as CrmCompanyTable;
12use Bitrix\Crm\ContactTable as CrmContactTable;
13use Bitrix\Crm\PhaseSemantics;
21use Bitrix\Main\Page\Asset;
28
29Loc::loadMessages(__FILE__);
30
36{
37 const PRODUCT_SOURCE_ORDERS_ALL = "ORDERS_ALL";
38 const PRODUCT_SOURCE_ORDERS_PAID = "ORDERS_PAID";
39 const PRODUCT_SOURCE_ORDERS_UNPAID = "ORDERS_UNPAID";
40 const PRODUCT_SOURCE_DEALS_ALL = "DEALS_ALL";
41 const PRODUCT_SOURCE_DEALS_PROCESS = "DEALS_PROCESS";
42 const PRODUCT_SOURCE_DEALS_SUCCESS = "DEALS_SUCCESS";
43 const PRODUCT_SOURCE_DEALS_FAILURE = "DEALS_FAILURE";
44 const API_VERSION = 3;
45 const YES = 'Y';
46 const NO = 'N';
47 const DEAL_CATEGORY_ID = "DEAL_CATEGORY_ID";
48
49 private $crmEntityFilter = null;
50
56 public function getName()
57 {
58 return Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_NAME');
59 }
60
66 public function getCode()
67 {
68 return "crm_client";
69 }
70
76 public function getQueries($selectList = [])
77 {
78 $queries = array();
79 $clientType = $this->getFieldValue('CLIENT_TYPE');
80
81 if (!$clientType || $clientType === \CCrmOwnerType::ContactName)
82 {
83 $queryCollection = $this->prepareQueryCollection($this->getContactQuery());
84 $queries = array_merge($queries, $queryCollection);
85 }
86 if (!$clientType || $clientType === \CCrmOwnerType::CompanyName)
87 {
88 $queryCollection = $this->prepareQueryCollection($this->getCompanyQuery());
89 $queries = array_merge($queries, $queryCollection);
90 }
91 return $queries;
92 }
93
103 public function getLimitedQueries(int $offset, int $limit, string $excludeType = null): array
104 {
105 $queries = array();
106 $clientType = $this->getFieldValue('CLIENT_TYPE');
107
108 if (!$clientType || $clientType === \CCrmOwnerType::ContactName)
109 {
110 if($excludeType !== \CCrmOwnerType::ContactName)
111 {
112 $this->prepareQueryForType($this->getContactQuery(), $offset, $limit,
113 $queries);
114 }
115 }
116 if (!$clientType || $clientType === \CCrmOwnerType::CompanyName)
117 {
118 if($excludeType !== \CCrmOwnerType::CompanyName)
119 {
120 $this->prepareQueryForType($this->getCompanyQuery(), $offset, $limit, $queries);
121 }
122 }
123
124 return $queries;
125 }
126
127 public function getEntityLimitInfo(): array
128 {
129 $lastContact = \CCrmContact::GetListEx(
130 ['ID' => 'DESC'],
131 [
132 'CHECK_PERMISSIONS' => 'N',
133 '@CATEGORY_ID' => 0,
134 ],
135 false,
136 ['nTopCount' => '1'],
137 ['ID'],
138 ['limit' => 1]
139 )->Fetch();
140
141 $lastCompany = \CCrmCompany::GetListEx(
142 ['ID' => 'DESC'],
143 [
144 'CHECK_PERMISSIONS' => 'N',
145 '@CATEGORY_ID' => 0,
146 ],
147 false,
148 ['nTopCount' => '1'],
149 ['ID']
150 )->Fetch();
151
152 $lastContactId = $lastContact['ID'] ?? 0;
153 $lastCompanyId = $lastCompany['ID'] ?? 0;
154
155 return [
156 'lastContactId' => $lastContactId,
157 'lastCompanyId' => $lastCompanyId,
158 'lastId' => max($lastCompanyId, $lastContactId),
159 ];
160 }
161
162 public function getLimitedData(int $offset, int $limit): ?Result
163 {
164 $entityInfo = $this->getEntityLimitInfo();
165 $excludedClass = $offset > $entityInfo['lastContactId'] ? \CCrmOwnerType::ContactName : null;
166 $excludedClass = $offset > $entityInfo['lastCompanyId'] ? \CCrmOwnerType::CompanyName : $excludedClass;
167
168 $query = QueryData::getUnionizedQuery($this->getLimitedQueries($offset, $limit, $excludedClass));
169
170 return !$query ? null : QueryData::getUnionizedData($query);
171 }
172
173 protected function prepareQueryForType(Query $query, int $from, int $to, array &$queries)
174 {
175 $query->whereBetween('ID', $from, $to);
176 $queryCollection = $this->prepareQueryCollection($query);
177 $queries = array_merge($queries, $queryCollection);
178 }
179
180 protected function getContactQuery()
181 {
182 $query = CrmContactTable::query();
183 $query->setFilter($this->getCrmEntityFilter(\CCrmOwnerType::ContactName));
184 if ($query->getEntity()->hasField('CATEGORY_ID'))
185 {
186 $query->where('CATEGORY_ID', 0);
187 }
188 $this->addCrmEntityReferences($query);
189 $query->registerRuntimeField(new Entity\ExpressionField('CRM_ENTITY_TYPE_ID', \CCrmOwnerType::Contact));
190 $query->registerRuntimeField(new Entity\ExpressionField('CRM_ENTITY_TYPE', '\''.\CCrmOwnerType::ContactName.'\''));
191 $query->registerRuntimeField(new Entity\ExpressionField('CRM_COMPANY_ID', 0));
192 $query->registerRuntimeField(new Entity\ExpressionField('CONTACT_ID', '%s', ['ID']));
193 $query->registerRuntimeField(Helper::createExpressionMultiField(\CCrmOwnerType::ContactName, 'EMAIL'));
194 $query->registerRuntimeField(Helper::createExpressionMultiField(\CCrmOwnerType::ContactName, 'PHONE'));
195 $query->setSelect(
196 [
197 'CRM_ENTITY_ID' => 'ID',
198 'NAME',
199 'CRM_ENTITY_TYPE_ID',
200 'CRM_ENTITY_TYPE',
201 'CRM_CONTACT_ID' => 'CONTACT_ID',
202 'CRM_COMPANY_ID',
203 'HAS_EMAIL',
204 'HAS_PHONE',
205 'HAS_IMOL',
206 ]
207 );
208
209 return $query;
210 }
211
212 protected function getCompanyQuery()
213 {
214 $query = CrmCompanyTable::query();
215 $query->setFilter($this->getCrmEntityFilter(\CCrmOwnerType::CompanyName));
216 if ($query->getEntity()->hasField('CATEGORY_ID'))
217 {
218 $query->where('CATEGORY_ID', 0);
219 }
220 $this->addCrmEntityReferences($query);
221 $query->registerRuntimeField(new Entity\ExpressionField('CRM_ENTITY_TYPE_ID', \CCrmOwnerType::Company));
222 $query->registerRuntimeField(new Entity\ExpressionField('CRM_ENTITY_TYPE', '\''.\CCrmOwnerType::CompanyName.'\''));
223 $query->registerRuntimeField(new Entity\ExpressionField('CONTACT_ID', 0));
224 $query->registerRuntimeField(new Entity\ExpressionField('COMPANY_ID', '%s', ['ID']));
225 $query->registerRuntimeField(Helper::createExpressionMultiField(\CCrmOwnerType::CompanyName, 'EMAIL'));
226 $query->registerRuntimeField(Helper::createExpressionMultiField(\CCrmOwnerType::CompanyName, 'PHONE'));
227 $query->setSelect(
228 [
229 'CRM_ENTITY_ID' => 'ID',
230 'NAME' => 'TITLE',
231 'CRM_ENTITY_TYPE_ID',
232 'CRM_ENTITY_TYPE',
233 'CRM_CONTACT_ID' => 'CONTACT_ID',
234 'CRM_COMPANY_ID' => 'COMPANY_ID',
235 'HAS_EMAIL',
236 'HAS_PHONE',
237 'HAS_IMOL',
238 ]
239 );
240
241 return $query;
242 }
243
244 protected function addCrmEntityReferences(Entity\Query $query)
245 {
246 $docTypes = array();
247 $docType = $this->getFieldValue('DOC_TYPE');
248 if ($docType)
249 {
250 $docTypes[] = $docType;
251 }
252 else
253 {
254 foreach (array_keys(self::getCrmDocumentTypes()) as $entityTypeName)
255 {
256 $filter = $this->getCrmReferencedEntityFilter($entityTypeName);
257 if (count($filter) === 0)
258 {
259 continue;
260 }
261
262 $docTypes[] = $entityTypeName;
263 }
264 }
265
266 foreach ($docTypes as $docType)
267 {
268 $refClassName = "\\Bitrix\\Crm\\" . ucfirst(mb_strtolower($docType)) . "Table";
269 if (!class_exists($refClassName))
270 {
271 continue;
272 }
273
274 if ($query->getEntity()->getName() === 'Contact')
275 {
276 $ref = array('=this.ID' => 'ref.CONTACT_ID');
277 }
278 elseif ($query->getEntity()->getName() === 'Company')
279 {
280 $ref = array('=this.ID' => 'ref.COMPANY_ID');
281 }
282 else
283 {
284 continue;
285 }
286
287 $runtimeFieldName = "SGT_$docType";
288 $filter = $this->getCrmReferencedEntityFilter($docType);
289 $joinType = $filter[$docType]['JOIN_TYPE']??'INNER';
290 unset($filter[$docType]['JOIN_TYPE']);
291
292 $query->registerRuntimeField(null, new Entity\ReferenceField(
293 $runtimeFieldName,
294 $refClassName,
295 $ref,
296 array('join_type' => $joinType)
297 ));
298
299 foreach ($filter as $key => $value)
300 {
301 $pattern = "/^[\W]{0,2}$docType\./";
302 if (preg_match($pattern, $key))
303 {
304 $key = str_replace("$docType.", "$runtimeFieldName.", $key);
305 }
306
307 $query->addFilter($key, $value);
308 }
309
310 $runtime = Helper::getRuntimeByEntity($docType);
311 foreach ($runtime as $item)
312 {
313 $item = new Entity\ExpressionField(
314 $item['name'],
315 str_replace("$docType.", "$runtimeFieldName.", $item['expression']),
316 array_map(
317 function ($from) use ($docType, $runtimeFieldName)
318 {
319 return str_replace("$docType.", "$runtimeFieldName.", $from);
320 },
321 $item['buildFrom']
322 )
323 );
324 $query->registerRuntimeField($item);
325 }
326 }
327
328 $entityTypeName = mb_strtoupper($query->getEntity()->getName());
329 $runtime = Helper::getRuntimeByEntity($entityTypeName);
330 foreach ($runtime as $item)
331 {
332 $item = new Entity\ExpressionField(
333 $item['name'],
334 $item['expression'],
335 array_map(
336 function ($from) use ($entityTypeName)
337 {
338 return str_replace("$entityTypeName.", "", $from);
339 },
340 $item['buildFrom']
341 )
342 );
343 $query->registerRuntimeField($item);
344 }
345
346 $filterFields = $query->getFilter();
347 if (array_key_exists('NO_PURCHASES', $filterFields))
348 {
349 $noPurchasesFilter = $filterFields['NO_PURCHASES'];
350 $productSource = $filterFields['PRODUCT_SOURCE'];
351
352 unset($filterFields['NO_PURCHASES']);
353 $query->setFilter($filterFields);
354
355 $this->addNoPurchasesFilter($query, $noPurchasesFilter, $productSource);
356 }
357 if (array_key_exists('DEAL', $filterFields))
358 {
359 $query->where(\Bitrix\Main\Entity\Query::filter()
360 ->logic('or')
361 ->where($filterFields['DEAL'])
362 );
363 unset($filterFields['DEAL']);
364 $query->setFilter($filterFields);
365 }
366 }
367
379 protected function addNoPurchasesFilter($query, $filterValue, $productSource)
380 {
381 $sqlHelper = Application::getConnection()->getSqlHelper();
382
383 $dealQuery = \Bitrix\Crm\DealTable::query();
384
385 if (is_array($productSource))
386 {
387 $semantics = [];
388 if (in_array(self::PRODUCT_SOURCE_DEALS_PROCESS, $productSource))
389 {
390 $semantics[] = \Bitrix\Crm\PhaseSemantics::PROCESS;
391 }
392 if (in_array(self::PRODUCT_SOURCE_DEALS_SUCCESS, $productSource))
393 {
394 $semantics[] = \Bitrix\Crm\PhaseSemantics::SUCCESS;
395 }
396 if (in_array(self::PRODUCT_SOURCE_DEALS_FAILURE, $productSource))
397 {
398 $semantics[] = \Bitrix\Crm\PhaseSemantics::FAILURE;
399 }
400
401 if ($semantics && count($semantics) < 3)
402 {
403 $dealQuery->whereIn('STAGE_SEMANTIC_ID', $semantics);
404 }
405 }
406
407 $dealsFilter = [];
408 foreach ($filterValue as $filterCode => $date)
409 {
410 $dealsFilter[str_replace('%PURCHASE_DATE%', 'DATE_CREATE', $filterCode)] =
411 new SqlExpression($sqlHelper->convertToDbDateTime(new DateTime($date)));
412 }
413 $dealQuery->setFilter($dealsFilter);
414
415 $orderQuery = null;
417 {
418 $orderQuery = \Bitrix\Crm\Binding\OrderContactCompanyTable::query();
419 $orderQuery->addSelect('ENTITY_ID', 'EID');
420
421 if (is_array($productSource))
422 {
423 if (in_array(self::PRODUCT_SOURCE_ORDERS_PAID, $productSource) &&
424 !in_array(self::PRODUCT_SOURCE_ORDERS_UNPAID, $productSource))
425 {
426 $orderQuery->where('ORDER.PAYED', true);
427 }
428 if (!in_array(self::PRODUCT_SOURCE_ORDERS_PAID, $productSource) &&
429 in_array(self::PRODUCT_SOURCE_ORDERS_UNPAID, $productSource))
430 {
431 $orderQuery->where('ORDER.PAYED', false);
432 }
433 }
434 $orderQuery->whereNotNull('ENTITY_ID');
435
436 $ordersFilter = [];
437 foreach ($filterValue as $filterCode => $date)
438 {
439 $ordersFilter[str_replace('%PURCHASE_DATE%', 'ORDER.DATE_INSERT', $filterCode)] =
440 new SqlExpression($sqlHelper->convertToDbDateTime(new DateTime($date)));
441 }
442 $orderQuery->setFilter($ordersFilter);
443 }
444
445 if ($query->getEntity()->getName() === 'Contact')
446 {
447 $dealQuery->addSelect('CONTACT_ID', 'EID');
448 $dealQuery->whereNotNull('CONTACT_ID');
449 if ($orderQuery)
450 {
451 $orderQuery->where('ENTITY_TYPE_ID', \CCrmOwnerType::Contact);
452 }
453 }
454 elseif ($query->getEntity()->getName() === 'Company')
455 {
456 $dealQuery->addSelect('COMPANY_ID', 'EID');
457 $dealQuery->whereNotNull('COMPANY_ID');
458 if ($orderQuery)
459 {
460 $orderQuery->where('ENTITY_TYPE_ID', \CCrmOwnerType::Company);
461 }
462 }
463
464 $dealsAreRequired = empty($productSource) ||
465 array_intersect($productSource, [self::PRODUCT_SOURCE_DEALS_PROCESS, self::PRODUCT_SOURCE_DEALS_SUCCESS, self::PRODUCT_SOURCE_DEALS_FAILURE]);
466 $ordersAreRequired = empty($productSource) ||
467 array_intersect($productSource, [self::PRODUCT_SOURCE_ORDERS_PAID, self::PRODUCT_SOURCE_ORDERS_UNPAID]);
468
469 $idSubQuery = false;
470 if ($orderQuery && $dealsAreRequired && $ordersAreRequired)
471 {
472 $idSubQuery = new SqlExpression($dealQuery->getQuery() . ' UNION ALL ' . $orderQuery->getQuery());
473 }
474 elseif ($orderQuery && $ordersAreRequired)
475 {
476 $idSubQuery = $orderQuery;
477 }
478 elseif ($dealsAreRequired)
479 {
480 $idSubQuery = $dealQuery;
481 }
482 if ($idSubQuery)
483 {
484 $query->whereNotIn('ID', $idSubQuery);
485 }
486 }
487
488 protected function prepareQueryCollection(Entity\Query $query)
489 {
490 $result = [$query];
491
492 $filterFields = $query->getFilter();
493 $productSource = $filterFields['PRODUCT_SOURCE'] ?? '';
494 unset($filterFields['PRODUCT_SOURCE']);
495 $query->setFilter($filterFields);
496
497 $productFilterKey = '=PRODUCT_ID';
498 if (array_key_exists($productFilterKey, $filterFields))
499 {
500 $productIds = $filterFields[$productFilterKey];
501
502 unset($filterFields[$productFilterKey]);
503 $query->setFilter($filterFields);
504
505 $productIds = array_merge($productIds, $this->getProductSkuIds($productIds));
506 if (empty($productIds))
507 {
508 return $result;
509 }
510
511 $result = $this->getQueryCollectionForProductsFilter($query, $productIds, $productSource);
512 }
513
514 return $result;
515 }
516
517 protected function getQueryCollectionForProductsFilter(Entity\Query $query, $productIds, $productSource)
518 {
519 $orderRef = [
520 '=this.ID' => 'ref.ENTITY_ID',
521 ];
522 $dealRef = [];
523
524 $entityName = $query->getEntity()->getName();
525 if ($entityName === 'Contact')
526 {
527 $orderRef['ref.ENTITY_TYPE_ID'] = new SqlExpression('?i', \CCrmOwnerType::Contact);
528 $dealRef['=this.ID'] = 'ref.CONTACT_ID';
529 $extraQuery = $this->getContactQuery();
530 }
531 elseif ($entityName === 'Company')
532 {
533 $orderRef['ref.ENTITY_TYPE_ID'] = new SqlExpression('?i', \CCrmOwnerType::Company);
534 $dealRef['=this.ID'] = 'ref.COMPANY_ID';
535 $extraQuery = $this->getCompanyQuery();
536 }
537 else
538 {
539 return [$query];
540 }
541
542 $query->whereIn('SGT_DEAL.PRODUCT_ROW.PRODUCT_ID', $productIds);
543 $semantics = [];
544
545 if (is_array($productSource))
546 {
547 if (in_array(self::PRODUCT_SOURCE_DEALS_PROCESS, $productSource))
548 {
549 $semantics[] = \Bitrix\Crm\PhaseSemantics::PROCESS;
550 }
551 if (in_array(self::PRODUCT_SOURCE_DEALS_SUCCESS, $productSource))
552 {
553 $semantics[] = \Bitrix\Crm\PhaseSemantics::SUCCESS;
554 }
555 if (in_array(self::PRODUCT_SOURCE_DEALS_FAILURE, $productSource))
556 {
557 $semantics[] = \Bitrix\Crm\PhaseSemantics::FAILURE;
558 }
559 }
560
561 switch (count($semantics))
562 {
563 case 1:
564 $dealRef['ref.STAGE_SEMANTIC_ID'] = new SqlExpression('?', $semantics[0]);
565 break;
566 case 2:
567 $dealRef['@ref.STAGE_SEMANTIC_ID'] = new SqlExpression('?, ?', $semantics[0], $semantics[1]);
568 break;
569 }
570
571 $query->registerRuntimeField(new Entity\ReferenceField(
572 'SGT_DEAL',
573 '\Bitrix\Crm\DealTable',
574 $dealRef,
575 array('join_type' => 'LEFT')
576 ));
577
578 $query->addSelect("SGT_DEAL.ID", "SGT_DEAL_ID");
579 $extraQuery->setFilter($query->getFilter()); // apply actual user filter
580
581 $extraQuery->registerRuntimeField(new Entity\ReferenceField(
582 'PROD_CRM_ORDER',
583 '\Bitrix\Crm\Binding\OrderContactCompanyTable',
584 $orderRef,
585 array('join_type' => 'LEFT')
586 ));
587 $extraQuery->addSelect("PROD_CRM_ORDER.ID", "PROD_CRM_ORDER_ID");
588
589 $extraQuery->registerRuntimeField(new Entity\ReferenceField(
590 'PROD_CRM_ORDER_PRODUCT',
591 '\Bitrix\Sale\Internals\BasketTable',
592 [
593 '=this.PROD_CRM_ORDER.ORDER_ID' => 'ref.ORDER_ID'
594 ],
595 array('join_type' => 'LEFT')
596 ));
597
598 $extraQuery->whereIn('PROD_CRM_ORDER_PRODUCT.PRODUCT_ID', $productIds);
599
600 if (is_array($productSource))
601 {
602 if (in_array(self::PRODUCT_SOURCE_ORDERS_PAID, $productSource) &&
603 !in_array(self::PRODUCT_SOURCE_ORDERS_UNPAID, $productSource))
604 {
605 $extraQuery->where('PROD_CRM_ORDER.ORDER.PAYED', true);
606 }
607 if (!in_array(self::PRODUCT_SOURCE_ORDERS_PAID, $productSource) &&
608 in_array(self::PRODUCT_SOURCE_ORDERS_UNPAID, $productSource))
609 {
610 $extraQuery->where('PROD_CRM_ORDER.ORDER.PAYED', false);
611 }
612 }
613
614 $result = [];
615 $dealsAreRequired = empty($productSource) ||
616 array_intersect($productSource, [self::PRODUCT_SOURCE_DEALS_PROCESS, self::PRODUCT_SOURCE_DEALS_SUCCESS, self::PRODUCT_SOURCE_DEALS_FAILURE]);
617 $ordersAreRequired = empty($productSource) ||
618 array_intersect($productSource, [self::PRODUCT_SOURCE_ORDERS_PAID, self::PRODUCT_SOURCE_ORDERS_UNPAID]);
619
620 $dataTypeId = $this->getDataTypeId();
621 if ($dataTypeId == Type::CRM_ORDER_PRODUCT_CONTACT_ID && $ordersAreRequired)
622 {
623 if ($entityName === 'Contact')
624 {
625 $result[] = $extraQuery;
626 }
627 }
628 elseif ($dataTypeId == Type::CRM_ORDER_PRODUCT_COMPANY_ID && $ordersAreRequired)
629 {
630 if ($entityName === 'Company')
631 {
632 $result[] = $extraQuery;
633 }
634 }
635 elseif ($dataTypeId == Type::CRM_DEAL_PRODUCT_CONTACT_ID && $dealsAreRequired)
636 {
637 if ($entityName === 'Contact')
638 {
639 $result[] = $query;
640 }
641 }
642 elseif ($dataTypeId == Type::CRM_DEAL_PRODUCT_COMPANY_ID && $dealsAreRequired)
643 {
644 if ($entityName === 'Company')
645 {
646 $result[] = $query;
647 }
648 }
649 else
650 {
651 if ($dealsAreRequired)
652 {
653 $result[] = $query;
654 }
655 if ($ordersAreRequired)
656 {
657 $result[] = $extraQuery;
658 }
659 }
660 return $result;
661 }
662
663 protected function getCrmReferencedEntityFilter($entityTypeName)
664 {
665 return $this->getCrmEntityFilter($entityTypeName, true);
666 }
667
668 protected function getCrmEntityFilter($entityTypeName, $isReferenced = false)
669 {
670 if ($this->crmEntityFilter === null)
671 {
672 $this->crmEntityFilter = Helper::getFilterByEntity(
673 self::getUiFilterFields(),
674 $this->getFieldValues(),
675 array_keys(self::getCrmDocumentTypes())
676 );
677 }
678
679 if (isset($this->crmEntityFilter[$entityTypeName]))
680 {
681 $filter = $this->crmEntityFilter[$entityTypeName];
682 }
683 else
684 {
685 $filter = array();
686 }
687
688 if ($isReferenced && count($filter) === 0)
689 {
690 return $filter;
691 }
692
693 $commonNames = ['ASSIGNED_BY_ID', 'EMAIL', 'PHONE', 'NAME'];
694 if ($isReferenced)
695 {
696 $commonNames = ['ASSIGNED_BY_ID'];
697 }
698 foreach ($commonNames as $commonName)
699 {
700 $value = $this->getFieldValue($commonName);
701 if (!$value)
702 {
703 continue;
704 }
705
706 if (in_array($commonName, ['EMAIL', 'PHONE', 'NAME']))
707 {
708 $commonName = "%$entityTypeName.$commonName";
709 }
710 else
711 {
712 $commonName = "=$entityTypeName.$commonName";
713 }
714 $filter[$commonName] = $value;
715 }
716
717 if ($isReferenced)
718 {
719 return $filter;
720 }
721
722 foreach ($filter as $key => $value)
723 {
724 $pattern = "/^([\W]{0,2})$entityTypeName\./";
725 if (!preg_match($pattern, $key))
726 {
727 continue;
728 }
729
730 unset($filter[$key]);
731 $key = preg_replace($pattern, '$1', $key);
732 $filter[$key] = $value;
733 }
734
735 return $filter;
736 }
737
738 protected static function getCrmDocumentTypes()
739 {
740 $types = array(\CCrmOwnerType::Deal);
741
742 $list = array();
743 foreach ($types as $typeId)
744 {
745 $typeName = \CCrmOwnerType::resolveName($typeId);
746 $typeCaption = \CCrmOwnerType::getDescription($typeId);
747 $list[$typeName] = $typeCaption;
748 }
749
750 return $list;
751 }
752
758 protected function getDataCountByType()
759 {
760 if (!$this->hasFieldValues())
761 {
762 return array();
763 }
764
765 return QueryCount::getUnionizedCount($this->getQueries(), $this->getDataTypeId());
766 }
767
773 public function getData()
774 {
775 if (!$this->hasFieldValues())
776 {
777 return array();
778 }
779
781 $this->getQueries(),
782 $this->getDataTypeId(),
783 $this->getResultView()->getNav()
784 );
785
786 return QueryData::getUnionizedData($query);
787 }
788
794 public static function getPersonalizeList()
795 {
796 return Loader::includeModule('crm') ? array_merge(
798 Helper::buildPersonalizeList(\CCrmOwnerType::ContactName),
799 Helper::buildPersonalizeList(\CCrmOwnerType::CompanyName)
801 }
802
803 public static function getDealCategoryList()
804 {
805 return Loader::includeModule('crm') ? DealCategory::getSelectListItems(true) : [];
806 }
807
808 public static function getDealCategoryStageList()
809 {
810 return Loader::includeModule('crm') ? DealCategory::getFullStageList() : [];
811 }
812
818 public static function getUiFilterFields(bool $checkAccessRights = true)
819 {
820 $list = [
821 [
822 'id' => 'EMAIL',
823 'type' => 'string',
824 'sender_segment_filter' => '%EMAIL',
825 'sender_internal' => true
826 ],
827 [
828 'id' => 'PHONE',
829 'type' => 'string',
830 'sender_segment_filter' => '%PHONE',
831 'sender_internal' => true
832 ],
833 [
834 'id' => 'NAME',
835 'type' => 'string',
836 'sender_segment_filter' => '%NAME',
837 'sender_internal' => true
838 ],
839 [
840 'id' => 'CLIENT_ID',
841 'type' => 'string',
842 'params' => array('hidden' => self::YES),
843 "name" => 'ID',
844 "default" => true,
845 'filter_callback' => ['\Bitrix\Sender\Integration\Crm\Connectors\Helper', 'getIdFilter']
846 ],
847 ];
848
849 $list[] = array(
850 "id" => "DOC_TYPE",
851 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DOC_TYPE'),
852 "type" => "list",
853 "items" => self::getCrmDocumentTypes(),
854 "sender_segment_filter" => false,
855 "default" => true,
856 );
857
858 $list[] = array(
859 "id" => "CLIENT_TYPE",
860 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CLIENT_TYPE'),
861 "type" => "list",
862 "items" => array(
863 "" => Loc::getMessage(
864 'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CLIENT_TYPE_NOT_SET',
865 [
866 '%default%' => \CCrmOwnerType::getDescription(\CCrmOwnerType::Contact) . ", " . \CCrmOwnerType::getDescription(\CCrmOwnerType::Company),
867 ]
868 ),
869 \CCrmOwnerType::ContactName => \CCrmOwnerType::getDescription(\CCrmOwnerType::Contact),
870 \CCrmOwnerType::CompanyName => \CCrmOwnerType::getDescription(\CCrmOwnerType::Company),
871 ),
872 "sender_segment_filter" => false,
873 "default" => true
874 );
875
876 $list[] = array(
877 "id" => "DEAL_DATE_CREATE",
878 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_DATE_CREATE'),
879 "type" => "date",
880 "include" => [
881 AdditionalDateType::CUSTOM_DATE,
882 AdditionalDateType::PREV_DAY,
883 AdditionalDateType::NEXT_DAY,
884 AdditionalDateType::MORE_THAN_DAYS_AGO,
885 AdditionalDateType::AFTER_DAYS,
886 ],
887 "allow_years_switcher" => true,
888 "default" => true
889 );
890
891 $stageList = self::getDealCategoryStageList();
892 $list[] = array(
893 "id" => "DEAL_STAGE_ID",
894 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_STATUS_ID'),
895 "type" => "list",
896 'params' => array('multiple' => self::YES),
897 "items" => $stageList,
898 "default" => true
899 );
900
901 $list[] = array(
902 "id" => "CONTACT_SOURCE_ID",
903 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CONTACT_SOURCE_ID'),
904 "type" => "list",
905 'params' => array('multiple' => self::YES),
906 "items" => \CCrmStatus::GetStatusList('SOURCE'),
907 "default" => true
908 );
909
910 $list[] = array(
911 'id' => 'CLIENT_COMMUNICATION_TYPE',
912 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_COMMUNICATION_TYPE'),
913 'params' => array('multiple' => self::YES),
914 'default' => true,
915 'type' => 'list',
916 'items' => \CCrmFieldMulti::PrepareListItems(array(
917 \CCrmFieldMulti::PHONE,
918 \CCrmFieldMulti::EMAIL,
919 \CCrmFieldMulti::IM
920 )),
921 'filter_callback' => ['\Bitrix\Sender\Integration\Crm\Connectors\Helper', 'getCommunicationTypeFilter']
922 );
923
924 $list[] = array(
925 "id" => "CLIENT_NO_PURCHASES_DATE",
926 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_NO_PURCHASES_DATE'),
927 "type" => "date",
928 "exclude" => [
929 \Bitrix\Main\UI\Filter\DateType::TOMORROW,
930 \Bitrix\Main\UI\Filter\DateType::NEXT_DAYS,
931 \Bitrix\Main\UI\Filter\DateType::NEXT_WEEK,
932 \Bitrix\Main\UI\Filter\DateType::NEXT_MONTH,
933 ],
934 "default" => true,
935 'messages' => [
936 'MAIN_UI_FILTER_FIELD_SUBTYPE_NONE' => ''
937 ],
938 'filter_callback' => ['\Bitrix\Sender\Integration\Crm\Connectors\Helper', 'getNoPurchasesFilter']
939 );
940
942 {
943 $list[] = array(
944 'id' => 'CLIENT_PRODUCT_ID',
945 "name" => Loc::getMessage("SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_PRODUCT_ID"),
946 'default' => true,
947 'type' => 'dest_selector',
948 'partial' => true,
949 'params' => array(
950 'multiple' => self::YES,
951 'apiVersion' => self::API_VERSION,
952 'context' => 'SENDER_FILTER_PRODUCT_ID',
953 'contextCode' => 'CRM',
954 'useClientDatabase' => self::NO,
955 'enableAll' => self::NO,
956 'enableDepartments' => self::NO,
957 'enableUsers' => self::NO,
958 'enableSonetgroups' => self::NO,
959 'allowEmailInvitation' => self::NO,
960 'allowSearchEmailUsers' => self::NO,
961 'departmentSelectDisable' => self::YES,
962 'addTabCrmProducts' => self::YES,
963 'enableCrm' => self::YES,
964 'enableCrmProducts' => self::YES,
965 'convertJson' => self::YES
966 ),
967 );
968
969 $list[] = array(
970 'id' => 'CLIENT_PRODUCT_SOURCE',
971 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE'),
972 'default' => true,
973 'type' => 'list',
974 'params' => array(
975 'multiple' => self::YES,
976 ),
977 'items' => [
978 "" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_ANY'),
979 self::PRODUCT_SOURCE_ORDERS_PAID => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_ORDERS_PAID'),
980 self::PRODUCT_SOURCE_ORDERS_UNPAID => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_ORDERS_UNPAID'),
981 self::PRODUCT_SOURCE_DEALS_PROCESS => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_DEALS_PROCESS'),
982 self::PRODUCT_SOURCE_DEALS_SUCCESS => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_DEALS_SUCCESS'),
983 self::PRODUCT_SOURCE_DEALS_FAILURE => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_DEALS_FAILURE'),
984 ],
985 'filter_callback' => ['\Bitrix\Sender\Integration\Crm\Connectors\Helper', 'productSourceFilter']
986 );
987 }
988 else
989 {
990 $list[] = array(
991 'id' => 'DEAL_PRODUCT_ROW.PRODUCT_ID',
992 "name" => Loc::getMessage("SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_PRODUCT_ID"),
993 'default' => true,
994 'type' => 'dest_selector',
995 'partial' => true,
996 'params' => array(
997 'multiple' => self::YES,
998 'apiVersion' => self::API_VERSION,
999 'context' => 'SENDER_FILTER_PRODUCT_ID',
1000 'contextCode' => 'CRM',
1001 'useClientDatabase' => self::NO,
1002 'enableAll' => self::NO,
1003 'enableDepartments' => self::NO,
1004 'enableUsers' => self::NO,
1005 'enableSonetgroups' => self::NO,
1006 'allowEmailInvitation' => self::NO,
1007 'allowSearchEmailUsers' => self::NO,
1008 'departmentSelectDisable' => self::YES,
1009 'addTabCrmProducts' => self::YES,
1010 'enableCrm' => self::YES,
1011 'enableCrmProducts' => self::YES,
1012 'convertJson' => self::YES
1013 )
1014 );
1015 }
1016
1017
1018 $list[] = PhaseSemantics::getListFilterInfo(
1019 \CCrmOwnerType::Deal,
1020 array(
1021 'id' => 'DEAL_STAGE_SEMANTIC_ID',
1022 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_STATUS_SEMANTIC_ID'),
1023 'default' => true,
1024 'params' => array('multiple' => self::YES)
1025 ),
1026 true
1027 );
1028
1029 $list[] = array(
1030 "id" => "CONTACT_POST",
1031 'type' => 'string',
1032 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CONTACT_POST'),
1033 'params' => array('multiple' => self::YES),
1034 "default" => false
1035 );
1036
1037 $list[] = array(
1038 "id" => "ASSIGNED_BY_ID",
1039 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_ASSIGNED_BY_ID'),
1040 'type' => 'dest_selector',
1041 'params' => array(
1042 'context' => 'SENDER_FILTER_ASSIGNED_BY_ID',
1043 'multiple' => self::YES,
1044 'contextCode' => 'U',
1045 'enableAll' => self::NO,
1046 'enableSonetgroups' => self::NO,
1047 'allowEmailInvitation' => self::NO,
1048 'allowSearchEmailUsers' => self::NO,
1049 'departmentSelectDisable' => self::YES,
1050 'isNumeric' => self::YES,
1051 'prefix' => 'U'
1052 ),
1053 "sender_segment_filter" => false,
1054 "default" => false
1055 );
1056
1057 foreach ([\CCrmOwnerType::Company, \CCrmOwnerType::Contact, \CCrmOwnerType::Deal] as $entityTypeId)
1058 {
1059 $entityTypeCaption = \CCrmOwnerType::getDescription($entityTypeId);
1060 $entityTypeName = \CCrmOwnerType::resolveName($entityTypeId);
1061 $fieldId = "{$entityTypeName}_ASSIGNED_BY_ID";
1062 $list[] = array(
1063 "id" => $fieldId,
1064 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_ASSIGNED_BY_ID') . " ($entityTypeCaption)",
1065 'type' => 'dest_selector',
1066 'params' => array(
1067 'context' => 'SENDER_FILTER_ASSIGNED_BY_ID',
1068 'multiple' => self::YES,
1069 'contextCode' => 'U',
1070 'enableAll' => self::NO,
1071 'enableSonetgroups' => self::NO,
1072 'allowEmailInvitation' => self::NO,
1073 'allowSearchEmailUsers' => self::NO,
1074 'departmentSelectDisable' => self::YES,
1075 'isNumeric' => self::YES,
1076 'prefix' => 'U'
1077 ),
1078 //"sender_segment_filter" => false,
1079 "default" => false
1080 );
1081 }
1082
1083 $list[] = array(
1084 "id" => "CONTACT_BIRTHDATE",
1085 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CONTACT_BIRTHDATE'),
1086 'type' => 'date',
1087 "include" => [
1088 AdditionalDateType::CUSTOM_DATE,
1089 AdditionalDateType::PREV_DAY,
1090 AdditionalDateType::NEXT_DAY,
1091 AdditionalDateType::MORE_THAN_DAYS_AGO,
1092 AdditionalDateType::AFTER_DAYS,
1093 ],
1094 "allow_years_switcher" => true,
1095 "default" => false,
1096 );
1097
1098 //we need to filter able deals
1099 $list[] = array(
1100 'id' => self::DEAL_CATEGORY_ID,
1101 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_CATEGORY_ID_MSG_1'),
1102 'params' => array('multiple' => self::YES),
1103 'default' => true,
1104 'type' => 'list',
1105 'required' => true,
1106 'valueRequired' => true,
1107 'items' => self::getDealCategoryList(),
1108 'filter_callback' => ['\Bitrix\Sender\Integration\Crm\Connectors\Helper', 'getDealCategoryFilter']
1109 );
1110
1111 $list[] = array(
1112 "id" => "DEAL_TYPE_ID",
1113 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_TYPE_ID'),
1114 "type" => "list",
1115 'params' => array('multiple' => self::YES),
1116 "items" => \CCrmStatus::GetStatusList('DEAL_TYPE'),
1117 "default" => false
1118 );
1119
1120 $list[] = array(
1121 "id" => "DEAL_OPPORTUNITY",
1122 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_OPPORTUNITY'),
1123 "type" => "number",
1124 "default" => false
1125 );
1126
1127 $list[] = array(
1128 "id" => "DEAL_CLOSEDATE",
1129 "name" => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_CLOSEDATE'),
1130 "type" => "date",
1131 "include" => [
1132 AdditionalDateType::CUSTOM_DATE,
1133 AdditionalDateType::PREV_DAY,
1134 AdditionalDateType::NEXT_DAY,
1135 AdditionalDateType::MORE_THAN_DAYS_AGO,
1136 AdditionalDateType::AFTER_DAYS,
1137 ],
1138 "allow_years_switcher" => true,
1139 "default" => false
1140 );
1141
1142 $list[] = array(
1143 'id' => 'COMPANY_COMPANY_TYPE',
1144 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_COMPANY_TYPE'),
1145 'params' => array('multiple' => self::YES),
1146 'default' => false,
1147 'type' => 'list',
1148 'items' => \CCrmStatus::GetStatusList('COMPANY_TYPE'),
1149 );
1150
1151 $list[] = array(
1152 'id' => 'CONTACT_TYPE_ID',
1153 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CONTACT_TYPE'),
1154 'params' => array('multiple' => self::YES),
1155 'default' => false,
1156 'type' => 'list',
1157 'items' => \CCrmStatus::GetStatusList('CONTACT_TYPE'),
1158 );
1159
1160 $list[] = array(
1161 'id' => 'CONTACT_HONORIFIC',
1162 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CONTACT_HONORIFIC'),
1163 'params' => array('multiple' => self::YES),
1164 'default' => false,
1165 'type' => 'list',
1166 'items' => \CCrmStatus::GetStatusList('HONORIFIC'),
1167 );
1168
1169 $list[] = array(
1170 'id' => 'COMPANY_INDUSTRY',
1171 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_COMPANY_INDUSTRY'),
1172 'params' => array('multiple' => self::YES),
1173 'default' => false,
1174 'type' => 'list',
1175 'items' => \CCrmStatus::GetStatusList('INDUSTRY'),
1176 );
1177
1178
1179 $entityTypes = array_merge(
1180 array(
1181 \CCrmOwnerType::ContactName,
1182 \CCrmOwnerType::CompanyName,
1183 ),
1184 array_keys(self::getCrmDocumentTypes())
1185 );
1186 foreach ($entityTypes as $entityTypeName)
1187 {
1188 $entityTypeId = \CCrmOwnerType::resolveId($entityTypeName);
1189 $entityTypeCaption = \CCrmOwnerType::getDescription($entityTypeId);
1190 $ufList = Helper::getFilterUserFields($entityTypeId, $checkAccessRights);
1191 foreach ($ufList as $item)
1192 {
1193 if (isset($item['name']))
1194 {
1195 $item['name'] .= " ($entityTypeCaption)";
1196 }
1197 elseif (isset($item['NAME']))
1198 {
1199 $item['NAME'] .= " ($entityTypeCaption)";
1200 }
1201
1202 if (isset($item['id']))
1203 {
1204 $item['id'] = $entityTypeName . "_" . $item['id'];
1205 }
1206 elseif (isset($item['ID']))
1207 {
1208 $item['ID'] = $entityTypeName . "_" . $item['ID'];
1209 }
1210
1211 $list[] = $item;
1212 }
1213 }
1214
1215 return $list;
1216 }
1217
1223 public static function getUiFilterPresets()
1224 {
1225 $list = array(
1226 'crm_client_all' => array(
1227 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_ALL'),
1228 'sender_segment_name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_ALL'),
1229 'fields' => array(
1230 self::FIELD_FOR_PRESET_ALL => self::YES,
1231 )
1232 ),
1233 'crm_client_deal_in_work' => array(
1234 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_DEAL_INW'),
1235 'sender_segment_name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_DEAL_INW'),
1236 'fields' => array(
1237 'DEAL_STAGE_SEMANTIC_ID' => array(PhaseSemantics::PROCESS),
1238 )
1239 ),
1240 'crm_client_deal_won' => array(
1241 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_DEAL_WON'),
1242 'sender_segment_name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_DEAL_WON'),
1243 'fields' => array(
1244 'DEAL_STAGE_SEMANTIC_ID' => array(PhaseSemantics::SUCCESS),
1245 )
1246 ),
1247 'crm_client_deal_loose' => array(
1248 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_DEAL_LOOSE'),
1249 'sender_segment_name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_DEAL_LOOSE'),
1250 'fields' => array(
1251 'DEAL_STAGE_SEMANTIC_ID' => array(PhaseSemantics::FAILURE),
1252 )
1253 ),
1254 'crm_client_birthday' => array(
1255 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_BIRTH'),
1256 'sender_segment_name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_BIRTH'),
1257 'sender_segment_business_case' => true,
1258 'fields' => array(
1259 'CONTACT_BIRTHDATE_datesel' => 'NEXT_DAY',
1260 'CONTACT_BIRTHDATE_days' => '5',
1261 'CONTACT_BIRTHDATE_allow_year' => '0',
1262 'CLIENT_TYPE' => \CCrmOwnerType::ContactName
1263 )
1264 ),
1265 'crm_client_aft_deal_clo' => array(
1266 'name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_AFTER_CLOSE_DEAL'),
1267 'sender_segment_name' => Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_AFTER_CLOSE_DEAL'),
1268 'sender_segment_business_case' => true,
1269 'fields' => array(
1270 'DEAL_CLOSEDATE_datesel' => 'PREV_DAY',
1271 'DEAL_CLOSEDATE_days' => "30",
1272 'DEAL_CLOSEDATE_allow_year' => '1',
1273 )
1274 ),
1275 );
1276
1277 foreach (Holiday::getList() as $holiday)
1278 {
1279 $code = $holiday->getCode();
1280 $name = $holiday->getName(
1281 Loc::getMessage('SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_HOLIDAY'),
1282 '%holiday_name%'
1283 );
1284
1285 $list["crm_client_$code"] = [
1286 'name' => $name,
1287 'sender_segment_name' => $name,
1288 'sender_segment_business_case' => true,
1289 'fields' => [
1290 'DEAL_DATE_CREATE_datesel' => 'RANGE',
1291 'DEAL_DATE_CREATE_from' => $holiday->getDateFrom()->toString(),
1292 'DEAL_DATE_CREATE_to' => $holiday->getDateTo()->toString(),
1293 'DEAL_DATE_CREATE_allow_year' => '0',
1294 ]
1295 ];
1296 }
1297
1298 return $list;
1299 }
1300
1306 public function isResultViewable()
1307 {
1308 return true;
1309 }
1310
1311 protected function onInitResultView()
1312 {
1313 $this->getResultView()
1314 ->setCallback(
1315 ResultView::ColumnModifier,
1316 function ()
1317 {
1318 Asset::getInstance()->addJs('/bitrix/js/crm/common.js');
1319 }
1320 )
1321 ->setCallback(
1322 ResultView::Draw,
1323 function (array &$row)
1324 {
1325 (new Helper())->onResultViewDraw($row);
1326 }
1327 );
1328 }
1329
1330 protected function getProductSkuIds($productIds)
1331 {
1332 if (!Loader::includeModule("catalog"))
1333 return [];
1334
1335 return
1336 array_reduce(
1337 \CCatalogSKU::getOffersList($productIds),
1338 function($ids, $items)
1339 {
1340 $ids = array_merge(
1341 $ids,
1342 array_map(
1343 function($item)
1344 {
1345 return $item['ID'];
1346 },
1347 $items)
1348 );
1349 return $ids;
1350 }, []);
1351 }
1352
1353 public function getUiFilterId()
1354 {
1355 $code = str_replace('_', '', $this->getCode());
1356 return $this->getId() . '_--filter--'.$code.'--';
1357 }
1358
1363 public function getStatFields()
1364 {
1365 return ['CLIENT_PRODUCT_ID', 'CLIENT_NO_PURCHASES_DATE'];
1366 }
1367}
static getConnection($name="")
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
getFieldValue($name, $defaultValue=null)
Definition base.php:195
getLimitedQueries(int $offset, int $limit, string $excludeType=null)
Definition client.php:103
static getUiFilterFields(bool $checkAccessRights=true)
Definition client.php:818
getCrmEntityFilter($entityTypeName, $isReferenced=false)
Definition client.php:668
addNoPurchasesFilter($query, $filterValue, $productSource)
Definition client.php:379
prepareQueryForType(Query $query, int $from, int $to, array &$queries)
Definition client.php:173
getQueryCollectionForProductsFilter(Entity\Query $query, $productIds, $productSource)
Definition client.php:517
static createExpressionMultiField($entityName, $multiFieldTypeId)
Definition helper.php:45
static getFilterByEntity(array $fields=array(), array $values=array(), array $entityTypeNames=array())
Definition helper.php:459
static getRuntimeByEntity($entityTypeName='')
Definition helper.php:399
static getFilterUserFields(int $entityTypeId, bool $checkAccessRights=true)
Definition helper.php:200
static getUnionizedCount(array $queries, $dataTypeId=null)
static getUnionizedQuery(array $queries, $dataTypeId=null, PageNavigation $nav=null)
Definition querydata.php:33
static getList($languageId=LANGUAGE_ID)
Definition holiday.php:51
setCallback($name, $callable)