static function getEventForViewInterface($entryId, $params = [])
{
$params['eventDate'] = ($params['eventDate'] ?? null);
$params['timezoneOffset'] = ($params['timezoneOffset'] ?? null);
$params['userId'] = ($params['userId'] ?? null);
$fromTs = CCalendar::Timestamp($params['eventDate']) - $params['timezoneOffset'];
$userDateFrom = CCalendar::Date($fromTs);
$entry = self::GetList([
'arFilter' => [
"ID" => $entryId,
"DELETED" => "N",
"FROM_LIMIT" => $userDateFrom,
"TO_LIMIT" => $userDateFrom
],
'parseRecursion' => true,
'maxInstanceCount' => 1,
'preciseLimits' => true,
'fetchAttendees' => true,
'checkPermissions' => true,
'setDefaultLimit' => false,
'getUserfields' => true,
]);
if (
$params['eventDate']
&& isset($entry[0])
&& is_array($entry[0])
&& $entry[0]['RRULE']
&& $entry[0]['EXDATE']
&& in_array($params['eventDate'], self::GetExDate($entry[0]['EXDATE']))
)
{
$entry = self::GetList([
'arFilter' => [
"RECURRENCE_ID" => $entryId,
"DELETED" => "N",
"FROM_LIMIT" => $params['eventDate'],
"TO_LIMIT" => $params['eventDate']
],
'parseRecursion' => true,
'maxInstanceCount' => 1,
'preciseLimits' => true,
'fetchAttendees' => true,
'checkPermissions' => true,
'setDefaultLimit' => false,
'getUserfields' => true,
]);
}
if (!$entry || !is_array($entry[0]))
{
$entry = self::GetList([
'arFilter' => [
"ID" => $entryId,
"DELETED" => "N"
],
'parseRecursion' => true,
'maxInstanceCount' => 1,
'fetchAttendees' => true,
'checkPermissions' => true,
'setDefaultLimit' => false,
'getUserfields' => true,
]);
}
// Here we can get events with wrong RRULE ('parseRecursion' => false)
if (!$entry || !is_array($entry[0]))
{
$entry = self::GetList([
'arFilter' => [
"ID" => $entryId,
"DELETED" => "N"
],
'parseRecursion' => false,
'fetchAttendees' => true,
'checkPermissions' => true,
'setDefaultLimit' => false,
'getUserfields' => true,
]);
}
if ($entry && is_array($entry[0]))
{
$entry = $entry[0];
if ($entry['IS_MEETING'] && (int)$entry['PARENT_ID'] !== (int)$entry['ID'])
{
$parentEntry = false;
$parentEntryList = self::GetList([
'arFilter' => [
"ID" => (int)$entry['PARENT_ID'],
],
'parseRecursion' => false,
'maxInstanceCount' => 1,
'preciseLimits' => false,
'fetchAttendees' => true,
'checkPermissions' => true,
'setDefaultLimit' => false,
'getUserfields' => true,
]);
if (!empty($parentEntryList[0]) && is_array($parentEntryList[0]))
{
$parentEntry = $parentEntryList[0];
}
if ($parentEntry)
{
if ($parentEntry['DELETED'] === 'Y')
{
self::CleanEventsWithDeadParents();
$entry = false;
}
if ((int)$parentEntry['MEETING_HOST'] === (int)$params['userId'])
{
$entry = $parentEntry;
}
}
}
if (
isset($entry['UF_WEBDAV_CAL_EVENT'])
&& is_array($entry['UF_WEBDAV_CAL_EVENT'])
&& empty($entry['UF_WEBDAV_CAL_EVENT'])
)
{
$entry['UF_WEBDAV_CAL_EVENT'] = null;
}
}
if (
($entry['IS_MEETING'] ?? null)
&& !empty($entry['ATTENDEE_LIST'])
&& is_array($entry['ATTENDEE_LIST'])
&& $entry['CREATED_BY'] !== $params['userId']
&& ($params['recursion'] ?? null) !== false
)
{
foreach($entry['ATTENDEE_LIST'] as $attendee)
{
if ((int)$attendee['id'] === (int)$params['userId'])
{
$entry = self::GetList([
'arFilter' => [
"PARENT_ID" => $entry['PARENT_ID'],
"CREATED_BY" => $params['userId'],
"DELETED" => "N"
],
'parseRecursion' => false,
'maxInstanceCount' => 1,
'preciseLimits' => false,
'fetchAttendees' => false,
'checkPermissions' => true,
'setDefaultLimit' => false,
'getUserfields' => true,
]);
if ($entry && is_array($entry[0]) && $entry[0]['CAL_TYPE'] === 'location')
{
$params['recursion'] = false;
$entry = self::getEventForViewInterface($entry[0]['PARENT_ID'], $params);
}
else if ($entry && is_array($entry[0]))
{
$params['recursion'] = false;
$entry = self::getEventForViewInterface($entry[0]['ID'], $params);
}
}
}
}
return $entry;
}