示例#1
0
 /**
  * get formatted date 
  *
  * @access public
  * @param int format type
  * @param string format string
  * @param string a specific timezone
  */
 public function get($a_format, $a_format_str = '', $a_tz = '')
 {
     if ($a_tz) {
         try {
             $timezone = ilTimeZone::_getInstance($a_tz);
         } catch (ilTimeZoneException $exc) {
             $this->log->write(__METHOD__ . ': Invalid timezone given. Timezone: ' . $a_tz);
         }
     } else {
         #$timezone = $this->timezone;
         $timezone = $this->default_timezone;
     }
     switch ($a_format) {
         case IL_CAL_UNIX:
             $date = $this->getUnixTime();
             break;
         case IL_CAL_DATE:
             $timezone->switchTZ();
             $date = date('Y-m-d', $this->getUnixTime());
             $timezone->restoreTZ();
             break;
         case IL_CAL_DATETIME:
             $timezone->switchTZ();
             $date = date('Y-m-d H:i:s', $this->getUnixTime());
             $timezone->restoreTZ();
             break;
         case IL_CAL_FKT_DATE:
             $timezone->switchTZ();
             $date = date($a_format_str, $this->getUnixTime());
             $timezone->restoreTZ();
             break;
         case IL_CAL_FKT_GETDATE:
             $timezone->switchTZ();
             $date = getdate($this->getUnixTime());
             $timezone->restoreTZ();
             // add iso 8601 week day number (Sunday = 7)
             $date['isoday'] = $date['wday'] == 0 ? 7 : $date['wday'];
             break;
         case IL_CAL_TIMESTAMP:
             $timezone->switchTZ();
             $date = date('YmdHis', $this->getUnixTime());
             $timezone->restoreTZ();
             break;
     }
     return $date;
 }
