示例#1
0
 function GetNearestEventsList($arParams)
 {
     if (!isset($arParams['userId'])) {
         global $USER;
         // Get current user id
         $curUserId = $USER->IsAuthorized() ? $USER->GetID() : 0;
     } else {
         $curUserId = intval($arParams['userId']);
     }
     if ($arParams['bCurUserList']) {
         if ($curUserId <= 0 || class_exists('CSocNetFeatures') && !CSocNetFeatures::IsActiveFeature(SONET_ENTITY_USER, $curUserId, "calendar")) {
             return 'inactive_feature';
         }
         // Get iblock id for users calendar from module-settings
         $iblockId = COption::GetOptionInt("intranet", 'iblock_calendar');
         // Get section id
         $sectionId = CEventCalendar::GetSectionIDByOwnerId($curUserId, "USER", $iblockId);
         // Expand filter
         $arFilterEx = array("CREATED_BY" => $curUserId, "SECTION_ID" => $sectionId, "INCLUDE_SUBSECTIONS" => "Y");
     } else {
         if (intVal($arParams['iblockSectionId']) > 0) {
             $arFilterEx = array("SECTION_ID" => $arParams['iblockSectionId'], "INCLUDE_SUBSECTIONS" => "Y");
         }
         $iblockId = $arParams['iblockId'];
     }
     // Check access
     $maxPerm = CIBlock::GetPermission($iblockId);
     $bAccess = $maxPerm >= 'R';
     if (CIBlock::GetPermission($iblockId) < 'R') {
         return 'access_denied';
     }
     $arSelect = array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "NAME", "ACTIVE_FROM", "ACTIVE_TO", "DETAIL_TEXT", "DETAIL_TEXT_TYPE", "CREATED_BY", "PROPERTY_*");
     $arFilter = array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "CHECK_PERMISSIONS" => 'N', ">=DATE_ACTIVE_TO" => $arParams['fromLimit'], "<=DATE_ACTIVE_FROM" => $arParams['toLimit']);
     if (count($arFilterEx) > 0) {
         $arFilter = array_merge($arFilter, $arFilterEx);
     }
     $bCache = true;
     $arResult = false;
     if ($bCache) {
         $cache = new CPHPCache();
         $cachePath = 'event_calendar/events/' . $iblockId . '/';
         $cacheId = 'ne_' . serialize($arFilter);
         if (($tzOffset = CTimeZone::GetOffset()) != 0) {
             $cacheId .= "_" . $tzOffset;
         }
         $cacheTime = 36000000;
         if ($cache->InitCache($cacheTime, $cacheId, $cachePath)) {
             $res = $cache->GetVars();
             $arResult = $res['events'];
         }
     }
     if (!$bCache || $arResult === false) {
         $arSort = array('ACTIVE_FROM' => 'ASC');
         $rsElement = CIBlockElement::GetList($arSort, $arFilter, false, false, $arSelect);
         $arResult = array();
         while ($obElement = $rsElement->GetNextElement()) {
             $arItem = $obElement->GetFields();
             $props = $obElement->GetProperties();
             $arItem["ACCESSIBILITY"] = isset($props['ACCESSIBILITY']['VALUE']) ? $props['ACCESSIBILITY']['VALUE'] : 'busy';
             $arItem["IMPORTANCE"] = isset($props['IMPORTANCE']['VALUE']) ? $props['IMPORTANCE']['VALUE'] : '';
             $arItem["PRIVATE"] = isset($props['PRIVATE']['VALUE']) ? $props['PRIVATE']['VALUE'] : '';
             if (isset($props['PARENT']) && $props['PARENT']['VALUE'] > 0) {
                 $status = strtoupper(isset($props['CONFIRMED']) ? $props['CONFIRMED']['VALUE_XML_ID'] : 'Q');
                 if ($status != 'Y' && $status != 'N') {
                     $status = 'Q';
                 }
                 $arItem['STATUS'] = $status;
             }
             $arItem["DISPLAY_ACTIVE_FROM"] = CIBlockFormatProperties::DateFormat(getDateFormat(true), MakeTimeStamp($arItem["ACTIVE_FROM"]));
             $arItem["DISPLAY_ACTIVE_TO"] = CIBlockFormatProperties::DateFormat(getDateFormat(true), MakeTimeStamp($arItem["ACTIVE_TO"]));
             $perType = isset($props['PERIOD_TYPE']['VALUE']) && $props['PERIOD_TYPE']['VALUE'] != 'NONE' ? strtoupper($props['PERIOD_TYPE']['VALUE']) : false;
             if ($perType) {
                 $count = isset($props['PERIOD_COUNT']['VALUE']) ? intval($props['PERIOD_COUNT']['VALUE']) : '';
                 $length = isset($props['EVENT_LENGTH']['VALUE']) ? intval($props['EVENT_LENGTH']['VALUE']) : '';
                 $additional = isset($props['PERIOD_ADDITIONAL']['VALUE']) ? $props['PERIOD_ADDITIONAL']['VALUE'] : '';
                 CEventCalendar::DisplayPeriodicEvent($arResult, array('arItem' => $arItem, 'perType' => $perType, 'count' => $count, 'length' => $length, 'additional' => $additional, 'fromLimit' => $arParams['fromLimit'], 'toLimit' => $arParams['toLimit']));
             } else {
                 CEventCalendar::HandleElement($arResult, $arItem);
             }
         }
         if ($bCache) {
             $cache->StartDataCache($cacheTime, $cacheId, $cachePath);
             $cache->EndDataCache(array("events" => $arResult));
         }
     }
     return $arResult;
 }