/** * Return given recurrence data as text. * * @param string $rrule Recurrence rule * * @return string */ public function rrule_to_text($rrule = '') { $txt = ''; $rc = new SG_iCal_Recurrence(new SG_iCal_Line('RRULE:' . $rrule)); switch ($rc->getFreq()) { case 'DAILY': $this->_get_interval($txt, 'daily', $rc->getInterval()); $this->_ending_sentence($txt, $rc); break; case 'WEEKLY': $this->_get_interval($txt, 'weekly', $rc->getInterval()); $this->_get_sentence_by($txt, 'weekly', $rc); $this->_ending_sentence($txt, $rc); break; case 'MONTHLY': $this->_get_interval($txt, 'monthly', $rc->getInterval()); $this->_get_sentence_by($txt, 'monthly', $rc); $this->_ending_sentence($txt, $rc); break; case 'YEARLY': $this->_get_interval($txt, 'yearly', $rc->getInterval()); $this->_get_sentence_by($txt, 'yearly', $rc); $this->_ending_sentence($txt, $rc); break; default: $processed = explode('=', $rrule); if (isset($processed[1]) && in_array(strtoupper($processed[0]), array('RDATE', 'EXDATE'))) { $txt = $this->exdate_to_text($processed[1]); } else { $txt = $rrule; } } return $txt; }
/** * Return given recurrence data as text. * * @param string $rrule Recurrence rule * * @return string */ public function rrule_to_text($rrule = '') { $txt = ''; $rc = new SG_iCal_Recurrence(new SG_iCal_Line('RRULE:' . $rrule)); switch ($rc->getFreq()) { case 'DAILY': $this->_get_interval($txt, 'daily', $rc->getInterval()); $this->_ending_sentence($txt, $rc); break; case 'WEEKLY': $this->_get_interval($txt, 'weekly', $rc->getInterval()); $this->_get_sentence_by($txt, 'weekly', $rc); $this->_ending_sentence($txt, $rc); break; case 'MONTHLY': $this->_get_interval($txt, 'monthly', $rc->getInterval()); $this->_get_sentence_by($txt, 'monthly', $rc); $this->_ending_sentence($txt, $rc); break; case 'YEARLY': $this->_get_interval($txt, 'yearly', $rc->getInterval()); $this->_get_sentence_by($txt, 'yearly', $rc); $this->_ending_sentence($txt, $rc); break; default: $txt = $rrule; } return $txt; }
public function testGetFrequencyGetIntervalWithTypicalLineReturnsFrequency() { $line = new SG_iCal_Line('RRULE:FREQ=DAILY;INTERVAL=2'); $recurrence = new SG_iCal_Recurrence($line); $this->assertEquals('DAILY', $recurrence->getFreq()); $this->assertEquals('2', $recurrence->getInterval()); }
/** * get_repeat_box function * * @return string **/ public function get_repeat_box() { $time_system = $this->_registry->get('date.system'); $loader = $this->_registry->get('theme.loader'); $repeat = (int) $_REQUEST["repeat"]; $repeat = $repeat == 1 ? 1 : 0; $post_id = (int) $_REQUEST["post_id"]; $count = 100; $end = 0; $until = $time_system->current_time(true); // try getting the event try { $event = $this->_registry->get('model.event', $post_id); $rule = ''; if ($repeat) { $rule = $event->get('recurrence_rules') ? $event->get('recurrence_rules') : ''; } else { $rule = $event->get('exception_rules') ? $event->get('exception_rules') : ''; } $rule = $this->_registry->get('recurrence.rule')->filter_rule($rule); $rc = new SG_iCal_Recurrence(new SG_iCal_Line('RRULE:' . $rule)); if ($until = $rc->getUntil()) { $until = is_numeric($until) ? $until : strtotime($until); $end = 2; } elseif ($count = $rc->getCount()) { $count = is_numeric($count) ? $count : 100; $end = 1; } } catch (Ai1ec_Event_Not_Found_Exception $e) { $rule = ''; $rc = new SG_iCal_Recurrence(new SG_iCal_Line('RRULE:')); } $args = array('row_daily' => $this->row_daily(false, $rc->getInterval() ? $rc->getInterval() : 1), 'row_weekly' => $this->row_weekly(false, $rc->getInterval() ? $rc->getInterval() : 1, is_array($rc->getByDay()) ? $rc->getByDay() : array()), 'row_monthly' => $this->row_monthly(false, $rc->getInterval() ? $rc->getInterval() : 1, !$this->_is_monthday_empty($rc), $rc->getByMonthDay() ? $rc->getByMonthDay() : array(), $rc->getByDay() ? $rc->getByDay() : array()), 'row_yearly' => $this->row_yearly(false, $rc->getInterval() ? $rc->getInterval() : 1, is_array($rc->getByMonth()) ? $rc->getByMonth() : array()), 'row_custom' => $this->row_custom(false, $this->get_date_array_from_rule($rule)), 'count' => $this->create_count_input('ai1ec_count', $count) . Ai1ec_I18n::__('times'), 'end' => $this->create_end_dropdown($end), 'until' => $until, 'repeat' => $repeat, 'ending_type' => $end, 'selected_tab' => $rc->getFreq() ? strtolower($rc->getFreq()) : 'custom'); $output = array('error' => false, 'message' => $loader->get_file('box_repeat.php', $args, true)->get_content(), 'repeat' => $repeat); $json_strategy = $this->_registry->get('http.response.render.strategy.json'); $json_strategy->render(array('data' => $output)); }