Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
message.php
1<?php
2
4
6
13final class Message
14{
15 public const TYPE_SHIPMENT_PICKUPED = 'SHIPMENT_PICKUPED';
16
18 private $subject;
19
21 private $body;
22
24 private $status;
25
27 private $type;
28
30 private $currency;
31
33 private $moneyValues = [];
34
36 private $dateValues = [];
37
41 public function getSubject(): ?string
42 {
43 return $this->subject;
44 }
45
49 public function getBody(): ?string
50 {
51 return $this->body;
52 }
53
57 public function getBodyForHtml(): string
58 {
59 $result = htmlspecialcharsbx($this->getBody());
60
61 $moneyValues = $this->getMoneyValues();
62 $currency = $this->getCurrency();
63 if ($moneyValues && $currency)
64 {
65 $result = str_replace(
66 array_keys($moneyValues),
67 array_map(
68 static function ($moneyValue) use ($currency)
69 {
70 return SaleFormatCurrency($moneyValue, $currency);
71 },
72 $this->getMoneyValues()
73 ),
74 $result
75 );
76 }
77
78 $dateValues = $this->getDateValues();
79 if ($dateValues)
80 {
81 $result = str_replace(
82 array_keys($dateValues),
83 array_map(
84 static function ($dateValue)
85 {
86 if (!isset($dateValue['VALUE']) || !isset($dateValue['FORMAT']))
87 {
88 return '';
89 }
90
91 return
92 DateTime::createFromTimestamp((int)$dateValue['VALUE'])
93 ->toUserTime()
94 ->format($dateValue['FORMAT'])
95 ;
96 },
97 $dateValues
98 ),
99 $result
100 );
101 }
102
103 return $result;
104 }
105
109 public function getStatus(): ?Status
110 {
111 return $this->status;
112 }
113
117 public function getType(): ?string
118 {
119 return $this->type;
120 }
121
125 public function getCurrency(): ?string
126 {
127 return $this->currency;
128 }
129
133 public function getMoneyValues(): array
134 {
135 return $this->moneyValues;
136 }
137
141 public function getDateValues(): array
142 {
143 return $this->dateValues;
144 }
145
150 public function setSubject(string $subject): Message
151 {
152 $this->subject = $subject;
153
154 return $this;
155 }
156
161 public function setBody(string $body): Message
162 {
163 $this->body = $body;
164
165 return $this;
166 }
167
172 public function setStatus(Status $status): Message
173 {
174 $this->status = $status;
175
176 return $this;
177 }
178
183 public function setType(string $type): Message
184 {
185 $this->type = $type;
186
187 return $this;
188 }
189
195 public function addMoneyValue(string $key, float $value): Message
196 {
197 $this->moneyValues[$key] = $value;
198
199 return $this;
200 }
201
206 public function setCurrency(string $currency): Message
207 {
208 $this->currency = $currency;
209
210 return $this;
211 }
212
219 public function addDateValue(string $key, int $value, string $format): Message
220 {
221 $this->dateValues[$key] = [
222 'VALUE' => $value,
223 'FORMAT' => $format,
224 ];
225
226 return $this;
227 }
228}
static createFromTimestamp($timestamp)
Definition datetime.php:246
addMoneyValue(string $key, float $value)
Definition message.php:195
addDateValue(string $key, int $value, string $format)
Definition message.php:219