1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mailcrmrecipientappearancefilter.php
См. документацию.
1<?php
2
3namespace Bitrix\Mail\Integration\UI\EntitySelector;
4
5use Bitrix\Main\Loader;
6use Bitrix\UI\EntitySelector\BaseFilter;
7use Bitrix\UI\EntitySelector\Dialog;
8use Bitrix\UI\EntitySelector\Item;
9use Bitrix\Crm\Multifield\Type;
10
12{
13 public function __construct()
14 {
15 parent::__construct();
16 }
17
18 public function isAvailable(): bool
19 {
20 return true;
21 }
22
23 private static function buildTitle(string $name, string $email): string
24 {
25 $emailIsEquivalentToName = $email === $name;
26
27 return ($emailIsEquivalentToName ? $name : $name . ' (' . $email . ')');
28 }
29
30 private static function buildSubtitle(string $name, string $email): string
31 {
32 $emailIsEquivalentToName = $email === $name;
33
34 return ($emailIsEquivalentToName ? '' : $email);
35 }
36
37 public function apply(array $items, Dialog $dialog): void
38 {
39 if (!Loader::includeModule('crm'))
40 {
41 return;
42 }
43
44 $companyCount = 0;
45 $contactCount = 0;
46 $leadCount = 0;
47
48 foreach ($items as $item)
49 {
50 if (!($item instanceof Item))
51 {
52 continue;
53 }
54
55 $email = '';
56 $title = $item->getTitle();
57
58 switch ($item->getEntityId())
59 {
60 case 'company':
61 {
62 if ($companyCount < MailCrmRecipientProvider::ITEMS_LIMIT)
63 {
65 $companyCount++;
66 }
67 }
68 case 'contact':
69 {
70 if ($contactCount < MailCrmRecipientProvider::ITEMS_LIMIT)
71 {
73 $contactCount++;
74 }
75 }
76 case 'lead':
77 {
79 {
81 $leadCount++;
82 }
83
84 $customDataValues = $item->getCustomData()->getValues();
85
86 if (isset($customDataValues['entityInfo']['advancedInfo']['multiFields']))
87 {
88 $fields = $customDataValues['entityInfo']['advancedInfo']['multiFields'];
89
90 foreach ($fields as $field)
91 {
92 if ($field['TYPE_ID'] === Type\Email::ID)
93 {
94 $email = $field['VALUE'];
95 $item->setTagOptions([
96 'title' => self::buildTitle($title, $email),
97 ]);
98 $item->setSubtitle(self::buildSubtitle($title, $email));
99 $customDataValues['email'] = $email;
100 }
101 }
102 }
103
104 $customDataValues['entityId'] = $item->getId();
105
106 $customDataValues['entityType'] = $item->getEntityId();
107
108 $customDataValues['name'] = $item->getTitle();
109
110 if ($customDataValues['name'] === '')
111 {
112 $customDataValues['name'] = $email;
113 }
114
115 $item->setCustomData($customDataValues);
116
117 break;
118 }
119 }
120 }
121 }
122}
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$name
Определения menu_edit.php:35
Определения collection.php:2
$email
Определения payment.php:49
$items
Определения template.php:224
$title
Определения pdf.php:123
$fields
Определения yandex_run.php:501