Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
notification.php
1
<?php
9
namespace
Bitrix\Sender\Integration\Im
;
10
11
use
Bitrix\Main\Loader
;
12
use
Bitrix\Sender\Security
;
13
use
Bitrix\Sender\Entity
;
14
19
class
Notification
20
{
22
protected
$to
= array();
23
25
protected
$message
;
26
32
public
static
function
canUse
()
33
{
34
if
(!Loader::includeModule(
'im'
))
35
{
36
return
false
;
37
}
38
else
39
{
40
return
true
;
41
}
42
}
43
49
public
static
function
create
()
50
{
51
return
new
static
();
52
}
53
60
public
function
setTo
(array $list)
61
{
62
$this->to = $list;
63
return
$this;
64
}
65
72
public
function
addTo
($userId)
73
{
74
$this->to[] = $userId;
75
$this->to = array_unique($this->to);
76
77
return
$this;
78
}
79
85
public
function
toAllAuthors
()
86
{
87
$list = Entity\Letter::getList(array(
88
'select'
=> array(
'CREATED_BY'
),
89
'filter'
=> array(
90
'=MESSAGE_CODE'
,
91
'!=CREATED_BY'
=>
null
92
),
93
'group'
=> array(
'CREATED_BY'
),
94
'cache'
=> array(
'ttl'
=> 3600),
95
));
96
foreach
($list as $item)
97
{
98
$this->
addTo
($item[
'CREATED_BY'
]);
99
}
100
101
return
$this;
102
}
103
109
public
function
toCurrentUser
()
110
{
111
$this->
addTo
(Security\User::current()->getId());
112
return
$this;
113
}
114
121
public
function
withMessage
(
$message
)
122
{
123
$this->message =
$message
;
124
return
$this;
125
}
126
132
public
function
send
()
133
{
134
if
(!static::canUse())
135
{
136
return
;
137
}
138
139
if
(count($this->to) === 0 || !$this->message)
140
{
141
return
;
142
}
143
144
foreach
($this->to as $userId)
145
{
146
$fields = array(
147
"TO_USER_ID"
=> $userId,
148
"FROM_USER_ID"
=> 0,
149
"NOTIFY_TYPE"
=> IM_NOTIFY_SYSTEM,
150
"NOTIFY_MODULE"
=>
"sender"
,
151
//"NOTIFY_EVENT" => $imNotifyEvent,
152
//"NOTIFY_TAG" => $notifyTag,
153
"NOTIFY_MESSAGE"
=> $this->message
154
);
155
\CIMNotify::Add($fields);
156
}
157
}
158
}
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Sender\Integration\Im\Notification
Definition
notification.php:20
Bitrix\Sender\Integration\Im\Notification\send
send()
Definition
notification.php:132
Bitrix\Sender\Integration\Im\Notification\withMessage
withMessage($message)
Definition
notification.php:121
Bitrix\Sender\Integration\Im\Notification\create
static create()
Definition
notification.php:49
Bitrix\Sender\Integration\Im\Notification\setTo
setTo(array $list)
Definition
notification.php:60
Bitrix\Sender\Integration\Im\Notification\$message
$message
Definition
notification.php:25
Bitrix\Sender\Integration\Im\Notification\toAllAuthors
toAllAuthors()
Definition
notification.php:85
Bitrix\Sender\Integration\Im\Notification\canUse
static canUse()
Definition
notification.php:32
Bitrix\Sender\Integration\Im\Notification\toCurrentUser
toCurrentUser()
Definition
notification.php:109
Bitrix\Sender\Integration\Im\Notification\addTo
addTo($userId)
Definition
notification.php:72
Bitrix\Sender\Integration\Im\Notification\$to
$to
Definition
notification.php:22
Bitrix\Sender\Entity
Definition
ad.php:8
Bitrix\Sender\Integration\Im
Definition
messageim.php:9
Bitrix\Sender\Security
Definition
access.php:3
modules
sender
lib
integration
im
notification.php
Создано системой
1.10.0