Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
senderinvitation.php
1
<?php
2
3
namespace
Bitrix\Calendar\ICal\MailInvitation
;
4
5
use
Bitrix\Calendar\ICal\Builder\Attach
;
6
use Bitrix\Calendar\SerializeObject;
7
use
Bitrix\Calendar\Util
;
8
use
Bitrix\Main\ArgumentException
;
9
use
Bitrix\Main\LoaderException
;
10
use
Bitrix\Main\Localization\Loc
;
11
use
Bitrix\Main\Mail\Event
;
12
use
Bitrix\Main\NotImplementedException
;
13
use
Bitrix\Main\ObjectPropertyException
;
14
use
Bitrix\Main\SystemException
;
15
use
Bitrix\Main\Type\Date
;
16
use
Bitrix\Main\Type\DateTime
;
17
use \Serializable;
18
23
abstract
class
SenderInvitation
implements
Serializable
24
{
25
use SerializeObject;
26
27
public
const
CHARSET
=
'utf-8'
;
28
public
const
CONTENT_TYPE
=
'text/calendar'
;
29
public
const
DECISION_YES
=
'Y'
;
30
public
const
DECISION_NO
=
'N'
;
31
protected
const
ATTACHMENT_NAME
=
'invite.ics'
;
32
protected
const
MAIL_TEMPLATE
=
'SEND_ICAL_INVENT'
;
33
37
protected
int
$counterInvitations
= 0;
41
protected
?array
$event
=
null
;
45
protected
?
Context
$context
=
null
;
49
protected
?
string
$uid
=
''
;
50
51
abstract
public
function
executeAfterSuccessfulInvitation
();
52
abstract
protected
function
getContent
();
53
abstract
protected
function
getMailEventField
();
54
abstract
protected
function
getSubjectTitle
();
55
56
public
static
function
createInstance
(array
$event
,
Context
$context
):
SenderInvitation
57
{
58
return
new
static
(
$event
,
$context
);
59
}
60
61
public
function
__construct
(array
$event
,
Context
$context
)
62
{
63
$this->
event
=
$event
;
64
$this->context =
$context
;
65
}
66
67
public
function
setCounterInvitations
(?
int
$counterInvitations
): static
68
{
69
$this->counterInvitations =
$counterInvitations
?? 0;
70
return
$this;
71
}
72
73
public
function
setEvent
(?array
$event
): static
74
{
75
$this->
event
=
$event
;
76
return
$this;
77
}
78
87
public
function
send
(): bool
88
{
89
if
($this->event ===
null
|| $this->context ===
null
)
90
{
91
return
false
;
92
}
93
94
$this->
prepareEventFields
();
95
96
$content = $this->
getContent
();
97
if
(!$content)
98
{
99
return
false
;
100
}
101
102
$status = \CEvent::sendImmediate(
103
self::MAIL_TEMPLATE,
104
SITE_ID,
105
$this->
getMailEventField
(),
106
"Y"
,
107
""
,
108
[],
109
''
,
110
$content
111
);
112
113
return
$status === Event::SEND_RESULT_SUCCESS;
114
}
115
119
public
function
getMethod
(): string
120
{
121
return
static::METHOD;
122
}
123
127
public
function
getEvent
(): array
128
{
129
return
$this->
event
?? [];
130
}
131
135
public
function
incrementCounterInvitations
(): void
136
{
137
$this->counterInvitations++;
138
}
139
143
public
function
getUid
(): string
144
{
145
return
$this->uid
;
146
}
147
151
public
function
getCountAttempsSend
(): int
152
{
153
return
$this->counterInvitations
;
154
}
155
159
public
function
getAddresser
():
MailAddresser
160
{
161
return
$this->context->getAddresser();
162
}
163
167
public
function
getReceiver
():
MailReceiver
168
{
169
return
$this->context->getReceiver();
170
}
171
175
public
function
getEventId
(): ?int
176
{
177
return
$this->
event
[
'ID'
] ??
null
;
178
}
179
183
public
function
getEventParentId
(): int
184
{
185
return
(
int
) ($this->
event
[
'PARENT_ID'
] ?? 0);
186
}
187
191
protected
function
getBodyMessage
(): string
192
{
193
//@TODO edit body message
194
return
'ical body message'
;
195
}
196
201
protected
function
getDateForTemplate
(): string
202
{
203
$res =
Helper::getIcalTemplateDate
([
204
'DATE_FROM'
=> $this->event[
'DATE_FROM'
],
205
'DATE_TO'
=> $this->event[
'DATE_TO'
],
206
'TZ_FROM'
=> $this->event[
'TZ_FROM'
],
207
'TZ_TO'
=> $this->event[
'TZ_TO'
],
208
'FULL_DAY'
=> $this->event[
'SKIP_TIME'
],
209
]);
210
$offset = (
Helper::getDateObject
(
null
,
false
, $this->event[
'TZ_FROM'
]))->format(
'P'
);
211
$res .=
' ('
. $this->
event
[
'TZ_FROM'
] .
', '
.
'UTC'
. $offset .
')'
;
212
213
if
(isset($this->event[
'RRULE'
][
'FREQ'
]) && $this->
event
[
'RRULE'
][
'FREQ'
] !==
'NONE'
)
214
{
215
$rruleString =
Helper::getIcalTemplateRRule
($this->event[
'RRULE'
],
216
[
217
'DATE_FROM'
=> $this->event[
'DATE_FROM'
],
218
'DATE_TO'
=> $this->event[
'DATE_TO'
],
219
'TZ_FROM'
=> $this->event[
'TZ_FROM'
],
220
'TZ_TO'
=> $this->event[
'TZ_TO'
],
221
'FULL_DAY'
=> $this->event[
'SKIP_TIME'
],
222
]
223
);
224
$res .=
', ('
. $rruleString .
')'
;
225
}
226
227
return
$res;
228
}
229
233
protected
function
getFilesLink
(): string
234
{
235
$result =
""
;
236
237
if
(is_iterable($this->event[
'ICAL_ATTACHES'
]))
238
{
239
foreach
($this->event[
'ICAL_ATTACHES'
] as $attach)
240
{
241
if
($attach instanceof
Attach
)
242
{
243
$result .=
"<a href=\"{$attach->getLink()}\"> {$attach->getName() }</a> <br />"
;
244
}
245
}
246
}
247
248
return
$result;
249
}
250
254
protected
function
getSiteName
(): string
255
{
256
if
(!empty($siteName = \COption::GetOptionString(
"main"
,
"site_name"
,
''
,
'-'
)))
257
{
258
return
"[{$siteName}]"
;
259
}
260
261
return
''
;
262
}
263
267
protected
function
getSubjectMessage
(): string
268
{
269
return
$this->
getSiteName
().
' '
. $this->
getSubjectTitle
();
270
}
271
275
protected
function
getMessageId
(): string
276
{
277
$serverName = \COption::GetOptionString(
"main"
,
"server_name"
,
$GLOBALS
[
"SERVER_NAME"
]);
278
return
"<CALENDAR_EVENT_{$this->getEventParentId()}@{$serverName}>"
;
279
}
280
284
protected
function
getAttendeesListForTemplate
(): string
285
{
286
if
($this->event[
'MEETING'
][
'HIDE_GUESTS'
])
287
{
288
return
Loc::getMessage
(
'EC_CALENDAR_ICAL_MAIL_HIDE_GUESTS_INFORMATION'
);
289
}
290
291
return
$this->
event
[
'ICAL_ATTENDEES'
];
292
}
293
297
protected
function
getEventDateCreateTimestamp
(): int
298
{
299
return
(
int
)
Util::getTimestamp
($this->event[
'CREATED'
]);
300
}
301
305
protected
function
getEventOwnerId
(): int
306
{
307
return
(
int
) $this->
event
[
'OWNER_ID'
];
308
}
309
310
private
function
getFormattedDate(
DateTime
$formattedDate,
string
$dtSkipTime): string
311
{
312
$timestamp = \CCalendar::Timestamp($formattedDate,
false
, $dtSkipTime !==
'Y'
);
313
314
return \CCalendar::Date($timestamp);
315
}
316
317
325
protected
function
prepareEventFields
(): void
326
{
327
$dtSkipTime = $this->
event
[
'DT_SKIP_TIME'
];
328
$this->
event
[
'DATE_FROM'
] = $this->getFormattedDate($this->event[
'DATE_FROM'
], $dtSkipTime);
329
$this->
event
[
'DATE_TO'
] = $this->getFormattedDate($this->event[
'DATE_TO'
], $dtSkipTime);
330
$this->
event
[
'CREATED'
] = $this->getFormattedDate($this->event[
'DATE_CREATE'
],
false
);
331
$this->
event
[
'MODIFIED'
] = $this->getFormattedDate($this->event[
'TIMESTAMP_X'
],
false
);
332
333
$this->
event
[
'SKIP_TIME'
] = $dtSkipTime ===
'Y'
;
334
$this->
event
[
'MEETING'
] = unserialize($this->event[
'MEETING'
], [
'allowed_classes'
=>
false
]);
335
$this->
event
[
'REMIND'
] = unserialize($this->event[
'REMIND'
], [
'allowed_classes'
=>
false
]);
336
$this->
event
[
'RRULE'
] = \CCalendarEvent::ParseRRULE($this->event[
'RRULE'
]);
337
$this->
event
[
'ATTENDEES_CODES'
] = !empty($this->event[
'ATTENDEES_CODES'
]) && is_string($this->event[
'ATTENDEES_CODES'
])
338
? explode(
','
, $this->event[
'ATTENDEES_CODES'
])
339
: []
340
;
341
$this->
event
[
'ICAL_ATTENDEES'
] =
Helper::getAttendeesByEventParentId
($this->event[
'PARENT_ID'
]);
342
$this->
event
[
'ICAL_ORGANIZER'
] =
Helper::getAttendee
($this->event[
'MEETING_HOST'
], $this->event[
'PARENT_ID'
],
false
);
343
$this->
event
[
'TEXT_LOCATION'
] = \CCalendar::GetTextLocation($this->event[
'LOCATION'
] ??
null
);
344
$this->
event
[
'ICAL_ATTACHES'
] =
Helper::getMailAttaches
(
345
null
,
346
$this->event[
'MEETING_HOST'
],
347
$this->event[
'PARENT_ID'
]
348
);
349
350
unset($this->event[
'DT_SKIP_TIME'
], $this->event[
'DATE_CREATE'
], $this->event[
'TIMESTAMP_X'
]);
351
}
352
}
Bitrix\Calendar\ICal\Builder\Attach
Definition
attach.php:11
Bitrix\Calendar\ICal\MailInvitation\Context
Definition
context.php:6
Bitrix\Calendar\ICal\MailInvitation\Helper\getAttendee
static getAttendee(int $userId, int $eventParentId, $isRsvp=true)
Definition
helper.php:450
Bitrix\Calendar\ICal\MailInvitation\Helper\getDateObject
static getDateObject(string $date=null, $fullDay=true, $tz='UTC')
Definition
helper.php:73
Bitrix\Calendar\ICal\MailInvitation\Helper\getAttendeesByEventParentId
static getAttendeesByEventParentId(int $parentId)
Definition
helper.php:494
Bitrix\Calendar\ICal\MailInvitation\Helper\getMailAttaches
static getMailAttaches($fields, $userId, $parentId, &$isChangeFiles=false)
Definition
helper.php:362
Bitrix\Calendar\ICal\MailInvitation\Helper\getIcalTemplateRRule
static getIcalTemplateRRule(array $rrule=null, array $params=null)
Definition
helper.php:92
Bitrix\Calendar\ICal\MailInvitation\Helper\getIcalTemplateDate
static getIcalTemplateDate(array $params=null)
Definition
helper.php:46
Bitrix\Calendar\ICal\MailInvitation\MailAddresser
Definition
mailaddresser.php:6
Bitrix\Calendar\ICal\MailInvitation\MailReceiver
Definition
mailreceiver.php:6
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation
Definition
senderinvitation.php:24
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getAddresser
getAddresser()
Definition
senderinvitation.php:159
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getEvent
getEvent()
Definition
senderinvitation.php:127
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getDateForTemplate
getDateForTemplate()
Definition
senderinvitation.php:201
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getCountAttempsSend
getCountAttempsSend()
Definition
senderinvitation.php:151
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getAttendeesListForTemplate
getAttendeesListForTemplate()
Definition
senderinvitation.php:284
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\send
send()
Definition
senderinvitation.php:87
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\MAIL_TEMPLATE
const MAIL_TEMPLATE
Definition
senderinvitation.php:32
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\createInstance
static createInstance(array $event, Context $context)
Definition
senderinvitation.php:56
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getEventParentId
getEventParentId()
Definition
senderinvitation.php:183
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getEventOwnerId
getEventOwnerId()
Definition
senderinvitation.php:305
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\ATTACHMENT_NAME
const ATTACHMENT_NAME
Definition
senderinvitation.php:31
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getSubjectMessage
getSubjectMessage()
Definition
senderinvitation.php:267
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\CHARSET
const CHARSET
Definition
senderinvitation.php:27
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\DECISION_YES
const DECISION_YES
Definition
senderinvitation.php:29
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getMessageId
getMessageId()
Definition
senderinvitation.php:275
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getContent
getContent()
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getBodyMessage
getBodyMessage()
Definition
senderinvitation.php:191
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\setCounterInvitations
setCounterInvitations(?int $counterInvitations)
Definition
senderinvitation.php:67
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\incrementCounterInvitations
incrementCounterInvitations()
Definition
senderinvitation.php:135
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getUid
getUid()
Definition
senderinvitation.php:143
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getSubjectTitle
getSubjectTitle()
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\$uid
string $uid
Definition
senderinvitation.php:49
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\setEvent
setEvent(?array $event)
Definition
senderinvitation.php:73
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getEventId
getEventId()
Definition
senderinvitation.php:175
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getSiteName
getSiteName()
Definition
senderinvitation.php:254
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\__construct
__construct(array $event, Context $context)
Definition
senderinvitation.php:61
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\$event
array $event
Definition
senderinvitation.php:41
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\DECISION_NO
const DECISION_NO
Definition
senderinvitation.php:30
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\CONTENT_TYPE
const CONTENT_TYPE
Definition
senderinvitation.php:28
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\prepareEventFields
prepareEventFields()
Definition
senderinvitation.php:325
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getReceiver
getReceiver()
Definition
senderinvitation.php:167
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getFilesLink
getFilesLink()
Definition
senderinvitation.php:233
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getMailEventField
getMailEventField()
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\$context
Context $context
Definition
senderinvitation.php:45
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getMethod
getMethod()
Definition
senderinvitation.php:119
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\getEventDateCreateTimestamp
getEventDateCreateTimestamp()
Definition
senderinvitation.php:297
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\executeAfterSuccessfulInvitation
executeAfterSuccessfulInvitation()
Bitrix\Calendar\ICal\MailInvitation\SenderInvitation\$counterInvitations
int $counterInvitations
Definition
senderinvitation.php:37
Bitrix\Calendar\Util
Definition
util.php:16
Bitrix\Calendar\Util\getTimestamp
static getTimestamp($date, $round=true, $getTime=true)
Definition
util.php:55
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\LoaderException
Definition
loader.php:582
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\NotImplementedException
Definition
exception.php:147
Bitrix\Main\ObjectPropertyException
Definition
exception.php:181
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Main\Type\Date
Definition
date.php:9
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Calendar\ICal\MailInvitation
Definition
attachmentcancelmanager.php:4
Bitrix\Main\$GLOBALS
$GLOBALS['____1444769544']
Definition
license.php:1
modules
calendar
lib
ical
mailinvitation
senderinvitation.php
Создано системой
1.10.0