Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
push.php
1<?php
2namespace Bitrix\Pull;
3
4class Push
5{
6 static $types = null;
7 static $config = array();
8
9 public static function add($users, $parameters)
10 {
11 unset($parameters['command']);
12 unset($parameters['params']);
13 return \Bitrix\Pull\Event::add($users, $parameters);
14 }
15
16 public static function send()
17 {
18 return \Bitrix\Pull\Event::send();
19 }
20
21 public static function getTypes()
22 {
23 if (is_array(self::$types))
24 {
25 return self::$types;
26 }
27
28 if (!\Bitrix\Main\Loader::includeModule('im'))
29 {
30 return Array();
31 }
32
33 $notifySchema = \CIMNotifySchema::GetNotifySchema();
34
35 $result = Array();
36 foreach ($notifySchema as $moduleId => $module)
37 {
38 if ($module['NAME'] == '')
39 {
40 $info = \CModule::CreateModuleObject($moduleId);
41 $name= $info->MODULE_NAME;
42 }
43 else
44 {
45 $name = $module['NAME'];
46 }
47
48 $types = Array();
49 foreach ($module['NOTIFY'] as $notifyType => $notifyConfig)
50 {
51 if (!$notifyConfig['PUSH'] && $notifyConfig['DISABLED']['PUSH'])
52 {
53 continue;
54 }
55 $types[$notifyType] = Array(
56 'NAME' => $notifyConfig['NAME'],
57 'TYPE' => $notifyType,
58 'DISABLED' => (bool)$notifyConfig['DISABLED']['PUSH'],
59 'DEFAULT' => (bool)$notifyConfig['PUSH'],
60 );
61 }
62 if (empty($types))
63 {
64 continue;
65 }
66
67 $result[$moduleId] = Array(
68 'NAME' => $name,
69 'MODULE_ID' => $moduleId,
70 'TYPES' => $types
71 );
72 }
73
74 self::$types = $result;
75
76 return $result;
77 }
78
79 public static function getConfig($userId = null)
80 {
81 if (!\Bitrix\Main\Loader::includeModule('im'))
82 {
83 return Array();
84 }
85
86 if (is_null($userId) && is_object($GLOBALS['USER']))
87 {
88 $userId = $GLOBALS['USER']->getId();
89 }
90
91 $userId = intval($userId);
92 if (!$userId)
93 {
94 return false;
95 }
96
97 if (isset(self::$config[$userId]))
98 {
99 return self::$config[$userId];
100 }
101
102 $pushDisabled = !\Bitrix\Pull\Push::getStatus($userId);
103
104 $userOptions = \CIMSettings::Get($userId)[\CIMSettings::NOTIFY] ?? [];
105
106 $result = Array();
107 foreach ($userOptions as $optionId => $optionValue)
108 {
109 list($clientId, $moduleId, $type) = explode('|', $optionId);
110 if ($clientId != \CIMSettings::CLIENT_PUSH)
111 {
112 continue;
113 }
114
115 $result[$moduleId][$type] = (bool)$optionValue;
116 }
117
118 $notifySchema = \CIMNotifySchema::GetNotifySchema();
119
120 foreach ($notifySchema as $moduleId => $module)
121 {
122 foreach ($module['NOTIFY'] as $notifyType => $notifyConfig)
123 {
124 if ($pushDisabled)
125 {
126 $result[$moduleId][$notifyType] = false;
127 continue;
128 }
129
130 if (!$notifyConfig['PUSH'] && $notifyConfig['DISABLED']['PUSH'])
131 {
132 continue;
133 }
134
135 if (!isset($result[$moduleId][$notifyType]) || $notifyConfig['DISABLED']['PUSH'])
136 {
137 $result[$moduleId][$notifyType] = (bool)$notifyConfig['PUSH'];
138 }
139 }
140 }
141
142 self::$config[$userId] = $result;
143
144 return $result;
145 }
146
147 public static function setConfig($config, $userId = null)
148 {
149 if (!\Bitrix\Main\Loader::includeModule('im'))
150 {
151 return false;
152 }
153
154 if (!is_array($config))
155 {
156 return false;
157 }
158
159 if (is_null($userId) && is_object($GLOBALS['USER']))
160 {
161 $userId = $GLOBALS['USER']->getId();
162 }
163 $userId = intval($userId);
164 if ($userId <= 0)
165 {
166 return false;
167 }
168
169 $types = self::getTypes();
170 $userConfig = self::getConfig($userId);
171 $userOptions = \CIMSettings::Get($userId)[\CIMSettings::NOTIFY] ?? [];
172
173 $needUpdate = false;
174 foreach ($types as $moduleId => $module)
175 {
176 foreach ($module['TYPES'] as $typeId => $type)
177 {
178 if (isset($config[$moduleId][$typeId]))
179 {
180 $needUpdate = true;
181 $userConfig[$moduleId][$typeId] = (bool)$config[$moduleId][$typeId];
182 }
183 if ($type['DEFAULT'] == $userConfig[$moduleId][$typeId])
184 {
185 unset($userOptions['push|'.$moduleId.'|'.$typeId]);
186 }
187 else
188 {
189 $userOptions['push|'.$moduleId.'|'.$typeId] = $userConfig[$moduleId][$typeId];
190 }
191 }
192 }
193
194 if ($needUpdate)
195 {
196 \CIMSettings::Set(\CIMSettings::NOTIFY, $userOptions, $userId);
197 \CIMSettings::ClearCache($userId);
198 unset(self::$config[$userId]);
199 }
200
201 return true;
202 }
203
204 public static function setConfigTypeStatus($moduleId, $typeId, $status, $userId = null)
205 {
206 return self::setConfig(Array($moduleId => Array($typeId => $status)), $userId);
207 }
208
209 public static function getConfigTypeStatus($moduleId, $typeId, $userId = null)
210 {
211 $config = self::getConfig($userId);
212 return isset($config[$moduleId][$typeId])? $config[$moduleId][$typeId]: true;
213 }
214
215 public static function getStatus($userId = null)
216 {
217 if (!\CPullOptions::GetPushStatus())
218 {
219 return null;
220 }
221
222 if (is_null($userId) && is_object($GLOBALS['USER']))
223 {
224 $userId = $GLOBALS['USER']->getId();
225 }
226 $userId = intval($userId);
227 if (!$userId)
228 {
229 return false;
230 }
231
232 return (bool)\CUserOptions::GetOption('pull', 'push_status', true, $userId);
233 }
234
235 public static function setStatus($status, $userId = null)
236 {
237 if (!\CPullOptions::GetPushStatus())
238 {
239 return null;
240 }
241
242 if (is_null($userId) && is_object($GLOBALS['USER']))
243 {
244 $userId = $GLOBALS['USER']->getId();
245 }
246 $userId = intval($userId);
247 if (!$userId)
248 {
249 return false;
250 }
251
252 $status = $status === false? false: true;
253
254 return (bool)\CUserOptions::SetOption('pull', 'push_status', $status, false, $userId);
255 }
256}
static setConfig($config, $userId=null)
Definition push.php:147
static getTypes()
Definition push.php:21
static setConfigTypeStatus($moduleId, $typeId, $status, $userId=null)
Definition push.php:204
static $config
Definition push.php:7
static getConfigTypeStatus($moduleId, $typeId, $userId=null)
Definition push.php:209
static send()
Definition push.php:16
static getStatus($userId=null)
Definition push.php:215
static $types
Definition push.php:6
static getConfig($userId=null)
Definition push.php:79
static add($users, $parameters)
Definition push.php:9
static setStatus($status, $userId=null)
Definition push.php:235
$GLOBALS['____1444769544']
Definition license.php:1