Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basemessage.php
1<?php
2
4
8
9abstract class BaseMessage
10{
11 protected array $deviceTokens = [];
12 protected ?string $text = null;
13 protected $category;
14 protected $badge;
15 protected string $sound = "default";
16 protected int $expiryValue = 7200;
17
19 protected $title;
20 public $customProperties = [];
21
22 public function addRecipient($sDeviceToken)
23 {
24 $this->deviceTokens[] = $sDeviceToken;
25 }
26
27 public function getRecipient($nRecipient = 0)
28 {
29 if (!isset($this->deviceTokens[$nRecipient]))
30 {
31 throw new ArgumentException(
32 "No recipient at index '{$nRecipient}'"
33 );
34 }
35
36 return $this->deviceTokens[$nRecipient];
37 }
38
39 public function getRecipients()
40 {
42 }
43
44 public function setText($sText)
45 {
46 $this->text = str_replace("\n", " ", $sText);
47 }
48
49 public function getText()
50 {
51 return $this->text;
52 }
53
54 public function setTitle(string $sTitle): void
55 {
56 $this->title = $sTitle;
57 }
58
59 public function getTitle()
60 {
61 return $this->title;
62 }
63
64 public function setBadge(int $nBadge): void
65 {
66 $this->badge = $nBadge;
67 }
68
69 public function getBadge()
70 {
71 return $this->badge;
72 }
73
74 public function setSound($sSound = 'default')
75 {
76 $this->sound = $sSound;
77 }
78
79 public function getSound()
80 {
81 return $this->sound;
82 }
83
84 public function setCustomProperty($sName, $mValue)
85 {
86 $this->customProperties[trim($sName)] = $mValue;
87 }
88
89 public function getCustomProperty($sName)
90 {
91 if (!array_key_exists($sName, $this->customProperties))
92 {
93 throw new ArgumentException(
94 "No property exists with the specified name '{$sName}'."
95 );
96 }
97
98 return $this->customProperties[$sName];
99 }
100
101 public function setExpiry(int $nExpiryValue)
102 {
103 $this->expiryValue = $nExpiryValue;
104 }
105
106 public function getExpiry()
107 {
108 return $this->expiryValue;
109 }
110
111 public function setCustomIdentifier($mCustomIdentifier)
112 {
113 $this->customIdentifier = $mCustomIdentifier;
114 }
115
116 public function getCustomIdentifier()
117 {
119 }
120
121 abstract function getBatch();
122
126 public function getCategory()
127 {
128 return $this->category;
129 }
130
134 public function setCategory($category)
135 {
136 $this->category = $category;
137 }
138
139 public function setFromArray(array $messageArray): BaseMessage
140 {
141 if (is_string($messageArray["TITLE"]) && $messageArray["TITLE"] != "")
142 {
143 $title = Encoding::convertEncoding($messageArray["TITLE"], SITE_CHARSET, "utf-8");
144 $this->setTitle($title);
145 }
146
147 $this->setSound('');
148 if (is_string($messageArray["MESSAGE"]) && $messageArray["MESSAGE"] != "")
149 {
150 $text = Encoding::convertEncoding($messageArray["MESSAGE"], SITE_CHARSET, "utf-8");
151 $this->setText($text);
152
153 if (is_string($messageArray["SOUND"]) && $messageArray["SOUND"] != "")
154 {
155 $this->setSound($messageArray["SOUND"]);
156 }
157 }
158
159 if (isset($messageArray["CATEGORY"]))
160 {
161 $this->setCategory($messageArray["CATEGORY"]);
162 }
163
164 if (array_key_exists("EXPIRY", $messageArray))
165 {
166 $expiry = (int)$messageArray["EXPIRY"];
167 $this->setExpiry($expiry >= 0 ? $expiry : BaseService::DEFAULT_EXPIRY);
168 }
169
170 if (isset($messageArray["PARAMS"]))
171 {
172 $this->setCustomProperty(
173 'params',
174 (is_array($messageArray["PARAMS"]) ? json_encode($messageArray["PARAMS"]) : $messageArray["PARAMS"])
175 );
176 }
177
178 if (is_array($messageArray["ADVANCED_PARAMS"]))
179 {
180 $messageArray["ADVANCED_PARAMS"] = Encoding::convertEncoding($messageArray["ADVANCED_PARAMS"], SITE_CHARSET, "utf-8");
181 if (array_key_exists("senderMessage", $messageArray["ADVANCED_PARAMS"]))
182 {
183 $this->setText("");
184 }
185
186 foreach ($messageArray["ADVANCED_PARAMS"] as $param => $value)
187 {
188 $this->setCustomProperty($param, $value);
189 }
190 }
191
192 $badge = (int)($messageArray["BADGE"] ?? 0);
193 if ($badge >= 0)
194 {
195 $this->setBadge($badge);
196 }
197 return $this;
198 }
199}
setCustomIdentifier($mCustomIdentifier)