Tribe__Tickets__Attendees_Table::prepare_items()
Prepares the list of items for displaying.
Source
File: src/Tribe/Attendees_Table.php
public function prepare_items() {
$this->process_actions();
$current_page = $this->get_pagenum();
$per_page = $this->get_items_per_page( $this->per_page_option );
$pagination_args = [
'total_items' => 0,
'per_page' => $per_page,
];
$args = [
'page' => $current_page,
'per_page' => $per_page,
'return_total_found' => true,
];
$event_id = empty( $_GET['event_id'] ) ? 0 : absint( $_GET['event_id'] );
$search = empty( $_REQUEST['s'] ) ? null : sanitize_text_field( $_REQUEST['s'] );
if ( ! empty( $search ) ) {
$search_keys = [
'purchaser_name',
'purchaser_email',
'order_status',
'product_id',
'security_code',
'user',
];
/**
* Filters the item keys that can be used to filter attendees while searching them.
*
* @since 4.7
* @since 4.10.6 Deprecated usage of $items attendees list.
*
* @param array $search_keys The keys that can be used to search attendees.
* @param array $items (deprecated) The attendees list.
* @param string $search The current search string.
*/
$search_keys = apply_filters( 'tribe_tickets_search_attendees_by', $search_keys, [], $search );
// Default selection.
$search_key = 'purchaser_name';
$search_type = sanitize_text_field( tribe_get_request_var( 'tribe_attendee_search_type' ) );
if ( $search_type && in_array( $search_type, $search_keys, true ) ) {
$search_key = $search_type;
}
$search_like_keys = [
'purchaser_name',
'purchaser_email',
];
/**
* Filters the item keys that support LIKE matching to filter attendees while searching them.
*
* @since 4.10.6
*
* @param array $search_like_keys The keys that support LIKE matching.
* @param array $search_keys The keys that can be used to search attendees.
* @param string $search The current search string.
*/
$search_like_keys = apply_filters( 'tribe_tickets_search_attendees_by_like', $search_like_keys, $search_keys, $search );
// Update search key if it supports LIKE matching.
if ( in_array( $search_key, $search_like_keys, true ) ) {
$search_key .= '__like';
$search = '%' . $search . '%';
}
// Only get matches that have search phrase in the key.
$args['by'] = [
$search_key => [
$search,
],
];
}
$item_data = Tribe__Tickets__Tickets::get_event_attendees_by_args( $event_id, $args );
$items = [];
if ( ! empty( $item_data ) ) {
$items = $item_data['attendees'];
$pagination_args['total_items'] = $item_data['total_found'];
}
$this->items = $items;
$this->set_pagination_args( $pagination_args );
}