Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
attachmentmanager.php
1
<?php
2
3
4
namespace
Bitrix\Calendar\ICal\MailInvitation
;
5
6
7
use
Bitrix\Calendar\ICal\Basic\RecurrenceRuleProperty
;
8
use
Bitrix\Calendar\ICal\Builder\Attach
;
9
use
Bitrix\Calendar\ICal\Builder\Attendee
;
10
use
Bitrix\Mail\User
;
11
use
Bitrix\Main\Loader
;
12
use
Bitrix\Main\Localization\Loc
;
13
use
Bitrix\Main\ObjectException
;
14
use
Bitrix\Main\Type\Date
;
15
16
abstract
class
AttachmentManager
17
{
21
protected
$event
= [];
25
protected
$uid
;
26
27
abstract
public
function
getContent
(): string;
28
33
public
static
function
createInstance
(array
$event
):
AttachmentManager
34
{
35
return
new
static
(
$event
);
36
}
37
42
public
function
__construct
(array
$event
)
43
{
44
$this->
event
=
$event
;
45
}
46
50
public
function
getUid
(): ?string
51
{
52
return
$this->uid
;
53
}
54
59
protected
function
prepareDescription
(
string
$description =
null
): ?string
60
{
61
if
(
62
empty($description)
63
&& (empty($this->event[
'ICAL_ATTACHES'
])
64
|| empty($this->event[
'ICAL_ATTACHES'
]->getCollection())
65
)
66
)
67
{
68
return
null
;
69
}
70
71
$description = $this->
parseText
($description);
72
73
if
(empty($this->event[
'ICAL_ATTACHES'
]->getCollection()))
74
{
75
return
str_replace(
"\r\n"
,
" \n"
, $description);
76
}
77
78
return
str_replace(
"\r\n"
,
" \n"
, $description .
"\n"
. $this->
getFilesDescription
());
79
}
80
85
protected
function
prepareRecurrenceRule
($rrule): ?
RecurrenceRuleProperty
86
{
87
if
(is_string($rrule))
88
{
89
$rrule = \CCalendarEvent::ParseRRULE($rrule);
90
}
91
92
return
is_array($rrule)
93
?
new
RecurrenceRuleProperty
($rrule)
94
:
null
;
95
}
96
100
protected
function
getFilesDescription
(): string
101
{
102
if
(empty($this->event[
'ICAL_ATTACHES'
]->getCollection()))
103
{
104
return
''
;
105
}
106
107
$filesDescription = [];
108
if
(is_iterable($this->event[
'ICAL_ATTACHES'
]))
109
{
110
foreach
($this->event[
'ICAL_ATTACHES'
] as $attach)
111
{
112
if
($attach instanceof
Attach
)
113
{
114
$filesDescription[] =
"{$attach->getName()} ({$attach->getLink()})"
;
115
}
116
}
117
}
118
119
return
Loc::getMessage
(
'EC_FILES_TITLE'
) .
":\n"
. implode(
"\n"
, $filesDescription) .
""
;
120
}
121
127
protected
function
prepareExDate
(
string
$exDates =
null
): ?
Date
128
{
129
return
!$exDates
130
? null
131
: array_map(
function
($exDate) {
132
return
new
Date
($exDate,
'd.m.Y'
);
133
}, explode(
';'
, $exDates));
134
}
135
140
protected
function
getOrganizerMailTo(): string
141
{
142
if
(!Loader::includeModule(
'mail'
))
143
{
144
return
''
;
145
}
146
147
$boxes = \Bitrix\Mail\MailboxTable::getUserMailboxes($this->event[
'MEETING_HOST'
]);
148
$organizer = $this->
event
[
'ICAL_ORGANIZER'
];
149
if
($organizer ===
null
)
150
{
151
$user =
Helper::getUserById
($this->event[
'MEETING_HOST'
]);
152
$organizer = Attendee::createInstance(
153
$user[
'EMAIL'
],
154
$user[
'NAME'
],
155
$user[
'LAST_NAME'
],
156
null
,
157
null
,
158
null
,
159
$user[
'EMAIL'
],
160
false
161
);
162
}
163
164
foreach
($boxes as $box)
165
{
167
if
($box[
'EMAIL'
] === $organizer->getMailTo())
168
{
169
return
$organizer->getMailTo();
170
}
171
}
172
173
return
$this->
getReplyAddress
();
174
175
}
176
177
protected
function
getReplyAddress
(): string
178
{
179
[$replyTo, $backUrl] =
User::getReplyTo
(
180
SITE_ID,
181
$this->event[
'OWNER_ID'
],
182
'ICAL_INVENT'
,
183
$this->event[
'PARENT_ID'
],
184
SITE_ID
185
);
186
187
return
$replyTo;
188
}
189
194
protected
function
parseText
(?
string
$description): string
195
{
196
if
(!$description)
197
{
198
return
''
;
199
}
200
201
return \CTextParser::clearAllTags($description);
202
}
203
}
Bitrix\Calendar\Core\Base\Date
Definition
date.php:10
Bitrix\Calendar\ICal\Basic\RecurrenceRuleProperty
Definition
recurrenceruleproperty.php:8
Bitrix\Calendar\ICal\Builder\Attach
Definition
attach.php:11
Bitrix\Calendar\ICal\Builder\Attendee
Definition
attendee.php:11
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager
Definition
attachmentmanager.php:17
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\$uid
$uid
Definition
attachmentmanager.php:25
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\prepareRecurrenceRule
prepareRecurrenceRule($rrule)
Definition
attachmentmanager.php:85
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\__construct
__construct(array $event)
Definition
attachmentmanager.php:42
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\createInstance
static createInstance(array $event)
Definition
attachmentmanager.php:33
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\getReplyAddress
getReplyAddress()
Definition
attachmentmanager.php:177
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\getContent
getContent()
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\$event
$event
Definition
attachmentmanager.php:21
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\getUid
getUid()
Definition
attachmentmanager.php:50
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\parseText
parseText(?string $description)
Definition
attachmentmanager.php:194
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\prepareExDate
prepareExDate(string $exDates=null)
Definition
attachmentmanager.php:127
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\prepareDescription
prepareDescription(string $description=null)
Definition
attachmentmanager.php:59
Bitrix\Calendar\ICal\MailInvitation\AttachmentManager\getFilesDescription
getFilesDescription()
Definition
attachmentmanager.php:100
Bitrix\Calendar\ICal\MailInvitation\Helper\getUserById
static getUserById(?int $id)
Definition
helper.php:220
Bitrix\Mail\User\getReplyTo
static getReplyTo($siteId, $userId, $entityType, $entityId, $entityLink=null, $backurl=null)
Definition
user.php:122
Bitrix\Main\Loader
Definition
loader.php:12
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\ObjectException
Definition
exception.php:192
Bitrix\Main\Type\Date
Definition
date.php:9
Bitrix\Calendar\ICal\MailInvitation
Definition
attachmentcancelmanager.php:4
Bitrix\Mail\User
Definition
message.php:8
modules
calendar
lib
ical
mailinvitation
attachmentmanager.php
Создано системой
1.10.0