24 private static $requestUid =
'';
25 private static $userAccessCodes = [];
26 private static $pathCache = [];
27 private static $isRussian =
null;
36 return in_array(
'IU'.$userId, self::getUserAccessCodes($managerId));
46 return \Bitrix\Main\Config\Option::get(
'calendar',
'sectionStructureConverted',
'N') ===
'Y';
55 public static function getTimestamp($date, $round =
true, $getTime =
true)
57 $timestamp = MakeTimeStamp($date, \CSite::getDateFormat($getTime ?
"FULL" :
"SHORT"));
59 return $round ? (round($timestamp / 60) * 60) : $timestamp;
68 return (!is_null($timeZone) && $timeZone !==
'false' && in_array($timeZone, timezone_identifiers_list(),
true));
79 return new \DateTimeZone(self::DEFAULT_TIMEZONE);
82 if (self::isTimezoneValid($tz))
84 return new \DateTimeZone($tz);
89 return new \DateTimeZone($timezones[0]);
92 return new \DateTimeZone(self::getServerTimezoneName());
102 public static function getDateObject(
string $date =
null, ?
bool $fullDay =
true, ?
string $tz =
'UTC'):
Date
104 $preparedDate = $date;
107 $timestamp = \CCalendar::Timestamp($date,
false, !$fullDay);
108 $preparedDate = \CCalendar::Date($timestamp, !$fullDay);
112 ?
new Date($preparedDate, Date::convertFormatToPhp(FORMAT_DATE))
126 if (!is_null(self::$isRussian))
128 return self::$isRussian;
133 self::$isRussian = (\CBitrix24::getPortalZone() ===
'ru');
139 'filter' => [
'=ID' =>
'ru',
'=ACTIVE' =>
'Y']
142 $row = $iterator->fetch();
145 self::$isRussian =
false;
151 'filter' => [
'@ID' => [
'ua',
'by',
'kz'],
'=ACTIVE' =>
'Y'],
154 $row = $iterator->fetch();
155 self::$isRussian = empty($row);
159 return self::$isRussian;
165 if (is_array($entityList))
167 foreach($entityList as $entity)
169 if ($entity[
'entityId'] ===
'meta-user' && $entity[
'id'] ===
'all-users')
173 elseif ($entity[
'entityId'] ===
'user')
175 $codeList[] =
'U'.$entity[
'id'];
177 elseif ($entity[
'entityId'] ===
'project' || $entity[
'entityId'] ===
'project-roles')
179 $codeList[] =
'SG'.$entity[
'id'];
181 elseif ($entity[
'entityId'] ===
'department')
183 $codeList[] =
'DR'.$entity[
'id'];
193 if (is_array($codeList))
195 foreach($codeList as $code)
200 'entityId' =>
'meta-user',
204 elseif (mb_substr($code, 0, 1) ==
'U')
207 'entityId' =>
'user',
208 'id' => intval(mb_substr($code, 1))
211 if (mb_substr($code, 0, 2) ==
'DR')
214 'entityId' =>
'department',
215 'id' => intval(mb_substr($code, 2))
218 elseif (preg_match(
'/^SG([0-9]+)_?([AEKMO])?$/', $code, $match) && isset($match[2]))
222 'entityId' =>
'project-roles',
223 'id' => mb_substr($code, 2)
226 elseif (mb_substr($code, 0, 2) ==
'SG')
229 'entityId' =>
'project',
230 'id' => intval(mb_substr($code, 2))
241 return \CCalendar::GetDestinationUsers(self::convertEntitiesToCodes($entityList), $fetchUsers);
247 $entityList = [[
'entityId' =>
'user',
'id' => $userId]];
248 if ($type ===
'user' && $ownerId !== $userId)
250 $entityList[] = [
'entityId' =>
'user',
'id' => $ownerId];
252 else if($type ===
'group')
254 $entityList[] = [
'entityId' =>
'project',
'id' => $ownerId];
267 public static function getAttendees(array $codeAttendees =
null,
string $stringWrapper =
''): array
269 if (empty($codeAttendees))
277 foreach ($codeAttendees as $codeAttend)
279 if (mb_strpos($codeAttend,
'U') === 0)
281 $userId = (int)(mb_substr($codeAttend, 1));
282 $userIdList[] = $userId;
286 if (!empty($userIdList))
288 $res = \Bitrix\Main\UserTable::getList(array(
290 '=ID' => $userIdList,
292 'select' => [
'NAME',
'LAST_NAME'],
295 while ($user = $res->fetch())
297 $userList[] = addcslashes($stringWrapper . $user[
'NAME'].
' '.$user[
'LAST_NAME'] . $stringWrapper,
"()");
314 if (Loader::includeModule(
'intranet'))
316 $userDb = \Bitrix\Intranet\UserTable::getList([
325 $user = $userDb->fetch();
326 return $user[
'USER_TYPE'] ===
'extranet';
341 $eventDb = Internals\EventTable::getList([
347 if ($event = $eventDb->fetch())
349 if (!empty($event[
'NAME']))
351 $event[
'NAME'] = Emoji::decode($event[
'NAME']);
353 if (!empty($event[
'DESCRIPTION']))
355 $event[
'DESCRIPTION'] = Emoji::decode($event[
'DESCRIPTION']);
357 if (!empty($event[
'LOCATION']))
359 $event[
'LOCATION'] = Emoji::decode($event[
'LOCATION']);
373 public static function addPullEvent(
string $command,
int $userId, array $params = []): bool
375 if (!Loader::includeModule(
"pull"))
384 'set_meeting_status',
388 \CPullWatch::AddToStack(
389 'calendar-planner-'.$userId,
391 'module_id' =>
'calendar',
392 'command' => $command,
402 'set_meeting_status',
404 && isset($params[
'fields'])
405 && isset($params[
'fields'][
'SECTION_OWNER_ID'])
406 && (
int)$params[
'fields'][
'SECTION_OWNER_ID'] !== $userId
409 \Bitrix\Pull\Event::add(
410 (
int)$params[
'fields'][
'SECTION_OWNER_ID'],
412 'module_id' =>
'calendar',
413 'command' => $command,
419 return \Bitrix\Pull\Event::add(
422 'module_id' =>
'calendar',
423 'command' => $command,
437 if (Loader::includeModule(
"pull"))
439 foreach($userIdList as $userId)
441 if ((
int)$userId !== $currentUserId)
443 \CPullWatch::Add($currentUserId,
'calendar-planner-'.$userId);
453 $strSql =
"SELECT * from b_uts_calendar_event WHERE VALUE_ID=" . $eventId;
454 $ufDb = $DB->query($strSql);
456 while ($uf = $ufDb->fetch())
459 'crm' => unserialize($uf[
'UF_CRM_CAL_EVENT'], [
'allowed_classes' =>
false]),
460 'webdav' => unserialize($uf[
'UF_WEBDAV_CAL_EVENT'], [
'allowed_classes' =>
false]),
472 return (
new \
DateTime())->getTimezone()->getName();
480 return (
new \
DateTime())->getOffset();
491 if ($date instanceof
Date)
493 $timestamp = $date->format(self::DATETIME_PHP_FORMAT);
495 elseif ($date ===
null)
501 $timestamp =
"@".(int)$date;
504 $date = new \DateTime($timestamp, self::prepareTimezone($tz));
514 self::$requestUid = $requestUid;
522 return self::$requestUid;
532 $userId = (int)$userId;
535 $userId = \CCalendar::GetCurUserId();
538 if (!isset(self::$userAccessCodes[$userId]))
541 $r = \CAccess::GetUserCodes($userId);
542 while($code = $r->Fetch())
544 $codes[] = $code[
'ACCESS_CODE'];
547 if (!in_array(
'G2', $codes))
552 if (!in_array(
'AU', $codes) && $USER && (
int)$USER->GetId() === $userId)
557 if(!in_array(
'UA', $codes) && $USER && (
int)$USER->GetId() == $userId)
562 self::$userAccessCodes[$userId] = $codes;
565 return self::$userAccessCodes[$userId];
576 $key = $type . $ownerId;
577 if (!isset(self::$pathCache[$key]) || !is_string(self::$pathCache[$key]))
579 if ($type ===
'user')
581 $path = \COption::GetOptionString(
583 'path_to_user_calendar',
584 \COption::getOptionString(
'socialnetwork',
'user_page',
"/company/personal/")
585 .
"user/#user_id#/calendar/"
588 elseif ($type ===
'group')
590 $path = \COption::GetOptionString(
592 'path_to_group_calendar',
593 \COption::getOptionString(
'socialnetwork',
'workgroups_page',
"/workgroups/")
594 .
"group/#group_id#/calendar/"
599 $settings = \CCalendar::GetSettings();
600 $path = $settings[
'path_to_type_' . $type] ??
null;
603 if (!\COption::GetOptionString(
'calendar',
'pathes_for_sites',
true))
605 $siteId = \CCalendar::GetSiteId();
606 $pathList = \CCalendar::GetPathes();
607 if (isset($pathList[$siteId]))
609 if ($type ===
'user' && isset($pathList[$siteId][
'path_to_user_calendar']))
611 $path = $pathList[$siteId][
'path_to_user_calendar'];
613 elseif ($type ===
'group' && isset($pathList[$siteId][
'path_to_group_calendar']))
615 $path = $pathList[$siteId][
'path_to_group_calendar'];
617 else if (!empty($pathList[$siteId][
'path_to_type_' . $type]))
619 $path = $pathList[$siteId][
'path_to_type_' . $type];
624 if (!is_string($path))
629 if (!empty($path) && $ownerId > 0)
631 if ($type ===
'user')
633 $path = str_replace([
'#user_id#',
'#USER_ID#'], $ownerId, $path);
635 elseif ($type ===
'group')
637 $path = str_replace([
'#group_id#',
'#GROUP_ID#'], $ownerId, $path);
640 self::$pathCache[$key] = $path;
643 return self::$pathCache[$key];
661 $day = $second / 24 / 3600;
662 $hours = $second / 3600 - (int)$day * 24;
663 $min = $second / 60 - (int)$day * 24 * 60 - (
int)$hours * 60;
667 'hours' => (
int)$hours,
668 'minutes' => (int)$min
679 $day = $minutes / 24 / 60;
680 $hours = $minutes / 60 - (int)$day * 24;
681 $min = $minutes - (int)$day * 24 * 60 - (
int)$hours * 60;
685 'hours' => (
int)$hours,
686 'minutes' => (int)$min
692 if (!$dateFrom || !$timezone)
697 $date = new \Bitrix\Calendar\Core\Base\Date(
705 return $date->getTimestamp();
710 $timezone = new \DateTimeZone($timezoneName);
711 $dateTimeFormat = Date::convertFormatToPhp(FORMAT_DATETIME);
713 return (
new \
DateTime(
'now', $timezone))
714 ->setTimestamp($timestamp)
715 ->format($dateTimeFormat)
721 $dateTimeFormat = Date::convertFormatToPhp(FORMAT_DATETIME);
723 return gmdate($dateTimeFormat, $timestamp);
728 $dateFormat = Date::convertFormatToPhp(FORMAT_DATE);
730 return gmdate($dateFormat, $timestamp);
735 $utc = new \DateTimeZone(
'UTC');
737 return (
new \DateTimeZone($timezoneName))->getOffset(
new \
DateTime(
'now', $utc));
743 $dateTimestampUTC = $date->
getTimestamp() + \CCalendar::GetTimezoneOffset($dateTimezone);
744 $eventOffsetUTC = \CCalendar::GetTimezoneOffset($eventTimezone);
746 return $dateTimestampUTC - $eventOffsetUTC;
751 $culture = Main\Application::getInstance()->getContext()->getCulture();
752 $dayMonthFormat = Main\Type\Date::convertFormatToPhp($culture->getDateFormat());
753 $timeFormat = $culture->get(
'SHORT_TIME_FORMAT');
755 $eventDate = FormatDate($dayMonthFormat, $dateTime->
getTimestamp());
756 $eventTime = FormatDate($timeFormat, $dateTime->
getTimestamp());
758 return "$eventDate $eventTime";
763 $skipTime = $event[
'DT_SKIP_TIME'] ===
"Y";
768 (
int)$event[
'~USER_OFFSET_FROM'] !== 0
769 || (
int)$event[
'~USER_OFFSET_TO'] !== 0
770 || $event[
'TZ_FROM'] !== $event[
'TZ_TO']
771 || $event[
'TZ_FROM'] !== \CCalendar::GetUserTimezoneName($userId)
775 if ($event[
'TZ_FROM'] === $event[
'TZ_TO'])
777 $timezoneHint = \CCalendar::GetFromToHtml(
778 \CCalendar::Timestamp($event[
'DATE_FROM']),
779 \CCalendar::Timestamp($event[
'DATE_TO']),
783 if ($event[
'TZ_FROM'])
785 $timezoneHint .=
' (' . $event[
'TZ_FROM'] .
')';
790 $timezoneHint =
Loc::getMessage(
'EC_VIEW_DATE_FROM_TO', array(
'#DATE_FROM#' => $event[
'DATE_FROM'].
' ('.$event[
'TZ_FROM'].
')',
'#DATE_TO#' => $event[
'DATE_TO'].
' ('.$event[
'TZ_TO'].
')'));
794 return $timezoneHint;
799 $culture = Main\Application::getInstance()->getContext()->getCulture();
800 $dayMonthFormat = Main\Type\Date::convertFormatToPhp($culture->getDateFormat());
802 return FormatDate($dayMonthFormat, $dateTime->
getTimestamp());
813 $startsInside = $from2 <= $from1 && $from1 < $to2;
814 $endsInside = $from2 < $to1 && $to1 <= $to2;
815 $startsBeforeEndsAfter = $from1 <= $from2 && $to1 >= $to2;
817 return $startsInside || $endsInside || $startsBeforeEndsAfter;
static getValidateTimezones(string $msTimezone)
static isExtranetUser(int $userId)
static oneIntervalIntersectsAnother($from1, $to1, $from2, $to2)
static isSectionStructureConverted()
static getDefaultEntityList($userId, $type, $ownerId)
static minutesToDayHoursMinutes(int $minutes)
static addPullEvent(string $command, int $userId, array $params=[])
static getTimezoneOffsetFromServer(?string $tz='UTC', $date=null)
static getTimezoneHint(int $userId, array $event)
static formatEventDateTime(DateTime $dateTime)
static getTimezoneOffsetUTC(string $timezoneName)
static getUserSelectorContext()
const USER_SELECTOR_CONTEXT
static getAttendees(array $codeAttendees=null, string $stringWrapper='')
static prepareTimezone(?string $tz=null)
static getEventById(int $eventId)
const DATETIME_PHP_FORMAT
static getServerTimezoneName()
static doIntervalsIntersect($from1, $to1, $from2, $to2)
static isTimezoneValid(?string $timeZone)
static getUsersByEntityList($entityList, $fetchUsers=false)
static getPathToCalendar(?int $ownerId, ?string $type)
static formatDateTimestampUTC(int $timestamp)
static getUserAccessCodes(int $userId)
static getUserFieldsByEventId(int $eventId)
static formatEventDate(DateTime $dateTime)
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
static convertEntitiesToCodes($entityList=[])
static secondsToDayHoursMinutes(int $second)
static formatDateTimeTimestampUTC(int $timestamp)
static convertCodesToEntities($codeList=[])
static getDateTimestamp(?string $dateFrom, ?string $timezone)
static initPlannerPullWatches(int $currentUserId, array $userIdList=[])
static isManagerForUser($managerId, $userId)
const USER_FIELD_ENTITY_ID
static setRequestUid(string $requestUid='')
static formatDateTimeTimestamp(int $timestamp, string $timezoneName)
static getServerOffsetUTC()
static getTimestamp($date, $round=true, $getTime=true)
const LIMIT_NUMBER_BANNER_IMPRESSIONS
static getDateTimestampUtc(DateTime $date, ?string $eventTimezone=null)
static getMessage($code, $replace=null, $language=null)
static isModuleInstalled($moduleName)
static getList(array $parameters=array())