public function testGetByDayReturnsArrayWhenMoreThanOneDayIsIncluded() { $line = new SG_iCal_Line('RRULE:FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH'); $recurrence = new SG_iCal_Recurrence($line); $this->assertEquals(array('TU', 'TH'), $recurrence->getByDay()); $this->assertEquals('SU', $recurrence->getWkst()); }
/** * 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)); }
/** * Returns an associative array containing the following information: * string 'repeat' => pattern of repetition ('DAILY', 'WEEKENDS', etc.) * int 'count' => end after 'count' times * int 'until' => repeat until date (as UNIX timestamp) * Elements are null if no such recurrence information is available. * * @param Ai1ec_Event Event object to parse recurrence rules of * @return array Array structured as described above **/ function parse_recurrence_rules(&$event) { $repeat = null; $count = null; $until = null; $end = 0; if (!is_null($event)) { if (strlen($event->recurrence_rules) > 0) { $line = new SG_iCal_Line($event->recurrence_rules); $rec = new SG_iCal_Recurrence($line); switch ($rec->req) { case 'DAILY': $by_day = $rec->getByDay(); if (empty($by_day)) { $repeat = 'DAILY'; } elseif ($by_day[0] == 'SA+SU') { $repeat = 'WEEKENDS'; } elseif (count($by_day) == 5) { $repeat = 'WEEKDAYS'; } else { foreach ($by_day as $d) { $repeat .= $d . '+'; } $repeat = substr($repeat, 0, -1); } break; case 'WEEKLY': $repeat = 'WEEKLY'; break; case 'MONTHLY': $repeat = 'MONTHLY'; break; case 'YEARLY': $repeat = 'YEARLY'; break; } $count = $rec->getCount(); $until = $rec->getUntil(); if ($until) { $until = strtotime($rec->getUntil()); $until += date('Z', $until); // Add timezone offset $end = 2; } elseif ($count) { $end = 1; } else { $end = 0; } } } return array('repeat' => $repeat, 'count' => $count, 'until' => $until, 'end' => $end); }