Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
recurringeventrules.php
1
<?php
2
3
namespace
Bitrix\Calendar\Core\Event\Properties
;
4
5
6
use
Bitrix\Calendar\Core\Base\Date
;
7
use
Bitrix\Calendar\Core\Base\Property
;
8
use
Bitrix\Calendar\Sync\Google\Helper
;
9
10
class
RecurringEventRules
implements
Property
11
{
12
public
const
FREQUENCY
= [
13
'daily'
=>
'DAILY'
,
14
'weekly'
=>
'WEEKLY'
,
15
'monthly'
=>
'MONTHLY'
,
16
'yearly'
=>
'YEARLY'
,
17
];
18
public
const
FREQUENCY_WEEKLY
=
'WEEKLY'
;
19
public
const
FREQUENCY_DAILY
=
'DAILY'
;
20
public
const
FREQUENCY_MONTHLY
=
'MONTHLY'
;
21
public
const
FREQUENCY_YEARLY
=
'YEARLY'
;
22
26
private
string
$frequency;
30
private
?
int
$count =
null
;
34
private
?
Date
$until =
null
;
38
private
$dateFormat;
42
private
int
$interval;
46
private
?array $byDay = [];
47
52
public
function
__construct
(
string
$frequency,
int
$interval = 1)
53
{
54
$this->frequency = $frequency;
55
$this->interval = $interval;
56
}
57
61
public
function
getFields
(): array
62
{
63
$fields = [];
64
65
$fields[
'frequency'
] = $this->frequency;
66
67
if
($this->count > 0)
68
{
69
$fields[
'count'
] = $this->count;
70
}
71
72
if
(isset($this->until))
73
{
74
$fields[
'until'
] = $this->until->format($this->dateFormat);
75
}
76
77
if
(isset($this->interval))
78
{
79
$fields[
'interval'
] = $this->interval;
80
}
81
82
if
(isset($this->byDay))
83
{
84
$fields[
'byday'
] = $this->byDay;
85
}
86
87
return
$fields;
88
}
89
95
public
function
setUntil
(
Date
$until,
string
$dateFormat =
null
):
RecurringEventRules
96
{
97
$this->until = $until;
98
$this->dateFormat = $dateFormat;
99
100
return
$this;
101
}
102
107
public
function
setCount
(
int
$count):
RecurringEventRules
108
{
109
$this->count = $count;
110
111
return
$this;
112
}
113
117
public
function
toString
(): string
118
{
119
$result =
"FREQ={$this->frequency}"
;
120
121
if
($this->count > 0)
122
{
123
$result .=
",COUNT={$this->count}"
;
124
}
125
126
if
(isset($this->until))
127
{
128
$result .=
",UNTIL={$this->until}"
;
129
}
130
131
if
(isset($this->interval))
132
{
133
$result .=
",INTERVAL={$this->interval}"
;
134
}
135
136
if
(isset($this->byDay) && $this->frequency === self::FREQUENCY_WEEKLY)
137
{
138
$byDayString = implode(
','
,$this->byDay);
139
$result .=
",BYDAY={$byDayString}"
;
140
}
141
142
return
$result;
143
}
144
148
public
function
toArray
(): array
149
{
150
$result = [
'FREQ'
=> $this->frequency];
151
if
($this->count > 0)
152
{
153
$result[
'COUNT'
] = $this->count;
154
}
155
156
if
(isset($this->until))
157
{
158
$result[
'UNTIL'
] = $this->until->toString();
159
}
160
161
if
(isset($this->interval))
162
{
163
$result [
'INTERVAL'
] = $this->interval;
164
}
165
166
if
(isset($this->byDay) && $this->frequency === self::FREQUENCY_WEEKLY)
167
{
168
$result[
'BYDAY'
] = $this->byDay;
169
}
170
171
return
$result;
172
}
173
178
public
function
setInterval
(
int
$interval):
RecurringEventRules
179
{
180
$this->interval = $interval;
181
182
return
$this;
183
}
184
190
public
function
setByDay
(array $byDay):
RecurringEventRules
191
{
192
$this->byDay = $byDay;
193
194
return
$this;
195
}
196
200
public
function
getFrequency
(): string
201
{
202
return
$this->frequency;
203
}
204
208
public
function
getCount
(): ?int
209
{
210
return
$this->count;
211
}
212
216
public
function
getUntil
(): ?
Date
217
{
218
return
$this->until;
219
}
220
224
public
function
getInterval
(): int
225
{
226
return
$this->interval;
227
}
228
232
public
function
getByday
(): array
233
{
234
return
$this->byDay;
235
}
236
240
public
function
hasDay
(): bool
241
{
242
return
($this->frequency === self::FREQUENCY_WEEKLY)
243
&& $this->byDay;
244
}
245
249
public
function
hasCount
(): bool
250
{
251
return
(
bool
)$this->count;
252
}
253
257
public
function
hasUntil
(): bool
258
{
259
return
$this->until !==
null
;
260
}
261
265
public
function
isUntilEndOfTime
(): bool
266
{
267
if
($this->until ===
null
)
268
{
269
return
false
;
270
}
271
272
return
$this->until->format(
'd.m.Y'
) === Helper::END_OF_TIME;
273
}
274
279
public
function
setFrequency
(
string
$frequency):
RecurringEventRules
280
{
281
$this->frequency = $frequency;
282
283
return
$this;
284
}
285
}
Bitrix\Calendar\Core\Base\Date
Definition
date.php:10
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules
Definition
recurringeventrules.php:11
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\FREQUENCY_WEEKLY
const FREQUENCY_WEEKLY
Definition
recurringeventrules.php:18
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\setInterval
setInterval(int $interval)
Definition
recurringeventrules.php:178
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\setByDay
setByDay(array $byDay)
Definition
recurringeventrules.php:190
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\hasCount
hasCount()
Definition
recurringeventrules.php:249
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\getCount
getCount()
Definition
recurringeventrules.php:208
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\setFrequency
setFrequency(string $frequency)
Definition
recurringeventrules.php:279
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\FREQUENCY_MONTHLY
const FREQUENCY_MONTHLY
Definition
recurringeventrules.php:20
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\FREQUENCY_DAILY
const FREQUENCY_DAILY
Definition
recurringeventrules.php:19
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\toString
toString()
Definition
recurringeventrules.php:117
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\getUntil
getUntil()
Definition
recurringeventrules.php:216
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\getInterval
getInterval()
Definition
recurringeventrules.php:224
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\hasDay
hasDay()
Definition
recurringeventrules.php:240
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\toArray
toArray()
Definition
recurringeventrules.php:148
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\hasUntil
hasUntil()
Definition
recurringeventrules.php:257
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\setCount
setCount(int $count)
Definition
recurringeventrules.php:107
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\FREQUENCY_YEARLY
const FREQUENCY_YEARLY
Definition
recurringeventrules.php:21
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\__construct
__construct(string $frequency, int $interval=1)
Definition
recurringeventrules.php:52
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\FREQUENCY
const FREQUENCY
Definition
recurringeventrules.php:12
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\isUntilEndOfTime
isUntilEndOfTime()
Definition
recurringeventrules.php:265
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\getFrequency
getFrequency()
Definition
recurringeventrules.php:200
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\setUntil
setUntil(Date $until, string $dateFormat=null)
Definition
recurringeventrules.php:95
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\getByday
getByday()
Definition
recurringeventrules.php:232
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules\getFields
getFields()
Definition
recurringeventrules.php:61
Bitrix\Calendar\Core\Role\Helper
Definition
helper.php:10
Bitrix\Calendar\Core\Base\Property
Definition
property.php:6
Bitrix\Calendar\Core\Event\Properties
Definition
attendee.php:3
modules
calendar
lib
core
event
properties
recurringeventrules.php
Создано системой
1.10.0