12 $event = new \Bitrix\Main\Event(
"pull",
"onGetMobileCounterTypes");
15 foreach ($event->getResults() as $eventResult)
17 if ($eventResult->getType() != \
Bitrix\Main\EventResult::SUCCESS)
22 $result = $eventResult->getParameters();
23 if (!is_array($types))
28 foreach ($result as $type => $config)
30 $config[
'TYPE'] = $eventResult->getModuleId().
'_'.$type;
31 $types[$eventResult->getModuleId().
'_'.$type] = $config;
38 public static function get($userId =
null)
40 if (is_null($userId) && is_object(
$GLOBALS[
'USER']))
45 $userId = intval($userId);
53 if (IsModuleInstalled(
'intranet'))
55 if (\
Bitrix\Main\Loader::includeModule(
'im'))
57 $siteId = \Bitrix\Im\User::getInstance($userId)->isExtranet()?
'ex':
's1';
66 $siteId = \Bitrix\Main\Context::getCurrent()->getSite();
73 $event = new \Bitrix\Main\Event(
"pull",
"onGetMobileCounter", array(
81 foreach ($event->getResults() as $eventResult)
83 if ($eventResult->getType() != \
Bitrix\Main\EventResult::SUCCESS)
88 $result = $eventResult->getParameters();
90 $type = $eventResult->getModuleId().
'_'.$result[
'TYPE'];
91 if ($typeStatus[$type] ===
false)
96 if (intval($result[
'COUNTER']) > 0)
98 $counter += $result[
'COUNTER'];
107 if (is_null($userId) && is_object(
$GLOBALS[
'USER']))
109 $userId =
$GLOBALS[
'USER']->getId();
112 $userId = intval($userId);
120 foreach (self::getTypes() as $type => $config)
122 $types[$type] = $config[
'DEFAULT'];
125 $options = \CUserOptions::GetOption(
'pull',
'mobileCounterType', Array(), $userId);
126 foreach ($options as $type => $default)
128 $types[$type] = $default;
139 public static function setConfig($config, $userId =
null)
141 if (!is_array($config))
146 if (is_null($userId) && is_object(
$GLOBALS[
'USER']))
148 $userId =
$GLOBALS[
'USER']->getId();
150 $userId = intval($userId);
159 foreach ($config as $type => $status)
161 if (!isset($types[$type]))
165 $types[$type] = (bool)$status;
171 \CUserOptions::SetOption(
'pull',
'mobileCounterType', $types,
false, $userId);
177 public static function send($userId =
null, $appId = self::MOBILE_APP)
179 if (is_null($userId) && is_object(
$GLOBALS[
'USER']))
181 $userId =
$GLOBALS[
'USER']->getId();
184 $userId = intval($userId);
190 \Bitrix\Pull\Push::add($userId, Array(
191 'module_id' =>
'pull',
192 'push' => Array(
'badge' =>
'Y')