1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mailboxaccess.php
См. документацию.
1<?php
2
3namespace Bitrix\Mail\Internals;
4
5use Bitrix\Mail\MailboxTable;
6use Bitrix\Main\Entity;
7use Bitrix\Main\ORM\Data\Internal\DeleteByFilterTrait;
8use Bitrix\Main\UserAccessTable;
9
27{
28 use DeleteByFilterTrait;
29
30 public static function getFilePath()
31 {
32 return __FILE__;
33 }
34
35 public static function getTableName()
36 {
37 return 'b_mail_mailbox_access';
38 }
39
40 public static function getMap()
41 {
42 return array(
43 'ID' => array(
44 'data_type' => 'integer',
45 'primary' => true,
46 'autocomplete' => true,
47 ),
48 'MAILBOX_ID' => array(
49 'data_type' => 'integer',
50 'required' => true,
51 ),
52 'TASK_ID' => array(
53 'data_type' => 'integer',
54 ),
55 'ACCESS_CODE' => array(
56 'data_type' => 'string',
57 'required' => true,
58 ),
59 );
60 }
61
69 public static function getUserIdsWithAccessToTheMailbox(int $mailboxId): array
70 {
71 $accesses = self::getList([
72 'filter' => [
73 '=MAILBOX_ID' => $mailboxId,
74 'TASK_ID' => 0,
75 ],
76 ]);
77
78 $userIds = [];
79
80 while ($item = $accesses->fetch())
81 {
82 if (preg_match('/^(U)(\d+)$/', $item['ACCESS_CODE'], $matches))
83 {
84 if ('U' == $matches[1])
85 {
86 $userIds[] = (int)$matches[2];
87 }
88 }
89 }
90 return $userIds;
91 }
92
100 public static function getUsersDataWithAccessToTheMailbox(int $mailboxId): array
101 {
102 $userIds = self::getUserIdsWithAccessToTheMailbox($mailboxId);
103 if (empty($userIds))
104 {
105 return [];
106 }
108 'select' => [
109 'ID',
110 'NAME',
111 'LAST_NAME',
112 'SECOND_NAME',
113 'LOGIN',
114 ],
115 'filter' => [
116 '@ID' => $userIds,
117 ],
118 ]);
119
120 $userCards = [];
121
122 while ($user = $users->fetch())
123 {
124 $userCards[] = [
125 'id' => (int) $user['ID'],
126 'name' => trim(\CUser::formatName(\CSite::getNameFormat(), $user, true, false)),
127 ];
128 }
129 return $userCards;
130 }
131
140 public static function getUsersDataByName(int $mailboxId, $name): array
141 {
142 $usersData = self::getUsersDataWithAccessToTheMailbox($mailboxId);
143 $foundUsers = [];
144
145 foreach ($usersData as $user)
146 {
147 if ($user['name'] === trim($name))
148 {
149 $foundUsers[] = $user;
150 }
151 }
152
153 return $foundUsers;
154 }
155
161 public static function getUserDataById(int $mailboxId, int $userId): array
162 {
163 $usersData = self::getUsersDataWithAccessToTheMailbox($mailboxId);
164 $foundUser = [];
165
166 foreach ($usersData as $user)
167 {
168 if ($user['id'] === $userId)
169 {
170 $foundUser = $user;
171 break;
172 }
173 }
174 return $foundUser;
175 }
176
177
178 public static function onAfterAdd(Entity\Event $event): void
179 {
180 self::cleanMailboxCache($event);
181 }
182
183 public static function onAfterUpdate(Entity\Event $event): void
184 {
185 self::cleanMailboxCache($event);
186 }
187
188 public static function onAfterDelete(Entity\Event $event): void
189 {
190 self::cleanMailboxCache($event);
191 }
192
193 private static function cleanMailboxCache(Entity\Event $event): void
194 {
195 $mailboxAccess = $event->getParameter('fields');
196
197 if (isset($mailboxAccess['ACCESS_CODE']))
198 {
199 $userIds = UserAccessTable::query()
200 ->setSelect(['USER_ID'])
201 ->where('ACCESS_CODE', $mailboxAccess['ACCESS_CODE'])
202 ->exec()
203 ->fetchAll();
204
205 foreach ($userIds as $userId)
206 {
207 $userId = (int)$userId['USER_ID'];
208 if ($userId > 0)
209 {
211 }
212 }
213 }
214 }
215
216 public static function onBeforeDeleteByFilter(): void
217 {
219 }
220}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static onAfterAdd(Entity\Event $event)
Определения mailboxaccess.php:178
static getUsersDataWithAccessToTheMailbox(int $mailboxId)
Определения mailboxaccess.php:100
static getUserIdsWithAccessToTheMailbox(int $mailboxId)
Определения mailboxaccess.php:69
static onAfterUpdate(Entity\Event $event)
Определения mailboxaccess.php:183
static getUsersDataByName(int $mailboxId, $name)
Определения mailboxaccess.php:140
static onAfterDelete(Entity\Event $event)
Определения mailboxaccess.php:188
static getUserDataById(int $mailboxId, int $userId)
Определения mailboxaccess.php:161
static cleanUserSharedCache(int $userId)
Определения mailbox.php:566
static cleanAllSharedCache()
Определения mailbox.php:581
Определения event.php:5
static getList(array $parameters=array())
Определения datamanager.php:431
</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
Определения ufield.php:9
$user
Определения mysql_to_pgsql.php:33
$event
Определения prolog_after.php:141
$matches
Определения index.php:22