Attendees::setup_template_vars()
Source
File: src/Tickets/Commerce/Reports/Attendees.php
public function setup_template_vars() {
$post_id = tribe_get_request_var( 'post_id' );
$post_id = tribe_get_request_var( 'event_id', $post_id );
$post = get_post( $post_id );
$post_type_object = get_post_type_object( $post->post_type );
$post_singular_label = $post_type_object->labels->singular_name;
$tickets = \Tribe__Tickets__Tickets::get_event_tickets( $post_id );
$ticket_ids = tribe_get_request_var( 'product_ids', false );
if ( false !== $ticket_ids ) {
$ticket_ids = array_map( 'absint', explode( ',', $ticket_ids ) );
$ticket_ids = array_filter(
$ticket_ids,
static function ( $ticket_id ) {
return get_post_type( $ticket_id ) === Commerce\Ticket::POSTTYPE;
}
);
$tickets = array_map( [ tribe( Commerce\Ticket::class ), 'get_ticket' ], $ticket_ids );
}
$event_data = [];
$tickets_data = [];
foreach ( $tickets as $ticket ) {
$quantities = tribe( Commerce\Ticket::class )->get_status_quantity( $ticket->ID );
$total_by_status = [];
foreach ( $quantities as $status_slug => $status_count ) {
if ( ! isset( $event_data['qty_by_status'][ $status_slug ] ) ) {
$event_data['qty_by_status'][ $status_slug ] = 0;
}
if ( ! isset( $event_data['total_by_status'][ $status_slug ] ) ) {
$event_data['total_by_status'][ $status_slug ] = [];
}
$total_by_status[ $status_slug ] = Price::sub_total( $ticket->price, $status_count );
$event_data['total_by_status'][ $status_slug ][] = $total_by_status[ $status_slug ];
$event_data['qty_by_status'][ $status_slug ] += (int) $status_count;
}
$tickets_data[ $ticket->ID ] = [
'total_by_status' => $total_by_status,
'qty_by_status' => $quantities,
];
}
$event_data['total_by_status'] = array_map(
static function ( $sub_totals ) {
return Price::total( $sub_totals );
},
$event_data['total_by_status']
);
$this->template_vars = [
'event_data' => $event_data,
'export_url' => '',
'post' => $post,
'post_id' => $post_id,
'post_singular_label' => $post_singular_label,
'post_type_object' => $post_type_object,
'report' => tribe( $this ),
'table' => tribe( Admin_Tables\Attendees::class ),
'tickets' => $tickets,
'tickets_data' => $tickets_data,
'title' => $this->get_title(),
'tooltip' => tribe( 'tooltip.view' ),
];
return $this->template_vars;
}
Changelog
| Version | Description |
|---|---|
| 5.2.0 | Introduced. |