public static function GetEventList($Params = array(), &$arAttendees) { $type = isset($Params['type']) ? $Params['type'] : self::$type; $ownerId = isset($Params['ownerId']) ? $Params['ownerId'] : self::$ownerId; $userId = isset($Params['userId']) ? $Params['userId'] : self::$userId; if ($type != 'user' && !isset($Params['section']) || count($Params['section']) <= 0) return array(); $arFilter = array( //"INCLUDE_INVITINGS" => "Y" ); CCalendarEvent::SetLastAttendees(false); if (isset($Params['fromLimit'])) $arFilter["FROM_LIMIT"] = $Params['fromLimit']; if (isset($Params['toLimit'])) $arFilter["TO_LIMIT"] = $Params['toLimit']; if (isset($Params['section'])) $arFilter["SECTION"] = $Params['section']; if ($type == 'user') $fetchMeetings = in_array(self::GetMeetingSection($ownerId), $Params['section']); else $fetchMeetings = in_array(self::GetCurUserMeetingSection(), $Params['section']); $res = CCalendarEvent::GetList( array( 'arFilter' => $arFilter, 'arSort' => Array('ACTIVE_FROM' => 'ASC'), 'parseRecursion' => true, 'fetchAttendees' => true, 'userId' => $userId, 'fetchMeetings' => $fetchMeetings ) ); // Simple hack. TODO: We have to rid of it after refactoring DB structure $resEventInd = array(); foreach($res as $i => $event) $resEventInd[$event['ID']] = true; // We selecting only meeting events from superpose $resAdd = array(); if (is_array($Params['additonalMeetingsId']) && count($Params['additonalMeetingsId']) > 0) { foreach($Params['additonalMeetingsId'] as $spUser) { if ($spUser['ID'] == $ownerId) continue; unset($arFilter["SECTION"]); $arFilter["IS_MEETING"] = 1; $arFilter["OWNER_ID"] = intVal($spUser['ID']); $res_i = CCalendarEvent::GetList( array( 'arFilter' => $arFilter, 'arSort' => Array('ACTIVE_FROM' => 'ASC'), 'parseRecursion' => true, 'fetchAttendees' => true, 'userId' => $userId, 'fetchMeetings' => true ) ); if (is_array($res_i) && count($res_i) > 0) { foreach($res_i as $i => $event) { if (($event['IS_MEETING'] || $event['~IS_MEETING']) && $event['SECT_ID'] != intVal($spUser['SECTION_ID']) && !$resEventInd[$event['ID']]) { $event['SECT_ID'] = intVal($spUser['SECTION_ID']); $checkPermissionsForEvent = $userId != $event['CREATED_BY']; // It's creator // It's event in user's calendar if ($checkPermissionsForEvent && $event['CAL_TYPE'] == 'user' && $userId == $event['OWNER_ID']) $checkPermissionsForEvent = false; if ($checkPermissionsForEvent && $event['IS_MEETING'] && $event['USER_MEETING'] && $event['USER_MEETING']['ATTENDEE_ID'] == $userId) $checkPermissionsForEvent = false; if ($checkPermissionsForEvent && $event['IS_MEETING'] && is_array($event['~ATTENDEES'])) { foreach($event['~ATTENDEES'] as $att) { if ($att['USER_ID'] == $userId) { $checkPermissionsForEvent = false; break; } } } $event = CCalendarEvent::ApplyAccessRestrictions($event, $userId); $resAdd[] = $event; } } } } } if ($type != 'user' && count($Params['section']) > 0) { $NewRes = array(); foreach($res as $event) { if (in_array($event['SECT_ID'], $Params['section'])) $NewRes[] = $event; } $res = $NewRes; } if(count($resAdd) > 0) $res = array_merge($res, $resAdd); $arAttendees = CCalendarEvent::GetLastAttendees(); return $res; }
public static function GetEventList($Params = array(), &$arAttendees) { $type = isset($Params['type']) ? $Params['type'] : self::$type; $ownerId = isset($Params['ownerId']) ? $Params['ownerId'] : self::$ownerId; $userId = isset($Params['userId']) ? $Params['userId'] : self::$userId; if ($type != 'user' && !isset($Params['section']) || count($Params['section']) <= 0) { return array(); } $arFilter = array(); CCalendarEvent::SetLastAttendees(false); if (isset($Params['fromLimit'])) { $arFilter["FROM_LIMIT"] = $Params['fromLimit']; } if (isset($Params['toLimit'])) { $arFilter["TO_LIMIT"] = $Params['toLimit']; } if (isset($Params['section'])) { $arFilter["SECTION"] = $Params['section']; } if ($type == 'user') { $fetchMeetings = in_array(self::GetMeetingSection($ownerId), $Params['section']); } else { $fetchMeetings = in_array(self::GetCurUserMeetingSection(), $Params['section']); } $res = CCalendarEvent::GetList(array('arFilter' => $arFilter, 'arSort' => array('ACTIVE_FROM' => 'ASC'), 'parseRecursion' => true, 'fetchAttendees' => true, 'userId' => $userId, 'fetchMeetings' => $fetchMeetings)); // Simple hack. TODO: We have to rid of it after refactoring DB structure $resEventInd = array(); foreach ($res as $i => $event) { $resEventInd[$event['ID']] = true; } // We selecting only meeting events from superpose $resAdd = array(); if (is_array($Params['additonalMeetingsId']) && count($Params['additonalMeetingsId']) > 0) { foreach ($Params['additonalMeetingsId'] as $spUser) { if ($spUser['ID'] == $ownerId) { continue; } unset($arFilter["SECTION"]); $arFilter["IS_MEETING"] = 1; $arFilter["OWNER_ID"] = intVal($spUser['ID']); $res_i = CCalendarEvent::GetList(array('arFilter' => $arFilter, 'arSort' => array('ACTIVE_FROM' => 'ASC'), 'parseRecursion' => true, 'fetchAttendees' => true, 'userId' => $userId, 'fetchMeetings' => true)); if (is_array($res_i) && count($res_i) > 0) { foreach ($res_i as $event) { if (($event['IS_MEETING'] || $event['~IS_MEETING']) && $event['SECT_ID'] != intVal($spUser['SECTION_ID']) && !$resEventInd[$event['ID']]) { $status = 'Q'; $event['SECT_ID'] = intVal($spUser['SECTION_ID']); foreach ($event['~ATTENDEES'] as $att) { if ($att['USER_ID'] == $spUser['ID']) { $status = $att['STATUS']; break; } } if ($status == 'Y') { $event = CCalendarEvent::ApplyAccessRestrictions($event, $userId); $resAdd[] = $event; } } elseif (!is_array($event['~ATTENDEES']) && !isset($event['IS_MEETING']) && $event['~IS_MEETING']) { $resAdd[] = $event; } } } } } if ($type != 'user' && count($Params['section']) > 0) { $NewRes = array(); foreach ($res as $event) { if (in_array($event['SECT_ID'], $Params['section'])) { $NewRes[] = $event; } } $res = $NewRes; } if (count($resAdd) > 0) { $res = array_merge($res, $resAdd); } $arAttendees = CCalendarEvent::GetLastAttendees(); return $res; }
public static function GetEventList($Params = array(), &$arAttendees) { // $cache = new CPHPCache; // $cacheId = array(); // $cachePath = CCalendar::CachePath().'events'; // if ($cache->InitCache(CCalendar::CacheTime(), $cacheId, CCalendar::CachePath().'events')) // { // $res = $cache->GetVars(); // $bRes = $res['id'] == $iblockId; // } $type = isset($Params['type']) ? $Params['type'] : self::$type; if ($type != 'user' && !isset($Params['section']) || count($Params['section']) <= 0) { return array(); } $arFilter = array(); CCalendarEvent::SetLastAttendees(false); if (isset($Params['fromLimit'])) { $arFilter["FROM_LIMIT"] = $Params['fromLimit']; } if (isset($Params['toLimit'])) { $arFilter["TO_LIMIT"] = $Params['toLimit']; } if (isset($Params['section'])) { $arFilter["SECTION"] = $Params['section']; } if (self::$type == 'user') { $fetchMeetings = in_array(self::GetMeetingSection(self::$ownerId), $Params['section']); } else { $fetchMeetings = in_array(self::GetCurUserMeetingSection(), $Params['section']); } $res = CCalendarEvent::GetList(array('arFilter' => $arFilter, 'arSort' => array('ACTIVE_FROM' => 'ASC'), 'parseRecursion' => true, 'fetchAttendees' => true, 'userId' => self::$userId, 'fetchMeetings' => $fetchMeetings)); // Simple hack. TODO: We have to rid of it after refactoring DB structure $resEventInd = array(); foreach ($res as $i => $event) { $resEventInd[$event['ID']] = true; } // We selecting only meeting events from superpose $resAdd = array(); if (is_array($Params['additonalMeetingsId']) && count($Params['additonalMeetingsId']) > 0) { foreach ($Params['additonalMeetingsId'] as $spUser) { if ($spUser['ID'] == self::$ownerId) { continue; } unset($arFilter["SECTION"]); $arFilter["IS_MEETING"] = 1; $arFilter["OWNER_ID"] = intVal($spUser['ID']); $res_i = CCalendarEvent::GetList(array('arFilter' => $arFilter, 'arSort' => array('ACTIVE_FROM' => 'ASC'), 'parseRecursion' => true, 'fetchAttendees' => true, 'userId' => self::$userId, 'fetchMeetings' => true)); if (is_array($res_i) && count($res_i) > 0) { foreach ($res_i as $i => $event) { if ($res_i[$i]['IS_MEETING'] && $res_i[$i]['SECT_ID'] != intVal($spUser['SECTION_ID']) && !$resEventInd[$res_i[$i]['ID']]) { $res_i[$i]['SECT_ID'] = intVal($spUser['SECTION_ID']); $res_i[$i] = CCalendarEvent::ApplyAccessRestrictions($res_i[$i], self::$userId); $resAdd[] = $res_i[$i]; } } } } } if ($type != 'user' && count($Params['section']) > 0) { $NewRes = array(); foreach ($res as $event) { if (in_array($event['SECT_ID'], $Params['section'])) { $NewRes[] = $event; } } $res = $NewRes; } if (count($resAdd) > 0) { $res = array_merge($res, $resAdd); } $arAttendees = CCalendarEvent::GetLastAttendees(); return $res; }