2namespace Bitrix\Calendar;
4use Bitrix\Calendar\Core\Event\Tools\Dictionary;
5use Bitrix\Calendar\Integration\Pull\PushCommand;
6use Bitrix\Calendar\Integration\Pull\PushService;
7use Bitrix\Calendar\Sync\Util\MsTimezoneConverter;
8use Bitrix\Extranet\Service\ServiceContainer;
10use Bitrix\Main\Application;
11use Bitrix\Main\Loader;
12use Bitrix\Main\LoaderException;
13use Bitrix\Main\Localization\LanguageTable;
14use Bitrix\Main\Localization\Loc;
15use Bitrix\Main\Text\Emoji;
16use Bitrix\Main\Type\Date;
17use Bitrix\Main\Type\DateTime;
29 private static $requestUid =
'';
30 private static $userAccessCodes = [];
31 private static $pathCache = [];
32 private static $isRussian =
null;
41 return in_array(
'IU'.
$userId, self::getUserAccessCodes($managerId));
51 return \Bitrix\Main\Config\Option::get(
'calendar',
'sectionStructureConverted',
'N') ===
'Y';
60 public static function getTimestamp($date, $round =
true, $getTime =
true)
62 $timestamp =
MakeTimeStamp($date, \CSite::getDateFormat($getTime ?
"FULL" :
"SHORT"));
64 return $round ? (round($timestamp / 60) * 60) : $timestamp;
73 return (!is_null($timeZone) && $timeZone !==
'false' && in_array($timeZone, timezone_identifiers_list(),
true));
84 return new \DateTimeZone(self::DEFAULT_TIMEZONE);
87 if (self::isTimezoneValid($tz))
89 return new \DateTimeZone($tz);
94 return new \DateTimeZone($timezones[0]);
97 return new \DateTimeZone(self::getServerTimezoneName());
107 public static function getDateObject(
string $date =
null, ?
bool $fullDay =
true, ?
string $tz =
'UTC'):
Date
109 $preparedDate = $date;
112 $timestamp = \CCalendar::Timestamp($date,
false, !$fullDay);
113 $preparedDate = \CCalendar::Date($timestamp, !$fullDay);
126 return self::USER_SELECTOR_CONTEXT;
131 if (!is_null(self::$isRussian))
133 return self::$isRussian;
138 self::$isRussian = (\CBitrix24::getPortalZone() ===
'ru');
144 'filter' => [
'=ID' =>
'ru',
'=ACTIVE' =>
'Y']
150 self::$isRussian =
false;
156 'filter' => [
'@ID' => [
'ua',
'by',
'kz'],
'=ACTIVE' =>
'Y'],
160 self::$isRussian = empty($row);
164 return self::$isRussian;
170 if (is_array($entityList))
172 foreach($entityList as
$entity)
174 if (
$entity[
'entityId'] ===
'meta-user' &&
$entity[
'id'] ===
'all-users')
180 $codeList[] =
'U'.$entity[
'id'];
184 $codeList[] =
'SG'.$entity[
'id'];
188 $codeList[] =
'DR'.$entity[
'id'];
198 if (is_array($codeList))
200 foreach($codeList as
$code)
205 'entityId' =>
'meta-user',
212 'entityId' =>
'user',
213 'id' => intval(mb_substr(
$code, 1))
216 if (mb_substr(
$code, 0, 2) ==
'DR')
219 'entityId' =>
'department',
220 'id' => intval(mb_substr(
$code, 2))
223 elseif (preg_match(
'/^SG([0-9]+)_?([AEKMO])?$/',
$code, $match) && isset($match[2]))
227 'entityId' =>
'project-roles',
228 'id' => mb_substr(
$code, 2)
234 'entityId' =>
'project',
235 'id' => intval(mb_substr(
$code, 2))
246 return \CCalendar::GetDestinationUsers(self::convertEntitiesToCodes($entityList), $fetchUsers);
252 $entityList = [[
'entityId' =>
'user',
'id' =>
$userId]];
255 $entityList[] = [
'entityId' =>
'user',
'id' => $ownerId];
257 else if(
$type ===
'group')
259 $entityList[] = [
'entityId' =>
'project',
'id' => $ownerId];
274 if (empty($codeAttendees))
282 foreach ($codeAttendees as $codeAttend)
284 if (mb_strpos($codeAttend,
'U') === 0)
286 $userId = (int)(mb_substr($codeAttend, 1));
291 if (!empty($userIdList))
295 '=ID' => $userIdList,
297 'select' => [
'NAME',
'LAST_NAME'],
302 $userList[] = addcslashes($stringWrapper .
$user[
'NAME'].
' '.
$user[
'LAST_NAME'] . $stringWrapper,
"()");
319 if (Loader::includeModule(
'intranet'))
321 $userDb = \Bitrix\Intranet\UserTable::getList([
330 $user = $userDb->fetch();
331 return $user[
'USER_TYPE'] ===
'extranet';
339 return Loader::includeModule(
'extranet')
340 && ServiceContainer::getInstance()->getCollaberService()->isCollaberById(
$userId);
352 $eventDb = Internals\EventTable::getList([
358 if (
$event = $eventDb->fetch())
360 if (!empty(
$event[
'NAME']))
364 if (!empty(
$event[
'DESCRIPTION']))
366 $event[
'DESCRIPTION'] = Emoji::decode(
$event[
'DESCRIPTION']);
368 if (!empty(
$event[
'LOCATION']))
387 if (!Loader::includeModule(
"pull"))
393 in_array($command->value, [
394 PushCommand::EditEvent->value,
395 PushCommand::DeleteEvent->value,
396 PushCommand::SetMeetingStatus->value,
400 PushService::addEventByTag(
'calendar-planner-'.
$userId, [
401 'module_id' => PushService::MODULE_ID,
402 'command' => $command->value,
406 if (isset(
$params[
'fields'][
'CAL_TYPE']) &&
$params[
'fields'][
'CAL_TYPE'] ===
'location')
408 PushService::addEventByTag(
'calendar-location', [
409 'module_id' => PushService::MODULE_ID,
410 'command' =>
"{$command->value}_location",
413 'DATE_FROM' =>
$params[
'fields'][
'DATE_FROM'],
414 'DATE_TO' =>
$params[
'fields'][
'DATE_TO'],
415 'EXDATE' =>
$params[
'fields'][
'EXDATE'],
423 isset(
$params[
'fields'][
'SECTION_OWNER_ID'])
425 && in_array($command->value, [
426 PushCommand::EditEvent->value,
427 PushCommand::DeleteEvent->value,
428 PushCommand::SetMeetingStatus->value,
432 PushService::addEvent((
int)
$params[
'fields'][
'SECTION_OWNER_ID'], [
433 'module_id' => PushService::MODULE_ID,
434 'command' => $command->value,
439 PushService::addEvent(
$userId, [
440 'module_id' => PushService::MODULE_ID,
441 'command' => $command->value,
454 if (Loader::includeModule(
"pull"))
456 foreach($userIdList as
$userId)
458 if ((
int)
$userId !== $currentUserId)
460 \CPullWatch::Add($currentUserId,
'calendar-planner-'.
$userId);
470 $strSql =
"SELECT * from b_uts_calendar_event WHERE VALUE_ID=" . $eventId;
471 $ufDb =
$DB->query($strSql);
473 while ($uf = $ufDb->fetch())
476 'crm' => unserialize($uf[
'UF_CRM_CAL_EVENT'], [
'allowed_classes' =>
false]),
477 'webdav' => unserialize($uf[
'UF_WEBDAV_CAL_EVENT'], [
'allowed_classes' =>
false]),
489 return (
new \
DateTime())->getTimezone()->getName();
497 return (
new \
DateTime())->getOffset();
508 if ($date instanceof
Date)
510 $timestamp = $date->format(self::DATETIME_PHP_FORMAT);
518 $timestamp =
"@".(int)$date;
521 $date = new \DateTime($timestamp, self::prepareTimezone($tz));
531 self::$requestUid = $requestUid;
539 return self::$requestUid;
552 $userId = \CCalendar::GetCurUserId();
555 if (!isset(self::$userAccessCodes[
$userId]))
558 $r = \CAccess::GetUserCodes(
$userId);
559 while(
$code = $r->Fetch())
561 $codes[] =
$code[
'ACCESS_CODE'];
564 if (!in_array(
'G2', $codes))
579 self::$userAccessCodes[
$userId] = $codes;
582 return self::$userAccessCodes[
$userId];
594 if (!isset(self::$pathCache[
$key]) || !is_string(self::$pathCache[
$key]))
596 if (
$type === Dictionary::CALENDAR_TYPE[
'user'] ||
$type === Dictionary::CALENDAR_TYPE[
'open_event'])
598 $path = \COption::GetOptionString(
600 'path_to_user_calendar',
601 \COption::getOptionString(
'socialnetwork',
'user_page',
"/company/personal/")
602 .
"user/#user_id#/calendar/"
605 else if (
$type === Dictionary::CALENDAR_TYPE[
'group'])
607 $path = \COption::GetOptionString(
609 'path_to_group_calendar',
610 \COption::getOptionString(
'socialnetwork',
'workgroups_page',
"/workgroups/")
611 .
"group/#group_id#/calendar/"
614 else if (in_array(
$type, [
'company',
'company_calendar',
'calendar_company'],
true))
616 $path =
'/calendar/';
624 if (!\COption::GetOptionString(
'calendar',
'pathes_for_sites',
true))
626 $siteId = \CCalendar::GetSiteId();
627 $pathList = \CCalendar::GetPathes();
630 if (
$type === Dictionary::CALENDAR_TYPE[
'user'] && !empty($pathList[
$siteId][
'path_to_user_calendar']))
634 else if (
$type === Dictionary::CALENDAR_TYPE[
'group'] && !empty($pathList[
$siteId][
'path_to_group_calendar']))
638 else if (!empty($pathList[
$siteId][
'path_to_type_company_calendar']) && in_array(
$type, [
'company',
'company_calendar',
'calendar_company'],
true))
640 $path = $pathList[
$siteId][
'path_to_type_company_calendar'];
642 else if (!empty($pathList[
$siteId][
'path_to_type_' .
$type]))
649 if (!is_string(
$path))
659 if (
$type === Dictionary::CALENDAR_TYPE[
'user'])
661 $path = str_replace([
'#user_id#',
'#USER_ID#'], $ownerId,
$path);
663 elseif (
$type === Dictionary::CALENDAR_TYPE[
'group'])
665 $path = str_replace([
'#group_id#',
'#GROUP_ID#'], $ownerId,
$path);
668 elseif (
$type === Dictionary::CALENDAR_TYPE[
'open_event'])
670 $path = str_replace([
'#user_id#',
'#USER_ID#'], $ownerId,
$path);
677 return self::$pathCache[
$key];
685 return COption::getOptionString(
'main',
'server_name', Application::getInstance()->getContext()->getServer()->
getServerName());
695 $day = $second / 24 / 3600;
696 $hours = $second / 3600 - (int)$day * 24;
697 $min = $second / 60 - (int)$day * 24 * 60 - (
int)
$hours * 60;
702 'minutes' => (int)$min
713 $day = $minutes / 24 / 60;
714 $hours = $minutes / 60 - (int)$day * 24;
715 $min = $minutes - (int)$day * 24 * 60 - (
int)
$hours * 60;
720 'minutes' => (int)$min
726 if (!$dateFrom || !$timezone)
731 $date = new \Bitrix\Calendar\Core\Base\Date(
739 return $date->getTimestamp();
744 $timezone = new \DateTimeZone($timezoneName);
747 return (
new \
DateTime(
'now', $timezone))
748 ->setTimestamp($timestamp)
749 ->format($dateTimeFormat)
757 return gmdate($dateTimeFormat, $timestamp);
762 $dateFormat = Date::convertFormatToPhp(
FORMAT_DATE);
764 return gmdate($dateFormat, $timestamp);
769 $utc = new \DateTimeZone(
'UTC');
771 return (
new \DateTimeZone($timezoneName))->getOffset(
new \
DateTime(
'now', $utc));
777 $dateTimestampUTC = $date->
getTimestamp() + \CCalendar::GetTimezoneOffset($dateTimezone);
778 $eventOffsetUTC = \CCalendar::GetTimezoneOffset($eventTimezone);
780 return $dateTimestampUTC - $eventOffsetUTC;
787 $timeFormat =
$culture->get(
'SHORT_TIME_FORMAT');
792 return "$eventDate $eventTime";
797 $skipTime =
$event[
'DT_SKIP_TIME'] ===
"Y";
802 (
int)
$event[
'~USER_OFFSET_FROM'] !== 0
803 || (
int)
$event[
'~USER_OFFSET_TO'] !== 0
805 ||
$event[
'TZ_FROM'] !== \CCalendar::GetUserTimezoneName(
$userId)
811 $timezoneHint = \CCalendar::GetFromToHtml(
812 \CCalendar::Timestamp(
$event[
'DATE_FROM']),
813 \CCalendar::Timestamp(
$event[
'DATE_TO']),
819 $timezoneHint .=
' (' .
$event[
'TZ_FROM'] .
')';
824 $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'].
')'));
828 return $timezoneHint;
847 $startsInside = $from2 <= $from1 && $from1 < $to2;
848 $endsInside = $from2 < $to1 && $to1 <= $to2;
849 $startsBeforeEndsAfter = $from1 <= $from2 && $to1 >= $to2;
851 return $startsInside || $endsInside || $startsBeforeEndsAfter;
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
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 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 addPullEvent(PushCommand $command, int $userId, array $params=[])
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 isCollabUser(int $userId)
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 isModuleInstalled($moduleName)
static getList(array $parameters=array())
static convertFormatToPhp($format)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
MakeTimeStamp($datetime, $format=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']