Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
template.php
1<?php
2
4
7
8abstract class Template
9{
11 protected bool $asRobotMessage = false;
12 protected bool $enablePush = false;
13
14 public function __construct()
15 {
16 $this->errors = new ErrorCollection();
17 }
18
19 public function formatMessage(array $messageFields): Result
20 {
21 $result = new Result();
22
23 $this->validate();
24 if ($this->errors->isEmpty())
25 {
26 $message = $this->buildMessage($messageFields);
27
28 if ($this->asRobotMessage)
29 {
30 $message['SYSTEM'] = 'N';
31 if (!is_array($message['PARAMS'] ?? null))
32 {
33 $message['PARAMS'] = [];
34 }
35 $message['PARAMS']['IS_ROBOT_MESSAGE'] = 'Y';
36 }
37
38 if ($this->enablePush)
39 {
40 $message['PUSH'] = 'Y';
41 $message['PUSH_MESSAGE'] = $this->buildDescriptionText();
42 }
43
44 $result->setData($message);
45 }
46 else
47 {
48 $result->addErrors($this->errors->getValues());
49 }
50
51 return $result;
52 }
53
54 public function markAsRobotMessage()
55 {
56 $this->asRobotMessage = true;
57 }
58
59 public function enablePushMessage()
60 {
61 $this->enablePush = true;
62 }
63
64 abstract function buildMessage(array $messageFields): array;
65 abstract protected function validate(): void;
66 abstract public function setFields(array $fields): self;
67 abstract public static function getFieldsMap(): array;
68}