示例#2
0
 /**
  * Create new date object
  *
  * @access public
  * @param mixed integer string following the format given as the second parameter
  * @param int format of date presentation
  * 
  */
 public function __construct($a_date = '', $a_format = 0)
 {
     parent::__construct($a_date, $a_format, ilTimeZone::UTC);
     $this->default_timezone = ilTimeZone::_getInstance('UTC');
 }
 /**
  * Apply BYMONTHDAY rules.
  *
  * @access protected
  */
 protected function applyBYMONTHDAYRules(ilDateList $list)
 {
     // return unmodified, if no byweekno rules are available
     if (!$this->recurrence->getBYMONTHDAYList()) {
         return $list;
     }
     $days_list = $this->initDateList();
     foreach ($list->get() as $seed) {
         $num_days = ilCalendarUtil::_getMaxDayOfMonth($seed->get(IL_CAL_FKT_DATE, 'Y', $this->timezone), $seed->get(IL_CAL_FKT_DATE, 'n', $this->timezone));
         /*
         $num_days = cal_days_in_month(CAL_GREGORIAN,
         	$seed->get(IL_CAL_FKT_DATE,'n',$this->timezone),
         	$seed->get(IL_CAL_FKT_DATE,'Y',$this->timezone));
         */
         #$this->log->write(__METHOD__.': Month '.$seed->get(IL_CAL_FKT_DATE,'M',$this->timezone).' has '.$num_days.' days.');
         foreach ($this->recurrence->getBYMONTHDAYList() as $bymonth_no) {
             $day_no = $bymonth_no < 0 ? $num_days + $bymonth_no + 1 : $bymonth_no;
             if ($this->frequence_context != ilCalendarRecurrence::FREQ_YEARLY) {
                 if ($day_no < 1 or $day_no > $num_days) {
                     $this->log->write(__METHOD__ . ': Ignoring BYMONTHDAY rule: ' . $day_no . ' for month ' . $seed->get(IL_CAL_FKT_DATE, 'M', $this->timezone));
                     continue;
                 }
             }
             $day_diff = $day_no - $seed->get(IL_CAL_FKT_DATE, 'j', $this->timezone);
             $new_day = $this->createDate($seed->get(IL_CAL_UNIX, '', $this->timezone));
             $new_day->increment(ilDateTime::DAY, $day_diff);
             switch ($this->frequence_context) {
                 case ilCalendarRecurrence::FREQ_DAILY:
                     // Check if day matches
                     #var_dump("<pre>",$seed->get(IL_CAL_FKT_DATE,'z',$this->timezone),$day_no,"</pre>");
                     if ($seed->get(IL_CAL_FKT_DATE, 'j', $this->timezone) == $day_no) {
                         $days_list->add($new_day);
                     }
                     break;
                 case ilCalendarRecurrence::FREQ_WEEKLY:
                     // Check if week matches
                     if ($seed->get(IL_CAL_FKT_DATE, 'W', $this->timezone) == $new_day->get(IL_CAL_FKT_DATE, 'W', $this->timezone)) {
                         $days_list->add($new_day);
                     }
                     break;
                 case ilCalendarRecurrence::FREQ_MONTHLY:
                     // seed and new day are in the same month.
                     $days_list->add($new_day);
                     break;
                 case ilCalendarRecurrence::FREQ_YEARLY:
                     $h = $this->event->isFullday() ? 0 : $seed->get(IL_CAL_FKT_DATE, 'H', $this->timezone);
                     $i = $this->event->isFullday() ? 0 : $seed->get(IL_CAL_FKT_DATE, 'i', $this->timezone);
                     $s = $this->event->isFullday() ? 0 : $seed->get(IL_CAL_FKT_DATE, 's', $this->timezone);
                     $y = $seed->get(IL_CAL_FKT_DATE, 'Y', $this->timezone);
                     // TODO: the chosen monthday has to added to all months
                     for ($month = 1; $month <= 12; $month++) {
                         #$num_days = cal_days_in_month(CAL_GREGORIAN,
                         #	$month,
                         #	$y);
                         $num_days = ilCalendarUtil::_getMaxDayOfMonth($y, $month);
                         $day_no = $bymonth_no < 0 ? $num_days + $bymonth_no + 1 : $bymonth_no;
                         if ($day_no < 1 or $day_no > $num_days) {
                             $this->log->write(__METHOD__ . ': Ignoring BYMONTHDAY rule: ' . $day_no . ' for month ' . $month);
                         } else {
                             $tz_obj = ilTimeZone::_getInstance($this->timezone);
                             $tz_obj->switchTZ();
                             $unix = mktime($h, $i, $s, $month, $day_no, $y);
                             $tz_obj->restoreTZ();
                             $new_day = $this->createDate($unix);
                             $days_list->add($new_day);
                         }
                     }
                     break;
             }
         }
     }
     $this->frequence_context = ilCalendarRecurrence::FREQ_DAILY;
     return $days_list;
 }
 private function verifyPref($key, $value)
 {
     switch ($key) {
         case 'mail_linebreak':
         case 'hits_per_page':
             if (!is_numeric($value) || $value < 0) {
                 $this->logFailure("---", "Wrong value '{$value}': Positiv numeric value expected for preference {$key}.");
             }
             break;
         case 'language':
         case 'skin':
         case 'style':
         case 'ilPageEditor_HTMLMode':
         case 'ilPageEditor_JavaScript':
         case 'ilPageEditor_MediaMode':
         case 'tst_javascript':
         case 'tst_lastquestiontype':
         case 'tst_multiline_answers':
         case 'tst_use_previous_answers':
         case 'graphicalAnswerSetting':
         case 'priv_feed_pass':
             $this->logFailure("---", "Preference {$key} is not supported.");
             break;
         case 'public_city':
         case 'public_country':
         case 'public_department':
         case 'public_email':
         case 'public_fax':
         case 'public_hobby':
         case 'public_institution':
         case 'public_matriculation':
         case 'public_phone':
         case 'public_phone_home':
         case 'public_phone_mobile':
         case 'public_phone_office':
         case 'public_street':
         case 'public_upload':
         case 'public_zip':
         case 'send_info_mails':
         case 'hide_own_online_status':
             if (!in_array($value, array('y', 'n'))) {
                 $this->logFailure("---", "Wrong value '{$value}': Value 'y' or 'n' expected for preference {$key}.");
             }
             break;
         case 'public_profile':
             if (!in_array($value, array('y', 'n', 'g'))) {
                 $this->logFailure("---", "Wrong value '{$value}': Value 'y', 'g' or 'n' expected for preference {$key}.");
             }
             break;
         case 'show_users_online':
             if (!in_array($value, array('y', 'n', 'associated'))) {
                 $this->logFailure("---", "Wrong value '{$value}': Value 'y' or 'n' or 'associated' expected for preference {$key}.");
             }
             break;
         case 'mail_incoming_type':
             if (!in_array((int) $value, array("0", "1", "2"))) {
                 $this->logFailure("---", "Wrong value '{$value}': Value \"0\" (LOCAL),\"1\" (EMAIL) or \"2\" (BOTH) expected for preference {$key}.");
             }
             break;
         case 'weekstart':
             if (!in_array($value, array("0", "1"))) {
                 $this->logFailure("---", "Wrong value '{$value}': Value \"0\" (Sunday) or \"1\" (Monday) expected for preference {$key}.");
             }
             break;
         case 'mail_signature':
             break;
         case 'user_tz':
             include_once 'Services/Calendar/classes/class.ilTimeZone.php';
             try {
                 $tz = ilTimeZone::_getInstance($value);
                 return true;
             } catch (ilTimeZoneException $tze) {
                 $this->logFailure("---", "Wrong value '{$value}': Invalid timezone {$value} detected for preference {$key}.");
             }
             break;
         default:
             if (!ilUserXMLWriter::isPrefExportable($key)) {
                 $this->logFailure("---", "Preference {$key} is not supported.");
             }
             break;
     }
 }
示例#5
0
 /**
  * get timezone
  *
  * @access protected
  */
 protected function getTZ($a_timezone)
 {
     $parts = explode('/', $a_timezone);
     $tz = array_pop($parts);
     $continent = array_pop($parts);
     if (isset($continent) and $continent) {
         $timezone = $continent . '/' . $tz;
     } else {
         $timezone = $a_timezone;
     }
     try {
         if ($this->default_timezone->getIdentifier() == $timezone) {
             return $this->default_timezone;
         } else {
             $this->log->write(__METHOD__ . ': Found new timezone: ' . $timezone);
             return ilTimeZone::_getInstance(trim($timezone));
         }
     } catch (ilTimeZoneException $e) {
         $this->log->write(__METHOD__ . ': Found invalid timezone: ' . $timezone);
         return $this->default_timezone;
     }
 }