Tribe__Tickets__Attendees::get_render_context( int $post_id )

Returns the context used to render the Attendees page.


Parameters

$post_id

(int) (Required) The ID of the post to render the Attendees page for.


Top ↑

Return

(array<string,mixed>) The context used to render the Attendees page.


Top ↑

Source

File: src/Tribe/Attendees.php

	public function get_render_context( int $post_id ): array {
		$tickets = Tribe__Tickets__Tickets::get_event_tickets( $post_id );
		$tickets_by_type = [ 'rsvp' => [], 'default' => [] ];
		$ticket_totals = [
			'sold'      => 0,
			'available' => 0,
		];

		$available_contributors = [];

		// Split Tickets by their type.
		/** @var Ticket[] $tickets */
		foreach ( $tickets as $ticket ) {
			$ticket_type = $ticket->type();
			if ( ! isset( $tickets_by_type[ $ticket_type ] ) ) {
				$tickets_by_type[ $ticket_type ] = [];
			}
			$tickets_by_type[ $ticket_type ][] = $ticket;
			$ticket_totals['sold'] += $ticket->qty_sold();

			if ( $ticket_totals['available'] === - 1 ) {
				// Unlimited capacity trumps any other capacity; if already unlimited, it will stay unlimited.
				continue;
			}

			if ( - 1 === $ticket->available() ) {
				// Unlimited capacity trumps any other capacity: set to unlimited.
				$ticket_totals['available'] = - 1;
				continue;
			}

			if ( $ticket->global_stock_mode() === Global_Stock::OWN_STOCK_MODE ) {
				// Own stock: add to the available count.
				$ticket_totals['available'] += $ticket->available();
				continue;
			}

			if ( ! isset( $available_contributors[ (int) $ticket->get_event_id() ] ) ) {
				// Shared or capped capacity: add to the available contributors only if we haven't already counted it.
				$available_contributors[ (int) $ticket->get_event_id() ] = $ticket->available();
			}
		}

		if ( $ticket_totals['available'] !== - 1 && count( $available_contributors ) ) {
			$ticket_totals['available'] += array_sum( $available_contributors );
		}

		$context = [
			'attendees'         => $this,
			'event_id'          => $post_id,
			'tickets_by_type'   => $tickets_by_type,
			'ticket_totals'     => $ticket_totals,
			'type_icon_classes' => [
				'default' => 'tec-tickets__admin-attendees-overview-ticket-type-icon--ticket',
				'rsvp'    => 'tec-tickets__admin-attendees-overview-ticket-type-icon--rsvp',
			],
			'type_labels'       => [
				'default' => sprintf(
				// Translators: %s is the uppercase plural Tickets label.
					_x( 'Single %s', 'Ticket overview', 'event-tickets' ),
					tribe_get_ticket_label_plural( 'Ticket overview' )
				),
				'rsvp'    => __( 'RSVP', 'event-tickets' ),
			]
		];

		return $context;
	}

Top ↑

Changelog

Changelog
Version Description
5.8.0 Introduced.