BakerMan

Helper Class - TEC Recurring Event Concatenation

Aug 17th, 2012
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. /**
  2.  * This is a short helper class that can be used to "concatenate"
  3.  * events so that the dates of future recurring instances are listed
  4.  * beside the main event.
  5.  */
  6. class EventListOrganiser {
  7.     protected static $alreadyLooped = array();
  8.     protected static $query;
  9.    
  10.    
  11.     public static function hasDisplayedAlready() {
  12.         $displayed = in_array(get_the_ID(), self::$alreadyLooped);
  13.         self::$alreadyLooped[] = get_the_ID();
  14.         return $displayed;
  15.     }
  16.    
  17.    
  18.     public static function listFutureRecurringEventDates() {
  19.         self::findRecurringPosts(get_the_ID(), array(__CLASS__, 'printDates'));
  20.     }
  21.    
  22.    
  23.     protected function findRecurringPosts($id, $callback) {
  24.         self::$query = new WP_Query($GLOBALS['wp_query']->query_vars);
  25.         $idList = array();
  26.        
  27.         while (self::$query->have_posts()) {
  28.             self::$query->the_post();
  29.  
  30.             if (self::$query->post->ID === $id) {
  31.                 if (in_array($id, $idList))
  32.                     call_user_func($callback); 
  33.                    
  34.                 $idList[] = $id;       
  35.             }
  36.         }
  37.     }
  38.    
  39.    
  40.     protected function printDates() {
  41.         echo '<li>'.tribe_get_start_date().'</li>';
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment