Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
notification.php
1<?php
10
14
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}