@@ -18,226 +18,226 @@ |
||
| 18 | 18 | class EE_Registration_CheckIn_List_Table extends EE_Admin_List_Table |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * EE_Registration_CheckIn_List_Table constructor. |
|
| 23 | - * |
|
| 24 | - * @param EE_Admin_Page $admin_page |
|
| 25 | - */ |
|
| 26 | - public function __construct($admin_page) |
|
| 27 | - { |
|
| 28 | - parent::__construct($admin_page); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @throws EE_Error |
|
| 34 | - */ |
|
| 35 | - protected function _setup_data() |
|
| 36 | - { |
|
| 37 | - $this->_data = $this->_get_checkins($this->_per_page); |
|
| 38 | - $this->_all_data_count = $this->_get_checkins($this->_per_page, true); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Sets up the properties for the list table. |
|
| 44 | - */ |
|
| 45 | - protected function _set_properties() |
|
| 46 | - { |
|
| 47 | - $this->_wp_list_args = array( |
|
| 48 | - 'singular' => __('check-in', 'event_espresso'), |
|
| 49 | - 'plural' => __('check-ins', 'event_espresso'), |
|
| 50 | - 'ajax' => true, |
|
| 51 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 52 | - ); |
|
| 53 | - |
|
| 54 | - $this->_columns = array( |
|
| 55 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
| 56 | - 'CHK_in' => __('Check-In', 'event_espresso'), |
|
| 57 | - 'CHK_timestamp' => __('Timestamp', 'event_espresso'), |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - $this->_sortable_columns = array( |
|
| 61 | - 'CHK_timestamp' => array('CHK_timestamp' => true), |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - $this->_primary_column = 'CHK_in'; |
|
| 65 | - |
|
| 66 | - $this->_hidden_columns = array(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return array |
|
| 72 | - */ |
|
| 73 | - protected function _get_table_filters() |
|
| 74 | - { |
|
| 75 | - return []; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Returning an empty string to remove the search box for this view. |
|
| 81 | - * |
|
| 82 | - * @param string $text |
|
| 83 | - * @param string $input_id |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - public function search_box($text, $input_id) |
|
| 87 | - { |
|
| 88 | - return ''; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @throws EE_Error |
|
| 94 | - */ |
|
| 95 | - protected function _add_view_counts() |
|
| 96 | - { |
|
| 97 | - $this->_views['all']['count'] = $this->_get_checkins(null, true); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param EE_Checkin $item |
|
| 103 | - * @return string |
|
| 104 | - * @throws EE_Error |
|
| 105 | - * @throws InvalidArgumentException |
|
| 106 | - * @throws ReflectionException |
|
| 107 | - * @throws InvalidDataTypeException |
|
| 108 | - * @throws InvalidInterfaceException |
|
| 109 | - */ |
|
| 110 | - public function column_cb($item) |
|
| 111 | - { |
|
| 112 | - return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID()); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param EE_Checkin $item |
|
| 118 | - * @return string |
|
| 119 | - * @throws EE_Error |
|
| 120 | - * @throws InvalidArgumentException |
|
| 121 | - * @throws InvalidDataTypeException |
|
| 122 | - * @throws InvalidInterfaceException |
|
| 123 | - * @throws ReflectionException |
|
| 124 | - */ |
|
| 125 | - public function column_CHK_in(EE_Checkin $item) |
|
| 126 | - { |
|
| 127 | - $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
| 128 | - return '<span class="' |
|
| 129 | - . $checkin_status_dashicon->cssClasses() |
|
| 130 | - . '"></span><span class="show-on-mobile-view-only">' |
|
| 131 | - . $item->get_datetime('CHK_timestamp') |
|
| 132 | - . '</span>'; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param EE_Checkin $item |
|
| 138 | - * @return string |
|
| 139 | - * @throws EE_Error |
|
| 140 | - * @throws InvalidArgumentException |
|
| 141 | - * @throws InvalidDataTypeException |
|
| 142 | - * @throws InvalidInterfaceException |
|
| 143 | - * @throws ReflectionException |
|
| 144 | - */ |
|
| 145 | - public function column_CHK_timestamp(EE_Checkin $item) |
|
| 146 | - { |
|
| 147 | - $actions = array(); |
|
| 148 | - $delete_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 149 | - array( |
|
| 150 | - 'action' => 'delete_checkin_row', |
|
| 151 | - 'DTT_ID' => $this->_req_data['DTT_ID'], |
|
| 152 | - '_REG_ID' => $this->_req_data['_REG_ID'], |
|
| 153 | - 'CHK_ID' => $item->ID(), |
|
| 154 | - ) |
|
| 155 | - ); |
|
| 156 | - $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 157 | - 'ee_delete_checkins', |
|
| 158 | - 'espresso_registrations_delete_checkin_row' |
|
| 159 | - ) |
|
| 160 | - ? '<a href="' . $delete_url . '" title="' |
|
| 161 | - . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' |
|
| 162 | - . __('Delete', 'event_espresso') . '</a>' |
|
| 163 | - : ''; |
|
| 164 | - |
|
| 165 | - return sprintf( |
|
| 166 | - '%1$s %2$s', |
|
| 167 | - $item->get_datetime('CHK_timestamp', '', 'H:i:s a'), |
|
| 168 | - $this->row_actions($actions) |
|
| 169 | - ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * This retrieves all the Check-ins for the given parameters. |
|
| 175 | - * experimenting with having the query for the table values within the list table. |
|
| 176 | - * |
|
| 177 | - * @param int $per_page How many to retrieve per page |
|
| 178 | - * @param bool $count Whether to return a count or not |
|
| 179 | - * @return EE_Checkin[]|int |
|
| 180 | - * @throws EE_Error |
|
| 181 | - * @throws InvalidArgumentException |
|
| 182 | - * @throws InvalidDataTypeException |
|
| 183 | - * @throws InvalidInterfaceException |
|
| 184 | - */ |
|
| 185 | - protected function _get_checkins($per_page = 10, $count = false) |
|
| 186 | - { |
|
| 187 | - $REG_ID = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : false; |
|
| 188 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : false; |
|
| 189 | - |
|
| 190 | - // if user does not have the capability for the checkins for this registration then get out! |
|
| 191 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 192 | - 'ee_read_checkin', |
|
| 193 | - 'espresso_registrations_registration_checkins', |
|
| 194 | - $REG_ID |
|
| 195 | - )) { |
|
| 196 | - return $count ? 0 : array(); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // if no reg id then get out cause need a reg id |
|
| 200 | - if (empty($REG_ID) || empty($DTT_ID)) { |
|
| 201 | - throw new EE_Error( |
|
| 202 | - __( |
|
| 203 | - 'This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', |
|
| 204 | - 'event_espresso' |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // set orderby |
|
| 210 | - // note that with this table we're only providing the option to orderby the timestamp value. |
|
| 211 | - $orderby = 'CHK_timestamp'; |
|
| 212 | - |
|
| 213 | - $order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 214 | - |
|
| 215 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 216 | - ? $this->_req_data['paged'] |
|
| 217 | - : 1; |
|
| 218 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 219 | - ? $this->_req_data['perpage'] |
|
| 220 | - : $per_page; |
|
| 221 | - $limit = null; |
|
| 222 | - if (! $count) { |
|
| 223 | - $offset = ($current_page - 1) * $per_page; |
|
| 224 | - $limit = array($offset, $per_page); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $_where = array( |
|
| 228 | - 'REG_ID' => $REG_ID, |
|
| 229 | - 'DTT_ID' => $DTT_ID, |
|
| 230 | - ); |
|
| 231 | - |
|
| 232 | - $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
| 233 | - |
|
| 234 | - // if no per_page value then we just want to return a count of all Check-ins |
|
| 235 | - if ($count) { |
|
| 236 | - return EEM_Checkin::instance()->count(array($_where)); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $count |
|
| 240 | - ? EEM_Checkin::instance()->count(array($_where)) |
|
| 241 | - : EEM_Checkin::instance()->get_all($query_params); |
|
| 242 | - } |
|
| 21 | + /** |
|
| 22 | + * EE_Registration_CheckIn_List_Table constructor. |
|
| 23 | + * |
|
| 24 | + * @param EE_Admin_Page $admin_page |
|
| 25 | + */ |
|
| 26 | + public function __construct($admin_page) |
|
| 27 | + { |
|
| 28 | + parent::__construct($admin_page); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @throws EE_Error |
|
| 34 | + */ |
|
| 35 | + protected function _setup_data() |
|
| 36 | + { |
|
| 37 | + $this->_data = $this->_get_checkins($this->_per_page); |
|
| 38 | + $this->_all_data_count = $this->_get_checkins($this->_per_page, true); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Sets up the properties for the list table. |
|
| 44 | + */ |
|
| 45 | + protected function _set_properties() |
|
| 46 | + { |
|
| 47 | + $this->_wp_list_args = array( |
|
| 48 | + 'singular' => __('check-in', 'event_espresso'), |
|
| 49 | + 'plural' => __('check-ins', 'event_espresso'), |
|
| 50 | + 'ajax' => true, |
|
| 51 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 52 | + ); |
|
| 53 | + |
|
| 54 | + $this->_columns = array( |
|
| 55 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
| 56 | + 'CHK_in' => __('Check-In', 'event_espresso'), |
|
| 57 | + 'CHK_timestamp' => __('Timestamp', 'event_espresso'), |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + $this->_sortable_columns = array( |
|
| 61 | + 'CHK_timestamp' => array('CHK_timestamp' => true), |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + $this->_primary_column = 'CHK_in'; |
|
| 65 | + |
|
| 66 | + $this->_hidden_columns = array(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return array |
|
| 72 | + */ |
|
| 73 | + protected function _get_table_filters() |
|
| 74 | + { |
|
| 75 | + return []; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Returning an empty string to remove the search box for this view. |
|
| 81 | + * |
|
| 82 | + * @param string $text |
|
| 83 | + * @param string $input_id |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + public function search_box($text, $input_id) |
|
| 87 | + { |
|
| 88 | + return ''; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @throws EE_Error |
|
| 94 | + */ |
|
| 95 | + protected function _add_view_counts() |
|
| 96 | + { |
|
| 97 | + $this->_views['all']['count'] = $this->_get_checkins(null, true); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param EE_Checkin $item |
|
| 103 | + * @return string |
|
| 104 | + * @throws EE_Error |
|
| 105 | + * @throws InvalidArgumentException |
|
| 106 | + * @throws ReflectionException |
|
| 107 | + * @throws InvalidDataTypeException |
|
| 108 | + * @throws InvalidInterfaceException |
|
| 109 | + */ |
|
| 110 | + public function column_cb($item) |
|
| 111 | + { |
|
| 112 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID()); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param EE_Checkin $item |
|
| 118 | + * @return string |
|
| 119 | + * @throws EE_Error |
|
| 120 | + * @throws InvalidArgumentException |
|
| 121 | + * @throws InvalidDataTypeException |
|
| 122 | + * @throws InvalidInterfaceException |
|
| 123 | + * @throws ReflectionException |
|
| 124 | + */ |
|
| 125 | + public function column_CHK_in(EE_Checkin $item) |
|
| 126 | + { |
|
| 127 | + $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
| 128 | + return '<span class="' |
|
| 129 | + . $checkin_status_dashicon->cssClasses() |
|
| 130 | + . '"></span><span class="show-on-mobile-view-only">' |
|
| 131 | + . $item->get_datetime('CHK_timestamp') |
|
| 132 | + . '</span>'; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param EE_Checkin $item |
|
| 138 | + * @return string |
|
| 139 | + * @throws EE_Error |
|
| 140 | + * @throws InvalidArgumentException |
|
| 141 | + * @throws InvalidDataTypeException |
|
| 142 | + * @throws InvalidInterfaceException |
|
| 143 | + * @throws ReflectionException |
|
| 144 | + */ |
|
| 145 | + public function column_CHK_timestamp(EE_Checkin $item) |
|
| 146 | + { |
|
| 147 | + $actions = array(); |
|
| 148 | + $delete_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 149 | + array( |
|
| 150 | + 'action' => 'delete_checkin_row', |
|
| 151 | + 'DTT_ID' => $this->_req_data['DTT_ID'], |
|
| 152 | + '_REG_ID' => $this->_req_data['_REG_ID'], |
|
| 153 | + 'CHK_ID' => $item->ID(), |
|
| 154 | + ) |
|
| 155 | + ); |
|
| 156 | + $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 157 | + 'ee_delete_checkins', |
|
| 158 | + 'espresso_registrations_delete_checkin_row' |
|
| 159 | + ) |
|
| 160 | + ? '<a href="' . $delete_url . '" title="' |
|
| 161 | + . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' |
|
| 162 | + . __('Delete', 'event_espresso') . '</a>' |
|
| 163 | + : ''; |
|
| 164 | + |
|
| 165 | + return sprintf( |
|
| 166 | + '%1$s %2$s', |
|
| 167 | + $item->get_datetime('CHK_timestamp', '', 'H:i:s a'), |
|
| 168 | + $this->row_actions($actions) |
|
| 169 | + ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * This retrieves all the Check-ins for the given parameters. |
|
| 175 | + * experimenting with having the query for the table values within the list table. |
|
| 176 | + * |
|
| 177 | + * @param int $per_page How many to retrieve per page |
|
| 178 | + * @param bool $count Whether to return a count or not |
|
| 179 | + * @return EE_Checkin[]|int |
|
| 180 | + * @throws EE_Error |
|
| 181 | + * @throws InvalidArgumentException |
|
| 182 | + * @throws InvalidDataTypeException |
|
| 183 | + * @throws InvalidInterfaceException |
|
| 184 | + */ |
|
| 185 | + protected function _get_checkins($per_page = 10, $count = false) |
|
| 186 | + { |
|
| 187 | + $REG_ID = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : false; |
|
| 188 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : false; |
|
| 189 | + |
|
| 190 | + // if user does not have the capability for the checkins for this registration then get out! |
|
| 191 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 192 | + 'ee_read_checkin', |
|
| 193 | + 'espresso_registrations_registration_checkins', |
|
| 194 | + $REG_ID |
|
| 195 | + )) { |
|
| 196 | + return $count ? 0 : array(); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // if no reg id then get out cause need a reg id |
|
| 200 | + if (empty($REG_ID) || empty($DTT_ID)) { |
|
| 201 | + throw new EE_Error( |
|
| 202 | + __( |
|
| 203 | + 'This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', |
|
| 204 | + 'event_espresso' |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // set orderby |
|
| 210 | + // note that with this table we're only providing the option to orderby the timestamp value. |
|
| 211 | + $orderby = 'CHK_timestamp'; |
|
| 212 | + |
|
| 213 | + $order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 214 | + |
|
| 215 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 216 | + ? $this->_req_data['paged'] |
|
| 217 | + : 1; |
|
| 218 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 219 | + ? $this->_req_data['perpage'] |
|
| 220 | + : $per_page; |
|
| 221 | + $limit = null; |
|
| 222 | + if (! $count) { |
|
| 223 | + $offset = ($current_page - 1) * $per_page; |
|
| 224 | + $limit = array($offset, $per_page); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $_where = array( |
|
| 228 | + 'REG_ID' => $REG_ID, |
|
| 229 | + 'DTT_ID' => $DTT_ID, |
|
| 230 | + ); |
|
| 231 | + |
|
| 232 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
| 233 | + |
|
| 234 | + // if no per_page value then we just want to return a count of all Check-ins |
|
| 235 | + if ($count) { |
|
| 236 | + return EEM_Checkin::instance()->count(array($_where)); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $count |
|
| 240 | + ? EEM_Checkin::instance()->count(array($_where)) |
|
| 241 | + : EEM_Checkin::instance()->get_all($query_params); |
|
| 242 | + } |
|
| 243 | 243 | } |