Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mobilecounter.php
1<?php
2namespace Bitrix\Pull;
3
5{
6 const MOBILE_APP = 'Bitrix24';
7
8 public static function getTypes()
9 {
10 $types = Array();
11
12 $event = new \Bitrix\Main\Event("pull", "onGetMobileCounterTypes");
13 $event->send();
14
15 foreach ($event->getResults() as $eventResult)
16 {
17 if ($eventResult->getType() != \Bitrix\Main\EventResult::SUCCESS)
18 {
19 continue;
20 }
21
22 $result = $eventResult->getParameters();
23 if (!is_array($types))
24 {
25 continue;
26 }
27
28 foreach ($result as $type => $config)
29 {
30 $config['TYPE'] = $eventResult->getModuleId().'_'.$type;
31 $types[$eventResult->getModuleId().'_'.$type] = $config;
32 }
33 }
34
35 return $types;
36 }
37
38 public static function get($userId = null)
39 {
40 if (is_null($userId) && is_object($GLOBALS['USER']))
41 {
42 $userId = $GLOBALS['USER']->getId();
43 }
44
45 $userId = intval($userId);
46 if (!$userId)
47 {
48 return false;
49 }
50
51 $counter = 0;
52
53 if (IsModuleInstalled('intranet'))
54 {
55 if (\Bitrix\Main\Loader::includeModule('im')) // TODO remove IM include!
56 {
57 $siteId = \Bitrix\Im\User::getInstance($userId)->isExtranet()? 'ex': 's1';
58 }
59 else
60 {
61 $siteId = 's1';
62 }
63 }
64 else
65 {
66 $siteId = \Bitrix\Main\Context::getCurrent()->getSite();
67 if (!$siteId)
68 {
69 $siteId = 's1';
70 }
71 }
72
73 $event = new \Bitrix\Main\Event("pull", "onGetMobileCounter", array(
74 'USER_ID' => $userId,
75 'SITE_ID' => $siteId
76 ));
77 $event->send();
78
79 $typeStatus = self::getConfig($userId);
80
81 foreach ($event->getResults() as $eventResult)
82 {
83 if ($eventResult->getType() != \Bitrix\Main\EventResult::SUCCESS)
84 {
85 continue;
86 }
87
88 $result = $eventResult->getParameters();
89
90 $type = $eventResult->getModuleId().'_'.$result['TYPE'];
91 if ($typeStatus[$type] === false)
92 {
93 continue;
94 }
95
96 if (intval($result['COUNTER']) > 0)
97 {
98 $counter += $result['COUNTER'];
99 }
100 }
101
102 return $counter;
103 }
104
105 public static function getConfig($userId = null)
106 {
107 if (is_null($userId) && is_object($GLOBALS['USER']))
108 {
109 $userId = $GLOBALS['USER']->getId();
110 }
111
112 $userId = intval($userId);
113 if ($userId <= 0)
114 {
115 return false;
116 }
117
118 $types = Array();
119
120 foreach (self::getTypes() as $type => $config)
121 {
122 $types[$type] = $config['DEFAULT'];
123 }
124
125 $options = \CUserOptions::GetOption('pull', 'mobileCounterType', Array(), $userId);
126 foreach ($options as $type => $default)
127 {
128 $types[$type] = $default;
129 }
130
131 return $types;
132 }
133
134 public static function setConfigType($type, $status, $userId = null)
135 {
136 return self::setConfig(Array($type => $status), $userId);
137 }
138
139 public static function setConfig($config, $userId = null)
140 {
141 if (!is_array($config))
142 {
143 return false;
144 }
145
146 if (is_null($userId) && is_object($GLOBALS['USER']))
147 {
148 $userId = $GLOBALS['USER']->getId();
149 }
150 $userId = intval($userId);
151 if ($userId <= 0)
152 {
153 return false;
154 }
155
156 $needUpdate = false;
157 $types = self::getConfig($userId);
158
159 foreach ($config as $type => $status)
160 {
161 if (!isset($types[$type]))
162 {
163 continue;
164 }
165 $types[$type] = (bool)$status;
166 $needUpdate = true;
167 }
168
169 if ($needUpdate)
170 {
171 \CUserOptions::SetOption('pull', 'mobileCounterType', $types, false, $userId);
172 }
173
174 return true;
175 }
176
177 public static function send($userId = null, $appId = self::MOBILE_APP)
178 {
179 if (is_null($userId) && is_object($GLOBALS['USER']))
180 {
181 $userId = $GLOBALS['USER']->getId();
182 }
183
184 $userId = intval($userId);
185 if ($userId <= 0)
186 {
187 return false;
188 }
189
190 \Bitrix\Pull\Push::add($userId, Array(
191 'module_id' => 'pull',
192 'push' => Array('badge' => 'Y')
193 ));
194
195 return true;
196 }
197
198 public static function onSonetLogCounterClear($counterType = '', $timestamp = 0)
199 {
200 $userId = is_object($GLOBALS['USER'])? intval($GLOBALS['USER']->getId()): 0;
201
202 if (
203 $userId <= 0
204 || $counterType != '**'
205 )
206 {
207 return false;
208 }
209
210 self::send($userId);
211
212 return true;
213 }
214}
static setConfig($config, $userId=null)
static setConfigType($type, $status, $userId=null)
static send($userId=null, $appId=self::MOBILE_APP)
static getConfig($userId=null)
static onSonetLogCounterClear($counterType='', $timestamp=0)
$GLOBALS['____1444769544']
Definition license.php:1