Пример #1
0
 /**
  * Do the actual work of saving a recurring series of events
  *
  * @return bool
  */
 public function save_events()
 {
     $existing_instances = Tribe__Events__Pro__Recurrence__Children_Events::instance()->get_ids($this->event_id);
     $recurrences = Tribe__Events__Pro__Recurrence__Meta::get_recurrence_for_event($this->event_id);
     $to_create = array();
     $exclusions = array();
     $to_update = array();
     $to_delete = array();
     $possible_next_pending = array();
     $earliest_date = strtotime(Tribe__Events__Pro__Recurrence__Meta::$scheduler->get_earliest_date());
     $latest_date = strtotime(Tribe__Events__Pro__Recurrence__Meta::$scheduler->get_latest_date());
     foreach ($recurrences['rules'] as &$recurrence) {
         if (!$recurrence) {
             continue;
         }
         $recurrence->setMinDate($earliest_date);
         $recurrence->setMaxDate($latest_date);
         $to_create = array_merge($to_create, $recurrence->getDates());
         if ($recurrence->constrainedByMaxDate() !== false) {
             $possible_next_pending[] = $recurrence->constrainedByMaxDate();
         }
     }
     $to_create = tribe_array_unique($to_create);
     // find days we should exclude
     foreach ($recurrences['exclusions'] as &$recurrence) {
         if (!$recurrence) {
             continue;
         }
         $recurrence->setMinDate($earliest_date);
         $recurrence->setMaxDate($latest_date);
         $exclusions = array_merge($exclusions, $recurrence->getDates());
     }
     // make sure we don't create excluded dates
     $exclusions = tribe_array_unique($exclusions);
     $to_create = $this->exclusions->remove_exclusions($to_create, $exclusions);
     if ($possible_next_pending) {
         update_post_meta($this->event_id, '_EventNextPendingRecurrence', date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, min($possible_next_pending)));
     }
     foreach ($existing_instances as $instance) {
         $start_date = strtotime(get_post_meta($instance, '_EventStartDate', true) . '+00:00');
         $end_date = strtotime(get_post_meta($instance, '_EventEndDate', true) . '+00:00');
         $duration = $end_date - $start_date;
         $existing_date_duration = array('timestamp' => $start_date, 'duration' => $duration);
         $found = array_search($existing_date_duration, $to_create);
         $should_be_excluded = in_array($existing_date_duration, $exclusions);
         if ($found === false || false !== $should_be_excluded) {
             $to_delete[$instance] = $existing_date_duration;
         } else {
             $to_update[$instance] = $to_create[$found];
             unset($to_create[$found]);
             // so we don't re-add it
         }
     }
     // Store the list of instances to create/update/delete etc for future processing
     $queue = new Tribe__Events__Pro__Recurrence__Queue($this->event_id);
     $queue->update($to_create, $to_update, $to_delete, $exclusions);
     // ...but don't wait around, process a small initial batch right away
     Tribe__Events__Pro__Main::instance()->queue_processor->process_batch($this->event_id);
     return true;
 }
Пример #2
0
 public function schedule_future_recurring_events()
 {
     /** @var wpdb $wpdb */
     global $wpdb;
     $post_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT m.post_id FROM {$wpdb->postmeta} m INNER JOIN {$wpdb->posts} p ON m.post_id=p.ID WHERE m.meta_key='_EventNextPendingRecurrence' AND m.meta_value < %s AND p.post_parent = 0", $this->latest_date));
     foreach ($post_ids as $post_id) {
         Tribe__Events__Pro__Recurrence__Meta::save_pending_events($post_id);
     }
 }
Пример #3
0
 /**
  * Responsible for displaying a user's custom recurrence pattern description.
  *
  * @deprecated since 3.6
  *
  * @param string $meta_id The meta group this is in.
  *
  * @return string The custom description.
  */
 public static function custom_recurrence_description($meta_id)
 {
     _deprecated_function(__METHOD__, '4.3');
     global $_tribe_meta_factory;
     $post_id = get_the_ID();
     $recurrence_meta = Tribe__Events__Pro__Recurrence__Meta::getRecurrenceMeta($post_id);
     $recurrence_description = !empty($recurrence_meta['recCustomRecurrenceDescription']) ? $recurrence_meta['recCustomRecurrenceDescription'] : tribe_get_recurrence_text($post_id);
     $html = tribe_is_recurring_event($post_id) ? Tribe__Events__Meta_Factory::template($_tribe_meta_factory->meta[$meta_id]['label'], $recurrence_description, $meta_id) : '';
     return apply_filters('tribe_event_pro_meta_custom_recurrence_description', $html);
 }
