Esempio n. 1
0
 /**
  * Get number of events per day
  *
  * @param int $date
  * @return array
  */
 private static function get_daily_counts($date)
 {
     global $wp_query;
     $count_args = self::$args;
     do_action('log', 'get_daily_counts $date', 'tribe-events-query', $date);
     $count_args['eventDisplay'] = 'month';
     $count_args['eventDate'] = date('Y-m', strtotime($date));
     $count_args['start_date'] = tribe_event_beginning_of_day($date);
     $count_args['end_date'] = tribe_event_end_of_day(date('Y-m-t', strtotime($date) + 1));
     $count_args['hide_upcoming_ids'] = self::$hide_upcoming_ids;
     $count_args['post_status'] = is_user_logged_in() ? array('publish', 'private') : 'publish';
     $count_args['tribeHideRecurrence'] = false;
     $result = TribeEventsQuery::getEventCounts($count_args);
     self::$event_daily_counts = $result['counts'];
     self::$event_daily_ids = $result['event_ids'];
     foreach (self::$event_daily_counts as $daily_count) {
         if ($daily_count > 0) {
             add_filter('tribe_events_month_has_events', '__return_true');
             break;
         }
     }
 }
Esempio n. 2
0
 /**
  * Sets up an array of $days based on the current query, that can be used in the calendar loop
  *
  * @return void
  * @since 3.0
  **/
 public function setup_view()
 {
     $tribe_ecp = TribeEvents::instance();
     $tribe_ecp->date = isset(self::$args['eventDate']) ? self::$args['eventDate'] : tribe_get_month_view_date();
     // get all upcoming ids to hide so we're not querying 31 times
     self::$hide_upcoming_ids = TribeEventsQuery::getHideFromUpcomingEvents();
     list($year, $month) = explode('-', $tribe_ecp->date);
     $first_date_of_month = mktime(12, 0, 0, $month, 1, $year);
     // 1st day of month as unix stamp
     $startOfWeek = get_option('start_of_week', 0);
     self::$event_daily_counts = self::get_daily_counts($first_date_of_month);
     if (empty(self::$tribe_bar_args)) {
         foreach ($_REQUEST as $key => $value) {
             if ($value && strpos($key, 'tribe-bar-') === 0 && $key != 'tribe-bar-date') {
                 self::$tribe_bar_args[$key] = $value;
             }
         }
     }
     // Var'ng up days, months and years
     self::$today = date_i18n('d');
     self::$current_month = date_i18n('m');
     self::$current_year = date_i18n('Y');
     // single dimensional array of days for the month
     $days = array();
     // setup counters
     $rawOffset = date('w', $first_date_of_month) - $startOfWeek;
     $prev_month_offset = (int) ($rawOffset < 0 ? $rawOffset + 7 : $rawOffset);
     // month begins on day x
     $days_in_month = (int) date('t', intval($first_date_of_month));
     $days_in_calendar = $days_in_month + $prev_month_offset;
     while ($days_in_calendar % 7 > 0) {
         $days_in_calendar++;
     }
     $week = 0;
     $cur_calendar_day = 0;
     // fill month with required days for previous month
     if ($prev_month_offset > 0) {
         $days = array_fill(0, $prev_month_offset, array('date' => 'previous'));
     }
     // get $cur_calendar_day up to speed
     $cur_calendar_day += $prev_month_offset;
     // add days for this month
     for ($i = 0; $i < $days_in_month; $i++) {
         $day = $i + 1;
         $date = date('Y-m-d', strtotime("{$year}-{$month}-{$day}"));
         $total_events = !empty(self::$event_daily_counts[$date]) ? self::$event_daily_counts[$date] : 0;
         $days[] = array('daynum' => $day, 'date' => $date, 'events' => self::get_daily_events($date), 'total_events' => $total_events, 'view_more' => self::view_more_link($date, self::$tribe_bar_args));
     }
     // get $cur_calendar_day up to speed
     $cur_calendar_day += $days_in_month;
     // check if $cur_calendar_day is less than $days_in_calendar, if so, add days for next month
     if ($cur_calendar_day < $days_in_calendar) {
         $days = array_merge($days, array_fill($cur_calendar_day, $days_in_calendar - $cur_calendar_day, array('date' => 'next')));
     }
     // store set of found days for use in calendar loop functions
     self::$calendar_days = $days;
 }