Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
alert.php
1<?php
2
3
5
7
8class Alert
9{
10 private const TRIGGER_START = 'trigger_start';
11 private const TRIGGER_END = 'trigger_end';
12 private const TRIGGER_DATE = 'trigger_date';
13 private $triggerDate;
14 private $triggerInterval;
15 private $triggerMode = self::TRIGGER_DATE;
16 private $message;
17
18 public static function date(Date $date, string $description = null): Alert
19 {
20 return static::getInstance($description)->triggerDate($date);
21 }
22
23 public static function minutesBeforeStart(int $minutes, string $description = null): Alert
24 {
25 $interval = new \DateInterval("PT{$minutes}M");
26 $interval->invert = 1;
27
28 return static::getInstance($description)->triggerAtStart($interval);
29 }
30
31 public static function minutesAfterStart(int $min, string $description = null): Alert
32 {
33 return static::getInstance($description)->triggerAtStart(new \DateInterval("PT{$min}M"));
34 }
35
36 public static function minutesBeforeEnd(int $min, string $description = null): Alert
37 {
38 $interval = new \DateInterval("PT{$min}M");
39 $interval->invert = 1;
40
41 return static::getInstance($description)->triggerAtEnd($interval);
42 }
43
44 public static function minutesAfterEnd(int $min, string $description = null): Alert
45 {
46 return static::getInstance($description)->triggerAtEnd(new \DateInterval("PT{$min}M"));
47 }
48
49 private static function getInstance(array $reminds = [], $description = ''): Alert
50 {
51 return new self($reminds, $description);
52 }
53
54 public function __construct(array $reminds = [], $description = '')
55 {
56 $this->message = $reminds;
57 $this->message = $description;
58 }
59
60 public function getType(): string
61 {
62 return 'VALARM';
63 }
64
65 public function getRequiredProperties(): array
66 {
67 return [
68 'ACTION',
69 'TRIGGER',
70 'DESCRIPTION',
71 ];
72 }
73
74 public function message(string $message): Alert
75 {
76 $this->message = $message;
77
78 return $this;
79 }
80
81 public function triggerDate(Date $triggerAt): Alert
82 {
83 $this->triggerMode = self::TRIGGER_DATE;
84 $this->triggerDate = $triggerAt;
85
86 return $this;
87 }
88
89 public function triggerAtStart(\DateInterval $interval): Alert
90 {
91 $this->triggerMode = self::TRIGGER_START;
92 $this->triggerInterval = $interval;
93
94 return $this;
95 }
96
97 public function triggerAtEnd(\DateInterval $interval): Alert
98 {
99 $this->triggerMode = self::TRIGGER_END;
100 $this->triggerInterval = $interval;
101
102 return $this;
103 }
104
105 protected function setContent(): Content
106 {
107 return Content::getInstance($this->getType())
108 ->textProperty('ACTION', 'DISPLAY')
109 ->textProperty('DESCRIPTION', $this->message)
110 ->property($this->resolveTriggerProperty());
111 }
112
113 private function resolveTriggerProperty()
114 {
115 if ($this->triggerMode === self::TRIGGER_DATE) {
116 return DateTimePropertyType::getInstance(
117 'TRIGGER',
118 $this->triggerDate,
119 true
120 )->addParameter(new Parameter('VALUE', 'DATE-TIME'));
121 }
122
123 $property = LengthPropertyType::getInstance('TRIGGER', $this->triggerInterval);
124
125 if ($this->triggerMode === self::TRIGGER_END) {
126 return $property->addParameter(new Parameter('RELATED', 'END'));
127 }
128
129 return $property;
130 }
131}
textProperty($names, ?string $value, bool $disableEscaping=false)
Definition content.php:48
static getInstance($names, \DateInterval $interval)
triggerAtEnd(\DateInterval $interval)
Definition alert.php:97
triggerDate(Date $triggerAt)
Definition alert.php:81
static minutesBeforeStart(int $minutes, string $description=null)
Definition alert.php:23
static minutesAfterStart(int $min, string $description=null)
Definition alert.php:31
static minutesBeforeEnd(int $min, string $description=null)
Definition alert.php:36
static date(Date $date, string $description=null)
Definition alert.php:18
__construct(array $reminds=[], $description='')
Definition alert.php:54
static minutesAfterEnd(int $min, string $description=null)
Definition alert.php:44
triggerAtStart(\DateInterval $interval)
Definition alert.php:89