Пример #4
0
 /**
  * Alter the Recurrence rule end-count value for appropriate rules (which, in this case have an end-type of "After")
  * when the given child event date exists within the rule as a valid date
  *
  * @param int $parent_id Event ID of the parent recurrence event
  * @param array $recurrence_meta Collection of recurrence rules for the event
  * @param string $child_date Date of the child event we are testing for
  * @param string $action Type of action we are taking on the field: reduce or set. Reduce subtracts, while set overrides the value
  * @param int $value Value to either subtract or set the end-count to
  */
 private function maybe_alter_recurrence_end_count($parent_id, $recurrence_meta, $child_date, $action = 'reduce', $value = 1)
 {
     $recurrences = Tribe__Events__Pro__Recurrence__Meta::get_recurrence_for_event($parent_id);
     $earliest_date = strtotime(Tribe__Events__Pro__Recurrence__Meta::$scheduler->get_earliest_date());
     $latest_date = strtotime(Tribe__Events__Pro__Recurrence__Meta::$scheduler->get_latest_date());
     // if the recurrence rule has an end-type of "After", then we'll need to reduce the number of events it repeats with
     foreach ($recurrence_meta['rules'] as $rule_key => $rule) {
         if (empty($rule['end-type']) || 'After' !== $rule['end-type']) {
             continue;
         }
         if (empty($recurrences['rules'][$rule_key])) {
             continue;
         }
         $recurrences['rules'][$rule_key]->setMinDate($earliest_date);
         $recurrences['rules'][$rule_key]->setMaxDate($latest_date);
         $dates = $recurrences['rules'][$rule_key]->getDates();
         if (!in_array($child_date, $dates)) {
             continue;
         }
         if ('reduce' === $action) {
             $recurrence_meta['rules'][$rule_key]['end-count'] -= $value;
         } else {
             $recurrence_meta['rules'][$rule_key]['end-count'] = $value;
         }
     }
     return $recurrence_meta;
 }
Пример #5
0
 /**
  * Enqueues the necessary JS for the admin side of things.
  *
  * @return void
  */
 public function admin_enqueue_scripts()
 {
     wp_enqueue_script('handlebars', $this->pluginUrl . 'vendor/handlebars/handlebars.min.js', array(), apply_filters('tribe_events_pro_js_version', self::VERSION), true);
     wp_enqueue_script('moment', $this->pluginUrl . 'vendor/momentjs/moment.min.js', array(), apply_filters('tribe_events_pro_js_version', self::VERSION), true);
     wp_enqueue_script(Tribe__Events__Main::POSTTYPE . '-premium-admin', tribe_events_pro_resource_url('events-admin.js'), array('jquery-ui-datepicker'), apply_filters('tribe_events_pro_js_version', self::VERSION), true);
     wp_enqueue_script(Tribe__Events__Main::POSTTYPE . '-premium-recurrence', tribe_events_pro_resource_url('events-recurrence.js'), array(Tribe__Events__Main::POSTTYPE . '-premium-admin', 'handlebars', 'moment'), apply_filters('tribe_events_pro_js_version', self::VERSION), true);
     $data = apply_filters('tribe_events_pro_localize_script', array(), 'TribeEventsProAdmin', Tribe__Events__Main::POSTTYPE . '-premium-admin');
     wp_localize_script(Tribe__Events__Main::POSTTYPE . '-premium-admin', 'TribeEventsProAdmin', $data);
     wp_localize_script(Tribe__Events__Main::POSTTYPE . '-premium-admin', 'tribe_events_pro_recurrence_strings', array('date' => Tribe__Events__Pro__Recurrence__Meta::date_strings(), 'recurrence' => Tribe__Events__Pro__Recurrence__Strings::recurrence_strings(), 'exclusion' => array()));
 }
Пример #6
0
 protected function do_deletions()
 {
     $instances_to_delete = $this->current_queue->instances_to_delete();
     foreach ($instances_to_delete as $instance_id => $start_date) {
         // Don't process more than the current batch size allows
         if ($this->batch_complete()) {
             break;
         }
         if (!$this->current_queue->have_ownership_of_job()) {
             return;
         }
         Tribe__Events__Pro__Recurrence__Meta::delete_unexcluded_event($instance_id, $start_date);
         unset($instances_to_delete[$instance_id]);
         $this->processed++;
     }
     // Update the "to delete" list
     $this->current_queue->instances_to_delete($instances_to_delete);
 }
Пример #7
0
 /**
  * Returns an instance of the Child Events class.
  *
  * @return Tribe__Events__Pro__Recurrence__Children_Events
  */
 private static function children()
 {
     if (empty(self::$children)) {
         self::$children = Tribe__Events__Pro__Recurrence__Children_Events::instance();
     }
     return self::$children;
 }
Пример #8
0
 function tribe_get_recurrence_text($postId = null)
 {
     $postId = Tribe__Events__Main::postIdHelper($postId);
     return apply_filters('tribe_get_recurrence_text', Tribe__Events__Pro__Recurrence__Meta::recurrenceToTextByPost($postId));
 }