14use Bitrix\Disk\Uf\FileUserType;
17use Bitrix\Main\Entity\ReferenceField;
29use \Bitrix\Disk\AttachedObject;
31IncludeModuleLangFile($_SERVER[
'DOCUMENT_ROOT'] . BX_ROOT .
'/modules/calendar/classes/general/calendar.php');
50 if ($from->format(
'dmY') !== $to->format(
'dmY'))
52 $res = $params[
'FULL_DAY']
53 ? $from->format(
'd.m.Y') .
' - ' . $to->format(
'd.m.Y')
54 : $from->format(
'd.m.Y H:i') .
' - ' . $to->format(
'd.m.Y H:i');
58 $res = $params[
'FULL_DAY']
59 ? $from->format(
'd.m.Y')
60 : $from->format(
'd.m.Y H:i') .
' - ' . $to->format(
'H:i');
73 public static function getDateObject(
string $date =
null, $fullDay =
true, $tz =
'UTC'):
Date
75 $preparedDate = $date;
78 $timestamp = \CCalendar::Timestamp($date,
false, !$fullDay);
79 $preparedDate = \CCalendar::Date($timestamp);
83 ?
new Date($preparedDate, Date::convertFormatToPhp(FORMAT_DATE))
95 if ($rrule[
'BYDAY'] ??
false)
97 $rrule[
'BYDAY'] = \CCalendarEvent::sortByDay($rrule[
'BYDAY']);
99 switch($rrule[
'FREQ'] ??
null)
102 $res = (int)$rrule[
'INTERVAL'] === 1
104 :
Loc::getMessage(
'EC_RRULE_EVERY_DAY_1', [
'#DAY#' => $rrule[
'INTERVAL']])
108 if (!isset($rrule[
'BYDAY']) || !is_array($rrule[
'BYDAY']))
110 $rrule[
'BYDAY'] = [
'MO'];
113 $daysList = implode(
', ', array_map(
static function($day) {
return Loc::getMessage(
'EC_' . $day);}, $rrule[
'BYDAY']));
114 $res = (int)$rrule[
'INTERVAL'] === 1
116 :
Loc::getMessage(
'EC_RRULE_EVERY_WEEK_1', [
'#WEEK#' => $rrule[
'INTERVAL'],
'#DAYS_LIST#' => $daysList])
120 $res = (int)$rrule[
'INTERVAL'] === 1
122 :
Loc::getMessage(
'EC_RRULE_EVERY_MONTH_1', [
'#MONTH#' => $rrule[
'INTERVAL']])
126 $fromTs = \CCalendar::Timestamp($params[
'DATE_FROM']);
127 $res = (int)$rrule[
'INTERVAL'] === 1
129 '#DAY#' => FormatDate(
'j', $fromTs),
130 '#MONTH#' => FormatDate(
'n', $fromTs)
133 '#YEAR#' => $rrule[
'INTERVAL'],
134 '#DAY#' => FormatDate(
'j', $fromTs),
135 '#MONTH#' => FormatDate(
'n', $fromTs)
141 if ($rrule[
'COUNT'] ??
false)
143 $res .=
' ' .
Loc::getMessage(
'EC_RRULE_COUNT', [
'#COUNT#' => $rrule[
'COUNT']]);
145 elseif (isset($rrule[
'UNTIL']) && $rrule[
'UNTIL'] && self::isNotEndOfTime($rrule[
'UNTIL']))
147 $res .=
' ' .
Loc::getMessage(
'EC_RRULE_UNTIL', [
'#UNTIL_DATE#' => $rrule[
'UNTIL']]);
150 if (!is_string($res))
163 return uniqid(self::getServerName(),
true);
181 ? (new \DateTime())->getTimezone()
200 $event = EventTable::getList([
202 '=DAV_XML_ID' => $uid,
208 return (!empty($event) && is_array($event))
227 $user = UserTable::getList([
240 return (!empty($user) && is_array($user))
254 $usersDb = UserTable::getList([
267 while ($user = $usersDb->fetch())
269 $collection[$user[
'ID']] = $user;
280 if($salt = \COption::GetOptionString(
'calendar',
'pub_event_salt'))
285 $salt = uniqid(
'',
true);
286 \COption::SetOptionString(
'calendar',
'pub_event_salt', $salt);
296 public static function getHashForPubEvent(
int $eventId,
int $userId,
int $dateCreateTimestamp): string
298 return md5($eventId.self::getSaltForPubLink().$dateCreateTimestamp.$userId);
307 public static function getPubEventLink(
int $eventId,
int $userId,
int $dateCreateTimestamp): string
309 $context = \Bitrix\Main\Application::getInstance()->getContext();
310 $scheme = $context->getRequest()->isHttps() ?
'https' :
'http';
311 $server = $context->getServer();
312 $domain = $server->getServerName() ?: \COption::getOptionString(
'main',
'server_name',
'');
314 if (preg_match(
'/^(?<domain>.+):(?<port>\d+)$/', $domain, $matches))
316 $domain = $matches[
'domain'];
317 $port = $matches[
'port'];
321 $port = $server->getServerPort();
324 $port = in_array((
int)$port, [80, 443],
true) ?
'' :
":{$port}";
326 return "{$scheme}://{$domain}{$port}/pub/calendar-event/{$eventId}/".self::getHashForPubEvent($eventId, $userId, $dateCreateTimestamp).
"/";
335 public static function getDetailLink(
int $eventId,
int $userId,
int $dateCreateTimestamp): string
349 return self::getDetailLink($eventId, $userId, $dateCreateTimestamp) .
"?decision={$decision}";
365 global $USER_FIELD_MANAGER;
367 $UF = $USER_FIELD_MANAGER->GetUserFields(
"CALENDAR_EVENT", $parentId, LANGUAGE_ID);
368 $attachedFilesIds = $UF[
'UF_WEBDAV_CAL_EVENT'][
'VALUE'];
370 $fields[
'UF_WEBDAV_CAL_EVENT'] ??=
null;
371 if (is_array($fields) && is_array($fields[
'UF_WEBDAV_CAL_EVENT']) && is_array($attachedFilesIds))
373 $ufIds = array_unique(array_merge($fields[
'UF_WEBDAV_CAL_EVENT'], $attachedFilesIds));
375 elseif(is_array($fields) && is_array($fields[
'UF_WEBDAV_CAL_EVENT']))
377 $ufIds = $fields[
'UF_WEBDAV_CAL_EVENT'];
379 elseif(is_array($attachedFilesIds))
381 $ufIds = $attachedFilesIds;
385 return $attachCollection;
388 if (!empty($ufIds) && \
Bitrix\Main\Loader::includeModule(
'disk'))
390 foreach ($ufIds as $item)
392 [$type, $realValue] = \Bitrix\Disk\Uf\FileUserType::detectType($item);
394 if ($type == FileUserType::TYPE_ALREADY_ATTACHED)
396 $attachedModel = AttachedObject::loadById($realValue);
398 || (!empty($fields[
'UF_WEBDAV_CAL_EVENT'])
400 && !in_array($item, $fields[
'UF_WEBDAV_CAL_EVENT'])))
402 $isChangeFiles =
true;
405 $file = $attachedModel->getFile();
407 elseif ($type == \
Bitrix\Disk\Uf\FileUserType::TYPE_NEW_OBJECT)
409 $isChangeFiles =
true;
410 $file = \Bitrix\Disk\File::loadById($realValue, [
'STORAGE']);
418 $externalLink = $file->addExternalLink([
419 'CREATED_BY' => $userId,
420 'TYPE' => \
Bitrix\Disk\Internals\ExternalLinkTable::TYPE_MANUAL,
427 $name = $file->getName();
428 $size = $file->getSize();
429 $link = \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink([
430 'hash' => $externalLink->getHash(),
431 'action' =>
'downloadFile',
438 $attachCollection->add($attach);
442 return $attachCollection;
452 $query = EventTable::query()
455 'USER_NAME' =>
'USER.NAME',
456 'USER_LAST_NAME' =>
'USER.LAST_NAME',
457 'USER_EMAIL' =>
'USER.EMAIL',
459 ->registerRuntimeField(
463 UserTable::getEntity(),
464 Join::on(
'this.OWNER_ID',
'ref.ID'),
465 [
'join_type' => Join::TYPE_INNER]
468 ->setFilter([
'USER.ID'=>$userId,
'=PARENT_ID'=>$eventParentId])
471 $attendee = $query->fetch();
473 if (is_null($attendee))
478 return Attendee::createInstance(
479 $attendee[
'USER_EMAIL'],
480 $attendee[
'USER_NAME'],
481 $attendee[
'USER_LAST_NAME'],
482 Dictionary::ATTENDEE_STATUS[$attendee[
'MEETING_STATUS']],
483 Dictionary::ATTENDEE_ROLE[
'REQ_PARTICIPANT'],
484 Dictionary::ATTENDEE_CUTYPE[
'individual'],
485 $attendee[
'USER_EMAIL'],
497 $attendeesCollection = AttendeesCollection::createInstance();
498 $attendeesDb = $DB->query(
'select event.MEETING_STATUS, user.NAME, user.LAST_NAME, user.EMAIL from b_calendar_event as event JOIN b_user as user ON event.OWNER_ID = user.ID where event.PARENT_ID = '. $parentId);
499 while ($attendee = $attendeesDb->fetch())
501 $attendeesCollection->add(Attendee::createInstance(
504 $attendee[
'LAST_NAME'],
505 Dictionary::ATTENDEE_STATUS[$attendee[
'MEETING_STATUS']],
506 Dictionary::ATTENDEE_ROLE[
'REQ_PARTICIPANT'],
507 Dictionary::ATTENDEE_CUTYPE[
'individual'],
512 return $attendeesCollection;
535 return new Date($date, self::ICAL_DATE_FORMAT);
549 'EMAIL' => $userInfo[
'EMAIL'],
555 $userDd = UserTable::getList($parameters);
556 if ($user = $userDd->fetch())
558 return (
int)$user[
'ID'];
581 || empty($params[
'EMAIL'])
582 || !check_email($params[
'EMAIL'])
583 || !Loader::includeModule(
'mail')
589 $userEmail = $params[
'EMAIL'];
593 || !check_email($userEmail)
599 $res = \CUser::getList(
603 "=EMAIL" => $userEmail,
607 "FIELDS" => [
"ID",
"EXTERNAL_AUTH_ID",
"ACTIVE" ]
611 while (($emailUser = $res->fetch()) && !$userId)
614 (
int)$emailUser[
"ID"] > 0
616 $emailUser[
"ACTIVE"] ===
"Y"
617 || $emailUser[
"EXTERNAL_AUTH_ID"] ===
"email"
621 if ($emailUser[
"ACTIVE"] ===
"N")
624 $user->update($emailUser[
"ID"], [
629 $userId = $emailUser[
'ID'];
636 'EMAIL' => $userEmail,
637 'NAME' => $params[
"NAME"] ??
'',
638 'LAST_NAME' => $params[
"LAST_NAME"] ??
''
642 $user = \Bitrix\Mail\User::create($userFields);
643 $errorMessage =
false;
644 if (is_object($user) && $user->LAST_ERROR !==
'')
646 $errorMessage = $user->LAST_ERROR;
649 if (!$errorMessage && (
int)$user > 0)
651 $userId = (int)$user;
655 $errorText = $errorMessage;
659 if (!is_object($user) && (int)$userId > 0)
661 \Bitrix\Main\UI\Selector\Entities::save([
663 'code' =>
'U'.$userId
684 $event = EventTable::getList([
685 'filter' => [
'=ID' => $eventId,],
686 'select' => [
'DESCRIPTION'],
690 return is_array($event)
691 ? $event[
'DESCRIPTION']
708 $event = EventTable::query()
742 ->setFilter([
'=ID' => $eventId])
779 : mb_strtoupper($date->
format(
'M'))
782 return is_string($month)
format(string $format=null)
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 getDetailLink(int $eventId, int $userId, int $dateCreateTimestamp)
static isNotEndOfTime($until)
static getEventByUId(?string $uid)
static getHashForPubEvent(int $eventId, int $userId, int $dateCreateTimestamp)
static getPubEventLinkWithParameters(int $eventId, int $userId, int $dateCreateTimestamp, string $decision)
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 getSaltForPubLink()
static getEventDescriptionById(?int $eventId)
static getPubEventLink(int $eventId, int $userId, int $dateCreateTimestamp)
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 getMessage($code, $replace=null, $language=null)
static getExternalUserTypes()