Beispiel #1
0
 function DisplayPeriodicEvent(&$res, $arParams)
 {
     $length = intVal($arParams['length']);
     // length in seconds
     $count = $arParams['count'];
     $f_limit_ts = MakeTimeStamp($arParams['fromLimit'], getTSFormat());
     $t_limit_ts = MakeTimeStamp($arParams['toLimit'], getTSFormat());
     $f_real_ts = MakeTimeStamp($arParams['arItem']['DISPLAY_ACTIVE_FROM'], getTSFormat());
     $t_real_ts = MakeTimeStamp($arParams['arItem']['DISPLAY_ACTIVE_TO'], getTSFormat());
     if ($count <= 0) {
         $count = 1;
     }
     if ($f_limit_ts < $f_real_ts) {
         $f_limit_ts = $f_real_ts;
     }
     if ($t_limit_ts > $t_real_ts) {
         $t_limit_ts = $t_real_ts;
     }
     $from_ts = $f_real_ts;
     $to_ts = $f_real_ts;
     $arDays = array();
     if ($arParams['perType'] == 'WEEKLY') {
         $arDays_ = explode(',', $arParams['additional']);
         $arDaysCount = count($arDays_);
         for ($i = 0; $i < count($arDays_); $i++) {
             if ($arDays_[$i] != "") {
                 $arDays[$arDays_[$i]] = true;
             }
         }
         $arParams['arDays'] = $arDays;
     }
     while ($to_ts < $t_limit_ts) {
         $f_time_h = date("H", $from_ts);
         $f_time_m = date("i", $from_ts);
         $f_time_s = date("s", $from_ts);
         $f_d = date("d", $from_ts);
         $f_m = date("m", $from_ts);
         $f_y = date("Y", $from_ts);
         if ($arParams['perType'] == 'WEEKLY') {
             $f_day = convertDayInd(date("w", $from_ts));
             if ($arDays[$f_day] || count($arDays) == 0) {
                 $to_ts = mktime($f_time_h, $f_time_m, $f_time_s + $length, $f_m, $f_d, $f_y);
                 if ($from_ts <= $t_limit_ts && $to_ts >= $f_limit_ts) {
                     CEventCalendar::HandlePeriodicElement($res, array_merge($arParams, array('dateFrom' => date(getDateFormat(), $from_ts), 'dateTo' => date(getDateFormat(), $to_ts))));
                 } elseif ($from_ts > $f_limit_ts) {
                     break;
                 }
             }
             if ($f_day == 6) {
                 $delta = ($count - 1) * 7 + 1;
             } else {
                 $delta = 1;
             }
             $from_ts = mktime($f_time_h, $f_time_m, $f_time_s, $f_m, $f_d + $delta, $f_y);
         } else {
             $to_ts = mktime($f_time_h, $f_time_m, $f_time_s + $length, $f_m, $f_d, $f_y);
             if ($from_ts <= $t_limit_ts && $to_ts >= $f_limit_ts) {
                 CEventCalendar::HandlePeriodicElement($res, array_merge($arParams, array('dateFrom' => date(getDateFormat(), $from_ts), 'dateTo' => date(getDateFormat(), $to_ts))));
             } elseif ($from_ts > $f_limit_ts) {
                 break;
             }
             switch ($arParams['perType']) {
                 case 'DAILY':
                     $from_ts = mktime($f_time_h, $f_time_m, $f_time_s, $f_m, $f_d + $count, $f_y);
                     break;
                 case 'MONTHLY':
                     $from_ts = mktime($f_time_h, $f_time_m, $f_time_s, $f_m + $count, $f_d, $f_y);
                     break;
                 case 'YEARLY':
                     $from_ts = mktime($f_time_h, $f_time_m, $f_time_s, $f_m, $f_d, $f_y + $count);
                     break;
             }
         }
     }
 }