Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
recipient.php
1<?php
2
3namespace Bitrix\Mail\Helper;
4
7
13{
21 public static function buildUniqueEmailCode($email)
22 {
23// return 'U' . md5($email);
24 return 'MC' . $email;
25 }
26
37 public static function loadLastRcpt($emailTo = null, $limit = 10)
38 {
39 global $APPLICATION;
40
41 $result = array();
42
43 $currentUser = \Bitrix\Main\Engine\CurrentUser::get();
44
45 $lastRcptResult = \Bitrix\Main\FinderDestTable::getList(array(
46 'filter' => array(
47 '=USER_ID' => $currentUser->getId(),
48 '=CONTEXT' => 'MAIL_LAST_RCPT',
49 ),
50 'select' => array('CODE'),
51 'order' => array('LAST_USE_DATE' => 'DESC'),
52 'limit' => $limit,
53 ));
54
55 $emailUsersIds = array();
56 while ($item = $lastRcptResult->fetch())
57 {
58 $emailUsersIds[] = (int) str_replace('MC', '', $item['CODE']);
59 }
60
61 if (count($emailUsersIds) > 0)
62 {
63 $mailContacts = Mail\Internals\MailContactTable::getList([
64 'filter' => array(
65 '@ID' => $emailUsersIds,
66 '=USER_ID' => $currentUser->getId(),
67 ),
68 'select' => ['ID', 'NAME', 'EMAIL', 'ICON'],
69 'limit' => $limit,
70 ])->fetchAll();
71
72 $contactAvatars = $resultsMailContacts = [];
73 foreach ($mailContacts as $mailContact)
74 {
75 $resultsMailContacts[$mailContact['EMAIL']] = $mailContact;
76 }
77 foreach ($resultsMailContacts as $mailContact)
78 {
79 $email = $mailContact['EMAIL'];
80 if ($contactAvatars[$email] === null)
81 {
82 ob_start();
83 $APPLICATION->includeComponent('bitrix:mail.contact.avatar', '', array(
84 'mailContact' => $mailContact,
85 ));
86 $contactAvatars[$email] = ob_get_clean();
87 }
88 $id = static::buildUniqueEmailCode($email);
89 $result[$id] = [
90 'id' => $id,
91 'entityType' => 'email',
92 'entityId' => $mailContact['ID'],
93 'name' => htmlspecialcharsbx($mailContact['NAME']),
94 'iconCustom' => $contactAvatars[$email],
95 'email' => htmlspecialcharsbx($mailContact['EMAIL']),
96 'desc' => htmlspecialcharsbx($mailContact['EMAIL']),
97 'isEmail' => 'Y',
98 ];
99 }
100 }
101
102 return $result;
103 }
104
105
116 public static function loadMailContacts($filter = [], $limit = 20)
117 {
118 global $APPLICATION;
119
120 $result = array();
121
122 $mailContacts = \Bitrix\Main\UserTable::getList(array(
123 'select' => array(
124 'ID',
125 'NAME',
126 'LAST_NAME',
127 'SECOND_NAME',
128 'EMAIL',
129 'PERSONAL_PHOTO',
130 ),
131 'filter' => array_merge(
132 array(
133 '=ACTIVE' => 'Y',
134 '=EXTERNAL_AUTH_ID' => 'email',
135 ),
136 $filter
137 ),
138 'order' => array(
139 'LAST_NAME' => 'ASC',
140 ),
141 'limit' => $limit,
142 ));
143
144 $contactAvatars = array();
145 while ($mailContact = $mailContacts->fetch())
146 {
147 $email = $mailContact['EMAIL'];
148 if ($contactAvatars[$email] === null)
149 {
150 ob_start();
151 $APPLICATION->includeComponent('bitrix:mail.contact.avatar', '',
152 [
153 'mailContact' => array(
154 'FILE_ID' => $mailContact['PERSONAL_PHOTO'],
155 'name' => \CUser::formatName(\CSite::getNameFormat(), $mailContact),
156 'email' => $mailContact['EMAIL'],
157 ),
158 ]);
159 $contactAvatars[$email] = ob_get_clean();
160 }
161
162 $id = static::buildUniqueEmailCode($email);
163 $result[$id] = array(
164 'id' => $id,
165 'entityType' => 'mailContacts',
166 'entityId' => $mailContact['ID'],
167 'name' => \CUser::formatName(\CSite::getNameFormat(), $mailContact, true, true),
168 'iconCustom' => $contactAvatars[$email],
169 'email' => htmlspecialcharsbx($mailContact['EMAIL']),
170 'desc' => htmlspecialcharsbx($mailContact['EMAIL']),
171 'isEmail' => 'Y',
172 );
173 }
174
175 return $result;
176 }
177
188 public static function loadCrmMailContacts($filter = [], $limit = 20)
189 {
190 global $APPLICATION;
191
192 $result = array();
193
194 if (Main\Loader::includeModule('crm'))
195 {
196 $mailContacts = \Bitrix\Main\UserTable::getList(array(
197 'select' => array(
198 'ID',
199 'NAME',
200 'LAST_NAME',
201 'SECOND_NAME',
202 'EMAIL',
203 'PERSONAL_PHOTO',
204 ),
205 'filter' => array_merge(
206 array(
207 '=ACTIVE' => 'Y',
208 '=EXTERNAL_AUTH_ID' => 'email',
209 ),
210 $filter
211 ),
212 'order' => array(
213 'LAST_NAME' => 'ASC',
214 ),
215 'limit' => $limit,
216 ));
217
218 $contactAvatars = array();
219 while ($mailContact = $mailContacts->fetch())
220 {
221 $email = $mailContact['EMAIL'];
222 if (empty($email))
223 {
224 continue;
225 }
226
227 $crmCommunications = \CSocNetLogDestination::searchCrmEntities(array(
228 'SEARCH' => $email,
229 'ENTITIES' => array('CONTACT'),
230 ));
231 foreach ($crmCommunications as $communication)
232 {
233 $email = $communication['email'];
234
235 if ($contactAvatars[$email] === null)
236 {
237 ob_start();
238 $APPLICATION->includeComponent('bitrix:mail.contact.avatar', '',
239 [
240 'mailContact' => array(
241 'FILE_ID' => $mailContact['PERSONAL_PHOTO'],
242 'name' => \CUser::formatName(\CSite::getNameFormat(), $mailContact),
243 'email' => $email,
244 ),
245 ]);
246 $contactAvatars[$email] = ob_get_clean();
247 $communication['iconCustom'] = $contactAvatars[$email];
248 }
249
250 $id = static::buildUniqueEmailCode($email);
251 $communication['id'] = $id;
252 $result[$id] = $communication;
253 }
254 }
255 }
256
257 return $result;
258 }
259}
static buildUniqueEmailCode($email)
Definition recipient.php:21
static loadMailContacts($filter=[], $limit=20)
static loadLastRcpt($emailTo=null, $limit=10)
Definition recipient.php:37
static loadCrmMailContacts($filter=[], $limit=20)