/** * 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() { if ($this->use_cache && $this->html_cache->get() !== false) { return; } $requested_date = $this->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(); self::$hide_upcoming_ids = Tribe__Events__Query::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(Tribe__Events__Date_Utils::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; }
/** * Returns a posts-not-in SQL fragment for use in a WHERE clause or else an empty * string if it is unneeded. * * @return string */ protected function hidden_events_fragment() { global $wpdb; // Despite the method name, this obtains a list of post IDs to be hidden from *all* event listings $ignore_events = Tribe__Events__Query::getHideFromUpcomingEvents(); // If it is empty we don't need to do anything further if (empty($ignore_events)) { return ''; } // Let's ensure they are all absolute integers then collapse into a string $ignore_events = implode(',', array_map('absint', $ignore_events)); // Terminate with AND so it can easily be combined with the rest of the WHERE clause return " {$wpdb->posts}.ID NOT IN ( {$ignore_events} ) AND "; }
/** * This Week Query * * * @return object */ public static function this_week_query($this_week_query_vars) { //Only Get Private Events if user can view $post_status = array('publish'); if (current_user_can('read_private_tribe_events')) { $post_status[] = 'private'; } //Get Events with Hide From Event Listings Checked $hide_upcoming_ids = Tribe__Events__Query::getHideFromUpcomingEvents(); $this_week_widget_args = array('post_type' => Tribe__Events__Main::POSTTYPE, 'tax_query' => $this_week_query_vars['tax_query'], 'eventDisplay' => 'custom', 'start_date' => $this_week_query_vars['start_date'], 'end_date' => $this_week_query_vars['end_date'], 'post_status' => $post_status, 'tribeHideRecurrence' => false, 'post__not_in' => $hide_upcoming_ids, 'tribe_render_context' => 'widget', 'posts_per_page' => -1); /** * Filter This Week Widget args * * @param array $this_week_widget_args Arguments for This Week Widget */ $this_week_widget_args = apply_filters('tribe_events_pro_this_week_widget_query_args', $this_week_widget_args); // Get all the upcoming events for this week $events = tribe_get_events($this_week_widget_args, true); //Days Array to set events for each day $week_days = array(); //Set First Day $day = $this_week_query_vars['start_date']; //Get Day Range $day_range = self::get_day_range(); //Todays Date According to WordPress $timestamp_today = strtotime(current_time(Tribe__Date_Utils::DBDATEFORMAT)); //Date Formats from The Events Calendar $display_date_format = apply_filters('tribe_events_this_week_date_format', 'jS'); $display_day_format = apply_filters('tribe_events_this_week_day_format', 'D '); // Array used for calculation of php strtotime relative dates $weekday_array = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); //Build an Array for Each Day foreach ($day_range as $i => $day_number) { //If Hide Weekends True then skip those days if ($this_week_query_vars['hide_weekends'] === 'true' && ($day_number == 0 || $day_number == 6)) { continue; } // figure out the $date that we're currently looking at if ($day_number >= $day_range[0]) { // usually we can just get the date for the next day $date = date(Tribe__Date_Utils::DBDATEFORMAT, strtotime($day . "+{$i} days")); } else { //Start Day of week in the Middle and not in typical Sunday or Monday $date = date(Tribe__Date_Utils::DBDATEFORMAT, strtotime("Next {$weekday_array[$day_number]}", strtotime($day))); } $this_week_events_sticky = $this_week_events = array(); if ($events->have_posts()) { //loop through all events and sort based on sticky or not foreach ($events->posts as $j => $event) { if (tribe_event_is_on_date($date, $event)) { $event->days_between = tribe_get_days_between($event->EventStartDate, $event->EventEndDate, true); if ($event->menu_order == -1) { $this_week_events_sticky[] = $event; } else { $this_week_events[] = $event; } } } } //Merge the two arrays for the day only if sticky events are included for that day if (!empty($this_week_events_sticky) && is_array($this_week_events_sticky) && is_array($this_week_events)) { $this_week_events = array_merge($this_week_events_sticky, $this_week_events); } $formatted_date = date_i18n($display_date_format, strtotime($date)); $formatted_day = date_i18n($display_day_format, strtotime($date)); $timestamp_date = strtotime($date); // create the "day" element to do display in the template $week_days[] = array('date' => $date, 'day_number' => $day_number, 'formatted_date' => $formatted_date, 'formatted_day' => $formatted_day, 'is_today' => $timestamp_date == $timestamp_today ? true : false, 'is_past' => $timestamp_date < $timestamp_today ? true : false, 'is_future' => $timestamp_date > $timestamp_today ? true : false, 'this_week_events' => $this_week_events, 'has_events' => $this_week_events, 'total_events' => count($this_week_events), 'events_limit' => $this_week_query_vars['count'], 'view_more' => count($this_week_events) > $this_week_query_vars['count'] ? esc_url_raw(tribe_get_day_link($date)) : false); } return $week_days; }