Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sharedmailboxesmanager.php
1<?php
3
6use Bitrix\Main\Entity\Query\Filter\Expression\Column;
7use Bitrix\Main\Entity\ReferenceField;
10
12{
13 public static function getSharedMailboxesCount()
14 {
15 $count = static::getBaseQueryForSharedMailboxes()
16 ->addSelect(Query::expr()->countDistinct('MAILBOX_ID'), 'CNT')
17 ->exec()
18 ->fetch();
19 return !empty($count['CNT']) ? $count['CNT'] : 0;
20 }
21
22 public static function getSharedMailboxesIds()
23 {
24 $mailboxesIds = static::getBaseQueryForSharedMailboxes()
25 ->addSelect('MAILBOX_ID')
26 ->addGroup('MAILBOX_ID')
27 ->exec()
28 ->fetchAll();
29 return array_map('intval', array_column($mailboxesIds, 'MAILBOX_ID'));
30 }
31
32 public static function getUserIdsWithAccessToMailbox($mailboxId)
33 {
34 $userCodes = MailboxAccessTable::query()
35 ->addSelect('ACCESS_CODE')
36 ->where('MAILBOX_ID', $mailboxId)
37 ->whereLike('ACCESS_CODE', 'U%')
38 ->exec()
39 ->fetchAll();
40 $results = [];
41 foreach ($userCodes as $userAccessCode)
42 {
43 // @TODO: departments
44 if (preg_match('#U[0-9]+#', $userAccessCode['ACCESS_CODE']) === 1)
45 {
46 $results[] = mb_substr($userAccessCode['ACCESS_CODE'], 1);
47 }
48 }
49 return $results;
50 }
51
57 private static function getBaseQueryForSharedMailboxes()
58 {
59 $helper = MailboxAccessTable::getEntity()->getConnection()->getSqlHelper();
61 ->registerRuntimeField('', new ReferenceField('ref', MailboxTable::class, ['=this.MAILBOX_ID' => 'ref.ID'], ['join_type' => 'INNER']))
62 ->where(new ExpressionField(
63 'ac',
64 $helper->getConcatFunction("'U'", '%s'),
65 'ref.USER_ID'), '!=', new Column('ACCESS_CODE'))
66 ->where('ref.ACTIVE', 'Y')
67 ->where('ref.LID', SITE_ID);
68 }
69}