Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
eventbuilder.php
1
<?php
2
3
namespace
Bitrix\Calendar\Core\Builders
;
4
5
use
Bitrix\Calendar\Core\Base\BaseException
;
6
use
Bitrix\Calendar\Core\Base\Date
;
7
use
Bitrix\Calendar\Core\Base\DateTimeZone
;
8
use
Bitrix\Calendar\Core\Event\Event
;
9
use
Bitrix\Calendar\Core\Event\Properties\AttendeeCollection
;
10
use
Bitrix\Calendar\Core\Event\Properties\ExcludedDatesCollection
;
11
use
Bitrix\Calendar\Core\Event\Properties\Location
;
12
use
Bitrix\Calendar\Core\Event\Properties\MeetingDescription
;
13
use
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules
;
14
use
Bitrix\Calendar\Core\Event\Properties\Relations
;
15
use
Bitrix\Calendar\Core\Event\Properties\RemindCollection
;
16
use
Bitrix\Calendar\Core\Role\Helper
;
17
use
Bitrix\Calendar\Core\Role\Role
;
18
use
Bitrix\Calendar\Core\Role\User
;
19
use
Bitrix\Calendar\Core\Section\Section
;
20
use
Bitrix\Calendar\Util
;
21
use
Bitrix\Main\ArgumentException
;
22
use Bitrix\Main\EO_User;
23
use
Bitrix\Main\ObjectException
;
24
use
Bitrix\Main\ObjectPropertyException
;
25
use
Bitrix\Main\SystemException
;
26
use
Bitrix\Main\UserTable
;
27
28
abstract
class
EventBuilder
implements
Builder
29
{
30
private
Event
$event;
31
32
public
function
setBaseEvent
(
Event
$event): self
33
{
34
$this->
event
= $event;
35
36
return
$this;
37
}
38
43
public
function
build
():
Event
44
{
45
return
$this->
getBaseEvent
()
46
->
setId
($this->
getId
())
47
->setParentId($this->
getParentId
())
48
->setName($this->
getName
())
49
->setRecurringRule($this->
getRecurringRule
())
50
->setLocation($this->
getLocation
())
51
->setStart($this->
getStart
())
52
->setStartTimeZone($this->
getStartTimezone
())
53
->setEnd($this->
getEnd
())
54
->setEndTimeZone($this->
getEndTimezone
())
55
->setIsFullDay($this->
getFullDay
())
56
->setAttendeesCollection($this->
getAttendees
())
57
->setRemindCollection($this->
getReminders
())
58
->setSection($this->
getSection
())
59
->setDescription($this->
getDescription
())
60
->setColor($this->
getColor
())
61
->setTransparent($this->
getTransparency
())
62
->setAccessibility($this->
getAccessibility
())
63
->setImportance($this->
getImportance
())
64
->setIsPrivate($this->
getIsPrivate
())
65
->setEventHost($this->
getEventHost
())
66
->setCreator($this->
getCreator
())
67
->setOwner($this->
getOwner
())
68
->setMeetingDescription($this->
getMeetingDescription
())
69
->setVersion($this->
getVersion
())
70
->setCalendarType($this->
getCalendarType
())
71
->setSpecialLabel($this->
getSpecialLabel
())
72
->setUid($this->
getUid
())
73
->setIsActive($this->
isActive
())
74
->setIsDeleted($this->
isDeleted
())
75
->setRecurrenceId($this->
getRecurrenceId
())
76
->setDateCreate($this->
getDateCreate
())
77
->setDateModified($this->
getDateModified
())
78
->setOriginalDateFrom($this->
getOriginalDate
())
79
->setExcludedDateCollection($this->
getExcludedDate
())
80
->setIsMeeting($this->
isMeeting
())
81
->setMeetingStatus($this->
getMeetingStatus
())
82
->setOriginalDateFrom($this->
getOriginalDate
())
83
->setRelations($this->
getRelations
())
84
;
85
}
86
90
protected
function
getBaseEvent
():
Event
91
{
92
if
(empty($this->event))
93
{
94
$this->
event
=
new
Event
();
95
}
96
return
$this->event;
97
}
98
106
protected
function
prepareRecurringRule
($ruleData =
null
): ?
RecurringEventRules
107
{
108
if
(empty($ruleData))
109
{
110
return
null
;
111
}
112
113
if
(is_string($ruleData))
114
{
115
$ruleData = \CCalendarEvent::ParseRRULE($ruleData);
116
}
117
118
if
(
119
isset($ruleData[
'FREQ'
])
120
&& $ruleData[
'FREQ'
] !==
'NONE'
121
)
122
{
123
$rule =
new
RecurringEventRules
($ruleData[
'FREQ'
]);
124
125
if
(isset($ruleData[
'COUNT'
]))
126
{
127
$rule->setCount((
int
)$ruleData[
'COUNT'
]);
128
}
129
130
if
(is_string($ruleData[
'UNTIL'
] ??
null
))
131
{
132
$ruleData[
'UNTIL'
] = \CCalendarEvent::convertDateToCulture($ruleData[
'UNTIL'
]);
133
$rule->setUntil(
new
Date
(
Util::getDateObject
($ruleData[
'UNTIL'
])));
134
}
135
136
if
(isset($ruleData[
'INTERVAL'
]))
137
{
138
$rule->setInterval((
int
)$ruleData[
'INTERVAL'
]);
139
}
140
141
if
(!empty($ruleData[
'BYDAY'
]) && $ruleData[
'FREQ'
] === RecurringEventRules::FREQUENCY_WEEKLY)
142
{
143
if
(
144
is_string($ruleData[
'BYDAY'
])
145
)
146
{
147
$rule->setByDay(explode(
","
, $ruleData[
'BYDAY'
]));
148
}
149
elseif (
150
is_array($ruleData[
'BYDAY'
])
151
)
152
{
153
$rule->setByDay($ruleData[
'BYDAY'
]);
154
}
155
}
156
157
return
$rule;
158
}
159
160
return
null
;
161
}
162
168
protected
function
prepareLocation
($locationData =
''
): ?
Location
169
{
170
if
(!$locationData)
171
{
172
return
null
;
173
}
174
175
if
(is_array($locationData) && isset($locationData[
'NEW'
]))
176
{
177
$location =
new
Location
($locationData[
'NEW'
]);
178
if
(isset($locationData[
'OLD'
]))
179
{
180
$location->setOriginalLocation($locationData[
'OLD'
]);
181
}
182
183
return
$location;
184
}
185
186
if
(is_string($locationData))
187
{
188
return
new
Location
($locationData);
189
}
190
191
return
null
;
192
}
193
199
protected
function
prepareEventHost
(
int
$hostId =
null
): ?
Role
200
{
201
return
$this->
prepareUserInstance
($hostId);
202
}
203
209
protected
function
prepareUserInstance
(
int
$userId): ?
Role
210
{
211
try
212
{
213
return
Helper::getUserRole($userId);
214
}
215
catch
(
BaseException
$e)
216
{}
217
218
return
null
;
219
}
220
230
private
function
getUserEntityObject(
int
$userId): ?EO_User
231
{
232
return
User::$users[$userId] =
UserTable::query
()
233
->setSelect([
'*'
])
234
->whereIn(
'ID'
, $userId)
235
->exec()
236
->fetchObject()
237
;
238
}
239
240
protected
function
fillAttendeeCollection
(
AttendeeCollection
$collection, $hostEventId)
241
{
242
// TODO: implement method
243
}
244
248
abstract
protected
function
getId
(): ?int;
249
253
abstract
protected
function
getParentId
(): ?int;
254
258
abstract
protected
function
getName
(): string;
259
263
abstract
protected
function
getStartTimezone
(): ?
DateTimeZone
;
264
268
abstract
protected
function
getEndTimezone
(): ?
DateTimeZone
;
269
273
abstract
protected
function
getRecurringRule
(): ?
RecurringEventRules
;
274
278
abstract
protected
function
getLocation
(): ?
Location
;
279
283
abstract
protected
function
getStart
():
Date
;
284
288
abstract
protected
function
getEnd
():
Date
;
289
293
abstract
protected
function
getFullDay
(): bool;
294
298
abstract
protected
function
getAttendees
(): ?
AttendeeCollection
;
299
303
abstract
protected
function
getReminders
():
RemindCollection
;
304
308
abstract
protected
function
getDescription
(): ?string;
309
313
abstract
protected
function
getSection
():
Section
;
314
318
abstract
protected
function
getColor
(): ?string;
319
323
abstract
protected
function
getTransparency
(): ?string;
324
328
abstract
protected
function
getImportance
(): ?string;
329
333
abstract
protected
function
getAccessibility
(): ?string;
334
338
abstract
protected
function
getIsPrivate
(): bool;
339
343
abstract
protected
function
getEventHost
(): ?
Role
;
344
348
abstract
protected
function
getCreator
(): ?
Role
;
349
353
abstract
protected
function
getOwner
(): ?
Role
;
354
358
abstract
protected
function
getMeetingDescription
(): ?
MeetingDescription
;
359
363
abstract
protected
function
getVersion
(): int;
364
368
abstract
protected
function
getCalendarType
(): ?string;
369
373
abstract
protected
function
getSpecialLabel
(): ?string;
374
378
abstract
protected
function
getUid
(): ?string;
379
383
abstract
protected
function
isDeleted
(): bool;
384
388
abstract
protected
function
isActive
(): bool;
389
393
abstract
protected
function
getRecurrenceId
(): ?int;
394
398
abstract
protected
function
getOriginalDate
(): ?
Date
;
399
403
abstract
protected
function
getDateCreate
(): ?
Date
;
404
408
abstract
protected
function
getDateModified
(): ?
Date
;
409
413
abstract
protected
function
getExcludedDate
():
ExcludedDatesCollection
;
414
418
abstract
protected
function
isMeeting
(): bool;
419
423
abstract
protected
function
getMeetingStatus
(): ?string;
424
428
abstract
protected
function
getRelations
(): ?
Relations
;
429
435
protected
function
prepareMeetingDescription
($meeting =
null
): ?
MeetingDescription
436
{
437
if
(!isset($meeting))
438
{
439
return
null
;
440
}
441
442
$meeting = is_string($meeting)
443
? unserialize($meeting, [
'allowed_classes'
=>
false
])
444
: $meeting;
445
446
if
($meeting && !empty($meeting[
'HOST_NAME'
]))
447
{
448
return
(
new
MeetingDescription
())
449
->setAllowInvite((
bool
)($meeting[
'ALLOW_INVITE'
] ??
null
))
450
->setReInvite((
bool
)($meeting[
'REINVITE'
] ??
null
))
451
->setHideGuests((
bool
)($meeting[
'HIDE_GUESTS'
] ??
null
))
452
->setHostName($meeting[
'HOST_NAME'
])
453
->setIsNotify((
bool
)($meeting[
'NOTIFY'
] ??
null
))
454
->setMeetingCreator((
int
)($meeting[
'MEETING_CREATOR'
] ??
null
))
455
->setLanguageId($meeting[
'LANGUAGE_ID'
] ??
null
)
456
->setMailFrom($meeting[
'MAIL_FROM'
] ??
null
)
457
->setChatId($meeting[
'CHAT_ID'
] ??
null
)
458
;
459
}
460
461
return
null
;
462
}
463
464
protected
function
prepareRelations
($relations): ?
Relations
465
{
466
if
(!isset($relations))
467
{
468
return
null
;
469
}
470
471
$relations = is_string($relations)
472
? unserialize($relations, [
'allowed_classes'
=>
false
])
473
: $relations
474
;
475
476
if
($relations && !empty($relations[
'COMMENT_XML_ID'
]))
477
{
478
return
(
new
Relations
($relations[
'COMMENT_XML_ID'
]));
479
}
480
481
return
null
;
482
}
483
490
protected
function
prepareExcludedDates
(
string
$dates =
''
):
ExcludedDatesCollection
491
{
492
if
(empty($dates))
493
{
494
return
new
ExcludedDatesCollection
();
495
}
496
497
$collection =
new
ExcludedDatesCollection
();
498
foreach
(explode(
";"
, $dates) as $exDate)
499
{
500
$collection->add($this->
createDateForRecurrence
($exDate));
501
}
502
503
return
$collection;
504
}
505
513
protected
function
createDateForRecurrence
(
string
$date):
Date
514
{
515
if
($date[2] ===
'.'
&& $date[5] ===
'.'
)
516
{
517
return
Date::createDateFromFormat(
518
$date,
519
ExcludedDatesCollection::EXCLUDED_DATE_FORMAT
520
);
521
}
522
523
return
new
Date
(
Util::getDateObject
($date));
524
}
525
}
Bitrix\Calendar\Core\Base\BaseException
Definition
baseexception.php:8
Bitrix\Calendar\Core\Base\Date
Definition
date.php:10
Bitrix\Calendar\Core\Base\DateTimeZone
Definition
datetimezone.php:8
Bitrix\Calendar\Core\Builders\EventBuilder
Definition
eventbuilder.php:29
Bitrix\Calendar\Core\Builders\EventBuilder\getEnd
getEnd()
Bitrix\Calendar\Core\Builders\EventBuilder\getRelations
getRelations()
Bitrix\Calendar\Core\Builders\EventBuilder\prepareEventHost
prepareEventHost(int $hostId=null)
Definition
eventbuilder.php:199
Bitrix\Calendar\Core\Builders\EventBuilder\getEventHost
getEventHost()
Bitrix\Calendar\Core\Builders\EventBuilder\getId
getId()
Bitrix\Calendar\Core\Builders\EventBuilder\prepareLocation
prepareLocation($locationData='')
Definition
eventbuilder.php:168
Bitrix\Calendar\Core\Builders\EventBuilder\getTransparency
getTransparency()
Bitrix\Calendar\Core\Builders\EventBuilder\getRecurrenceId
getRecurrenceId()
Bitrix\Calendar\Core\Builders\EventBuilder\getLocation
getLocation()
Bitrix\Calendar\Core\Builders\EventBuilder\prepareUserInstance
prepareUserInstance(int $userId)
Definition
eventbuilder.php:209
Bitrix\Calendar\Core\Builders\EventBuilder\getDateCreate
getDateCreate()
Bitrix\Calendar\Core\Builders\EventBuilder\getDescription
getDescription()
Bitrix\Calendar\Core\Builders\EventBuilder\getAccessibility
getAccessibility()
Bitrix\Calendar\Core\Builders\EventBuilder\getCalendarType
getCalendarType()
Bitrix\Calendar\Core\Builders\EventBuilder\build
build()
Definition
eventbuilder.php:43
Bitrix\Calendar\Core\Builders\EventBuilder\getBaseEvent
getBaseEvent()
Definition
eventbuilder.php:90
Bitrix\Calendar\Core\Builders\EventBuilder\getName
getName()
Bitrix\Calendar\Core\Builders\EventBuilder\getSpecialLabel
getSpecialLabel()
Bitrix\Calendar\Core\Builders\EventBuilder\setBaseEvent
setBaseEvent(Event $event)
Definition
eventbuilder.php:32
Bitrix\Calendar\Core\Builders\EventBuilder\getFullDay
getFullDay()
Bitrix\Calendar\Core\Builders\EventBuilder\prepareRelations
prepareRelations($relations)
Definition
eventbuilder.php:464
Bitrix\Calendar\Core\Builders\EventBuilder\isMeeting
isMeeting()
Bitrix\Calendar\Core\Builders\EventBuilder\getUid
getUid()
Bitrix\Calendar\Core\Builders\EventBuilder\getMeetingDescription
getMeetingDescription()
Bitrix\Calendar\Core\Builders\EventBuilder\getCreator
getCreator()
Bitrix\Calendar\Core\Builders\EventBuilder\getAttendees
getAttendees()
Bitrix\Calendar\Core\Builders\EventBuilder\getOriginalDate
getOriginalDate()
Bitrix\Calendar\Core\Builders\EventBuilder\prepareMeetingDescription
prepareMeetingDescription($meeting=null)
Definition
eventbuilder.php:435
Bitrix\Calendar\Core\Builders\EventBuilder\createDateForRecurrence
createDateForRecurrence(string $date)
Definition
eventbuilder.php:513
Bitrix\Calendar\Core\Builders\EventBuilder\fillAttendeeCollection
fillAttendeeCollection(AttendeeCollection $collection, $hostEventId)
Definition
eventbuilder.php:240
Bitrix\Calendar\Core\Builders\EventBuilder\prepareRecurringRule
prepareRecurringRule($ruleData=null)
Definition
eventbuilder.php:106
Bitrix\Calendar\Core\Builders\EventBuilder\getReminders
getReminders()
Bitrix\Calendar\Core\Builders\EventBuilder\isActive
isActive()
Bitrix\Calendar\Core\Builders\EventBuilder\getColor
getColor()
Bitrix\Calendar\Core\Builders\EventBuilder\getStart
getStart()
Bitrix\Calendar\Core\Builders\EventBuilder\getSection
getSection()
Bitrix\Calendar\Core\Builders\EventBuilder\getExcludedDate
getExcludedDate()
Bitrix\Calendar\Core\Builders\EventBuilder\getIsPrivate
getIsPrivate()
Bitrix\Calendar\Core\Builders\EventBuilder\getParentId
getParentId()
Bitrix\Calendar\Core\Builders\EventBuilder\getStartTimezone
getStartTimezone()
Bitrix\Calendar\Core\Builders\EventBuilder\getRecurringRule
getRecurringRule()
Bitrix\Calendar\Core\Builders\EventBuilder\prepareExcludedDates
prepareExcludedDates(string $dates='')
Definition
eventbuilder.php:490
Bitrix\Calendar\Core\Builders\EventBuilder\getOwner
getOwner()
Bitrix\Calendar\Core\Builders\EventBuilder\getDateModified
getDateModified()
Bitrix\Calendar\Core\Builders\EventBuilder\isDeleted
isDeleted()
Bitrix\Calendar\Core\Builders\EventBuilder\getMeetingStatus
getMeetingStatus()
Bitrix\Calendar\Core\Builders\EventBuilder\getVersion
getVersion()
Bitrix\Calendar\Core\Builders\EventBuilder\getImportance
getImportance()
Bitrix\Calendar\Core\Builders\EventBuilder\getEndTimezone
getEndTimezone()
Bitrix\Calendar\Core\Event\Event
Definition
event.php:20
Bitrix\Calendar\Core\Event\Event\setId
setId(?int $id)
Definition
event.php:906
Bitrix\Calendar\Core\Event\Properties\AttendeeCollection
Definition
attendeecollection.php:11
Bitrix\Calendar\Core\Event\Properties\ExcludedDatesCollection
Definition
excludeddatescollection.php:10
Bitrix\Calendar\Core\Event\Properties\Location
Definition
location.php:9
Bitrix\Calendar\Core\Event\Properties\MeetingDescription
Definition
meetingdescription.php:9
Bitrix\Calendar\Core\Event\Properties\RecurringEventRules
Definition
recurringeventrules.php:11
Bitrix\Calendar\Core\Event\Properties\Relations
Definition
relations.php:8
Bitrix\Calendar\Core\Event\Properties\RemindCollection
Definition
remindcollection.php:11
Bitrix\Calendar\Core\Role\Helper
Definition
helper.php:10
Bitrix\Calendar\Core\Role\Role
Definition
role.php:8
Bitrix\Calendar\Core\Role\User
Definition
user.php:8
Bitrix\Calendar\Core\Section\Section
Definition
section.php:11
Bitrix\Calendar\Util
Definition
util.php:16
Bitrix\Calendar\Util\getDateObject
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Definition
util.php:102
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\ORM\Data\DataManager\query
static query()
Definition
datamanager.php:559
Bitrix\Main\ObjectException
Definition
exception.php:192
Bitrix\Main\ObjectPropertyException
Definition
exception.php:181
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Main\UserTable
Definition
user.php:46
Bitrix\Calendar\Core\Builders\Builder
Definition
builder.php:6
Bitrix\Calendar\Core\Builders
Definition
builder.php:3
modules
calendar
lib
core
builders
eventbuilder.php
Создано системой
1.10.0