/** * Sets up an array of $days based on the current query, that can be used in the calendar loop * * @return void **/ public function setup_view() { do_action('log', 'setup view month view args', 'tribe-month', self::$args); $requested_date = isset(self::$args['eventDate']) ? self::$args['eventDate'] : tribe_get_month_view_date(); $first_day_of_month = date('Y-m-01', strtotime($requested_date)); do_action('log', 'eventDate', 'tribe-events-query', $first_day_of_month); // get all upcoming ids to hide so we're not querying 31 times self::$hide_upcoming_ids = TribeEventsQuery::getHideFromUpcomingEvents(); $year = date('Y', strtotime($first_day_of_month)); $month = date('m', strtotime($first_day_of_month)); $startOfWeek = get_option('start_of_week', 0); self::get_daily_counts($first_day_of_month); if (empty(self::$tribe_bar_args)) { foreach ($_REQUEST as $key => $value) { if ($value && strpos($key, 'tribe') === 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', strtotime($first_day_of_month)) - $startOfWeek; $prev_month_offset = (int) ($rawOffset < 0 ? $rawOffset + 7 : $rawOffset); // month begins on day x $days_in_month = (int) date('t', strtotime($first_day_of_month)); $days_in_calendar = $days_in_month + $prev_month_offset; while ($days_in_calendar % 7 > 0) { $days_in_calendar++; } $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; $empty_query = new WP_Query(); // 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' => $total_events ? self::get_daily_events($date) : $empty_query, '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; }
/** * Sets up an array of $days based on the current query, that can be used in the calendar loop * * @return void **/ public function setup_view() { $requested_date = isset(self::$args['eventDate']) ? self::$args['eventDate'] : tribe_get_month_view_date(); $first_day_of_month = date('Y-m-01', strtotime($requested_date)); $first_grid_date = $this->calculate_first_cell_date($requested_date); $final_grid_date = $this->calculate_final_cell_date($requested_date); $days = array(); $this->setup_tribe_bar_args(); $this->current_day_vals(); do_action('log', 'setup view month view args', 'tribe-month', self::$args); do_action('log', 'eventDate', 'tribe-events-query', $first_day_of_month); self::$hide_upcoming_ids = TribeEventsQuery::getHideFromUpcomingEvents(); self::get_daily_counts($first_grid_date, $final_grid_date); $date = $first_grid_date; // Start with the first grid date $empty = new WP_Query(); // Use for empty days // Populate complete date range including leading/trailing days from adjacent months while ($date <= $final_grid_date) { $day = (int) substr($date, -2); $total_events = !empty(self::$event_daily_counts[$date]) ? self::$event_daily_counts[$date] : 0; $prev_month = (int) substr($date, 5, 2) < (int) substr($requested_date, 5, 2); $next_month = (int) substr($date, 5, 2) > (int) substr($requested_date, 5, 2); $month_type = self::CURRENT_MONTH; if ($prev_month) { $month_type = self::PREVIOUS_MONTH; } if ($next_month) { $month_type = self::NEXT_MONTH; } $days[] = array('daynum' => $day, 'date' => $date, 'events' => $total_events ? self::get_daily_events($date) : $empty, 'total_events' => $total_events, 'view_more' => self::view_more_link($date, self::$tribe_bar_args), 'month' => $month_type); // Record the indicies marking the portion of the array relating to the current month if (!isset($this->current_month_begins) && self::CURRENT_MONTH === $month_type) { $this->current_month_begins = count($days) - 1; } if (isset($this->current_month_begins) && !isset($this->current_month_ends) && self::CURRENT_MONTH !== $month_type) { $this->current_month_ends = count($days) - 1; } // Advance forward one day $date = date(TribeDateUtils::DBDATEFORMAT, strtotime("{$date} +1 day")); } // If the month ended without bleeding into the next month, our current_month_ends property may not be set if (!isset($this->current_month_ends)) { $this->current_month_ends = count($days) - 1; } // store set of found days for use in calendar loop functions self::$calendar_days = $days; }