Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active August 7, 2019 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/fc545da115fc3dce9829fce6772dfd22 to your computer and use it in GitHub Desktop.
Save joshfeck/fc545da115fc3dce9829fce6772dfd22 to your computer and use it in GitHub Desktop.
Add a timestamp column and change the sort order to the Attendee Checkin admin page. Event Espresso 4.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_filter(
'FHEE_manage_event-espresso_page_espresso_registrations_columns',
'my_filter_registration_list_table_columns',
10,
2
);
add_action(
'AHEE__EE_Admin_List_Table__column_timestampcolumn__event-espresso_page_espresso_registrations',
'my_registration_list_table_timestampcolumn',
10,
2
);
add_filter(
'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
'my_change_reg_checkin_orderby',
10,
2
);
/**
* this function adds the column name to the array of table headers
*
* @param array $columns
* @param string $screen
* @return array
*/
function my_filter_registration_list_table_columns( $columns, $screen ) {
if ( $screen === "espresso_registrations_event_registrations" && isset($_REQUEST['DTT_ID']) ) {
$columns = EEH_Array::insert_into_array(
$columns,
array( 'timestampcolumn' => 'Checked In' ),
'ATT_fname',
false
);
}
return $columns;
}
/**
* this function echoes out the data you want to appear in your custom column.
*
* @param \EE_Registration $item
* @param string $screen
*/
function my_registration_list_table_timestampcolumn( $item, $screen ) {
if ( $screen === "espresso_registrations_event_registrations" && $item instanceof EE_Registration && isset($_REQUEST['DTT_ID'])) {
$DTT_ID = $_REQUEST['DTT_ID'];
if (! empty($DTT_ID)
&& EE_Registry::instance()->CAP->current_user_can(
'ee_read_checkins',
'espresso_registrations_registration_checkins'
)
) {
$timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
if (! empty($timestamps)) {
// get the last timestamp
$last_timestamp = end($timestamps);
// get timestamp string
$timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
echo $timestamp_string;
}
}
}
}
/**
* this function changes the sort order of the reg checkins page
*
* @param array $orderby
* @param array $data
* @return array
*/
function my_change_reg_checkin_orderby($orderby, $data) {
if(
(!isset($data['action']) || isset($data['DTT_ID'])) &&
isset($data['event_id']) &&
isset($data['page']) &&
$data['page'] == 'espresso_registrations'
) {
$orderby = array();
$orderby['Checkin.CHK_timestamp'] = 'ASC';
}
return $orderby;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment