; /** * Filters Whether the Latest Past Events Should Show for a specific View. * * @since 5.1.0 * * @param boolean $show If we should display Latest Past Events. * @param View $instance The current View object. */ $show = apply_filters( "tribe_events_views_v2_{$this->get_slug()}_show_latest_past_events_view", $show, $this ); return $show; } /** * Setup of Additional Views into another View. * * @since 5.1.0 * * @param array $events Array that will be counted to verify if we have events. * @param array $template_vars An associative array of variables that will be set, and exported, in the template. */ protected function setup_additional_views( array $events = [], array $template_vars = [] ) { $manager = tribe( Manager::class ); $default_slug = $manager->get_default_view_option(); // If the slug is `default`, get the slug another way. if ( 'default' === $default_slug ) { $default_class = $manager->get_default_view(); $default_slug = $manager->get_view_slug_by_class( $default_class ); } // Show Latest Past Events only on the default view. if ( $this->get_slug() !== $default_slug ) { return; } // If doing a search, do not show. if ( $this->context->get( 'keyword', '' ) ) { return; } // If no events found, do not show. if ( 0 === tribe_events()->found() ) { return; } $now = $this->context->get( 'now', time() ); $latest = tribe_events_latest_date(); // If now is less then the latest event published, do not show. if ( $now < $latest ) { return; } // Checks to verify on the initial load of a view or if using today's date for the view. $today = $this->context->get( 'today' ); $view_date = $this->context->get( 'event_date', '' ); switch ( $this->get_slug() ) { case 'month': $today_formatted = Dates::build_date_object( $today )->format( Dates::DBYEARMONTHTIMEFORMAT ); $view_date_formatted = Dates::build_date_object( $view_date )->format( Dates::DBYEARMONTHTIMEFORMAT ); break; case 'week': list( $today_week_start, $today_week_end ) = Dates::get_week_start_end( $today, (int) $this->context->get( 'start_of_week', 0 ) ); list( $view_week_start, $view_week_end ) = Dates::get_week_start_end( $view_date, (int) $this->context->get( 'start_of_week', 0 ) ); $today_formatted = $today_week_start->format( Dates::DBDATEFORMAT ); $view_date_formatted = $view_week_start->format( Dates::DBDATEFORMAT ); break; default: $today_formatted = Dates::build_date_object( $today )->format( Dates::DBDATEFORMAT ); $view_date_formatted = Dates::build_date_object( $view_date )->format( Dates::DBDATEFORMAT ); } // If view date is not empty and today does not equal the view date, then do not show. if ( ! empty( $view_date ) && $today_formatted !== $view_date_formatted ) { return; } // Flatten Views such as Month and Week that have an array values. $first_value = reset( $events ); if ( is_array( $first_value ) ) { $events = array_unique( array_merge( ...array_values( $events ) ), SORT_REGULAR ); } /** * Filters The Threshold to Show The Latest Past Events. * Defaults to show when there are Zero Events. * * @since 5.1.0 * * @param int The threshold to show The Latest Past Events. * @param array $events Array that will be counted to verify if we have events. * @param array $template_vars An associative array of variables that will be set, and exported, in the template. * @param View $instance The current View object. */ $latest_past_threshold = apply_filters( 'tribe_events_views_v2_threshold_to_show_latest_past_events', absint( 0 ), $events, $template_vars, $this ); // If threshold is less than upcoming events, do not show Recent Past Events. if ( $latest_past_threshold < count( $events ) ) { return; } if ( ! empty( $template_vars['show_latest_past'] ) ) { $template_vars['show_latest_past'] = true; $latest_past_view = static::make( Latest_Past_View::Class ); $latest_past_view->set_context( $this->context ); $latest_past_view->add_view_filters(); } } /** * Returns the number of upcoming events in relation to the "now" time. * * @since 5.2.0 * * @return int The number of upcoming events from "now". */ protected function upcoming_events_count() { $now = $this->context->get( 'now', Dates::build_date_object()->format( 'Y-m-d H:i:s' ) ); $from_date = tribe_beginning_of_day( $now ); return (int) tribe_events()->where( 'starts_after', $from_date )->found(); } /** * Returns the View current URL query arguments, parsed from the View `get_url()` method. * * Since there are a number of parties filtering each View URL arguments, this method will * parse a View URL query arguments from its filtered URL. This will include all the modifications * done to a View URL by other plugins and add-ons. * * @since 5.3.0 * * @return array The current View URL args or an empty array if the View URL is empty * or not valid.. */ public function get_url_args() { $view_url = $this->get_url( false ); $view_query_str = wp_parse_url( $view_url, PHP_URL_QUERY ); if ( empty( $view_query_str ) ) { // This might happen if the URL is too mangled to be parsed. return []; } parse_str( $view_query_str, $view_query_args ); return (array) $view_query_args; } /** * Initializes the View repository args, if required, and * applies them to the View repository instance. * * @since 4.6.0 */ protected function get_repository_args() { if ( ! empty( $this->repository_args ) ) { return $this->repository_args; } return $this->filter_repository_args( $this->setup_repository_args() ); } /** * Sets up the View repository args to produce the correct list of Events * in the context of an iCalendar export. * * @since 4.6.0 * * @param int $per_page The number of events per page to show in the iCalendar * export. The value will override whatever events per page * setting the View might have. */ protected function setup_ical_repository_args( $per_page ) { if ( empty( $this->repository_args ) ) { $this->repository->by_args( $this->filter_ical_repository_args( $this->get_repository_args() ) ); } // Overwrites the amount of posts manually for ical. $this->repository->per_page( $per_page ); } /** * Filters the repository arguments that will be used to set up the View repository instance for iCal requests. * * @since 4.6.0 * * @param array $repository_args The repository arguments that will be used to set up the View repository instance. * * @return array The filtered repository arguments for ical requests. */ protected function filter_ical_repository_args( $repository_args ) { /** * Filters the repository args for a View on iCal requests. * * @since 4.6.0 * * @param array $repository_args An array of repository arguments that will be set for all Views. * @param View_Interface $this The View that will use the repository arguments. */ $repository_args = apply_filters( 'tribe_events_views_v2_view_ical_repository_args', $repository_args, $this ); /** * Filters the repository args for a specific View on iCal requests. * * @since 4.6.0 * * @param array $repository_args An array of repository arguments that will be set for a specific View. * @param View_Interface $this The View that will use the repository arguments. */ $repository_args = apply_filters( "tribe_events_views_v2_view_{$this->slug}_ical_repository_args", $repository_args, $this ); return $repository_args; } /** * {@inheritdoc} */ public function get_ical_ids( $per_page ) { $this->setup_ical_repository_args( $per_page ); $ids = $this->repository->get_ids(); // Reset the repository args to force a re-initialization of the repository on next run. $this->repository_args = null; return $ids; } /** * {@inheritdoc} */ public function set_url_object( Url $url_object ) { $this->url = $url_object; } /** * {@inheritdoc} */ public function disable_url_management() { $this->should_manage_url = false; return $this; } /** * Gets the base object for asset registration. * * @since 5.7.0 * * @return \stdClass $object Object to tie registered assets to. */ public static function get_asset_origin( $slug ) { $asset_registration_object = tribe( 'tec.main' ); /** * Filters the object used for registering assets. * * @since 5.7.0 * * @param \stdClass $origin_object Object used for asset registration. * @param string $slug View slug. */ $asset_registration_object = apply_filters( "tribe_events_views_v2_view_{$slug}_asset_origin_object", $asset_registration_object, $slug ); return $asset_registration_object; } /** * Registers assets for the view. * * Should be overridden if there are assets for the view. * * @since 5.7.0 * * @param \stdClass $object Object to tie registered assets to. */ public static function register_assets( $object ) { // Default to a no-op. } }