Server IP : 85.193.89.191 / Your IP : 18.119.160.95 Web Server : Apache System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64 User : bitrix ( 600) PHP Version : 8.1.27 Disable Function : NONE MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/bitrix/www/bitrix/modules/mail/lib/helper/mailbox/ |
Upload File : |
<?php namespace Bitrix\Mail\Helper\Mailbox; use Bitrix\Mail\Internals\MailboxAccessTable; use Bitrix\Mail\MailboxTable; use Bitrix\Main\Entity\Query\Filter\Expression\Column; use Bitrix\Main\Entity\ReferenceField; use Bitrix\Main\ORM\Fields\ExpressionField; use Bitrix\Main\ORM\Query\Query; class SharedMailboxesManager { public static function getSharedMailboxesCount() { $count = static::getBaseQueryForSharedMailboxes() ->addSelect(Query::expr()->countDistinct('MAILBOX_ID'), 'CNT') ->exec() ->fetch(); return !empty($count['CNT']) ? $count['CNT'] : 0; } public static function getSharedMailboxesIds() { $mailboxesIds = static::getBaseQueryForSharedMailboxes() ->addSelect('MAILBOX_ID') ->addGroup('MAILBOX_ID') ->exec() ->fetchAll(); return array_map('intval', array_column($mailboxesIds, 'MAILBOX_ID')); } public static function getUserIdsWithAccessToMailbox($mailboxId) { $userCodes = MailboxAccessTable::query() ->addSelect('ACCESS_CODE') ->where('MAILBOX_ID', $mailboxId) ->whereLike('ACCESS_CODE', 'U%') ->exec() ->fetchAll(); $results = []; foreach ($userCodes as $userAccessCode) { // @TODO: departments if (preg_match('#U[0-9]+#', $userAccessCode['ACCESS_CODE']) === 1) { $results[] = mb_substr($userAccessCode['ACCESS_CODE'], 1); } } return $results; } /** * @return \Bitrix\Mail\Internals\EO_MailboxAccess_Query|Query * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\SystemException */ private static function getBaseQueryForSharedMailboxes() { $helper = MailboxAccessTable::getEntity()->getConnection()->getSqlHelper(); return MailboxAccessTable::query() ->registerRuntimeField('', new ReferenceField('ref', MailboxTable::class, ['=this.MAILBOX_ID' => 'ref.ID'], ['join_type' => 'INNER'])) ->where(new ExpressionField( 'ac', $helper->getConcatFunction("'U'", '%s'), 'ref.USER_ID'), '!=', new Column('ACCESS_CODE')) ->where('ref.ACTIVE', 'Y') ->where('ref.LID', SITE_ID); } }