1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
remind.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Calendar\Core\Event\Properties;
4
5
use Bitrix\Calendar\Core\Base\BaseProperty;
6
use Bitrix\Calendar\Core\Base\Date;
7
use Bitrix\Calendar\Core\Event\Tools\Dictionary;
8
use Bitrix\Calendar\Core\Event\Tools\PropertyException;
9
10
class
Remind
extends
BaseProperty
11
{
12
public
const
UNIT_SECONDS
=
'seconds'
;
13
public
const
UNIT_MINUTES
=
'minutes'
;
14
public
const
UNIT_HOURS
=
'hour'
;
15
public
const
UNIT_DAYS
=
'day'
;
16
public
const
UNIT_WEEKS
=
'weeks'
;
17
public
const
UNIT_MONTHS
=
'months'
;
18
public
const
UNIT_YEARS
=
'years'
;
19
public
const
UNIT_DATES
=
'date'
;
20
public
const
UNIT_DAY_BEFORE
=
'daybefore'
;
21
protected
const
MINUTE_PER_DAY
= 1440;
22
26
private
string
$method;
30
private
?
int
$time =
null
;
34
private
?
string
$units =
null
;
38
private
?
Date
$specificTime =
null
;
42
protected
?
Date
$eventStart
=
null
;
46
private
?
int
$daysBefore =
null
;
47
48
public
function
__construct
(
string
$method =
'popup'
)
49
{
50
$this->method = $method;
51
}
52
56
public
function
getFields
():
array
57
{
58
return
[
59
'method'
=>
$this->method
,
60
'time'
=>
$this->time
,
61
'units'
=> $this->units,
62
'specificTime'
=> $this->specificTime ??
null
,
63
'eventStart'
=> $this->eventStart ??
null
,
64
'daysBefore'
=> $this->daysBefore ?? null
65
];
66
}
67
72
public
function
toString
(): string
73
{
74
if
($this->specificTime || $this->eventStart)
75
{
76
return
(
string
)$this->
getSpecificTime
();
77
}
78
79
return
''
;
80
}
81
87
public
function
setTimeBeforeEvent
(
int
$time = 15,
string
$units = self::UNIT_MINUTES):
Remind
88
{
89
$this->time = $time;
90
$this->units = $units;
91
92
return
$this;
93
}
94
99
public
function
setSpecificTime
(
Date
$specificTime):
Remind
100
{
101
$this->specificTime = $specificTime;
102
103
return
$this;
104
}
105
106
public
function
setDaysBefore
(
int
$daysBefore):
Remind
107
{
108
$this->daysBefore = $daysBefore;
109
110
return
$this;
111
}
112
117
public
function
getSpecificTime
():
Date
118
{
119
if
(
120
$this->specificTime ===
null
121
&& $this->time !==
null
122
&& $this->units
123
&& $this->eventStart !==
null
124
)
125
{
126
return
(clone $this->eventStart)->sub(
"{$this->time} {$this->units}"
);
127
}
128
129
if
($this->specificTime)
130
{
131
return
$this->specificTime;
132
}
133
134
throw
new
PropertyException
(
'It is impossible to perform this operation. You should set property $eventStart or $specificTime'
);
135
}
136
141
public
function
setEventStart
(
Date
$eventStart
):
Remind
142
{
143
$this->eventStart =
$eventStart
;
144
145
return
$this;
146
}
147
151
public
function
isBeforeEventStart
(): bool
152
{
153
if
($this->checkSpecificTime())
154
{
155
try
156
{
157
return
$this->
getSpecificTime
()->getTimestamp() <= $this->eventStart->getTimestamp();
158
}
159
catch
(
PropertyException
$e)
160
{
161
return
false
;
162
}
163
}
164
165
return
false
;
166
}
167
173
public
static
function
calculateDayBeforeToMinute
(
int
$dayBefore,
int
$minute): int
174
{
175
return
($dayBefore * self::MINUTE_PER_DAY) - $minute;
176
}
177
181
private
function
checkSpecificTime(): bool
182
{
183
return
$this->specificTime ||
$this->eventStart
;
184
}
185
189
public
function
getTimeBeforeStartInMinutes
(): int
190
{
191
if
(!$this->checkSpecificTime())
192
{
193
return
0;
194
}
195
196
try
197
{
198
$delta
= $this->eventStart->getTimestamp() - $this->
getSpecificTime
()->getTimestamp();
199
200
return
$delta
/ 60;
201
}
202
catch
(
PropertyException
$e)
203
{
204
return
0;
205
}
206
}
207
211
public
function
getRank
(): int
212
{
213
$rank = 0;
214
if
(!empty($this->daysBefore))
215
{
216
$rank = 100;
217
}
218
elseif
(!empty($this->specificTime))
219
{
220
$rank = 10;
221
}
222
elseif
(!empty($this->units))
223
{
224
$rankMap = [
225
self::UNIT_SECONDS => 1,
226
self::UNIT_MINUTES => 2,
227
self::UNIT_HOURS => 3,
228
self::UNIT_DAYS => 4,
229
self::UNIT_WEEKS => 5,
230
self::UNIT_MONTHS => 6,
231
self::UNIT_YEARS => 7,
232
];
233
$rank = $rankMap[$this->units] ?? 0;
234
}
235
236
return
$rank;
237
}
238
242
public
function
getMethod
(): string
243
{
244
return
$this->method
;
245
}
246
250
public
function
getTime
(): ?int
251
{
252
return
$this->time ??
null
;
253
}
254
258
public
function
getUnits
(): ?string
259
{
260
return
$this->units ??
null
;
261
}
262
266
public
function
getDaysBefore
(): ?int
267
{
268
return
$this->daysBefore ??
null
;
269
}
270
274
public
function
getEventStart
(): ?
Date
275
{
276
return
isset($this->eventStart)
277
? (clone
$this->eventStart
)
278
: null
279
;
280
}
281
287
public
function
getTimeOffset
(): int
288
{
289
$time = $this->
getSpecificTime
();
290
return
60 * intval($time->format(
'H'
))
291
+ intval($time->format(
'i'
));
292
}
293
297
public
function
isSimpleType
(): bool
298
{
299
return
!empty($this->units);
300
}
301
}
Bitrix\Calendar\Core\Base\BaseProperty
Определения
baseproperty.php:6
Bitrix\Calendar\Core\Event\Properties\Remind
Определения
remind.php:11
Bitrix\Calendar\Core\Event\Properties\Remind\UNIT_MONTHS
const UNIT_MONTHS
Определения
remind.php:17
Bitrix\Calendar\Core\Event\Properties\Remind\UNIT_DAYS
const UNIT_DAYS
Определения
remind.php:15
Bitrix\Calendar\Core\Event\Properties\Remind\setSpecificTime
setSpecificTime(Date $specificTime)
Определения
remind.php:99
Bitrix\Calendar\Core\Event\Properties\Remind\setTimeBeforeEvent
setTimeBeforeEvent(int $time=15, string $units=self::UNIT_MINUTES)
Определения
remind.php:87
Bitrix\Calendar\Core\Event\Properties\Remind\__construct
__construct(string $method='popup')
Определения
remind.php:48
Bitrix\Calendar\Core\Event\Properties\Remind\MINUTE_PER_DAY
const MINUTE_PER_DAY
Определения
remind.php:21
Bitrix\Calendar\Core\Event\Properties\Remind\getDaysBefore
getDaysBefore()
Определения
remind.php:266
Bitrix\Calendar\Core\Event\Properties\Remind\getSpecificTime
getSpecificTime()
Определения
remind.php:117
Bitrix\Calendar\Core\Event\Properties\Remind\toString
toString()
Определения
remind.php:72
Bitrix\Calendar\Core\Event\Properties\Remind\getTime
getTime()
Определения
remind.php:250
Bitrix\Calendar\Core\Event\Properties\Remind\getEventStart
getEventStart()
Определения
remind.php:274
Bitrix\Calendar\Core\Event\Properties\Remind\$eventStart
Date $eventStart
Определения
remind.php:42
Bitrix\Calendar\Core\Event\Properties\Remind\UNIT_DAY_BEFORE
const UNIT_DAY_BEFORE
Определения
remind.php:20
Bitrix\Calendar\Core\Event\Properties\Remind\calculateDayBeforeToMinute
static calculateDayBeforeToMinute(int $dayBefore, int $minute)
Определения
remind.php:173
Bitrix\Calendar\Core\Event\Properties\Remind\getUnits
getUnits()
Определения
remind.php:258
Bitrix\Calendar\Core\Event\Properties\Remind\setEventStart
setEventStart(Date $eventStart)
Определения
remind.php:141
Bitrix\Calendar\Core\Event\Properties\Remind\UNIT_SECONDS
const UNIT_SECONDS
Определения
remind.php:12
Bitrix\Calendar\Core\Event\Properties\Remind\UNIT_HOURS
const UNIT_HOURS
Определения
remind.php:14
Bitrix\Calendar\Core\Event\Properties\Remind\getTimeOffset
getTimeOffset()
Определения
remind.php:287
Bitrix\Calendar\Core\Event\Properties\Remind\UNIT_WEEKS
const UNIT_WEEKS
Определения
remind.php:16
Bitrix\Calendar\Core\Event\Properties\Remind\setDaysBefore
setDaysBefore(int $daysBefore)
Определения
remind.php:106
Bitrix\Calendar\Core\Event\Properties\Remind\UNIT_YEARS
const UNIT_YEARS
Определения
remind.php:18
Bitrix\Calendar\Core\Event\Properties\Remind\getRank
getRank()
Определения
remind.php:211
Bitrix\Calendar\Core\Event\Properties\Remind\getTimeBeforeStartInMinutes
getTimeBeforeStartInMinutes()
Определения
remind.php:189
Bitrix\Calendar\Core\Event\Properties\Remind\UNIT_MINUTES
const UNIT_MINUTES
Определения
remind.php:13
Bitrix\Calendar\Core\Event\Properties\Remind\isBeforeEventStart
isBeforeEventStart()
Определения
remind.php:151
Bitrix\Calendar\Core\Event\Properties\Remind\getMethod
getMethod()
Определения
remind.php:242
Bitrix\Calendar\Core\Event\Properties\Remind\isSimpleType
isSimpleType()
Определения
remind.php:297
Bitrix\Calendar\Core\Event\Properties\Remind\UNIT_DATES
const UNIT_DATES
Определения
remind.php:19
Bitrix\Calendar\Core\Event\Properties\Remind\getFields
getFields()
Определения
remind.php:56
Bitrix\Calendar\Core\Event\Tools\PropertyException
Определения
propertyexception.php:6
Bitrix\Main\Type\Date
Определения
date.php:9
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$time
$time
Определения
payment.php:61
$delta
$delta
Определения
prolog_main_admin.php:363
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$method
$method
Определения
index.php:27
bitrix
modules
calendar
lib
core
event
properties
remind.php
Создано системой
1.14.0