Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
duration.php
1<?php
9
11
14
15Loc::loadMessages(__FILE__);
16
22{
24 private $letter;
25
27 private $durationCountBased;
28
30 private $durationDateBased;
31
37 public function __construct(Entity\Letter $letter)
38 {
39 $this->letter = $letter;
40 $this->durationCountBased = new DurationCountBased($letter->getMessage());
41 $this->durationDateBased = new DurationDateBased($letter);
42 }
43
49 public function getDate()
50 {
51 $date = new DateTime;
52 $date->add($this->getInterval() . ' seconds');
53 return $date;
54 }
55
61 protected function getCount()
62 {
63 return $this->letter->getCounter()->getUnsent();
64 }
65
71 public function getInterval()
72 {
73 $count = $this->getCount();
74 $interval = $this->durationCountBased->getInterval($count);
75 if (!$interval)
76 {
77 $interval = $this->durationDateBased->getInterval($count);
78 }
79
80 return $interval;
81 }
82
88 public function getFormatted()
89 {
90 return $this->format($this->getDate());
91 }
92
98 public static function getFormattedMinimalInterval()
99 {
100 return Loc::getMessage('SENDER_DISPATCH_DURATION_LESS_HOUR');
101 }
102
108 public static function getFormattedMaximalInterval()
109 {
110 return Loc::getMessage('SENDER_DISPATCH_DURATION_MORE_3_DAYS');
111 }
112
118 public static function getMinimalInterval()
119 {
120 return 3600;
121 }
122
128 public static function getMaximalInterval()
129 {
130 return 3600 * 24 * 3;
131 }
132
138 public static function getWarnInterval()
139 {
140 return self::getMinimalInterval() * 10;
141 }
142
148 public function getFormattedInterval()
149 {
150 if ($this->getInterval() < self::getMinimalInterval())
151 {
153 }
154 elseif ($this->getInterval() > self::getMaximalInterval())
155 {
157 }
158 else
159 {
160 $formatted = \FormatDate('Hdiff', $this->getDate());
161 if (mb_substr($formatted, 0, 1) === '-')
162 {
163 $formatted = mb_substr($formatted, 1);
164 }
165
166 return $formatted;
167 }
168 }
169
176 public function format(DateTime $dateTime = null)
177 {
178 if (!$dateTime)
179 {
180 return '';
181 }
182
183 return \FormatDate('d F, H:i', $dateTime);
184 }
185}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
add($interval)
Definition date.php:145
__construct(Entity\Letter $letter)
Definition duration.php:37
format(DateTime $dateTime=null)
Definition duration.php:176