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