Ejemplo n.º 1
0
 /**
  * set calendar component property trigger
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.9.9 - 2011-06-17
  * @param mixed $year
  * @param mixed $month optional
  * @param int $day optional
  * @param int $week optional
  * @param int $hour optional
  * @param int $min optional
  * @param int $sec optional
  * @param bool $relatedStart optional
  * @param bool $before optional
  * @param array $params optional
  * @return bool
  */
 function setTrigger($year, $month = null, $day = null, $week = FALSE, $hour = FALSE, $min = FALSE, $sec = FALSE, $relatedStart = TRUE, $before = TRUE, $params = FALSE)
 {
     if (empty($year) && empty($month) && empty($day) && empty($week) && empty($hour) && empty($min) && empty($sec)) {
         if ($this->getConfig('allowEmpty')) {
             $this->trigger = array('value' => null, 'params' => iCal_UtilityFunctions::_setParams($params));
             return TRUE;
         } else {
             return FALSE;
         }
     }
     if (iCal_UtilityFunctions::_isArrayTimestampDate($year)) {
         // timestamp
         $params = iCal_UtilityFunctions::_setParams($month);
         $date = iCal_UtilityFunctions::_timestamp2date($year, 7);
         foreach ($date as $k => $v) {
             ${$k} = $v;
         }
     } elseif (is_array($year) && (is_array($month) || empty($month))) {
         $params = iCal_UtilityFunctions::_setParams($month);
         if (!(array_key_exists('year', $year) && array_key_exists('month', $year) && array_key_exists('day', $year))) {
             // when this must be a duration
             if (isset($params['RELATED']) && 'END' == strtoupper($params['RELATED'])) {
                 $relatedStart = FALSE;
             } else {
                 $relatedStart = array_key_exists('relatedStart', $year) && TRUE !== $year['relatedStart'] ? FALSE : TRUE;
             }
             $before = array_key_exists('before', $year) && TRUE !== $year['before'] ? FALSE : TRUE;
         }
         $SSYY = array_key_exists('year', $year) ? $year['year'] : null;
         $month = array_key_exists('month', $year) ? $year['month'] : null;
         $day = array_key_exists('day', $year) ? $year['day'] : null;
         $week = array_key_exists('week', $year) ? $year['week'] : null;
         $hour = array_key_exists('hour', $year) ? $year['hour'] : 0;
         //null;
         $min = array_key_exists('min', $year) ? $year['min'] : 0;
         //null;
         $sec = array_key_exists('sec', $year) ? $year['sec'] : 0;
         //null;
         $year = $SSYY;
     } elseif (is_string($year) && (is_array($month) || empty($month))) {
         // duration or date in a string
         $params = iCal_UtilityFunctions::_setParams($month);
         if (in_array($year[0], array('P', '+', '-'))) {
             // duration
             $relatedStart = isset($params['RELATED']) && 'END' == strtoupper($params['RELATED']) ? FALSE : TRUE;
             $before = '-' == $year[0] ? TRUE : FALSE;
             if ('P' != $year[0]) {
                 $year = substr($year, 1);
             }
             $date = iCal_UtilityFunctions::_duration_string($year);
         } else {
             // date
             $date = iCal_UtilityFunctions::_date_time_string($year, 7);
         }
         unset($year, $month, $day);
         if (empty($date)) {
             $sec = 0;
         } else {
             foreach ($date as $k => $v) {
                 ${$k} = $v;
             }
         }
     } else {
         // single values in function input parameters
         $params = iCal_UtilityFunctions::_setParams($params);
     }
     if (!empty($year) && !empty($month) && !empty($day)) {
         // date
         $params['VALUE'] = 'DATE-TIME';
         $hour = $hour ? $hour : 0;
         $min = $min ? $min : 0;
         $sec = $sec ? $sec : 0;
         $this->trigger = array('params' => $params);
         $this->trigger['value'] = array('year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'min' => $min, 'sec' => $sec, 'tz' => 'Z');
         return TRUE;
     } elseif (empty($year) && empty($month) && (!empty($week) || 0 == $week || (!empty($day) || 0 == $day) || (!empty($hour) || 0 == $hour) || (!empty($min) || 0 == $min) || (!empty($sec) || 0 == $sec))) {
         unset($params['RELATED']);
         // set at output creation (END only)
         unset($params['VALUE']);
         // 'DURATION' default
         $this->trigger = array('params' => $params);
         $this->trigger['value'] = array();
         if (!empty($week)) {
             $this->trigger['value']['week'] = $week;
         }
         if (!empty($day)) {
             $this->trigger['value']['day'] = $day;
         }
         if (!empty($hour)) {
             $this->trigger['value']['hour'] = $hour;
         }
         if (!empty($min)) {
             $this->trigger['value']['min'] = $min;
         }
         if (!empty($sec)) {
             $this->trigger['value']['sec'] = $sec;
         }
         if (empty($this->trigger['value'])) {
             $this->trigger['value']['sec'] = 0;
             $before = FALSE;
         }
         $relatedStart = FALSE !== $relatedStart ? TRUE : FALSE;
         $before = FALSE !== $before ? TRUE : FALSE;
         $this->trigger['value']['relatedStart'] = $relatedStart;
         $this->trigger['value']['before'] = $before;
         return TRUE;
     }
     return FALSE;
 }