'attendee',
'plural' => 'attendees',
'ajax' => true,
'screen' => get_current_screen(),
) );
// Fetch the event Object
if ( ! empty( $_GET['event_id'] ) ) {
$this->event = get_post( $_GET['event_id'] );
}
add_filter( 'event_tickets_attendees_table_row_actions', array( $this, 'add_default_row_actions' ), 10, 2 );
parent::__construct( apply_filters( 'tribe_events_tickets_attendees_table_args', $args ) );
}
/**
* Get a list of columns. The format is:
* 'internal-name' => 'Title'
*
* @return array
*/
public static function get_table_columns() {
$columns = array(
'cb' => '',
'ticket' => esc_html_x( 'Ticket', 'attendee table', 'event-tickets' ),
'primary_info' => esc_html_x( 'Primary Information', 'attendee table', 'event-tickets' ),
'security' => esc_html_x( 'Security Code', 'attendee table', 'event-tickets' ),
'status' => esc_html_x( 'Status', 'attendee table', 'event-tickets' ),
'check_in' => esc_html_x( 'Check in', 'attendee table', 'event-tickets' ),
);
/**
* Controls the columns rendered within the attendee screen.
*
* @param array $columns
*/
return apply_filters( 'tribe_tickets_attendee_table_columns', $columns );
}
/**
* Display the search box.
* We don't want Core's search box, because we implemented our own jQuery based filter,
* so this function overrides the parent's one and returns empty.
*
* @param string $text The search button text
* @param string $input_id The search input id
*/
public function search_box( $text, $input_id ) {
return;
}
/**
* Display the pagination.
* We are not paginating the attendee list, so it returns empty.
*/
public function pagination( $which ) {
return '';
}
/**
* Checks the current user's permissions
*/
public function ajax_user_can() {
return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
}
/**
* Get a list of columns. The format is:
* 'internal-name' => 'Title'
*
* @return array
*/
public function get_columns() {
return self::get_table_columns();
}
/**
* Handler for the columns that don't have a specific column_{name} handler function.
*
* @param $item
* @param $column
*
* @return string
*/
public function column_default( $item, $column ) {
$value = empty( $item[ $column ] ) ? '' : $item[ $column ];
return apply_filters( 'tribe_events_tickets_attendees_table_column', $value, $item, $column );
}
/**
* Handler for the checkbox column
*
* @param $item
*
* @return string
*/
public function column_cb( $item ) {
return sprintf( '', esc_attr( $this->_args['singular'] ), esc_attr( $item['attendee_id'] . '|' . $item['provider'] ) );
}
/**
* Populates the purchaser column.
*
* @param array $item
*
* @return string
*/
public function column_primary_info( array $item ) {
$purchaser_name = empty( $item[ 'purchaser_name' ] ) ? '' : esc_html( $item[ 'purchaser_name' ] );
$purchaser_email = empty( $item[ 'purchaser_email' ] ) ? '' : esc_html( $item[ 'purchaser_email' ] );
return "
{$purchaser_name}
{$purchaser_email}
";
}
/**
* Populates the status column.
*
* @param array $item
*
* @return string
*/
public function column_status( array $item ) {
$icon = '';
$warning = false;
// Check if the order_warning flag has been set (to indicate the order has been cancelled, refunded etc)
if ( isset( $item['order_warning'] ) && $item['order_warning'] ) {
$warning = true;
}
// If the warning flag is set, add the appropriate icon
if ( $warning ) {
$icon = sprintf( " ", esc_url( Tribe__Tickets__Main::instance()->plugin_url . 'src/resources/images/warning.png' ) );
}
// Look for an order_status_label, fall back on the actual order_status string @todo remove fallback in 3.4.3
if ( empty( $item['order_status'] ) ) {
$item['order_status'] = '';
}
$label = isset( $item['order_status_label'] ) ? $item['order_status_label'] : ucwords( $item['order_status'] );
$order_id_url = $this->get_order_id_url( $item );
if ( ! empty( $order_id_url ) && ! empty( $item[ 'order_id' ] ) ) {
$label = '#' . esc_html( $item[ 'order_id' ] ) . ' – ' . $label . '';
} elseif ( ! empty( $item[ 'order_id' ] ) ) {
$label = '#' . esc_html( $item[ 'order_id' ] ) . ' – ' . $label;
}
/**
* Provides an opportunity to modify the order status text within
* the attendees table.
*
* @param string $order_status_html
* @param array $item
*/
return apply_filters( 'tribe_tickets_attendees_table_order_status', $icon . $label, $item );
}
/**
* Retrieves the order id for the specified table row item.
*
* In some cases, such as when the current item belongs to the RSVP provider, an
* empty string may be returned as there is no order screen that can be linekd to.
*
* @param array $item
*
* @return string
*/
public function get_order_id_url( array $item ) {
// Backwards compatibility
if ( empty( $item['order_id_url'] ) ) {
$item['order_id_url'] = get_edit_post_link( $item['order_id'], true );
}
return $item['order_id_url'];
}
/**
* Handler for the ticket column
*
* @since 4.1
*
* @param array $item Item whose ticket data should be output
*
* @return string
*/
public function column_ticket( $item ) {
ob_start();
$attendee_id = trim( esc_html( $this->get_attendee_id( $item ) ) );
if ( ! empty( $attendee_id ) ) {
$attendee_id .= ' – ';
}
?>
get_row_actions( $item ); ?>
' . $row_actions . '';
}
/**
* Adds a set of default row actions to each item in the attendee list table.
*
* @param array $row_actions
* @param array $item
*
* @return array
*/
public function add_default_row_actions( array $row_actions, array $item ) {
$attendee = esc_attr( $item['attendee_id'] . '|' . $item['provider'] );
$nonce = wp_create_nonce( 'do_item_action_' . $attendee );
$check_in_out_url = esc_url( add_query_arg( array(
'action' => $item[ 'check_in' ] ? 'uncheck_in' : 'check_in',
'nonce' => $nonce,
'attendee' => $attendee,
) ) );
$check_in_out_text = $item[ 'check_in' ]
? esc_html_x( 'Undo Check In', 'row action', 'event-tickets' )
: esc_html_x( 'Check In', 'row action', 'event-tickets' );
$delete_url = esc_url( add_query_arg( array(
'action' => 'delete_attendee',
'nonce' => $nonce,
'attendee' => $attendee,
) ) );
$default_actions = array(
'' . $check_in_out_text . '',
);
if ( is_admin() ) {
$default_actions[] = '' . esc_html_x( 'Move', 'row action', 'event-tickets' ) . '';
}
$default_actions[] = '' . esc_html_x( 'Delete', 'row action', 'event-tickets' ) . '';
return array_merge( $row_actions, $default_actions );
}
/**
* Returns the attendee ID (or "unique ID" if set).
*
* @param array $item
*
* @return int|string
*/
public function get_attendee_id( $item ) {
$attendee_id = empty( $item['attendee_id'] ) ? '' : $item['attendee_id'];
if ( $attendee_id === '' ) {
return '';
}
$unique_id = get_post_meta( $attendee_id, '_unique_id', true );
if ( $unique_id === '' ) {
$unique_id = $attendee_id;
}
/**
* Filters the ticket number; defaults to the ticket unique ID.
*
* @param string $unique_id A unique string identifier for the ticket.
* @param array $item The item entry.
*/
return apply_filters( 'tribe_events_tickets_attendees_table_attendee_id_column', $unique_id, $item );
}
/**
* Handler for the check in column
*
* @param $item
*
* @return string
*/
public function column_check_in( $item ) {
$default_checkin_stati = array();
$provider = $item['provider_slug'];
$order_id = $item['order_id'];
/**
* Filters the order stati that will allow for a ticket to be checked in for all commerce providers.
*
* @since 4.1
*
* @param array $default_checkin_stati An array of default order stati that will make a ticket eligible for check-in.
* @param string $provider The ticket provider slug.
* @param int $order_id The order post ID.
*/
$check_in_stati = apply_filters( 'event_tickets_attendees_checkin_stati', $default_checkin_stati, $provider, $order_id );
/**
* Filters the order stati that will allow for a ticket to be checked in for a specific commerce provider.
*
* @since 4.1
*
* @param array $default_checkin_stati An array of default order stati that will make a ticket eligible for check-in.
* @param int $order_id The order post ID.
*/
$check_in_stati = apply_filters( "event_tickets_attendees_{$provider}_checkin_stati", $check_in_stati, $order_id );
if (
! empty( $item['order_status'] )
&& ! empty( $item['order_id_link_src'] )
&& is_array( $check_in_stati )
&& ! in_array( $item['order_status'], $check_in_stati )
) {
$button_template = '%s';
return sprintf( $button_template, $item['order_id_link_src'], __( 'View order', 'event-tickets' ) );
}
$button_classes = ! empty( $item['order_status'] ) && in_array( $item['order_status'], $check_in_stati ) ?
'button-primary' : 'button-primary button-disabled';
if ( empty( $this->event ) ) {
$checkin = sprintf(
'%s',
esc_attr( $item['attendee_id'] ),
esc_attr( $item['provider'] ),
esc_attr( $button_classes ),
esc_html__( 'Check In', 'event-tickets' )
);
$uncheckin = sprintf(
'%s',
esc_attr( $item['attendee_id'] ),
esc_attr( $item['provider'] ),
sprintf(
'