Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
sharedmailboxesmanager.php
1
<?php
2
namespace
Bitrix\Mail\Helper\Mailbox
;
3
4
use
Bitrix\Mail\Internals\MailboxAccessTable
;
5
use
Bitrix\Mail\MailboxTable
;
6
use Bitrix\Main\Entity\Query\Filter\Expression\Column;
7
use Bitrix\Main\Entity\ReferenceField;
8
use
Bitrix\Main\ORM\Fields\ExpressionField
;
9
use
Bitrix\Main\ORM\Query\Query
;
10
11
class
SharedMailboxesManager
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();
60
return
MailboxAccessTable::query
()
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
}
Bitrix\Mail\Helper\Mailbox\SharedMailboxesManager
Definition
sharedmailboxesmanager.php:12
Bitrix\Mail\Helper\Mailbox\SharedMailboxesManager\getSharedMailboxesCount
static getSharedMailboxesCount()
Definition
sharedmailboxesmanager.php:13
Bitrix\Mail\Helper\Mailbox\SharedMailboxesManager\getUserIdsWithAccessToMailbox
static getUserIdsWithAccessToMailbox($mailboxId)
Definition
sharedmailboxesmanager.php:32
Bitrix\Mail\Helper\Mailbox\SharedMailboxesManager\getSharedMailboxesIds
static getSharedMailboxesIds()
Definition
sharedmailboxesmanager.php:22
Bitrix\Mail\Internals\MailboxAccessTable
Definition
mailboxaccess.php:24
Bitrix\Mail\MailboxTable
Definition
mailbox.php:28
Bitrix\Main\ORM\Data\DataManager\query
static query()
Definition
datamanager.php:559
Bitrix\Main\ORM\Data\DataManager\getEntity
static getEntity()
Definition
datamanager.php:78
Bitrix\Main\ORM\Fields\ExpressionField
Definition
expressionfield.php:25
Bitrix\Main\ORM\Query\Query
Definition
query.php:118
Bitrix\Mail\Helper\Mailbox
Definition
imap.php:3
modules
mail
lib
helper
mailbox
sharedmailboxesmanager.php
Создано системой
1.10.0