Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mailboxaccess.php
1<?php
2
4
6
24{
25
26 public static function getFilePath()
27 {
28 return __FILE__;
29 }
30
31 public static function getTableName()
32 {
33 return 'b_mail_mailbox_access';
34 }
35
36 public static function getMap()
37 {
38 return array(
39 'ID' => array(
40 'data_type' => 'integer',
41 'primary' => true,
42 'autocomplete' => true,
43 ),
44 'MAILBOX_ID' => array(
45 'data_type' => 'integer',
46 'required' => true,
47 ),
48 'TASK_ID' => array(
49 'data_type' => 'integer',
50 ),
51 'ACCESS_CODE' => array(
52 'data_type' => 'string',
53 'required' => true,
54 ),
55 );
56 }
57
65 public static function getUserIdsWithAccessToTheMailbox(int $mailboxId): array
66 {
67 $accesses = self::getList([
68 'filter' => [
69 '=MAILBOX_ID' => $mailboxId,
70 'TASK_ID' => 0,
71 ],
72 ]);
73
74 $userIds = [];
75
76 while ($item = $accesses->fetch())
77 {
78 if (preg_match('/^(U)(\d+)$/', $item['ACCESS_CODE'], $matches))
79 {
80 if ('U' == $matches[1])
81 {
82 $userIds[] = (int)$matches[2];
83 }
84 }
85 }
86 return $userIds;
87 }
88
96 public static function getUsersDataWithAccessToTheMailbox(int $mailboxId): array
97 {
98 $userIds = self::getUserIdsWithAccessToTheMailbox($mailboxId);
99 if (empty($userIds))
100 {
101 return [];
102 }
103 $users = \Bitrix\Main\UserTable::getList([
104 'select' => [
105 'ID',
106 'NAME',
107 'LAST_NAME',
108 'SECOND_NAME',
109 'LOGIN',
110 ],
111 'filter' => [
112 '@ID' => $userIds,
113 ],
114 ]);
115
116 $userCards = [];
117
118 while ($user = $users->fetch())
119 {
120 $userCards[] = [
121 'id' => (int) $user['ID'],
122 'name' => trim(\CUser::formatName(\CSite::getNameFormat(), $user, true, false)),
123 ];
124 }
125 return $userCards;
126 }
127
136 public static function getUsersDataByName(int $mailboxId, $name): array
137 {
138 $usersData = self::getUsersDataWithAccessToTheMailbox($mailboxId);
139 $foundUsers = [];
140
141 foreach ($usersData as $user)
142 {
143 if ($user['name'] === trim($name))
144 {
145 $foundUsers[] = $user;
146 }
147 }
148
149 return $foundUsers;
150 }
151
157 public static function getUserDataById(int $mailboxId, int $userId): array
158 {
159 $usersData = self::getUsersDataWithAccessToTheMailbox($mailboxId);
160 $foundUser = [];
161
162 foreach ($usersData as $user)
163 {
164 if ($user['id'] === $userId)
165 {
166 $foundUser = $user;
167 break;
168 }
169 }
170 return $foundUser;
171 }
172
173}
static getUsersDataWithAccessToTheMailbox(int $mailboxId)
static getUserIdsWithAccessToTheMailbox(int $mailboxId)
static getUsersDataByName(int $mailboxId, $name)
static getUserDataById(int $mailboxId, int $userId)
static getList(array $parameters=array())