Exemple #1
0
 public function testEndsOnNotBeforeLastDate()
 {
     $start_date = strtotime("2011-09-06");
     $end_date = strtotime("2011-12-06");
     $series_rules = new WeekSeriesRules(1, array(2));
     $rec = new TribeRecurrence($start_date, $end_date, $series_rules);
     $this->assertTrue(in_array($end_date, $rec->getDates()));
 }
 /**
  * Do the actual work of saving a recurring series of events
  * @param array $postId The event that is being saved 
  * @return void
  */
 public static function saveEvents($postId)
 {
     extract(TribeEventsRecurrenceMeta::getRecurrenceMeta($postId));
     $rules = TribeEventsRecurrenceMeta::getSeriesRules($postId);
     // use the recurrence start meta if necessary because we can't guarantee which order the start date will come back in
     $recStart = strtotime(get_post_meta($postId, '_EventStartDate', true));
     $eventEnd = strtotime(get_post_meta($postId, '_EventEndDate', true));
     $duration = $eventEnd - $recStart;
     $recEnd = $recEndType == "On" ? strtotime(TribeDateUtils::endOfDay($recEnd)) : $recEndCount - 1;
     // subtract one because event is first occurrence
     // different update types
     delete_post_meta($postId, '_EventStartDate');
     delete_post_meta($postId, '_EventEndDate');
     delete_post_meta($postId, '_EventDuration');
     // add back original start and end date
     add_post_meta($postId, '_EventStartDate', date(DateSeriesRules::DATE_FORMAT, $recStart));
     add_post_meta($postId, '_EventEndDate', date(DateSeriesRules::DATE_FORMAT, $eventEnd));
     add_post_meta($postId, '_EventDuration', $duration);
     if ($recType != "None") {
         $recurrence = new TribeRecurrence($recStart, $recEnd, $rules, $recEndType == "After");
         $dates = (array) $recurrence->getDates();
         // add meta for all dates in recurrence
         foreach ($dates as $date) {
             add_post_meta($postId, '_EventStartDate', date(DateSeriesRules::DATE_FORMAT, $date));
         }
     }
 }
 /**
  * Checks the recurrence amount and adds a filter to display an errir if it is not correct.
  *
  * @since 3.0
  * @author Paul Hughes
  *
  * @param int $post_id The post id.
  * @return void
  */
 public function checkRecurrenceAmount($post_id)
 {
     $is_success = true;
     if (get_post_type($post_id) == TribeEvents::POSTTYPE && get_post_meta($post_id, '_EventRecurrence')) {
         extract(TribeEventsRecurrenceMeta::getRecurrenceMeta($post_id));
         $rules = TribeEventsRecurrenceMeta::getSeriesRules($post_id);
         // use the recurrence start meta if necessary because we can't guarantee which order the start date will come back in
         $recStart = strtotime(get_post_meta($post_id, '_EventStartDate', true));
         $eventEnd = strtotime(get_post_meta($post_id, '_EventEndDate', true));
         $duration = $eventEnd - $recStart;
         $recEnd = $recEndType == "On" ? strtotime(TribeDateUtils::endOfDay($recEnd)) : $recEndCount - 1;
         // subtract one because event is first occurrence
         $old_start_dates = get_post_meta($post_id, '_EventStartDate');
         if ($recType != "None") {
             $recurrence = new TribeRecurrence($recStart, $recEnd, $rules, $recEndType == "After", get_post($post_id));
             $dates = (array) $recurrence->getDates(true, $old_start_dates);
             $max_recurrences = apply_filters('tribe_events_max_recurrences', 199);
             if (count($dates) > $max_recurrences) {
                 add_filter('redirect_post_location', array(__CLASS__, 'tooManyRecurrencesError'));
                 $is_success = false;
             }
         }
     }
     return $is_success;
 }