Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Registrations_Admin_Page often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Registrations_Admin_Page, and based on these observations, apply Extract Interface, too.
| 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
||
| 24 | class Registrations_Admin_Page extends EE_Admin_Page_CPT { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var EE_Registration |
||
| 28 | */ |
||
| 29 | private $_registration; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var EE_Event |
||
| 33 | */ |
||
| 34 | private $_reg_event; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var EE_Session |
||
| 38 | */ |
||
| 39 | private $_session; |
||
| 40 | private static $_reg_status; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Form for displaying the custom questions for this registration. |
||
| 44 | * This gets used a few times throughout the request so its best to cache it |
||
| 45 | * @var EE_Registration_Custom_Questions_Form |
||
| 46 | */ |
||
| 47 | protected $_reg_custom_questions_form = null; |
||
| 48 | |||
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * constructor |
||
| 53 | * |
||
| 54 | * @Constructor |
||
| 55 | * @access public |
||
| 56 | * @param bool $routing |
||
| 57 | * @return Registrations_Admin_Page |
||
|
|
|||
| 58 | */ |
||
| 59 | public function __construct( $routing = TRUE ) { |
||
| 60 | parent::__construct( $routing ); |
||
| 61 | add_action( 'wp_loaded', array( $this, 'wp_loaded' )); |
||
| 62 | } |
||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | public function wp_loaded() { |
||
| 67 | // when adding a new registration... |
||
| 68 | if ( isset( $this->_req_data[ 'action' ] ) && $this->_req_data[ 'action' ] == 'new_registration' ) { |
||
| 69 | EE_System::do_not_cache(); |
||
| 70 | if ( |
||
| 71 | ! isset( $this->_req_data[ 'processing_registration' ] ) |
||
| 72 | || absint( $this->_req_data[ 'processing_registration' ] ) !== 1 |
||
| 73 | ) { |
||
| 74 | // and it's NOT the attendee information reg step |
||
| 75 | // force cookie expiration by setting time to last week |
||
| 76 | setcookie( 'ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/' ); |
||
| 77 | // and update the global |
||
| 78 | $_COOKIE[ 'ee_registration_added' ] = 0; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | protected function _init_page_props() { |
||
| 89 | $this->page_slug = REG_PG_SLUG; |
||
| 90 | $this->_admin_base_url = REG_ADMIN_URL; |
||
| 91 | $this->_admin_base_path = REG_ADMIN; |
||
| 92 | $this->page_label = __('Registrations', 'event_espresso'); |
||
| 93 | $this->_cpt_routes = array( |
||
| 94 | 'add_new_attendee' => 'espresso_attendees', |
||
| 95 | 'edit_attendee' => 'espresso_attendees', |
||
| 96 | 'insert_attendee' => 'espresso_attendees', |
||
| 97 | 'update_attendee' => 'espresso_attendees' |
||
| 98 | ); |
||
| 99 | $this->_cpt_model_names = array( |
||
| 100 | 'add_new_attendee' => 'EEM_Attendee', |
||
| 101 | 'edit_attendee' => 'EEM_Attendee' |
||
| 102 | ); |
||
| 103 | $this->_cpt_edit_routes = array( |
||
| 104 | 'espresso_attendees' => 'edit_attendee' |
||
| 105 | ); |
||
| 106 | $this->_pagenow_map = array( |
||
| 107 | 'add_new_attendee' => 'post-new.php', |
||
| 108 | 'edit_attendee' => 'post.php', |
||
| 109 | 'trash' => 'post.php' |
||
| 110 | ); |
||
| 111 | |||
| 112 | add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10 ); |
||
| 113 | //add filters so that the comment urls don't take users to a confusing 404 page |
||
| 114 | add_filter('get_comment_link', array( $this, 'clear_comment_link' ), 10, 3 ); |
||
| 115 | } |
||
| 116 | |||
| 117 | |||
| 118 | public function clear_comment_link( $link, $comment, $args ) { |
||
| 125 | |||
| 126 | |||
| 127 | protected function _ajax_hooks() { |
||
| 131 | |||
| 132 | |||
| 133 | |||
| 134 | |||
| 135 | |||
| 136 | protected function _define_page_props() { |
||
| 157 | |||
| 158 | |||
| 159 | |||
| 160 | |||
| 161 | |||
| 162 | |||
| 163 | |||
| 164 | /** |
||
| 165 | * grab url requests and route them |
||
| 166 | * @access private |
||
| 167 | * @return void |
||
| 168 | */ |
||
| 169 | public function _set_page_routes() { |
||
| 170 | |||
| 171 | $this->_get_registration_status_array(); |
||
| 172 | |||
| 173 | $reg_id = ! empty( $this->_req_data['_REG_ID'] ) && ! is_array( $this->_req_data['_REG_ID'] ) ? $this->_req_data['_REG_ID'] : 0; |
||
| 174 | $att_id = ! empty( $this->_req_data[ 'ATT_ID' ] ) && ! is_array( $this->_req_data['ATT_ID'] ) ? $this->_req_data['ATT_ID'] : 0; |
||
| 175 | $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) ? $this->_req_data['post'] : $att_id; |
||
| 176 | |||
| 177 | $this->_page_routes = array( |
||
| 178 | |||
| 179 | 'default' => array( |
||
| 180 | 'func' => '_registrations_overview_list_table', |
||
| 181 | 'capability' => 'ee_read_registrations' |
||
| 182 | ), |
||
| 183 | |||
| 184 | 'view_registration' => array( |
||
| 185 | 'func' => '_registration_details', |
||
| 186 | 'capability' => 'ee_read_registration', |
||
| 187 | 'obj_id' => $reg_id |
||
| 188 | ), |
||
| 189 | |||
| 190 | 'edit_registration' => array( |
||
| 191 | 'func' => '_update_attendee_registration_form', |
||
| 192 | 'noheader' => TRUE, |
||
| 193 | 'headers_sent_route'=>'view_registration', |
||
| 194 | 'capability' => 'ee_edit_registration', |
||
| 195 | 'obj_id' => $reg_id, |
||
| 196 | '_REG_ID' => $reg_id, |
||
| 197 | ), |
||
| 198 | |||
| 199 | 'trash_registrations' => array( |
||
| 200 | 'func' => '_trash_or_restore_registrations', |
||
| 201 | 'args' => array('trash' => TRUE), |
||
| 202 | 'noheader' => TRUE, |
||
| 203 | 'capability' => 'ee_delete_registrations' |
||
| 204 | ), |
||
| 205 | |||
| 206 | 'restore_registrations' => array( |
||
| 207 | 'func' => '_trash_or_restore_registrations', |
||
| 208 | 'args' => array( 'trash' => FALSE ), |
||
| 209 | 'noheader' => TRUE, |
||
| 210 | 'capability' => 'ee_delete_registrations' |
||
| 211 | ), |
||
| 212 | |||
| 213 | 'delete_registrations' => array( |
||
| 214 | 'func' => '_delete_registrations', |
||
| 215 | 'noheader' => TRUE, |
||
| 216 | 'capability' => 'ee_delete_registrations' |
||
| 217 | ), |
||
| 218 | |||
| 219 | 'new_registration' => array( |
||
| 220 | 'func' => 'new_registration', |
||
| 221 | 'capability' => 'ee_edit_registrations' |
||
| 222 | ), |
||
| 223 | |||
| 224 | 'process_reg_step' => array( |
||
| 225 | 'func' => 'process_reg_step', |
||
| 226 | 'noheader' => TRUE, |
||
| 227 | 'capability' => 'ee_edit_registrations' |
||
| 228 | ), |
||
| 229 | |||
| 230 | 'redirect_to_txn' => array( |
||
| 231 | 'func' => 'redirect_to_txn', |
||
| 232 | 'noheader' => TRUE, |
||
| 233 | 'capability' => 'ee_edit_registrations' |
||
| 234 | ), |
||
| 235 | |||
| 236 | 'change_reg_status' => array( |
||
| 237 | 'func' => '_change_reg_status', |
||
| 238 | 'noheader' => TRUE, |
||
| 239 | 'capability' => 'ee_edit_registration', |
||
| 240 | 'obj_id' => $reg_id |
||
| 241 | ), |
||
| 242 | |||
| 243 | 'approve_registration' => array( |
||
| 244 | 'func' => 'approve_registration', |
||
| 245 | 'noheader' => TRUE, |
||
| 246 | 'capability' => 'ee_edit_registration', |
||
| 247 | 'obj_id' => $reg_id |
||
| 248 | ), |
||
| 249 | |||
| 250 | 'approve_and_notify_registration' => array( |
||
| 251 | 'func' => 'approve_registration', |
||
| 252 | 'noheader' => TRUE, |
||
| 253 | 'args' => array(TRUE), |
||
| 254 | 'capability' => 'ee_edit_registration', |
||
| 255 | 'obj_id' => $reg_id |
||
| 256 | ), |
||
| 257 | |||
| 258 | 'decline_registration' => array( |
||
| 259 | 'func' => 'decline_registration', |
||
| 260 | 'noheader' => TRUE, |
||
| 261 | 'capability' => 'ee_edit_registration', |
||
| 262 | 'obj_id' => $reg_id |
||
| 263 | ), |
||
| 264 | |||
| 265 | 'decline_and_notify_registration' => array( |
||
| 266 | 'func' => 'decline_registration', |
||
| 267 | 'noheader' => TRUE, |
||
| 268 | 'args' => array(TRUE), |
||
| 269 | 'capability' => 'ee_edit_registration', |
||
| 270 | 'obj_id' => $reg_id |
||
| 271 | ), |
||
| 272 | |||
| 273 | 'pending_registration' => array( |
||
| 274 | 'func' => 'pending_registration', |
||
| 275 | 'noheader' => TRUE, |
||
| 276 | 'capability' => 'ee_edit_registration', |
||
| 277 | 'obj_id' => $reg_id |
||
| 278 | ), |
||
| 279 | |||
| 280 | 'pending_and_notify_registration' => array( |
||
| 281 | 'func' => 'pending_registration', |
||
| 282 | 'noheader' => TRUE, |
||
| 283 | 'args' => array(TRUE), |
||
| 284 | 'capability' => 'ee_edit_registration', |
||
| 285 | 'obj_id' => $reg_id |
||
| 286 | ), |
||
| 287 | |||
| 288 | 'no_approve_registration' => array( |
||
| 289 | 'func' => 'not_approve_registration', |
||
| 290 | 'noheader' => TRUE, |
||
| 291 | 'capability' => 'ee_edit_registration', |
||
| 292 | 'obj_id' => $reg_id |
||
| 293 | ), |
||
| 294 | |||
| 295 | 'no_approve_and_notify_registration' => array( |
||
| 296 | 'func' => 'not_approve_registration', |
||
| 297 | 'noheader' => TRUE, |
||
| 298 | 'args' => array(TRUE), |
||
| 299 | 'capability' => 'ee_edit_registration', |
||
| 300 | 'obj_id' => $reg_id |
||
| 301 | ), |
||
| 302 | |||
| 303 | 'cancel_registration' => array( |
||
| 304 | 'func' => 'cancel_registration', |
||
| 305 | 'noheader' => TRUE, |
||
| 306 | 'capability' => 'ee_edit_registration', |
||
| 307 | 'obj_id' => $reg_id |
||
| 308 | ), |
||
| 309 | |||
| 310 | 'cancel_and_notify_registration' => array( |
||
| 311 | 'func' => 'cancel_registration', |
||
| 312 | 'noheader' => TRUE, |
||
| 313 | 'args' => array(TRUE), |
||
| 314 | 'capability' => 'ee_edit_registration', |
||
| 315 | 'obj_id' => $reg_id |
||
| 316 | ), |
||
| 317 | |||
| 318 | 'contact_list' => array( |
||
| 319 | 'func' => '_attendee_contact_list_table', |
||
| 320 | 'capability' => 'ee_read_contacts' |
||
| 321 | ), |
||
| 322 | |||
| 323 | |||
| 324 | 'add_new_attendee' => array( |
||
| 325 | 'func' => '_create_new_cpt_item', |
||
| 326 | 'args' => array( |
||
| 327 | 'new_attendee' => TRUE, |
||
| 328 | 'capability' => 'ee_edit_contacts' |
||
| 329 | ) |
||
| 330 | ), |
||
| 331 | |||
| 332 | 'edit_attendee' => array( |
||
| 333 | 'func' => '_edit_cpt_item', |
||
| 334 | 'capability' => 'ee_edit_contacts', |
||
| 335 | 'obj_id' => $att_id |
||
| 336 | ), |
||
| 337 | |||
| 338 | 'duplicate_attendee' => array( |
||
| 339 | 'func' => '_duplicate_attendee', |
||
| 340 | 'noheader' => TRUE, |
||
| 341 | 'capability' => 'ee_edit_contacts', |
||
| 342 | 'obj_id' => $att_id |
||
| 343 | ), |
||
| 344 | |||
| 345 | 'insert_attendee' => array( |
||
| 346 | 'func' => '_insert_or_update_attendee', |
||
| 347 | 'args' => array( |
||
| 348 | 'new_attendee' => TRUE |
||
| 349 | ), |
||
| 350 | 'noheader' => TRUE, |
||
| 351 | 'capability' => 'ee_edit_contacts' |
||
| 352 | ), |
||
| 353 | |||
| 354 | 'update_attendee' => array( |
||
| 355 | 'func' => '_insert_or_update_attendee', |
||
| 356 | 'args' => array( |
||
| 357 | 'new_attendee' => FALSE |
||
| 358 | ), |
||
| 359 | 'noheader' => TRUE, |
||
| 360 | 'capability' => 'ee_edit_contacts', |
||
| 361 | 'obj_id' => $att_id |
||
| 362 | ), |
||
| 363 | |||
| 364 | 'trash_attendees' => array( |
||
| 365 | 'func' => '_trash_or_restore_attendees', |
||
| 366 | 'args' => array( |
||
| 367 | 'trash' => TRUE |
||
| 368 | ), |
||
| 369 | 'noheader' => TRUE, |
||
| 370 | 'capability' => 'ee_delete_contacts', |
||
| 371 | 'obj_id' => $att_id |
||
| 372 | ), |
||
| 373 | |||
| 374 | 'restore_attendees' => array( |
||
| 375 | 'func' => '_trash_or_restore_attendees', |
||
| 376 | 'args' => array( |
||
| 377 | 'trash' => FALSE |
||
| 378 | ), |
||
| 379 | 'noheader' => TRUE, |
||
| 380 | 'capability' => 'ee_delete_contacts', |
||
| 381 | 'obj_id' => $att_id |
||
| 382 | ), |
||
| 383 | 'resend_registration' => array( |
||
| 384 | 'func' => '_resend_registration', |
||
| 385 | 'noheader' => TRUE, |
||
| 386 | 'capability' => 'ee_send_message' |
||
| 387 | ), |
||
| 388 | 'registrations_report'=>array( |
||
| 389 | 'func'=>'_registrations_report', |
||
| 390 | 'noheader'=> TRUE, |
||
| 391 | 'capability' => 'ee_read_registrations' |
||
| 392 | ), |
||
| 393 | 'contact_list_export'=>array( |
||
| 394 | 'func'=>'_contact_list_export', |
||
| 395 | 'noheader'=>TRUE, |
||
| 396 | 'capability' => 'export' |
||
| 397 | ), |
||
| 398 | 'contact_list_report' => array( |
||
| 399 | 'func'=> '_contact_list_report', |
||
| 400 | 'noheader' => TRUE, |
||
| 401 | 'capability' => 'ee_read_contacts', |
||
| 402 | ) |
||
| 403 | ); |
||
| 404 | |||
| 405 | } |
||
| 406 | |||
| 407 | |||
| 408 | |||
| 409 | |||
| 410 | |||
| 411 | protected function _set_page_config() { |
||
| 412 | $this->_page_config = array( |
||
| 413 | |||
| 414 | 'default' => array( |
||
| 415 | 'nav' => array( |
||
| 416 | 'label' => __('Overview', 'event_espresso'), |
||
| 417 | 'order' => 5 |
||
| 418 | ), |
||
| 419 | 'help_tabs' => array( |
||
| 420 | 'registrations_overview_help_tab' => array( |
||
| 421 | 'title' => __('Registrations Overview', 'event_espresso'), |
||
| 422 | 'filename' => 'registrations_overview' |
||
| 423 | ), |
||
| 424 | 'registrations_overview_table_column_headings_help_tab' => array( |
||
| 425 | 'title' => __('Registrations Table Column Headings', 'event_espresso'), |
||
| 426 | 'filename' => 'registrations_overview_table_column_headings' |
||
| 427 | ), |
||
| 428 | 'registrations_overview_filters_help_tab' => array( |
||
| 429 | 'title' => __('Registration Filters', 'event_espresso'), |
||
| 430 | 'filename' => 'registrations_overview_filters' |
||
| 431 | ), |
||
| 432 | 'registrations_overview_views_help_tab' => array( |
||
| 433 | 'title' => __('Registration Views', 'event_espresso'), |
||
| 434 | 'filename' => 'registrations_overview_views' |
||
| 435 | ), |
||
| 436 | 'registrations_overview_other_help_tab' => array( |
||
| 437 | 'title' => __('Registrations Other', 'event_espresso'), |
||
| 438 | 'filename' => 'registrations_overview_other' |
||
| 439 | ) |
||
| 440 | ), |
||
| 441 | 'help_tour' => array( 'Registration_Overview_Help_Tour' ), |
||
| 442 | 'qtips' => array('Registration_List_Table_Tips'), |
||
| 443 | 'list_table' => 'EE_Registrations_List_Table', |
||
| 444 | 'require_nonce' => FALSE |
||
| 445 | ), |
||
| 446 | |||
| 447 | 'view_registration' => array( |
||
| 448 | 'nav' => array( |
||
| 449 | 'label' => __('REG Details', 'event_espresso'), |
||
| 450 | 'order' => 15, |
||
| 451 | 'url' => isset($this->_req_data['_REG_ID']) ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID'] ), $this->_current_page_view_url ) : $this->_admin_base_url, |
||
| 452 | 'persistent' => FALSE |
||
| 453 | ), |
||
| 454 | 'help_tabs' => array( |
||
| 455 | 'registrations_details_help_tab' => array( |
||
| 456 | 'title' => __('Registration Details', 'event_espresso'), |
||
| 457 | 'filename' => 'registrations_details' |
||
| 458 | ), |
||
| 459 | 'registrations_details_table_help_tab' => array( |
||
| 460 | 'title' => __('Registration Details Table', 'event_espresso'), |
||
| 461 | 'filename' => 'registrations_details_table' |
||
| 462 | ), |
||
| 463 | 'registrations_details_form_answers_help_tab' => array( |
||
| 464 | 'title' => __('Registration Form Answers', 'event_espresso'), |
||
| 465 | 'filename' => 'registrations_details_form_answers' |
||
| 466 | ), |
||
| 467 | 'registrations_details_registrant_details_help_tab' => array( |
||
| 468 | 'title' => __('Contact Details', 'event_espresso'), |
||
| 469 | 'filename' => 'registrations_details_registrant_details' |
||
| 470 | ) |
||
| 471 | ), |
||
| 472 | 'help_tour' => array( 'Registration_Details_Help_Tour' ), |
||
| 473 | 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_registration_details_metaboxes' ) ), |
||
| 474 | 'require_nonce' => FALSE |
||
| 475 | ), |
||
| 476 | |||
| 477 | 'new_registration' => array( |
||
| 478 | 'nav' => array( |
||
| 479 | 'label' => __('Add New Registration', 'event_espresso'), |
||
| 480 | 'url' => '#', |
||
| 481 | 'order' => 15, |
||
| 482 | 'persistent' => FALSE |
||
| 483 | ), |
||
| 484 | 'metaboxes' => $this->_default_espresso_metaboxes, |
||
| 485 | 'labels' => array( |
||
| 486 | 'publishbox' => __('Save Registration', 'event_espresso') |
||
| 487 | ), |
||
| 488 | 'require_nonce' => FALSE |
||
| 489 | ), |
||
| 490 | |||
| 491 | 'add_new_attendee' => array( |
||
| 492 | 'nav' => array( |
||
| 493 | 'label' => __('Add Contact', 'event_espresso'), |
||
| 494 | 'order' => 15, |
||
| 495 | 'persistent' => FALSE |
||
| 496 | ), |
||
| 497 | 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box', 'attendee_editor_metaboxes' ) ), |
||
| 498 | 'require_nonce' => FALSE |
||
| 499 | ), |
||
| 500 | |||
| 501 | 'edit_attendee' => array( |
||
| 502 | 'nav' => array( |
||
| 503 | 'label' => __('Edit Contact', 'event_espresso'), |
||
| 504 | 'order' => 15, |
||
| 505 | 'persistent' => FALSE, |
||
| 506 | 'url' => isset($this->_req_data['ATT_ID']) ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
||
| 507 | ), |
||
| 508 | 'metaboxes' => array('attendee_editor_metaboxes'), |
||
| 509 | 'require_nonce' => FALSE |
||
| 510 | ), |
||
| 511 | |||
| 512 | 'contact_list' => array( |
||
| 513 | 'nav' => array( |
||
| 514 | 'label' => __('Contact List', 'event_espresso'), |
||
| 515 | 'order' => 20 |
||
| 516 | ), |
||
| 517 | 'list_table' => 'EE_Attendee_Contact_List_Table', |
||
| 518 | 'help_tabs' => array( |
||
| 519 | 'registrations_contact_list_help_tab' => array( |
||
| 520 | 'title' => __('Registrations Contact List', 'event_espresso'), |
||
| 521 | 'filename' => 'registrations_contact_list' |
||
| 522 | ), |
||
| 523 | 'registrations_contact-list_table_column_headings_help_tab' => array( |
||
| 524 | 'title' => __('Contact List Table Column Headings', 'event_espresso'), |
||
| 525 | 'filename' => 'registrations_contact_list_table_column_headings' |
||
| 526 | ), |
||
| 527 | 'registrations_contact_list_views_help_tab' => array( |
||
| 528 | 'title' => __('Contact List Views', 'event_espresso'), |
||
| 529 | 'filename' => 'registrations_contact_list_views' |
||
| 530 | ), |
||
| 531 | 'registrations_contact_list_other_help_tab' => array( |
||
| 532 | 'title' => __('Contact List Other', 'event_espresso'), |
||
| 533 | 'filename' => 'registrations_contact_list_other' |
||
| 534 | ) |
||
| 535 | ), |
||
| 536 | 'help_tour' => array( 'Contact_List_Help_Tour' ), |
||
| 537 | 'metaboxes' => array(), |
||
| 538 | 'require_nonce' => FALSE |
||
| 539 | ), |
||
| 540 | |||
| 541 | //override default cpt routes |
||
| 542 | 'create_new' => '', |
||
| 543 | 'edit' => '' |
||
| 544 | |||
| 545 | ); |
||
| 546 | } |
||
| 547 | |||
| 548 | |||
| 549 | /** |
||
| 550 | * The below methods aren't used by this class currently |
||
| 551 | */ |
||
| 552 | protected function _add_screen_options() {} |
||
| 553 | protected function _add_feature_pointers() {} |
||
| 554 | public function admin_init() { |
||
| 555 | EE_Registry::$i18n_js_strings[ 'update_att_qstns' ] = __( 'click "Update Registration Questions" to save your changes', 'event_espresso' ); |
||
| 556 | } |
||
| 557 | public function admin_notices() {} |
||
| 558 | public function admin_footer_scripts() {} |
||
| 559 | |||
| 560 | |||
| 561 | |||
| 562 | |||
| 563 | |||
| 564 | |||
| 565 | |||
| 566 | |||
| 567 | /** |
||
| 568 | * get list of registration statuses |
||
| 569 | * @access private |
||
| 570 | * @return void |
||
| 571 | */ |
||
| 572 | private function _get_registration_status_array() { |
||
| 573 | self::$_reg_status = EEM_Registration::reg_status_array( array(), TRUE); |
||
| 574 | } |
||
| 575 | |||
| 576 | |||
| 577 | |||
| 578 | |||
| 579 | protected function _add_screen_options_default() { |
||
| 580 | $this->_per_page_screen_option(); |
||
| 581 | } |
||
| 582 | |||
| 583 | View Code Duplication | protected function _add_screen_options_contact_list() { |
|
| 584 | $page_title = $this->_admin_page_title; |
||
| 585 | $this->_admin_page_title = __("Contacts", 'event_espresso'); |
||
| 586 | $this->_per_page_screen_option(); |
||
| 587 | $this->_admin_page_title = $page_title; |
||
| 588 | } |
||
| 589 | |||
| 590 | |||
| 591 | |||
| 592 | |||
| 593 | View Code Duplication | public function load_scripts_styles() { |
|
| 594 | //style |
||
| 595 | //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION ); |
||
| 596 | wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'), EVENT_ESPRESSO_VERSION ); |
||
| 597 | wp_enqueue_style('espresso_reg'); |
||
| 598 | |||
| 599 | //script |
||
| 600 | wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js', array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, TRUE); |
||
| 601 | wp_enqueue_script('espresso_reg'); |
||
| 602 | } |
||
| 603 | |||
| 604 | |||
| 605 | |||
| 606 | public function load_scripts_styles_edit_attendee() { |
||
| 607 | //stuff to only show up on our attendee edit details page. |
||
| 608 | $attendee_details_translations = array( |
||
| 609 | 'att_publish_text' => sprintf( __('Created on: <b>%1$s</b>', 'event_espresso'), $this->_cpt_model_obj->get_datetime('ATT_created') ) |
||
| 610 | ); |
||
| 611 | wp_localize_script( 'espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations ); |
||
| 612 | wp_enqueue_script('jquery-validate'); |
||
| 613 | } |
||
| 614 | |||
| 615 | |||
| 616 | public function load_scripts_styles_view_registration() { |
||
| 617 | //styles |
||
| 618 | wp_enqueue_style('espresso-ui-theme'); |
||
| 619 | //scripts |
||
| 620 | $this->_get_reg_custom_questions_form( $this->_registration->ID() ); |
||
| 621 | $this->_reg_custom_questions_form->wp_enqueue_scripts( true ); |
||
| 622 | } |
||
| 623 | |||
| 624 | |||
| 625 | |||
| 626 | |||
| 627 | |||
| 628 | |||
| 629 | public function load_scripts_styles_contact_list() { |
||
| 630 | wp_deregister_style('espresso_reg'); |
||
| 631 | wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'), EVENT_ESPRESSO_VERSION ); |
||
| 632 | wp_enqueue_style('espresso_att'); |
||
| 633 | } |
||
| 634 | |||
| 635 | |||
| 636 | |||
| 637 | |||
| 638 | |||
| 639 | public function load_scripts_styles_new_registration() { |
||
| 640 | wp_register_script( 'ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'), EVENT_ESPRESSO_VERSION, TRUE ); |
||
| 641 | wp_enqueue_script('ee-spco-for-admin'); |
||
| 642 | add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' ); |
||
| 643 | EE_Form_Section_Proper::wp_enqueue_scripts(); |
||
| 644 | EED_Ticket_Selector::load_tckt_slctr_assets(); |
||
| 645 | EE_Datepicker_Input::enqueue_styles_and_scripts(); |
||
| 646 | } |
||
| 647 | |||
| 648 | |||
| 649 | |||
| 650 | |||
| 651 | |||
| 652 | public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() { |
||
| 653 | add_filter('FHEE_load_EE_messages', '__return_true'); |
||
| 654 | } |
||
| 655 | |||
| 656 | |||
| 657 | |||
| 658 | public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() { |
||
| 659 | add_filter('FHEE_load_EE_messages', '__return_true'); |
||
| 660 | } |
||
| 661 | |||
| 662 | |||
| 663 | |||
| 664 | protected function _set_list_table_views_default() { |
||
| 665 | |||
| 666 | //for notification related bulk actions we need to make sure only active messengers have an option. |
||
| 667 | EED_Messages::set_autoloaders(); |
||
| 668 | $EEMSG = EE_Registry::instance()->load_lib('messages'); |
||
| 669 | $active_mts = $EEMSG->get_active_message_types(); |
||
| 670 | //key= bulk_action_slug, value= message type. |
||
| 671 | $match_array = array( |
||
| 672 | 'approve_registration' => 'registration', |
||
| 673 | 'decline_registration' => 'declined_registration', |
||
| 674 | 'pending_registration' => 'pending_approval', |
||
| 675 | 'no_approve_registration' => 'not_approved_registration', |
||
| 676 | 'cancel_registration' => 'cancelled_registration' |
||
| 677 | ); |
||
| 678 | |||
| 679 | /** setup reg status bulk actions **/ |
||
| 680 | $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso'); |
||
| 681 | View Code Duplication | if ( in_array( $match_array['approve_registration'], $active_mts ) && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'batch_send_messages' ) ) { |
|
| 682 | $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations', 'event_espresso'); |
||
| 683 | } |
||
| 684 | $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso'); |
||
| 685 | View Code Duplication | if ( in_array( $match_array['decline_registration'], $active_mts ) && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'batch_send_messages' ) ) { |
|
| 686 | $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations', 'event_espresso'); |
||
| 687 | } |
||
| 688 | $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso'); |
||
| 689 | View Code Duplication | if ( in_array( $match_array['pending_registration'], $active_mts ) && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'batch_send_messages' ) ) { |
|
| 690 | $def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify', 'event_espresso'); |
||
| 691 | } |
||
| 692 | $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso'); |
||
| 693 | View Code Duplication | if ( in_array( $match_array['no_approve_registration'], $active_mts ) && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'batch_send_messages' ) ) { |
|
| 694 | $def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify', 'event_espresso'); |
||
| 695 | } |
||
| 696 | $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso'); |
||
| 697 | View Code Duplication | if ( in_array( $match_array['cancel_registration'], $active_mts ) && EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'batch_send_messages' ) ) { |
|
| 698 | $def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify', 'event_espresso'); |
||
| 699 | } |
||
| 700 | |||
| 701 | $this->_views = array( |
||
| 702 | 'all' => array( |
||
| 703 | 'slug' => 'all', |
||
| 704 | 'label' => __('View All Registrations', 'event_espresso'), |
||
| 705 | 'count' => 0, |
||
| 706 | 'bulk_action' => array_merge( $def_reg_status_actions, array( |
||
| 707 | 'trash_registrations' => __('Trash Registrations', 'event_espresso') |
||
| 708 | ) ) |
||
| 709 | ), |
||
| 710 | 'month' => array( |
||
| 711 | 'slug' => 'month', |
||
| 712 | 'label' => __('This Month', 'event_espresso'), |
||
| 713 | 'count' => 0, |
||
| 714 | 'bulk_action' => array_merge( $def_reg_status_actions, array( |
||
| 715 | 'trash_registrations' => __('Trash Registrations', 'event_espresso') |
||
| 716 | )) |
||
| 717 | ), |
||
| 718 | 'today' => array( |
||
| 719 | 'slug' => 'today', |
||
| 720 | 'label' => sprintf( __('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp' ) ) ), |
||
| 721 | 'count' => 0, |
||
| 722 | 'bulk_action' => array_merge( $def_reg_status_actions, array( |
||
| 723 | 'trash_registrations' => __('Trash Registrations', 'event_espresso') |
||
| 724 | )) |
||
| 725 | ) |
||
| 726 | ); |
||
| 727 | |||
| 728 | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_registrations', 'espresso_registrations_delete_registration' ) ) { |
||
| 729 | $this->_views['incomplete'] = array( |
||
| 730 | 'slug' => 'incomplete', |
||
| 731 | 'label' => __('Incomplete', 'event_espresso'), |
||
| 732 | 'count' => 0, |
||
| 733 | 'bulk_action' => array( |
||
| 734 | 'trash_registrations' => __('Trash Registrations', 'event_espresso') |
||
| 735 | ) |
||
| 736 | ); |
||
| 737 | $this->_views['trash'] = array( |
||
| 738 | 'slug' => 'trash', |
||
| 739 | 'label' => __('Trash', 'event_espresso'), |
||
| 740 | 'count' => 0, |
||
| 741 | 'bulk_action' => array( |
||
| 742 | 'restore_registrations' => __('Restore Registrations', 'event_espresso'), |
||
| 743 | 'delete_registrations' => __('Delete Registrations Permanently', 'event_espresso') |
||
| 744 | ) |
||
| 745 | ); |
||
| 746 | } |
||
| 747 | } |
||
| 748 | |||
| 749 | |||
| 750 | |||
| 751 | |||
| 752 | protected function _set_list_table_views_contact_list() { |
||
| 775 | |||
| 776 | |||
| 777 | |||
| 778 | |||
| 779 | |||
| 780 | protected function _registration_legend_items() { |
||
| 781 | $fc_items = array( |
||
| 782 | 'star-icon' => array( |
||
| 783 | 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
||
| 784 | 'desc' => __('This is the Primary Registrant', 'event_espresso') |
||
| 785 | ), |
||
| 786 | 'view_details' => array( |
||
| 787 | 'class' => 'dashicons dashicons-clipboard', |
||
| 788 | 'desc' => __('View Registration Details', 'event_espresso') |
||
| 789 | ), |
||
| 790 | 'edit_attendee' => array( |
||
| 791 | 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
||
| 840 | |||
| 841 | |||
| 842 | |||
| 843 | /*************************************** REGISTRATION OVERVIEW ***************************************/ |
||
| 844 | |||
| 845 | |||
| 846 | |||
| 847 | |||
| 848 | |||
| 849 | |||
| 850 | protected function _registrations_overview_list_table() { |
||
| 862 | |||
| 863 | |||
| 864 | |||
| 865 | |||
| 866 | /** |
||
| 867 | * This sets the _registration property for the registration details screen |
||
| 868 | * |
||
| 869 | * @access private |
||
| 870 | * @return bool |
||
| 871 | */ |
||
| 872 | private function _set_registration_object() { |
||
| 891 | |||
| 892 | |||
| 893 | |||
| 894 | /** |
||
| 895 | * get registrations for given parameters (used by list table) |
||
| 896 | * |
||
| 897 | * @param int $per_page how many registrations displayed per page |
||
| 898 | * @param boolean $count return the count or objects |
||
| 899 | * @param boolean $this_month whether to return for just this month |
||
| 900 | * @param boolean $today whether to return results for just today |
||
| 901 | * @throws \EE_Error |
||
| 902 | * @internal param bool $all whether to ignore all query params and just return ALL registrations (or count if count is set) |
||
| 903 | * @return mixed (int|array) int = count || array of registration objects |
||
| 904 | */ |
||
| 905 | public function get_registrations( $per_page = 10, $count = FALSE, $this_month = FALSE, $today = FALSE ) { |
||
| 1080 | |||
| 1081 | |||
| 1082 | |||
| 1083 | |||
| 1084 | |||
| 1085 | |||
| 1086 | public function get_registration_status_array() { |
||
| 1089 | |||
| 1090 | |||
| 1091 | |||
| 1092 | |||
| 1093 | /*************************************** REGISTRATION DETAILS ***************************************/ |
||
| 1094 | |||
| 1095 | |||
| 1096 | |||
| 1097 | |||
| 1098 | |||
| 1099 | /** |
||
| 1100 | * generates HTML for the View Registration Details Admin page |
||
| 1101 | * @access protected |
||
| 1102 | * @return void |
||
| 1103 | */ |
||
| 1104 | protected function _registration_details() { |
||
| 1153 | |||
| 1154 | |||
| 1155 | |||
| 1156 | |||
| 1157 | |||
| 1158 | |||
| 1159 | protected function _registration_details_metaboxes() { |
||
| 1173 | |||
| 1174 | |||
| 1175 | |||
| 1176 | |||
| 1177 | |||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * _set_approve_or_decline_reg_status_buttons |
||
| 1181 | * @access protected |
||
| 1182 | * @return string |
||
| 1183 | */ |
||
| 1184 | public function set_reg_status_buttons_metabox() { |
||
| 1210 | |||
| 1211 | |||
| 1212 | |||
| 1213 | |||
| 1214 | /** |
||
| 1215 | * Returns an array of all the buttons for the various statuses and switch status actions |
||
| 1216 | * @return array |
||
| 1217 | */ |
||
| 1218 | private function _get_reg_status_buttons() { |
||
| 1229 | |||
| 1230 | |||
| 1231 | /** |
||
| 1232 | * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
||
| 1233 | * |
||
| 1234 | * @param bool $status REG status given for changing registrations to. |
||
| 1235 | * @param bool $notify Whether to send messages notifications or not. |
||
| 1236 | * |
||
| 1237 | * @return array (array with reg_id(s) updated and whether update was successful. |
||
| 1238 | */ |
||
| 1239 | protected function _set_registration_status_from_request( $status = false, $notify = false ) { |
||
| 1251 | |||
| 1252 | |||
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an array). |
||
| 1256 | * |
||
| 1257 | * Note, this method does NOT take care of possible notifications. That is required by calling code. |
||
| 1258 | * |
||
| 1259 | * @param bool $REG_ID |
||
| 1260 | * @param bool $status |
||
| 1261 | * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as the array of updated registrations). |
||
| 1262 | */ |
||
| 1263 | protected function _set_registration_status( $REG_ID, $status = false ) { |
||
| 1289 | |||
| 1290 | |||
| 1291 | |||
| 1292 | |||
| 1293 | /** |
||
| 1294 | * Common logic for setting up success message and redirecting to appropriate route |
||
| 1295 | * @param string $STS_ID status id for the registration changed to |
||
| 1296 | * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
||
| 1297 | * @return void |
||
| 1298 | */ |
||
| 1299 | protected function _reg_status_change_return( $STS_ID, $notify = false ) { |
||
| 1300 | |||
| 1301 | $result = ! empty( $STS_ID ) ? $this->_set_registration_status_from_request( $STS_ID, $notify ) : array( 'success' => false ); |
||
| 1302 | |||
| 1303 | |||
| 1304 | $success = isset( $result['success'] ) && $result['success']; |
||
| 1305 | |||
| 1306 | //setup success message |
||
| 1307 | if ( $success ) { |
||
| 1308 | $msg = is_array( $result['REG_ID'] ) && count( $result['REG_ID'] ) > 1 ? sprintf( __('Registration status has been set to %s', 'event_espresso'), EEH_Template::pretty_status($STS_ID, false, 'lower' ) ) : sprintf( __('Registrations have been set to %s.', 'event_espresso'), EEH_Template::pretty_status($STS_ID, false, 'lower' ) ) ; |
||
| 1309 | EE_Error::add_success( $msg ); |
||
| 1310 | } else { |
||
| 1311 | EE_Error::add_error( __('Something went wrong, and the status was not changed', 'event_espresso' ), __FILE__, __LINE__, __FUNCTION__ ); |
||
| 1312 | } |
||
| 1313 | |||
| 1314 | $route = isset( $this->_req_data['return'] ) && $this->_req_data['return'] == 'view_registration' ? array( 'action' => 'view_registration', '_REG_ID' => $result['REG_ID'][0] ) : array( 'action' => 'default' ); |
||
| 1315 | //unset nonces |
||
| 1316 | foreach ( $this->_req_data as $ref => $value ) { |
||
| 1317 | if ( strpos( $ref, 'nonce' ) !== false ) { |
||
| 1318 | unset( $this->_req_data[$ref] ); |
||
| 1319 | continue; |
||
| 1320 | } |
||
| 1321 | |||
| 1322 | $value = is_array( $value ) ? array_map( 'urlencode', $value ) : urlencode( $value ); |
||
| 1323 | $this->_req_data[$ref] = $value; |
||
| 1324 | } |
||
| 1325 | |||
| 1326 | //merge request vars so that the reloaded list table contains any existing filter query params |
||
| 1327 | $route = array_merge( $this->_req_data, $route ); |
||
| 1328 | |||
| 1329 | $this->_redirect_after_action( false, '', '', $route, true ); |
||
| 1330 | } |
||
| 1331 | |||
| 1332 | |||
| 1333 | |||
| 1334 | /** |
||
| 1335 | * incoming reg status change from reg details page. |
||
| 1336 | * @return void |
||
| 1337 | */ |
||
| 1338 | protected function _change_reg_status() { |
||
| 1367 | |||
| 1368 | |||
| 1369 | |||
| 1370 | /** |
||
| 1371 | * approve_registration |
||
| 1372 | * @access protected |
||
| 1373 | * @param bool $notify whether or not to notify the registrant about their approval. |
||
| 1374 | * @return void |
||
| 1375 | */ |
||
| 1376 | protected function approve_registration( $notify = false ) { |
||
| 1379 | |||
| 1380 | |||
| 1381 | |||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * decline_registration |
||
| 1385 | * @access protected |
||
| 1386 | * @param bool $notify whether or not to notify the registrant about their approval. |
||
| 1387 | * @return void |
||
| 1388 | */ |
||
| 1389 | protected function decline_registration( $notify = false ) { |
||
| 1392 | |||
| 1393 | |||
| 1394 | |||
| 1395 | |||
| 1396 | /** |
||
| 1397 | * cancel_registration |
||
| 1398 | * @access protected |
||
| 1399 | * @param bool $notify whether or not to notify the registrant about their approval. |
||
| 1400 | * @return void |
||
| 1401 | */ |
||
| 1402 | protected function cancel_registration( $notify = false ) { |
||
| 1405 | |||
| 1406 | |||
| 1407 | |||
| 1408 | |||
| 1409 | |||
| 1410 | /** |
||
| 1411 | * not_approve_registration |
||
| 1412 | * @access protected |
||
| 1413 | * @param bool $notify whether or not to notify the registrant about their approval. |
||
| 1414 | * @return void |
||
| 1415 | */ |
||
| 1416 | protected function not_approve_registration( $notify = false ) { |
||
| 1419 | |||
| 1420 | |||
| 1421 | |||
| 1422 | /** |
||
| 1423 | * decline_registration |
||
| 1424 | * @access protected |
||
| 1425 | * @param bool $notify whether or not to notify the registrant about their approval. |
||
| 1426 | * @return void |
||
| 1427 | */ |
||
| 1428 | protected function pending_registration( $notify = false ) { |
||
| 1431 | |||
| 1432 | |||
| 1433 | |||
| 1434 | |||
| 1435 | /** |
||
| 1436 | * generates HTML for the Registration main meta box |
||
| 1437 | * @access public |
||
| 1438 | * @return void |
||
| 1439 | */ |
||
| 1440 | public function _reg_details_meta_box() { |
||
| 1514 | |||
| 1515 | /** |
||
| 1516 | * generates HTML for the Registration Questions meta box. |
||
| 1517 | * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
||
| 1518 | * otherwise uses new forms system |
||
| 1519 | * |
||
| 1520 | * @access public |
||
| 1521 | * @return void |
||
| 1522 | */ |
||
| 1523 | public function _reg_questions_meta_box() { |
||
| 1535 | |||
| 1536 | |||
| 1537 | |||
| 1538 | /** |
||
| 1539 | * form_before_question_group |
||
| 1540 | * |
||
| 1541 | * @deprecated as of 4.8.32.rc.000 |
||
| 1542 | * @access public |
||
| 1543 | * @param string $output |
||
| 1544 | * @return string |
||
| 1545 | */ |
||
| 1546 | View Code Duplication | public function form_before_question_group( $output ) { |
|
| 1559 | |||
| 1560 | |||
| 1561 | |||
| 1562 | /** |
||
| 1563 | * form_after_question_group |
||
| 1564 | * |
||
| 1565 | * @deprecated as of 4.8.32.rc.000 |
||
| 1566 | * @access public |
||
| 1567 | * @param string $output |
||
| 1568 | * @return string |
||
| 1569 | */ |
||
| 1570 | public function form_after_question_group( $output ) { |
||
| 1592 | |||
| 1593 | |||
| 1594 | |||
| 1595 | /** |
||
| 1596 | * form_form_field_label_wrap |
||
| 1597 | * |
||
| 1598 | * @deprecated as of 4.8.32.rc.000 |
||
| 1599 | * @access public |
||
| 1600 | * @param string $label |
||
| 1601 | * @return string |
||
| 1602 | */ |
||
| 1603 | View Code Duplication | public function form_form_field_label_wrap( $label ) { |
|
| 1617 | |||
| 1618 | |||
| 1619 | |||
| 1620 | /** |
||
| 1621 | * form_form_field_input__wrap |
||
| 1622 | * |
||
| 1623 | * @deprecated as of 4.8.32.rc.000 |
||
| 1624 | * @access public |
||
| 1625 | * @param string $input |
||
| 1626 | * @return string |
||
| 1627 | */ |
||
| 1628 | View Code Duplication | public function form_form_field_input__wrap( $input ) { |
|
| 1642 | |||
| 1643 | /** |
||
| 1644 | * Updates the registration's custom questions according to the form info, if the form is submitted. |
||
| 1645 | * If it's not a post, the "view_registrations" route will be called next on the SAME request |
||
| 1646 | * to display the page |
||
| 1647 | * |
||
| 1648 | * @access protected |
||
| 1649 | * @return void |
||
| 1650 | */ |
||
| 1651 | protected function _update_attendee_registration_form() { |
||
| 1663 | |||
| 1664 | /** |
||
| 1665 | * Gets the form for saving registrations custom questions (if done |
||
| 1666 | * previously retrieves the cached form object, which may have validation errors in it) |
||
| 1667 | * @param int $REG_ID |
||
| 1668 | * @return EE_Registration_Custom_Questions_Form |
||
| 1669 | */ |
||
| 1670 | protected function _get_reg_custom_questions_form( $REG_ID ) { |
||
| 1678 | |||
| 1679 | |||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * Saves |
||
| 1683 | * @access private |
||
| 1684 | * @param bool $REG_ID |
||
| 1685 | * @return bool |
||
| 1686 | */ |
||
| 1687 | private function _save_reg_custom_questions_form( $REG_ID = FALSE ) { |
||
| 1721 | |||
| 1722 | /** |
||
| 1723 | * generates HTML for the Registration main meta box |
||
| 1724 | * @access public |
||
| 1725 | * @return void |
||
| 1726 | */ |
||
| 1727 | public function _reg_attendees_meta_box() { |
||
| 1774 | |||
| 1775 | |||
| 1776 | |||
| 1777 | |||
| 1778 | |||
| 1779 | |||
| 1780 | /** |
||
| 1781 | * generates HTML for the Edit Registration side meta box |
||
| 1782 | * @access public |
||
| 1783 | * @return void |
||
| 1784 | */ |
||
| 1785 | public function _reg_registrant_side_meta_box() { |
||
| 1828 | |||
| 1829 | |||
| 1830 | |||
| 1831 | |||
| 1832 | |||
| 1833 | /** |
||
| 1834 | * trash or restore registrations |
||
| 1835 | * @param boolean $trash whether to archive or restore |
||
| 1836 | * @access protected |
||
| 1837 | * @return void |
||
| 1838 | */ |
||
| 1839 | protected function _trash_or_restore_registrations( $trash = TRUE ) { |
||
| 1907 | |||
| 1908 | |||
| 1909 | |||
| 1910 | |||
| 1911 | |||
| 1912 | /** |
||
| 1913 | * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the registration but also. |
||
| 1914 | * |
||
| 1915 | * 1. Removing relations to EE_Attendee |
||
| 1916 | * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are ALSO trashed. |
||
| 1917 | * 3. Deleting permanently any related Line items but only if the above conditions are met. |
||
| 1918 | * 4. Removing relationships between all tickets and the related registrations |
||
| 1919 | * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
||
| 1920 | * 6. Deleting permanently any related Checkins. |
||
| 1921 | * @return void |
||
| 1922 | */ |
||
| 1923 | protected function _delete_registrations() { |
||
| 1958 | |||
| 1959 | |||
| 1960 | |||
| 1961 | |||
| 1962 | |||
| 1963 | /** |
||
| 1964 | * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what models get affected. |
||
| 1965 | * @param EE_Registration $REG registration to be deleted permenantly |
||
| 1966 | * @return boolean true = successful deletion, false = fail. |
||
| 1967 | */ |
||
| 1968 | protected function _delete_registration( EE_Registration $REG ) { |
||
| 2024 | |||
| 2025 | |||
| 2026 | |||
| 2027 | /** |
||
| 2028 | * generates HTML for the Register New Attendee Admin page |
||
| 2029 | * |
||
| 2030 | * @access private |
||
| 2031 | * @throws \EE_Error |
||
| 2032 | * @return void |
||
| 2033 | */ |
||
| 2034 | public function new_registration() { |
||
| 2035 | if ( ! $this->_set_reg_event() ) { |
||
| 2036 | throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request', 'event_espresso') ); |
||
| 2037 | } |
||
| 2038 | EE_Registry::instance()->REQ->set_espresso_page( TRUE ); |
||
| 2039 | // gotta start with a clean slate if we're not coming here via ajax |
||
| 2040 | if ( |
||
| 2041 | ! defined('DOING_AJAX' ) |
||
| 2042 | && ( ! isset( $this->_req_data['processing_registration'] ) || isset( $this->_req_data['step_error'] ) ) |
||
| 2043 | ) { |
||
| 2044 | EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ ); |
||
| 2045 | } |
||
| 2046 | |||
| 2047 | $this->_template_args['event_name'] = '' ; |
||
| 2048 | // event name |
||
| 2049 | if ( $this->_reg_event ) { |
||
| 2050 | $this->_template_args['event_name'] = $this->_reg_event->name(); |
||
| 2051 | $edit_event_url = self::add_query_args_and_nonce( array( 'action'=>'edit', 'post'=>$this->_reg_event->ID() ), EVENTS_ADMIN_URL ); |
||
| 2052 | $edit_event_lnk = '<a href="'.$edit_event_url.'" title="' . esc_attr__( 'Edit ', 'event_espresso' ) . $this->_reg_event->name() . '">' . __( 'Edit Event', 'event_espresso' ) . '</a>'; |
||
| 2053 | $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' . $edit_event_lnk . '</span>' ; |
||
| 2054 | } |
||
| 2055 | |||
| 2056 | $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
||
| 2057 | |||
| 2058 | if ( defined('DOING_AJAX' ) ) { |
||
| 2059 | $this->_return_json(); |
||
| 2060 | } |
||
| 2061 | // grab header |
||
| 2062 | $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
||
| 2063 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE ); |
||
| 2064 | |||
| 2065 | //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
||
| 2066 | // the details template wrapper |
||
| 2067 | $this->display_admin_page_with_sidebar(); |
||
| 2068 | } |
||
| 2069 | |||
| 2070 | |||
| 2071 | |||
| 2072 | |||
| 2073 | /** |
||
| 2074 | * This returns the content for a registration step |
||
| 2075 | * |
||
| 2076 | * @access protected |
||
| 2077 | * @return string html |
||
| 2078 | */ |
||
| 2079 | protected function _get_registration_step_content() { |
||
| 2080 | if ( isset( $_COOKIE[ 'ee_registration_added' ] ) && $_COOKIE[ 'ee_registration_added' ] ) { |
||
| 2081 | $warning_msg = sprintf( |
||
| 2082 | __( |
||
| 2083 | '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
||
| 2084 | 'event_espresso' |
||
| 2085 | ), |
||
| 2086 | '<br />', |
||
| 2087 | '<h3 class="important-notice">', |
||
| 2088 | '</h3>', |
||
| 2089 | '<div class="float-right">', |
||
| 2090 | '<span id="redirect_timer" class="important-notice">30</span>', |
||
| 2091 | '</div>', |
||
| 2092 | '<b>', |
||
| 2093 | '</b>' |
||
| 2094 | ); |
||
| 2095 | return ' |
||
| 2096 | <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div> |
||
| 2097 | <script > |
||
| 2098 | // WHOAH !!! it appears that someone is using the back button from the Transaction admin page |
||
| 2099 | // after just adding a new registration... we gotta try to put a stop to that !!! |
||
| 2100 | var timer = 30; |
||
| 2101 | setInterval( function () { |
||
| 2102 | jQuery("#redirect_timer").html( parseInt( timer ) ); |
||
| 2103 | if ( --timer < 0 ) { |
||
| 2104 | window.history.forward() |
||
| 2105 | } |
||
| 2106 | }, 800 ); |
||
| 2107 | </script >'; |
||
| 2108 | } |
||
| 2109 | $template_args = array( |
||
| 2110 | 'title' => '', |
||
| 2111 | 'content' => '', |
||
| 2112 | 'step_button_text' => '', |
||
| 2113 | 'show_notification_toggle' => false |
||
| 2114 | ); |
||
| 2115 | //to indicate we're processing a new registration |
||
| 2116 | $hidden_fields = array( |
||
| 2117 | 'processing_registration' => array( |
||
| 2118 | 'type' => 'hidden', |
||
| 2119 | 'value' => 0 |
||
| 2120 | ), |
||
| 2121 | 'event_id' => array( |
||
| 2122 | 'type' => 'hidden', |
||
| 2123 | 'value' => $this->_reg_event->ID() |
||
| 2124 | ) |
||
| 2125 | ); |
||
| 2126 | |||
| 2127 | //if the cart is empty then we know we're at step one so we'll display ticket selector |
||
| 2128 | $cart = EE_Registry::instance()->SSN->cart(); |
||
| 2129 | $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
||
| 2130 | |||
| 2131 | switch ( $step ) { |
||
| 2132 | case 'ticket' : |
||
| 2133 | $hidden_fields['processing_registration']['value'] = 1; |
||
| 2134 | $template_args['title'] = __('Step One: Select the Ticket for this registration', 'event_espresso'); |
||
| 2135 | $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector( $this->_reg_event ); |
||
| 2136 | $template_args['step_button_text'] = __('Add Tickets and Continue to Registrant Details', 'event_espresso'); |
||
| 2137 | $template_args['show_notification_toggle'] = FALSE; |
||
| 2138 | break; |
||
| 2139 | case 'questions' : |
||
| 2140 | $hidden_fields[ 'processing_registration' ][ 'value' ] = 2; |
||
| 2141 | $template_args['title'] = __('Step Two: Add Registrant Details for this Registration', 'event_espresso'); |
||
| 2142 | //in theory we should be able to run EED_SPCO at this point because the cart should have been setup properly by the first process_reg_step run. |
||
| 2143 | $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin(); |
||
| 2144 | $template_args['step_button_text'] = __('Save Registration and Continue to Details', 'event_espresso'); |
||
| 2145 | $template_args['show_notification_toggle'] = TRUE; |
||
| 2146 | break; |
||
| 2147 | } |
||
| 2148 | |||
| 2149 | $this->_set_add_edit_form_tags( 'process_reg_step', $hidden_fields ); //we come back to the process_registration_step route. |
||
| 2150 | |||
| 2151 | return EEH_Template::display_template( |
||
| 2152 | REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', $template_args, TRUE |
||
| 2153 | ); |
||
| 2154 | } |
||
| 2155 | |||
| 2156 | |||
| 2157 | |||
| 2158 | |||
| 2159 | |||
| 2160 | |||
| 2161 | /** |
||
| 2162 | * set_reg_event |
||
| 2163 | * @access private |
||
| 2164 | * @return boolean |
||
| 2165 | */ |
||
| 2166 | private function _set_reg_event() { |
||
| 2178 | |||
| 2179 | |||
| 2180 | |||
| 2181 | |||
| 2182 | |||
| 2183 | /** |
||
| 2184 | * process_reg_step |
||
| 2185 | * |
||
| 2186 | * @access public |
||
| 2187 | * @return string |
||
| 2188 | */ |
||
| 2189 | public function process_reg_step() { |
||
| 2190 | EE_System::do_not_cache(); |
||
| 2191 | $this->_set_reg_event(); |
||
| 2192 | EE_Registry::instance()->REQ->set_espresso_page( TRUE ); |
||
| 2193 | |||
| 2194 | //what step are we on? |
||
| 2195 | $cart = EE_Registry::instance()->SSN->cart(); |
||
| 2196 | $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
||
| 2197 | |||
| 2198 | //if doing ajax then we need to verify the nonce |
||
| 2199 | View Code Duplication | if ( defined( 'DOING_AJAX' ) ) { |
|
| 2200 | $nonce = isset( $this->_req_data[$this->_req_nonce] ) ? sanitize_text_field( $this->_req_data[$this->_req_nonce] ) : ''; |
||
| 2201 | $this->_verify_nonce( $nonce, $this->_req_nonce ); |
||
| 2202 | } |
||
| 2203 | |||
| 2204 | switch ( $step ) { |
||
| 2205 | |||
| 2206 | case 'ticket' : |
||
| 2207 | //process ticket selection |
||
| 2208 | $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
||
| 2209 | if ( $success ) { |
||
| 2210 | EE_Error::add_success( __('Tickets Selected. Now complete the registration.'), 'event_espresso'); |
||
| 2211 | } else { |
||
| 2212 | $query_args['step_error'] = $this->_req_data['step_error'] = TRUE; |
||
| 2213 | } |
||
| 2214 | if ( defined('DOING_AJAX') ) { |
||
| 2215 | $this->new_registration(); //display next step |
||
| 2216 | } else { |
||
| 2217 | $query_args['action'] = 'new_registration'; |
||
| 2218 | $query_args['processing_registration'] = 1; |
||
| 2219 | $query_args['event_id'] = $this->_reg_event->ID(); |
||
| 2220 | $this->_redirect_after_action( FALSE, '', '', $query_args, TRUE ); |
||
| 2221 | } |
||
| 2222 | break; |
||
| 2223 | |||
| 2224 | case 'questions' : |
||
| 2225 | if( ! isset( $this->_req_data[ 'txn_reg_status_change' ], $this->_req_data[ 'txn_reg_status_change' ][ 'send_notifications' ] ) ) { |
||
| 2226 | add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15 ); |
||
| 2227 | } |
||
| 2228 | //process registration |
||
| 2229 | $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
||
| 2230 | if ( $cart instanceof EE_Cart ) { |
||
| 2231 | $grand_total = $cart->get_cart_grand_total(); |
||
| 2232 | if ( $grand_total instanceof EE_Line_Item ) { |
||
| 2233 | $grand_total->save_this_and_descendants_to_txn(); |
||
| 2234 | } |
||
| 2235 | } |
||
| 2236 | if ( ! $transaction instanceof EE_Transaction ) { |
||
| 2237 | $query_args = array( |
||
| 2238 | 'action' => 'new_registration', |
||
| 2239 | 'processing_registration' => 2, |
||
| 2240 | 'event_id' => $this->_reg_event->ID() |
||
| 2241 | ); |
||
| 2242 | |||
| 2243 | View Code Duplication | if ( defined('DOING_AJAX' )) { |
|
| 2244 | //display registration form again because there are errors (maybe validation?) |
||
| 2245 | $this->new_registration(); |
||
| 2246 | return; |
||
| 2247 | } else { |
||
| 2248 | $this->_redirect_after_action( FALSE, '', '', $query_args, TRUE ); |
||
| 2249 | return; |
||
| 2250 | } |
||
| 2251 | } |
||
| 2252 | /** @type EE_Transaction_Payments $transaction_payments */ |
||
| 2253 | $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
||
| 2254 | // maybe update status, and make sure to save transaction if not done already |
||
| 2255 | if ( ! $transaction_payments->update_transaction_status_based_on_total_paid( $transaction )) { |
||
| 2256 | $transaction->save(); |
||
| 2257 | } |
||
| 2258 | EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ ); |
||
| 2259 | $this->_req_data = array(); |
||
| 2260 | $query_args = array( |
||
| 2261 | 'action' => 'redirect_to_txn', |
||
| 2262 | 'TXN_ID' => $transaction->ID(), |
||
| 2263 | 'EVT_ID' => $this->_reg_event->ID(), |
||
| 2264 | 'event_name' => urlencode( $this->_reg_event->name() ), |
||
| 2265 | 'redirect_from' => 'new_registration' |
||
| 2266 | ); |
||
| 2267 | $this->_redirect_after_action( false, '', '', $query_args, true ); |
||
| 2268 | break; |
||
| 2269 | } |
||
| 2270 | |||
| 2271 | //what are you looking here for? Should be nothing to do at this point. |
||
| 2272 | } |
||
| 2273 | |||
| 2274 | |||
| 2275 | |||
| 2276 | /** |
||
| 2277 | * redirect_to_txn |
||
| 2278 | * |
||
| 2279 | * @access public |
||
| 2280 | * @return void |
||
| 2281 | */ |
||
| 2282 | public function redirect_to_txn() { |
||
| 2283 | EE_System::do_not_cache(); |
||
| 2284 | EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ ); |
||
| 2285 | $query_args = array( |
||
| 2286 | 'action' => 'view_transaction', |
||
| 2287 | 'TXN_ID' => isset( $this->_req_data['TXN_ID'] ) ? absint( $this->_req_data[ 'TXN_ID' ] ) : 0, |
||
| 2288 | 'page' => 'espresso_transactions' |
||
| 2289 | ); |
||
| 2290 | if ( isset( $this->_req_data[ 'EVT_ID' ], $this->_req_data[ 'redirect_from' ] ) ) { |
||
| 2291 | $query_args['EVT_ID'] = $this->_req_data[ 'EVT_ID' ]; |
||
| 2292 | $query_args['event_name'] = urlencode( $this->_req_data[ 'event_name' ] ); |
||
| 2293 | $query_args['redirect_from'] = $this->_req_data[ 'redirect_from' ]; |
||
| 2294 | } |
||
| 2295 | EE_Error::add_success( |
||
| 2296 | __( 'Registration Created. Please review the transaction and add any payments as necessary', 'event_espresso' ) |
||
| 2297 | ); |
||
| 2298 | $this->_redirect_after_action( false, '', '', $query_args, true ); |
||
| 2299 | } |
||
| 2300 | |||
| 2301 | |||
| 2302 | |||
| 2303 | /** |
||
| 2304 | * generates HTML for the Attendee Contact List |
||
| 2305 | * @access protected |
||
| 2306 | * @return void |
||
| 2307 | */ |
||
| 2308 | protected function _attendee_contact_list_table() { |
||
| 2313 | |||
| 2314 | |||
| 2315 | |||
| 2316 | |||
| 2317 | |||
| 2318 | /** |
||
| 2319 | * get_attendees |
||
| 2320 | * @param bool $count whether to return count or data. |
||
| 2321 | * @access public |
||
| 2322 | * @return array |
||
| 2323 | */ |
||
| 2324 | public function get_attendees( $per_page, $count = FALSE, $trash = FALSE ) { |
||
| 2400 | |||
| 2401 | |||
| 2402 | |||
| 2403 | |||
| 2404 | /** |
||
| 2405 | * This is just taking care of resending the registration confirmation |
||
| 2406 | * |
||
| 2407 | * @access protected |
||
| 2408 | * @return void |
||
| 2409 | */ |
||
| 2410 | protected function _resend_registration() { |
||
| 2417 | |||
| 2418 | |||
| 2419 | |||
| 2420 | |||
| 2421 | |||
| 2422 | |||
| 2423 | public function _registrations_report(){ |
||
| 2449 | |||
| 2450 | |||
| 2451 | |||
| 2452 | public function _contact_list_export(){ |
||
| 2460 | |||
| 2461 | public function _contact_list_report(){ |
||
| 2479 | |||
| 2480 | |||
| 2481 | |||
| 2482 | |||
| 2483 | |||
| 2484 | |||
| 2485 | /*************************************** ATTENDEE DETAILS ***************************************/ |
||
| 2486 | |||
| 2487 | |||
| 2488 | /** |
||
| 2489 | * This duplicates the attendee object for the given incoming registration id and attendee_id. |
||
| 2490 | * @return void |
||
| 2491 | */ |
||
| 2492 | protected function _duplicate_attendee() { |
||
| 2522 | |||
| 2523 | |||
| 2524 | //related to cpt routes |
||
| 2525 | protected function _insert_update_cpt_item($post_id, $post) { |
||
| 2562 | |||
| 2563 | |||
| 2564 | |||
| 2565 | |||
| 2566 | public function trash_cpt_item($post_id) {} |
||
| 2570 | |||
| 2571 | |||
| 2572 | public function attendee_editor_metaboxes() { |
||
| 2591 | |||
| 2592 | |||
| 2593 | /** |
||
| 2594 | * Metabox for attendee contact info |
||
| 2595 | * @param WP_Post $post wp post object |
||
| 2596 | * @return string attendee contact info ( and form ) |
||
| 2597 | */ |
||
| 2598 | public function attendee_contact_info( $post ) { |
||
| 2604 | |||
| 2605 | |||
| 2606 | |||
| 2607 | /** |
||
| 2608 | * Metabox for attendee details |
||
| 2609 | * @param WP_Post $post wp post object |
||
| 2610 | * @return string attendee address details (and form) |
||
| 2611 | */ |
||
| 2612 | public function attendee_address_details($post) { |
||
| 2655 | |||
| 2656 | |||
| 2657 | /** |
||
| 2658 | * _attendee_details |
||
| 2659 | * @access protected |
||
| 2660 | * @return void |
||
| 2661 | */ |
||
| 2662 | public function attendee_registrations_meta_box( $post ) { |
||
| 2670 | |||
| 2671 | |||
| 2672 | |||
| 2673 | |||
| 2674 | /** |
||
| 2675 | * add in the form fields for the attendee edit |
||
| 2676 | * @param WP_Post $post wp post object |
||
| 2677 | * @return string html for new form. |
||
| 2678 | */ |
||
| 2679 | public function after_title_form_fields($post) { |
||
| 2686 | |||
| 2687 | |||
| 2688 | |||
| 2689 | |||
| 2690 | |||
| 2691 | |||
| 2692 | /** |
||
| 2693 | * _trash_or_restore_attendee |
||
| 2694 | * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
||
| 2695 | * @access protected |
||
| 2696 | * @return void |
||
| 2697 | */ |
||
| 2698 | protected function _trash_or_restore_attendees( $trash = TRUE ) { |
||
| 2735 | |||
| 2736 | } |
||
| 2737 | |||
| 2738 | |||
| 2739 | |||
| 2740 | // end of file: includes/core/admin/transactions/Registrations_Admin_Page.core.php |
||
| 2741 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.