/**
  * 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;
 }
 /**
  * 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 = NULL;
     $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');
         }
         $rc = new SG_iCal_Recurrence(new SG_iCal_Line('RRULE:' . $rule));
         if ($until = $rc->getUntil()) {
             $until = is_numeric($until) ? $until : strtotime($until);
         } elseif ($count = $rc->getCount()) {
             $count = is_numeric($count) ? $count : 100;
         }
     } catch (Ai1ec_Event_Not_Found_Exception $e) {
         /* event wasn't found, keep defaults */
     }
     $args = array('row_daily' => $this->row_daily(), 'row_weekly' => $this->row_weekly(), 'row_monthly' => $this->row_monthly(), 'row_yearly' => $this->row_yearly(), 'count' => $this->create_count_input('ai1ec_count', $count) . Ai1ec_I18n::__('times'), 'end' => $this->create_end_dropdown($end), 'until' => $until, 'repeat' => $repeat);
     $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));
 }
 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());
 }
Example #5
0
 /**
  * Returns whether recurrence rule has non null ByMonthDay.
  *
  * @param SG_iCal_Recurrence $rc iCal class.
  *
  * @return bool True or false.
  */
 protected function _is_monthday_empty(SG_iCal_Recurrence $rc)
 {
     return false === $rc->getByMonthDay();
 }
 /**
  * get_repeat_box function
  *
  * @return string
  **/
 function get_repeat_box()
 {
     global $ai1ec_view_helper;
     $repeat = (int) $_REQUEST["repeat"];
     $repeat = $repeat == 1 ? 1 : 0;
     $post_id = (int) $_REQUEST["post_id"];
     $count = 100;
     $end = null;
     $until = Ai1ec_Time_Utility::current_time(true);
     // try getting the event
     try {
         $event = new Ai1ec_Event($post_id);
         $rule = '';
         if ($repeat) {
             $rule = empty($event->recurrence_rules) ? '' : $event->recurrence_rules;
         } else {
             $rule = empty($event->exception_rules) ? '' : $event->exception_rules;
         }
         $rc = new SG_iCal_Recurrence(new SG_iCal_Line('RRULE:' . $rule));
         if ($until = $rc->getUntil()) {
             $until = is_numeric($until) ? $until : strtotime($until);
         } else {
             if ($count = $rc->getCount()) {
                 $count = is_numeric($count) ? $count : 100;
             }
         }
     } catch (Ai1ec_Event_Not_Found $e) {
         /* event wasn't found, keep defaults */
     }
     $args = array('row_daily' => $this->row_daily(), 'row_weekly' => $this->row_weekly(), 'row_monthly' => $this->row_monthly(), 'row_yearly' => $this->row_yearly(), 'count' => $this->create_count_input('ai1ec_count', $count) . __('times', AI1EC_PLUGIN_NAME), 'end' => $this->create_end_dropdown($end), 'until' => $until, 'repeat' => $repeat);
     $output = array("error" => false, "message" => $ai1ec_view_helper->get_admin_view('box_repeat.php', $args), "repeat" => $repeat);
     echo json_encode($output);
     exit;
 }