Пример #1
0
 public static function process_event(&$row)
 {
     if (!isset($row['start']) && !(isset($row['timeless']) && $row['timeless'])) {
         trigger_error('Invalid return of event method: get(_all) (missing field \'start\' or \'timeless\' in ' . print_r($row, true) . ')', E_USER_ERROR);
     }
     if (!isset($row['duration']) || !is_numeric($row['duration'])) {
         trigger_error('Invalid return of event method: get(_all) (missing or not numeric field \'duration\' in ' . print_r($row, true) . ')', E_USER_ERROR);
     }
     if (!isset($row['title'])) {
         trigger_error('Invalid return of event method: get(_all) (missing field \'title\' in ' . print_r($row, true) . ')', E_USER_ERROR);
     }
     if (!isset($row['description'])) {
         trigger_error('Invalid return of event method: get(_all) (missing field \'description\' in ' . print_r($row, true) . ')', E_USER_ERROR);
     }
     if (!isset($row['id'])) {
         trigger_error('Invalid return of event method: get(_all) (missing field \'id\' in ' . print_r($row, true) . ')', E_USER_ERROR);
     }
     if (!isset($row['additional_info'])) {
         $row['additional_info'] = '';
     }
     if (!isset($row['additional_info2'])) {
         $row['additional_info2'] = '';
     }
     if (!isset($row['actions'])) {
         $row['actions'] = array();
     }
     if (isset($row['timeless']) && $row['timeless']) {
         if (!isset($row['timeless_caption'])) {
             $row['timeless_caption'] = str_replace(' ', ' ', __('Timeless'));
         }
         $start_time = $row['timeless_caption'];
         $end_time = $start_time;
         $ev_start = strtotime($row['timeless']);
         if (!isset($row['start'])) {
             $start_day = _V(date('D', $ev_start));
         } else {
             $start_day = _V(date('D', $row['start']));
         }
         $start_date = Base_RegionalSettingsCommon::time2reg($ev_start, false, true, false);
         if ($start_date == Base_RegionalSettingsCommon::time2reg(time(), false)) {
             $start_t = __('Today');
         } elseif ($start_date == Base_RegionalSettingsCommon::time2reg(time() + 3600 * 24, false)) {
             $start_t = __('Tomorrow');
         } elseif ($start_date == Base_RegionalSettingsCommon::time2reg(time() - 3600 * 24, false)) {
             $start_t = __('Yesterday');
         } else {
             $start_t = $start_day . ', ' . $start_date;
         }
         $end_date = $start_date;
         $end_day = $start_day;
         $end_t = $start_t;
     } else {
         if (!is_numeric($row['start']) && is_string($row['start'])) {
             $row['start'] = strtotime($row['start']);
         }
         if ($row['start'] === false) {
             trigger_error('Invalid return of event method: get (start equal to null)', E_USER_ERROR);
         }
         $row['end'] = $row['start'] + $row['duration'];
         $ev_start = $row['start'];
         $ev_end = $row['end'];
         Base_RegionalSettingsCommon::set();
         $start_day = __date('D', $ev_start);
         $end_day = __date('D', $ev_end);
         Base_RegionalSettingsCommon::restore();
         $start_date = Base_RegionalSettingsCommon::time2reg($ev_start, false);
         $end_date = Base_RegionalSettingsCommon::time2reg($ev_end, false);
         $oneday = $start_date == $end_date;
         if ($oneday) {
             $end_t = Base_RegionalSettingsCommon::time2reg($ev_end, 2, false);
         }
         $start_time = Base_RegionalSettingsCommon::time2reg($ev_start, 2, false);
         $end_time = Base_RegionalSettingsCommon::time2reg($ev_end, 2, false);
         if ($start_date == Base_RegionalSettingsCommon::time2reg(time(), false)) {
             $start_t = __('Today') . ', ' . $start_time;
         } elseif ($start_date == Base_RegionalSettingsCommon::time2reg(time() + 3600 * 24, false)) {
             $start_t = __('Tomorrow') . ', ' . $start_time;
         } elseif ($start_date == Base_RegionalSettingsCommon::time2reg(time() - 3600 * 24, false)) {
             $start_t = __('Yesterday') . ', ' . $start_time;
         } else {
             $start_t = $start_day . ', ' . $start_date . ' ' . $start_time;
         }
         if (!$oneday) {
             $end_t = $end_day . ', ' . $end_date . ' ' . $end_time;
         }
     }
     if (isset($row['fake_duration'])) {
         $duration_str = Base_RegionalSettingsCommon::seconds_to_words($row['fake_duration']);
     } elseif ($row['duration'] > 0) {
         $duration_str = Base_RegionalSettingsCommon::seconds_to_words($row['duration']);
     } else {
         $duration_str = '---';
     }
     return array('duration' => $duration_str, 'start' => $start_t, 'end' => $end_t, 'start_time' => $start_time, 'end_time' => $end_time, 'start_date' => $start_date, 'end_date' => $end_date, 'start_day' => $start_day, 'end_day' => $end_day);
 }