3namespace Bitrix\Calendar\ICal\MailInvitation;
5use Bitrix\Calendar\Core\Event\Event;
6use Bitrix\Calendar\ICal\Builder\Attach;
7use Bitrix\Calendar\ICal\Builder\AttachCollection;
8use Bitrix\Calendar\ICal\Builder\Attendee;
9use Bitrix\Calendar\ICal\Builder\AttendeesCollection;
10use Bitrix\Calendar\ICal\Builder\Dictionary;
11use Bitrix\Calendar\ICal\Parser\ParserPropertyType;
12use Bitrix\Calendar\Util;
13use Bitrix\Disk\Uf\FileUserType;
14use Bitrix\Main\Application;
15use Bitrix\Main\ArgumentException;
16use Bitrix\Main\Entity\ReferenceField;
17use Bitrix\Main\Loader;
18use Bitrix\Main\Localization\Loc;
19use Bitrix\Main\ObjectPropertyException;
20use Bitrix\Main\ORM\Entity;
21use Bitrix\Main\ORM\Fields\Relations\Reference;
22use Bitrix\Main\ORM\Query\Join;
23use Bitrix\Main\SystemException;
24use Bitrix\Main\Type\Date;
25use Bitrix\Main\Type\DateTime;
28use Bitrix\Calendar\Internals\EventTable;
29use Bitrix\Main\UserTable;
30use \Bitrix\Disk\AttachedObject;
49 $from = self::getDateObject(
$params[
'DATE_FROM'],
false,
$params[
'TZ_FROM']);
50 $to = self::getDateObject(
$params[
'DATE_TO'],
false,
$params[
'TZ_TO']);
51 if ($from->format(
'dmY') !== $to->format(
'dmY'))
54 ? $from->format(
'd.m.Y') .
' - ' . $to->format(
'd.m.Y')
55 : $from->format(
'd.m.Y H:i') .
' - ' . $to->format(
'd.m.Y H:i');
60 ? $from->format(
'd.m.Y')
61 : $from->format(
'd.m.Y H:i') .
' - ' . $to->format(
'H:i');
74 public static function getDateObject(
string $date =
null, $fullDay =
true, $tz =
'UTC'):
Date
76 $preparedDate = $date;
79 $timestamp = \CCalendar::Timestamp($date,
false, !$fullDay);
80 $preparedDate = \CCalendar::Date($timestamp);
96 if ($rrule[
'BYDAY'] ??
false)
98 $rrule[
'BYDAY'] = \CCalendarEvent::sortByDay($rrule[
'BYDAY']);
100 switch($rrule[
'FREQ'] ??
null)
103 $res = (int)$rrule[
'INTERVAL'] === 1
104 ? Loc::getMessage(
'EC_RRULE_EVERY_DAY')
105 : Loc::getMessage(
'EC_RRULE_EVERY_DAY_1', [
'#DAY#' => $rrule[
'INTERVAL']])
109 if (!isset($rrule[
'BYDAY']) || !is_array($rrule[
'BYDAY']))
111 $rrule[
'BYDAY'] = [
'MO'];
114 $daysList = implode(
', ', array_map(
static function($day) {
return Loc::getMessage(
'EC_' . $day);}, $rrule[
'BYDAY']));
115 $res = (int)$rrule[
'INTERVAL'] === 1
116 ? Loc::getMessage(
'EC_RRULE_EVERY_WEEK', [
'#DAYS_LIST#' => $daysList])
117 : Loc::getMessage(
'EC_RRULE_EVERY_WEEK_1', [
'#WEEK#' => $rrule[
'INTERVAL'],
'#DAYS_LIST#' => $daysList])
121 $res = (int)$rrule[
'INTERVAL'] === 1
122 ? Loc::getMessage(
'EC_RRULE_EVERY_MONTH')
123 : Loc::getMessage(
'EC_RRULE_EVERY_MONTH_1', [
'#MONTH#' => $rrule[
'INTERVAL']])
127 $fromTs = \CCalendar::Timestamp(
$params[
'DATE_FROM']);
128 $res = (int)$rrule[
'INTERVAL'] === 1
129 ? Loc::getMessage(
'EC_RRULE_EVERY_YEAR', [
133 : Loc::getMessage(
'EC_RRULE_EVERY_YEAR_1', [
134 '#YEAR#' => $rrule[
'INTERVAL'],
142 if ($rrule[
'COUNT'] ??
false)
144 $res .=
' ' . Loc::getMessage(
'EC_RRULE_COUNT', [
'#COUNT#' => $rrule[
'COUNT']]);
146 elseif (isset($rrule[
'UNTIL']) && $rrule[
'UNTIL'] && self::isNotEndOfTime($rrule[
'UNTIL']))
148 $res .=
' ' . Loc::getMessage(
'EC_RRULE_UNTIL', [
'#UNTIL_DATE#' => $rrule[
'UNTIL']]);
151 if (!is_string(
$res))
164 return uniqid(self::getServerName(),
true);
172 return COption::getOptionString(
'main',
'server_name', Application::getInstance()->getContext()->getServer()->
getServerName());
182 ? (new \DateTime())->getTimezone()
201 $event = EventTable::getList([
203 '=DAV_XML_ID' =>
$uid,
228 $user = UserTable::getList([
255 $usersDb = UserTable::getList([
268 while (
$user = $usersDb->fetch())
292 $attachedFilesIds = $UF[
'UF_WEBDAV_CAL_EVENT'][
'VALUE'];
294 $fields[
'UF_WEBDAV_CAL_EVENT'] ??=
null;
295 if (is_array(
$fields) && is_array(
$fields[
'UF_WEBDAV_CAL_EVENT']) && is_array($attachedFilesIds))
297 $ufIds = array_unique(array_merge(
$fields[
'UF_WEBDAV_CAL_EVENT'], $attachedFilesIds));
301 $ufIds =
$fields[
'UF_WEBDAV_CAL_EVENT'];
303 elseif(is_array($attachedFilesIds))
305 $ufIds = $attachedFilesIds;
309 return $attachCollection;
312 if (!empty($ufIds) && \
Bitrix\
Main\Loader::includeModule(
'disk'))
314 foreach ($ufIds as $item)
316 [
$type, $realValue] = \Bitrix\Disk\Uf\FileUserType::detectType($item);
318 if (
$type == FileUserType::TYPE_ALREADY_ATTACHED)
320 $attachedModel = AttachedObject::loadById($realValue);
322 || (!empty(
$fields[
'UF_WEBDAV_CAL_EVENT'])
324 && !in_array($item,
$fields[
'UF_WEBDAV_CAL_EVENT'])))
326 $isChangeFiles =
true;
329 $file = $attachedModel->getFile();
333 $isChangeFiles =
true;
334 $file = \Bitrix\Disk\File::loadById($realValue, [
'STORAGE']);
342 $externalLink = $file->addExternalLink([
351 $name = $file->getName();
352 $size = $file->getSize();
353 $link = \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink([
354 'hash' => $externalLink->getHash(),
355 'action' =>
'downloadFile',
362 $attachCollection->add($attach);
366 return $attachCollection;
376 $query = EventTable::query()
379 'USER_NAME' =>
'USER.NAME',
380 'USER_LAST_NAME' =>
'USER.LAST_NAME',
381 'USER_EMAIL' =>
'USER.EMAIL',
383 ->registerRuntimeField(
387 UserTable::getEntity(),
388 Join::on(
'this.OWNER_ID',
'ref.ID'),
389 [
'join_type' => Join::TYPE_INNER]
392 ->setFilter([
'USER.ID'=>
$userId,
'=PARENT_ID'=>$eventParentId])
395 $attendee =
$query->fetch();
397 if (is_null($attendee))
402 return Attendee::createInstance(
403 $attendee[
'USER_EMAIL'],
404 $attendee[
'USER_NAME'],
405 $attendee[
'USER_LAST_NAME'],
406 Dictionary::ATTENDEE_STATUS[$attendee[
'MEETING_STATUS']],
407 Dictionary::ATTENDEE_ROLE[
'REQ_PARTICIPANT'],
408 Dictionary::ATTENDEE_CUTYPE[
'individual'],
409 $attendee[
'USER_EMAIL'],
420 $attendeesCollection = AttendeesCollection::createInstance();
422 $query = EventTable::query()
425 'USER_NAME' =>
'USER.NAME',
426 'USER_LAST_NAME' =>
'USER.LAST_NAME',
427 'USER_EMAIL' =>
'USER.EMAIL'
429 ->where(
'PARENT_ID', $parentId)
430 ->registerRuntimeField(
434 UserTable::getEntity(),
435 Join::on(
'this.OWNER_ID',
'ref.ID'),
436 [
'join_type' => Join::TYPE_INNER]
442 while ($attendee =
$query->fetch())
444 $attendeesCollection->add(Attendee::createInstance(
445 $attendee[
'USER_EMAIL'],
446 $attendee[
'USER_NAME'],
447 $attendee[
'USER_LAST_NAME'],
448 Dictionary::ATTENDEE_STATUS[$attendee[
'MEETING_STATUS']],
449 Dictionary::ATTENDEE_ROLE[
'REQ_PARTICIPANT'],
450 Dictionary::ATTENDEE_CUTYPE[
'individual'],
451 $attendee[
'USER_EMAIL']
455 return $attendeesCollection;
466 $format = $tz ===
'UTC' ? self::ICAL_DATETIME_FORMAT_UTC : self::ICAL_DATETIME_FORMAT;
478 return new Date($date, self::ICAL_DATE_FORMAT);
492 'EMAIL' => $userInfo[
'EMAIL'],
498 $userDd = UserTable::getList($parameters);
499 if (
$user = $userDd->fetch())
501 return (
int)
$user[
'ID'];
504 return self::getExternalUserByEmail($userInfo, $errorCollection);
526 || !Loader::includeModule(
'mail')
542 $res = \CUser::getList(
546 "=EMAIL" => $userEmail,
550 "FIELDS" => [
"ID",
"EXTERNAL_AUTH_ID",
"ACTIVE" ]
557 (
int)$emailUser[
"ID"] > 0
559 $emailUser[
"ACTIVE"] ===
"Y"
560 || $emailUser[
"EXTERNAL_AUTH_ID"] ===
"email"
564 if ($emailUser[
"ACTIVE"] ===
"N")
567 $user->update($emailUser[
"ID"], [
579 'EMAIL' => $userEmail,
580 'NAME' =>
$params[
"NAME"] ??
'',
581 'LAST_NAME' =>
$params[
"LAST_NAME"] ??
''
585 $user = \Bitrix\Mail\User::create($userFields);
587 if (is_object(
$user) &&
$user->LAST_ERROR !==
'')
627 $event = EventTable::getList([
628 'filter' => [
'=ID' => $eventId,],
629 'select' => [
'DESCRIPTION'],
651 $event = EventTable::query()
685 ->setFilter([
'=ID' => $eventId])
722 : mb_strtoupper($date->
format(
'M'))
725 return is_string($month)
752 : self::getIcalDate($date->
getValue())
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static createInstance(string $link, string $name, int $size)
static getExternalUserByEmail($params, &$errorText)
static getAttendee(int $userId, int $eventParentId, $isRsvp=true)
static getDateObject(string $date=null, $fullDay=true, $tz='UTC')
static getDateByParserProperty(?ParserPropertyType $date)
static isNotEndOfTime($until)
static getEventByUId(?string $uid)
const ICAL_DATETIME_FORMAT
static getTimezoneObject(string $tz=null)
static getIcalDate(string $date=null)
static getIcalDateTime(string $dateTime=null, string $tz=null)
static getAttendeesByEventParentId(int $parentId)
static getMailAttaches($fields, $userId, $parentId, &$isChangeFiles=false)
static getUserIdByEmail(array $userInfo)
static getShortMonthName(?Date $date)
static getUserById(?int $id)
static getIndexUsersByIds(?array $idList)
const ICAL_DATETIME_FORMAT_UTC
static getEventDescriptionById(?int $eventId)
const ICAL_DATETIME_FORMAT_SHORT
static getIcalTemplateRRule(array $rrule=null, array $params=null)
static getEventById(?int $eventId)
static getIcalDateTimeShort(string $dateTime=null, string $tz='UTC')
static getIcalTemplateDate(array $params=null)
getParameterValueByName(string $name)
static getUserSelectorContext()
static prepareTimezone(?string $tz=null)
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
static getExternalUserTypes()
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
global $USER_FIELD_MANAGER
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
$_SERVER["DOCUMENT_ROOT"]
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
check_email($email, $strict=false, $domainCheck=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']