Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
baseservice.php
1<?php
2
4
8
9abstract class BaseService implements PushService
10{
11 protected bool $allowEmptyMessage = true;
12 const DEFAULT_EXPIRY = 14400;
13
14 protected function getBatchWithModifier($appMessages = Array(), $modifier = ""): string
15 {
16 $batch = "";
17 if (!is_array($appMessages) || count($appMessages) <= 0)
18 {
19 return $batch;
20 }
21 foreach ($appMessages as $appID => $tokenMessages)
22 {
23 foreach ($tokenMessages as $token => $messages)
24 {
25 foreach ($messages as $messageArray)
26 {
27 if (
28 (!$this->allowEmptyMessage && trim($messageArray["MESSAGE"]) == '')
29 || !static::shouldBeSent($messageArray)
30 )
31 {
32 continue;
33 }
34
35 $message = static::getMessageInstance($token);
36 $id = random_int(1, 10000);
37 $message->setCustomIdentifier($id);
38 $message->setFromArray($messageArray);
39 $message->setCustomProperty('target', md5($messageArray["USER_ID"] . \CMain::GetServerUniqID()));
40
41 if ($batch <> '')
42 {
43 $batch .= ";";
44 }
45
46 $messageBatch = $message->getBatch();
47 if($messageBatch && $messageBatch <> '')
48 {
49 $batch .= $messageBatch;
50 }
51 }
52 }
53 $host = static::getHost();
54 $appModifier = ";tkey={$appID};";
55 if ($host != '')
56 {
57 $appModifier .= "h={$host};";
58 }
59 $batch = $appModifier . $batch;
60 }
61
62 if ($batch == '')
63 {
64 return $batch;
65 }
66
67 return $modifier . $batch;
68 }
69
70 protected static function getGroupedByServiceMode($arMessages): array
71 {
72 $groupedMessages = array();
73 foreach ($arMessages as $keyToken => $messTokenData)
74 {
75 $count = count($messTokenData["messages"]);
76 for ($i = 0; $i < $count; $i++)
77 {
78 $mode = $messTokenData["mode"];
79 $mess = $messTokenData["messages"][$i];
80 $app_id = $mess["APP_ID"];
81 $groupedMessages[$mode][$app_id][$keyToken][] = $mess;
82 }
83 }
84
85 return $groupedMessages;
86 }
87
88 protected static function getGroupedByAppID($arMessages): array
89 {
90 $groupedMessages = array();
91 foreach ($arMessages as $keyToken => $messTokenData)
92 {
93 $count = count($messTokenData["messages"]);
94 for ($i = 0; $i < $count; $i++)
95 {
96 $mode = $arMessages[$keyToken]["mode"];
97 $mess = $messTokenData["messages"][$i];
98 $app_id = $mess["APP_ID"];
99 $groupedMessages[$app_id][$keyToken][] = $mess;
100 }
101 }
102
103 return $groupedMessages;
104 }
105
106 private static function getHost(): string {
107 if (defined("SITE_SERVER_NAME") && SITE_SERVER_NAME)
108 {
109 return SITE_SERVER_NAME;
110 }
111 else
112 {
113 return Option::get("main", "server_name", Context::getCurrent()->getRequest()->getHttpHost());
114 }
115 }
116
117 abstract function getMessageInstance(string $token): BaseMessage;
118 abstract static function shouldBeSent(array $messageRowData): bool;
119 abstract function getBatch(array $messages): string;
120}
static getCurrent()
Definition context.php:241
static shouldBeSent(array $messageRowData)
static getGroupedByAppID($arMessages)
getBatchWithModifier($appMessages=Array(), $modifier="")
static getGroupedByServiceMode($arMessages)
if(!function_exists(__NAMESPACE__.'\\___1034172934'))
Definition license.php:1