@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public static function apply_query_filters( WP_Query $WP_Query ) { |
| 93 | 93 | return ( |
| 94 | - isset( $WP_Query->query, $WP_Query->query['post_type'] ) |
|
| 95 | - && $WP_Query->query['post_type'] === 'espresso_events' |
|
| 96 | - ) || apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ; |
|
| 94 | + isset( $WP_Query->query, $WP_Query->query['post_type'] ) |
|
| 95 | + && $WP_Query->query['post_type'] === 'espresso_events' |
|
| 96 | + ) || apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public static function filter_query_parts( WP_Query $WP_Query ) { |
| 106 | 106 | // ONLY add our filters if this isn't the main wp_query, |
| 107 | - // because if this is the main wp_query we already have |
|
| 108 | - // our cpt strategies take care of adding things in. |
|
| 107 | + // because if this is the main wp_query we already have |
|
| 108 | + // our cpt strategies take care of adding things in. |
|
| 109 | 109 | if ( $WP_Query instanceof WP_Query && ! $WP_Query->is_main_query() ) { |
| 110 | 110 | // build event list query |
| 111 | 111 | add_filter( 'posts_fields', array( 'EEH_Event_Query', 'posts_fields' ), 10, 2 ); |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | * @param string $orderby |
| 128 | 128 | * @param string $sort |
| 129 | 129 | */ |
| 130 | - public static function set_query_params( |
|
| 131 | - $month = '', |
|
| 132 | - $category = '', |
|
| 133 | - $show_expired = false, |
|
| 134 | - $orderby = 'start_date', |
|
| 135 | - $sort = 'ASC' |
|
| 136 | - ) { |
|
| 130 | + public static function set_query_params( |
|
| 131 | + $month = '', |
|
| 132 | + $category = '', |
|
| 133 | + $show_expired = false, |
|
| 134 | + $orderby = 'start_date', |
|
| 135 | + $sort = 'ASC' |
|
| 136 | + ) { |
|
| 137 | 137 | self::$_query_params = array(); |
| 138 | 138 | EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month( $month ); |
| 139 | 139 | EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug( $category ); |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | * @return string |
| 152 | 152 | */ |
| 153 | 153 | private static function _display_month( $month = '' ) { |
| 154 | - return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month)); |
|
| 155 | - } |
|
| 154 | + return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month)); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | 157 | |
| 158 | 158 | |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | private static function _show_expired( $show_expired = false ) { |
| 178 | 178 | // override default expired option if set via filter |
| 179 | 179 | return filter_var( |
| 180 | - EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired), |
|
| 181 | - FILTER_VALIDATE_BOOLEAN |
|
| 182 | - ); |
|
| 180 | + EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired), |
|
| 181 | + FILTER_VALIDATE_BOOLEAN |
|
| 182 | + ); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
@@ -193,8 +193,8 @@ discard block |
||
| 193 | 193 | private static function _orderby( $orderby = 'start_date' ) { |
| 194 | 194 | $event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby); |
| 195 | 195 | $event_query_orderby = is_array( $event_query_orderby ) |
| 196 | - ? $event_query_orderby |
|
| 197 | - : explode( ',', $event_query_orderby ); |
|
| 196 | + ? $event_query_orderby |
|
| 197 | + : explode( ',', $event_query_orderby ); |
|
| 198 | 198 | $event_query_orderby = array_map( 'trim', $event_query_orderby ); |
| 199 | 199 | $event_query_orderby = array_map( 'sanitize_text_field', $event_query_orderby ); |
| 200 | 200 | return $event_query_orderby; |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | private static function _sort( $sort = 'ASC' ) { |
| 212 | 212 | $sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort); |
| 213 | 213 | return in_array( $sort, array( 'ASC', 'asc', 'DESC', 'desc' ), true) |
| 214 | - ? strtoupper( $sort ) |
|
| 215 | - : 'ASC'; |
|
| 214 | + ? strtoupper( $sort ) |
|
| 215 | + : 'ASC'; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | |
@@ -235,14 +235,14 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * posts_fields |
|
| 240 | - * |
|
| 241 | - * @param $SQL |
|
| 242 | - * @param WP_Query $wp_query |
|
| 243 | - * @return string |
|
| 244 | - * @throws \EE_Error |
|
| 245 | - */ |
|
| 238 | + /** |
|
| 239 | + * posts_fields |
|
| 240 | + * |
|
| 241 | + * @param $SQL |
|
| 242 | + * @param WP_Query $wp_query |
|
| 243 | + * @return string |
|
| 244 | + * @throws \EE_Error |
|
| 245 | + */ |
|
| 246 | 246 | public static function posts_fields( $SQL, WP_Query $wp_query ) { |
| 247 | 247 | if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
| 248 | 248 | // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
@@ -253,13 +253,13 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | |
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * posts_join_sql_for_terms |
|
| 258 | - * |
|
| 259 | - * @param array $orderby_params |
|
| 260 | - * @return string |
|
| 261 | - * @throws \EE_Error |
|
| 262 | - */ |
|
| 256 | + /** |
|
| 257 | + * posts_join_sql_for_terms |
|
| 258 | + * |
|
| 259 | + * @param array $orderby_params |
|
| 260 | + * @return string |
|
| 261 | + * @throws \EE_Error |
|
| 262 | + */ |
|
| 263 | 263 | public static function posts_fields_sql_for_orderby( $orderby_params = array() ) { |
| 264 | 264 | $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ' ; |
| 265 | 265 | foreach( (array)$orderby_params as $orderby ) { |
@@ -292,14 +292,14 @@ discard block |
||
| 292 | 292 | |
| 293 | 293 | |
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * posts_join |
|
| 297 | - * |
|
| 298 | - * @param string $SQL |
|
| 299 | - * @param WP_Query $wp_query |
|
| 300 | - * @return string |
|
| 301 | - * @throws \EE_Error |
|
| 302 | - */ |
|
| 295 | + /** |
|
| 296 | + * posts_join |
|
| 297 | + * |
|
| 298 | + * @param string $SQL |
|
| 299 | + * @param WP_Query $wp_query |
|
| 300 | + * @return string |
|
| 301 | + * @throws \EE_Error |
|
| 302 | + */ |
|
| 303 | 303 | public static function posts_join( $SQL = '', WP_Query $wp_query ) { |
| 304 | 304 | if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
| 305 | 305 | // Category |
@@ -312,14 +312,14 @@ discard block |
||
| 312 | 312 | |
| 313 | 313 | |
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * posts_join_sql_for_terms |
|
| 317 | - * |
|
| 318 | - * @param string $SQL |
|
| 319 | - * @param boolean $show_expired if TRUE, then displayed past events |
|
| 320 | - * @return string |
|
| 321 | - * @throws \EE_Error |
|
| 322 | - */ |
|
| 315 | + /** |
|
| 316 | + * posts_join_sql_for_terms |
|
| 317 | + * |
|
| 318 | + * @param string $SQL |
|
| 319 | + * @param boolean $show_expired if TRUE, then displayed past events |
|
| 320 | + * @return string |
|
| 321 | + * @throws \EE_Error |
|
| 322 | + */ |
|
| 323 | 323 | public static function posts_join_sql_for_show_expired( $SQL = '', $show_expired = FALSE ) { |
| 324 | 324 | if ( ! $show_expired ) { |
| 325 | 325 | $join = EEM_Event::instance()->table() . '.ID = '; |
@@ -353,24 +353,24 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | |
| 355 | 355 | |
| 356 | - /** |
|
| 357 | - * posts_join_for_orderby |
|
| 358 | - * usage: $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params ); |
|
| 359 | - * |
|
| 360 | - * @param string $SQL |
|
| 361 | - * @param array $orderby_params |
|
| 362 | - * @return string |
|
| 363 | - * @throws \EE_Error |
|
| 364 | - */ |
|
| 356 | + /** |
|
| 357 | + * posts_join_for_orderby |
|
| 358 | + * usage: $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params ); |
|
| 359 | + * |
|
| 360 | + * @param string $SQL |
|
| 361 | + * @param array $orderby_params |
|
| 362 | + * @return string |
|
| 363 | + * @throws \EE_Error |
|
| 364 | + */ |
|
| 365 | 365 | public static function posts_join_for_orderby( $SQL = '', $orderby_params = array() ) { |
| 366 | 366 | foreach ( (array)$orderby_params as $orderby ) { |
| 367 | 367 | switch ( $orderby ) { |
| 368 | 368 | case 'ticket_start' : |
| 369 | 369 | case 'ticket_end' : |
| 370 | 370 | $SQL .= EEH_Event_Query::_posts_join_for_datetime( |
| 371 | - $SQL, |
|
| 372 | - EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
| 373 | - ); |
|
| 371 | + $SQL, |
|
| 372 | + EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
| 373 | + ); |
|
| 374 | 374 | $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table(); |
| 375 | 375 | $SQL .= ' ON ('; |
| 376 | 376 | $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
@@ -398,14 +398,14 @@ discard block |
||
| 398 | 398 | |
| 399 | 399 | |
| 400 | 400 | |
| 401 | - /** |
|
| 402 | - * _posts_join_for_datetime |
|
| 403 | - * |
|
| 404 | - * @param string $SQL |
|
| 405 | - * @param string $join |
|
| 406 | - * @return string |
|
| 407 | - * @throws \EE_Error |
|
| 408 | - */ |
|
| 401 | + /** |
|
| 402 | + * _posts_join_for_datetime |
|
| 403 | + * |
|
| 404 | + * @param string $SQL |
|
| 405 | + * @param string $join |
|
| 406 | + * @return string |
|
| 407 | + * @throws \EE_Error |
|
| 408 | + */ |
|
| 409 | 409 | protected static function _posts_join_for_datetime( $SQL = '', $join = '' ) { |
| 410 | 410 | if ( ! empty( $join )) { |
| 411 | 411 | $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
@@ -418,13 +418,13 @@ discard block |
||
| 418 | 418 | |
| 419 | 419 | |
| 420 | 420 | |
| 421 | - /** |
|
| 422 | - * _posts_join_for_event_venue |
|
| 423 | - * |
|
| 424 | - * @param string $SQL |
|
| 425 | - * @return string |
|
| 426 | - * @throws \EE_Error |
|
| 427 | - */ |
|
| 421 | + /** |
|
| 422 | + * _posts_join_for_event_venue |
|
| 423 | + * |
|
| 424 | + * @param string $SQL |
|
| 425 | + * @return string |
|
| 426 | + * @throws \EE_Error |
|
| 427 | + */ |
|
| 428 | 428 | protected static function _posts_join_for_event_venue( $SQL = '' ) { |
| 429 | 429 | // Event Venue table name |
| 430 | 430 | $event_venue_table = EEM_Event_Venue::instance()->table(); |
@@ -454,13 +454,13 @@ discard block |
||
| 454 | 454 | |
| 455 | 455 | |
| 456 | 456 | |
| 457 | - /** |
|
| 458 | - * _posts_join_for_venue_state |
|
| 459 | - * |
|
| 460 | - * @param string $SQL |
|
| 461 | - * @return string |
|
| 462 | - * @throws \EE_Error |
|
| 463 | - */ |
|
| 457 | + /** |
|
| 458 | + * _posts_join_for_venue_state |
|
| 459 | + * |
|
| 460 | + * @param string $SQL |
|
| 461 | + * @return string |
|
| 462 | + * @throws \EE_Error |
|
| 463 | + */ |
|
| 464 | 464 | protected static function _posts_join_for_venue_state( $SQL = '' ) { |
| 465 | 465 | // Venue Meta table name |
| 466 | 466 | $venue_meta_table = EEM_Venue::instance()->second_table(); |
@@ -484,14 +484,14 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | |
| 486 | 486 | |
| 487 | - /** |
|
| 488 | - * posts_where |
|
| 489 | - * |
|
| 490 | - * @param string $SQL |
|
| 491 | - * @param WP_Query $wp_query |
|
| 492 | - * @return string |
|
| 493 | - * @throws \EE_Error |
|
| 494 | - */ |
|
| 487 | + /** |
|
| 488 | + * posts_where |
|
| 489 | + * |
|
| 490 | + * @param string $SQL |
|
| 491 | + * @param WP_Query $wp_query |
|
| 492 | + * @return string |
|
| 493 | + * @throws \EE_Error |
|
| 494 | + */ |
|
| 495 | 495 | public static function posts_where( $SQL = '', WP_Query $wp_query ) { |
| 496 | 496 | if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
| 497 | 497 | // Show Expired ? |
@@ -506,17 +506,17 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | |
| 508 | 508 | |
| 509 | - /** |
|
| 510 | - * posts_where_sql_for_show_expired |
|
| 511 | - * |
|
| 512 | - * @param boolean $show_expired if TRUE, then displayed past events |
|
| 513 | - * @return string |
|
| 514 | - * @throws \EE_Error |
|
| 515 | - */ |
|
| 509 | + /** |
|
| 510 | + * posts_where_sql_for_show_expired |
|
| 511 | + * |
|
| 512 | + * @param boolean $show_expired if TRUE, then displayed past events |
|
| 513 | + * @return string |
|
| 514 | + * @throws \EE_Error |
|
| 515 | + */ |
|
| 516 | 516 | public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) { |
| 517 | 517 | return ! $show_expired |
| 518 | - ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' ' |
|
| 519 | - : ''; |
|
| 518 | + ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' ' |
|
| 519 | + : ''; |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | |
@@ -531,19 +531,19 @@ discard block |
||
| 531 | 531 | global $wpdb; |
| 532 | 532 | $event_category_slug = esc_sql($event_category_slug); |
| 533 | 533 | return ! empty( $event_category_slug ) |
| 534 | - ? " AND {$wpdb->terms}.slug = '{$event_category_slug}' " |
|
| 535 | - : ''; |
|
| 534 | + ? " AND {$wpdb->terms}.slug = '{$event_category_slug}' " |
|
| 535 | + : ''; |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | |
| 539 | 539 | |
| 540 | - /** |
|
| 541 | - * posts_where_sql_for_event_list_month |
|
| 542 | - * |
|
| 543 | - * @param boolean $month |
|
| 544 | - * @return string |
|
| 545 | - * @throws \EE_Error |
|
| 546 | - */ |
|
| 540 | + /** |
|
| 541 | + * posts_where_sql_for_event_list_month |
|
| 542 | + * |
|
| 543 | + * @param boolean $month |
|
| 544 | + * @return string |
|
| 545 | + * @throws \EE_Error |
|
| 546 | + */ |
|
| 547 | 547 | public static function posts_where_sql_for_event_list_month( $month = NULL ) { |
| 548 | 548 | $SQL = ''; |
| 549 | 549 | if ( ! empty( $month ) ) { |
@@ -558,55 +558,55 @@ discard block |
||
| 558 | 558 | |
| 559 | 559 | |
| 560 | 560 | |
| 561 | - /** |
|
| 562 | - * posts_orderby |
|
| 563 | - * |
|
| 564 | - * @param string $SQL |
|
| 565 | - * @param WP_Query $wp_query |
|
| 566 | - * @return string |
|
| 567 | - * @throws \EE_Error |
|
| 568 | - */ |
|
| 561 | + /** |
|
| 562 | + * posts_orderby |
|
| 563 | + * |
|
| 564 | + * @param string $SQL |
|
| 565 | + * @param WP_Query $wp_query |
|
| 566 | + * @return string |
|
| 567 | + * @throws \EE_Error |
|
| 568 | + */ |
|
| 569 | 569 | public static function posts_orderby( $SQL = '', WP_Query $wp_query ) { |
| 570 | 570 | if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
| 571 | 571 | $SQL = EEH_Event_Query::posts_orderby_sql( |
| 572 | - EEH_Event_Query::$_event_query_orderby, |
|
| 573 | - EEH_Event_Query::$_event_query_sort |
|
| 574 | - ); |
|
| 572 | + EEH_Event_Query::$_event_query_orderby, |
|
| 573 | + EEH_Event_Query::$_event_query_sort |
|
| 574 | + ); |
|
| 575 | 575 | } |
| 576 | 576 | return $SQL; |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | |
| 580 | 580 | |
| 581 | - /** |
|
| 582 | - * posts_orderby_sql |
|
| 583 | - * possible parameters: |
|
| 584 | - * ID |
|
| 585 | - * start_date |
|
| 586 | - * end_date |
|
| 587 | - * event_name |
|
| 588 | - * category_slug |
|
| 589 | - * ticket_start |
|
| 590 | - * ticket_end |
|
| 591 | - * venue_title |
|
| 592 | - * city |
|
| 593 | - * state |
|
| 594 | - * **IMPORTANT** |
|
| 595 | - * make sure to also send the $orderby_params array to the posts_join_for_orderby() method |
|
| 596 | - * or else some of the table references below will result in MySQL errors |
|
| 597 | - * |
|
| 598 | - * @param array|bool $orderby_params |
|
| 599 | - * @param string $sort |
|
| 600 | - * @return string |
|
| 601 | - * @throws \EE_Error |
|
| 602 | - */ |
|
| 581 | + /** |
|
| 582 | + * posts_orderby_sql |
|
| 583 | + * possible parameters: |
|
| 584 | + * ID |
|
| 585 | + * start_date |
|
| 586 | + * end_date |
|
| 587 | + * event_name |
|
| 588 | + * category_slug |
|
| 589 | + * ticket_start |
|
| 590 | + * ticket_end |
|
| 591 | + * venue_title |
|
| 592 | + * city |
|
| 593 | + * state |
|
| 594 | + * **IMPORTANT** |
|
| 595 | + * make sure to also send the $orderby_params array to the posts_join_for_orderby() method |
|
| 596 | + * or else some of the table references below will result in MySQL errors |
|
| 597 | + * |
|
| 598 | + * @param array|bool $orderby_params |
|
| 599 | + * @param string $sort |
|
| 600 | + * @return string |
|
| 601 | + * @throws \EE_Error |
|
| 602 | + */ |
|
| 603 | 603 | public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) { |
| 604 | 604 | global $wpdb; |
| 605 | 605 | $SQL = ''; |
| 606 | 606 | $counter = 0; |
| 607 | 607 | $sort = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
| 608 | - ? strtoupper($sort) |
|
| 609 | - : 'ASC'; |
|
| 608 | + ? strtoupper($sort) |
|
| 609 | + : 'ASC'; |
|
| 610 | 610 | //make sure 'orderby' is set in query params |
| 611 | 611 | if ( ! isset( self::$_query_params['orderby'] )) { |
| 612 | 612 | self::$_query_params['orderby'] = array(); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public static function add_query_filters() { |
| 80 | 80 | //add query filters |
| 81 | - add_action( 'pre_get_posts', array( 'EEH_Event_Query', 'filter_query_parts' ), 10, 1 ); |
|
| 81 | + add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | |
@@ -89,11 +89,11 @@ discard block |
||
| 89 | 89 | * @param \WP_Query $WP_Query |
| 90 | 90 | * @return bool |
| 91 | 91 | */ |
| 92 | - public static function apply_query_filters( WP_Query $WP_Query ) { |
|
| 92 | + public static function apply_query_filters(WP_Query $WP_Query) { |
|
| 93 | 93 | return ( |
| 94 | - isset( $WP_Query->query, $WP_Query->query['post_type'] ) |
|
| 94 | + isset($WP_Query->query, $WP_Query->query['post_type']) |
|
| 95 | 95 | && $WP_Query->query['post_type'] === 'espresso_events' |
| 96 | - ) || apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ; |
|
| 96 | + ) || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
@@ -102,17 +102,17 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @param \WP_Query $WP_Query |
| 104 | 104 | */ |
| 105 | - public static function filter_query_parts( WP_Query $WP_Query ) { |
|
| 105 | + public static function filter_query_parts(WP_Query $WP_Query) { |
|
| 106 | 106 | // ONLY add our filters if this isn't the main wp_query, |
| 107 | 107 | // because if this is the main wp_query we already have |
| 108 | 108 | // our cpt strategies take care of adding things in. |
| 109 | - if ( $WP_Query instanceof WP_Query && ! $WP_Query->is_main_query() ) { |
|
| 109 | + if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) { |
|
| 110 | 110 | // build event list query |
| 111 | - add_filter( 'posts_fields', array( 'EEH_Event_Query', 'posts_fields' ), 10, 2 ); |
|
| 112 | - add_filter( 'posts_join', array( 'EEH_Event_Query', 'posts_join' ), 10, 2 ); |
|
| 113 | - add_filter( 'posts_where', array( 'EEH_Event_Query', 'posts_where' ), 10, 2 ); |
|
| 114 | - add_filter( 'posts_orderby', array( 'EEH_Event_Query', 'posts_orderby' ), 10, 2 ); |
|
| 115 | - add_filter( 'posts_clauses_request', array( 'EEH_Event_Query', 'posts_clauses' ), 10, 2 ); |
|
| 111 | + add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2); |
|
| 112 | + add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2); |
|
| 113 | + add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2); |
|
| 114 | + add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2); |
|
| 115 | + add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | $sort = 'ASC' |
| 136 | 136 | ) { |
| 137 | 137 | self::$_query_params = array(); |
| 138 | - EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month( $month ); |
|
| 139 | - EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug( $category ); |
|
| 140 | - EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired( $show_expired ); |
|
| 141 | - EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby( $orderby ); |
|
| 142 | - EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort( $sort ); |
|
| 138 | + EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month($month); |
|
| 139 | + EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug($category); |
|
| 140 | + EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired); |
|
| 141 | + EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby($orderby); |
|
| 142 | + EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort($sort); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param string $month |
| 151 | 151 | * @return string |
| 152 | 152 | */ |
| 153 | - private static function _display_month( $month = '' ) { |
|
| 153 | + private static function _display_month($month = '') { |
|
| 154 | 154 | return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month)); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @param string $category |
| 163 | 163 | * @return string |
| 164 | 164 | */ |
| 165 | - private static function _event_category_slug( $category = '' ) { |
|
| 165 | + private static function _event_category_slug($category = '') { |
|
| 166 | 166 | return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category)); |
| 167 | 167 | } |
| 168 | 168 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @param bool $show_expired |
| 175 | 175 | * @return boolean |
| 176 | 176 | */ |
| 177 | - private static function _show_expired( $show_expired = false ) { |
|
| 177 | + private static function _show_expired($show_expired = false) { |
|
| 178 | 178 | // override default expired option if set via filter |
| 179 | 179 | return filter_var( |
| 180 | 180 | EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired), |
@@ -190,13 +190,13 @@ discard block |
||
| 190 | 190 | * @param string $orderby |
| 191 | 191 | * @return array |
| 192 | 192 | */ |
| 193 | - private static function _orderby( $orderby = 'start_date' ) { |
|
| 193 | + private static function _orderby($orderby = 'start_date') { |
|
| 194 | 194 | $event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby); |
| 195 | - $event_query_orderby = is_array( $event_query_orderby ) |
|
| 195 | + $event_query_orderby = is_array($event_query_orderby) |
|
| 196 | 196 | ? $event_query_orderby |
| 197 | - : explode( ',', $event_query_orderby ); |
|
| 198 | - $event_query_orderby = array_map( 'trim', $event_query_orderby ); |
|
| 199 | - $event_query_orderby = array_map( 'sanitize_text_field', $event_query_orderby ); |
|
| 197 | + : explode(',', $event_query_orderby); |
|
| 198 | + $event_query_orderby = array_map('trim', $event_query_orderby); |
|
| 199 | + $event_query_orderby = array_map('sanitize_text_field', $event_query_orderby); |
|
| 200 | 200 | return $event_query_orderby; |
| 201 | 201 | } |
| 202 | 202 | |
@@ -208,10 +208,10 @@ discard block |
||
| 208 | 208 | * @param string $sort |
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | - private static function _sort( $sort = 'ASC' ) { |
|
| 211 | + private static function _sort($sort = 'ASC') { |
|
| 212 | 212 | $sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort); |
| 213 | - return in_array( $sort, array( 'ASC', 'asc', 'DESC', 'desc' ), true) |
|
| 214 | - ? strtoupper( $sort ) |
|
| 213 | + return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
|
| 214 | + ? strtoupper($sort) |
|
| 215 | 215 | : 'ASC'; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -225,10 +225,10 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @return array array of clauses |
| 227 | 227 | */ |
| 228 | - public static function posts_clauses( $clauses, WP_Query $wp_query ) { |
|
| 229 | - if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
|
| 228 | + public static function posts_clauses($clauses, WP_Query $wp_query) { |
|
| 229 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
| 230 | 230 | global $wpdb; |
| 231 | - $clauses['groupby'] = $wpdb->posts . '.ID '; |
|
| 231 | + $clauses['groupby'] = $wpdb->posts.'.ID '; |
|
| 232 | 232 | } |
| 233 | 233 | return $clauses; |
| 234 | 234 | } |
@@ -243,10 +243,10 @@ discard block |
||
| 243 | 243 | * @return string |
| 244 | 244 | * @throws \EE_Error |
| 245 | 245 | */ |
| 246 | - public static function posts_fields( $SQL, WP_Query $wp_query ) { |
|
| 247 | - if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
|
| 246 | + public static function posts_fields($SQL, WP_Query $wp_query) { |
|
| 247 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
| 248 | 248 | // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
| 249 | - $SQL .= EEH_Event_Query::posts_fields_sql_for_orderby( EEH_Event_Query::$_event_query_orderby ); |
|
| 249 | + $SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby); |
|
| 250 | 250 | } |
| 251 | 251 | return $SQL; |
| 252 | 252 | } |
@@ -260,29 +260,29 @@ discard block |
||
| 260 | 260 | * @return string |
| 261 | 261 | * @throws \EE_Error |
| 262 | 262 | */ |
| 263 | - public static function posts_fields_sql_for_orderby( $orderby_params = array() ) { |
|
| 264 | - $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ' ; |
|
| 265 | - foreach( (array)$orderby_params as $orderby ) { |
|
| 266 | - switch ( $orderby ) { |
|
| 263 | + public static function posts_fields_sql_for_orderby($orderby_params = array()) { |
|
| 264 | + $SQL = ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date '; |
|
| 265 | + foreach ((array) $orderby_params as $orderby) { |
|
| 266 | + switch ($orderby) { |
|
| 267 | 267 | |
| 268 | 268 | case 'ticket_start' : |
| 269 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date' ; |
|
| 269 | + $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_start_date'; |
|
| 270 | 270 | break; |
| 271 | 271 | |
| 272 | 272 | case 'ticket_end' : |
| 273 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date' ; |
|
| 273 | + $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_end_date'; |
|
| 274 | 274 | break; |
| 275 | 275 | |
| 276 | 276 | case 'venue_title' : |
| 277 | - $SQL .= ', Venue.post_title AS venue_title' ; |
|
| 277 | + $SQL .= ', Venue.post_title AS venue_title'; |
|
| 278 | 278 | break; |
| 279 | 279 | |
| 280 | 280 | case 'city' : |
| 281 | - $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city' ; |
|
| 281 | + $SQL .= ', '.EEM_Venue::instance()->second_table().'.VNU_city'; |
|
| 282 | 282 | break; |
| 283 | 283 | |
| 284 | 284 | case 'state' : |
| 285 | - $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name' ; |
|
| 285 | + $SQL .= ', '.EEM_State::instance()->table().'.STA_name'; |
|
| 286 | 286 | break; |
| 287 | 287 | |
| 288 | 288 | } |
@@ -300,12 +300,12 @@ discard block |
||
| 300 | 300 | * @return string |
| 301 | 301 | * @throws \EE_Error |
| 302 | 302 | */ |
| 303 | - public static function posts_join( $SQL = '', WP_Query $wp_query ) { |
|
| 304 | - if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
|
| 303 | + public static function posts_join($SQL = '', WP_Query $wp_query) { |
|
| 304 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
| 305 | 305 | // Category |
| 306 | - $SQL = EEH_Event_Query::posts_join_sql_for_show_expired( $SQL, EEH_Event_Query::$_event_query_show_expired ); |
|
| 307 | - $SQL = EEH_Event_Query::posts_join_sql_for_terms( $SQL, EEH_Event_Query::$_event_query_category ); |
|
| 308 | - $SQL = EEH_Event_Query::posts_join_for_orderby( $SQL, EEH_Event_Query::$_event_query_orderby ); |
|
| 306 | + $SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired); |
|
| 307 | + $SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category); |
|
| 308 | + $SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby); |
|
| 309 | 309 | } |
| 310 | 310 | return $SQL; |
| 311 | 311 | } |
@@ -320,13 +320,13 @@ discard block |
||
| 320 | 320 | * @return string |
| 321 | 321 | * @throws \EE_Error |
| 322 | 322 | */ |
| 323 | - public static function posts_join_sql_for_show_expired( $SQL = '', $show_expired = FALSE ) { |
|
| 324 | - if ( ! $show_expired ) { |
|
| 325 | - $join = EEM_Event::instance()->table() . '.ID = '; |
|
| 326 | - $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
| 323 | + public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = FALSE) { |
|
| 324 | + if ( ! $show_expired) { |
|
| 325 | + $join = EEM_Event::instance()->table().'.ID = '; |
|
| 326 | + $join .= EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name(); |
|
| 327 | 327 | // don't add if this is already in the SQL |
| 328 | - if ( strpos( $SQL, $join ) === FALSE ) { |
|
| 329 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) '; |
|
| 328 | + if (strpos($SQL, $join) === FALSE) { |
|
| 329 | + $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' ) '; |
|
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | return $SQL; |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | * @param string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet |
| 342 | 342 | * @return string |
| 343 | 343 | */ |
| 344 | - public static function posts_join_sql_for_terms( $SQL = '', $join_terms = '' ) { |
|
| 345 | - if ( ! empty( $join_terms ) ) { |
|
| 344 | + public static function posts_join_sql_for_terms($SQL = '', $join_terms = '') { |
|
| 345 | + if ( ! empty($join_terms)) { |
|
| 346 | 346 | global $wpdb; |
| 347 | 347 | $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
| 348 | 348 | $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
@@ -362,33 +362,33 @@ discard block |
||
| 362 | 362 | * @return string |
| 363 | 363 | * @throws \EE_Error |
| 364 | 364 | */ |
| 365 | - public static function posts_join_for_orderby( $SQL = '', $orderby_params = array() ) { |
|
| 366 | - foreach ( (array)$orderby_params as $orderby ) { |
|
| 367 | - switch ( $orderby ) { |
|
| 365 | + public static function posts_join_for_orderby($SQL = '', $orderby_params = array()) { |
|
| 366 | + foreach ((array) $orderby_params as $orderby) { |
|
| 367 | + switch ($orderby) { |
|
| 368 | 368 | case 'ticket_start' : |
| 369 | 369 | case 'ticket_end' : |
| 370 | 370 | $SQL .= EEH_Event_Query::_posts_join_for_datetime( |
| 371 | 371 | $SQL, |
| 372 | - EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
| 372 | + EEM_Datetime_Ticket::instance()->table().'.'.EEM_Datetime::instance()->primary_key_name() |
|
| 373 | 373 | ); |
| 374 | - $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table(); |
|
| 374 | + $SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table(); |
|
| 375 | 375 | $SQL .= ' ON ('; |
| 376 | - $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
| 376 | + $SQL .= EEM_Datetime_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name(); |
|
| 377 | 377 | $SQL .= ' = '; |
| 378 | - $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
| 379 | - $SQL .= ' )'; |
|
| 378 | + $SQL .= EEM_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name(); |
|
| 379 | + $SQL .= ' )'; |
|
| 380 | 380 | break; |
| 381 | 381 | case 'venue_title' : |
| 382 | 382 | case 'city' : |
| 383 | - $SQL .= EEH_Event_Query::_posts_join_for_event_venue( $SQL ); |
|
| 383 | + $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
| 384 | 384 | break; |
| 385 | 385 | case 'state' : |
| 386 | - $SQL .= EEH_Event_Query::_posts_join_for_event_venue( $SQL ); |
|
| 387 | - $SQL .= EEH_Event_Query::_posts_join_for_venue_state( $SQL ); |
|
| 386 | + $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
| 387 | + $SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL); |
|
| 388 | 388 | break; |
| 389 | 389 | case 'start_date' : |
| 390 | 390 | default : |
| 391 | - $SQL .= EEH_Event_Query::_posts_join_for_datetime( $SQL, EEM_Event::instance()->table() . '.ID' ); |
|
| 391 | + $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table().'.ID'); |
|
| 392 | 392 | break; |
| 393 | 393 | |
| 394 | 394 | } |
@@ -406,11 +406,11 @@ discard block |
||
| 406 | 406 | * @return string |
| 407 | 407 | * @throws \EE_Error |
| 408 | 408 | */ |
| 409 | - protected static function _posts_join_for_datetime( $SQL = '', $join = '' ) { |
|
| 410 | - if ( ! empty( $join )) { |
|
| 411 | - $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
| 412 | - if ( strpos( $SQL, $join ) === FALSE ) { |
|
| 413 | - return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )'; |
|
| 409 | + protected static function _posts_join_for_datetime($SQL = '', $join = '') { |
|
| 410 | + if ( ! empty($join)) { |
|
| 411 | + $join .= ' = '.EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name(); |
|
| 412 | + if (strpos($SQL, $join) === FALSE) { |
|
| 413 | + return ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' )'; |
|
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | 416 | return ''; |
@@ -425,14 +425,14 @@ discard block |
||
| 425 | 425 | * @return string |
| 426 | 426 | * @throws \EE_Error |
| 427 | 427 | */ |
| 428 | - protected static function _posts_join_for_event_venue( $SQL = '' ) { |
|
| 428 | + protected static function _posts_join_for_event_venue($SQL = '') { |
|
| 429 | 429 | // Event Venue table name |
| 430 | 430 | $event_venue_table = EEM_Event_Venue::instance()->table(); |
| 431 | 431 | // generate conditions for: Event <=> Event Venue JOIN clause |
| 432 | - $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = '; |
|
| 433 | - $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name(); |
|
| 432 | + $event_to_event_venue_join = EEM_Event::instance()->table().'.ID = '; |
|
| 433 | + $event_to_event_venue_join .= $event_venue_table.'.'.EEM_Event::instance()->primary_key_name(); |
|
| 434 | 434 | // don't add joins if they have already been added |
| 435 | - if ( strpos( $SQL, $event_to_event_venue_join ) === FALSE ) { |
|
| 435 | + if (strpos($SQL, $event_to_event_venue_join) === FALSE) { |
|
| 436 | 436 | // Venue table name |
| 437 | 437 | $venue_table = EEM_Venue::instance()->table(); |
| 438 | 438 | // Venue table pk |
@@ -445,10 +445,10 @@ discard block |
||
| 445 | 445 | $venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )"; |
| 446 | 446 | // generate JOIN clause for: Venue <=> Venue Meta |
| 447 | 447 | $venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )"; |
| 448 | - unset( $event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table ); |
|
| 448 | + unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table); |
|
| 449 | 449 | return $venue_SQL; |
| 450 | 450 | } |
| 451 | - unset( $event_venue_table, $event_to_event_venue_join ); |
|
| 451 | + unset($event_venue_table, $event_to_event_venue_join); |
|
| 452 | 452 | return ''; |
| 453 | 453 | } |
| 454 | 454 | |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * @return string |
| 462 | 462 | * @throws \EE_Error |
| 463 | 463 | */ |
| 464 | - protected static function _posts_join_for_venue_state( $SQL = '' ) { |
|
| 464 | + protected static function _posts_join_for_venue_state($SQL = '') { |
|
| 465 | 465 | // Venue Meta table name |
| 466 | 466 | $venue_meta_table = EEM_Venue::instance()->second_table(); |
| 467 | 467 | // State table name |
@@ -469,16 +469,16 @@ discard block |
||
| 469 | 469 | // State table pk |
| 470 | 470 | $state_table_pk = EEM_State::instance()->primary_key_name(); |
| 471 | 471 | // verify vars |
| 472 | - if ( $venue_meta_table && $state_table && $state_table_pk ) { |
|
| 472 | + if ($venue_meta_table && $state_table && $state_table_pk) { |
|
| 473 | 473 | // like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID |
| 474 | 474 | $join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk"; |
| 475 | 475 | // don't add join if it has already been added |
| 476 | - if ( strpos( $SQL, $join ) === FALSE ) { |
|
| 477 | - unset( $state_table_pk, $venue_meta_table, $venue_table_pk ); |
|
| 476 | + if (strpos($SQL, $join) === FALSE) { |
|
| 477 | + unset($state_table_pk, $venue_meta_table, $venue_table_pk); |
|
| 478 | 478 | return " LEFT JOIN $state_table ON ( $join )"; |
| 479 | 479 | } |
| 480 | 480 | } |
| 481 | - unset( $join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk ); |
|
| 481 | + unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk); |
|
| 482 | 482 | return ''; |
| 483 | 483 | } |
| 484 | 484 | |
@@ -492,14 +492,14 @@ discard block |
||
| 492 | 492 | * @return string |
| 493 | 493 | * @throws \EE_Error |
| 494 | 494 | */ |
| 495 | - public static function posts_where( $SQL = '', WP_Query $wp_query ) { |
|
| 496 | - if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
|
| 495 | + public static function posts_where($SQL = '', WP_Query $wp_query) { |
|
| 496 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
| 497 | 497 | // Show Expired ? |
| 498 | - $SQL .= EEH_Event_Query::posts_where_sql_for_show_expired( EEH_Event_Query::$_event_query_show_expired ); |
|
| 498 | + $SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired); |
|
| 499 | 499 | // Category |
| 500 | - $SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug( EEH_Event_Query::$_event_query_category ); |
|
| 500 | + $SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category); |
|
| 501 | 501 | // Start Date |
| 502 | - $SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month( EEH_Event_Query::$_event_query_month ); |
|
| 502 | + $SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month); |
|
| 503 | 503 | } |
| 504 | 504 | return $SQL; |
| 505 | 505 | } |
@@ -513,9 +513,9 @@ discard block |
||
| 513 | 513 | * @return string |
| 514 | 514 | * @throws \EE_Error |
| 515 | 515 | */ |
| 516 | - public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) { |
|
| 516 | + public static function posts_where_sql_for_show_expired($show_expired = FALSE) { |
|
| 517 | 517 | return ! $show_expired |
| 518 | - ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' ' |
|
| 518 | + ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > \''.current_time('mysql', TRUE).'\' ' |
|
| 519 | 519 | : ''; |
| 520 | 520 | } |
| 521 | 521 | |
@@ -527,10 +527,10 @@ discard block |
||
| 527 | 527 | * @param boolean $event_category_slug |
| 528 | 528 | * @return string |
| 529 | 529 | */ |
| 530 | - public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) { |
|
| 530 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) { |
|
| 531 | 531 | global $wpdb; |
| 532 | 532 | $event_category_slug = esc_sql($event_category_slug); |
| 533 | - return ! empty( $event_category_slug ) |
|
| 533 | + return ! empty($event_category_slug) |
|
| 534 | 534 | ? " AND {$wpdb->terms}.slug = '{$event_category_slug}' " |
| 535 | 535 | : ''; |
| 536 | 536 | } |
@@ -544,16 +544,16 @@ discard block |
||
| 544 | 544 | * @return string |
| 545 | 545 | * @throws \EE_Error |
| 546 | 546 | */ |
| 547 | - public static function posts_where_sql_for_event_list_month( $month = NULL ) { |
|
| 547 | + public static function posts_where_sql_for_event_list_month($month = NULL) { |
|
| 548 | 548 | $SQL = ''; |
| 549 | - if ( ! empty( $month ) ) { |
|
| 549 | + if ( ! empty($month)) { |
|
| 550 | 550 | $datetime_table = EEM_Datetime::instance()->table(); |
| 551 | 551 | // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
| 552 | 552 | $SQL = " AND {$datetime_table}.DTT_EVT_start <= '"; |
| 553 | - $SQL .= date( 'Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'"; |
|
| 553 | + $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month))."'"; |
|
| 554 | 554 | // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
| 555 | 555 | $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '"; |
| 556 | - $SQL .= date( 'Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' "; |
|
| 556 | + $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month))."' "; |
|
| 557 | 557 | } |
| 558 | 558 | return $SQL; |
| 559 | 559 | } |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | * @return string |
| 569 | 569 | * @throws \EE_Error |
| 570 | 570 | */ |
| 571 | - public static function posts_orderby( $SQL = '', WP_Query $wp_query ) { |
|
| 572 | - if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
|
| 571 | + public static function posts_orderby($SQL = '', WP_Query $wp_query) { |
|
| 572 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
| 573 | 573 | $SQL = EEH_Event_Query::posts_orderby_sql( |
| 574 | 574 | EEH_Event_Query::$_event_query_orderby, |
| 575 | 575 | EEH_Event_Query::$_event_query_sort |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | * @return string |
| 603 | 603 | * @throws \EE_Error |
| 604 | 604 | */ |
| 605 | - public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) { |
|
| 605 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') { |
|
| 606 | 606 | global $wpdb; |
| 607 | 607 | $SQL = ''; |
| 608 | 608 | $counter = 0; |
@@ -610,58 +610,58 @@ discard block |
||
| 610 | 610 | ? strtoupper($sort) |
| 611 | 611 | : 'ASC'; |
| 612 | 612 | //make sure 'orderby' is set in query params |
| 613 | - if ( ! isset( self::$_query_params['orderby'] )) { |
|
| 613 | + if ( ! isset(self::$_query_params['orderby'])) { |
|
| 614 | 614 | self::$_query_params['orderby'] = array(); |
| 615 | 615 | } |
| 616 | 616 | // loop thru $orderby_params (type cast as array) |
| 617 | - foreach ( (array)$orderby_params as $orderby ) { |
|
| 617 | + foreach ((array) $orderby_params as $orderby) { |
|
| 618 | 618 | // check if we have already added this param |
| 619 | - if ( isset( self::$_query_params['orderby'][ $orderby ] )) { |
|
| 619 | + if (isset(self::$_query_params['orderby'][$orderby])) { |
|
| 620 | 620 | // if so then remove from the $orderby_params so that the count() method below is accurate |
| 621 | - unset( $orderby_params[ $orderby ] ); |
|
| 621 | + unset($orderby_params[$orderby]); |
|
| 622 | 622 | // then bump ahead to the next param |
| 623 | 623 | continue; |
| 624 | 624 | } |
| 625 | 625 | // this will ad a comma depending on whether this is the first or last param |
| 626 | - $glue = $counter === 0 || $counter === count( $orderby_params ) ? ' ' : ', '; |
|
| 626 | + $glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', '; |
|
| 627 | 627 | // ok what's we dealing with? |
| 628 | - switch ( $orderby ) { |
|
| 628 | + switch ($orderby) { |
|
| 629 | 629 | case 'id' : |
| 630 | 630 | case 'ID' : |
| 631 | - $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
| 631 | + $SQL .= $glue.$wpdb->posts.'.ID '.$sort; |
|
| 632 | 632 | break; |
| 633 | 633 | case 'end_date' : |
| 634 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
| 634 | + $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort; |
|
| 635 | 635 | break; |
| 636 | 636 | case 'event_name' : |
| 637 | - $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
| 637 | + $SQL .= $glue.$wpdb->posts.'.post_title '.$sort; |
|
| 638 | 638 | break; |
| 639 | 639 | case 'category_slug' : |
| 640 | - $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
| 640 | + $SQL .= $glue.$wpdb->terms.'.slug '.$sort; |
|
| 641 | 641 | break; |
| 642 | 642 | case 'ticket_start' : |
| 643 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
| 643 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort; |
|
| 644 | 644 | break; |
| 645 | 645 | case 'ticket_end' : |
| 646 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
| 646 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort; |
|
| 647 | 647 | break; |
| 648 | 648 | case 'venue_title' : |
| 649 | - $SQL .= $glue . 'venue_title ' . $sort; |
|
| 649 | + $SQL .= $glue.'venue_title '.$sort; |
|
| 650 | 650 | break; |
| 651 | 651 | case 'city' : |
| 652 | - $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
| 652 | + $SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort; |
|
| 653 | 653 | break; |
| 654 | 654 | case 'state' : |
| 655 | - $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
| 655 | + $SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort; |
|
| 656 | 656 | break; |
| 657 | 657 | case 'start_date' : |
| 658 | 658 | default : |
| 659 | - $SQL .= $glue . ' event_start_date ' . $sort; |
|
| 659 | + $SQL .= $glue.' event_start_date '.$sort; |
|
| 660 | 660 | break; |
| 661 | 661 | } |
| 662 | 662 | // add to array of orderby params that have been added |
| 663 | - self::$_query_params['orderby'][ $orderby ] = TRUE; |
|
| 664 | - $counter ++; |
|
| 663 | + self::$_query_params['orderby'][$orderby] = TRUE; |
|
| 664 | + $counter++; |
|
| 665 | 665 | } |
| 666 | 666 | return $SQL; |
| 667 | 667 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param WP $WP |
| 43 | 43 | * @return void |
| 44 | 44 | */ |
| 45 | - public abstract function run( WP $WP ); |
|
| 45 | + public abstract function run(WP $WP); |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param array $attributes |
| 55 | 55 | * @return mixed |
| 56 | 56 | */ |
| 57 | - public abstract function process_shortcode( $attributes = array() ); |
|
| 57 | + public abstract function process_shortcode($attributes = array()); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | * @param string $shortcode_class |
| 66 | 66 | * @return \EES_Shortcode |
| 67 | 67 | */ |
| 68 | - final public static function instance( $shortcode_class = null ) { |
|
| 69 | - $shortcode_class = ! empty( $shortcode_class ) ? $shortcode_class : get_called_class(); |
|
| 70 | - if ( $shortcode_class === 'EES_Shortcode' || empty( $shortcode_class )) { |
|
| 68 | + final public static function instance($shortcode_class = null) { |
|
| 69 | + $shortcode_class = ! empty($shortcode_class) ? $shortcode_class : get_called_class(); |
|
| 70 | + if ($shortcode_class === 'EES_Shortcode' || empty($shortcode_class)) { |
|
| 71 | 71 | return null; |
| 72 | 72 | } |
| 73 | - $shortcode = str_replace( 'EES_', '', strtoupper( $shortcode_class )); |
|
| 74 | - $shortcode_obj = isset( EE_Registry::instance()->shortcodes->{$shortcode} ) |
|
| 73 | + $shortcode = str_replace('EES_', '', strtoupper($shortcode_class)); |
|
| 74 | + $shortcode_obj = isset(EE_Registry::instance()->shortcodes->{$shortcode} ) |
|
| 75 | 75 | ? EE_Registry::instance()->shortcodes->{$shortcode} |
| 76 | 76 | : null; |
| 77 | 77 | return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self' |
@@ -90,23 +90,23 @@ discard block |
||
| 90 | 90 | * @param $attributes |
| 91 | 91 | * @return mixed |
| 92 | 92 | */ |
| 93 | - final public static function fallback_shortcode_processor( $attributes ) { |
|
| 94 | - if ( EE_Maintenance_Mode::disable_frontend_for_maintenance() ) { |
|
| 93 | + final public static function fallback_shortcode_processor($attributes) { |
|
| 94 | + if (EE_Maintenance_Mode::disable_frontend_for_maintenance()) { |
|
| 95 | 95 | return null; |
| 96 | 96 | } |
| 97 | 97 | // what shortcode was actually parsed ? |
| 98 | 98 | $shortcode_class = get_called_class(); |
| 99 | 99 | // notify rest of system that fallback processor was triggered |
| 100 | - add_filter( 'FHEE__fallback_shortcode_processor__' . $shortcode_class, '__return_true' ); |
|
| 100 | + add_filter('FHEE__fallback_shortcode_processor__'.$shortcode_class, '__return_true'); |
|
| 101 | 101 | // get instance of actual shortcode |
| 102 | - $shortcode_obj = self::instance( $shortcode_class ); |
|
| 102 | + $shortcode_obj = self::instance($shortcode_class); |
|
| 103 | 103 | // verify class |
| 104 | - if ( $shortcode_obj instanceof EES_Shortcode ) { |
|
| 104 | + if ($shortcode_obj instanceof EES_Shortcode) { |
|
| 105 | 105 | global $wp; |
| 106 | - $shortcode_obj->run( $wp ); |
|
| 106 | + $shortcode_obj->run($wp); |
|
| 107 | 107 | // set attributes and run the shortcode |
| 108 | - $shortcode_obj->_attributes = (array)$attributes; |
|
| 109 | - return $shortcode_obj->process_shortcode( $shortcode_obj->_attributes ); |
|
| 108 | + $shortcode_obj->_attributes = (array) $attributes; |
|
| 109 | + return $shortcode_obj->process_shortcode($shortcode_obj->_attributes); |
|
| 110 | 110 | } else { |
| 111 | 111 | return null; |
| 112 | 112 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param $attributes |
| 123 | 123 | * @return string |
| 124 | 124 | */ |
| 125 | - final public static function invalid_shortcode_processor( $attributes ) { |
|
| 125 | + final public static function invalid_shortcode_processor($attributes) { |
|
| 126 | 126 | return ''; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -133,11 +133,11 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | final public function __construct() { |
| 135 | 135 | // get classname, remove EES_prefix, and convert to UPPERCASE |
| 136 | - $shortcode = strtoupper( str_replace( 'EES_', '', get_class( $this ))); |
|
| 136 | + $shortcode = strtoupper(str_replace('EES_', '', get_class($this))); |
|
| 137 | 137 | // assign shortcode to the preferred callback, which overwrites the "fallback shortcode processor" assigned earlier |
| 138 | - add_shortcode( $shortcode, array( $this, 'process_shortcode' )); |
|
| 138 | + add_shortcode($shortcode, array($this, 'process_shortcode')); |
|
| 139 | 139 | // make sure system knows this is an EE page |
| 140 | - EE_Registry::instance()->REQ->set_espresso_page( TRUE ); |
|
| 140 | + EE_Registry::instance()->REQ->set_espresso_page(TRUE); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
@@ -151,12 +151,12 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | foreach ($attributes as $key => $value) { |
| 153 | 153 | // is a custom sanitization callback specified ? |
| 154 | - if ( isset($custom_sanitization[$key])) { |
|
| 154 | + if (isset($custom_sanitization[$key])) { |
|
| 155 | 155 | $callback = $custom_sanitization[$key]; |
| 156 | 156 | if ($callback === 'skip_sanitization') { |
| 157 | 157 | $attributes[$key] = $value; |
| 158 | 158 | continue; |
| 159 | - } else if (function_exists($callback)){ |
|
| 159 | + } else if (function_exists($callback)) { |
|
| 160 | 160 | $attributes[$key] = $callback($value); |
| 161 | 161 | continue; |
| 162 | 162 | } |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | $shortcode = str_replace( 'EES_', '', strtoupper( $shortcode_class )); |
| 74 | 74 | $shortcode_obj = isset( EE_Registry::instance()->shortcodes->{$shortcode} ) |
| 75 | - ? EE_Registry::instance()->shortcodes->{$shortcode} |
|
| 76 | - : null; |
|
| 75 | + ? EE_Registry::instance()->shortcodes->{$shortcode} |
|
| 76 | + : null; |
|
| 77 | 77 | return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self' |
| 78 | - ? $shortcode_obj |
|
| 79 | - : new $shortcode_class(); |
|
| 78 | + ? $shortcode_obj |
|
| 79 | + : new $shortcode_class(); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -142,59 +142,59 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | |
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Performs basic sanitization on shortcode attributes |
|
| 147 | - * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
| 148 | - * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
| 149 | - * This can be overridden by supplying an array for the $custom_sanitization param, |
|
| 150 | - * where keys match keys in your attributes array, |
|
| 151 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
| 152 | - * So for example, if you had an integer attribute named "event_id" |
|
| 153 | - * that you wanted to be sanitized using absint(), |
|
| 154 | - * then you would pass the following for your $custom_sanitization array: |
|
| 155 | - * array('event_id' => 'absint') |
|
| 156 | - * all other attributes would be sanitized using the defaults in the switch statement below |
|
| 157 | - * |
|
| 158 | - * @param array $attributes |
|
| 159 | - * @param array $custom_sanitization |
|
| 160 | - * @return array |
|
| 161 | - */ |
|
| 162 | - public static function sanitize_attributes(array $attributes, $custom_sanitization = array()) |
|
| 163 | - { |
|
| 164 | - foreach ($attributes as $key => $value) { |
|
| 165 | - // is a custom sanitization callback specified ? |
|
| 166 | - if ( isset($custom_sanitization[$key])) { |
|
| 167 | - $callback = $custom_sanitization[$key]; |
|
| 168 | - if ($callback === 'skip_sanitization') { |
|
| 169 | - $attributes[$key] = $value; |
|
| 170 | - continue; |
|
| 171 | - } else if (function_exists($callback)){ |
|
| 172 | - $attributes[$key] = $callback($value); |
|
| 173 | - continue; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - switch (true) { |
|
| 177 | - case $value === null : |
|
| 178 | - case is_int($value) : |
|
| 179 | - case is_float($value) : |
|
| 180 | - // typical booleans |
|
| 181 | - case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
| 182 | - $attributes[$key] = $value; |
|
| 183 | - break; |
|
| 184 | - case is_string($value) : |
|
| 185 | - $attributes[$key] = sanitize_text_field($value); |
|
| 186 | - break; |
|
| 187 | - case is_array($value) : |
|
| 188 | - $attributes[$key] = \EES_Shortcode::sanitize_attributes($value); |
|
| 189 | - break; |
|
| 190 | - default : |
|
| 191 | - // only remaining data types are Object and Resource |
|
| 192 | - // which are not allowed as shortcode attributes |
|
| 193 | - $attributes[$key] = null; |
|
| 194 | - break; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - return $attributes; |
|
| 145 | + /** |
|
| 146 | + * Performs basic sanitization on shortcode attributes |
|
| 147 | + * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
| 148 | + * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
| 149 | + * This can be overridden by supplying an array for the $custom_sanitization param, |
|
| 150 | + * where keys match keys in your attributes array, |
|
| 151 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
| 152 | + * So for example, if you had an integer attribute named "event_id" |
|
| 153 | + * that you wanted to be sanitized using absint(), |
|
| 154 | + * then you would pass the following for your $custom_sanitization array: |
|
| 155 | + * array('event_id' => 'absint') |
|
| 156 | + * all other attributes would be sanitized using the defaults in the switch statement below |
|
| 157 | + * |
|
| 158 | + * @param array $attributes |
|
| 159 | + * @param array $custom_sanitization |
|
| 160 | + * @return array |
|
| 161 | + */ |
|
| 162 | + public static function sanitize_attributes(array $attributes, $custom_sanitization = array()) |
|
| 163 | + { |
|
| 164 | + foreach ($attributes as $key => $value) { |
|
| 165 | + // is a custom sanitization callback specified ? |
|
| 166 | + if ( isset($custom_sanitization[$key])) { |
|
| 167 | + $callback = $custom_sanitization[$key]; |
|
| 168 | + if ($callback === 'skip_sanitization') { |
|
| 169 | + $attributes[$key] = $value; |
|
| 170 | + continue; |
|
| 171 | + } else if (function_exists($callback)){ |
|
| 172 | + $attributes[$key] = $callback($value); |
|
| 173 | + continue; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + switch (true) { |
|
| 177 | + case $value === null : |
|
| 178 | + case is_int($value) : |
|
| 179 | + case is_float($value) : |
|
| 180 | + // typical booleans |
|
| 181 | + case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
| 182 | + $attributes[$key] = $value; |
|
| 183 | + break; |
|
| 184 | + case is_string($value) : |
|
| 185 | + $attributes[$key] = sanitize_text_field($value); |
|
| 186 | + break; |
|
| 187 | + case is_array($value) : |
|
| 188 | + $attributes[$key] = \EES_Shortcode::sanitize_attributes($value); |
|
| 189 | + break; |
|
| 190 | + default : |
|
| 191 | + // only remaining data types are Object and Resource |
|
| 192 | + // which are not allowed as shortcode attributes |
|
| 193 | + $attributes[$key] = null; |
|
| 194 | + break; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + return $attributes; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -81,7 +81,7 @@ |
||
| 81 | 81 | /** |
| 82 | 82 | * Checks if that value is the one selected |
| 83 | 83 | * @param string|int $value unnormalized value option (string) |
| 84 | - * @return string |
|
| 84 | + * @return boolean |
|
| 85 | 85 | */ |
| 86 | 86 | protected function _check_if_option_selected( $value ){ |
| 87 | 87 | return $this->_input->raw_value() === $value ? TRUE : FALSE; |
@@ -11,49 +11,49 @@ discard block |
||
| 11 | 11 | * @since $VID:$ |
| 12 | 12 | * |
| 13 | 13 | */ |
| 14 | -class EE_Select_Display_Strategy extends EE_Display_Strategy_Base{ |
|
| 14 | +class EE_Select_Display_Strategy extends EE_Display_Strategy_Base { |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * |
| 18 | 18 | * @throws EE_Error |
| 19 | 19 | * @return string of html to display the field |
| 20 | 20 | */ |
| 21 | - function display(){ |
|
| 22 | - if( ! $this->_input instanceof EE_Form_Input_With_Options_Base){ |
|
| 23 | - throw new EE_Error( sprintf( __( 'Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso' ))); |
|
| 21 | + function display() { |
|
| 22 | + if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
| 23 | + throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - $html = EEH_HTML::nl( 0, 'select' ); |
|
| 26 | + $html = EEH_HTML::nl(0, 'select'); |
|
| 27 | 27 | $html .= '<select'; |
| 28 | - $html .= ' id="' . $this->_input->html_id() . '"'; |
|
| 29 | - $html .= ' name="' . $this->_input->html_name() . '"'; |
|
| 30 | - $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); |
|
| 31 | - $html .= ' class="' . $class . '"'; |
|
| 28 | + $html .= ' id="'.$this->_input->html_id().'"'; |
|
| 29 | + $html .= ' name="'.$this->_input->html_name().'"'; |
|
| 30 | + $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class(); |
|
| 31 | + $html .= ' class="'.$class.'"'; |
|
| 32 | 32 | // add html5 required |
| 33 | 33 | $html .= $this->_input->required() ? ' required' : ''; |
| 34 | - $html .= ' style="' . $this->_input->html_style() . '"'; |
|
| 35 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
| 34 | + $html .= ' style="'.$this->_input->html_style().'"'; |
|
| 35 | + $html .= ' '.$this->_input->other_html_attributes(); |
|
| 36 | 36 | $html .= '>'; |
| 37 | 37 | |
| 38 | - if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) { |
|
| 39 | - EEH_HTML::indent( 1, 'optgroup' ); |
|
| 40 | - foreach( $this->_input->options() as $opt_group_label => $opt_group ){ |
|
| 38 | + if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
| 39 | + EEH_HTML::indent(1, 'optgroup'); |
|
| 40 | + foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
| 41 | 41 | if ( ! empty($opt_group_label)) { |
| 42 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
| 42 | + $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">'; |
|
| 43 | 43 | } |
| 44 | - EEH_HTML::indent( 1, 'option' ); |
|
| 45 | - $html .= $this->_display_options( $opt_group ); |
|
| 44 | + EEH_HTML::indent(1, 'option'); |
|
| 45 | + $html .= $this->_display_options($opt_group); |
|
| 46 | 46 | EEH_HTML::indent( -1, 'option' ); |
| 47 | 47 | if ( ! empty($opt_group_label)) { |
| 48 | - $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>'; |
|
| 48 | + $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>'; |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | EEH_HTML::indent( -1, 'optgroup' ); |
| 52 | 52 | } else { |
| 53 | - $html.=$this->_display_options( $this->_input->options() ); |
|
| 53 | + $html .= $this->_display_options($this->_input->options()); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $html.= EEH_HTML::nl( 0, 'select' ) . '</select>'; |
|
| 56 | + $html .= EEH_HTML::nl(0, 'select').'</select>'; |
|
| 57 | 57 | return $html; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | * @param array $options |
| 65 | 65 | * @return string |
| 66 | 66 | */ |
| 67 | - protected function _display_options($options){ |
|
| 67 | + protected function _display_options($options) { |
|
| 68 | 68 | $html = ''; |
| 69 | - EEH_HTML::indent( 1, 'option' ); |
|
| 70 | - foreach( $options as $value => $display_text ){ |
|
| 71 | - $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value ); |
|
| 72 | - $selected = $this->_check_if_option_selected( $unnormalized_value ) ? ' selected="selected"' : ''; |
|
| 73 | - $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr( $unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>'; |
|
| 69 | + EEH_HTML::indent(1, 'option'); |
|
| 70 | + foreach ($options as $value => $display_text) { |
|
| 71 | + $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
| 72 | + $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : ''; |
|
| 73 | + $html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>'; |
|
| 74 | 74 | } |
| 75 | 75 | EEH_HTML::indent( -1, 'option' ); |
| 76 | 76 | return $html; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param string|int $value unnormalized value option (string) |
| 84 | 84 | * @return string |
| 85 | 85 | */ |
| 86 | - protected function _check_if_option_selected( $value ){ |
|
| 86 | + protected function _check_if_option_selected($value) { |
|
| 87 | 87 | return $this->_input->raw_value() === $value ? TRUE : FALSE; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -569,11 +569,11 @@ discard block |
||
| 569 | 569 | { |
| 570 | 570 | //style |
| 571 | 571 | //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION ); |
| 572 | - wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'), |
|
| 572 | + wp_register_style('espresso_reg', REG_ASSETS_URL.'espresso_registrations_admin.css', array('ee-admin-css'), |
|
| 573 | 573 | EVENT_ESPRESSO_VERSION); |
| 574 | 574 | wp_enqueue_style('espresso_reg'); |
| 575 | 575 | //script |
| 576 | - wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 576 | + wp_register_script('espresso_reg', REG_ASSETS_URL.'espresso_registrations_admin.js', |
|
| 577 | 577 | array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true); |
| 578 | 578 | wp_enqueue_script('espresso_reg'); |
| 579 | 579 | } |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | public function load_scripts_styles_contact_list() |
| 605 | 605 | { |
| 606 | 606 | wp_deregister_style('espresso_reg'); |
| 607 | - wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'), |
|
| 607 | + wp_register_style('espresso_att', REG_ASSETS_URL.'espresso_attendees_admin.css', array('ee-admin-css'), |
|
| 608 | 608 | EVENT_ESPRESSO_VERSION); |
| 609 | 609 | wp_enqueue_style('espresso_att'); |
| 610 | 610 | } |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | |
| 613 | 613 | public function load_scripts_styles_new_registration() |
| 614 | 614 | { |
| 615 | - wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'), |
|
| 615 | + wp_register_script('ee-spco-for-admin', REG_ASSETS_URL.'spco_for_admin.js', array('underscore', 'jquery'), |
|
| 616 | 616 | EVENT_ESPRESSO_VERSION, true); |
| 617 | 617 | wp_enqueue_script('ee-spco-for-admin'); |
| 618 | 618 | add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
| 723 | 723 | ), |
| 724 | 724 | ); |
| 725 | - $this->_views['trash'] = array( |
|
| 725 | + $this->_views['trash'] = array( |
|
| 726 | 726 | 'slug' => 'trash', |
| 727 | 727 | 'label' => __('Trash', 'event_espresso'), |
| 728 | 728 | 'count' => 0, |
@@ -807,31 +807,31 @@ discard block |
||
| 807 | 807 | } |
| 808 | 808 | $sc_items = array( |
| 809 | 809 | 'approved_status' => array( |
| 810 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 810 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved, |
|
| 811 | 811 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
| 812 | 812 | ), |
| 813 | 813 | 'pending_status' => array( |
| 814 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 814 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment, |
|
| 815 | 815 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
| 816 | 816 | ), |
| 817 | 817 | 'wait_list' => array( |
| 818 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 818 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list, |
|
| 819 | 819 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
| 820 | 820 | ), |
| 821 | 821 | 'incomplete_status' => array( |
| 822 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 822 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete, |
|
| 823 | 823 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'), |
| 824 | 824 | ), |
| 825 | 825 | 'not_approved' => array( |
| 826 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 826 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved, |
|
| 827 | 827 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
| 828 | 828 | ), |
| 829 | 829 | 'declined_status' => array( |
| 830 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 830 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined, |
|
| 831 | 831 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
| 832 | 832 | ), |
| 833 | 833 | 'cancelled_status' => array( |
| 834 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 834 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled, |
|
| 835 | 835 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
| 836 | 836 | ), |
| 837 | 837 | ); |
@@ -852,17 +852,17 @@ discard block |
||
| 852 | 852 | if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations', |
| 853 | 853 | 'espresso_registrations_new_registration', $EVT_ID) |
| 854 | 854 | ) { |
| 855 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant', |
|
| 855 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button('new_registration', 'add-registrant', |
|
| 856 | 856 | array('event_id' => $EVT_ID), 'add-new-h2'); |
| 857 | 857 | } |
| 858 | 858 | $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
| 859 | 859 | if ($event instanceof EE_Event) { |
| 860 | 860 | $this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s', |
| 861 | 861 | 'event_espresso'), '<h3 style="line-height:1.5em;">', |
| 862 | - '<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 862 | + '<br /><a href="'.EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 863 | 863 | 'action' => 'edit', |
| 864 | 864 | 'post' => $event->ID(), |
| 865 | - ), EVENTS_ADMIN_URL) . '"> ' . $event->get('EVT_name') . ' </a> ', '</h3>'); |
|
| 865 | + ), EVENTS_ADMIN_URL).'"> '.$event->get('EVT_name').' </a> ', '</h3>'); |
|
| 866 | 866 | } |
| 867 | 867 | $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
| 868 | 868 | $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
@@ -871,7 +871,7 @@ discard block |
||
| 871 | 871 | $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
| 872 | 872 | $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
| 873 | 873 | $this->_template_args['admin_page_header'] .= $datetime->name(); |
| 874 | - $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 874 | + $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )'; |
|
| 875 | 875 | $this->_template_args['admin_page_header'] .= '</span></h3>'; |
| 876 | 876 | } |
| 877 | 877 | } |
@@ -921,10 +921,10 @@ discard block |
||
| 921 | 921 | $this_month = false, |
| 922 | 922 | $today = false |
| 923 | 923 | ) { |
| 924 | - if( $this_month ) { |
|
| 924 | + if ($this_month) { |
|
| 925 | 925 | $this->_req_data['status'] = 'month'; |
| 926 | 926 | } |
| 927 | - if( $today ) { |
|
| 927 | + if ($today) { |
|
| 928 | 928 | $this->_req_data['status'] = 'today'; |
| 929 | 929 | } |
| 930 | 930 | $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
@@ -995,7 +995,7 @@ discard block |
||
| 995 | 995 | protected function _add_category_id_to_where_conditions(array $request) |
| 996 | 996 | { |
| 997 | 997 | $where = array(); |
| 998 | - if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
| 998 | + if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) { |
|
| 999 | 999 | $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
| 1000 | 1000 | } |
| 1001 | 1001 | return $where; |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | if ( ! empty($request['datetime_id'])) { |
| 1015 | 1015 | $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
| 1016 | 1016 | } |
| 1017 | - if( ! empty($request['DTT_ID'])){ |
|
| 1017 | + if ( ! empty($request['DTT_ID'])) { |
|
| 1018 | 1018 | $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
| 1019 | 1019 | } |
| 1020 | 1020 | return $where; |
@@ -1030,7 +1030,7 @@ discard block |
||
| 1030 | 1030 | protected function _add_registration_status_to_where_conditions(array $request) |
| 1031 | 1031 | { |
| 1032 | 1032 | $where = array(); |
| 1033 | - $view = EEH_Array::is_set( $request, 'status', '' ); |
|
| 1033 | + $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1034 | 1034 | $registration_status = ! empty($request['_reg_status']) |
| 1035 | 1035 | ? sanitize_text_field($request['_reg_status']) |
| 1036 | 1036 | : ''; |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | protected function _add_date_to_where_conditions(array $request) |
| 1066 | 1066 | { |
| 1067 | 1067 | $where = array(); |
| 1068 | - $view = EEH_Array::is_set( $request, 'status', '' ); |
|
| 1068 | + $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1069 | 1069 | $month_range = ! empty($request['month_range']) |
| 1070 | 1070 | ? sanitize_text_field($request['month_range']) |
| 1071 | 1071 | : ''; |
@@ -1079,12 +1079,12 @@ discard block |
||
| 1079 | 1079 | array( |
| 1080 | 1080 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1081 | 1081 | 'REG_date', |
| 1082 | - $now . ' 00:00:00', |
|
| 1082 | + $now.' 00:00:00', |
|
| 1083 | 1083 | 'Y-m-d H:i:s' |
| 1084 | 1084 | ), |
| 1085 | 1085 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1086 | 1086 | 'REG_date', |
| 1087 | - $now . ' 23:59:59', |
|
| 1087 | + $now.' 23:59:59', |
|
| 1088 | 1088 | 'Y-m-d H:i:s' |
| 1089 | 1089 | ), |
| 1090 | 1090 | ), |
@@ -1097,12 +1097,12 @@ discard block |
||
| 1097 | 1097 | array( |
| 1098 | 1098 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1099 | 1099 | 'REG_date', |
| 1100 | - $current_year_and_month . '-01 00:00:00', |
|
| 1100 | + $current_year_and_month.'-01 00:00:00', |
|
| 1101 | 1101 | 'Y-m-d H:i:s' |
| 1102 | 1102 | ), |
| 1103 | 1103 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1104 | 1104 | 'REG_date', |
| 1105 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1105 | + $current_year_and_month.'-'.$days_this_month.' 23:59:59', |
|
| 1106 | 1106 | 'Y-m-d H:i:s' |
| 1107 | 1107 | ), |
| 1108 | 1108 | ), |
@@ -1117,18 +1117,18 @@ discard block |
||
| 1117 | 1117 | : ''; |
| 1118 | 1118 | //if there is not a month or year then we can't go further |
| 1119 | 1119 | if ($month_requested && $year_requested) { |
| 1120 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1120 | + $days_in_month = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01')); |
|
| 1121 | 1121 | $where['REG_date'] = array( |
| 1122 | 1122 | 'BETWEEN', |
| 1123 | 1123 | array( |
| 1124 | 1124 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1125 | 1125 | 'REG_date', |
| 1126 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1126 | + $year_requested.'-'.$month_requested.'-01 00:00:00', |
|
| 1127 | 1127 | 'Y-m-d H:i:s' |
| 1128 | 1128 | ), |
| 1129 | 1129 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1130 | 1130 | 'REG_date', |
| 1131 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1131 | + $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59', |
|
| 1132 | 1132 | 'Y-m-d H:i:s' |
| 1133 | 1133 | ), |
| 1134 | 1134 | ), |
@@ -1149,7 +1149,7 @@ discard block |
||
| 1149 | 1149 | { |
| 1150 | 1150 | $where = array(); |
| 1151 | 1151 | if ( ! empty($request['s'])) { |
| 1152 | - $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1152 | + $search_string = '%'.sanitize_text_field($request['s']).'%'; |
|
| 1153 | 1153 | $where['OR'] = array( |
| 1154 | 1154 | 'Event.EVT_name' => array('LIKE', $search_string), |
| 1155 | 1155 | 'Event.EVT_desc' => array('LIKE', $search_string), |
@@ -1251,7 +1251,7 @@ discard block |
||
| 1251 | 1251 | : $per_page; |
| 1252 | 1252 | |
| 1253 | 1253 | //-1 means return all results so get out if that's set. |
| 1254 | - if ((int)$per_page === -1) { |
|
| 1254 | + if ((int) $per_page === -1) { |
|
| 1255 | 1255 | return array(); |
| 1256 | 1256 | } |
| 1257 | 1257 | $per_page = absint($per_page); |
@@ -1297,12 +1297,12 @@ discard block |
||
| 1297 | 1297 | 'action' => 'default', |
| 1298 | 1298 | 'event_id' => $event_id, |
| 1299 | 1299 | ), REG_ADMIN_URL); |
| 1300 | - $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1300 | + $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1301 | 1301 | 'action' => 'default', |
| 1302 | 1302 | 'EVT_ID' => $event_id, |
| 1303 | 1303 | 'page' => 'espresso_transactions', |
| 1304 | 1304 | ), admin_url('admin.php')); |
| 1305 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1305 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1306 | 1306 | 'page' => 'espresso_events', |
| 1307 | 1307 | 'action' => 'edit', |
| 1308 | 1308 | 'post' => $event_id, |
@@ -1321,7 +1321,7 @@ discard block |
||
| 1321 | 1321 | '_REG_ID' => $previous_reg['REG_ID'], |
| 1322 | 1322 | ), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : ''; |
| 1323 | 1323 | // grab header |
| 1324 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1324 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php'; |
|
| 1325 | 1325 | $this->_template_args['REG_ID'] = $this->_registration->ID(); |
| 1326 | 1326 | $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
| 1327 | 1327 | $this->_template_args, true); |
@@ -1395,8 +1395,8 @@ discard block |
||
| 1395 | 1395 | 'default' => $this->_registration->ID(), |
| 1396 | 1396 | )), |
| 1397 | 1397 | 'current_status' => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status', |
| 1398 | - 'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(), |
|
| 1399 | - '', 'status-' . $this->_registration->status_ID(), |
|
| 1398 | + 'event_espresso')))).EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(), |
|
| 1399 | + '', 'status-'.$this->_registration->status_ID(), |
|
| 1400 | 1400 | 'line-height: 1em; font-size: 1.5em; font-weight: bold;')))), |
| 1401 | 1401 | 'reg_status' => new EE_Select_Input($this->_get_reg_statuses(), array( |
| 1402 | 1402 | 'html_label_text' => __('Change Registration Status to', 'event_espresso'), |
@@ -1452,9 +1452,9 @@ discard block |
||
| 1452 | 1452 | { |
| 1453 | 1453 | if (isset($this->_req_data['reg_status_change_form'])) { |
| 1454 | 1454 | $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
| 1455 | - ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1455 | + ? (array) $this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1456 | 1456 | } else { |
| 1457 | - $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
| 1457 | + $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array) $this->_req_data['_REG_ID'] : array(); |
|
| 1458 | 1458 | } |
| 1459 | 1459 | $success = $this->_set_registration_status($REG_IDs, $status); |
| 1460 | 1460 | //notify? |
@@ -1482,7 +1482,7 @@ discard block |
||
| 1482 | 1482 | { |
| 1483 | 1483 | $success = false; |
| 1484 | 1484 | // typecast $REG_IDs |
| 1485 | - $REG_IDs = (array)$REG_IDs; |
|
| 1485 | + $REG_IDs = (array) $REG_IDs; |
|
| 1486 | 1486 | if ( ! empty($REG_IDs)) { |
| 1487 | 1487 | $success = true; |
| 1488 | 1488 | // set default status if none is passed |
@@ -1775,7 +1775,7 @@ discard block |
||
| 1775 | 1775 | ), REG_ADMIN_URL); |
| 1776 | 1776 | $this->_template_args['REG_ID'] = $this->_registration->ID(); |
| 1777 | 1777 | $this->_template_args['event_id'] = $this->_registration->event_ID(); |
| 1778 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 1778 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 1779 | 1779 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 1780 | 1780 | } |
| 1781 | 1781 | |
@@ -1797,7 +1797,7 @@ discard block |
||
| 1797 | 1797 | $this->_template_args['att_questions'] = count($form->subforms()) > 0 ? $form->get_html_and_js() : ''; |
| 1798 | 1798 | $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
| 1799 | 1799 | $this->_template_args['REG_ID'] = $this->_registration->ID(); |
| 1800 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 1800 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 1801 | 1801 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 1802 | 1802 | } |
| 1803 | 1803 | } |
@@ -1813,7 +1813,7 @@ discard block |
||
| 1813 | 1813 | */ |
| 1814 | 1814 | public function form_before_question_group($output) |
| 1815 | 1815 | { |
| 1816 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1816 | + EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__, |
|
| 1817 | 1817 | __('This method would have been protected but was used on a filter callback' |
| 1818 | 1818 | . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
| 1819 | 1819 | '4.8.32.rc.000'); |
@@ -1834,7 +1834,7 @@ discard block |
||
| 1834 | 1834 | */ |
| 1835 | 1835 | public function form_after_question_group($output) |
| 1836 | 1836 | { |
| 1837 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1837 | + EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__, |
|
| 1838 | 1838 | __('This method would have been protected but was used on a filter callback' |
| 1839 | 1839 | . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
| 1840 | 1840 | '4.8.32.rc.000'); |
@@ -1868,14 +1868,14 @@ discard block |
||
| 1868 | 1868 | */ |
| 1869 | 1869 | public function form_form_field_label_wrap($label) |
| 1870 | 1870 | { |
| 1871 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1871 | + EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__, |
|
| 1872 | 1872 | __('This method would have been protected but was used on a filter callback' |
| 1873 | 1873 | . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
| 1874 | 1874 | '4.8.32.rc.000'); |
| 1875 | 1875 | return ' |
| 1876 | 1876 | <tr> |
| 1877 | 1877 | <th> |
| 1878 | - ' . $label . ' |
|
| 1878 | + ' . $label.' |
|
| 1879 | 1879 | </th>'; |
| 1880 | 1880 | } |
| 1881 | 1881 | |
@@ -1890,13 +1890,13 @@ discard block |
||
| 1890 | 1890 | */ |
| 1891 | 1891 | public function form_form_field_input__wrap($input) |
| 1892 | 1892 | { |
| 1893 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1893 | + EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__, |
|
| 1894 | 1894 | __('This method would have been protected but was used on a filter callback' |
| 1895 | 1895 | . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
| 1896 | 1896 | '4.8.32.rc.000'); |
| 1897 | 1897 | return ' |
| 1898 | 1898 | <td class="reg-admin-attendee-questions-input-td disabled-input"> |
| 1899 | - ' . $input . ' |
|
| 1899 | + ' . $input.' |
|
| 1900 | 1900 | </td> |
| 1901 | 1901 | </tr>'; |
| 1902 | 1902 | } |
@@ -1936,7 +1936,7 @@ discard block |
||
| 1936 | 1936 | protected function _get_reg_custom_questions_form($REG_ID) |
| 1937 | 1937 | { |
| 1938 | 1938 | if ( ! $this->_reg_custom_questions_form) { |
| 1939 | - require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 1939 | + require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 1940 | 1940 | $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
| 1941 | 1941 | EEM_Registration::instance()->get_one_by_ID($REG_ID) |
| 1942 | 1942 | ); |
@@ -1965,7 +1965,7 @@ discard block |
||
| 1965 | 1965 | if ($form->is_valid()) { |
| 1966 | 1966 | foreach ($form->subforms() as $question_group_id => $question_group_form) { |
| 1967 | 1967 | foreach ($question_group_form->inputs() as $question_id => $input) { |
| 1968 | - $where_conditions = array( |
|
| 1968 | + $where_conditions = array( |
|
| 1969 | 1969 | 'QST_ID' => $question_id, |
| 1970 | 1970 | 'REG_ID' => $REG_ID, |
| 1971 | 1971 | ); |
@@ -2001,7 +2001,7 @@ discard block |
||
| 2001 | 2001 | $REG = EEM_Registration::instance(); |
| 2002 | 2002 | //get all other registrations on this transaction, and cache |
| 2003 | 2003 | //the attendees for them so we don't have to run another query using force_join |
| 2004 | - $registrations = $REG->get_all(array( |
|
| 2004 | + $registrations = $REG->get_all(array( |
|
| 2005 | 2005 | array( |
| 2006 | 2006 | 'TXN_ID' => $this->_registration->transaction_ID(), |
| 2007 | 2007 | 'REG_ID' => array('!=', $this->_registration->ID()), |
@@ -2021,29 +2021,29 @@ discard block |
||
| 2021 | 2021 | $att_nmbr = 1; |
| 2022 | 2022 | foreach ($registrations as $registration) { |
| 2023 | 2023 | /* @var $registration EE_Registration */ |
| 2024 | - $attendee = $registration->attendee() |
|
| 2024 | + $attendee = $registration->attendee() |
|
| 2025 | 2025 | ? $registration->attendee() |
| 2026 | 2026 | : EEM_Attendee::instance() |
| 2027 | 2027 | ->create_default_object(); |
| 2028 | 2028 | $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
| 2029 | - $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : ''; |
|
| 2030 | - $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : ''; |
|
| 2031 | - $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : ''; |
|
| 2032 | - $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : ''; |
|
| 2029 | + $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname(); //( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : ''; |
|
| 2030 | + $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname(); //( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : ''; |
|
| 2031 | + $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email(); //( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : ''; |
|
| 2032 | + $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price(); //( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : ''; |
|
| 2033 | 2033 | $this->_template_args['attendees'][$att_nmbr]['address'] = implode(', ', |
| 2034 | 2034 | $attendee->full_address_as_array()); |
| 2035 | 2035 | $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(array( |
| 2036 | 2036 | 'action' => 'edit_attendee', |
| 2037 | 2037 | 'post' => $attendee->ID(), |
| 2038 | 2038 | ), REG_ADMIN_URL); |
| 2039 | - $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2039 | + $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2040 | 2040 | $att_nmbr++; |
| 2041 | 2041 | } |
| 2042 | 2042 | //EEH_Debug_Tools::printr( $attendees, '$attendees <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' ); |
| 2043 | 2043 | $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
| 2044 | 2044 | // $this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees' ), REG_ADMIN_URL ); |
| 2045 | 2045 | } |
| 2046 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2046 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2047 | 2047 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2048 | 2048 | } |
| 2049 | 2049 | |
@@ -2072,26 +2072,26 @@ discard block |
||
| 2072 | 2072 | $primary_registration = null; |
| 2073 | 2073 | } |
| 2074 | 2074 | $this->_template_args['ATT_ID'] = $attendee->ID(); |
| 2075 | - $this->_template_args['fname'] = $attendee->fname();//$this->_registration->ATT_fname; |
|
| 2076 | - $this->_template_args['lname'] = $attendee->lname();//$this->_registration->ATT_lname; |
|
| 2077 | - $this->_template_args['email'] = $attendee->email();//$this->_registration->ATT_email; |
|
| 2075 | + $this->_template_args['fname'] = $attendee->fname(); //$this->_registration->ATT_fname; |
|
| 2076 | + $this->_template_args['lname'] = $attendee->lname(); //$this->_registration->ATT_lname; |
|
| 2077 | + $this->_template_args['email'] = $attendee->email(); //$this->_registration->ATT_email; |
|
| 2078 | 2078 | $this->_template_args['phone'] = $attendee->phone(); |
| 2079 | 2079 | $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
| 2080 | 2080 | //edit link |
| 2081 | - $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2081 | + $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2082 | 2082 | 'action' => 'edit_attendee', |
| 2083 | 2083 | 'post' => $attendee->ID(), |
| 2084 | 2084 | ), REG_ADMIN_URL); |
| 2085 | 2085 | $this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso'); |
| 2086 | 2086 | //create link |
| 2087 | - $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2087 | + $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2088 | 2088 | ? EE_Admin_Page::add_query_args_and_nonce(array( |
| 2089 | 2089 | 'action' => 'duplicate_attendee', |
| 2090 | 2090 | '_REG_ID' => $this->_registration->ID(), |
| 2091 | 2091 | ), REG_ADMIN_URL) : ''; |
| 2092 | 2092 | $this->_template_args['create_label'] = __('Create Contact', 'event_espresso'); |
| 2093 | 2093 | $this->_template_args['att_check'] = $att_check; |
| 2094 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2094 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2095 | 2095 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2096 | 2096 | } |
| 2097 | 2097 | |
@@ -2305,7 +2305,7 @@ discard block |
||
| 2305 | 2305 | 'action' => 'edit', |
| 2306 | 2306 | 'post' => $this->_reg_event->ID(), |
| 2307 | 2307 | ), EVENTS_ADMIN_URL); |
| 2308 | - $edit_event_lnk = '<a href="' |
|
| 2308 | + $edit_event_lnk = '<a href="' |
|
| 2309 | 2309 | . $edit_event_url |
| 2310 | 2310 | . '" title="' |
| 2311 | 2311 | . esc_attr__('Edit ', 'event_espresso') |
@@ -2322,7 +2322,7 @@ discard block |
||
| 2322 | 2322 | $this->_return_json(); |
| 2323 | 2323 | } |
| 2324 | 2324 | // grab header |
| 2325 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2325 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php'; |
|
| 2326 | 2326 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
| 2327 | 2327 | $this->_template_args, true); |
| 2328 | 2328 | //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
@@ -2344,7 +2344,7 @@ discard block |
||
| 2344 | 2344 | 'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">', |
| 2345 | 2345 | '<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>'); |
| 2346 | 2346 | return ' |
| 2347 | - <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div> |
|
| 2347 | + <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div> |
|
| 2348 | 2348 | <script > |
| 2349 | 2349 | // WHOAH !!! it appears that someone is using the back button from the Transaction admin page |
| 2350 | 2350 | // after just adding a new registration... we gotta try to put a stop to that !!! |
@@ -2569,7 +2569,7 @@ discard block |
||
| 2569 | 2569 | public function get_attendees($per_page, $count = false, $trash = false) |
| 2570 | 2570 | { |
| 2571 | 2571 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2572 | - require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 2572 | + require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php'); |
|
| 2573 | 2573 | $ATT_MDL = EEM_Attendee::instance(); |
| 2574 | 2574 | $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
| 2575 | 2575 | switch ($this->_req_data['orderby']) { |
@@ -2603,7 +2603,7 @@ discard block |
||
| 2603 | 2603 | ? $this->_req_data['perpage'] : $per_page; |
| 2604 | 2604 | $_where = array(); |
| 2605 | 2605 | if ( ! empty($this->_req_data['s'])) { |
| 2606 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2606 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 2607 | 2607 | $_where['OR'] = array( |
| 2608 | 2608 | 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
| 2609 | 2609 | 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
@@ -2681,7 +2681,7 @@ discard block |
||
| 2681 | 2681 | * the query parameters from the request |
| 2682 | 2682 | * @return void ends the request with a redirect or download |
| 2683 | 2683 | */ |
| 2684 | - public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
| 2684 | + public function _registrations_report_base($method_name_for_getting_query_params) |
|
| 2685 | 2685 | { |
| 2686 | 2686 | if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
| 2687 | 2687 | wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
@@ -2691,7 +2691,7 @@ discard block |
||
| 2691 | 2691 | 'filters' => urlencode( |
| 2692 | 2692 | serialize( |
| 2693 | 2693 | call_user_func( |
| 2694 | - array( $this, $method_name_for_getting_query_params ), |
|
| 2694 | + array($this, $method_name_for_getting_query_params), |
|
| 2695 | 2695 | EEH_Array::is_set( |
| 2696 | 2696 | $this->_req_data, |
| 2697 | 2697 | 'filters', |
@@ -2711,8 +2711,8 @@ discard block |
||
| 2711 | 2711 | 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
| 2712 | 2712 | ); |
| 2713 | 2713 | $this->_req_data = array_merge($this->_req_data, $new_request_args); |
| 2714 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2715 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2714 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 2715 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 2716 | 2716 | $EE_Export = EE_Export::instance($this->_req_data); |
| 2717 | 2717 | $EE_Export->export(); |
| 2718 | 2718 | } |
@@ -2727,14 +2727,14 @@ discard block |
||
| 2727 | 2727 | */ |
| 2728 | 2728 | public function _registrations_report() |
| 2729 | 2729 | { |
| 2730 | - $this->_registrations_report_base( '_get_registration_query_parameters' ); |
|
| 2730 | + $this->_registrations_report_base('_get_registration_query_parameters'); |
|
| 2731 | 2731 | } |
| 2732 | 2732 | |
| 2733 | 2733 | |
| 2734 | 2734 | public function _contact_list_export() |
| 2735 | 2735 | { |
| 2736 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2737 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2736 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 2737 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 2738 | 2738 | $EE_Export = EE_Export::instance($this->_req_data); |
| 2739 | 2739 | $EE_Export->export_attendees(); |
| 2740 | 2740 | } |
@@ -2751,8 +2751,8 @@ discard block |
||
| 2751 | 2751 | 'return_url' => urlencode($this->_req_data['return_url']), |
| 2752 | 2752 | ))); |
| 2753 | 2753 | } else { |
| 2754 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2755 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2754 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 2755 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 2756 | 2756 | $EE_Export = EE_Export::instance($this->_req_data); |
| 2757 | 2757 | $EE_Export->report_attendees(); |
| 2758 | 2758 | } |
@@ -2809,7 +2809,7 @@ discard block |
||
| 2809 | 2809 | $updated_fields = array( |
| 2810 | 2810 | 'ATT_fname' => $this->_req_data['ATT_fname'], |
| 2811 | 2811 | 'ATT_lname' => $this->_req_data['ATT_lname'], |
| 2812 | - 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 2812 | + 'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'], |
|
| 2813 | 2813 | 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
| 2814 | 2814 | 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
| 2815 | 2815 | 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
@@ -2892,7 +2892,7 @@ discard block |
||
| 2892 | 2892 | { |
| 2893 | 2893 | //get attendee object ( should already have it ) |
| 2894 | 2894 | $this->_template_args['attendee'] = $this->_cpt_model_obj; |
| 2895 | - $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
| 2895 | + $template = REG_TEMPLATE_PATH.'attendee_contact_info_metabox_content.template.php'; |
|
| 2896 | 2896 | EEH_Template::display_template($template, $this->_template_args); |
| 2897 | 2897 | } |
| 2898 | 2898 | |
@@ -2933,7 +2933,7 @@ discard block |
||
| 2933 | 2933 | 'input_prefix' => '', |
| 2934 | 2934 | 'append_qstn_id' => false, |
| 2935 | 2935 | ))); |
| 2936 | - $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 2936 | + $template = REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php'; |
|
| 2937 | 2937 | EEH_Template::display_template($template, $this->_template_args); |
| 2938 | 2938 | } |
| 2939 | 2939 | |
@@ -2948,7 +2948,7 @@ discard block |
||
| 2948 | 2948 | { |
| 2949 | 2949 | $this->_template_args['attendee'] = $this->_cpt_model_obj; |
| 2950 | 2950 | $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
| 2951 | - $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 2951 | + $template = REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php'; |
|
| 2952 | 2952 | EEH_Template::display_template($template, $this->_template_args); |
| 2953 | 2953 | } |
| 2954 | 2954 | |
@@ -2962,7 +2962,7 @@ discard block |
||
| 2962 | 2962 | public function after_title_form_fields($post) |
| 2963 | 2963 | { |
| 2964 | 2964 | if ($post->post_type == 'espresso_attendees') { |
| 2965 | - $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 2965 | + $template = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php'; |
|
| 2966 | 2966 | $template_args['attendee'] = $this->_cpt_model_obj; |
| 2967 | 2967 | EEH_Template::display_template($template, $template_args); |
| 2968 | 2968 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -23,1844 +23,1844 @@ discard block |
||
| 23 | 23 | class Registrations_Admin_Page extends EE_Admin_Page_CPT |
| 24 | 24 | { |
| 25 | 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 | - |
|
| 41 | - private static $_reg_status; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Form for displaying the custom questions for this registration. |
|
| 45 | - * This gets used a few times throughout the request so its best to cache it |
|
| 46 | - * |
|
| 47 | - * @var EE_Registration_Custom_Questions_Form |
|
| 48 | - */ |
|
| 49 | - protected $_reg_custom_questions_form = null; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * constructor |
|
| 54 | - * |
|
| 55 | - * @Constructor |
|
| 56 | - * @access public |
|
| 57 | - * @param bool $routing |
|
| 58 | - * @return Registrations_Admin_Page |
|
| 59 | - */ |
|
| 60 | - public function __construct($routing = true) |
|
| 61 | - { |
|
| 62 | - parent::__construct($routing); |
|
| 63 | - add_action('wp_loaded', array($this, 'wp_loaded')); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - public function wp_loaded() |
|
| 68 | - { |
|
| 69 | - // when adding a new registration... |
|
| 70 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
| 71 | - EE_System::do_not_cache(); |
|
| 72 | - if ( ! isset($this->_req_data['processing_registration']) |
|
| 73 | - || absint($this->_req_data['processing_registration']) !== 1 |
|
| 74 | - ) { |
|
| 75 | - // and it's NOT the attendee information reg step |
|
| 76 | - // force cookie expiration by setting time to last week |
|
| 77 | - setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 78 | - // and update the global |
|
| 79 | - $_COOKIE['ee_registration_added'] = 0; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - protected function _init_page_props() |
|
| 86 | - { |
|
| 87 | - $this->page_slug = REG_PG_SLUG; |
|
| 88 | - $this->_admin_base_url = REG_ADMIN_URL; |
|
| 89 | - $this->_admin_base_path = REG_ADMIN; |
|
| 90 | - $this->page_label = __('Registrations', 'event_espresso'); |
|
| 91 | - $this->_cpt_routes = array( |
|
| 92 | - 'add_new_attendee' => 'espresso_attendees', |
|
| 93 | - 'edit_attendee' => 'espresso_attendees', |
|
| 94 | - 'insert_attendee' => 'espresso_attendees', |
|
| 95 | - 'update_attendee' => 'espresso_attendees', |
|
| 96 | - ); |
|
| 97 | - $this->_cpt_model_names = array( |
|
| 98 | - 'add_new_attendee' => 'EEM_Attendee', |
|
| 99 | - 'edit_attendee' => 'EEM_Attendee', |
|
| 100 | - ); |
|
| 101 | - $this->_cpt_edit_routes = array( |
|
| 102 | - 'espresso_attendees' => 'edit_attendee', |
|
| 103 | - ); |
|
| 104 | - $this->_pagenow_map = array( |
|
| 105 | - 'add_new_attendee' => 'post-new.php', |
|
| 106 | - 'edit_attendee' => 'post.php', |
|
| 107 | - 'trash' => 'post.php', |
|
| 108 | - ); |
|
| 109 | - add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
| 110 | - //add filters so that the comment urls don't take users to a confusing 404 page |
|
| 111 | - add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - public function clear_comment_link($link, $comment, $args) |
|
| 116 | - { |
|
| 117 | - //gotta make sure this only happens on this route |
|
| 118 | - $post_type = get_post_type($comment->comment_post_ID); |
|
| 119 | - if ($post_type === 'espresso_attendees') { |
|
| 120 | - return '#commentsdiv'; |
|
| 121 | - } |
|
| 122 | - return $link; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - protected function _ajax_hooks() |
|
| 127 | - { |
|
| 128 | - //todo: all hooks for registrations ajax goes in here |
|
| 129 | - add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - protected function _define_page_props() |
|
| 134 | - { |
|
| 135 | - $this->_admin_page_title = $this->page_label; |
|
| 136 | - $this->_labels = array( |
|
| 137 | - 'buttons' => array( |
|
| 138 | - 'add-registrant' => __('Add New Registration', 'event_espresso'), |
|
| 139 | - 'add-attendee' => __('Add Contact', 'event_espresso'), |
|
| 140 | - 'edit' => __('Edit Contact', 'event_espresso'), |
|
| 141 | - 'report' => __("Event Registrations CSV Report", "event_espresso"), |
|
| 142 | - 'report_all' => __('All Registrations CSV Report', 'event_espresso'), |
|
| 143 | - 'report_filtered' => __('Filtered CSV Report', 'event_espresso'), |
|
| 144 | - 'contact_list_report' => __('Contact List Report', 'event_espresso'), |
|
| 145 | - 'contact_list_export' => __("Export Data", "event_espresso"), |
|
| 146 | - ), |
|
| 147 | - 'publishbox' => array( |
|
| 148 | - 'add_new_attendee' => __("Add Contact Record", 'event_espresso'), |
|
| 149 | - 'edit_attendee' => __("Update Contact Record", 'event_espresso'), |
|
| 150 | - ), |
|
| 151 | - 'hide_add_button_on_cpt_route' => array( |
|
| 152 | - 'edit_attendee' => true, |
|
| 153 | - ), |
|
| 154 | - ); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * grab url requests and route them |
|
| 160 | - * |
|
| 161 | - * @access private |
|
| 162 | - * @return void |
|
| 163 | - */ |
|
| 164 | - public function _set_page_routes() |
|
| 165 | - { |
|
| 166 | - $this->_get_registration_status_array(); |
|
| 167 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 168 | - ? $this->_req_data['_REG_ID'] : 0; |
|
| 169 | - $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
| 170 | - ? $this->_req_data['ATT_ID'] : 0; |
|
| 171 | - $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post'] |
|
| 172 | - : $att_id; |
|
| 173 | - $this->_page_routes = array( |
|
| 174 | - 'default' => array( |
|
| 175 | - 'func' => '_registrations_overview_list_table', |
|
| 176 | - 'capability' => 'ee_read_registrations', |
|
| 177 | - ), |
|
| 178 | - 'view_registration' => array( |
|
| 179 | - 'func' => '_registration_details', |
|
| 180 | - 'capability' => 'ee_read_registration', |
|
| 181 | - 'obj_id' => $reg_id, |
|
| 182 | - ), |
|
| 183 | - 'edit_registration' => array( |
|
| 184 | - 'func' => '_update_attendee_registration_form', |
|
| 185 | - 'noheader' => true, |
|
| 186 | - 'headers_sent_route' => 'view_registration', |
|
| 187 | - 'capability' => 'ee_edit_registration', |
|
| 188 | - 'obj_id' => $reg_id, |
|
| 189 | - '_REG_ID' => $reg_id, |
|
| 190 | - ), |
|
| 191 | - 'trash_registrations' => array( |
|
| 192 | - 'func' => '_trash_or_restore_registrations', |
|
| 193 | - 'args' => array('trash' => true), |
|
| 194 | - 'noheader' => true, |
|
| 195 | - 'capability' => 'ee_delete_registrations', |
|
| 196 | - ), |
|
| 197 | - 'restore_registrations' => array( |
|
| 198 | - 'func' => '_trash_or_restore_registrations', |
|
| 199 | - 'args' => array('trash' => false), |
|
| 200 | - 'noheader' => true, |
|
| 201 | - 'capability' => 'ee_delete_registrations', |
|
| 202 | - ), |
|
| 203 | - 'delete_registrations' => array( |
|
| 204 | - 'func' => '_delete_registrations', |
|
| 205 | - 'noheader' => true, |
|
| 206 | - 'capability' => 'ee_delete_registrations', |
|
| 207 | - ), |
|
| 208 | - 'new_registration' => array( |
|
| 209 | - 'func' => 'new_registration', |
|
| 210 | - 'capability' => 'ee_edit_registrations', |
|
| 211 | - ), |
|
| 212 | - 'process_reg_step' => array( |
|
| 213 | - 'func' => 'process_reg_step', |
|
| 214 | - 'noheader' => true, |
|
| 215 | - 'capability' => 'ee_edit_registrations', |
|
| 216 | - ), |
|
| 217 | - 'redirect_to_txn' => array( |
|
| 218 | - 'func' => 'redirect_to_txn', |
|
| 219 | - 'noheader' => true, |
|
| 220 | - 'capability' => 'ee_edit_registrations', |
|
| 221 | - ), |
|
| 222 | - 'change_reg_status' => array( |
|
| 223 | - 'func' => '_change_reg_status', |
|
| 224 | - 'noheader' => true, |
|
| 225 | - 'capability' => 'ee_edit_registration', |
|
| 226 | - 'obj_id' => $reg_id, |
|
| 227 | - ), |
|
| 228 | - 'approve_registration' => array( |
|
| 229 | - 'func' => 'approve_registration', |
|
| 230 | - 'noheader' => true, |
|
| 231 | - 'capability' => 'ee_edit_registration', |
|
| 232 | - 'obj_id' => $reg_id, |
|
| 233 | - ), |
|
| 234 | - 'approve_and_notify_registration' => array( |
|
| 235 | - 'func' => 'approve_registration', |
|
| 236 | - 'noheader' => true, |
|
| 237 | - 'args' => array(true), |
|
| 238 | - 'capability' => 'ee_edit_registration', |
|
| 239 | - 'obj_id' => $reg_id, |
|
| 240 | - ), |
|
| 241 | - 'decline_registration' => array( |
|
| 242 | - 'func' => 'decline_registration', |
|
| 243 | - 'noheader' => true, |
|
| 244 | - 'capability' => 'ee_edit_registration', |
|
| 245 | - 'obj_id' => $reg_id, |
|
| 246 | - ), |
|
| 247 | - 'decline_and_notify_registration' => array( |
|
| 248 | - 'func' => 'decline_registration', |
|
| 249 | - 'noheader' => true, |
|
| 250 | - 'args' => array(true), |
|
| 251 | - 'capability' => 'ee_edit_registration', |
|
| 252 | - 'obj_id' => $reg_id, |
|
| 253 | - ), |
|
| 254 | - 'pending_registration' => array( |
|
| 255 | - 'func' => 'pending_registration', |
|
| 256 | - 'noheader' => true, |
|
| 257 | - 'capability' => 'ee_edit_registration', |
|
| 258 | - 'obj_id' => $reg_id, |
|
| 259 | - ), |
|
| 260 | - 'pending_and_notify_registration' => array( |
|
| 261 | - 'func' => 'pending_registration', |
|
| 262 | - 'noheader' => true, |
|
| 263 | - 'args' => array(true), |
|
| 264 | - 'capability' => 'ee_edit_registration', |
|
| 265 | - 'obj_id' => $reg_id, |
|
| 266 | - ), |
|
| 267 | - 'no_approve_registration' => array( |
|
| 268 | - 'func' => 'not_approve_registration', |
|
| 269 | - 'noheader' => true, |
|
| 270 | - 'capability' => 'ee_edit_registration', |
|
| 271 | - 'obj_id' => $reg_id, |
|
| 272 | - ), |
|
| 273 | - 'no_approve_and_notify_registration' => array( |
|
| 274 | - 'func' => 'not_approve_registration', |
|
| 275 | - 'noheader' => true, |
|
| 276 | - 'args' => array(true), |
|
| 277 | - 'capability' => 'ee_edit_registration', |
|
| 278 | - 'obj_id' => $reg_id, |
|
| 279 | - ), |
|
| 280 | - 'cancel_registration' => array( |
|
| 281 | - 'func' => 'cancel_registration', |
|
| 282 | - 'noheader' => true, |
|
| 283 | - 'capability' => 'ee_edit_registration', |
|
| 284 | - 'obj_id' => $reg_id, |
|
| 285 | - ), |
|
| 286 | - 'cancel_and_notify_registration' => array( |
|
| 287 | - 'func' => 'cancel_registration', |
|
| 288 | - 'noheader' => true, |
|
| 289 | - 'args' => array(true), |
|
| 290 | - 'capability' => 'ee_edit_registration', |
|
| 291 | - 'obj_id' => $reg_id, |
|
| 292 | - ), |
|
| 293 | - 'contact_list' => array( |
|
| 294 | - 'func' => '_attendee_contact_list_table', |
|
| 295 | - 'capability' => 'ee_read_contacts', |
|
| 296 | - ), |
|
| 297 | - 'add_new_attendee' => array( |
|
| 298 | - 'func' => '_create_new_cpt_item', |
|
| 299 | - 'args' => array( |
|
| 300 | - 'new_attendee' => true, |
|
| 301 | - 'capability' => 'ee_edit_contacts', |
|
| 302 | - ), |
|
| 303 | - ), |
|
| 304 | - 'edit_attendee' => array( |
|
| 305 | - 'func' => '_edit_cpt_item', |
|
| 306 | - 'capability' => 'ee_edit_contacts', |
|
| 307 | - 'obj_id' => $att_id, |
|
| 308 | - ), |
|
| 309 | - 'duplicate_attendee' => array( |
|
| 310 | - 'func' => '_duplicate_attendee', |
|
| 311 | - 'noheader' => true, |
|
| 312 | - 'capability' => 'ee_edit_contacts', |
|
| 313 | - 'obj_id' => $att_id, |
|
| 314 | - ), |
|
| 315 | - 'insert_attendee' => array( |
|
| 316 | - 'func' => '_insert_or_update_attendee', |
|
| 317 | - 'args' => array( |
|
| 318 | - 'new_attendee' => true, |
|
| 319 | - ), |
|
| 320 | - 'noheader' => true, |
|
| 321 | - 'capability' => 'ee_edit_contacts', |
|
| 322 | - ), |
|
| 323 | - 'update_attendee' => array( |
|
| 324 | - 'func' => '_insert_or_update_attendee', |
|
| 325 | - 'args' => array( |
|
| 326 | - 'new_attendee' => false, |
|
| 327 | - ), |
|
| 328 | - 'noheader' => true, |
|
| 329 | - 'capability' => 'ee_edit_contacts', |
|
| 330 | - 'obj_id' => $att_id, |
|
| 331 | - ), |
|
| 332 | - 'trash_attendees' => array( |
|
| 333 | - 'func' => '_trash_or_restore_attendees', |
|
| 334 | - 'args' => array( |
|
| 335 | - 'trash' => true, |
|
| 336 | - ), |
|
| 337 | - 'noheader' => true, |
|
| 338 | - 'capability' => 'ee_delete_contacts', |
|
| 339 | - 'obj_id' => $att_id, |
|
| 340 | - ), |
|
| 341 | - 'restore_attendees' => array( |
|
| 342 | - 'func' => '_trash_or_restore_attendees', |
|
| 343 | - 'args' => array( |
|
| 344 | - 'trash' => false, |
|
| 345 | - ), |
|
| 346 | - 'noheader' => true, |
|
| 347 | - 'capability' => 'ee_delete_contacts', |
|
| 348 | - 'obj_id' => $att_id, |
|
| 349 | - ), |
|
| 350 | - 'resend_registration' => array( |
|
| 351 | - 'func' => '_resend_registration', |
|
| 352 | - 'noheader' => true, |
|
| 353 | - 'capability' => 'ee_send_message', |
|
| 354 | - ), |
|
| 355 | - 'registrations_report' => array( |
|
| 356 | - 'func' => '_registrations_report', |
|
| 357 | - 'noheader' => true, |
|
| 358 | - 'capability' => 'ee_read_registrations', |
|
| 359 | - ), |
|
| 360 | - 'contact_list_export' => array( |
|
| 361 | - 'func' => '_contact_list_export', |
|
| 362 | - 'noheader' => true, |
|
| 363 | - 'capability' => 'export', |
|
| 364 | - ), |
|
| 365 | - 'contact_list_report' => array( |
|
| 366 | - 'func' => '_contact_list_report', |
|
| 367 | - 'noheader' => true, |
|
| 368 | - 'capability' => 'ee_read_contacts', |
|
| 369 | - ), |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - protected function _set_page_config() |
|
| 375 | - { |
|
| 376 | - $this->_page_config = array( |
|
| 377 | - 'default' => array( |
|
| 378 | - 'nav' => array( |
|
| 379 | - 'label' => __('Overview', 'event_espresso'), |
|
| 380 | - 'order' => 5, |
|
| 381 | - ), |
|
| 382 | - 'help_tabs' => array( |
|
| 383 | - 'registrations_overview_help_tab' => array( |
|
| 384 | - 'title' => __('Registrations Overview', 'event_espresso'), |
|
| 385 | - 'filename' => 'registrations_overview', |
|
| 386 | - ), |
|
| 387 | - 'registrations_overview_table_column_headings_help_tab' => array( |
|
| 388 | - 'title' => __('Registrations Table Column Headings', 'event_espresso'), |
|
| 389 | - 'filename' => 'registrations_overview_table_column_headings', |
|
| 390 | - ), |
|
| 391 | - 'registrations_overview_filters_help_tab' => array( |
|
| 392 | - 'title' => __('Registration Filters', 'event_espresso'), |
|
| 393 | - 'filename' => 'registrations_overview_filters', |
|
| 394 | - ), |
|
| 395 | - 'registrations_overview_views_help_tab' => array( |
|
| 396 | - 'title' => __('Registration Views', 'event_espresso'), |
|
| 397 | - 'filename' => 'registrations_overview_views', |
|
| 398 | - ), |
|
| 399 | - 'registrations_regoverview_other_help_tab' => array( |
|
| 400 | - 'title' => __('Registrations Other', 'event_espresso'), |
|
| 401 | - 'filename' => 'registrations_overview_other', |
|
| 402 | - ), |
|
| 403 | - ), |
|
| 404 | - 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 405 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
| 406 | - 'list_table' => 'EE_Registrations_List_Table', |
|
| 407 | - 'require_nonce' => false, |
|
| 408 | - ), |
|
| 409 | - 'view_registration' => array( |
|
| 410 | - 'nav' => array( |
|
| 411 | - 'label' => __('REG Details', 'event_espresso'), |
|
| 412 | - 'order' => 15, |
|
| 413 | - 'url' => isset($this->_req_data['_REG_ID']) |
|
| 414 | - ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
| 415 | - : $this->_admin_base_url, |
|
| 416 | - 'persistent' => false, |
|
| 417 | - ), |
|
| 418 | - 'help_tabs' => array( |
|
| 419 | - 'registrations_details_help_tab' => array( |
|
| 420 | - 'title' => __('Registration Details', 'event_espresso'), |
|
| 421 | - 'filename' => 'registrations_details', |
|
| 422 | - ), |
|
| 423 | - 'registrations_details_table_help_tab' => array( |
|
| 424 | - 'title' => __('Registration Details Table', 'event_espresso'), |
|
| 425 | - 'filename' => 'registrations_details_table', |
|
| 426 | - ), |
|
| 427 | - 'registrations_details_form_answers_help_tab' => array( |
|
| 428 | - 'title' => __('Registration Form Answers', 'event_espresso'), |
|
| 429 | - 'filename' => 'registrations_details_form_answers', |
|
| 430 | - ), |
|
| 431 | - 'registrations_details_registrant_details_help_tab' => array( |
|
| 432 | - 'title' => __('Contact Details', 'event_espresso'), |
|
| 433 | - 'filename' => 'registrations_details_registrant_details', |
|
| 434 | - ), |
|
| 435 | - ), |
|
| 436 | - 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 437 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, |
|
| 438 | - array('_registration_details_metaboxes')), |
|
| 439 | - 'require_nonce' => false, |
|
| 440 | - ), |
|
| 441 | - 'new_registration' => array( |
|
| 442 | - 'nav' => array( |
|
| 443 | - 'label' => __('Add New Registration', 'event_espresso'), |
|
| 444 | - 'url' => '#', |
|
| 445 | - 'order' => 15, |
|
| 446 | - 'persistent' => false, |
|
| 447 | - ), |
|
| 448 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 449 | - 'labels' => array( |
|
| 450 | - 'publishbox' => __('Save Registration', 'event_espresso'), |
|
| 451 | - ), |
|
| 452 | - 'require_nonce' => false, |
|
| 453 | - ), |
|
| 454 | - 'add_new_attendee' => array( |
|
| 455 | - 'nav' => array( |
|
| 456 | - 'label' => __('Add Contact', 'event_espresso'), |
|
| 457 | - 'order' => 15, |
|
| 458 | - 'persistent' => false, |
|
| 459 | - ), |
|
| 460 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, |
|
| 461 | - array('_publish_post_box', 'attendee_editor_metaboxes')), |
|
| 462 | - 'require_nonce' => false, |
|
| 463 | - ), |
|
| 464 | - 'edit_attendee' => array( |
|
| 465 | - 'nav' => array( |
|
| 466 | - 'label' => __('Edit Contact', 'event_espresso'), |
|
| 467 | - 'order' => 15, |
|
| 468 | - 'persistent' => false, |
|
| 469 | - 'url' => isset($this->_req_data['ATT_ID']) |
|
| 470 | - ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
| 471 | - : $this->_admin_base_url, |
|
| 472 | - ), |
|
| 473 | - 'metaboxes' => array('attendee_editor_metaboxes'), |
|
| 474 | - 'require_nonce' => false, |
|
| 475 | - ), |
|
| 476 | - 'contact_list' => array( |
|
| 477 | - 'nav' => array( |
|
| 478 | - 'label' => __('Contact List', 'event_espresso'), |
|
| 479 | - 'order' => 20, |
|
| 480 | - ), |
|
| 481 | - 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 482 | - 'help_tabs' => array( |
|
| 483 | - 'registrations_contact_list_help_tab' => array( |
|
| 484 | - 'title' => __('Registrations Contact List', 'event_espresso'), |
|
| 485 | - 'filename' => 'registrations_contact_list', |
|
| 486 | - ), |
|
| 487 | - 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
| 488 | - 'title' => __('Contact List Table Column Headings', 'event_espresso'), |
|
| 489 | - 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 490 | - ), |
|
| 491 | - 'registrations_contact_list_views_help_tab' => array( |
|
| 492 | - 'title' => __('Contact List Views', 'event_espresso'), |
|
| 493 | - 'filename' => 'registrations_contact_list_views', |
|
| 494 | - ), |
|
| 495 | - 'registrations_contact_list_other_help_tab' => array( |
|
| 496 | - 'title' => __('Contact List Other', 'event_espresso'), |
|
| 497 | - 'filename' => 'registrations_contact_list_other', |
|
| 498 | - ), |
|
| 499 | - ), |
|
| 500 | - 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 501 | - 'metaboxes' => array(), |
|
| 502 | - 'require_nonce' => false, |
|
| 503 | - ), |
|
| 504 | - //override default cpt routes |
|
| 505 | - 'create_new' => '', |
|
| 506 | - 'edit' => '', |
|
| 507 | - ); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * The below methods aren't used by this class currently |
|
| 513 | - */ |
|
| 514 | - protected function _add_screen_options() |
|
| 515 | - { |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - protected function _add_feature_pointers() |
|
| 520 | - { |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - public function admin_init() |
|
| 525 | - { |
|
| 526 | - EE_Registry::$i18n_js_strings['update_att_qstns'] = __('click "Update Registration Questions" to save your changes', |
|
| 527 | - 'event_espresso'); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - public function admin_notices() |
|
| 532 | - { |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - public function admin_footer_scripts() |
|
| 537 | - { |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * get list of registration statuses |
|
| 543 | - * |
|
| 544 | - * @access private |
|
| 545 | - * @return void |
|
| 546 | - */ |
|
| 547 | - private function _get_registration_status_array() |
|
| 548 | - { |
|
| 549 | - self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - protected function _add_screen_options_default() |
|
| 554 | - { |
|
| 555 | - $this->_per_page_screen_option(); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - protected function _add_screen_options_contact_list() |
|
| 560 | - { |
|
| 561 | - $page_title = $this->_admin_page_title; |
|
| 562 | - $this->_admin_page_title = __("Contacts", 'event_espresso'); |
|
| 563 | - $this->_per_page_screen_option(); |
|
| 564 | - $this->_admin_page_title = $page_title; |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - public function load_scripts_styles() |
|
| 569 | - { |
|
| 570 | - //style |
|
| 571 | - //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
| 572 | - wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'), |
|
| 573 | - EVENT_ESPRESSO_VERSION); |
|
| 574 | - wp_enqueue_style('espresso_reg'); |
|
| 575 | - //script |
|
| 576 | - wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 577 | - array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true); |
|
| 578 | - wp_enqueue_script('espresso_reg'); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - public function load_scripts_styles_edit_attendee() |
|
| 583 | - { |
|
| 584 | - //stuff to only show up on our attendee edit details page. |
|
| 585 | - $attendee_details_translations = array( |
|
| 586 | - 'att_publish_text' => sprintf(__('Created on: <b>%1$s</b>', 'event_espresso'), |
|
| 587 | - $this->_cpt_model_obj->get_datetime('ATT_created')), |
|
| 588 | - ); |
|
| 589 | - wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 590 | - wp_enqueue_script('jquery-validate'); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - public function load_scripts_styles_view_registration() |
|
| 595 | - { |
|
| 596 | - //styles |
|
| 597 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 598 | - //scripts |
|
| 599 | - $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 600 | - $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - public function load_scripts_styles_contact_list() |
|
| 605 | - { |
|
| 606 | - wp_deregister_style('espresso_reg'); |
|
| 607 | - wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'), |
|
| 608 | - EVENT_ESPRESSO_VERSION); |
|
| 609 | - wp_enqueue_style('espresso_att'); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - public function load_scripts_styles_new_registration() |
|
| 614 | - { |
|
| 615 | - wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'), |
|
| 616 | - EVENT_ESPRESSO_VERSION, true); |
|
| 617 | - wp_enqueue_script('ee-spco-for-admin'); |
|
| 618 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 619 | - EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 620 | - EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 621 | - EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 626 | - { |
|
| 627 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 632 | - { |
|
| 633 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - |
|
| 637 | - protected function _set_list_table_views_default() |
|
| 638 | - { |
|
| 639 | - //for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 640 | - EED_Messages::set_autoloaders(); |
|
| 641 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 642 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 643 | - $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 644 | - //key= bulk_action_slug, value= message type. |
|
| 645 | - $match_array = array( |
|
| 646 | - 'approve_registration' => 'registration', |
|
| 647 | - 'decline_registration' => 'declined_registration', |
|
| 648 | - 'pending_registration' => 'pending_approval', |
|
| 649 | - 'no_approve_registration' => 'not_approved_registration', |
|
| 650 | - 'cancel_registration' => 'cancelled_registration', |
|
| 651 | - ); |
|
| 652 | - /** setup reg status bulk actions **/ |
|
| 653 | - $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso'); |
|
| 654 | - if (in_array($match_array['approve_registration'], $active_mts) |
|
| 655 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 656 | - ) { |
|
| 657 | - $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations', |
|
| 658 | - 'event_espresso'); |
|
| 659 | - } |
|
| 660 | - $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso'); |
|
| 661 | - if (in_array($match_array['decline_registration'], $active_mts) |
|
| 662 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 663 | - ) { |
|
| 664 | - $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations', |
|
| 665 | - 'event_espresso'); |
|
| 666 | - } |
|
| 667 | - $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso'); |
|
| 668 | - if (in_array($match_array['pending_registration'], $active_mts) |
|
| 669 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 670 | - ) { |
|
| 671 | - $def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify', |
|
| 672 | - 'event_espresso'); |
|
| 673 | - } |
|
| 674 | - $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso'); |
|
| 675 | - if (in_array($match_array['no_approve_registration'], $active_mts) |
|
| 676 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 677 | - ) { |
|
| 678 | - $def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify', |
|
| 679 | - 'event_espresso'); |
|
| 680 | - } |
|
| 681 | - $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso'); |
|
| 682 | - if (in_array($match_array['cancel_registration'], $active_mts) |
|
| 683 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 684 | - ) { |
|
| 685 | - $def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify', |
|
| 686 | - 'event_espresso'); |
|
| 687 | - } |
|
| 688 | - $this->_views = array( |
|
| 689 | - 'all' => array( |
|
| 690 | - 'slug' => 'all', |
|
| 691 | - 'label' => __('View All Registrations', 'event_espresso'), |
|
| 692 | - 'count' => 0, |
|
| 693 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 694 | - 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 695 | - )), |
|
| 696 | - ), |
|
| 697 | - 'month' => array( |
|
| 698 | - 'slug' => 'month', |
|
| 699 | - 'label' => __('This Month', 'event_espresso'), |
|
| 700 | - 'count' => 0, |
|
| 701 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 702 | - 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 703 | - )), |
|
| 704 | - ), |
|
| 705 | - 'today' => array( |
|
| 706 | - 'slug' => 'today', |
|
| 707 | - 'label' => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))), |
|
| 708 | - 'count' => 0, |
|
| 709 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 710 | - 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 711 | - )), |
|
| 712 | - ), |
|
| 713 | - ); |
|
| 714 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations', |
|
| 715 | - 'espresso_registrations_delete_registration') |
|
| 716 | - ) { |
|
| 717 | - $this->_views['incomplete'] = array( |
|
| 718 | - 'slug' => 'incomplete', |
|
| 719 | - 'label' => __('Incomplete', 'event_espresso'), |
|
| 720 | - 'count' => 0, |
|
| 721 | - 'bulk_action' => array( |
|
| 722 | - 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 723 | - ), |
|
| 724 | - ); |
|
| 725 | - $this->_views['trash'] = array( |
|
| 726 | - 'slug' => 'trash', |
|
| 727 | - 'label' => __('Trash', 'event_espresso'), |
|
| 728 | - 'count' => 0, |
|
| 729 | - 'bulk_action' => array( |
|
| 730 | - 'restore_registrations' => __('Restore Registrations', 'event_espresso'), |
|
| 731 | - 'delete_registrations' => __('Delete Registrations Permanently', 'event_espresso'), |
|
| 732 | - ), |
|
| 733 | - ); |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - |
|
| 738 | - protected function _set_list_table_views_contact_list() |
|
| 739 | - { |
|
| 740 | - $this->_views = array( |
|
| 741 | - 'in_use' => array( |
|
| 742 | - 'slug' => 'in_use', |
|
| 743 | - 'label' => __('In Use', 'event_espresso'), |
|
| 744 | - 'count' => 0, |
|
| 745 | - 'bulk_action' => array( |
|
| 746 | - 'trash_attendees' => __('Move to Trash', 'event_espresso'), |
|
| 747 | - ), |
|
| 748 | - ), |
|
| 749 | - ); |
|
| 750 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', |
|
| 751 | - 'espresso_registrations_trash_attendees') |
|
| 752 | - ) { |
|
| 753 | - $this->_views['trash'] = array( |
|
| 754 | - 'slug' => 'trash', |
|
| 755 | - 'label' => __('Trash', 'event_espresso'), |
|
| 756 | - 'count' => 0, |
|
| 757 | - 'bulk_action' => array( |
|
| 758 | - 'restore_attendees' => __('Restore from Trash', 'event_espresso'), |
|
| 759 | - ), |
|
| 760 | - ); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - protected function _registration_legend_items() |
|
| 766 | - { |
|
| 767 | - $fc_items = array( |
|
| 768 | - 'star-icon' => array( |
|
| 769 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 770 | - 'desc' => __('This is the Primary Registrant', 'event_espresso'), |
|
| 771 | - ), |
|
| 772 | - 'view_details' => array( |
|
| 773 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 774 | - 'desc' => __('View Registration Details', 'event_espresso'), |
|
| 775 | - ), |
|
| 776 | - 'edit_attendee' => array( |
|
| 777 | - 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
| 778 | - 'desc' => __('Edit Contact Details', 'event_espresso'), |
|
| 779 | - ), |
|
| 780 | - 'view_transaction' => array( |
|
| 781 | - 'class' => 'dashicons dashicons-cart', |
|
| 782 | - 'desc' => __('View Transaction Details', 'event_espresso'), |
|
| 783 | - ), |
|
| 784 | - 'view_invoice' => array( |
|
| 785 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 786 | - 'desc' => __('View Transaction Invoice', 'event_espresso'), |
|
| 787 | - ), |
|
| 788 | - ); |
|
| 789 | - if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 790 | - 'espresso_registrations_resend_registration') |
|
| 791 | - ) { |
|
| 792 | - $fc_items['resend_registration'] = array( |
|
| 793 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 794 | - 'desc' => __('Resend Registration Details', 'event_espresso'), |
|
| 795 | - ); |
|
| 796 | - } else { |
|
| 797 | - $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
| 798 | - } |
|
| 799 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 800 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 801 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 802 | - $fc_items['view_related_messages'] = array( |
|
| 803 | - 'class' => $related_for_icon['css_class'], |
|
| 804 | - 'desc' => $related_for_icon['label'], |
|
| 805 | - ); |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - $sc_items = array( |
|
| 809 | - 'approved_status' => array( |
|
| 810 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 811 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 812 | - ), |
|
| 813 | - 'pending_status' => array( |
|
| 814 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 815 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 816 | - ), |
|
| 817 | - 'wait_list' => array( |
|
| 818 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 819 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 820 | - ), |
|
| 821 | - 'incomplete_status' => array( |
|
| 822 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 823 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'), |
|
| 824 | - ), |
|
| 825 | - 'not_approved' => array( |
|
| 826 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 827 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 828 | - ), |
|
| 829 | - 'declined_status' => array( |
|
| 830 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 831 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 832 | - ), |
|
| 833 | - 'cancelled_status' => array( |
|
| 834 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 835 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 836 | - ), |
|
| 837 | - ); |
|
| 838 | - return array_merge($fc_items, $sc_items); |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - |
|
| 842 | - |
|
| 843 | - /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 844 | - /** |
|
| 845 | - * @throws \EE_Error |
|
| 846 | - */ |
|
| 847 | - protected function _registrations_overview_list_table() |
|
| 848 | - { |
|
| 849 | - $this->_template_args['admin_page_header'] = ''; |
|
| 850 | - $EVT_ID = ! empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : 0; |
|
| 851 | - if ($EVT_ID) { |
|
| 852 | - if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations', |
|
| 853 | - 'espresso_registrations_new_registration', $EVT_ID) |
|
| 854 | - ) { |
|
| 855 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant', |
|
| 856 | - array('event_id' => $EVT_ID), 'add-new-h2'); |
|
| 857 | - } |
|
| 858 | - $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 859 | - if ($event instanceof EE_Event) { |
|
| 860 | - $this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s', |
|
| 861 | - 'event_espresso'), '<h3 style="line-height:1.5em;">', |
|
| 862 | - '<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 863 | - 'action' => 'edit', |
|
| 864 | - 'post' => $event->ID(), |
|
| 865 | - ), EVENTS_ADMIN_URL) . '"> ' . $event->get('EVT_name') . ' </a> ', '</h3>'); |
|
| 866 | - } |
|
| 867 | - $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
| 868 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 869 | - if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
| 870 | - $this->_template_args['admin_page_header'] = substr($this->_template_args['admin_page_header'], 0, -5); |
|
| 871 | - $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
| 872 | - $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 873 | - $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
| 874 | - $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 875 | - $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 879 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * This sets the _registration property for the registration details screen |
|
| 885 | - * |
|
| 886 | - * @access private |
|
| 887 | - * @return bool |
|
| 888 | - */ |
|
| 889 | - private function _set_registration_object() |
|
| 890 | - { |
|
| 891 | - //get out if we've already set the object |
|
| 892 | - if (is_object($this->_registration)) { |
|
| 893 | - return true; |
|
| 894 | - } |
|
| 895 | - $REG = EEM_Registration::instance(); |
|
| 896 | - $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 897 | - if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
| 898 | - return true; |
|
| 899 | - } else { |
|
| 900 | - $error_msg = sprintf(__('An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 901 | - 'event_espresso'), $REG_ID); |
|
| 902 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 903 | - $this->_registration = null; |
|
| 904 | - return false; |
|
| 905 | - } |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Used to retrieve registrations for the list table. |
|
| 911 | - * |
|
| 912 | - * @param int $per_page |
|
| 913 | - * @param bool $count |
|
| 914 | - * @param bool $this_month |
|
| 915 | - * @param bool $today |
|
| 916 | - * @return \EE_Registration[]|int |
|
| 917 | - */ |
|
| 918 | - public function get_registrations( |
|
| 919 | - $per_page = 10, |
|
| 920 | - $count = false, |
|
| 921 | - $this_month = false, |
|
| 922 | - $today = false |
|
| 923 | - ) { |
|
| 924 | - if( $this_month ) { |
|
| 925 | - $this->_req_data['status'] = 'month'; |
|
| 926 | - } |
|
| 927 | - if( $today ) { |
|
| 928 | - $this->_req_data['status'] = 'today'; |
|
| 929 | - } |
|
| 930 | - $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
| 931 | - /** |
|
| 932 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 933 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 934 | - * @see EEM_Base::get_all() |
|
| 935 | - */ |
|
| 936 | - $query_params['group_by'] = ''; |
|
| 937 | - |
|
| 938 | - return $count |
|
| 939 | - ? EEM_Registration::instance()->count($query_params) |
|
| 940 | - /** @type EE_Registration[] */ |
|
| 941 | - : EEM_Registration::instance()->get_all($query_params); |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 948 | - * Note: this listens to values on the request for some of the query parameters. |
|
| 949 | - * |
|
| 950 | - * @param array $request |
|
| 951 | - * @param int $per_page |
|
| 952 | - * @param bool $count |
|
| 953 | - * @return array |
|
| 954 | - */ |
|
| 955 | - protected function _get_registration_query_parameters( |
|
| 956 | - $request = array(), |
|
| 957 | - $per_page = 10, |
|
| 958 | - $count = false |
|
| 959 | - ) { |
|
| 960 | - |
|
| 961 | - $query_params = array( |
|
| 962 | - 0 => $this->_get_where_conditions_for_registrations_query( |
|
| 963 | - $request |
|
| 964 | - ), |
|
| 965 | - 'caps' => EEM_Registration::caps_read_admin, |
|
| 966 | - 'default_where_conditions' => 'this_model_only', |
|
| 967 | - ); |
|
| 968 | - if ( ! $count) { |
|
| 969 | - $query_params = array_merge( |
|
| 970 | - $query_params, |
|
| 971 | - $this->_get_orderby_for_registrations_query(), |
|
| 972 | - $this->_get_limit($per_page) |
|
| 973 | - ); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - return $query_params; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - |
|
| 980 | - /** |
|
| 981 | - * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
| 982 | - * |
|
| 983 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 984 | - * @return array |
|
| 985 | - */ |
|
| 986 | - protected function _add_event_id_to_where_conditions(array $request) |
|
| 987 | - { |
|
| 988 | - $where = array(); |
|
| 989 | - if ( ! empty($request['event_id'])) { |
|
| 990 | - $where['EVT_ID'] = absint($request['event_id']); |
|
| 991 | - } |
|
| 992 | - return $where; |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - |
|
| 996 | - /** |
|
| 997 | - * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 998 | - * |
|
| 999 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1000 | - * @return array |
|
| 1001 | - */ |
|
| 1002 | - protected function _add_category_id_to_where_conditions(array $request) |
|
| 1003 | - { |
|
| 1004 | - $where = array(); |
|
| 1005 | - if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
| 1006 | - $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
| 1007 | - } |
|
| 1008 | - return $where; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - |
|
| 1012 | - /** |
|
| 1013 | - * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 1014 | - * |
|
| 1015 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1016 | - * @return array |
|
| 1017 | - */ |
|
| 1018 | - protected function _add_datetime_id_to_where_conditions(array $request) |
|
| 1019 | - { |
|
| 1020 | - $where = array(); |
|
| 1021 | - if ( ! empty($request['datetime_id'])) { |
|
| 1022 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
| 1023 | - } |
|
| 1024 | - if( ! empty($request['DTT_ID'])){ |
|
| 1025 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
| 1026 | - } |
|
| 1027 | - return $where; |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * Adds the correct registration status to the where conditions for the registrations query. |
|
| 1033 | - * |
|
| 1034 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1035 | - * @return array |
|
| 1036 | - */ |
|
| 1037 | - protected function _add_registration_status_to_where_conditions(array $request) |
|
| 1038 | - { |
|
| 1039 | - $where = array(); |
|
| 1040 | - $view = EEH_Array::is_set( $request, 'status', '' ); |
|
| 1041 | - $registration_status = ! empty($request['_reg_status']) |
|
| 1042 | - ? sanitize_text_field($request['_reg_status']) |
|
| 1043 | - : ''; |
|
| 1044 | - |
|
| 1045 | - /* |
|
| 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 | + |
|
| 41 | + private static $_reg_status; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Form for displaying the custom questions for this registration. |
|
| 45 | + * This gets used a few times throughout the request so its best to cache it |
|
| 46 | + * |
|
| 47 | + * @var EE_Registration_Custom_Questions_Form |
|
| 48 | + */ |
|
| 49 | + protected $_reg_custom_questions_form = null; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * constructor |
|
| 54 | + * |
|
| 55 | + * @Constructor |
|
| 56 | + * @access public |
|
| 57 | + * @param bool $routing |
|
| 58 | + * @return Registrations_Admin_Page |
|
| 59 | + */ |
|
| 60 | + public function __construct($routing = true) |
|
| 61 | + { |
|
| 62 | + parent::__construct($routing); |
|
| 63 | + add_action('wp_loaded', array($this, 'wp_loaded')); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + public function wp_loaded() |
|
| 68 | + { |
|
| 69 | + // when adding a new registration... |
|
| 70 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
| 71 | + EE_System::do_not_cache(); |
|
| 72 | + if ( ! isset($this->_req_data['processing_registration']) |
|
| 73 | + || absint($this->_req_data['processing_registration']) !== 1 |
|
| 74 | + ) { |
|
| 75 | + // and it's NOT the attendee information reg step |
|
| 76 | + // force cookie expiration by setting time to last week |
|
| 77 | + setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 78 | + // and update the global |
|
| 79 | + $_COOKIE['ee_registration_added'] = 0; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + protected function _init_page_props() |
|
| 86 | + { |
|
| 87 | + $this->page_slug = REG_PG_SLUG; |
|
| 88 | + $this->_admin_base_url = REG_ADMIN_URL; |
|
| 89 | + $this->_admin_base_path = REG_ADMIN; |
|
| 90 | + $this->page_label = __('Registrations', 'event_espresso'); |
|
| 91 | + $this->_cpt_routes = array( |
|
| 92 | + 'add_new_attendee' => 'espresso_attendees', |
|
| 93 | + 'edit_attendee' => 'espresso_attendees', |
|
| 94 | + 'insert_attendee' => 'espresso_attendees', |
|
| 95 | + 'update_attendee' => 'espresso_attendees', |
|
| 96 | + ); |
|
| 97 | + $this->_cpt_model_names = array( |
|
| 98 | + 'add_new_attendee' => 'EEM_Attendee', |
|
| 99 | + 'edit_attendee' => 'EEM_Attendee', |
|
| 100 | + ); |
|
| 101 | + $this->_cpt_edit_routes = array( |
|
| 102 | + 'espresso_attendees' => 'edit_attendee', |
|
| 103 | + ); |
|
| 104 | + $this->_pagenow_map = array( |
|
| 105 | + 'add_new_attendee' => 'post-new.php', |
|
| 106 | + 'edit_attendee' => 'post.php', |
|
| 107 | + 'trash' => 'post.php', |
|
| 108 | + ); |
|
| 109 | + add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
| 110 | + //add filters so that the comment urls don't take users to a confusing 404 page |
|
| 111 | + add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + public function clear_comment_link($link, $comment, $args) |
|
| 116 | + { |
|
| 117 | + //gotta make sure this only happens on this route |
|
| 118 | + $post_type = get_post_type($comment->comment_post_ID); |
|
| 119 | + if ($post_type === 'espresso_attendees') { |
|
| 120 | + return '#commentsdiv'; |
|
| 121 | + } |
|
| 122 | + return $link; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + protected function _ajax_hooks() |
|
| 127 | + { |
|
| 128 | + //todo: all hooks for registrations ajax goes in here |
|
| 129 | + add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + protected function _define_page_props() |
|
| 134 | + { |
|
| 135 | + $this->_admin_page_title = $this->page_label; |
|
| 136 | + $this->_labels = array( |
|
| 137 | + 'buttons' => array( |
|
| 138 | + 'add-registrant' => __('Add New Registration', 'event_espresso'), |
|
| 139 | + 'add-attendee' => __('Add Contact', 'event_espresso'), |
|
| 140 | + 'edit' => __('Edit Contact', 'event_espresso'), |
|
| 141 | + 'report' => __("Event Registrations CSV Report", "event_espresso"), |
|
| 142 | + 'report_all' => __('All Registrations CSV Report', 'event_espresso'), |
|
| 143 | + 'report_filtered' => __('Filtered CSV Report', 'event_espresso'), |
|
| 144 | + 'contact_list_report' => __('Contact List Report', 'event_espresso'), |
|
| 145 | + 'contact_list_export' => __("Export Data", "event_espresso"), |
|
| 146 | + ), |
|
| 147 | + 'publishbox' => array( |
|
| 148 | + 'add_new_attendee' => __("Add Contact Record", 'event_espresso'), |
|
| 149 | + 'edit_attendee' => __("Update Contact Record", 'event_espresso'), |
|
| 150 | + ), |
|
| 151 | + 'hide_add_button_on_cpt_route' => array( |
|
| 152 | + 'edit_attendee' => true, |
|
| 153 | + ), |
|
| 154 | + ); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * grab url requests and route them |
|
| 160 | + * |
|
| 161 | + * @access private |
|
| 162 | + * @return void |
|
| 163 | + */ |
|
| 164 | + public function _set_page_routes() |
|
| 165 | + { |
|
| 166 | + $this->_get_registration_status_array(); |
|
| 167 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 168 | + ? $this->_req_data['_REG_ID'] : 0; |
|
| 169 | + $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
| 170 | + ? $this->_req_data['ATT_ID'] : 0; |
|
| 171 | + $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post'] |
|
| 172 | + : $att_id; |
|
| 173 | + $this->_page_routes = array( |
|
| 174 | + 'default' => array( |
|
| 175 | + 'func' => '_registrations_overview_list_table', |
|
| 176 | + 'capability' => 'ee_read_registrations', |
|
| 177 | + ), |
|
| 178 | + 'view_registration' => array( |
|
| 179 | + 'func' => '_registration_details', |
|
| 180 | + 'capability' => 'ee_read_registration', |
|
| 181 | + 'obj_id' => $reg_id, |
|
| 182 | + ), |
|
| 183 | + 'edit_registration' => array( |
|
| 184 | + 'func' => '_update_attendee_registration_form', |
|
| 185 | + 'noheader' => true, |
|
| 186 | + 'headers_sent_route' => 'view_registration', |
|
| 187 | + 'capability' => 'ee_edit_registration', |
|
| 188 | + 'obj_id' => $reg_id, |
|
| 189 | + '_REG_ID' => $reg_id, |
|
| 190 | + ), |
|
| 191 | + 'trash_registrations' => array( |
|
| 192 | + 'func' => '_trash_or_restore_registrations', |
|
| 193 | + 'args' => array('trash' => true), |
|
| 194 | + 'noheader' => true, |
|
| 195 | + 'capability' => 'ee_delete_registrations', |
|
| 196 | + ), |
|
| 197 | + 'restore_registrations' => array( |
|
| 198 | + 'func' => '_trash_or_restore_registrations', |
|
| 199 | + 'args' => array('trash' => false), |
|
| 200 | + 'noheader' => true, |
|
| 201 | + 'capability' => 'ee_delete_registrations', |
|
| 202 | + ), |
|
| 203 | + 'delete_registrations' => array( |
|
| 204 | + 'func' => '_delete_registrations', |
|
| 205 | + 'noheader' => true, |
|
| 206 | + 'capability' => 'ee_delete_registrations', |
|
| 207 | + ), |
|
| 208 | + 'new_registration' => array( |
|
| 209 | + 'func' => 'new_registration', |
|
| 210 | + 'capability' => 'ee_edit_registrations', |
|
| 211 | + ), |
|
| 212 | + 'process_reg_step' => array( |
|
| 213 | + 'func' => 'process_reg_step', |
|
| 214 | + 'noheader' => true, |
|
| 215 | + 'capability' => 'ee_edit_registrations', |
|
| 216 | + ), |
|
| 217 | + 'redirect_to_txn' => array( |
|
| 218 | + 'func' => 'redirect_to_txn', |
|
| 219 | + 'noheader' => true, |
|
| 220 | + 'capability' => 'ee_edit_registrations', |
|
| 221 | + ), |
|
| 222 | + 'change_reg_status' => array( |
|
| 223 | + 'func' => '_change_reg_status', |
|
| 224 | + 'noheader' => true, |
|
| 225 | + 'capability' => 'ee_edit_registration', |
|
| 226 | + 'obj_id' => $reg_id, |
|
| 227 | + ), |
|
| 228 | + 'approve_registration' => array( |
|
| 229 | + 'func' => 'approve_registration', |
|
| 230 | + 'noheader' => true, |
|
| 231 | + 'capability' => 'ee_edit_registration', |
|
| 232 | + 'obj_id' => $reg_id, |
|
| 233 | + ), |
|
| 234 | + 'approve_and_notify_registration' => array( |
|
| 235 | + 'func' => 'approve_registration', |
|
| 236 | + 'noheader' => true, |
|
| 237 | + 'args' => array(true), |
|
| 238 | + 'capability' => 'ee_edit_registration', |
|
| 239 | + 'obj_id' => $reg_id, |
|
| 240 | + ), |
|
| 241 | + 'decline_registration' => array( |
|
| 242 | + 'func' => 'decline_registration', |
|
| 243 | + 'noheader' => true, |
|
| 244 | + 'capability' => 'ee_edit_registration', |
|
| 245 | + 'obj_id' => $reg_id, |
|
| 246 | + ), |
|
| 247 | + 'decline_and_notify_registration' => array( |
|
| 248 | + 'func' => 'decline_registration', |
|
| 249 | + 'noheader' => true, |
|
| 250 | + 'args' => array(true), |
|
| 251 | + 'capability' => 'ee_edit_registration', |
|
| 252 | + 'obj_id' => $reg_id, |
|
| 253 | + ), |
|
| 254 | + 'pending_registration' => array( |
|
| 255 | + 'func' => 'pending_registration', |
|
| 256 | + 'noheader' => true, |
|
| 257 | + 'capability' => 'ee_edit_registration', |
|
| 258 | + 'obj_id' => $reg_id, |
|
| 259 | + ), |
|
| 260 | + 'pending_and_notify_registration' => array( |
|
| 261 | + 'func' => 'pending_registration', |
|
| 262 | + 'noheader' => true, |
|
| 263 | + 'args' => array(true), |
|
| 264 | + 'capability' => 'ee_edit_registration', |
|
| 265 | + 'obj_id' => $reg_id, |
|
| 266 | + ), |
|
| 267 | + 'no_approve_registration' => array( |
|
| 268 | + 'func' => 'not_approve_registration', |
|
| 269 | + 'noheader' => true, |
|
| 270 | + 'capability' => 'ee_edit_registration', |
|
| 271 | + 'obj_id' => $reg_id, |
|
| 272 | + ), |
|
| 273 | + 'no_approve_and_notify_registration' => array( |
|
| 274 | + 'func' => 'not_approve_registration', |
|
| 275 | + 'noheader' => true, |
|
| 276 | + 'args' => array(true), |
|
| 277 | + 'capability' => 'ee_edit_registration', |
|
| 278 | + 'obj_id' => $reg_id, |
|
| 279 | + ), |
|
| 280 | + 'cancel_registration' => array( |
|
| 281 | + 'func' => 'cancel_registration', |
|
| 282 | + 'noheader' => true, |
|
| 283 | + 'capability' => 'ee_edit_registration', |
|
| 284 | + 'obj_id' => $reg_id, |
|
| 285 | + ), |
|
| 286 | + 'cancel_and_notify_registration' => array( |
|
| 287 | + 'func' => 'cancel_registration', |
|
| 288 | + 'noheader' => true, |
|
| 289 | + 'args' => array(true), |
|
| 290 | + 'capability' => 'ee_edit_registration', |
|
| 291 | + 'obj_id' => $reg_id, |
|
| 292 | + ), |
|
| 293 | + 'contact_list' => array( |
|
| 294 | + 'func' => '_attendee_contact_list_table', |
|
| 295 | + 'capability' => 'ee_read_contacts', |
|
| 296 | + ), |
|
| 297 | + 'add_new_attendee' => array( |
|
| 298 | + 'func' => '_create_new_cpt_item', |
|
| 299 | + 'args' => array( |
|
| 300 | + 'new_attendee' => true, |
|
| 301 | + 'capability' => 'ee_edit_contacts', |
|
| 302 | + ), |
|
| 303 | + ), |
|
| 304 | + 'edit_attendee' => array( |
|
| 305 | + 'func' => '_edit_cpt_item', |
|
| 306 | + 'capability' => 'ee_edit_contacts', |
|
| 307 | + 'obj_id' => $att_id, |
|
| 308 | + ), |
|
| 309 | + 'duplicate_attendee' => array( |
|
| 310 | + 'func' => '_duplicate_attendee', |
|
| 311 | + 'noheader' => true, |
|
| 312 | + 'capability' => 'ee_edit_contacts', |
|
| 313 | + 'obj_id' => $att_id, |
|
| 314 | + ), |
|
| 315 | + 'insert_attendee' => array( |
|
| 316 | + 'func' => '_insert_or_update_attendee', |
|
| 317 | + 'args' => array( |
|
| 318 | + 'new_attendee' => true, |
|
| 319 | + ), |
|
| 320 | + 'noheader' => true, |
|
| 321 | + 'capability' => 'ee_edit_contacts', |
|
| 322 | + ), |
|
| 323 | + 'update_attendee' => array( |
|
| 324 | + 'func' => '_insert_or_update_attendee', |
|
| 325 | + 'args' => array( |
|
| 326 | + 'new_attendee' => false, |
|
| 327 | + ), |
|
| 328 | + 'noheader' => true, |
|
| 329 | + 'capability' => 'ee_edit_contacts', |
|
| 330 | + 'obj_id' => $att_id, |
|
| 331 | + ), |
|
| 332 | + 'trash_attendees' => array( |
|
| 333 | + 'func' => '_trash_or_restore_attendees', |
|
| 334 | + 'args' => array( |
|
| 335 | + 'trash' => true, |
|
| 336 | + ), |
|
| 337 | + 'noheader' => true, |
|
| 338 | + 'capability' => 'ee_delete_contacts', |
|
| 339 | + 'obj_id' => $att_id, |
|
| 340 | + ), |
|
| 341 | + 'restore_attendees' => array( |
|
| 342 | + 'func' => '_trash_or_restore_attendees', |
|
| 343 | + 'args' => array( |
|
| 344 | + 'trash' => false, |
|
| 345 | + ), |
|
| 346 | + 'noheader' => true, |
|
| 347 | + 'capability' => 'ee_delete_contacts', |
|
| 348 | + 'obj_id' => $att_id, |
|
| 349 | + ), |
|
| 350 | + 'resend_registration' => array( |
|
| 351 | + 'func' => '_resend_registration', |
|
| 352 | + 'noheader' => true, |
|
| 353 | + 'capability' => 'ee_send_message', |
|
| 354 | + ), |
|
| 355 | + 'registrations_report' => array( |
|
| 356 | + 'func' => '_registrations_report', |
|
| 357 | + 'noheader' => true, |
|
| 358 | + 'capability' => 'ee_read_registrations', |
|
| 359 | + ), |
|
| 360 | + 'contact_list_export' => array( |
|
| 361 | + 'func' => '_contact_list_export', |
|
| 362 | + 'noheader' => true, |
|
| 363 | + 'capability' => 'export', |
|
| 364 | + ), |
|
| 365 | + 'contact_list_report' => array( |
|
| 366 | + 'func' => '_contact_list_report', |
|
| 367 | + 'noheader' => true, |
|
| 368 | + 'capability' => 'ee_read_contacts', |
|
| 369 | + ), |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + protected function _set_page_config() |
|
| 375 | + { |
|
| 376 | + $this->_page_config = array( |
|
| 377 | + 'default' => array( |
|
| 378 | + 'nav' => array( |
|
| 379 | + 'label' => __('Overview', 'event_espresso'), |
|
| 380 | + 'order' => 5, |
|
| 381 | + ), |
|
| 382 | + 'help_tabs' => array( |
|
| 383 | + 'registrations_overview_help_tab' => array( |
|
| 384 | + 'title' => __('Registrations Overview', 'event_espresso'), |
|
| 385 | + 'filename' => 'registrations_overview', |
|
| 386 | + ), |
|
| 387 | + 'registrations_overview_table_column_headings_help_tab' => array( |
|
| 388 | + 'title' => __('Registrations Table Column Headings', 'event_espresso'), |
|
| 389 | + 'filename' => 'registrations_overview_table_column_headings', |
|
| 390 | + ), |
|
| 391 | + 'registrations_overview_filters_help_tab' => array( |
|
| 392 | + 'title' => __('Registration Filters', 'event_espresso'), |
|
| 393 | + 'filename' => 'registrations_overview_filters', |
|
| 394 | + ), |
|
| 395 | + 'registrations_overview_views_help_tab' => array( |
|
| 396 | + 'title' => __('Registration Views', 'event_espresso'), |
|
| 397 | + 'filename' => 'registrations_overview_views', |
|
| 398 | + ), |
|
| 399 | + 'registrations_regoverview_other_help_tab' => array( |
|
| 400 | + 'title' => __('Registrations Other', 'event_espresso'), |
|
| 401 | + 'filename' => 'registrations_overview_other', |
|
| 402 | + ), |
|
| 403 | + ), |
|
| 404 | + 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 405 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
| 406 | + 'list_table' => 'EE_Registrations_List_Table', |
|
| 407 | + 'require_nonce' => false, |
|
| 408 | + ), |
|
| 409 | + 'view_registration' => array( |
|
| 410 | + 'nav' => array( |
|
| 411 | + 'label' => __('REG Details', 'event_espresso'), |
|
| 412 | + 'order' => 15, |
|
| 413 | + 'url' => isset($this->_req_data['_REG_ID']) |
|
| 414 | + ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
| 415 | + : $this->_admin_base_url, |
|
| 416 | + 'persistent' => false, |
|
| 417 | + ), |
|
| 418 | + 'help_tabs' => array( |
|
| 419 | + 'registrations_details_help_tab' => array( |
|
| 420 | + 'title' => __('Registration Details', 'event_espresso'), |
|
| 421 | + 'filename' => 'registrations_details', |
|
| 422 | + ), |
|
| 423 | + 'registrations_details_table_help_tab' => array( |
|
| 424 | + 'title' => __('Registration Details Table', 'event_espresso'), |
|
| 425 | + 'filename' => 'registrations_details_table', |
|
| 426 | + ), |
|
| 427 | + 'registrations_details_form_answers_help_tab' => array( |
|
| 428 | + 'title' => __('Registration Form Answers', 'event_espresso'), |
|
| 429 | + 'filename' => 'registrations_details_form_answers', |
|
| 430 | + ), |
|
| 431 | + 'registrations_details_registrant_details_help_tab' => array( |
|
| 432 | + 'title' => __('Contact Details', 'event_espresso'), |
|
| 433 | + 'filename' => 'registrations_details_registrant_details', |
|
| 434 | + ), |
|
| 435 | + ), |
|
| 436 | + 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 437 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, |
|
| 438 | + array('_registration_details_metaboxes')), |
|
| 439 | + 'require_nonce' => false, |
|
| 440 | + ), |
|
| 441 | + 'new_registration' => array( |
|
| 442 | + 'nav' => array( |
|
| 443 | + 'label' => __('Add New Registration', 'event_espresso'), |
|
| 444 | + 'url' => '#', |
|
| 445 | + 'order' => 15, |
|
| 446 | + 'persistent' => false, |
|
| 447 | + ), |
|
| 448 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 449 | + 'labels' => array( |
|
| 450 | + 'publishbox' => __('Save Registration', 'event_espresso'), |
|
| 451 | + ), |
|
| 452 | + 'require_nonce' => false, |
|
| 453 | + ), |
|
| 454 | + 'add_new_attendee' => array( |
|
| 455 | + 'nav' => array( |
|
| 456 | + 'label' => __('Add Contact', 'event_espresso'), |
|
| 457 | + 'order' => 15, |
|
| 458 | + 'persistent' => false, |
|
| 459 | + ), |
|
| 460 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, |
|
| 461 | + array('_publish_post_box', 'attendee_editor_metaboxes')), |
|
| 462 | + 'require_nonce' => false, |
|
| 463 | + ), |
|
| 464 | + 'edit_attendee' => array( |
|
| 465 | + 'nav' => array( |
|
| 466 | + 'label' => __('Edit Contact', 'event_espresso'), |
|
| 467 | + 'order' => 15, |
|
| 468 | + 'persistent' => false, |
|
| 469 | + 'url' => isset($this->_req_data['ATT_ID']) |
|
| 470 | + ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
| 471 | + : $this->_admin_base_url, |
|
| 472 | + ), |
|
| 473 | + 'metaboxes' => array('attendee_editor_metaboxes'), |
|
| 474 | + 'require_nonce' => false, |
|
| 475 | + ), |
|
| 476 | + 'contact_list' => array( |
|
| 477 | + 'nav' => array( |
|
| 478 | + 'label' => __('Contact List', 'event_espresso'), |
|
| 479 | + 'order' => 20, |
|
| 480 | + ), |
|
| 481 | + 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 482 | + 'help_tabs' => array( |
|
| 483 | + 'registrations_contact_list_help_tab' => array( |
|
| 484 | + 'title' => __('Registrations Contact List', 'event_espresso'), |
|
| 485 | + 'filename' => 'registrations_contact_list', |
|
| 486 | + ), |
|
| 487 | + 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
| 488 | + 'title' => __('Contact List Table Column Headings', 'event_espresso'), |
|
| 489 | + 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 490 | + ), |
|
| 491 | + 'registrations_contact_list_views_help_tab' => array( |
|
| 492 | + 'title' => __('Contact List Views', 'event_espresso'), |
|
| 493 | + 'filename' => 'registrations_contact_list_views', |
|
| 494 | + ), |
|
| 495 | + 'registrations_contact_list_other_help_tab' => array( |
|
| 496 | + 'title' => __('Contact List Other', 'event_espresso'), |
|
| 497 | + 'filename' => 'registrations_contact_list_other', |
|
| 498 | + ), |
|
| 499 | + ), |
|
| 500 | + 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 501 | + 'metaboxes' => array(), |
|
| 502 | + 'require_nonce' => false, |
|
| 503 | + ), |
|
| 504 | + //override default cpt routes |
|
| 505 | + 'create_new' => '', |
|
| 506 | + 'edit' => '', |
|
| 507 | + ); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * The below methods aren't used by this class currently |
|
| 513 | + */ |
|
| 514 | + protected function _add_screen_options() |
|
| 515 | + { |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + protected function _add_feature_pointers() |
|
| 520 | + { |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + public function admin_init() |
|
| 525 | + { |
|
| 526 | + EE_Registry::$i18n_js_strings['update_att_qstns'] = __('click "Update Registration Questions" to save your changes', |
|
| 527 | + 'event_espresso'); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + public function admin_notices() |
|
| 532 | + { |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + public function admin_footer_scripts() |
|
| 537 | + { |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * get list of registration statuses |
|
| 543 | + * |
|
| 544 | + * @access private |
|
| 545 | + * @return void |
|
| 546 | + */ |
|
| 547 | + private function _get_registration_status_array() |
|
| 548 | + { |
|
| 549 | + self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + protected function _add_screen_options_default() |
|
| 554 | + { |
|
| 555 | + $this->_per_page_screen_option(); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + protected function _add_screen_options_contact_list() |
|
| 560 | + { |
|
| 561 | + $page_title = $this->_admin_page_title; |
|
| 562 | + $this->_admin_page_title = __("Contacts", 'event_espresso'); |
|
| 563 | + $this->_per_page_screen_option(); |
|
| 564 | + $this->_admin_page_title = $page_title; |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + public function load_scripts_styles() |
|
| 569 | + { |
|
| 570 | + //style |
|
| 571 | + //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
| 572 | + wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'), |
|
| 573 | + EVENT_ESPRESSO_VERSION); |
|
| 574 | + wp_enqueue_style('espresso_reg'); |
|
| 575 | + //script |
|
| 576 | + wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 577 | + array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true); |
|
| 578 | + wp_enqueue_script('espresso_reg'); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + public function load_scripts_styles_edit_attendee() |
|
| 583 | + { |
|
| 584 | + //stuff to only show up on our attendee edit details page. |
|
| 585 | + $attendee_details_translations = array( |
|
| 586 | + 'att_publish_text' => sprintf(__('Created on: <b>%1$s</b>', 'event_espresso'), |
|
| 587 | + $this->_cpt_model_obj->get_datetime('ATT_created')), |
|
| 588 | + ); |
|
| 589 | + wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 590 | + wp_enqueue_script('jquery-validate'); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + public function load_scripts_styles_view_registration() |
|
| 595 | + { |
|
| 596 | + //styles |
|
| 597 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 598 | + //scripts |
|
| 599 | + $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 600 | + $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + public function load_scripts_styles_contact_list() |
|
| 605 | + { |
|
| 606 | + wp_deregister_style('espresso_reg'); |
|
| 607 | + wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'), |
|
| 608 | + EVENT_ESPRESSO_VERSION); |
|
| 609 | + wp_enqueue_style('espresso_att'); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + public function load_scripts_styles_new_registration() |
|
| 614 | + { |
|
| 615 | + wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'), |
|
| 616 | + EVENT_ESPRESSO_VERSION, true); |
|
| 617 | + wp_enqueue_script('ee-spco-for-admin'); |
|
| 618 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 619 | + EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 620 | + EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 621 | + EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 626 | + { |
|
| 627 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 632 | + { |
|
| 633 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + |
|
| 637 | + protected function _set_list_table_views_default() |
|
| 638 | + { |
|
| 639 | + //for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 640 | + EED_Messages::set_autoloaders(); |
|
| 641 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 642 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 643 | + $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 644 | + //key= bulk_action_slug, value= message type. |
|
| 645 | + $match_array = array( |
|
| 646 | + 'approve_registration' => 'registration', |
|
| 647 | + 'decline_registration' => 'declined_registration', |
|
| 648 | + 'pending_registration' => 'pending_approval', |
|
| 649 | + 'no_approve_registration' => 'not_approved_registration', |
|
| 650 | + 'cancel_registration' => 'cancelled_registration', |
|
| 651 | + ); |
|
| 652 | + /** setup reg status bulk actions **/ |
|
| 653 | + $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso'); |
|
| 654 | + if (in_array($match_array['approve_registration'], $active_mts) |
|
| 655 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 656 | + ) { |
|
| 657 | + $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations', |
|
| 658 | + 'event_espresso'); |
|
| 659 | + } |
|
| 660 | + $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso'); |
|
| 661 | + if (in_array($match_array['decline_registration'], $active_mts) |
|
| 662 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 663 | + ) { |
|
| 664 | + $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations', |
|
| 665 | + 'event_espresso'); |
|
| 666 | + } |
|
| 667 | + $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso'); |
|
| 668 | + if (in_array($match_array['pending_registration'], $active_mts) |
|
| 669 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 670 | + ) { |
|
| 671 | + $def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify', |
|
| 672 | + 'event_espresso'); |
|
| 673 | + } |
|
| 674 | + $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso'); |
|
| 675 | + if (in_array($match_array['no_approve_registration'], $active_mts) |
|
| 676 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 677 | + ) { |
|
| 678 | + $def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify', |
|
| 679 | + 'event_espresso'); |
|
| 680 | + } |
|
| 681 | + $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso'); |
|
| 682 | + if (in_array($match_array['cancel_registration'], $active_mts) |
|
| 683 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 684 | + ) { |
|
| 685 | + $def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify', |
|
| 686 | + 'event_espresso'); |
|
| 687 | + } |
|
| 688 | + $this->_views = array( |
|
| 689 | + 'all' => array( |
|
| 690 | + 'slug' => 'all', |
|
| 691 | + 'label' => __('View All Registrations', 'event_espresso'), |
|
| 692 | + 'count' => 0, |
|
| 693 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 694 | + 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 695 | + )), |
|
| 696 | + ), |
|
| 697 | + 'month' => array( |
|
| 698 | + 'slug' => 'month', |
|
| 699 | + 'label' => __('This Month', 'event_espresso'), |
|
| 700 | + 'count' => 0, |
|
| 701 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 702 | + 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 703 | + )), |
|
| 704 | + ), |
|
| 705 | + 'today' => array( |
|
| 706 | + 'slug' => 'today', |
|
| 707 | + 'label' => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))), |
|
| 708 | + 'count' => 0, |
|
| 709 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 710 | + 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 711 | + )), |
|
| 712 | + ), |
|
| 713 | + ); |
|
| 714 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations', |
|
| 715 | + 'espresso_registrations_delete_registration') |
|
| 716 | + ) { |
|
| 717 | + $this->_views['incomplete'] = array( |
|
| 718 | + 'slug' => 'incomplete', |
|
| 719 | + 'label' => __('Incomplete', 'event_espresso'), |
|
| 720 | + 'count' => 0, |
|
| 721 | + 'bulk_action' => array( |
|
| 722 | + 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 723 | + ), |
|
| 724 | + ); |
|
| 725 | + $this->_views['trash'] = array( |
|
| 726 | + 'slug' => 'trash', |
|
| 727 | + 'label' => __('Trash', 'event_espresso'), |
|
| 728 | + 'count' => 0, |
|
| 729 | + 'bulk_action' => array( |
|
| 730 | + 'restore_registrations' => __('Restore Registrations', 'event_espresso'), |
|
| 731 | + 'delete_registrations' => __('Delete Registrations Permanently', 'event_espresso'), |
|
| 732 | + ), |
|
| 733 | + ); |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + |
|
| 738 | + protected function _set_list_table_views_contact_list() |
|
| 739 | + { |
|
| 740 | + $this->_views = array( |
|
| 741 | + 'in_use' => array( |
|
| 742 | + 'slug' => 'in_use', |
|
| 743 | + 'label' => __('In Use', 'event_espresso'), |
|
| 744 | + 'count' => 0, |
|
| 745 | + 'bulk_action' => array( |
|
| 746 | + 'trash_attendees' => __('Move to Trash', 'event_espresso'), |
|
| 747 | + ), |
|
| 748 | + ), |
|
| 749 | + ); |
|
| 750 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', |
|
| 751 | + 'espresso_registrations_trash_attendees') |
|
| 752 | + ) { |
|
| 753 | + $this->_views['trash'] = array( |
|
| 754 | + 'slug' => 'trash', |
|
| 755 | + 'label' => __('Trash', 'event_espresso'), |
|
| 756 | + 'count' => 0, |
|
| 757 | + 'bulk_action' => array( |
|
| 758 | + 'restore_attendees' => __('Restore from Trash', 'event_espresso'), |
|
| 759 | + ), |
|
| 760 | + ); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + protected function _registration_legend_items() |
|
| 766 | + { |
|
| 767 | + $fc_items = array( |
|
| 768 | + 'star-icon' => array( |
|
| 769 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 770 | + 'desc' => __('This is the Primary Registrant', 'event_espresso'), |
|
| 771 | + ), |
|
| 772 | + 'view_details' => array( |
|
| 773 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 774 | + 'desc' => __('View Registration Details', 'event_espresso'), |
|
| 775 | + ), |
|
| 776 | + 'edit_attendee' => array( |
|
| 777 | + 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
| 778 | + 'desc' => __('Edit Contact Details', 'event_espresso'), |
|
| 779 | + ), |
|
| 780 | + 'view_transaction' => array( |
|
| 781 | + 'class' => 'dashicons dashicons-cart', |
|
| 782 | + 'desc' => __('View Transaction Details', 'event_espresso'), |
|
| 783 | + ), |
|
| 784 | + 'view_invoice' => array( |
|
| 785 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 786 | + 'desc' => __('View Transaction Invoice', 'event_espresso'), |
|
| 787 | + ), |
|
| 788 | + ); |
|
| 789 | + if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 790 | + 'espresso_registrations_resend_registration') |
|
| 791 | + ) { |
|
| 792 | + $fc_items['resend_registration'] = array( |
|
| 793 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 794 | + 'desc' => __('Resend Registration Details', 'event_espresso'), |
|
| 795 | + ); |
|
| 796 | + } else { |
|
| 797 | + $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
| 798 | + } |
|
| 799 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 800 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 801 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 802 | + $fc_items['view_related_messages'] = array( |
|
| 803 | + 'class' => $related_for_icon['css_class'], |
|
| 804 | + 'desc' => $related_for_icon['label'], |
|
| 805 | + ); |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + $sc_items = array( |
|
| 809 | + 'approved_status' => array( |
|
| 810 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 811 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 812 | + ), |
|
| 813 | + 'pending_status' => array( |
|
| 814 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 815 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 816 | + ), |
|
| 817 | + 'wait_list' => array( |
|
| 818 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 819 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 820 | + ), |
|
| 821 | + 'incomplete_status' => array( |
|
| 822 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 823 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'), |
|
| 824 | + ), |
|
| 825 | + 'not_approved' => array( |
|
| 826 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 827 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 828 | + ), |
|
| 829 | + 'declined_status' => array( |
|
| 830 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 831 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 832 | + ), |
|
| 833 | + 'cancelled_status' => array( |
|
| 834 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 835 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 836 | + ), |
|
| 837 | + ); |
|
| 838 | + return array_merge($fc_items, $sc_items); |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + |
|
| 842 | + |
|
| 843 | + /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 844 | + /** |
|
| 845 | + * @throws \EE_Error |
|
| 846 | + */ |
|
| 847 | + protected function _registrations_overview_list_table() |
|
| 848 | + { |
|
| 849 | + $this->_template_args['admin_page_header'] = ''; |
|
| 850 | + $EVT_ID = ! empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : 0; |
|
| 851 | + if ($EVT_ID) { |
|
| 852 | + if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations', |
|
| 853 | + 'espresso_registrations_new_registration', $EVT_ID) |
|
| 854 | + ) { |
|
| 855 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant', |
|
| 856 | + array('event_id' => $EVT_ID), 'add-new-h2'); |
|
| 857 | + } |
|
| 858 | + $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 859 | + if ($event instanceof EE_Event) { |
|
| 860 | + $this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s', |
|
| 861 | + 'event_espresso'), '<h3 style="line-height:1.5em;">', |
|
| 862 | + '<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 863 | + 'action' => 'edit', |
|
| 864 | + 'post' => $event->ID(), |
|
| 865 | + ), EVENTS_ADMIN_URL) . '"> ' . $event->get('EVT_name') . ' </a> ', '</h3>'); |
|
| 866 | + } |
|
| 867 | + $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
| 868 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 869 | + if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
| 870 | + $this->_template_args['admin_page_header'] = substr($this->_template_args['admin_page_header'], 0, -5); |
|
| 871 | + $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
| 872 | + $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 873 | + $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
| 874 | + $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 875 | + $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 879 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * This sets the _registration property for the registration details screen |
|
| 885 | + * |
|
| 886 | + * @access private |
|
| 887 | + * @return bool |
|
| 888 | + */ |
|
| 889 | + private function _set_registration_object() |
|
| 890 | + { |
|
| 891 | + //get out if we've already set the object |
|
| 892 | + if (is_object($this->_registration)) { |
|
| 893 | + return true; |
|
| 894 | + } |
|
| 895 | + $REG = EEM_Registration::instance(); |
|
| 896 | + $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 897 | + if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
| 898 | + return true; |
|
| 899 | + } else { |
|
| 900 | + $error_msg = sprintf(__('An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 901 | + 'event_espresso'), $REG_ID); |
|
| 902 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 903 | + $this->_registration = null; |
|
| 904 | + return false; |
|
| 905 | + } |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Used to retrieve registrations for the list table. |
|
| 911 | + * |
|
| 912 | + * @param int $per_page |
|
| 913 | + * @param bool $count |
|
| 914 | + * @param bool $this_month |
|
| 915 | + * @param bool $today |
|
| 916 | + * @return \EE_Registration[]|int |
|
| 917 | + */ |
|
| 918 | + public function get_registrations( |
|
| 919 | + $per_page = 10, |
|
| 920 | + $count = false, |
|
| 921 | + $this_month = false, |
|
| 922 | + $today = false |
|
| 923 | + ) { |
|
| 924 | + if( $this_month ) { |
|
| 925 | + $this->_req_data['status'] = 'month'; |
|
| 926 | + } |
|
| 927 | + if( $today ) { |
|
| 928 | + $this->_req_data['status'] = 'today'; |
|
| 929 | + } |
|
| 930 | + $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
| 931 | + /** |
|
| 932 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 933 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 934 | + * @see EEM_Base::get_all() |
|
| 935 | + */ |
|
| 936 | + $query_params['group_by'] = ''; |
|
| 937 | + |
|
| 938 | + return $count |
|
| 939 | + ? EEM_Registration::instance()->count($query_params) |
|
| 940 | + /** @type EE_Registration[] */ |
|
| 941 | + : EEM_Registration::instance()->get_all($query_params); |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 948 | + * Note: this listens to values on the request for some of the query parameters. |
|
| 949 | + * |
|
| 950 | + * @param array $request |
|
| 951 | + * @param int $per_page |
|
| 952 | + * @param bool $count |
|
| 953 | + * @return array |
|
| 954 | + */ |
|
| 955 | + protected function _get_registration_query_parameters( |
|
| 956 | + $request = array(), |
|
| 957 | + $per_page = 10, |
|
| 958 | + $count = false |
|
| 959 | + ) { |
|
| 960 | + |
|
| 961 | + $query_params = array( |
|
| 962 | + 0 => $this->_get_where_conditions_for_registrations_query( |
|
| 963 | + $request |
|
| 964 | + ), |
|
| 965 | + 'caps' => EEM_Registration::caps_read_admin, |
|
| 966 | + 'default_where_conditions' => 'this_model_only', |
|
| 967 | + ); |
|
| 968 | + if ( ! $count) { |
|
| 969 | + $query_params = array_merge( |
|
| 970 | + $query_params, |
|
| 971 | + $this->_get_orderby_for_registrations_query(), |
|
| 972 | + $this->_get_limit($per_page) |
|
| 973 | + ); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + return $query_params; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + |
|
| 980 | + /** |
|
| 981 | + * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
| 982 | + * |
|
| 983 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 984 | + * @return array |
|
| 985 | + */ |
|
| 986 | + protected function _add_event_id_to_where_conditions(array $request) |
|
| 987 | + { |
|
| 988 | + $where = array(); |
|
| 989 | + if ( ! empty($request['event_id'])) { |
|
| 990 | + $where['EVT_ID'] = absint($request['event_id']); |
|
| 991 | + } |
|
| 992 | + return $where; |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + |
|
| 996 | + /** |
|
| 997 | + * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 998 | + * |
|
| 999 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1000 | + * @return array |
|
| 1001 | + */ |
|
| 1002 | + protected function _add_category_id_to_where_conditions(array $request) |
|
| 1003 | + { |
|
| 1004 | + $where = array(); |
|
| 1005 | + if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
| 1006 | + $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
| 1007 | + } |
|
| 1008 | + return $where; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + |
|
| 1012 | + /** |
|
| 1013 | + * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 1014 | + * |
|
| 1015 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1016 | + * @return array |
|
| 1017 | + */ |
|
| 1018 | + protected function _add_datetime_id_to_where_conditions(array $request) |
|
| 1019 | + { |
|
| 1020 | + $where = array(); |
|
| 1021 | + if ( ! empty($request['datetime_id'])) { |
|
| 1022 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
| 1023 | + } |
|
| 1024 | + if( ! empty($request['DTT_ID'])){ |
|
| 1025 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
| 1026 | + } |
|
| 1027 | + return $where; |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * Adds the correct registration status to the where conditions for the registrations query. |
|
| 1033 | + * |
|
| 1034 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1035 | + * @return array |
|
| 1036 | + */ |
|
| 1037 | + protected function _add_registration_status_to_where_conditions(array $request) |
|
| 1038 | + { |
|
| 1039 | + $where = array(); |
|
| 1040 | + $view = EEH_Array::is_set( $request, 'status', '' ); |
|
| 1041 | + $registration_status = ! empty($request['_reg_status']) |
|
| 1042 | + ? sanitize_text_field($request['_reg_status']) |
|
| 1043 | + : ''; |
|
| 1044 | + |
|
| 1045 | + /* |
|
| 1046 | 1046 | * If filtering by registration status, then we show registrations matching that status. |
| 1047 | 1047 | * If not filtering by specified status, then we show all registrations excluding incomplete registrations UNLESS |
| 1048 | 1048 | * viewing trashed registrations. |
| 1049 | 1049 | */ |
| 1050 | - if ( ! empty($registration_status)) { |
|
| 1051 | - $where['STS_ID'] = $registration_status; |
|
| 1052 | - } else { |
|
| 1053 | - //make sure we exclude incomplete registrations, but only if not trashed. |
|
| 1054 | - if ($view === 'trash') { |
|
| 1055 | - $where['REG_deleted'] = true; |
|
| 1056 | - } else if ($view === 'incomplete') { |
|
| 1057 | - $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 1058 | - } else { |
|
| 1059 | - $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 1060 | - } |
|
| 1061 | - } |
|
| 1062 | - return $where; |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - |
|
| 1066 | - /** |
|
| 1067 | - * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 1068 | - * |
|
| 1069 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1070 | - * @return array |
|
| 1071 | - */ |
|
| 1072 | - protected function _add_date_to_where_conditions(array $request) |
|
| 1073 | - { |
|
| 1074 | - $where = array(); |
|
| 1075 | - $view = EEH_Array::is_set( $request, 'status', '' ); |
|
| 1076 | - $month_range = ! empty($request['month_range']) |
|
| 1077 | - ? sanitize_text_field($request['month_range']) |
|
| 1078 | - : ''; |
|
| 1079 | - $retrieve_for_today = $view === 'today'; |
|
| 1080 | - $retrieve_for_this_month = $view === 'month'; |
|
| 1081 | - |
|
| 1082 | - if ($retrieve_for_today) { |
|
| 1083 | - $now = date('Y-m-d', current_time('timestamp')); |
|
| 1084 | - $where['REG_date'] = array( |
|
| 1085 | - 'BETWEEN', |
|
| 1086 | - array( |
|
| 1087 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1088 | - 'REG_date', |
|
| 1089 | - $now . ' 00:00:00', |
|
| 1090 | - 'Y-m-d H:i:s' |
|
| 1091 | - ), |
|
| 1092 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1093 | - 'REG_date', |
|
| 1094 | - $now . ' 23:59:59', |
|
| 1095 | - 'Y-m-d H:i:s' |
|
| 1096 | - ), |
|
| 1097 | - ), |
|
| 1098 | - ); |
|
| 1099 | - } elseif ($retrieve_for_this_month) { |
|
| 1100 | - $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
| 1101 | - $days_this_month = date('t', current_time('timestamp')); |
|
| 1102 | - $where['REG_date'] = array( |
|
| 1103 | - 'BETWEEN', |
|
| 1104 | - array( |
|
| 1105 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1106 | - 'REG_date', |
|
| 1107 | - $current_year_and_month . '-01 00:00:00', |
|
| 1108 | - 'Y-m-d H:i:s' |
|
| 1109 | - ), |
|
| 1110 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1111 | - 'REG_date', |
|
| 1112 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1113 | - 'Y-m-d H:i:s' |
|
| 1114 | - ), |
|
| 1115 | - ), |
|
| 1116 | - ); |
|
| 1117 | - } elseif ($month_range) { |
|
| 1118 | - $pieces = explode(' ', $month_range, 3); |
|
| 1119 | - $month_requested = ! empty($pieces[0]) |
|
| 1120 | - ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 1121 | - : ''; |
|
| 1122 | - $year_requested = ! empty($pieces[1]) |
|
| 1123 | - ? $pieces[1] |
|
| 1124 | - : ''; |
|
| 1125 | - //if there is not a month or year then we can't go further |
|
| 1126 | - if ($month_requested && $year_requested) { |
|
| 1127 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1128 | - $where['REG_date'] = array( |
|
| 1129 | - 'BETWEEN', |
|
| 1130 | - array( |
|
| 1131 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1132 | - 'REG_date', |
|
| 1133 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1134 | - 'Y-m-d H:i:s' |
|
| 1135 | - ), |
|
| 1136 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1137 | - 'REG_date', |
|
| 1138 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1139 | - 'Y-m-d H:i:s' |
|
| 1140 | - ), |
|
| 1141 | - ), |
|
| 1142 | - ); |
|
| 1143 | - } |
|
| 1144 | - } |
|
| 1145 | - return $where; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - /** |
|
| 1150 | - * Adds any provided search restraints to the where conditions for the registrations query |
|
| 1151 | - * |
|
| 1152 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1153 | - * @return array |
|
| 1154 | - */ |
|
| 1155 | - protected function _add_search_to_where_conditions(array $request) |
|
| 1156 | - { |
|
| 1157 | - $where = array(); |
|
| 1158 | - if ( ! empty($request['s'])) { |
|
| 1159 | - $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1160 | - $where['OR'] = array( |
|
| 1161 | - 'Event.EVT_name' => array('LIKE', $search_string), |
|
| 1162 | - 'Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1163 | - 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1164 | - 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1165 | - 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1166 | - 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1167 | - 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1168 | - 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1169 | - 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1170 | - 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1171 | - 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1172 | - 'REG_final_price' => array('LIKE', $search_string), |
|
| 1173 | - 'REG_code' => array('LIKE', $search_string), |
|
| 1174 | - 'REG_count' => array('LIKE', $search_string), |
|
| 1175 | - 'REG_group_size' => array('LIKE', $search_string), |
|
| 1176 | - 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1177 | - 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1178 | - 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 1179 | - ); |
|
| 1180 | - } |
|
| 1181 | - return $where; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * Sets up the where conditions for the registrations query. |
|
| 1187 | - * |
|
| 1188 | - * @param array $request |
|
| 1189 | - * @return array |
|
| 1190 | - */ |
|
| 1191 | - protected function _get_where_conditions_for_registrations_query($request) |
|
| 1192 | - { |
|
| 1193 | - return array_merge( |
|
| 1194 | - $this->_add_event_id_to_where_conditions($request), |
|
| 1195 | - $this->_add_category_id_to_where_conditions($request), |
|
| 1196 | - $this->_add_datetime_id_to_where_conditions($request), |
|
| 1197 | - $this->_add_registration_status_to_where_conditions($request), |
|
| 1198 | - $this->_add_date_to_where_conditions($request), |
|
| 1199 | - $this->_add_search_to_where_conditions($request) |
|
| 1200 | - ); |
|
| 1201 | - } |
|
| 1202 | - |
|
| 1203 | - |
|
| 1204 | - /** |
|
| 1205 | - * Sets up the orderby for the registrations query. |
|
| 1206 | - * |
|
| 1207 | - * @return array |
|
| 1208 | - */ |
|
| 1209 | - protected function _get_orderby_for_registrations_query() |
|
| 1210 | - { |
|
| 1211 | - $orderby_field = ! empty($this->_req_data['orderby']) |
|
| 1212 | - ? sanitize_text_field($this->_req_data['orderby']) |
|
| 1213 | - : ''; |
|
| 1214 | - switch ($orderby_field) { |
|
| 1215 | - case '_REG_ID': |
|
| 1216 | - $orderby_field = 'REG_ID'; |
|
| 1217 | - break; |
|
| 1218 | - case '_Reg_status': |
|
| 1219 | - $orderby_field = 'STS_ID'; |
|
| 1220 | - break; |
|
| 1221 | - case 'ATT_fname': |
|
| 1222 | - $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
| 1223 | - break; |
|
| 1224 | - case 'ATT_lname' : |
|
| 1225 | - $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
| 1226 | - break; |
|
| 1227 | - case 'event_name': |
|
| 1228 | - $orderby_field = 'Event.EVT_name'; |
|
| 1229 | - break; |
|
| 1230 | - case 'DTT_EVT_start': |
|
| 1231 | - $orderby_field = 'Event.Datetime.DTT_EVT_start'; |
|
| 1232 | - break; |
|
| 1233 | - default: //'REG_date' |
|
| 1234 | - $orderby_field = 'REG_date'; |
|
| 1235 | - } |
|
| 1236 | - |
|
| 1237 | - //order |
|
| 1238 | - $order = ! empty($this->_req_data['order']) |
|
| 1239 | - ? sanitize_text_field($this->_req_data['order']) |
|
| 1240 | - : 'DESC'; |
|
| 1241 | - |
|
| 1242 | - //mutate orderby_field |
|
| 1243 | - $orderby_field = array_combine( |
|
| 1244 | - (array) $orderby_field, |
|
| 1245 | - array_fill(0, count($orderby_field), $order) |
|
| 1246 | - ); |
|
| 1247 | - return array('order_by' => $orderby_field); |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - |
|
| 1251 | - /** |
|
| 1252 | - * Sets up the limit for the registrations query. |
|
| 1253 | - * |
|
| 1254 | - * @param $per_page |
|
| 1255 | - * @return array |
|
| 1256 | - */ |
|
| 1257 | - protected function _get_limit($per_page) |
|
| 1258 | - { |
|
| 1259 | - $current_page = ! empty($this->_req_data['paged']) |
|
| 1260 | - ? absint($this->_req_data['paged']) |
|
| 1261 | - : 1; |
|
| 1262 | - $per_page = ! empty($this->_req_data['perpage']) |
|
| 1263 | - ? $this->_req_data['perpage'] |
|
| 1264 | - : $per_page; |
|
| 1265 | - |
|
| 1266 | - //-1 means return all results so get out if that's set. |
|
| 1267 | - if ((int)$per_page === -1) { |
|
| 1268 | - return array(); |
|
| 1269 | - } |
|
| 1270 | - $per_page = absint($per_page); |
|
| 1271 | - $offset = ($current_page - 1) * $per_page; |
|
| 1272 | - return array('limit' => array($offset, $per_page)); |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - |
|
| 1276 | - public function get_registration_status_array() |
|
| 1277 | - { |
|
| 1278 | - return self::$_reg_status; |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - |
|
| 1282 | - |
|
| 1283 | - |
|
| 1284 | - /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1285 | - /** |
|
| 1286 | - * generates HTML for the View Registration Details Admin page |
|
| 1287 | - * |
|
| 1288 | - * @access protected |
|
| 1289 | - * @return void |
|
| 1290 | - */ |
|
| 1291 | - protected function _registration_details() |
|
| 1292 | - { |
|
| 1293 | - $this->_template_args = array(); |
|
| 1294 | - $this->_set_registration_object(); |
|
| 1295 | - if (is_object($this->_registration)) { |
|
| 1296 | - $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 1297 | - : EE_Transaction::new_instance(); |
|
| 1298 | - $this->_session = $transaction->session_data(); |
|
| 1299 | - $event_id = $this->_registration->event_ID(); |
|
| 1300 | - $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1301 | - $this->_template_args['reg_nmbr']['label'] = __('Registration Number', 'event_espresso'); |
|
| 1302 | - $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1303 | - $this->_template_args['reg_datetime']['label'] = __('Date', 'event_espresso'); |
|
| 1304 | - $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1305 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1306 | - // link back to overview |
|
| 1307 | - $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1308 | - $this->_template_args['registration'] = $this->_registration; |
|
| 1309 | - $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1310 | - 'action' => 'default', |
|
| 1311 | - 'event_id' => $event_id, |
|
| 1312 | - ), REG_ADMIN_URL); |
|
| 1313 | - $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1314 | - 'action' => 'default', |
|
| 1315 | - 'EVT_ID' => $event_id, |
|
| 1316 | - 'page' => 'espresso_transactions', |
|
| 1317 | - ), admin_url('admin.php')); |
|
| 1318 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1319 | - 'page' => 'espresso_events', |
|
| 1320 | - 'action' => 'edit', |
|
| 1321 | - 'post' => $event_id, |
|
| 1322 | - ), admin_url('admin.php')); |
|
| 1323 | - //next and previous links |
|
| 1324 | - $next_reg = $this->_registration->next(null, array(), 'REG_ID'); |
|
| 1325 | - $this->_template_args['next_registration'] = $next_reg |
|
| 1326 | - ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1327 | - 'action' => 'view_registration', |
|
| 1328 | - '_REG_ID' => $next_reg['REG_ID'], |
|
| 1329 | - ), REG_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : ''; |
|
| 1330 | - $previous_reg = $this->_registration->previous(null, array(), 'REG_ID'); |
|
| 1331 | - $this->_template_args['previous_registration'] = $previous_reg |
|
| 1332 | - ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1333 | - 'action' => 'view_registration', |
|
| 1334 | - '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1335 | - ), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : ''; |
|
| 1336 | - // grab header |
|
| 1337 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1338 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1339 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
| 1340 | - $this->_template_args, true); |
|
| 1341 | - } else { |
|
| 1342 | - $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
| 1343 | - } |
|
| 1344 | - // the details template wrapper |
|
| 1345 | - $this->display_admin_page_with_sidebar(); |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - |
|
| 1349 | - protected function _registration_details_metaboxes() |
|
| 1350 | - { |
|
| 1351 | - do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1352 | - $this->_set_registration_object(); |
|
| 1353 | - $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1354 | - add_meta_box('edit-reg-status-mbox', __('Registration Status', 'event_espresso'), |
|
| 1355 | - array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1356 | - add_meta_box('edit-reg-details-mbox', __('Registration Details', 'event_espresso'), |
|
| 1357 | - array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1358 | - if ($attendee instanceof EE_Attendee |
|
| 1359 | - && EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox') |
|
| 1360 | - ) { |
|
| 1361 | - add_meta_box('edit-reg-questions-mbox', __('Registration Form Answers', 'event_espresso'), |
|
| 1362 | - array($this, '_reg_questions_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1363 | - } |
|
| 1364 | - add_meta_box('edit-reg-registrant-mbox', __('Contact Details', 'event_espresso'), |
|
| 1365 | - array($this, '_reg_registrant_side_meta_box'), $this->wp_page_slug, 'side', 'high'); |
|
| 1366 | - if ($this->_registration->group_size() > 1) { |
|
| 1367 | - add_meta_box('edit-reg-attendees-mbox', __('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1368 | - array($this, '_reg_attendees_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1369 | - } |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - /** |
|
| 1374 | - * set_reg_status_buttons_metabox |
|
| 1375 | - * |
|
| 1376 | - * @access protected |
|
| 1377 | - * @return string |
|
| 1378 | - * @throws \EE_Error |
|
| 1379 | - */ |
|
| 1380 | - public function set_reg_status_buttons_metabox() |
|
| 1381 | - { |
|
| 1382 | - $this->_set_registration_object(); |
|
| 1383 | - $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1384 | - echo $change_reg_status_form->form_open(self::add_query_args_and_nonce(array( |
|
| 1385 | - 'action' => 'change_reg_status', |
|
| 1386 | - ), REG_ADMIN_URL)); |
|
| 1387 | - echo $change_reg_status_form->get_html(); |
|
| 1388 | - echo $change_reg_status_form->form_close(); |
|
| 1389 | - } |
|
| 1390 | - |
|
| 1391 | - |
|
| 1392 | - /** |
|
| 1393 | - * @return EE_Form_Section_Proper |
|
| 1394 | - */ |
|
| 1395 | - protected function _generate_reg_status_change_form() |
|
| 1396 | - { |
|
| 1397 | - return new EE_Form_Section_Proper(array( |
|
| 1398 | - 'name' => 'reg_status_change_form', |
|
| 1399 | - 'html_id' => 'reg-status-change-form', |
|
| 1400 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1401 | - 'subsections' => array( |
|
| 1402 | - 'return' => new EE_Hidden_Input(array( |
|
| 1403 | - 'name' => 'return', |
|
| 1404 | - 'default' => 'view_registration', |
|
| 1405 | - )), |
|
| 1406 | - 'REG_ID' => new EE_Hidden_Input(array( |
|
| 1407 | - 'name' => 'REG_ID', |
|
| 1408 | - 'default' => $this->_registration->ID(), |
|
| 1409 | - )), |
|
| 1410 | - 'current_status' => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status', |
|
| 1411 | - 'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(), |
|
| 1412 | - '', 'status-' . $this->_registration->status_ID(), |
|
| 1413 | - 'line-height: 1em; font-size: 1.5em; font-weight: bold;')))), |
|
| 1414 | - 'reg_status' => new EE_Select_Input($this->_get_reg_statuses(), array( |
|
| 1415 | - 'html_label_text' => __('Change Registration Status to', 'event_espresso'), |
|
| 1416 | - 'default' => $this->_registration->status_ID(), |
|
| 1417 | - )), |
|
| 1418 | - 'send_notifications' => new EE_Yes_No_Input(array( |
|
| 1419 | - 'html_label_text' => __('Send Related Messages', 'event_espresso'), |
|
| 1420 | - 'default' => false, |
|
| 1421 | - 'html_help_text' => __('If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1422 | - 'event_espresso'), |
|
| 1423 | - )), |
|
| 1424 | - 'submit' => new EE_Submit_Input(array( |
|
| 1425 | - 'html_class' => 'button-primary', |
|
| 1426 | - 'html_label_text' => ' ', |
|
| 1427 | - 'default' => __('Update Registration Status', 'event_espresso'), |
|
| 1428 | - )), |
|
| 1429 | - ), |
|
| 1430 | - )); |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - |
|
| 1434 | - |
|
| 1435 | - /** |
|
| 1436 | - * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1437 | - * |
|
| 1438 | - * @return array |
|
| 1439 | - */ |
|
| 1440 | - protected function _get_reg_statuses() |
|
| 1441 | - { |
|
| 1442 | - $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
| 1443 | - unset ($reg_status_array[EEM_Registration::status_id_incomplete]); |
|
| 1444 | - // get current reg status |
|
| 1445 | - $current_status = $this->_registration->status_ID(); |
|
| 1446 | - // is registration for free event? This will determine whether to display the pending payment option |
|
| 1447 | - if ($current_status != EEM_Registration::status_id_pending_payment |
|
| 1448 | - && $this->_registration->transaction() |
|
| 1449 | - ->is_free() |
|
| 1450 | - ) { |
|
| 1451 | - unset($reg_status_array[EEM_Registration::status_id_pending_payment]); |
|
| 1452 | - } |
|
| 1453 | - return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1454 | - } |
|
| 1455 | - |
|
| 1456 | - |
|
| 1457 | - /** |
|
| 1458 | - * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1459 | - * |
|
| 1460 | - * @param bool $status REG status given for changing registrations to. |
|
| 1461 | - * @param bool $notify Whether to send messages notifications or not. |
|
| 1462 | - * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1463 | - */ |
|
| 1464 | - protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1465 | - { |
|
| 1466 | - if (isset($this->_req_data['reg_status_change_form'])) { |
|
| 1467 | - $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 1468 | - ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1469 | - } else { |
|
| 1470 | - $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
| 1471 | - } |
|
| 1472 | - $success = $this->_set_registration_status($REG_IDs, $status); |
|
| 1473 | - //notify? |
|
| 1474 | - if ($success |
|
| 1475 | - && $notify |
|
| 1476 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 1477 | - 'espresso_registrations_resend_registration') |
|
| 1478 | - ) { |
|
| 1479 | - $this->_process_resend_registration(); |
|
| 1480 | - } |
|
| 1481 | - return $success; |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - |
|
| 1485 | - /** |
|
| 1486 | - * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1487 | - * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1488 | - * |
|
| 1489 | - * @param array $REG_IDs |
|
| 1490 | - * @param bool $status |
|
| 1491 | - * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1492 | - * the array of updated registrations). |
|
| 1493 | - */ |
|
| 1494 | - protected function _set_registration_status($REG_IDs = array(), $status = false) |
|
| 1495 | - { |
|
| 1496 | - $success = false; |
|
| 1497 | - // typecast $REG_IDs |
|
| 1498 | - $REG_IDs = (array)$REG_IDs; |
|
| 1499 | - if ( ! empty($REG_IDs)) { |
|
| 1500 | - $success = true; |
|
| 1501 | - // set default status if none is passed |
|
| 1502 | - $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
| 1503 | - // sanitize $REG_IDs |
|
| 1504 | - $REG_IDs = array_filter($REG_IDs, 'absint'); |
|
| 1505 | - //loop through REG_ID's and change status |
|
| 1506 | - foreach ($REG_IDs as $REG_ID) { |
|
| 1507 | - $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1508 | - if ($registration instanceof EE_Registration) { |
|
| 1509 | - $registration->set_status($status); |
|
| 1510 | - $result = $registration->save(); |
|
| 1511 | - // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1512 | - $success = $result !== false ? $success : false; |
|
| 1513 | - } |
|
| 1514 | - } |
|
| 1515 | - } |
|
| 1516 | - //reset _req_data['_REG_ID'] for any potential future messages notifications |
|
| 1517 | - $this->_req_data['_REG_ID'] = $REG_IDs; |
|
| 1518 | - //return $success and processed registrations |
|
| 1519 | - return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - |
|
| 1523 | - /** |
|
| 1524 | - * Common logic for setting up success message and redirecting to appropriate route |
|
| 1525 | - * |
|
| 1526 | - * @param string $STS_ID status id for the registration changed to |
|
| 1527 | - * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1528 | - * @return void |
|
| 1529 | - */ |
|
| 1530 | - protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1531 | - { |
|
| 1532 | - $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1533 | - : array('success' => false); |
|
| 1534 | - $success = isset($result['success']) && $result['success']; |
|
| 1535 | - //setup success message |
|
| 1536 | - if ($success) { |
|
| 1537 | - if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1538 | - $msg = sprintf(__('Registration status has been set to %s', 'event_espresso'), |
|
| 1539 | - EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1540 | - } else { |
|
| 1541 | - $msg = sprintf(__('Registrations have been set to %s.', 'event_espresso'), |
|
| 1542 | - EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1543 | - } |
|
| 1544 | - EE_Error::add_success($msg); |
|
| 1545 | - } else { |
|
| 1546 | - EE_Error::add_error(__('Something went wrong, and the status was not changed', 'event_espresso'), __FILE__, |
|
| 1547 | - __LINE__, __FUNCTION__); |
|
| 1548 | - } |
|
| 1549 | - if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
| 1550 | - $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
| 1551 | - } else { |
|
| 1552 | - $route = array('action' => 'default'); |
|
| 1553 | - } |
|
| 1554 | - //unset nonces |
|
| 1555 | - foreach ($this->_req_data as $ref => $value) { |
|
| 1556 | - if (strpos($ref, 'nonce') !== false) { |
|
| 1557 | - unset($this->_req_data[$ref]); |
|
| 1558 | - continue; |
|
| 1559 | - } |
|
| 1560 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 1561 | - $this->_req_data[$ref] = $value; |
|
| 1562 | - } |
|
| 1563 | - //merge request vars so that the reloaded list table contains any existing filter query params |
|
| 1564 | - $route = array_merge($this->_req_data, $route); |
|
| 1565 | - $this->_redirect_after_action($success, '', '', $route, true); |
|
| 1566 | - } |
|
| 1567 | - |
|
| 1568 | - |
|
| 1569 | - /** |
|
| 1570 | - * incoming reg status change from reg details page. |
|
| 1571 | - * |
|
| 1572 | - * @return void |
|
| 1573 | - */ |
|
| 1574 | - protected function _change_reg_status() |
|
| 1575 | - { |
|
| 1576 | - $this->_req_data['return'] = 'view_registration'; |
|
| 1577 | - //set notify based on whether the send notifications toggle is set or not |
|
| 1578 | - $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
| 1579 | - //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
| 1580 | - $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
| 1581 | - ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
| 1582 | - switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
| 1583 | - case EEM_Registration::status_id_approved : |
|
| 1584 | - case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') : |
|
| 1585 | - $this->approve_registration($notify); |
|
| 1586 | - break; |
|
| 1587 | - case EEM_Registration::status_id_pending_payment : |
|
| 1588 | - case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') : |
|
| 1589 | - $this->pending_registration($notify); |
|
| 1590 | - break; |
|
| 1591 | - case EEM_Registration::status_id_not_approved : |
|
| 1592 | - case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') : |
|
| 1593 | - $this->not_approve_registration($notify); |
|
| 1594 | - break; |
|
| 1595 | - case EEM_Registration::status_id_declined : |
|
| 1596 | - case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') : |
|
| 1597 | - $this->decline_registration($notify); |
|
| 1598 | - break; |
|
| 1599 | - case EEM_Registration::status_id_cancelled : |
|
| 1600 | - case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') : |
|
| 1601 | - $this->cancel_registration($notify); |
|
| 1602 | - break; |
|
| 1603 | - case EEM_Registration::status_id_wait_list : |
|
| 1604 | - case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') : |
|
| 1605 | - $this->waitlist_registration($notify); |
|
| 1606 | - break; |
|
| 1607 | - case EEM_Registration::status_id_incomplete : |
|
| 1608 | - default : |
|
| 1609 | - $result['success'] = false; |
|
| 1610 | - unset($this->_req_data['return']); |
|
| 1611 | - $this->_reg_status_change_return('', false); |
|
| 1612 | - break; |
|
| 1613 | - } |
|
| 1614 | - } |
|
| 1615 | - |
|
| 1616 | - |
|
| 1617 | - /** |
|
| 1618 | - * approve_registration |
|
| 1619 | - * |
|
| 1620 | - * @access protected |
|
| 1621 | - * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 1622 | - * @return void |
|
| 1623 | - */ |
|
| 1624 | - protected function approve_registration($notify = false) |
|
| 1625 | - { |
|
| 1626 | - $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * decline_registration |
|
| 1632 | - * |
|
| 1633 | - * @access protected |
|
| 1634 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1635 | - * @return void |
|
| 1636 | - */ |
|
| 1637 | - protected function decline_registration($notify = false) |
|
| 1638 | - { |
|
| 1639 | - $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 1640 | - } |
|
| 1641 | - |
|
| 1642 | - |
|
| 1643 | - /** |
|
| 1644 | - * cancel_registration |
|
| 1645 | - * |
|
| 1646 | - * @access protected |
|
| 1647 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1648 | - * @return void |
|
| 1649 | - */ |
|
| 1650 | - protected function cancel_registration($notify = false) |
|
| 1651 | - { |
|
| 1652 | - $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 1653 | - } |
|
| 1654 | - |
|
| 1655 | - |
|
| 1656 | - /** |
|
| 1657 | - * not_approve_registration |
|
| 1658 | - * |
|
| 1659 | - * @access protected |
|
| 1660 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1661 | - * @return void |
|
| 1662 | - */ |
|
| 1663 | - protected function not_approve_registration($notify = false) |
|
| 1664 | - { |
|
| 1665 | - $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - |
|
| 1669 | - /** |
|
| 1670 | - * decline_registration |
|
| 1671 | - * |
|
| 1672 | - * @access protected |
|
| 1673 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1674 | - * @return void |
|
| 1675 | - */ |
|
| 1676 | - protected function pending_registration($notify = false) |
|
| 1677 | - { |
|
| 1678 | - $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 1679 | - } |
|
| 1680 | - |
|
| 1681 | - |
|
| 1682 | - /** |
|
| 1683 | - * waitlist_registration |
|
| 1684 | - * |
|
| 1685 | - * @access protected |
|
| 1686 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1687 | - * @return void |
|
| 1688 | - */ |
|
| 1689 | - protected function waitlist_registration($notify = false) |
|
| 1690 | - { |
|
| 1691 | - $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - |
|
| 1695 | - /** |
|
| 1696 | - * generates HTML for the Registration main meta box |
|
| 1697 | - * |
|
| 1698 | - * @access public |
|
| 1699 | - * @return void |
|
| 1700 | - */ |
|
| 1701 | - public function _reg_details_meta_box() |
|
| 1702 | - { |
|
| 1703 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1704 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 1705 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
| 1706 | - $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 1707 | - : EE_Transaction::new_instance(); |
|
| 1708 | - $this->_session = $transaction->session_data(); |
|
| 1709 | - $filters = new EE_Line_Item_Filter_Collection(); |
|
| 1710 | - //$filters->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
| 1711 | - $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 1712 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, |
|
| 1713 | - $transaction->total_line_item()); |
|
| 1714 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 1715 | - $line_item_display = new EE_Line_Item_Display('reg_admin_table', |
|
| 1716 | - 'EE_Admin_Table_Registration_Line_Item_Display_Strategy'); |
|
| 1717 | - $this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree, |
|
| 1718 | - array('EE_Registration' => $this->_registration)); |
|
| 1719 | - $attendee = $this->_registration->attendee(); |
|
| 1720 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 1721 | - 'espresso_transactions_view_transaction') |
|
| 1722 | - ) { |
|
| 1723 | - $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1724 | - 'action' => 'view_transaction', |
|
| 1725 | - 'TXN_ID' => $transaction->ID(), |
|
| 1726 | - ), TXN_ADMIN_URL), esc_html__(' View Transaction'), 'button secondary-button right', |
|
| 1727 | - 'dashicons dashicons-cart'); |
|
| 1728 | - } else { |
|
| 1729 | - $this->_template_args['view_transaction_button'] = ''; |
|
| 1730 | - } |
|
| 1731 | - if ($attendee instanceof EE_Attendee |
|
| 1732 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 1733 | - 'espresso_registrations_resend_registration') |
|
| 1734 | - ) { |
|
| 1735 | - $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1736 | - 'action' => 'resend_registration', |
|
| 1737 | - '_REG_ID' => $this->_registration->ID(), |
|
| 1738 | - 'redirect_to' => 'view_registration', |
|
| 1739 | - ), REG_ADMIN_URL), esc_html__(' Resend Registration'), 'button secondary-button right', |
|
| 1740 | - 'dashicons dashicons-email-alt'); |
|
| 1741 | - } else { |
|
| 1742 | - $this->_template_args['resend_registration_button'] = ''; |
|
| 1743 | - } |
|
| 1744 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1745 | - $payment = $transaction->get_first_related('Payment'); |
|
| 1746 | - $payment = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment; |
|
| 1747 | - $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 1748 | - $payment_method = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance() |
|
| 1749 | - : $payment_method; |
|
| 1750 | - $reg_details = array( |
|
| 1751 | - 'payment_method' => $payment_method->name(), |
|
| 1752 | - 'response_msg' => $payment->gateway_response(), |
|
| 1753 | - 'registration_id' => $this->_registration->get('REG_code'), |
|
| 1754 | - 'registration_session' => $this->_registration->session_ID(), |
|
| 1755 | - 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 1756 | - 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 1757 | - ); |
|
| 1758 | - if (isset($reg_details['registration_id'])) { |
|
| 1759 | - $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 1760 | - $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso'); |
|
| 1761 | - $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 1762 | - } |
|
| 1763 | - if (isset($reg_details['payment_method'])) { |
|
| 1764 | - $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 1765 | - $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method', |
|
| 1766 | - 'event_espresso'); |
|
| 1767 | - $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 1768 | - $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 1769 | - $this->_template_args['reg_details']['response_msg']['label'] = __('Payment method response', |
|
| 1770 | - 'event_espresso'); |
|
| 1771 | - $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 1772 | - } |
|
| 1773 | - $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 1774 | - $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session', |
|
| 1775 | - 'event_espresso'); |
|
| 1776 | - $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 1777 | - $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 1778 | - $this->_template_args['reg_details']['ip_address']['label'] = __('Registration placed from IP', |
|
| 1779 | - 'event_espresso'); |
|
| 1780 | - $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 1781 | - $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 1782 | - $this->_template_args['reg_details']['user_agent']['label'] = __('Registrant User Agent', |
|
| 1783 | - 'event_espresso'); |
|
| 1784 | - $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 1785 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1786 | - 'action' => 'default', |
|
| 1787 | - 'event_id' => $this->_registration->event_ID(), |
|
| 1788 | - ), REG_ADMIN_URL); |
|
| 1789 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1790 | - $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 1791 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 1792 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1793 | - } |
|
| 1794 | - |
|
| 1795 | - |
|
| 1796 | - /** |
|
| 1797 | - * generates HTML for the Registration Questions meta box. |
|
| 1798 | - * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 1799 | - * otherwise uses new forms system |
|
| 1800 | - * |
|
| 1801 | - * @access public |
|
| 1802 | - * @return void |
|
| 1803 | - */ |
|
| 1804 | - public function _reg_questions_meta_box() |
|
| 1805 | - { |
|
| 1806 | - //allow someone to override this method entirely |
|
| 1807 | - if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, |
|
| 1808 | - $this->_registration)) { |
|
| 1809 | - $form = $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 1810 | - $this->_template_args['att_questions'] = count($form->subforms()) > 0 ? $form->get_html_and_js() : ''; |
|
| 1811 | - $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 1812 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1813 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 1814 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1815 | - } |
|
| 1816 | - } |
|
| 1817 | - |
|
| 1818 | - |
|
| 1819 | - /** |
|
| 1820 | - * form_before_question_group |
|
| 1821 | - * |
|
| 1822 | - * @deprecated as of 4.8.32.rc.000 |
|
| 1823 | - * @access public |
|
| 1824 | - * @param string $output |
|
| 1825 | - * @return string |
|
| 1826 | - */ |
|
| 1827 | - public function form_before_question_group($output) |
|
| 1828 | - { |
|
| 1829 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1830 | - __('This method would have been protected but was used on a filter callback' |
|
| 1831 | - . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1832 | - '4.8.32.rc.000'); |
|
| 1833 | - return ' |
|
| 1050 | + if ( ! empty($registration_status)) { |
|
| 1051 | + $where['STS_ID'] = $registration_status; |
|
| 1052 | + } else { |
|
| 1053 | + //make sure we exclude incomplete registrations, but only if not trashed. |
|
| 1054 | + if ($view === 'trash') { |
|
| 1055 | + $where['REG_deleted'] = true; |
|
| 1056 | + } else if ($view === 'incomplete') { |
|
| 1057 | + $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 1058 | + } else { |
|
| 1059 | + $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 1060 | + } |
|
| 1061 | + } |
|
| 1062 | + return $where; |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + |
|
| 1066 | + /** |
|
| 1067 | + * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 1068 | + * |
|
| 1069 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1070 | + * @return array |
|
| 1071 | + */ |
|
| 1072 | + protected function _add_date_to_where_conditions(array $request) |
|
| 1073 | + { |
|
| 1074 | + $where = array(); |
|
| 1075 | + $view = EEH_Array::is_set( $request, 'status', '' ); |
|
| 1076 | + $month_range = ! empty($request['month_range']) |
|
| 1077 | + ? sanitize_text_field($request['month_range']) |
|
| 1078 | + : ''; |
|
| 1079 | + $retrieve_for_today = $view === 'today'; |
|
| 1080 | + $retrieve_for_this_month = $view === 'month'; |
|
| 1081 | + |
|
| 1082 | + if ($retrieve_for_today) { |
|
| 1083 | + $now = date('Y-m-d', current_time('timestamp')); |
|
| 1084 | + $where['REG_date'] = array( |
|
| 1085 | + 'BETWEEN', |
|
| 1086 | + array( |
|
| 1087 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1088 | + 'REG_date', |
|
| 1089 | + $now . ' 00:00:00', |
|
| 1090 | + 'Y-m-d H:i:s' |
|
| 1091 | + ), |
|
| 1092 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1093 | + 'REG_date', |
|
| 1094 | + $now . ' 23:59:59', |
|
| 1095 | + 'Y-m-d H:i:s' |
|
| 1096 | + ), |
|
| 1097 | + ), |
|
| 1098 | + ); |
|
| 1099 | + } elseif ($retrieve_for_this_month) { |
|
| 1100 | + $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
| 1101 | + $days_this_month = date('t', current_time('timestamp')); |
|
| 1102 | + $where['REG_date'] = array( |
|
| 1103 | + 'BETWEEN', |
|
| 1104 | + array( |
|
| 1105 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1106 | + 'REG_date', |
|
| 1107 | + $current_year_and_month . '-01 00:00:00', |
|
| 1108 | + 'Y-m-d H:i:s' |
|
| 1109 | + ), |
|
| 1110 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1111 | + 'REG_date', |
|
| 1112 | + $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1113 | + 'Y-m-d H:i:s' |
|
| 1114 | + ), |
|
| 1115 | + ), |
|
| 1116 | + ); |
|
| 1117 | + } elseif ($month_range) { |
|
| 1118 | + $pieces = explode(' ', $month_range, 3); |
|
| 1119 | + $month_requested = ! empty($pieces[0]) |
|
| 1120 | + ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 1121 | + : ''; |
|
| 1122 | + $year_requested = ! empty($pieces[1]) |
|
| 1123 | + ? $pieces[1] |
|
| 1124 | + : ''; |
|
| 1125 | + //if there is not a month or year then we can't go further |
|
| 1126 | + if ($month_requested && $year_requested) { |
|
| 1127 | + $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1128 | + $where['REG_date'] = array( |
|
| 1129 | + 'BETWEEN', |
|
| 1130 | + array( |
|
| 1131 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1132 | + 'REG_date', |
|
| 1133 | + $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1134 | + 'Y-m-d H:i:s' |
|
| 1135 | + ), |
|
| 1136 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1137 | + 'REG_date', |
|
| 1138 | + $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1139 | + 'Y-m-d H:i:s' |
|
| 1140 | + ), |
|
| 1141 | + ), |
|
| 1142 | + ); |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + return $where; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + /** |
|
| 1150 | + * Adds any provided search restraints to the where conditions for the registrations query |
|
| 1151 | + * |
|
| 1152 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1153 | + * @return array |
|
| 1154 | + */ |
|
| 1155 | + protected function _add_search_to_where_conditions(array $request) |
|
| 1156 | + { |
|
| 1157 | + $where = array(); |
|
| 1158 | + if ( ! empty($request['s'])) { |
|
| 1159 | + $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1160 | + $where['OR'] = array( |
|
| 1161 | + 'Event.EVT_name' => array('LIKE', $search_string), |
|
| 1162 | + 'Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1163 | + 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1164 | + 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1165 | + 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1166 | + 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1167 | + 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1168 | + 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1169 | + 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1170 | + 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1171 | + 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1172 | + 'REG_final_price' => array('LIKE', $search_string), |
|
| 1173 | + 'REG_code' => array('LIKE', $search_string), |
|
| 1174 | + 'REG_count' => array('LIKE', $search_string), |
|
| 1175 | + 'REG_group_size' => array('LIKE', $search_string), |
|
| 1176 | + 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1177 | + 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1178 | + 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 1179 | + ); |
|
| 1180 | + } |
|
| 1181 | + return $where; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * Sets up the where conditions for the registrations query. |
|
| 1187 | + * |
|
| 1188 | + * @param array $request |
|
| 1189 | + * @return array |
|
| 1190 | + */ |
|
| 1191 | + protected function _get_where_conditions_for_registrations_query($request) |
|
| 1192 | + { |
|
| 1193 | + return array_merge( |
|
| 1194 | + $this->_add_event_id_to_where_conditions($request), |
|
| 1195 | + $this->_add_category_id_to_where_conditions($request), |
|
| 1196 | + $this->_add_datetime_id_to_where_conditions($request), |
|
| 1197 | + $this->_add_registration_status_to_where_conditions($request), |
|
| 1198 | + $this->_add_date_to_where_conditions($request), |
|
| 1199 | + $this->_add_search_to_where_conditions($request) |
|
| 1200 | + ); |
|
| 1201 | + } |
|
| 1202 | + |
|
| 1203 | + |
|
| 1204 | + /** |
|
| 1205 | + * Sets up the orderby for the registrations query. |
|
| 1206 | + * |
|
| 1207 | + * @return array |
|
| 1208 | + */ |
|
| 1209 | + protected function _get_orderby_for_registrations_query() |
|
| 1210 | + { |
|
| 1211 | + $orderby_field = ! empty($this->_req_data['orderby']) |
|
| 1212 | + ? sanitize_text_field($this->_req_data['orderby']) |
|
| 1213 | + : ''; |
|
| 1214 | + switch ($orderby_field) { |
|
| 1215 | + case '_REG_ID': |
|
| 1216 | + $orderby_field = 'REG_ID'; |
|
| 1217 | + break; |
|
| 1218 | + case '_Reg_status': |
|
| 1219 | + $orderby_field = 'STS_ID'; |
|
| 1220 | + break; |
|
| 1221 | + case 'ATT_fname': |
|
| 1222 | + $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
| 1223 | + break; |
|
| 1224 | + case 'ATT_lname' : |
|
| 1225 | + $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
| 1226 | + break; |
|
| 1227 | + case 'event_name': |
|
| 1228 | + $orderby_field = 'Event.EVT_name'; |
|
| 1229 | + break; |
|
| 1230 | + case 'DTT_EVT_start': |
|
| 1231 | + $orderby_field = 'Event.Datetime.DTT_EVT_start'; |
|
| 1232 | + break; |
|
| 1233 | + default: //'REG_date' |
|
| 1234 | + $orderby_field = 'REG_date'; |
|
| 1235 | + } |
|
| 1236 | + |
|
| 1237 | + //order |
|
| 1238 | + $order = ! empty($this->_req_data['order']) |
|
| 1239 | + ? sanitize_text_field($this->_req_data['order']) |
|
| 1240 | + : 'DESC'; |
|
| 1241 | + |
|
| 1242 | + //mutate orderby_field |
|
| 1243 | + $orderby_field = array_combine( |
|
| 1244 | + (array) $orderby_field, |
|
| 1245 | + array_fill(0, count($orderby_field), $order) |
|
| 1246 | + ); |
|
| 1247 | + return array('order_by' => $orderby_field); |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + |
|
| 1251 | + /** |
|
| 1252 | + * Sets up the limit for the registrations query. |
|
| 1253 | + * |
|
| 1254 | + * @param $per_page |
|
| 1255 | + * @return array |
|
| 1256 | + */ |
|
| 1257 | + protected function _get_limit($per_page) |
|
| 1258 | + { |
|
| 1259 | + $current_page = ! empty($this->_req_data['paged']) |
|
| 1260 | + ? absint($this->_req_data['paged']) |
|
| 1261 | + : 1; |
|
| 1262 | + $per_page = ! empty($this->_req_data['perpage']) |
|
| 1263 | + ? $this->_req_data['perpage'] |
|
| 1264 | + : $per_page; |
|
| 1265 | + |
|
| 1266 | + //-1 means return all results so get out if that's set. |
|
| 1267 | + if ((int)$per_page === -1) { |
|
| 1268 | + return array(); |
|
| 1269 | + } |
|
| 1270 | + $per_page = absint($per_page); |
|
| 1271 | + $offset = ($current_page - 1) * $per_page; |
|
| 1272 | + return array('limit' => array($offset, $per_page)); |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + |
|
| 1276 | + public function get_registration_status_array() |
|
| 1277 | + { |
|
| 1278 | + return self::$_reg_status; |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + |
|
| 1282 | + |
|
| 1283 | + |
|
| 1284 | + /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1285 | + /** |
|
| 1286 | + * generates HTML for the View Registration Details Admin page |
|
| 1287 | + * |
|
| 1288 | + * @access protected |
|
| 1289 | + * @return void |
|
| 1290 | + */ |
|
| 1291 | + protected function _registration_details() |
|
| 1292 | + { |
|
| 1293 | + $this->_template_args = array(); |
|
| 1294 | + $this->_set_registration_object(); |
|
| 1295 | + if (is_object($this->_registration)) { |
|
| 1296 | + $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 1297 | + : EE_Transaction::new_instance(); |
|
| 1298 | + $this->_session = $transaction->session_data(); |
|
| 1299 | + $event_id = $this->_registration->event_ID(); |
|
| 1300 | + $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1301 | + $this->_template_args['reg_nmbr']['label'] = __('Registration Number', 'event_espresso'); |
|
| 1302 | + $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1303 | + $this->_template_args['reg_datetime']['label'] = __('Date', 'event_espresso'); |
|
| 1304 | + $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1305 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1306 | + // link back to overview |
|
| 1307 | + $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1308 | + $this->_template_args['registration'] = $this->_registration; |
|
| 1309 | + $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1310 | + 'action' => 'default', |
|
| 1311 | + 'event_id' => $event_id, |
|
| 1312 | + ), REG_ADMIN_URL); |
|
| 1313 | + $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1314 | + 'action' => 'default', |
|
| 1315 | + 'EVT_ID' => $event_id, |
|
| 1316 | + 'page' => 'espresso_transactions', |
|
| 1317 | + ), admin_url('admin.php')); |
|
| 1318 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1319 | + 'page' => 'espresso_events', |
|
| 1320 | + 'action' => 'edit', |
|
| 1321 | + 'post' => $event_id, |
|
| 1322 | + ), admin_url('admin.php')); |
|
| 1323 | + //next and previous links |
|
| 1324 | + $next_reg = $this->_registration->next(null, array(), 'REG_ID'); |
|
| 1325 | + $this->_template_args['next_registration'] = $next_reg |
|
| 1326 | + ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1327 | + 'action' => 'view_registration', |
|
| 1328 | + '_REG_ID' => $next_reg['REG_ID'], |
|
| 1329 | + ), REG_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : ''; |
|
| 1330 | + $previous_reg = $this->_registration->previous(null, array(), 'REG_ID'); |
|
| 1331 | + $this->_template_args['previous_registration'] = $previous_reg |
|
| 1332 | + ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1333 | + 'action' => 'view_registration', |
|
| 1334 | + '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1335 | + ), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : ''; |
|
| 1336 | + // grab header |
|
| 1337 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1338 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1339 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
| 1340 | + $this->_template_args, true); |
|
| 1341 | + } else { |
|
| 1342 | + $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
| 1343 | + } |
|
| 1344 | + // the details template wrapper |
|
| 1345 | + $this->display_admin_page_with_sidebar(); |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + |
|
| 1349 | + protected function _registration_details_metaboxes() |
|
| 1350 | + { |
|
| 1351 | + do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1352 | + $this->_set_registration_object(); |
|
| 1353 | + $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1354 | + add_meta_box('edit-reg-status-mbox', __('Registration Status', 'event_espresso'), |
|
| 1355 | + array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1356 | + add_meta_box('edit-reg-details-mbox', __('Registration Details', 'event_espresso'), |
|
| 1357 | + array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1358 | + if ($attendee instanceof EE_Attendee |
|
| 1359 | + && EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox') |
|
| 1360 | + ) { |
|
| 1361 | + add_meta_box('edit-reg-questions-mbox', __('Registration Form Answers', 'event_espresso'), |
|
| 1362 | + array($this, '_reg_questions_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1363 | + } |
|
| 1364 | + add_meta_box('edit-reg-registrant-mbox', __('Contact Details', 'event_espresso'), |
|
| 1365 | + array($this, '_reg_registrant_side_meta_box'), $this->wp_page_slug, 'side', 'high'); |
|
| 1366 | + if ($this->_registration->group_size() > 1) { |
|
| 1367 | + add_meta_box('edit-reg-attendees-mbox', __('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1368 | + array($this, '_reg_attendees_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1369 | + } |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + /** |
|
| 1374 | + * set_reg_status_buttons_metabox |
|
| 1375 | + * |
|
| 1376 | + * @access protected |
|
| 1377 | + * @return string |
|
| 1378 | + * @throws \EE_Error |
|
| 1379 | + */ |
|
| 1380 | + public function set_reg_status_buttons_metabox() |
|
| 1381 | + { |
|
| 1382 | + $this->_set_registration_object(); |
|
| 1383 | + $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1384 | + echo $change_reg_status_form->form_open(self::add_query_args_and_nonce(array( |
|
| 1385 | + 'action' => 'change_reg_status', |
|
| 1386 | + ), REG_ADMIN_URL)); |
|
| 1387 | + echo $change_reg_status_form->get_html(); |
|
| 1388 | + echo $change_reg_status_form->form_close(); |
|
| 1389 | + } |
|
| 1390 | + |
|
| 1391 | + |
|
| 1392 | + /** |
|
| 1393 | + * @return EE_Form_Section_Proper |
|
| 1394 | + */ |
|
| 1395 | + protected function _generate_reg_status_change_form() |
|
| 1396 | + { |
|
| 1397 | + return new EE_Form_Section_Proper(array( |
|
| 1398 | + 'name' => 'reg_status_change_form', |
|
| 1399 | + 'html_id' => 'reg-status-change-form', |
|
| 1400 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1401 | + 'subsections' => array( |
|
| 1402 | + 'return' => new EE_Hidden_Input(array( |
|
| 1403 | + 'name' => 'return', |
|
| 1404 | + 'default' => 'view_registration', |
|
| 1405 | + )), |
|
| 1406 | + 'REG_ID' => new EE_Hidden_Input(array( |
|
| 1407 | + 'name' => 'REG_ID', |
|
| 1408 | + 'default' => $this->_registration->ID(), |
|
| 1409 | + )), |
|
| 1410 | + 'current_status' => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status', |
|
| 1411 | + 'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(), |
|
| 1412 | + '', 'status-' . $this->_registration->status_ID(), |
|
| 1413 | + 'line-height: 1em; font-size: 1.5em; font-weight: bold;')))), |
|
| 1414 | + 'reg_status' => new EE_Select_Input($this->_get_reg_statuses(), array( |
|
| 1415 | + 'html_label_text' => __('Change Registration Status to', 'event_espresso'), |
|
| 1416 | + 'default' => $this->_registration->status_ID(), |
|
| 1417 | + )), |
|
| 1418 | + 'send_notifications' => new EE_Yes_No_Input(array( |
|
| 1419 | + 'html_label_text' => __('Send Related Messages', 'event_espresso'), |
|
| 1420 | + 'default' => false, |
|
| 1421 | + 'html_help_text' => __('If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1422 | + 'event_espresso'), |
|
| 1423 | + )), |
|
| 1424 | + 'submit' => new EE_Submit_Input(array( |
|
| 1425 | + 'html_class' => 'button-primary', |
|
| 1426 | + 'html_label_text' => ' ', |
|
| 1427 | + 'default' => __('Update Registration Status', 'event_espresso'), |
|
| 1428 | + )), |
|
| 1429 | + ), |
|
| 1430 | + )); |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + |
|
| 1434 | + |
|
| 1435 | + /** |
|
| 1436 | + * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1437 | + * |
|
| 1438 | + * @return array |
|
| 1439 | + */ |
|
| 1440 | + protected function _get_reg_statuses() |
|
| 1441 | + { |
|
| 1442 | + $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
| 1443 | + unset ($reg_status_array[EEM_Registration::status_id_incomplete]); |
|
| 1444 | + // get current reg status |
|
| 1445 | + $current_status = $this->_registration->status_ID(); |
|
| 1446 | + // is registration for free event? This will determine whether to display the pending payment option |
|
| 1447 | + if ($current_status != EEM_Registration::status_id_pending_payment |
|
| 1448 | + && $this->_registration->transaction() |
|
| 1449 | + ->is_free() |
|
| 1450 | + ) { |
|
| 1451 | + unset($reg_status_array[EEM_Registration::status_id_pending_payment]); |
|
| 1452 | + } |
|
| 1453 | + return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1454 | + } |
|
| 1455 | + |
|
| 1456 | + |
|
| 1457 | + /** |
|
| 1458 | + * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1459 | + * |
|
| 1460 | + * @param bool $status REG status given for changing registrations to. |
|
| 1461 | + * @param bool $notify Whether to send messages notifications or not. |
|
| 1462 | + * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1463 | + */ |
|
| 1464 | + protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1465 | + { |
|
| 1466 | + if (isset($this->_req_data['reg_status_change_form'])) { |
|
| 1467 | + $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 1468 | + ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1469 | + } else { |
|
| 1470 | + $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
| 1471 | + } |
|
| 1472 | + $success = $this->_set_registration_status($REG_IDs, $status); |
|
| 1473 | + //notify? |
|
| 1474 | + if ($success |
|
| 1475 | + && $notify |
|
| 1476 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 1477 | + 'espresso_registrations_resend_registration') |
|
| 1478 | + ) { |
|
| 1479 | + $this->_process_resend_registration(); |
|
| 1480 | + } |
|
| 1481 | + return $success; |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + |
|
| 1485 | + /** |
|
| 1486 | + * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1487 | + * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1488 | + * |
|
| 1489 | + * @param array $REG_IDs |
|
| 1490 | + * @param bool $status |
|
| 1491 | + * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1492 | + * the array of updated registrations). |
|
| 1493 | + */ |
|
| 1494 | + protected function _set_registration_status($REG_IDs = array(), $status = false) |
|
| 1495 | + { |
|
| 1496 | + $success = false; |
|
| 1497 | + // typecast $REG_IDs |
|
| 1498 | + $REG_IDs = (array)$REG_IDs; |
|
| 1499 | + if ( ! empty($REG_IDs)) { |
|
| 1500 | + $success = true; |
|
| 1501 | + // set default status if none is passed |
|
| 1502 | + $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
| 1503 | + // sanitize $REG_IDs |
|
| 1504 | + $REG_IDs = array_filter($REG_IDs, 'absint'); |
|
| 1505 | + //loop through REG_ID's and change status |
|
| 1506 | + foreach ($REG_IDs as $REG_ID) { |
|
| 1507 | + $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1508 | + if ($registration instanceof EE_Registration) { |
|
| 1509 | + $registration->set_status($status); |
|
| 1510 | + $result = $registration->save(); |
|
| 1511 | + // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1512 | + $success = $result !== false ? $success : false; |
|
| 1513 | + } |
|
| 1514 | + } |
|
| 1515 | + } |
|
| 1516 | + //reset _req_data['_REG_ID'] for any potential future messages notifications |
|
| 1517 | + $this->_req_data['_REG_ID'] = $REG_IDs; |
|
| 1518 | + //return $success and processed registrations |
|
| 1519 | + return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + |
|
| 1523 | + /** |
|
| 1524 | + * Common logic for setting up success message and redirecting to appropriate route |
|
| 1525 | + * |
|
| 1526 | + * @param string $STS_ID status id for the registration changed to |
|
| 1527 | + * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1528 | + * @return void |
|
| 1529 | + */ |
|
| 1530 | + protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1531 | + { |
|
| 1532 | + $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1533 | + : array('success' => false); |
|
| 1534 | + $success = isset($result['success']) && $result['success']; |
|
| 1535 | + //setup success message |
|
| 1536 | + if ($success) { |
|
| 1537 | + if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1538 | + $msg = sprintf(__('Registration status has been set to %s', 'event_espresso'), |
|
| 1539 | + EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1540 | + } else { |
|
| 1541 | + $msg = sprintf(__('Registrations have been set to %s.', 'event_espresso'), |
|
| 1542 | + EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1543 | + } |
|
| 1544 | + EE_Error::add_success($msg); |
|
| 1545 | + } else { |
|
| 1546 | + EE_Error::add_error(__('Something went wrong, and the status was not changed', 'event_espresso'), __FILE__, |
|
| 1547 | + __LINE__, __FUNCTION__); |
|
| 1548 | + } |
|
| 1549 | + if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
| 1550 | + $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
| 1551 | + } else { |
|
| 1552 | + $route = array('action' => 'default'); |
|
| 1553 | + } |
|
| 1554 | + //unset nonces |
|
| 1555 | + foreach ($this->_req_data as $ref => $value) { |
|
| 1556 | + if (strpos($ref, 'nonce') !== false) { |
|
| 1557 | + unset($this->_req_data[$ref]); |
|
| 1558 | + continue; |
|
| 1559 | + } |
|
| 1560 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 1561 | + $this->_req_data[$ref] = $value; |
|
| 1562 | + } |
|
| 1563 | + //merge request vars so that the reloaded list table contains any existing filter query params |
|
| 1564 | + $route = array_merge($this->_req_data, $route); |
|
| 1565 | + $this->_redirect_after_action($success, '', '', $route, true); |
|
| 1566 | + } |
|
| 1567 | + |
|
| 1568 | + |
|
| 1569 | + /** |
|
| 1570 | + * incoming reg status change from reg details page. |
|
| 1571 | + * |
|
| 1572 | + * @return void |
|
| 1573 | + */ |
|
| 1574 | + protected function _change_reg_status() |
|
| 1575 | + { |
|
| 1576 | + $this->_req_data['return'] = 'view_registration'; |
|
| 1577 | + //set notify based on whether the send notifications toggle is set or not |
|
| 1578 | + $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
| 1579 | + //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
| 1580 | + $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
| 1581 | + ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
| 1582 | + switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
| 1583 | + case EEM_Registration::status_id_approved : |
|
| 1584 | + case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') : |
|
| 1585 | + $this->approve_registration($notify); |
|
| 1586 | + break; |
|
| 1587 | + case EEM_Registration::status_id_pending_payment : |
|
| 1588 | + case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') : |
|
| 1589 | + $this->pending_registration($notify); |
|
| 1590 | + break; |
|
| 1591 | + case EEM_Registration::status_id_not_approved : |
|
| 1592 | + case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') : |
|
| 1593 | + $this->not_approve_registration($notify); |
|
| 1594 | + break; |
|
| 1595 | + case EEM_Registration::status_id_declined : |
|
| 1596 | + case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') : |
|
| 1597 | + $this->decline_registration($notify); |
|
| 1598 | + break; |
|
| 1599 | + case EEM_Registration::status_id_cancelled : |
|
| 1600 | + case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') : |
|
| 1601 | + $this->cancel_registration($notify); |
|
| 1602 | + break; |
|
| 1603 | + case EEM_Registration::status_id_wait_list : |
|
| 1604 | + case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') : |
|
| 1605 | + $this->waitlist_registration($notify); |
|
| 1606 | + break; |
|
| 1607 | + case EEM_Registration::status_id_incomplete : |
|
| 1608 | + default : |
|
| 1609 | + $result['success'] = false; |
|
| 1610 | + unset($this->_req_data['return']); |
|
| 1611 | + $this->_reg_status_change_return('', false); |
|
| 1612 | + break; |
|
| 1613 | + } |
|
| 1614 | + } |
|
| 1615 | + |
|
| 1616 | + |
|
| 1617 | + /** |
|
| 1618 | + * approve_registration |
|
| 1619 | + * |
|
| 1620 | + * @access protected |
|
| 1621 | + * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 1622 | + * @return void |
|
| 1623 | + */ |
|
| 1624 | + protected function approve_registration($notify = false) |
|
| 1625 | + { |
|
| 1626 | + $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * decline_registration |
|
| 1632 | + * |
|
| 1633 | + * @access protected |
|
| 1634 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1635 | + * @return void |
|
| 1636 | + */ |
|
| 1637 | + protected function decline_registration($notify = false) |
|
| 1638 | + { |
|
| 1639 | + $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 1640 | + } |
|
| 1641 | + |
|
| 1642 | + |
|
| 1643 | + /** |
|
| 1644 | + * cancel_registration |
|
| 1645 | + * |
|
| 1646 | + * @access protected |
|
| 1647 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1648 | + * @return void |
|
| 1649 | + */ |
|
| 1650 | + protected function cancel_registration($notify = false) |
|
| 1651 | + { |
|
| 1652 | + $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 1653 | + } |
|
| 1654 | + |
|
| 1655 | + |
|
| 1656 | + /** |
|
| 1657 | + * not_approve_registration |
|
| 1658 | + * |
|
| 1659 | + * @access protected |
|
| 1660 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1661 | + * @return void |
|
| 1662 | + */ |
|
| 1663 | + protected function not_approve_registration($notify = false) |
|
| 1664 | + { |
|
| 1665 | + $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + |
|
| 1669 | + /** |
|
| 1670 | + * decline_registration |
|
| 1671 | + * |
|
| 1672 | + * @access protected |
|
| 1673 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1674 | + * @return void |
|
| 1675 | + */ |
|
| 1676 | + protected function pending_registration($notify = false) |
|
| 1677 | + { |
|
| 1678 | + $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 1679 | + } |
|
| 1680 | + |
|
| 1681 | + |
|
| 1682 | + /** |
|
| 1683 | + * waitlist_registration |
|
| 1684 | + * |
|
| 1685 | + * @access protected |
|
| 1686 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1687 | + * @return void |
|
| 1688 | + */ |
|
| 1689 | + protected function waitlist_registration($notify = false) |
|
| 1690 | + { |
|
| 1691 | + $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + |
|
| 1695 | + /** |
|
| 1696 | + * generates HTML for the Registration main meta box |
|
| 1697 | + * |
|
| 1698 | + * @access public |
|
| 1699 | + * @return void |
|
| 1700 | + */ |
|
| 1701 | + public function _reg_details_meta_box() |
|
| 1702 | + { |
|
| 1703 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1704 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 1705 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
| 1706 | + $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 1707 | + : EE_Transaction::new_instance(); |
|
| 1708 | + $this->_session = $transaction->session_data(); |
|
| 1709 | + $filters = new EE_Line_Item_Filter_Collection(); |
|
| 1710 | + //$filters->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
| 1711 | + $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 1712 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, |
|
| 1713 | + $transaction->total_line_item()); |
|
| 1714 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 1715 | + $line_item_display = new EE_Line_Item_Display('reg_admin_table', |
|
| 1716 | + 'EE_Admin_Table_Registration_Line_Item_Display_Strategy'); |
|
| 1717 | + $this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree, |
|
| 1718 | + array('EE_Registration' => $this->_registration)); |
|
| 1719 | + $attendee = $this->_registration->attendee(); |
|
| 1720 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 1721 | + 'espresso_transactions_view_transaction') |
|
| 1722 | + ) { |
|
| 1723 | + $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1724 | + 'action' => 'view_transaction', |
|
| 1725 | + 'TXN_ID' => $transaction->ID(), |
|
| 1726 | + ), TXN_ADMIN_URL), esc_html__(' View Transaction'), 'button secondary-button right', |
|
| 1727 | + 'dashicons dashicons-cart'); |
|
| 1728 | + } else { |
|
| 1729 | + $this->_template_args['view_transaction_button'] = ''; |
|
| 1730 | + } |
|
| 1731 | + if ($attendee instanceof EE_Attendee |
|
| 1732 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 1733 | + 'espresso_registrations_resend_registration') |
|
| 1734 | + ) { |
|
| 1735 | + $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1736 | + 'action' => 'resend_registration', |
|
| 1737 | + '_REG_ID' => $this->_registration->ID(), |
|
| 1738 | + 'redirect_to' => 'view_registration', |
|
| 1739 | + ), REG_ADMIN_URL), esc_html__(' Resend Registration'), 'button secondary-button right', |
|
| 1740 | + 'dashicons dashicons-email-alt'); |
|
| 1741 | + } else { |
|
| 1742 | + $this->_template_args['resend_registration_button'] = ''; |
|
| 1743 | + } |
|
| 1744 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1745 | + $payment = $transaction->get_first_related('Payment'); |
|
| 1746 | + $payment = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment; |
|
| 1747 | + $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 1748 | + $payment_method = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance() |
|
| 1749 | + : $payment_method; |
|
| 1750 | + $reg_details = array( |
|
| 1751 | + 'payment_method' => $payment_method->name(), |
|
| 1752 | + 'response_msg' => $payment->gateway_response(), |
|
| 1753 | + 'registration_id' => $this->_registration->get('REG_code'), |
|
| 1754 | + 'registration_session' => $this->_registration->session_ID(), |
|
| 1755 | + 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 1756 | + 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 1757 | + ); |
|
| 1758 | + if (isset($reg_details['registration_id'])) { |
|
| 1759 | + $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 1760 | + $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso'); |
|
| 1761 | + $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 1762 | + } |
|
| 1763 | + if (isset($reg_details['payment_method'])) { |
|
| 1764 | + $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 1765 | + $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method', |
|
| 1766 | + 'event_espresso'); |
|
| 1767 | + $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 1768 | + $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 1769 | + $this->_template_args['reg_details']['response_msg']['label'] = __('Payment method response', |
|
| 1770 | + 'event_espresso'); |
|
| 1771 | + $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 1772 | + } |
|
| 1773 | + $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 1774 | + $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session', |
|
| 1775 | + 'event_espresso'); |
|
| 1776 | + $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 1777 | + $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 1778 | + $this->_template_args['reg_details']['ip_address']['label'] = __('Registration placed from IP', |
|
| 1779 | + 'event_espresso'); |
|
| 1780 | + $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 1781 | + $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 1782 | + $this->_template_args['reg_details']['user_agent']['label'] = __('Registrant User Agent', |
|
| 1783 | + 'event_espresso'); |
|
| 1784 | + $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 1785 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1786 | + 'action' => 'default', |
|
| 1787 | + 'event_id' => $this->_registration->event_ID(), |
|
| 1788 | + ), REG_ADMIN_URL); |
|
| 1789 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1790 | + $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 1791 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 1792 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1793 | + } |
|
| 1794 | + |
|
| 1795 | + |
|
| 1796 | + /** |
|
| 1797 | + * generates HTML for the Registration Questions meta box. |
|
| 1798 | + * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 1799 | + * otherwise uses new forms system |
|
| 1800 | + * |
|
| 1801 | + * @access public |
|
| 1802 | + * @return void |
|
| 1803 | + */ |
|
| 1804 | + public function _reg_questions_meta_box() |
|
| 1805 | + { |
|
| 1806 | + //allow someone to override this method entirely |
|
| 1807 | + if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, |
|
| 1808 | + $this->_registration)) { |
|
| 1809 | + $form = $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 1810 | + $this->_template_args['att_questions'] = count($form->subforms()) > 0 ? $form->get_html_and_js() : ''; |
|
| 1811 | + $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 1812 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1813 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 1814 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1815 | + } |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + |
|
| 1819 | + /** |
|
| 1820 | + * form_before_question_group |
|
| 1821 | + * |
|
| 1822 | + * @deprecated as of 4.8.32.rc.000 |
|
| 1823 | + * @access public |
|
| 1824 | + * @param string $output |
|
| 1825 | + * @return string |
|
| 1826 | + */ |
|
| 1827 | + public function form_before_question_group($output) |
|
| 1828 | + { |
|
| 1829 | + EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1830 | + __('This method would have been protected but was used on a filter callback' |
|
| 1831 | + . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1832 | + '4.8.32.rc.000'); |
|
| 1833 | + return ' |
|
| 1834 | 1834 | <table class="form-table ee-width-100"> |
| 1835 | 1835 | <tbody> |
| 1836 | 1836 | '; |
| 1837 | - } |
|
| 1838 | - |
|
| 1839 | - |
|
| 1840 | - /** |
|
| 1841 | - * form_after_question_group |
|
| 1842 | - * |
|
| 1843 | - * @deprecated as of 4.8.32.rc.000 |
|
| 1844 | - * @access public |
|
| 1845 | - * @param string $output |
|
| 1846 | - * @return string |
|
| 1847 | - */ |
|
| 1848 | - public function form_after_question_group($output) |
|
| 1849 | - { |
|
| 1850 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1851 | - __('This method would have been protected but was used on a filter callback' |
|
| 1852 | - . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1853 | - '4.8.32.rc.000'); |
|
| 1854 | - return ' |
|
| 1837 | + } |
|
| 1838 | + |
|
| 1839 | + |
|
| 1840 | + /** |
|
| 1841 | + * form_after_question_group |
|
| 1842 | + * |
|
| 1843 | + * @deprecated as of 4.8.32.rc.000 |
|
| 1844 | + * @access public |
|
| 1845 | + * @param string $output |
|
| 1846 | + * @return string |
|
| 1847 | + */ |
|
| 1848 | + public function form_after_question_group($output) |
|
| 1849 | + { |
|
| 1850 | + EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1851 | + __('This method would have been protected but was used on a filter callback' |
|
| 1852 | + . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1853 | + '4.8.32.rc.000'); |
|
| 1854 | + return ' |
|
| 1855 | 1855 | <tr class="hide-if-no-js"> |
| 1856 | 1856 | <th> </th> |
| 1857 | 1857 | <td class="reg-admin-edit-attendee-question-td"> |
| 1858 | 1858 | <a class="reg-admin-edit-attendee-question-lnk" href="#" title="' |
| 1859 | - . esc_attr__('click to edit question', 'event_espresso') |
|
| 1860 | - . '"> |
|
| 1859 | + . esc_attr__('click to edit question', 'event_espresso') |
|
| 1860 | + . '"> |
|
| 1861 | 1861 | <span class="reg-admin-edit-question-group-spn lt-grey-txt">' |
| 1862 | - . __('edit the above question group', 'event_espresso') |
|
| 1863 | - . '</span> |
|
| 1862 | + . __('edit the above question group', 'event_espresso') |
|
| 1863 | + . '</span> |
|
| 1864 | 1864 | <div class="dashicons dashicons-edit"></div> |
| 1865 | 1865 | </a> |
| 1866 | 1866 | </td> |
@@ -1868,495 +1868,495 @@ discard block |
||
| 1868 | 1868 | </tbody> |
| 1869 | 1869 | </table> |
| 1870 | 1870 | '; |
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - |
|
| 1874 | - /** |
|
| 1875 | - * form_form_field_label_wrap |
|
| 1876 | - * |
|
| 1877 | - * @deprecated as of 4.8.32.rc.000 |
|
| 1878 | - * @access public |
|
| 1879 | - * @param string $label |
|
| 1880 | - * @return string |
|
| 1881 | - */ |
|
| 1882 | - public function form_form_field_label_wrap($label) |
|
| 1883 | - { |
|
| 1884 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1885 | - __('This method would have been protected but was used on a filter callback' |
|
| 1886 | - . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1887 | - '4.8.32.rc.000'); |
|
| 1888 | - return ' |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + |
|
| 1874 | + /** |
|
| 1875 | + * form_form_field_label_wrap |
|
| 1876 | + * |
|
| 1877 | + * @deprecated as of 4.8.32.rc.000 |
|
| 1878 | + * @access public |
|
| 1879 | + * @param string $label |
|
| 1880 | + * @return string |
|
| 1881 | + */ |
|
| 1882 | + public function form_form_field_label_wrap($label) |
|
| 1883 | + { |
|
| 1884 | + EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1885 | + __('This method would have been protected but was used on a filter callback' |
|
| 1886 | + . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1887 | + '4.8.32.rc.000'); |
|
| 1888 | + return ' |
|
| 1889 | 1889 | <tr> |
| 1890 | 1890 | <th> |
| 1891 | 1891 | ' . $label . ' |
| 1892 | 1892 | </th>'; |
| 1893 | - } |
|
| 1894 | - |
|
| 1895 | - |
|
| 1896 | - /** |
|
| 1897 | - * form_form_field_input__wrap |
|
| 1898 | - * |
|
| 1899 | - * @deprecated as of 4.8.32.rc.000 |
|
| 1900 | - * @access public |
|
| 1901 | - * @param string $input |
|
| 1902 | - * @return string |
|
| 1903 | - */ |
|
| 1904 | - public function form_form_field_input__wrap($input) |
|
| 1905 | - { |
|
| 1906 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1907 | - __('This method would have been protected but was used on a filter callback' |
|
| 1908 | - . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1909 | - '4.8.32.rc.000'); |
|
| 1910 | - return ' |
|
| 1893 | + } |
|
| 1894 | + |
|
| 1895 | + |
|
| 1896 | + /** |
|
| 1897 | + * form_form_field_input__wrap |
|
| 1898 | + * |
|
| 1899 | + * @deprecated as of 4.8.32.rc.000 |
|
| 1900 | + * @access public |
|
| 1901 | + * @param string $input |
|
| 1902 | + * @return string |
|
| 1903 | + */ |
|
| 1904 | + public function form_form_field_input__wrap($input) |
|
| 1905 | + { |
|
| 1906 | + EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1907 | + __('This method would have been protected but was used on a filter callback' |
|
| 1908 | + . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1909 | + '4.8.32.rc.000'); |
|
| 1910 | + return ' |
|
| 1911 | 1911 | <td class="reg-admin-attendee-questions-input-td disabled-input"> |
| 1912 | 1912 | ' . $input . ' |
| 1913 | 1913 | </td> |
| 1914 | 1914 | </tr>'; |
| 1915 | - } |
|
| 1916 | - |
|
| 1917 | - |
|
| 1918 | - /** |
|
| 1919 | - * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 1920 | - * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 1921 | - * to display the page |
|
| 1922 | - * |
|
| 1923 | - * @access protected |
|
| 1924 | - * @return void |
|
| 1925 | - */ |
|
| 1926 | - protected function _update_attendee_registration_form() |
|
| 1927 | - { |
|
| 1928 | - do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 1929 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 1930 | - $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 1931 | - $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 1932 | - if ($success) { |
|
| 1933 | - $what = __('Registration Form', 'event_espresso'); |
|
| 1934 | - $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
| 1935 | - : array('action' => 'default'); |
|
| 1936 | - $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
| 1937 | - } |
|
| 1938 | - } |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - |
|
| 1942 | - /** |
|
| 1943 | - * Gets the form for saving registrations custom questions (if done |
|
| 1944 | - * previously retrieves the cached form object, which may have validation errors in it) |
|
| 1945 | - * |
|
| 1946 | - * @param int $REG_ID |
|
| 1947 | - * @return EE_Registration_Custom_Questions_Form |
|
| 1948 | - */ |
|
| 1949 | - protected function _get_reg_custom_questions_form($REG_ID) |
|
| 1950 | - { |
|
| 1951 | - if ( ! $this->_reg_custom_questions_form) { |
|
| 1952 | - require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 1953 | - $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 1954 | - EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
| 1955 | - ); |
|
| 1956 | - $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 1957 | - } |
|
| 1958 | - return $this->_reg_custom_questions_form; |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - |
|
| 1962 | - /** |
|
| 1963 | - * Saves |
|
| 1964 | - * |
|
| 1965 | - * @access private |
|
| 1966 | - * @param bool $REG_ID |
|
| 1967 | - * @return bool |
|
| 1968 | - */ |
|
| 1969 | - private function _save_reg_custom_questions_form($REG_ID = false) |
|
| 1970 | - { |
|
| 1971 | - if ( ! $REG_ID) { |
|
| 1972 | - EE_Error::add_error(__('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__, |
|
| 1973 | - __FUNCTION__, __LINE__); |
|
| 1974 | - } |
|
| 1975 | - $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 1976 | - $form->receive_form_submission($this->_req_data); |
|
| 1977 | - $success = false; |
|
| 1978 | - if ($form->is_valid()) { |
|
| 1979 | - foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
| 1980 | - foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 1981 | - $where_conditions = array( |
|
| 1982 | - 'QST_ID' => $question_id, |
|
| 1983 | - 'REG_ID' => $REG_ID, |
|
| 1984 | - ); |
|
| 1985 | - $possibly_new_values = array( |
|
| 1986 | - 'ANS_value' => $input->normalized_value(), |
|
| 1987 | - ); |
|
| 1988 | - $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
| 1989 | - if ($answer instanceof EE_Answer) { |
|
| 1990 | - $success = $answer->save($possibly_new_values); |
|
| 1991 | - } else { |
|
| 1992 | - //insert it then |
|
| 1993 | - $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 1994 | - $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 1995 | - $success = $answer->save(); |
|
| 1996 | - } |
|
| 1997 | - } |
|
| 1998 | - } |
|
| 1999 | - } else { |
|
| 2000 | - EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2001 | - } |
|
| 2002 | - return $success; |
|
| 2003 | - } |
|
| 2004 | - |
|
| 2005 | - |
|
| 2006 | - /** |
|
| 2007 | - * generates HTML for the Registration main meta box |
|
| 2008 | - * |
|
| 2009 | - * @access public |
|
| 2010 | - * @return void |
|
| 2011 | - */ |
|
| 2012 | - public function _reg_attendees_meta_box() |
|
| 2013 | - { |
|
| 2014 | - $REG = EEM_Registration::instance(); |
|
| 2015 | - //get all other registrations on this transaction, and cache |
|
| 2016 | - //the attendees for them so we don't have to run another query using force_join |
|
| 2017 | - $registrations = $REG->get_all(array( |
|
| 2018 | - array( |
|
| 2019 | - 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2020 | - 'REG_ID' => array('!=', $this->_registration->ID()), |
|
| 2021 | - ), |
|
| 2022 | - 'force_join' => array('Attendee'), |
|
| 2023 | - )); |
|
| 2024 | - $this->_template_args['attendees'] = array(); |
|
| 2025 | - $this->_template_args['attendee_notice'] = ''; |
|
| 2026 | - if (empty($registrations) |
|
| 2027 | - || (is_array($registrations) |
|
| 2028 | - && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2029 | - ) { |
|
| 2030 | - EE_Error::add_error(__('There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2031 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2032 | - $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2033 | - } else { |
|
| 2034 | - $att_nmbr = 1; |
|
| 2035 | - foreach ($registrations as $registration) { |
|
| 2036 | - /* @var $registration EE_Registration */ |
|
| 2037 | - $attendee = $registration->attendee() |
|
| 2038 | - ? $registration->attendee() |
|
| 2039 | - : EEM_Attendee::instance() |
|
| 2040 | - ->create_default_object(); |
|
| 2041 | - $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
|
| 2042 | - $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : ''; |
|
| 2043 | - $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : ''; |
|
| 2044 | - $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : ''; |
|
| 2045 | - $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : ''; |
|
| 2046 | - $this->_template_args['attendees'][$att_nmbr]['address'] = implode(', ', |
|
| 2047 | - $attendee->full_address_as_array()); |
|
| 2048 | - $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(array( |
|
| 2049 | - 'action' => 'edit_attendee', |
|
| 2050 | - 'post' => $attendee->ID(), |
|
| 2051 | - ), REG_ADMIN_URL); |
|
| 2052 | - $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2053 | - $att_nmbr++; |
|
| 2054 | - } |
|
| 2055 | - //EEH_Debug_Tools::printr( $attendees, '$attendees <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' ); |
|
| 2056 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2057 | - // $this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees' ), REG_ADMIN_URL ); |
|
| 2058 | - } |
|
| 2059 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2060 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2061 | - } |
|
| 2062 | - |
|
| 2063 | - |
|
| 2064 | - /** |
|
| 2065 | - * generates HTML for the Edit Registration side meta box |
|
| 2066 | - * |
|
| 2067 | - * @access public |
|
| 2068 | - * @return void |
|
| 2069 | - */ |
|
| 2070 | - public function _reg_registrant_side_meta_box() |
|
| 2071 | - { |
|
| 2072 | - /*@var $attendee EE_Attendee */ |
|
| 2073 | - $att_check = $this->_registration->attendee(); |
|
| 2074 | - $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
| 2075 | - //now let's determine if this is not the primary registration. If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show create button or not) |
|
| 2076 | - if ( ! $this->_registration->is_primary_registrant()) { |
|
| 2077 | - $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2078 | - $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2079 | - : null; |
|
| 2080 | - if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2081 | - //in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg. |
|
| 2082 | - $primary_registration = null; |
|
| 2083 | - } |
|
| 2084 | - } else { |
|
| 2085 | - $primary_registration = null; |
|
| 2086 | - } |
|
| 2087 | - $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2088 | - $this->_template_args['fname'] = $attendee->fname();//$this->_registration->ATT_fname; |
|
| 2089 | - $this->_template_args['lname'] = $attendee->lname();//$this->_registration->ATT_lname; |
|
| 2090 | - $this->_template_args['email'] = $attendee->email();//$this->_registration->ATT_email; |
|
| 2091 | - $this->_template_args['phone'] = $attendee->phone(); |
|
| 2092 | - $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2093 | - //edit link |
|
| 2094 | - $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2095 | - 'action' => 'edit_attendee', |
|
| 2096 | - 'post' => $attendee->ID(), |
|
| 2097 | - ), REG_ADMIN_URL); |
|
| 2098 | - $this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso'); |
|
| 2099 | - //create link |
|
| 2100 | - $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2101 | - ? EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2102 | - 'action' => 'duplicate_attendee', |
|
| 2103 | - '_REG_ID' => $this->_registration->ID(), |
|
| 2104 | - ), REG_ADMIN_URL) : ''; |
|
| 2105 | - $this->_template_args['create_label'] = __('Create Contact', 'event_espresso'); |
|
| 2106 | - $this->_template_args['att_check'] = $att_check; |
|
| 2107 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2108 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2109 | - } |
|
| 2110 | - |
|
| 2111 | - |
|
| 2112 | - /** |
|
| 2113 | - * trash or restore registrations |
|
| 2114 | - * |
|
| 2115 | - * @param boolean $trash whether to archive or restore |
|
| 2116 | - * @access protected |
|
| 2117 | - * @return void |
|
| 2118 | - */ |
|
| 2119 | - protected function _trash_or_restore_registrations($trash = true) |
|
| 2120 | - { |
|
| 2121 | - $REGM = EEM_Registration::instance(); |
|
| 2122 | - $success = 1; |
|
| 2123 | - $error = 0; |
|
| 2124 | - $tickets = array(); |
|
| 2125 | - $dtts = array(); |
|
| 2126 | - //if empty _REG_ID then get out because there's nothing to do |
|
| 2127 | - if (empty($this->_req_data['_REG_ID'])) { |
|
| 2128 | - $msg = $trash |
|
| 2129 | - ? __('In order to trash registrations you must select which ones you wish to trash by clicking the checkboxes.', |
|
| 2130 | - 'event_espresso') |
|
| 2131 | - : __('In order to restore registrations you must select which ones you wish to restore by clicking the checkboxes.', |
|
| 2132 | - 'event_espresso'); |
|
| 2133 | - EE_Error::add_error($msg, __FILE__, __LINE__, __FUNCTION__); |
|
| 2134 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 2135 | - } |
|
| 2136 | - //Checkboxes |
|
| 2137 | - if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2138 | - // if array has more than one element than success message should be plural |
|
| 2139 | - $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2140 | - // cycle thru checkboxes |
|
| 2141 | - while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2142 | - /** @var EE_Registration $REG */ |
|
| 2143 | - $REG = $REGM->get_one_by_ID($REG_ID); |
|
| 2144 | - $payment_count = $REG->get_first_related('Transaction')->count_related('Payment'); |
|
| 2145 | - if ($payment_count > 0) { |
|
| 2146 | - $name = $REG->attendee() instanceof EE_Attendee ? $REG->attendee()->full_name() |
|
| 2147 | - : __('Unknown Attendee', 'event_espresso'); |
|
| 2148 | - $error = 1; |
|
| 2149 | - $success = 0; |
|
| 2150 | - EE_Error::add_error(sprintf(__('The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
| 2151 | - 'event_espresso'), $name), __FILE__, __FUNCTION__, __LINE__); |
|
| 2152 | - continue; //can't trash this registration because it has payments. |
|
| 2153 | - } |
|
| 2154 | - $ticket = $REG->get_first_related('Ticket'); |
|
| 2155 | - $tickets[$ticket->ID()] = $ticket; |
|
| 2156 | - $dtt = $ticket->get_many_related('Datetime'); |
|
| 2157 | - $dtts = array_merge($dtts, $dtt); |
|
| 2158 | - $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2159 | - if ( ! $updated) { |
|
| 2160 | - $success = 0; |
|
| 2161 | - } else { |
|
| 2162 | - $success = 2; |
|
| 2163 | - }/**/ |
|
| 2164 | - } |
|
| 2165 | - } else { |
|
| 2166 | - // grab single id and delete |
|
| 2167 | - $REG_ID = absint($this->_req_data['_REG_ID']); |
|
| 2168 | - $REG = $REGM->get_one_by_ID($REG_ID); |
|
| 2169 | - $ticket = $REG->get_first_related('Ticket'); |
|
| 2170 | - $tickets[$ticket->ID()] = $ticket; |
|
| 2171 | - $dtts = $ticket->get_many_related('Datetime'); |
|
| 2172 | - $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2173 | - if ( ! $updated) { |
|
| 2174 | - $success = 0; |
|
| 2175 | - } |
|
| 2176 | - } |
|
| 2177 | - //now let's update counts |
|
| 2178 | - EEM_Ticket::instance()->update_tickets_sold($tickets); |
|
| 2179 | - EEM_Datetime::instance()->update_sold($dtts); |
|
| 2180 | - $what = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso'); |
|
| 2181 | - $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2182 | - $overwrite_msgs = $error ? true : false; |
|
| 2183 | - $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), $overwrite_msgs); |
|
| 2184 | - } |
|
| 2185 | - |
|
| 2186 | - |
|
| 2187 | - /** |
|
| 2188 | - * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2189 | - * registration but also. |
|
| 2190 | - * 1. Removing relations to EE_Attendee |
|
| 2191 | - * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2192 | - * ALSO trashed. |
|
| 2193 | - * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2194 | - * 4. Removing relationships between all tickets and the related registrations |
|
| 2195 | - * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2196 | - * 6. Deleting permanently any related Checkins. |
|
| 2197 | - * |
|
| 2198 | - * @return void |
|
| 2199 | - */ |
|
| 2200 | - protected function _delete_registrations() |
|
| 2201 | - { |
|
| 2202 | - $REG_MDL = EEM_Registration::instance(); |
|
| 2203 | - $success = 1; |
|
| 2204 | - //Checkboxes |
|
| 2205 | - if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2206 | - // if array has more than one element than success message should be plural |
|
| 2207 | - $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2208 | - // cycle thru checkboxes |
|
| 2209 | - while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2210 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2211 | - if ( ! $REG instanceof EE_Registration) { |
|
| 2212 | - continue; |
|
| 2213 | - } |
|
| 2214 | - $deleted = $this->_delete_registration($REG); |
|
| 2215 | - if ( ! $deleted) { |
|
| 2216 | - $success = 0; |
|
| 2217 | - } |
|
| 2218 | - } |
|
| 2219 | - } else { |
|
| 2220 | - // grab single id and delete |
|
| 2221 | - $REG_ID = $this->_req_data['_REG_ID']; |
|
| 2222 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2223 | - $deleted = $this->_delete_registration($REG); |
|
| 2224 | - if ( ! $deleted) { |
|
| 2225 | - $success = 0; |
|
| 2226 | - } |
|
| 2227 | - } |
|
| 2228 | - $what = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso'); |
|
| 2229 | - $action_desc = __('permanently deleted.', 'event_espresso'); |
|
| 2230 | - $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), true); |
|
| 2231 | - } |
|
| 2232 | - |
|
| 2233 | - |
|
| 2234 | - /** |
|
| 2235 | - * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2236 | - * models get affected. |
|
| 2237 | - * |
|
| 2238 | - * @param EE_Registration $REG registration to be deleted permenantly |
|
| 2239 | - * @return boolean true = successful deletion, false = fail. |
|
| 2240 | - */ |
|
| 2241 | - protected function _delete_registration(EE_Registration $REG) |
|
| 2242 | - { |
|
| 2243 | - //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed. |
|
| 2244 | - $TXN = $REG->get_first_related('Transaction'); |
|
| 2245 | - $REGS = $TXN->get_many_related('Registration'); |
|
| 2246 | - $all_trashed = true; |
|
| 2247 | - foreach ($REGS as $registration) { |
|
| 2248 | - if ( ! $registration->get('REG_deleted')) { |
|
| 2249 | - $all_trashed = false; |
|
| 2250 | - } |
|
| 2251 | - } |
|
| 2252 | - if ( ! $all_trashed) { |
|
| 2253 | - EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
| 2254 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2255 | - return false; |
|
| 2256 | - } |
|
| 2257 | - //k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one). |
|
| 2258 | - foreach ($REGS as $registration) { |
|
| 2259 | - //delete related answers |
|
| 2260 | - $registration->delete_related_permanently('Answer'); |
|
| 2261 | - //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2262 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 2263 | - if ($attendee instanceof EE_Attendee) { |
|
| 2264 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2265 | - } |
|
| 2266 | - //now remove relationships to tickets on this registration. |
|
| 2267 | - $registration->_remove_relations('Ticket'); |
|
| 2268 | - //now delete permanently the checkins related to this registration. |
|
| 2269 | - $registration->delete_related_permanently('Checkin'); |
|
| 2270 | - if ($registration->ID() === $REG->ID()) { |
|
| 2271 | - continue; |
|
| 2272 | - } //we don't want to delete permanently the existing registration just yet. |
|
| 2273 | - //remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2274 | - $registration->_remove_relations('Transaction'); |
|
| 2275 | - //delete permanently any related messages. |
|
| 2276 | - $registration->delete_related_permanently('Message'); |
|
| 2277 | - //now delete this registration permanently |
|
| 2278 | - $registration->delete_permanently(); |
|
| 2279 | - } |
|
| 2280 | - //now all related registrations on the transaction are handled. So let's just handle this registration itself (the transaction and line items should be all that's left). |
|
| 2281 | - //delete the line items related to the transaction for this registration. |
|
| 2282 | - $TXN->delete_related_permanently('Line_Item'); |
|
| 2283 | - //we need to remove all the relationships on the transaction |
|
| 2284 | - $TXN->delete_related_permanently('Payment'); |
|
| 2285 | - $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2286 | - $TXN->delete_related_permanently('Message'); |
|
| 2287 | - //now we can delete this REG permanently (and the transaction of course) |
|
| 2288 | - $REG->delete_related_permanently('Transaction'); |
|
| 2289 | - return $REG->delete_permanently(); |
|
| 2290 | - } |
|
| 2291 | - |
|
| 2292 | - |
|
| 2293 | - /** |
|
| 2294 | - * generates HTML for the Register New Attendee Admin page |
|
| 2295 | - * |
|
| 2296 | - * @access private |
|
| 2297 | - * @throws \EE_Error |
|
| 2298 | - * @return void |
|
| 2299 | - */ |
|
| 2300 | - public function new_registration() |
|
| 2301 | - { |
|
| 2302 | - if ( ! $this->_set_reg_event()) { |
|
| 2303 | - throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request', |
|
| 2304 | - 'event_espresso')); |
|
| 2305 | - } |
|
| 2306 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2307 | - // gotta start with a clean slate if we're not coming here via ajax |
|
| 2308 | - if ( ! defined('DOING_AJAX') |
|
| 2309 | - && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
| 2310 | - ) { |
|
| 2311 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2312 | - } |
|
| 2313 | - $this->_template_args['event_name'] = ''; |
|
| 2314 | - // event name |
|
| 2315 | - if ($this->_reg_event) { |
|
| 2316 | - $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2317 | - $edit_event_url = self::add_query_args_and_nonce(array( |
|
| 2318 | - 'action' => 'edit', |
|
| 2319 | - 'post' => $this->_reg_event->ID(), |
|
| 2320 | - ), EVENTS_ADMIN_URL); |
|
| 2321 | - $edit_event_lnk = '<a href="' |
|
| 2322 | - . $edit_event_url |
|
| 2323 | - . '" title="' |
|
| 2324 | - . esc_attr__('Edit ', 'event_espresso') |
|
| 2325 | - . $this->_reg_event->name() |
|
| 2326 | - . '">' |
|
| 2327 | - . __('Edit Event', 'event_espresso') |
|
| 2328 | - . '</a>'; |
|
| 2329 | - $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2330 | - . $edit_event_lnk |
|
| 2331 | - . '</span>'; |
|
| 2332 | - } |
|
| 2333 | - $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2334 | - if (defined('DOING_AJAX')) { |
|
| 2335 | - $this->_return_json(); |
|
| 2336 | - } |
|
| 2337 | - // grab header |
|
| 2338 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2339 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
| 2340 | - $this->_template_args, true); |
|
| 2341 | - //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2342 | - // the details template wrapper |
|
| 2343 | - $this->display_admin_page_with_sidebar(); |
|
| 2344 | - } |
|
| 2345 | - |
|
| 2346 | - |
|
| 2347 | - /** |
|
| 2348 | - * This returns the content for a registration step |
|
| 2349 | - * |
|
| 2350 | - * @access protected |
|
| 2351 | - * @return string html |
|
| 2352 | - */ |
|
| 2353 | - protected function _get_registration_step_content() |
|
| 2354 | - { |
|
| 2355 | - if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 2356 | - $warning_msg = sprintf(__('%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', |
|
| 2357 | - 'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">', |
|
| 2358 | - '<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>'); |
|
| 2359 | - return ' |
|
| 1915 | + } |
|
| 1916 | + |
|
| 1917 | + |
|
| 1918 | + /** |
|
| 1919 | + * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 1920 | + * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 1921 | + * to display the page |
|
| 1922 | + * |
|
| 1923 | + * @access protected |
|
| 1924 | + * @return void |
|
| 1925 | + */ |
|
| 1926 | + protected function _update_attendee_registration_form() |
|
| 1927 | + { |
|
| 1928 | + do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 1929 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 1930 | + $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 1931 | + $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 1932 | + if ($success) { |
|
| 1933 | + $what = __('Registration Form', 'event_espresso'); |
|
| 1934 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
| 1935 | + : array('action' => 'default'); |
|
| 1936 | + $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
| 1937 | + } |
|
| 1938 | + } |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + |
|
| 1942 | + /** |
|
| 1943 | + * Gets the form for saving registrations custom questions (if done |
|
| 1944 | + * previously retrieves the cached form object, which may have validation errors in it) |
|
| 1945 | + * |
|
| 1946 | + * @param int $REG_ID |
|
| 1947 | + * @return EE_Registration_Custom_Questions_Form |
|
| 1948 | + */ |
|
| 1949 | + protected function _get_reg_custom_questions_form($REG_ID) |
|
| 1950 | + { |
|
| 1951 | + if ( ! $this->_reg_custom_questions_form) { |
|
| 1952 | + require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 1953 | + $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 1954 | + EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
| 1955 | + ); |
|
| 1956 | + $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 1957 | + } |
|
| 1958 | + return $this->_reg_custom_questions_form; |
|
| 1959 | + } |
|
| 1960 | + |
|
| 1961 | + |
|
| 1962 | + /** |
|
| 1963 | + * Saves |
|
| 1964 | + * |
|
| 1965 | + * @access private |
|
| 1966 | + * @param bool $REG_ID |
|
| 1967 | + * @return bool |
|
| 1968 | + */ |
|
| 1969 | + private function _save_reg_custom_questions_form($REG_ID = false) |
|
| 1970 | + { |
|
| 1971 | + if ( ! $REG_ID) { |
|
| 1972 | + EE_Error::add_error(__('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__, |
|
| 1973 | + __FUNCTION__, __LINE__); |
|
| 1974 | + } |
|
| 1975 | + $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 1976 | + $form->receive_form_submission($this->_req_data); |
|
| 1977 | + $success = false; |
|
| 1978 | + if ($form->is_valid()) { |
|
| 1979 | + foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
| 1980 | + foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 1981 | + $where_conditions = array( |
|
| 1982 | + 'QST_ID' => $question_id, |
|
| 1983 | + 'REG_ID' => $REG_ID, |
|
| 1984 | + ); |
|
| 1985 | + $possibly_new_values = array( |
|
| 1986 | + 'ANS_value' => $input->normalized_value(), |
|
| 1987 | + ); |
|
| 1988 | + $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
| 1989 | + if ($answer instanceof EE_Answer) { |
|
| 1990 | + $success = $answer->save($possibly_new_values); |
|
| 1991 | + } else { |
|
| 1992 | + //insert it then |
|
| 1993 | + $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 1994 | + $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 1995 | + $success = $answer->save(); |
|
| 1996 | + } |
|
| 1997 | + } |
|
| 1998 | + } |
|
| 1999 | + } else { |
|
| 2000 | + EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2001 | + } |
|
| 2002 | + return $success; |
|
| 2003 | + } |
|
| 2004 | + |
|
| 2005 | + |
|
| 2006 | + /** |
|
| 2007 | + * generates HTML for the Registration main meta box |
|
| 2008 | + * |
|
| 2009 | + * @access public |
|
| 2010 | + * @return void |
|
| 2011 | + */ |
|
| 2012 | + public function _reg_attendees_meta_box() |
|
| 2013 | + { |
|
| 2014 | + $REG = EEM_Registration::instance(); |
|
| 2015 | + //get all other registrations on this transaction, and cache |
|
| 2016 | + //the attendees for them so we don't have to run another query using force_join |
|
| 2017 | + $registrations = $REG->get_all(array( |
|
| 2018 | + array( |
|
| 2019 | + 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2020 | + 'REG_ID' => array('!=', $this->_registration->ID()), |
|
| 2021 | + ), |
|
| 2022 | + 'force_join' => array('Attendee'), |
|
| 2023 | + )); |
|
| 2024 | + $this->_template_args['attendees'] = array(); |
|
| 2025 | + $this->_template_args['attendee_notice'] = ''; |
|
| 2026 | + if (empty($registrations) |
|
| 2027 | + || (is_array($registrations) |
|
| 2028 | + && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2029 | + ) { |
|
| 2030 | + EE_Error::add_error(__('There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2031 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2032 | + $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2033 | + } else { |
|
| 2034 | + $att_nmbr = 1; |
|
| 2035 | + foreach ($registrations as $registration) { |
|
| 2036 | + /* @var $registration EE_Registration */ |
|
| 2037 | + $attendee = $registration->attendee() |
|
| 2038 | + ? $registration->attendee() |
|
| 2039 | + : EEM_Attendee::instance() |
|
| 2040 | + ->create_default_object(); |
|
| 2041 | + $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
|
| 2042 | + $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : ''; |
|
| 2043 | + $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : ''; |
|
| 2044 | + $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : ''; |
|
| 2045 | + $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : ''; |
|
| 2046 | + $this->_template_args['attendees'][$att_nmbr]['address'] = implode(', ', |
|
| 2047 | + $attendee->full_address_as_array()); |
|
| 2048 | + $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(array( |
|
| 2049 | + 'action' => 'edit_attendee', |
|
| 2050 | + 'post' => $attendee->ID(), |
|
| 2051 | + ), REG_ADMIN_URL); |
|
| 2052 | + $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2053 | + $att_nmbr++; |
|
| 2054 | + } |
|
| 2055 | + //EEH_Debug_Tools::printr( $attendees, '$attendees <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' ); |
|
| 2056 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2057 | + // $this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees' ), REG_ADMIN_URL ); |
|
| 2058 | + } |
|
| 2059 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2060 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2061 | + } |
|
| 2062 | + |
|
| 2063 | + |
|
| 2064 | + /** |
|
| 2065 | + * generates HTML for the Edit Registration side meta box |
|
| 2066 | + * |
|
| 2067 | + * @access public |
|
| 2068 | + * @return void |
|
| 2069 | + */ |
|
| 2070 | + public function _reg_registrant_side_meta_box() |
|
| 2071 | + { |
|
| 2072 | + /*@var $attendee EE_Attendee */ |
|
| 2073 | + $att_check = $this->_registration->attendee(); |
|
| 2074 | + $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
| 2075 | + //now let's determine if this is not the primary registration. If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show create button or not) |
|
| 2076 | + if ( ! $this->_registration->is_primary_registrant()) { |
|
| 2077 | + $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2078 | + $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2079 | + : null; |
|
| 2080 | + if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2081 | + //in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg. |
|
| 2082 | + $primary_registration = null; |
|
| 2083 | + } |
|
| 2084 | + } else { |
|
| 2085 | + $primary_registration = null; |
|
| 2086 | + } |
|
| 2087 | + $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2088 | + $this->_template_args['fname'] = $attendee->fname();//$this->_registration->ATT_fname; |
|
| 2089 | + $this->_template_args['lname'] = $attendee->lname();//$this->_registration->ATT_lname; |
|
| 2090 | + $this->_template_args['email'] = $attendee->email();//$this->_registration->ATT_email; |
|
| 2091 | + $this->_template_args['phone'] = $attendee->phone(); |
|
| 2092 | + $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2093 | + //edit link |
|
| 2094 | + $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2095 | + 'action' => 'edit_attendee', |
|
| 2096 | + 'post' => $attendee->ID(), |
|
| 2097 | + ), REG_ADMIN_URL); |
|
| 2098 | + $this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso'); |
|
| 2099 | + //create link |
|
| 2100 | + $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2101 | + ? EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2102 | + 'action' => 'duplicate_attendee', |
|
| 2103 | + '_REG_ID' => $this->_registration->ID(), |
|
| 2104 | + ), REG_ADMIN_URL) : ''; |
|
| 2105 | + $this->_template_args['create_label'] = __('Create Contact', 'event_espresso'); |
|
| 2106 | + $this->_template_args['att_check'] = $att_check; |
|
| 2107 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2108 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2109 | + } |
|
| 2110 | + |
|
| 2111 | + |
|
| 2112 | + /** |
|
| 2113 | + * trash or restore registrations |
|
| 2114 | + * |
|
| 2115 | + * @param boolean $trash whether to archive or restore |
|
| 2116 | + * @access protected |
|
| 2117 | + * @return void |
|
| 2118 | + */ |
|
| 2119 | + protected function _trash_or_restore_registrations($trash = true) |
|
| 2120 | + { |
|
| 2121 | + $REGM = EEM_Registration::instance(); |
|
| 2122 | + $success = 1; |
|
| 2123 | + $error = 0; |
|
| 2124 | + $tickets = array(); |
|
| 2125 | + $dtts = array(); |
|
| 2126 | + //if empty _REG_ID then get out because there's nothing to do |
|
| 2127 | + if (empty($this->_req_data['_REG_ID'])) { |
|
| 2128 | + $msg = $trash |
|
| 2129 | + ? __('In order to trash registrations you must select which ones you wish to trash by clicking the checkboxes.', |
|
| 2130 | + 'event_espresso') |
|
| 2131 | + : __('In order to restore registrations you must select which ones you wish to restore by clicking the checkboxes.', |
|
| 2132 | + 'event_espresso'); |
|
| 2133 | + EE_Error::add_error($msg, __FILE__, __LINE__, __FUNCTION__); |
|
| 2134 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 2135 | + } |
|
| 2136 | + //Checkboxes |
|
| 2137 | + if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2138 | + // if array has more than one element than success message should be plural |
|
| 2139 | + $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2140 | + // cycle thru checkboxes |
|
| 2141 | + while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2142 | + /** @var EE_Registration $REG */ |
|
| 2143 | + $REG = $REGM->get_one_by_ID($REG_ID); |
|
| 2144 | + $payment_count = $REG->get_first_related('Transaction')->count_related('Payment'); |
|
| 2145 | + if ($payment_count > 0) { |
|
| 2146 | + $name = $REG->attendee() instanceof EE_Attendee ? $REG->attendee()->full_name() |
|
| 2147 | + : __('Unknown Attendee', 'event_espresso'); |
|
| 2148 | + $error = 1; |
|
| 2149 | + $success = 0; |
|
| 2150 | + EE_Error::add_error(sprintf(__('The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
| 2151 | + 'event_espresso'), $name), __FILE__, __FUNCTION__, __LINE__); |
|
| 2152 | + continue; //can't trash this registration because it has payments. |
|
| 2153 | + } |
|
| 2154 | + $ticket = $REG->get_first_related('Ticket'); |
|
| 2155 | + $tickets[$ticket->ID()] = $ticket; |
|
| 2156 | + $dtt = $ticket->get_many_related('Datetime'); |
|
| 2157 | + $dtts = array_merge($dtts, $dtt); |
|
| 2158 | + $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2159 | + if ( ! $updated) { |
|
| 2160 | + $success = 0; |
|
| 2161 | + } else { |
|
| 2162 | + $success = 2; |
|
| 2163 | + }/**/ |
|
| 2164 | + } |
|
| 2165 | + } else { |
|
| 2166 | + // grab single id and delete |
|
| 2167 | + $REG_ID = absint($this->_req_data['_REG_ID']); |
|
| 2168 | + $REG = $REGM->get_one_by_ID($REG_ID); |
|
| 2169 | + $ticket = $REG->get_first_related('Ticket'); |
|
| 2170 | + $tickets[$ticket->ID()] = $ticket; |
|
| 2171 | + $dtts = $ticket->get_many_related('Datetime'); |
|
| 2172 | + $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2173 | + if ( ! $updated) { |
|
| 2174 | + $success = 0; |
|
| 2175 | + } |
|
| 2176 | + } |
|
| 2177 | + //now let's update counts |
|
| 2178 | + EEM_Ticket::instance()->update_tickets_sold($tickets); |
|
| 2179 | + EEM_Datetime::instance()->update_sold($dtts); |
|
| 2180 | + $what = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso'); |
|
| 2181 | + $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2182 | + $overwrite_msgs = $error ? true : false; |
|
| 2183 | + $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), $overwrite_msgs); |
|
| 2184 | + } |
|
| 2185 | + |
|
| 2186 | + |
|
| 2187 | + /** |
|
| 2188 | + * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2189 | + * registration but also. |
|
| 2190 | + * 1. Removing relations to EE_Attendee |
|
| 2191 | + * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2192 | + * ALSO trashed. |
|
| 2193 | + * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2194 | + * 4. Removing relationships between all tickets and the related registrations |
|
| 2195 | + * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2196 | + * 6. Deleting permanently any related Checkins. |
|
| 2197 | + * |
|
| 2198 | + * @return void |
|
| 2199 | + */ |
|
| 2200 | + protected function _delete_registrations() |
|
| 2201 | + { |
|
| 2202 | + $REG_MDL = EEM_Registration::instance(); |
|
| 2203 | + $success = 1; |
|
| 2204 | + //Checkboxes |
|
| 2205 | + if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2206 | + // if array has more than one element than success message should be plural |
|
| 2207 | + $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2208 | + // cycle thru checkboxes |
|
| 2209 | + while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2210 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2211 | + if ( ! $REG instanceof EE_Registration) { |
|
| 2212 | + continue; |
|
| 2213 | + } |
|
| 2214 | + $deleted = $this->_delete_registration($REG); |
|
| 2215 | + if ( ! $deleted) { |
|
| 2216 | + $success = 0; |
|
| 2217 | + } |
|
| 2218 | + } |
|
| 2219 | + } else { |
|
| 2220 | + // grab single id and delete |
|
| 2221 | + $REG_ID = $this->_req_data['_REG_ID']; |
|
| 2222 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2223 | + $deleted = $this->_delete_registration($REG); |
|
| 2224 | + if ( ! $deleted) { |
|
| 2225 | + $success = 0; |
|
| 2226 | + } |
|
| 2227 | + } |
|
| 2228 | + $what = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso'); |
|
| 2229 | + $action_desc = __('permanently deleted.', 'event_espresso'); |
|
| 2230 | + $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), true); |
|
| 2231 | + } |
|
| 2232 | + |
|
| 2233 | + |
|
| 2234 | + /** |
|
| 2235 | + * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2236 | + * models get affected. |
|
| 2237 | + * |
|
| 2238 | + * @param EE_Registration $REG registration to be deleted permenantly |
|
| 2239 | + * @return boolean true = successful deletion, false = fail. |
|
| 2240 | + */ |
|
| 2241 | + protected function _delete_registration(EE_Registration $REG) |
|
| 2242 | + { |
|
| 2243 | + //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed. |
|
| 2244 | + $TXN = $REG->get_first_related('Transaction'); |
|
| 2245 | + $REGS = $TXN->get_many_related('Registration'); |
|
| 2246 | + $all_trashed = true; |
|
| 2247 | + foreach ($REGS as $registration) { |
|
| 2248 | + if ( ! $registration->get('REG_deleted')) { |
|
| 2249 | + $all_trashed = false; |
|
| 2250 | + } |
|
| 2251 | + } |
|
| 2252 | + if ( ! $all_trashed) { |
|
| 2253 | + EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
| 2254 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2255 | + return false; |
|
| 2256 | + } |
|
| 2257 | + //k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one). |
|
| 2258 | + foreach ($REGS as $registration) { |
|
| 2259 | + //delete related answers |
|
| 2260 | + $registration->delete_related_permanently('Answer'); |
|
| 2261 | + //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2262 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 2263 | + if ($attendee instanceof EE_Attendee) { |
|
| 2264 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2265 | + } |
|
| 2266 | + //now remove relationships to tickets on this registration. |
|
| 2267 | + $registration->_remove_relations('Ticket'); |
|
| 2268 | + //now delete permanently the checkins related to this registration. |
|
| 2269 | + $registration->delete_related_permanently('Checkin'); |
|
| 2270 | + if ($registration->ID() === $REG->ID()) { |
|
| 2271 | + continue; |
|
| 2272 | + } //we don't want to delete permanently the existing registration just yet. |
|
| 2273 | + //remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2274 | + $registration->_remove_relations('Transaction'); |
|
| 2275 | + //delete permanently any related messages. |
|
| 2276 | + $registration->delete_related_permanently('Message'); |
|
| 2277 | + //now delete this registration permanently |
|
| 2278 | + $registration->delete_permanently(); |
|
| 2279 | + } |
|
| 2280 | + //now all related registrations on the transaction are handled. So let's just handle this registration itself (the transaction and line items should be all that's left). |
|
| 2281 | + //delete the line items related to the transaction for this registration. |
|
| 2282 | + $TXN->delete_related_permanently('Line_Item'); |
|
| 2283 | + //we need to remove all the relationships on the transaction |
|
| 2284 | + $TXN->delete_related_permanently('Payment'); |
|
| 2285 | + $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2286 | + $TXN->delete_related_permanently('Message'); |
|
| 2287 | + //now we can delete this REG permanently (and the transaction of course) |
|
| 2288 | + $REG->delete_related_permanently('Transaction'); |
|
| 2289 | + return $REG->delete_permanently(); |
|
| 2290 | + } |
|
| 2291 | + |
|
| 2292 | + |
|
| 2293 | + /** |
|
| 2294 | + * generates HTML for the Register New Attendee Admin page |
|
| 2295 | + * |
|
| 2296 | + * @access private |
|
| 2297 | + * @throws \EE_Error |
|
| 2298 | + * @return void |
|
| 2299 | + */ |
|
| 2300 | + public function new_registration() |
|
| 2301 | + { |
|
| 2302 | + if ( ! $this->_set_reg_event()) { |
|
| 2303 | + throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request', |
|
| 2304 | + 'event_espresso')); |
|
| 2305 | + } |
|
| 2306 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2307 | + // gotta start with a clean slate if we're not coming here via ajax |
|
| 2308 | + if ( ! defined('DOING_AJAX') |
|
| 2309 | + && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
| 2310 | + ) { |
|
| 2311 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2312 | + } |
|
| 2313 | + $this->_template_args['event_name'] = ''; |
|
| 2314 | + // event name |
|
| 2315 | + if ($this->_reg_event) { |
|
| 2316 | + $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2317 | + $edit_event_url = self::add_query_args_and_nonce(array( |
|
| 2318 | + 'action' => 'edit', |
|
| 2319 | + 'post' => $this->_reg_event->ID(), |
|
| 2320 | + ), EVENTS_ADMIN_URL); |
|
| 2321 | + $edit_event_lnk = '<a href="' |
|
| 2322 | + . $edit_event_url |
|
| 2323 | + . '" title="' |
|
| 2324 | + . esc_attr__('Edit ', 'event_espresso') |
|
| 2325 | + . $this->_reg_event->name() |
|
| 2326 | + . '">' |
|
| 2327 | + . __('Edit Event', 'event_espresso') |
|
| 2328 | + . '</a>'; |
|
| 2329 | + $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2330 | + . $edit_event_lnk |
|
| 2331 | + . '</span>'; |
|
| 2332 | + } |
|
| 2333 | + $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2334 | + if (defined('DOING_AJAX')) { |
|
| 2335 | + $this->_return_json(); |
|
| 2336 | + } |
|
| 2337 | + // grab header |
|
| 2338 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2339 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
| 2340 | + $this->_template_args, true); |
|
| 2341 | + //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2342 | + // the details template wrapper |
|
| 2343 | + $this->display_admin_page_with_sidebar(); |
|
| 2344 | + } |
|
| 2345 | + |
|
| 2346 | + |
|
| 2347 | + /** |
|
| 2348 | + * This returns the content for a registration step |
|
| 2349 | + * |
|
| 2350 | + * @access protected |
|
| 2351 | + * @return string html |
|
| 2352 | + */ |
|
| 2353 | + protected function _get_registration_step_content() |
|
| 2354 | + { |
|
| 2355 | + if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 2356 | + $warning_msg = sprintf(__('%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', |
|
| 2357 | + 'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">', |
|
| 2358 | + '<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>'); |
|
| 2359 | + return ' |
|
| 2360 | 2360 | <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div> |
| 2361 | 2361 | <script > |
| 2362 | 2362 | // WHOAH !!! it appears that someone is using the back button from the Transaction admin page |
@@ -2369,658 +2369,658 @@ discard block |
||
| 2369 | 2369 | } |
| 2370 | 2370 | }, 800 ); |
| 2371 | 2371 | </script >'; |
| 2372 | - } |
|
| 2373 | - $template_args = array( |
|
| 2374 | - 'title' => '', |
|
| 2375 | - 'content' => '', |
|
| 2376 | - 'step_button_text' => '', |
|
| 2377 | - 'show_notification_toggle' => false, |
|
| 2378 | - ); |
|
| 2379 | - //to indicate we're processing a new registration |
|
| 2380 | - $hidden_fields = array( |
|
| 2381 | - 'processing_registration' => array( |
|
| 2382 | - 'type' => 'hidden', |
|
| 2383 | - 'value' => 0, |
|
| 2384 | - ), |
|
| 2385 | - 'event_id' => array( |
|
| 2386 | - 'type' => 'hidden', |
|
| 2387 | - 'value' => $this->_reg_event->ID(), |
|
| 2388 | - ), |
|
| 2389 | - ); |
|
| 2390 | - //if the cart is empty then we know we're at step one so we'll display ticket selector |
|
| 2391 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2392 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2393 | - switch ($step) { |
|
| 2394 | - case 'ticket' : |
|
| 2395 | - $hidden_fields['processing_registration']['value'] = 1; |
|
| 2396 | - $template_args['title'] = __('Step One: Select the Ticket for this registration', |
|
| 2397 | - 'event_espresso'); |
|
| 2398 | - $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 2399 | - $template_args['step_button_text'] = __('Add Tickets and Continue to Registrant Details', |
|
| 2400 | - 'event_espresso'); |
|
| 2401 | - $template_args['show_notification_toggle'] = false; |
|
| 2402 | - break; |
|
| 2403 | - case 'questions' : |
|
| 2404 | - $hidden_fields['processing_registration']['value'] = 2; |
|
| 2405 | - $template_args['title'] = __('Step Two: Add Registrant Details for this Registration', |
|
| 2406 | - 'event_espresso'); |
|
| 2407 | - //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. |
|
| 2408 | - $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 2409 | - $template_args['step_button_text'] = __('Save Registration and Continue to Details', |
|
| 2410 | - 'event_espresso'); |
|
| 2411 | - $template_args['show_notification_toggle'] = true; |
|
| 2412 | - break; |
|
| 2413 | - } |
|
| 2414 | - $this->_set_add_edit_form_tags('process_reg_step', |
|
| 2415 | - $hidden_fields); //we come back to the process_registration_step route. |
|
| 2416 | - return EEH_Template::display_template(REG_TEMPLATE_PATH |
|
| 2417 | - . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2418 | - $template_args, true); |
|
| 2419 | - } |
|
| 2420 | - |
|
| 2421 | - |
|
| 2422 | - /** |
|
| 2423 | - * set_reg_event |
|
| 2424 | - * |
|
| 2425 | - * @access private |
|
| 2426 | - * @return boolean |
|
| 2427 | - */ |
|
| 2428 | - private function _set_reg_event() |
|
| 2429 | - { |
|
| 2430 | - if (is_object($this->_reg_event)) { |
|
| 2431 | - return true; |
|
| 2432 | - } |
|
| 2433 | - $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 2434 | - if ( ! $EVT_ID) { |
|
| 2435 | - return false; |
|
| 2436 | - } |
|
| 2437 | - $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2438 | - return true; |
|
| 2439 | - } |
|
| 2440 | - |
|
| 2441 | - |
|
| 2442 | - /** |
|
| 2443 | - * process_reg_step |
|
| 2444 | - * |
|
| 2445 | - * @access public |
|
| 2446 | - * @return string |
|
| 2447 | - * @throws \RuntimeException |
|
| 2448 | - * @throws \EE_Error |
|
| 2449 | - */ |
|
| 2450 | - public function process_reg_step() |
|
| 2451 | - { |
|
| 2452 | - EE_System::do_not_cache(); |
|
| 2453 | - $this->_set_reg_event(); |
|
| 2454 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2455 | - EE_Registry::instance()->REQ->set('uts', time()); |
|
| 2456 | - //what step are we on? |
|
| 2457 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2458 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2459 | - //if doing ajax then we need to verify the nonce |
|
| 2460 | - if (defined('DOING_AJAX')) { |
|
| 2461 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 2462 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : ''; |
|
| 2463 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 2464 | - } |
|
| 2465 | - switch ($step) { |
|
| 2466 | - case 'ticket' : |
|
| 2467 | - //process ticket selection |
|
| 2468 | - $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 2469 | - if ($success) { |
|
| 2470 | - EE_Error::add_success(esc_html__('Tickets Selected. Now complete the registration.', |
|
| 2471 | - 'event_espresso')); |
|
| 2472 | - } else { |
|
| 2473 | - $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
| 2474 | - } |
|
| 2475 | - if (defined('DOING_AJAX')) { |
|
| 2476 | - $this->new_registration(); //display next step |
|
| 2477 | - } else { |
|
| 2478 | - $query_args = array( |
|
| 2479 | - 'action' => 'new_registration', |
|
| 2480 | - 'processing_registration' => 1, |
|
| 2481 | - 'event_id' => $this->_reg_event->ID(), |
|
| 2482 | - 'uts' => time(), |
|
| 2483 | - ); |
|
| 2484 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2485 | - } |
|
| 2486 | - break; |
|
| 2487 | - case 'questions' : |
|
| 2488 | - if ( ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) { |
|
| 2489 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 2490 | - } |
|
| 2491 | - //process registration |
|
| 2492 | - $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 2493 | - if ($cart instanceof EE_Cart) { |
|
| 2494 | - $grand_total = $cart->get_cart_grand_total(); |
|
| 2495 | - if ($grand_total instanceof EE_Line_Item) { |
|
| 2496 | - $grand_total->save_this_and_descendants_to_txn(); |
|
| 2497 | - } |
|
| 2498 | - } |
|
| 2499 | - if ( ! $transaction instanceof EE_Transaction) { |
|
| 2500 | - $query_args = array( |
|
| 2501 | - 'action' => 'new_registration', |
|
| 2502 | - 'processing_registration' => 2, |
|
| 2503 | - 'event_id' => $this->_reg_event->ID(), |
|
| 2504 | - 'uts' => time(), |
|
| 2505 | - ); |
|
| 2506 | - if (defined('DOING_AJAX')) { |
|
| 2507 | - //display registration form again because there are errors (maybe validation?) |
|
| 2508 | - $this->new_registration(); |
|
| 2509 | - return; |
|
| 2510 | - } else { |
|
| 2511 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2512 | - return; |
|
| 2513 | - } |
|
| 2514 | - } |
|
| 2515 | - // maybe update status, and make sure to save transaction if not done already |
|
| 2516 | - if ( ! $transaction->update_status_based_on_total_paid()) { |
|
| 2517 | - $transaction->save(); |
|
| 2518 | - } |
|
| 2519 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2520 | - $this->_req_data = array(); |
|
| 2521 | - $query_args = array( |
|
| 2522 | - 'action' => 'redirect_to_txn', |
|
| 2523 | - 'TXN_ID' => $transaction->ID(), |
|
| 2524 | - 'EVT_ID' => $this->_reg_event->ID(), |
|
| 2525 | - 'event_name' => urlencode($this->_reg_event->name()), |
|
| 2526 | - 'redirect_from' => 'new_registration', |
|
| 2527 | - ); |
|
| 2528 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2529 | - break; |
|
| 2530 | - } |
|
| 2531 | - //what are you looking here for? Should be nothing to do at this point. |
|
| 2532 | - } |
|
| 2533 | - |
|
| 2534 | - |
|
| 2535 | - /** |
|
| 2536 | - * redirect_to_txn |
|
| 2537 | - * |
|
| 2538 | - * @access public |
|
| 2539 | - * @return void |
|
| 2540 | - */ |
|
| 2541 | - public function redirect_to_txn() |
|
| 2542 | - { |
|
| 2543 | - EE_System::do_not_cache(); |
|
| 2544 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2545 | - $query_args = array( |
|
| 2546 | - 'action' => 'view_transaction', |
|
| 2547 | - 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
| 2548 | - 'page' => 'espresso_transactions', |
|
| 2549 | - ); |
|
| 2550 | - if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
| 2551 | - $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2552 | - $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
| 2553 | - $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
| 2554 | - } |
|
| 2555 | - EE_Error::add_success(__('Registration Created. Please review the transaction and add any payments as necessary', |
|
| 2556 | - 'event_espresso')); |
|
| 2557 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2558 | - } |
|
| 2559 | - |
|
| 2560 | - |
|
| 2561 | - /** |
|
| 2562 | - * generates HTML for the Attendee Contact List |
|
| 2563 | - * |
|
| 2564 | - * @access protected |
|
| 2565 | - * @return void |
|
| 2566 | - */ |
|
| 2567 | - protected function _attendee_contact_list_table() |
|
| 2568 | - { |
|
| 2569 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2570 | - $this->_search_btn_label = __('Contacts', 'event_espresso'); |
|
| 2571 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 2572 | - } |
|
| 2573 | - |
|
| 2574 | - |
|
| 2575 | - /** |
|
| 2576 | - * get_attendees |
|
| 2577 | - * |
|
| 2578 | - * @param bool $count whether to return count or data. |
|
| 2579 | - * @access public |
|
| 2580 | - * @return array |
|
| 2581 | - */ |
|
| 2582 | - public function get_attendees($per_page, $count = false, $trash = false) |
|
| 2583 | - { |
|
| 2584 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2585 | - require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 2586 | - $ATT_MDL = EEM_Attendee::instance(); |
|
| 2587 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2588 | - switch ($this->_req_data['orderby']) { |
|
| 2589 | - case 'ATT_ID': |
|
| 2590 | - $orderby = 'ATT_ID'; |
|
| 2591 | - break; |
|
| 2592 | - case 'ATT_fname': |
|
| 2593 | - $orderby = 'ATT_fname'; |
|
| 2594 | - break; |
|
| 2595 | - case 'ATT_email': |
|
| 2596 | - $orderby = 'ATT_email'; |
|
| 2597 | - break; |
|
| 2598 | - case 'ATT_city': |
|
| 2599 | - $orderby = 'ATT_city'; |
|
| 2600 | - break; |
|
| 2601 | - case 'STA_ID': |
|
| 2602 | - $orderby = 'STA_ID'; |
|
| 2603 | - break; |
|
| 2604 | - case 'CNT_ID': |
|
| 2605 | - $orderby = 'CNT_ID'; |
|
| 2606 | - break; |
|
| 2607 | - default: |
|
| 2608 | - $orderby = 'ATT_lname'; |
|
| 2609 | - } |
|
| 2610 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 2611 | - : 'ASC'; |
|
| 2612 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 2613 | - ? $this->_req_data['paged'] : 1; |
|
| 2614 | - $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
| 2615 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 2616 | - ? $this->_req_data['perpage'] : $per_page; |
|
| 2617 | - $_where = array(); |
|
| 2618 | - if ( ! empty($this->_req_data['s'])) { |
|
| 2619 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2620 | - $_where['OR'] = array( |
|
| 2621 | - 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
| 2622 | - 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
| 2623 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 2624 | - 'ATT_fname' => array('LIKE', $sstr), |
|
| 2625 | - 'ATT_lname' => array('LIKE', $sstr), |
|
| 2626 | - 'ATT_short_bio' => array('LIKE', $sstr), |
|
| 2627 | - 'ATT_email' => array('LIKE', $sstr), |
|
| 2628 | - 'ATT_address' => array('LIKE', $sstr), |
|
| 2629 | - 'ATT_address2' => array('LIKE', $sstr), |
|
| 2630 | - 'ATT_city' => array('LIKE', $sstr), |
|
| 2631 | - 'Country.CNT_name' => array('LIKE', $sstr), |
|
| 2632 | - 'State.STA_name' => array('LIKE', $sstr), |
|
| 2633 | - 'ATT_phone' => array('LIKE', $sstr), |
|
| 2634 | - 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
| 2635 | - 'Registration.REG_code' => array('LIKE', $sstr), |
|
| 2636 | - 'Registration.REG_count' => array('LIKE', $sstr), |
|
| 2637 | - 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
| 2638 | - ); |
|
| 2639 | - } |
|
| 2640 | - $offset = ($current_page - 1) * $per_page; |
|
| 2641 | - $limit = $count ? null : array($offset, $per_page); |
|
| 2642 | - if ($trash) { |
|
| 2643 | - $_where['status'] = array('!=', 'publish'); |
|
| 2644 | - $all_attendees = $count |
|
| 2645 | - ? $ATT_MDL->count(array( |
|
| 2646 | - $_where, |
|
| 2647 | - 'order_by' => array($orderby => $sort), |
|
| 2648 | - 'limit' => $limit, |
|
| 2649 | - ), 'ATT_ID', true) |
|
| 2650 | - : $ATT_MDL->get_all(array( |
|
| 2651 | - $_where, |
|
| 2652 | - 'order_by' => array($orderby => $sort), |
|
| 2653 | - 'limit' => $limit, |
|
| 2654 | - )); |
|
| 2655 | - } else { |
|
| 2656 | - $_where['status'] = array('IN', array('publish')); |
|
| 2657 | - $all_attendees = $count |
|
| 2658 | - ? $ATT_MDL->count(array( |
|
| 2659 | - $_where, |
|
| 2660 | - 'order_by' => array($orderby => $sort), |
|
| 2661 | - 'limit' => $limit, |
|
| 2662 | - ), 'ATT_ID', true) |
|
| 2663 | - : $ATT_MDL->get_all(array( |
|
| 2664 | - $_where, |
|
| 2665 | - 'order_by' => array($orderby => $sort), |
|
| 2666 | - 'limit' => $limit, |
|
| 2667 | - )); |
|
| 2668 | - } |
|
| 2669 | - return $all_attendees; |
|
| 2670 | - } |
|
| 2671 | - |
|
| 2672 | - |
|
| 2673 | - /** |
|
| 2674 | - * This is just taking care of resending the registration confirmation |
|
| 2675 | - * |
|
| 2676 | - * @access protected |
|
| 2677 | - * @return void |
|
| 2678 | - */ |
|
| 2679 | - protected function _resend_registration() |
|
| 2680 | - { |
|
| 2681 | - $this->_process_resend_registration(); |
|
| 2682 | - $query_args = isset($this->_req_data['redirect_to']) |
|
| 2683 | - ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
| 2684 | - : array( |
|
| 2685 | - 'action' => 'default', |
|
| 2686 | - ); |
|
| 2687 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2688 | - } |
|
| 2689 | - |
|
| 2690 | - /** |
|
| 2691 | - * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 2692 | - * to use when selecting registrations |
|
| 2693 | - * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 2694 | - * the query parameters from the request |
|
| 2695 | - * @return void ends the request with a redirect or download |
|
| 2696 | - */ |
|
| 2697 | - public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
| 2698 | - { |
|
| 2699 | - if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 2700 | - wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2701 | - 'page' => 'espresso_batch', |
|
| 2702 | - 'batch' => 'file', |
|
| 2703 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 2704 | - 'filters' => urlencode( |
|
| 2705 | - serialize( |
|
| 2706 | - call_user_func( |
|
| 2707 | - array( $this, $method_name_for_getting_query_params ), |
|
| 2708 | - EEH_Array::is_set( |
|
| 2709 | - $this->_req_data, |
|
| 2710 | - 'filters', |
|
| 2711 | - array() |
|
| 2712 | - ) |
|
| 2713 | - ) |
|
| 2714 | - ) |
|
| 2715 | - ), |
|
| 2716 | - 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
| 2717 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 2718 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 2719 | - ))); |
|
| 2720 | - } else { |
|
| 2721 | - $new_request_args = array( |
|
| 2722 | - 'export' => 'report', |
|
| 2723 | - 'action' => 'registrations_report_for_event', |
|
| 2724 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 2725 | - ); |
|
| 2726 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 2727 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2728 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2729 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2730 | - $EE_Export->export(); |
|
| 2731 | - } |
|
| 2732 | - } |
|
| 2733 | - } |
|
| 2734 | - |
|
| 2735 | - |
|
| 2736 | - |
|
| 2737 | - /** |
|
| 2738 | - * Creates a registration report using only query parameters in the request |
|
| 2739 | - * @return void |
|
| 2740 | - */ |
|
| 2741 | - public function _registrations_report() |
|
| 2742 | - { |
|
| 2743 | - $this->_registrations_report_base( '_get_registration_query_parameters' ); |
|
| 2744 | - } |
|
| 2745 | - |
|
| 2746 | - |
|
| 2747 | - public function _contact_list_export() |
|
| 2748 | - { |
|
| 2749 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2750 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2751 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2752 | - $EE_Export->export_attendees(); |
|
| 2753 | - } |
|
| 2754 | - } |
|
| 2755 | - |
|
| 2756 | - |
|
| 2757 | - public function _contact_list_report() |
|
| 2758 | - { |
|
| 2759 | - if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 2760 | - wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2761 | - 'page' => 'espresso_batch', |
|
| 2762 | - 'batch' => 'file', |
|
| 2763 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 2764 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 2765 | - ))); |
|
| 2766 | - } else { |
|
| 2767 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2768 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2769 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2770 | - $EE_Export->report_attendees(); |
|
| 2771 | - } |
|
| 2772 | - } |
|
| 2773 | - } |
|
| 2774 | - |
|
| 2775 | - |
|
| 2776 | - |
|
| 2777 | - |
|
| 2778 | - |
|
| 2779 | - /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 2780 | - /** |
|
| 2781 | - * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 2782 | - * |
|
| 2783 | - * @return void |
|
| 2784 | - */ |
|
| 2785 | - protected function _duplicate_attendee() |
|
| 2786 | - { |
|
| 2787 | - $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
| 2788 | - //verify we have necessary info |
|
| 2789 | - if (empty($this->_req_data['_REG_ID'])) { |
|
| 2790 | - EE_Error::add_error(__('Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 2791 | - 'event_espresso'), __FILE__, __LINE__, __FUNCTION__); |
|
| 2792 | - $query_args = array('action' => $action); |
|
| 2793 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 2794 | - } |
|
| 2795 | - //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 2796 | - $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
| 2797 | - $attendee = $registration->attendee(); |
|
| 2798 | - //remove relation of existing attendee on registration |
|
| 2799 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2800 | - //new attendee |
|
| 2801 | - $new_attendee = clone $attendee; |
|
| 2802 | - $new_attendee->set('ATT_ID', 0); |
|
| 2803 | - $new_attendee->save(); |
|
| 2804 | - //add new attendee to reg |
|
| 2805 | - $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 2806 | - EE_Error::add_success(__('New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 2807 | - 'event_espresso')); |
|
| 2808 | - //redirect to edit page for attendee |
|
| 2809 | - $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
| 2810 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 2811 | - } |
|
| 2812 | - |
|
| 2813 | - |
|
| 2814 | - //related to cpt routes |
|
| 2815 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 2816 | - { |
|
| 2817 | - $success = true; |
|
| 2818 | - $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id); |
|
| 2819 | - //for attendee updates |
|
| 2820 | - if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) { |
|
| 2821 | - //note we should only be UPDATING attendees at this point. |
|
| 2822 | - $updated_fields = array( |
|
| 2823 | - 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
| 2824 | - 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
| 2825 | - 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 2826 | - 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
| 2827 | - 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
| 2828 | - 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
| 2829 | - 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
| 2830 | - 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
| 2831 | - 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
| 2832 | - 'ATT_email' => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '', |
|
| 2833 | - 'ATT_phone' => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '', |
|
| 2834 | - ); |
|
| 2835 | - foreach ($updated_fields as $field => $value) { |
|
| 2836 | - $attendee->set($field, $value); |
|
| 2837 | - } |
|
| 2838 | - $success = $attendee->save(); |
|
| 2839 | - $attendee_update_callbacks = apply_filters('FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 2840 | - array()); |
|
| 2841 | - foreach ($attendee_update_callbacks as $a_callback) { |
|
| 2842 | - if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
| 2843 | - throw new EE_Error(sprintf(__('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
| 2844 | - 'event_espresso'), $a_callback)); |
|
| 2845 | - } |
|
| 2846 | - } |
|
| 2847 | - } |
|
| 2848 | - if ($success === false) { |
|
| 2849 | - EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.', |
|
| 2850 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2851 | - } |
|
| 2852 | - } |
|
| 2853 | - |
|
| 2854 | - |
|
| 2855 | - public function trash_cpt_item($post_id) |
|
| 2856 | - { |
|
| 2857 | - } |
|
| 2858 | - |
|
| 2859 | - |
|
| 2860 | - public function delete_cpt_item($post_id) |
|
| 2861 | - { |
|
| 2862 | - } |
|
| 2863 | - |
|
| 2864 | - |
|
| 2865 | - public function restore_cpt_item($post_id) |
|
| 2866 | - { |
|
| 2867 | - } |
|
| 2868 | - |
|
| 2869 | - |
|
| 2870 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 2871 | - { |
|
| 2872 | - } |
|
| 2873 | - |
|
| 2874 | - |
|
| 2875 | - public function attendee_editor_metaboxes() |
|
| 2876 | - { |
|
| 2877 | - $this->verify_cpt_object(); |
|
| 2878 | - remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action], |
|
| 2879 | - 'normal', 'core'); |
|
| 2880 | - remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2881 | - if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 2882 | - add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box', |
|
| 2883 | - $this->_cpt_routes[$this->_req_action], 'normal'); |
|
| 2884 | - } |
|
| 2885 | - if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 2886 | - add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box', |
|
| 2887 | - $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2888 | - } |
|
| 2889 | - add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'), |
|
| 2890 | - array($this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core'); |
|
| 2891 | - add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'), |
|
| 2892 | - array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2893 | - add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'), |
|
| 2894 | - array($this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high'); |
|
| 2895 | - } |
|
| 2896 | - |
|
| 2897 | - |
|
| 2898 | - /** |
|
| 2899 | - * Metabox for attendee contact info |
|
| 2900 | - * |
|
| 2901 | - * @param WP_Post $post wp post object |
|
| 2902 | - * @return string attendee contact info ( and form ) |
|
| 2903 | - */ |
|
| 2904 | - public function attendee_contact_info($post) |
|
| 2905 | - { |
|
| 2906 | - //get attendee object ( should already have it ) |
|
| 2907 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2908 | - $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
| 2909 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 2910 | - } |
|
| 2911 | - |
|
| 2912 | - |
|
| 2913 | - /** |
|
| 2914 | - * Metabox for attendee details |
|
| 2915 | - * |
|
| 2916 | - * @param WP_Post $post wp post object |
|
| 2917 | - * @return string attendee address details (and form) |
|
| 2918 | - */ |
|
| 2919 | - public function attendee_address_details($post) |
|
| 2920 | - { |
|
| 2921 | - //get attendee object (should already have it) |
|
| 2922 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2923 | - $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array( |
|
| 2924 | - 'QST_ID' => 0, |
|
| 2925 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 2926 | - 'QST_system' => 'admin-state', |
|
| 2927 | - )), EE_Answer::new_instance(array( |
|
| 2928 | - 'ANS_ID' => 0, |
|
| 2929 | - 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 2930 | - )), array( |
|
| 2931 | - 'input_id' => 'STA_ID', |
|
| 2932 | - 'input_name' => 'STA_ID', |
|
| 2933 | - 'input_prefix' => '', |
|
| 2934 | - 'append_qstn_id' => false, |
|
| 2935 | - ))); |
|
| 2936 | - $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array( |
|
| 2937 | - 'QST_ID' => 0, |
|
| 2938 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 2939 | - 'QST_system' => 'admin-country', |
|
| 2940 | - )), EE_Answer::new_instance(array( |
|
| 2941 | - 'ANS_ID' => 0, |
|
| 2942 | - 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 2943 | - )), array( |
|
| 2944 | - 'input_id' => 'CNT_ISO', |
|
| 2945 | - 'input_name' => 'CNT_ISO', |
|
| 2946 | - 'input_prefix' => '', |
|
| 2947 | - 'append_qstn_id' => false, |
|
| 2948 | - ))); |
|
| 2949 | - $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 2950 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 2951 | - } |
|
| 2952 | - |
|
| 2953 | - |
|
| 2954 | - /** |
|
| 2955 | - * _attendee_details |
|
| 2956 | - * |
|
| 2957 | - * @access protected |
|
| 2958 | - * @return void |
|
| 2959 | - */ |
|
| 2960 | - public function attendee_registrations_meta_box($post) |
|
| 2961 | - { |
|
| 2962 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2963 | - $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 2964 | - $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 2965 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 2966 | - } |
|
| 2967 | - |
|
| 2968 | - |
|
| 2969 | - /** |
|
| 2970 | - * add in the form fields for the attendee edit |
|
| 2971 | - * |
|
| 2972 | - * @param WP_Post $post wp post object |
|
| 2973 | - * @return string html for new form. |
|
| 2974 | - */ |
|
| 2975 | - public function after_title_form_fields($post) |
|
| 2976 | - { |
|
| 2977 | - if ($post->post_type == 'espresso_attendees') { |
|
| 2978 | - $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 2979 | - $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2980 | - EEH_Template::display_template($template, $template_args); |
|
| 2981 | - } |
|
| 2982 | - } |
|
| 2983 | - |
|
| 2984 | - |
|
| 2985 | - /** |
|
| 2986 | - * _trash_or_restore_attendee |
|
| 2987 | - * |
|
| 2988 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 2989 | - * @access protected |
|
| 2990 | - * @return void |
|
| 2991 | - */ |
|
| 2992 | - protected function _trash_or_restore_attendees($trash = true) |
|
| 2993 | - { |
|
| 2994 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2995 | - $ATT_MDL = EEM_Attendee::instance(); |
|
| 2996 | - $success = 1; |
|
| 2997 | - //Checkboxes |
|
| 2998 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2999 | - // if array has more than one element than success message should be plural |
|
| 3000 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3001 | - // cycle thru checkboxes |
|
| 3002 | - while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3003 | - $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
| 3004 | - : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
| 3005 | - if ( ! $updated) { |
|
| 3006 | - $success = 0; |
|
| 3007 | - } |
|
| 3008 | - } |
|
| 3009 | - } else { |
|
| 3010 | - // grab single id and delete |
|
| 3011 | - $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
| 3012 | - //get attendee |
|
| 3013 | - $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
| 3014 | - $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
| 3015 | - $updated = $att->save(); |
|
| 3016 | - if ( ! $updated) { |
|
| 3017 | - $success = 0; |
|
| 3018 | - } |
|
| 3019 | - } |
|
| 3020 | - $what = $success > 1 ? __('Contacts', 'event_espresso') : __('Contact', 'event_espresso'); |
|
| 3021 | - $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 3022 | - $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
| 3023 | - } |
|
| 2372 | + } |
|
| 2373 | + $template_args = array( |
|
| 2374 | + 'title' => '', |
|
| 2375 | + 'content' => '', |
|
| 2376 | + 'step_button_text' => '', |
|
| 2377 | + 'show_notification_toggle' => false, |
|
| 2378 | + ); |
|
| 2379 | + //to indicate we're processing a new registration |
|
| 2380 | + $hidden_fields = array( |
|
| 2381 | + 'processing_registration' => array( |
|
| 2382 | + 'type' => 'hidden', |
|
| 2383 | + 'value' => 0, |
|
| 2384 | + ), |
|
| 2385 | + 'event_id' => array( |
|
| 2386 | + 'type' => 'hidden', |
|
| 2387 | + 'value' => $this->_reg_event->ID(), |
|
| 2388 | + ), |
|
| 2389 | + ); |
|
| 2390 | + //if the cart is empty then we know we're at step one so we'll display ticket selector |
|
| 2391 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2392 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2393 | + switch ($step) { |
|
| 2394 | + case 'ticket' : |
|
| 2395 | + $hidden_fields['processing_registration']['value'] = 1; |
|
| 2396 | + $template_args['title'] = __('Step One: Select the Ticket for this registration', |
|
| 2397 | + 'event_espresso'); |
|
| 2398 | + $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 2399 | + $template_args['step_button_text'] = __('Add Tickets and Continue to Registrant Details', |
|
| 2400 | + 'event_espresso'); |
|
| 2401 | + $template_args['show_notification_toggle'] = false; |
|
| 2402 | + break; |
|
| 2403 | + case 'questions' : |
|
| 2404 | + $hidden_fields['processing_registration']['value'] = 2; |
|
| 2405 | + $template_args['title'] = __('Step Two: Add Registrant Details for this Registration', |
|
| 2406 | + 'event_espresso'); |
|
| 2407 | + //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. |
|
| 2408 | + $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 2409 | + $template_args['step_button_text'] = __('Save Registration and Continue to Details', |
|
| 2410 | + 'event_espresso'); |
|
| 2411 | + $template_args['show_notification_toggle'] = true; |
|
| 2412 | + break; |
|
| 2413 | + } |
|
| 2414 | + $this->_set_add_edit_form_tags('process_reg_step', |
|
| 2415 | + $hidden_fields); //we come back to the process_registration_step route. |
|
| 2416 | + return EEH_Template::display_template(REG_TEMPLATE_PATH |
|
| 2417 | + . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2418 | + $template_args, true); |
|
| 2419 | + } |
|
| 2420 | + |
|
| 2421 | + |
|
| 2422 | + /** |
|
| 2423 | + * set_reg_event |
|
| 2424 | + * |
|
| 2425 | + * @access private |
|
| 2426 | + * @return boolean |
|
| 2427 | + */ |
|
| 2428 | + private function _set_reg_event() |
|
| 2429 | + { |
|
| 2430 | + if (is_object($this->_reg_event)) { |
|
| 2431 | + return true; |
|
| 2432 | + } |
|
| 2433 | + $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 2434 | + if ( ! $EVT_ID) { |
|
| 2435 | + return false; |
|
| 2436 | + } |
|
| 2437 | + $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2438 | + return true; |
|
| 2439 | + } |
|
| 2440 | + |
|
| 2441 | + |
|
| 2442 | + /** |
|
| 2443 | + * process_reg_step |
|
| 2444 | + * |
|
| 2445 | + * @access public |
|
| 2446 | + * @return string |
|
| 2447 | + * @throws \RuntimeException |
|
| 2448 | + * @throws \EE_Error |
|
| 2449 | + */ |
|
| 2450 | + public function process_reg_step() |
|
| 2451 | + { |
|
| 2452 | + EE_System::do_not_cache(); |
|
| 2453 | + $this->_set_reg_event(); |
|
| 2454 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2455 | + EE_Registry::instance()->REQ->set('uts', time()); |
|
| 2456 | + //what step are we on? |
|
| 2457 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2458 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2459 | + //if doing ajax then we need to verify the nonce |
|
| 2460 | + if (defined('DOING_AJAX')) { |
|
| 2461 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 2462 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : ''; |
|
| 2463 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 2464 | + } |
|
| 2465 | + switch ($step) { |
|
| 2466 | + case 'ticket' : |
|
| 2467 | + //process ticket selection |
|
| 2468 | + $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 2469 | + if ($success) { |
|
| 2470 | + EE_Error::add_success(esc_html__('Tickets Selected. Now complete the registration.', |
|
| 2471 | + 'event_espresso')); |
|
| 2472 | + } else { |
|
| 2473 | + $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
| 2474 | + } |
|
| 2475 | + if (defined('DOING_AJAX')) { |
|
| 2476 | + $this->new_registration(); //display next step |
|
| 2477 | + } else { |
|
| 2478 | + $query_args = array( |
|
| 2479 | + 'action' => 'new_registration', |
|
| 2480 | + 'processing_registration' => 1, |
|
| 2481 | + 'event_id' => $this->_reg_event->ID(), |
|
| 2482 | + 'uts' => time(), |
|
| 2483 | + ); |
|
| 2484 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2485 | + } |
|
| 2486 | + break; |
|
| 2487 | + case 'questions' : |
|
| 2488 | + if ( ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) { |
|
| 2489 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 2490 | + } |
|
| 2491 | + //process registration |
|
| 2492 | + $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 2493 | + if ($cart instanceof EE_Cart) { |
|
| 2494 | + $grand_total = $cart->get_cart_grand_total(); |
|
| 2495 | + if ($grand_total instanceof EE_Line_Item) { |
|
| 2496 | + $grand_total->save_this_and_descendants_to_txn(); |
|
| 2497 | + } |
|
| 2498 | + } |
|
| 2499 | + if ( ! $transaction instanceof EE_Transaction) { |
|
| 2500 | + $query_args = array( |
|
| 2501 | + 'action' => 'new_registration', |
|
| 2502 | + 'processing_registration' => 2, |
|
| 2503 | + 'event_id' => $this->_reg_event->ID(), |
|
| 2504 | + 'uts' => time(), |
|
| 2505 | + ); |
|
| 2506 | + if (defined('DOING_AJAX')) { |
|
| 2507 | + //display registration form again because there are errors (maybe validation?) |
|
| 2508 | + $this->new_registration(); |
|
| 2509 | + return; |
|
| 2510 | + } else { |
|
| 2511 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2512 | + return; |
|
| 2513 | + } |
|
| 2514 | + } |
|
| 2515 | + // maybe update status, and make sure to save transaction if not done already |
|
| 2516 | + if ( ! $transaction->update_status_based_on_total_paid()) { |
|
| 2517 | + $transaction->save(); |
|
| 2518 | + } |
|
| 2519 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2520 | + $this->_req_data = array(); |
|
| 2521 | + $query_args = array( |
|
| 2522 | + 'action' => 'redirect_to_txn', |
|
| 2523 | + 'TXN_ID' => $transaction->ID(), |
|
| 2524 | + 'EVT_ID' => $this->_reg_event->ID(), |
|
| 2525 | + 'event_name' => urlencode($this->_reg_event->name()), |
|
| 2526 | + 'redirect_from' => 'new_registration', |
|
| 2527 | + ); |
|
| 2528 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2529 | + break; |
|
| 2530 | + } |
|
| 2531 | + //what are you looking here for? Should be nothing to do at this point. |
|
| 2532 | + } |
|
| 2533 | + |
|
| 2534 | + |
|
| 2535 | + /** |
|
| 2536 | + * redirect_to_txn |
|
| 2537 | + * |
|
| 2538 | + * @access public |
|
| 2539 | + * @return void |
|
| 2540 | + */ |
|
| 2541 | + public function redirect_to_txn() |
|
| 2542 | + { |
|
| 2543 | + EE_System::do_not_cache(); |
|
| 2544 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2545 | + $query_args = array( |
|
| 2546 | + 'action' => 'view_transaction', |
|
| 2547 | + 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
| 2548 | + 'page' => 'espresso_transactions', |
|
| 2549 | + ); |
|
| 2550 | + if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
| 2551 | + $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2552 | + $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
| 2553 | + $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
| 2554 | + } |
|
| 2555 | + EE_Error::add_success(__('Registration Created. Please review the transaction and add any payments as necessary', |
|
| 2556 | + 'event_espresso')); |
|
| 2557 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2558 | + } |
|
| 2559 | + |
|
| 2560 | + |
|
| 2561 | + /** |
|
| 2562 | + * generates HTML for the Attendee Contact List |
|
| 2563 | + * |
|
| 2564 | + * @access protected |
|
| 2565 | + * @return void |
|
| 2566 | + */ |
|
| 2567 | + protected function _attendee_contact_list_table() |
|
| 2568 | + { |
|
| 2569 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2570 | + $this->_search_btn_label = __('Contacts', 'event_espresso'); |
|
| 2571 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 2572 | + } |
|
| 2573 | + |
|
| 2574 | + |
|
| 2575 | + /** |
|
| 2576 | + * get_attendees |
|
| 2577 | + * |
|
| 2578 | + * @param bool $count whether to return count or data. |
|
| 2579 | + * @access public |
|
| 2580 | + * @return array |
|
| 2581 | + */ |
|
| 2582 | + public function get_attendees($per_page, $count = false, $trash = false) |
|
| 2583 | + { |
|
| 2584 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2585 | + require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 2586 | + $ATT_MDL = EEM_Attendee::instance(); |
|
| 2587 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2588 | + switch ($this->_req_data['orderby']) { |
|
| 2589 | + case 'ATT_ID': |
|
| 2590 | + $orderby = 'ATT_ID'; |
|
| 2591 | + break; |
|
| 2592 | + case 'ATT_fname': |
|
| 2593 | + $orderby = 'ATT_fname'; |
|
| 2594 | + break; |
|
| 2595 | + case 'ATT_email': |
|
| 2596 | + $orderby = 'ATT_email'; |
|
| 2597 | + break; |
|
| 2598 | + case 'ATT_city': |
|
| 2599 | + $orderby = 'ATT_city'; |
|
| 2600 | + break; |
|
| 2601 | + case 'STA_ID': |
|
| 2602 | + $orderby = 'STA_ID'; |
|
| 2603 | + break; |
|
| 2604 | + case 'CNT_ID': |
|
| 2605 | + $orderby = 'CNT_ID'; |
|
| 2606 | + break; |
|
| 2607 | + default: |
|
| 2608 | + $orderby = 'ATT_lname'; |
|
| 2609 | + } |
|
| 2610 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 2611 | + : 'ASC'; |
|
| 2612 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 2613 | + ? $this->_req_data['paged'] : 1; |
|
| 2614 | + $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
| 2615 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 2616 | + ? $this->_req_data['perpage'] : $per_page; |
|
| 2617 | + $_where = array(); |
|
| 2618 | + if ( ! empty($this->_req_data['s'])) { |
|
| 2619 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2620 | + $_where['OR'] = array( |
|
| 2621 | + 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
| 2622 | + 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
| 2623 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 2624 | + 'ATT_fname' => array('LIKE', $sstr), |
|
| 2625 | + 'ATT_lname' => array('LIKE', $sstr), |
|
| 2626 | + 'ATT_short_bio' => array('LIKE', $sstr), |
|
| 2627 | + 'ATT_email' => array('LIKE', $sstr), |
|
| 2628 | + 'ATT_address' => array('LIKE', $sstr), |
|
| 2629 | + 'ATT_address2' => array('LIKE', $sstr), |
|
| 2630 | + 'ATT_city' => array('LIKE', $sstr), |
|
| 2631 | + 'Country.CNT_name' => array('LIKE', $sstr), |
|
| 2632 | + 'State.STA_name' => array('LIKE', $sstr), |
|
| 2633 | + 'ATT_phone' => array('LIKE', $sstr), |
|
| 2634 | + 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
| 2635 | + 'Registration.REG_code' => array('LIKE', $sstr), |
|
| 2636 | + 'Registration.REG_count' => array('LIKE', $sstr), |
|
| 2637 | + 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
| 2638 | + ); |
|
| 2639 | + } |
|
| 2640 | + $offset = ($current_page - 1) * $per_page; |
|
| 2641 | + $limit = $count ? null : array($offset, $per_page); |
|
| 2642 | + if ($trash) { |
|
| 2643 | + $_where['status'] = array('!=', 'publish'); |
|
| 2644 | + $all_attendees = $count |
|
| 2645 | + ? $ATT_MDL->count(array( |
|
| 2646 | + $_where, |
|
| 2647 | + 'order_by' => array($orderby => $sort), |
|
| 2648 | + 'limit' => $limit, |
|
| 2649 | + ), 'ATT_ID', true) |
|
| 2650 | + : $ATT_MDL->get_all(array( |
|
| 2651 | + $_where, |
|
| 2652 | + 'order_by' => array($orderby => $sort), |
|
| 2653 | + 'limit' => $limit, |
|
| 2654 | + )); |
|
| 2655 | + } else { |
|
| 2656 | + $_where['status'] = array('IN', array('publish')); |
|
| 2657 | + $all_attendees = $count |
|
| 2658 | + ? $ATT_MDL->count(array( |
|
| 2659 | + $_where, |
|
| 2660 | + 'order_by' => array($orderby => $sort), |
|
| 2661 | + 'limit' => $limit, |
|
| 2662 | + ), 'ATT_ID', true) |
|
| 2663 | + : $ATT_MDL->get_all(array( |
|
| 2664 | + $_where, |
|
| 2665 | + 'order_by' => array($orderby => $sort), |
|
| 2666 | + 'limit' => $limit, |
|
| 2667 | + )); |
|
| 2668 | + } |
|
| 2669 | + return $all_attendees; |
|
| 2670 | + } |
|
| 2671 | + |
|
| 2672 | + |
|
| 2673 | + /** |
|
| 2674 | + * This is just taking care of resending the registration confirmation |
|
| 2675 | + * |
|
| 2676 | + * @access protected |
|
| 2677 | + * @return void |
|
| 2678 | + */ |
|
| 2679 | + protected function _resend_registration() |
|
| 2680 | + { |
|
| 2681 | + $this->_process_resend_registration(); |
|
| 2682 | + $query_args = isset($this->_req_data['redirect_to']) |
|
| 2683 | + ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
| 2684 | + : array( |
|
| 2685 | + 'action' => 'default', |
|
| 2686 | + ); |
|
| 2687 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2688 | + } |
|
| 2689 | + |
|
| 2690 | + /** |
|
| 2691 | + * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 2692 | + * to use when selecting registrations |
|
| 2693 | + * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 2694 | + * the query parameters from the request |
|
| 2695 | + * @return void ends the request with a redirect or download |
|
| 2696 | + */ |
|
| 2697 | + public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
| 2698 | + { |
|
| 2699 | + if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 2700 | + wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2701 | + 'page' => 'espresso_batch', |
|
| 2702 | + 'batch' => 'file', |
|
| 2703 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 2704 | + 'filters' => urlencode( |
|
| 2705 | + serialize( |
|
| 2706 | + call_user_func( |
|
| 2707 | + array( $this, $method_name_for_getting_query_params ), |
|
| 2708 | + EEH_Array::is_set( |
|
| 2709 | + $this->_req_data, |
|
| 2710 | + 'filters', |
|
| 2711 | + array() |
|
| 2712 | + ) |
|
| 2713 | + ) |
|
| 2714 | + ) |
|
| 2715 | + ), |
|
| 2716 | + 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
| 2717 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 2718 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 2719 | + ))); |
|
| 2720 | + } else { |
|
| 2721 | + $new_request_args = array( |
|
| 2722 | + 'export' => 'report', |
|
| 2723 | + 'action' => 'registrations_report_for_event', |
|
| 2724 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 2725 | + ); |
|
| 2726 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 2727 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2728 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2729 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2730 | + $EE_Export->export(); |
|
| 2731 | + } |
|
| 2732 | + } |
|
| 2733 | + } |
|
| 2734 | + |
|
| 2735 | + |
|
| 2736 | + |
|
| 2737 | + /** |
|
| 2738 | + * Creates a registration report using only query parameters in the request |
|
| 2739 | + * @return void |
|
| 2740 | + */ |
|
| 2741 | + public function _registrations_report() |
|
| 2742 | + { |
|
| 2743 | + $this->_registrations_report_base( '_get_registration_query_parameters' ); |
|
| 2744 | + } |
|
| 2745 | + |
|
| 2746 | + |
|
| 2747 | + public function _contact_list_export() |
|
| 2748 | + { |
|
| 2749 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2750 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2751 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2752 | + $EE_Export->export_attendees(); |
|
| 2753 | + } |
|
| 2754 | + } |
|
| 2755 | + |
|
| 2756 | + |
|
| 2757 | + public function _contact_list_report() |
|
| 2758 | + { |
|
| 2759 | + if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 2760 | + wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2761 | + 'page' => 'espresso_batch', |
|
| 2762 | + 'batch' => 'file', |
|
| 2763 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 2764 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 2765 | + ))); |
|
| 2766 | + } else { |
|
| 2767 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2768 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2769 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2770 | + $EE_Export->report_attendees(); |
|
| 2771 | + } |
|
| 2772 | + } |
|
| 2773 | + } |
|
| 2774 | + |
|
| 2775 | + |
|
| 2776 | + |
|
| 2777 | + |
|
| 2778 | + |
|
| 2779 | + /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 2780 | + /** |
|
| 2781 | + * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 2782 | + * |
|
| 2783 | + * @return void |
|
| 2784 | + */ |
|
| 2785 | + protected function _duplicate_attendee() |
|
| 2786 | + { |
|
| 2787 | + $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
| 2788 | + //verify we have necessary info |
|
| 2789 | + if (empty($this->_req_data['_REG_ID'])) { |
|
| 2790 | + EE_Error::add_error(__('Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 2791 | + 'event_espresso'), __FILE__, __LINE__, __FUNCTION__); |
|
| 2792 | + $query_args = array('action' => $action); |
|
| 2793 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 2794 | + } |
|
| 2795 | + //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 2796 | + $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
| 2797 | + $attendee = $registration->attendee(); |
|
| 2798 | + //remove relation of existing attendee on registration |
|
| 2799 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2800 | + //new attendee |
|
| 2801 | + $new_attendee = clone $attendee; |
|
| 2802 | + $new_attendee->set('ATT_ID', 0); |
|
| 2803 | + $new_attendee->save(); |
|
| 2804 | + //add new attendee to reg |
|
| 2805 | + $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 2806 | + EE_Error::add_success(__('New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 2807 | + 'event_espresso')); |
|
| 2808 | + //redirect to edit page for attendee |
|
| 2809 | + $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
| 2810 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 2811 | + } |
|
| 2812 | + |
|
| 2813 | + |
|
| 2814 | + //related to cpt routes |
|
| 2815 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 2816 | + { |
|
| 2817 | + $success = true; |
|
| 2818 | + $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id); |
|
| 2819 | + //for attendee updates |
|
| 2820 | + if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) { |
|
| 2821 | + //note we should only be UPDATING attendees at this point. |
|
| 2822 | + $updated_fields = array( |
|
| 2823 | + 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
| 2824 | + 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
| 2825 | + 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 2826 | + 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
| 2827 | + 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
| 2828 | + 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
| 2829 | + 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
| 2830 | + 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
| 2831 | + 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
| 2832 | + 'ATT_email' => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '', |
|
| 2833 | + 'ATT_phone' => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '', |
|
| 2834 | + ); |
|
| 2835 | + foreach ($updated_fields as $field => $value) { |
|
| 2836 | + $attendee->set($field, $value); |
|
| 2837 | + } |
|
| 2838 | + $success = $attendee->save(); |
|
| 2839 | + $attendee_update_callbacks = apply_filters('FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 2840 | + array()); |
|
| 2841 | + foreach ($attendee_update_callbacks as $a_callback) { |
|
| 2842 | + if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
| 2843 | + throw new EE_Error(sprintf(__('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
| 2844 | + 'event_espresso'), $a_callback)); |
|
| 2845 | + } |
|
| 2846 | + } |
|
| 2847 | + } |
|
| 2848 | + if ($success === false) { |
|
| 2849 | + EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.', |
|
| 2850 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2851 | + } |
|
| 2852 | + } |
|
| 2853 | + |
|
| 2854 | + |
|
| 2855 | + public function trash_cpt_item($post_id) |
|
| 2856 | + { |
|
| 2857 | + } |
|
| 2858 | + |
|
| 2859 | + |
|
| 2860 | + public function delete_cpt_item($post_id) |
|
| 2861 | + { |
|
| 2862 | + } |
|
| 2863 | + |
|
| 2864 | + |
|
| 2865 | + public function restore_cpt_item($post_id) |
|
| 2866 | + { |
|
| 2867 | + } |
|
| 2868 | + |
|
| 2869 | + |
|
| 2870 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 2871 | + { |
|
| 2872 | + } |
|
| 2873 | + |
|
| 2874 | + |
|
| 2875 | + public function attendee_editor_metaboxes() |
|
| 2876 | + { |
|
| 2877 | + $this->verify_cpt_object(); |
|
| 2878 | + remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action], |
|
| 2879 | + 'normal', 'core'); |
|
| 2880 | + remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2881 | + if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 2882 | + add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box', |
|
| 2883 | + $this->_cpt_routes[$this->_req_action], 'normal'); |
|
| 2884 | + } |
|
| 2885 | + if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 2886 | + add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box', |
|
| 2887 | + $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2888 | + } |
|
| 2889 | + add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'), |
|
| 2890 | + array($this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core'); |
|
| 2891 | + add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'), |
|
| 2892 | + array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2893 | + add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'), |
|
| 2894 | + array($this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high'); |
|
| 2895 | + } |
|
| 2896 | + |
|
| 2897 | + |
|
| 2898 | + /** |
|
| 2899 | + * Metabox for attendee contact info |
|
| 2900 | + * |
|
| 2901 | + * @param WP_Post $post wp post object |
|
| 2902 | + * @return string attendee contact info ( and form ) |
|
| 2903 | + */ |
|
| 2904 | + public function attendee_contact_info($post) |
|
| 2905 | + { |
|
| 2906 | + //get attendee object ( should already have it ) |
|
| 2907 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2908 | + $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
| 2909 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 2910 | + } |
|
| 2911 | + |
|
| 2912 | + |
|
| 2913 | + /** |
|
| 2914 | + * Metabox for attendee details |
|
| 2915 | + * |
|
| 2916 | + * @param WP_Post $post wp post object |
|
| 2917 | + * @return string attendee address details (and form) |
|
| 2918 | + */ |
|
| 2919 | + public function attendee_address_details($post) |
|
| 2920 | + { |
|
| 2921 | + //get attendee object (should already have it) |
|
| 2922 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2923 | + $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array( |
|
| 2924 | + 'QST_ID' => 0, |
|
| 2925 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 2926 | + 'QST_system' => 'admin-state', |
|
| 2927 | + )), EE_Answer::new_instance(array( |
|
| 2928 | + 'ANS_ID' => 0, |
|
| 2929 | + 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 2930 | + )), array( |
|
| 2931 | + 'input_id' => 'STA_ID', |
|
| 2932 | + 'input_name' => 'STA_ID', |
|
| 2933 | + 'input_prefix' => '', |
|
| 2934 | + 'append_qstn_id' => false, |
|
| 2935 | + ))); |
|
| 2936 | + $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array( |
|
| 2937 | + 'QST_ID' => 0, |
|
| 2938 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 2939 | + 'QST_system' => 'admin-country', |
|
| 2940 | + )), EE_Answer::new_instance(array( |
|
| 2941 | + 'ANS_ID' => 0, |
|
| 2942 | + 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 2943 | + )), array( |
|
| 2944 | + 'input_id' => 'CNT_ISO', |
|
| 2945 | + 'input_name' => 'CNT_ISO', |
|
| 2946 | + 'input_prefix' => '', |
|
| 2947 | + 'append_qstn_id' => false, |
|
| 2948 | + ))); |
|
| 2949 | + $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 2950 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 2951 | + } |
|
| 2952 | + |
|
| 2953 | + |
|
| 2954 | + /** |
|
| 2955 | + * _attendee_details |
|
| 2956 | + * |
|
| 2957 | + * @access protected |
|
| 2958 | + * @return void |
|
| 2959 | + */ |
|
| 2960 | + public function attendee_registrations_meta_box($post) |
|
| 2961 | + { |
|
| 2962 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2963 | + $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 2964 | + $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 2965 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 2966 | + } |
|
| 2967 | + |
|
| 2968 | + |
|
| 2969 | + /** |
|
| 2970 | + * add in the form fields for the attendee edit |
|
| 2971 | + * |
|
| 2972 | + * @param WP_Post $post wp post object |
|
| 2973 | + * @return string html for new form. |
|
| 2974 | + */ |
|
| 2975 | + public function after_title_form_fields($post) |
|
| 2976 | + { |
|
| 2977 | + if ($post->post_type == 'espresso_attendees') { |
|
| 2978 | + $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 2979 | + $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2980 | + EEH_Template::display_template($template, $template_args); |
|
| 2981 | + } |
|
| 2982 | + } |
|
| 2983 | + |
|
| 2984 | + |
|
| 2985 | + /** |
|
| 2986 | + * _trash_or_restore_attendee |
|
| 2987 | + * |
|
| 2988 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 2989 | + * @access protected |
|
| 2990 | + * @return void |
|
| 2991 | + */ |
|
| 2992 | + protected function _trash_or_restore_attendees($trash = true) |
|
| 2993 | + { |
|
| 2994 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2995 | + $ATT_MDL = EEM_Attendee::instance(); |
|
| 2996 | + $success = 1; |
|
| 2997 | + //Checkboxes |
|
| 2998 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2999 | + // if array has more than one element than success message should be plural |
|
| 3000 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3001 | + // cycle thru checkboxes |
|
| 3002 | + while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3003 | + $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
| 3004 | + : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
| 3005 | + if ( ! $updated) { |
|
| 3006 | + $success = 0; |
|
| 3007 | + } |
|
| 3008 | + } |
|
| 3009 | + } else { |
|
| 3010 | + // grab single id and delete |
|
| 3011 | + $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
| 3012 | + //get attendee |
|
| 3013 | + $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
| 3014 | + $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
| 3015 | + $updated = $att->save(); |
|
| 3016 | + if ( ! $updated) { |
|
| 3017 | + $success = 0; |
|
| 3018 | + } |
|
| 3019 | + } |
|
| 3020 | + $what = $success > 1 ? __('Contacts', 'event_espresso') : __('Contact', 'event_espresso'); |
|
| 3021 | + $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 3022 | + $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
| 3023 | + } |
|
| 3024 | 3024 | |
| 3025 | 3025 | } |
| 3026 | 3026 | |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @since 4.3.0 |
| 8 | 8 | */ |
| 9 | 9 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 10 | - exit('No direct script access allowed'); |
|
| 10 | + exit('No direct script access allowed'); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -22,455 +22,455 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Holds values for registered message types |
|
| 27 | - * |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected static $_ee_message_type_registry = array(); |
|
| 25 | + /** |
|
| 26 | + * Holds values for registered message types |
|
| 27 | + * |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected static $_ee_message_type_registry = array(); |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Method for registering new message types in the EE_messages system. |
|
| 35 | - * Note: All message types must have the following files in order to work: |
|
| 36 | - * Template files for default templates getting setup. |
|
| 37 | - * See /core/libraries/messages/defaults/default/ for examples |
|
| 38 | - * (note that template files match a specific naming schema). |
|
| 39 | - * These templates will need to be registered with the default template pack. |
|
| 40 | - * - EE_Messages_Validator extended class(es). See /core/libraries/messages/validators/email/ |
|
| 41 | - * for examples. Note for any new message types, there will need to be a validator for each |
|
| 42 | - * messenger combo this message type can activate with. |
|
| 43 | - * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new |
|
| 44 | - * message type and its properties. |
|
| 45 | - * |
|
| 46 | - * @since 4.3.0 |
|
| 47 | - * @param string $mt_name Whatever is defined for the $name property of |
|
| 48 | - * the message type you are registering (eg. |
|
| 49 | - * declined_registration). Required. |
|
| 50 | - * @param array $setup_args An array of arguments provided for registering the message type. |
|
| 51 | - * @see inline docs in the register method for what can be passed in as arguments. |
|
| 52 | - * @throws \EE_Error |
|
| 53 | - * } |
|
| 54 | - */ |
|
| 55 | - public static function register($mt_name = null, $setup_args = array()) |
|
| 56 | - { |
|
| 57 | - //required fields MUST be present, so let's make sure they are. |
|
| 58 | - if ( |
|
| 59 | - ! isset($mt_name) |
|
| 60 | - || ! is_array($setup_args) |
|
| 61 | - || empty($setup_args['mtfilename']) || empty($setup_args['autoloadpaths']) |
|
| 62 | - ) { |
|
| 63 | - throw new EE_Error( |
|
| 64 | - __('In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"', |
|
| 65 | - 'event_espresso') |
|
| 66 | - ); |
|
| 67 | - } |
|
| 33 | + /** |
|
| 34 | + * Method for registering new message types in the EE_messages system. |
|
| 35 | + * Note: All message types must have the following files in order to work: |
|
| 36 | + * Template files for default templates getting setup. |
|
| 37 | + * See /core/libraries/messages/defaults/default/ for examples |
|
| 38 | + * (note that template files match a specific naming schema). |
|
| 39 | + * These templates will need to be registered with the default template pack. |
|
| 40 | + * - EE_Messages_Validator extended class(es). See /core/libraries/messages/validators/email/ |
|
| 41 | + * for examples. Note for any new message types, there will need to be a validator for each |
|
| 42 | + * messenger combo this message type can activate with. |
|
| 43 | + * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new |
|
| 44 | + * message type and its properties. |
|
| 45 | + * |
|
| 46 | + * @since 4.3.0 |
|
| 47 | + * @param string $mt_name Whatever is defined for the $name property of |
|
| 48 | + * the message type you are registering (eg. |
|
| 49 | + * declined_registration). Required. |
|
| 50 | + * @param array $setup_args An array of arguments provided for registering the message type. |
|
| 51 | + * @see inline docs in the register method for what can be passed in as arguments. |
|
| 52 | + * @throws \EE_Error |
|
| 53 | + * } |
|
| 54 | + */ |
|
| 55 | + public static function register($mt_name = null, $setup_args = array()) |
|
| 56 | + { |
|
| 57 | + //required fields MUST be present, so let's make sure they are. |
|
| 58 | + if ( |
|
| 59 | + ! isset($mt_name) |
|
| 60 | + || ! is_array($setup_args) |
|
| 61 | + || empty($setup_args['mtfilename']) || empty($setup_args['autoloadpaths']) |
|
| 62 | + ) { |
|
| 63 | + throw new EE_Error( |
|
| 64 | + __('In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"', |
|
| 65 | + 'event_espresso') |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - //make sure we don't register twice |
|
| 70 | - if (isset(self::$_ee_message_type_registry[$mt_name])) { |
|
| 71 | - return; |
|
| 72 | - } |
|
| 69 | + //make sure we don't register twice |
|
| 70 | + if (isset(self::$_ee_message_type_registry[$mt_name])) { |
|
| 71 | + return; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - //make sure this was called in the right place! |
|
| 75 | - if ( |
|
| 76 | - ! did_action('EE_Brewing_Regular___messages_caf') |
|
| 77 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
| 78 | - ) { |
|
| 79 | - EE_Error::doing_it_wrong( |
|
| 80 | - __METHOD__, |
|
| 81 | - sprintf( |
|
| 82 | - __('A message type named "%s" has been attempted to be registered with the EE Messages System. It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.', |
|
| 83 | - 'event_espresso'), |
|
| 84 | - $mt_name |
|
| 85 | - ), |
|
| 86 | - '4.3.0' |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - //setup $__ee_message_type_registry array from incoming values. |
|
| 90 | - self::$_ee_message_type_registry[$mt_name] = array( |
|
| 91 | - /** |
|
| 92 | - * The file name for the message type being registered. |
|
| 93 | - * Required. |
|
| 94 | - * @type string |
|
| 95 | - */ |
|
| 96 | - 'mtfilename' => (string)$setup_args['mtfilename'], |
|
| 97 | - /** |
|
| 98 | - * Autoload paths for classes used by the message type. |
|
| 99 | - * Required. |
|
| 100 | - * @type array |
|
| 101 | - */ |
|
| 102 | - 'autoloadpaths' => (array)$setup_args['autoloadpaths'], |
|
| 103 | - /** |
|
| 104 | - * Messengers that the message type should be able to activate with. |
|
| 105 | - * Use messenger slugs. |
|
| 106 | - * @type array |
|
| 107 | - */ |
|
| 108 | - 'messengers_to_activate_with' => ! empty($setup_args['messengers_to_activate_with']) |
|
| 109 | - ? (array)$setup_args['messengers_to_activate_with'] |
|
| 110 | - : array(), |
|
| 111 | - /** |
|
| 112 | - * Messengers that the message type should validate with. |
|
| 113 | - * Use messenger slugs. |
|
| 114 | - * @type array |
|
| 115 | - */ |
|
| 116 | - 'messengers_to_validate_with' => ! empty($setup_args['messengers_to_validate_with']) |
|
| 117 | - ? (array)$setup_args['messengers_to_validate_with'] |
|
| 118 | - : array(), |
|
| 119 | - /** |
|
| 120 | - * Whether to force activate this message type the first time it is registered. |
|
| 121 | - * @type bool False means its not activated by default and left up to the end user to activate. |
|
| 122 | - */ |
|
| 123 | - 'force_activation' => ! empty($setup_args['force_activation']) |
|
| 124 | - ? (bool)$setup_args['force_activation'] |
|
| 125 | - : false, |
|
| 126 | - /** |
|
| 127 | - * What messengers this message type supports the default template pack for. |
|
| 128 | - * Note: If you do not set this (or any of the following template pack/variation related arguments) to true, |
|
| 129 | - * then it is expected that the message type being registered is doing its own custom default template |
|
| 130 | - * pack/variation registration. |
|
| 131 | - * |
|
| 132 | - * If this is set and has values, then it is expected that the following arguments are also set in the incoming options |
|
| 133 | - * $setup_arguments array as well: |
|
| 134 | - * - 'base_path_for_default_templates' |
|
| 135 | - * |
|
| 136 | - * @type array Expect an array of messengers this supports default template packs for. |
|
| 137 | - */ |
|
| 138 | - 'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with']) |
|
| 139 | - ? (array)$setup_args['messengers_supporting_default_template_pack_with'] |
|
| 140 | - : array(), |
|
| 141 | - /** |
|
| 142 | - * The base path where the default templates for this message type can be found. |
|
| 143 | - * @type string |
|
| 144 | - */ |
|
| 145 | - 'base_path_for_default_templates' => isset($setup_args['base_path_for_default_templates']) |
|
| 146 | - ? $setup_args['base_path_for_default_templates'] |
|
| 147 | - : '', |
|
| 148 | - /** |
|
| 149 | - * The base path where the default variations for this message type can be found. |
|
| 150 | - * @type string |
|
| 151 | - */ |
|
| 152 | - 'base_path_for_default_variation' => isset($setup_args['base_path_for_default_variation']) |
|
| 153 | - ? $setup_args['base_path_for_default_variation'] |
|
| 154 | - : '', |
|
| 155 | - /** |
|
| 156 | - * The base url for the default variations for this message type. |
|
| 157 | - * @type string |
|
| 158 | - */ |
|
| 159 | - 'base_url_for_default_variation' => isset($setup_args['base_url_for_default_variation']) |
|
| 160 | - ? $setup_args['base_url_for_default_variation'] |
|
| 161 | - : '' |
|
| 162 | - ); |
|
| 163 | - //add filters but only if they haven't already been set (these filters only need to be registered ONCE because |
|
| 164 | - //the callback handles all registered message types. |
|
| 165 | - if ( false === has_filter( |
|
| 166 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
| 167 | - array('EE_Register_Message_Type', 'register_msgs_autoload_paths') |
|
| 168 | - )) { |
|
| 169 | - add_filter( |
|
| 170 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
| 171 | - array('EE_Register_Message_Type', 'register_msgs_autoload_paths'), |
|
| 172 | - 10 |
|
| 173 | - ); |
|
| 174 | - add_filter( |
|
| 175 | - 'FHEE__EE_messages__get_installed__messagetype_files', |
|
| 176 | - array('EE_Register_Message_Type', 'register_messagetype_files'), |
|
| 177 | - 10, |
|
| 178 | - 1 |
|
| 179 | - ); |
|
| 180 | - add_filter( |
|
| 181 | - 'FHEE__EE_messenger__get_default_message_types__default_types', |
|
| 182 | - array('EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'), |
|
| 183 | - 10, |
|
| 184 | - 2 |
|
| 185 | - ); |
|
| 186 | - add_filter( |
|
| 187 | - 'FHEE__EE_messenger__get_valid_message_types__valid_types', |
|
| 188 | - array('EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'), |
|
| 189 | - 10, |
|
| 190 | - 2 |
|
| 191 | - ); |
|
| 192 | - //actions |
|
| 193 | - add_action( |
|
| 194 | - 'AHEE__EE_Addon__initialize_default_data__begin', |
|
| 195 | - array('EE_Register_Message_Type', 'set_defaults') |
|
| 196 | - ); |
|
| 74 | + //make sure this was called in the right place! |
|
| 75 | + if ( |
|
| 76 | + ! did_action('EE_Brewing_Regular___messages_caf') |
|
| 77 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
| 78 | + ) { |
|
| 79 | + EE_Error::doing_it_wrong( |
|
| 80 | + __METHOD__, |
|
| 81 | + sprintf( |
|
| 82 | + __('A message type named "%s" has been attempted to be registered with the EE Messages System. It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.', |
|
| 83 | + 'event_espresso'), |
|
| 84 | + $mt_name |
|
| 85 | + ), |
|
| 86 | + '4.3.0' |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + //setup $__ee_message_type_registry array from incoming values. |
|
| 90 | + self::$_ee_message_type_registry[$mt_name] = array( |
|
| 91 | + /** |
|
| 92 | + * The file name for the message type being registered. |
|
| 93 | + * Required. |
|
| 94 | + * @type string |
|
| 95 | + */ |
|
| 96 | + 'mtfilename' => (string)$setup_args['mtfilename'], |
|
| 97 | + /** |
|
| 98 | + * Autoload paths for classes used by the message type. |
|
| 99 | + * Required. |
|
| 100 | + * @type array |
|
| 101 | + */ |
|
| 102 | + 'autoloadpaths' => (array)$setup_args['autoloadpaths'], |
|
| 103 | + /** |
|
| 104 | + * Messengers that the message type should be able to activate with. |
|
| 105 | + * Use messenger slugs. |
|
| 106 | + * @type array |
|
| 107 | + */ |
|
| 108 | + 'messengers_to_activate_with' => ! empty($setup_args['messengers_to_activate_with']) |
|
| 109 | + ? (array)$setup_args['messengers_to_activate_with'] |
|
| 110 | + : array(), |
|
| 111 | + /** |
|
| 112 | + * Messengers that the message type should validate with. |
|
| 113 | + * Use messenger slugs. |
|
| 114 | + * @type array |
|
| 115 | + */ |
|
| 116 | + 'messengers_to_validate_with' => ! empty($setup_args['messengers_to_validate_with']) |
|
| 117 | + ? (array)$setup_args['messengers_to_validate_with'] |
|
| 118 | + : array(), |
|
| 119 | + /** |
|
| 120 | + * Whether to force activate this message type the first time it is registered. |
|
| 121 | + * @type bool False means its not activated by default and left up to the end user to activate. |
|
| 122 | + */ |
|
| 123 | + 'force_activation' => ! empty($setup_args['force_activation']) |
|
| 124 | + ? (bool)$setup_args['force_activation'] |
|
| 125 | + : false, |
|
| 126 | + /** |
|
| 127 | + * What messengers this message type supports the default template pack for. |
|
| 128 | + * Note: If you do not set this (or any of the following template pack/variation related arguments) to true, |
|
| 129 | + * then it is expected that the message type being registered is doing its own custom default template |
|
| 130 | + * pack/variation registration. |
|
| 131 | + * |
|
| 132 | + * If this is set and has values, then it is expected that the following arguments are also set in the incoming options |
|
| 133 | + * $setup_arguments array as well: |
|
| 134 | + * - 'base_path_for_default_templates' |
|
| 135 | + * |
|
| 136 | + * @type array Expect an array of messengers this supports default template packs for. |
|
| 137 | + */ |
|
| 138 | + 'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with']) |
|
| 139 | + ? (array)$setup_args['messengers_supporting_default_template_pack_with'] |
|
| 140 | + : array(), |
|
| 141 | + /** |
|
| 142 | + * The base path where the default templates for this message type can be found. |
|
| 143 | + * @type string |
|
| 144 | + */ |
|
| 145 | + 'base_path_for_default_templates' => isset($setup_args['base_path_for_default_templates']) |
|
| 146 | + ? $setup_args['base_path_for_default_templates'] |
|
| 147 | + : '', |
|
| 148 | + /** |
|
| 149 | + * The base path where the default variations for this message type can be found. |
|
| 150 | + * @type string |
|
| 151 | + */ |
|
| 152 | + 'base_path_for_default_variation' => isset($setup_args['base_path_for_default_variation']) |
|
| 153 | + ? $setup_args['base_path_for_default_variation'] |
|
| 154 | + : '', |
|
| 155 | + /** |
|
| 156 | + * The base url for the default variations for this message type. |
|
| 157 | + * @type string |
|
| 158 | + */ |
|
| 159 | + 'base_url_for_default_variation' => isset($setup_args['base_url_for_default_variation']) |
|
| 160 | + ? $setup_args['base_url_for_default_variation'] |
|
| 161 | + : '' |
|
| 162 | + ); |
|
| 163 | + //add filters but only if they haven't already been set (these filters only need to be registered ONCE because |
|
| 164 | + //the callback handles all registered message types. |
|
| 165 | + if ( false === has_filter( |
|
| 166 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
| 167 | + array('EE_Register_Message_Type', 'register_msgs_autoload_paths') |
|
| 168 | + )) { |
|
| 169 | + add_filter( |
|
| 170 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
| 171 | + array('EE_Register_Message_Type', 'register_msgs_autoload_paths'), |
|
| 172 | + 10 |
|
| 173 | + ); |
|
| 174 | + add_filter( |
|
| 175 | + 'FHEE__EE_messages__get_installed__messagetype_files', |
|
| 176 | + array('EE_Register_Message_Type', 'register_messagetype_files'), |
|
| 177 | + 10, |
|
| 178 | + 1 |
|
| 179 | + ); |
|
| 180 | + add_filter( |
|
| 181 | + 'FHEE__EE_messenger__get_default_message_types__default_types', |
|
| 182 | + array('EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'), |
|
| 183 | + 10, |
|
| 184 | + 2 |
|
| 185 | + ); |
|
| 186 | + add_filter( |
|
| 187 | + 'FHEE__EE_messenger__get_valid_message_types__valid_types', |
|
| 188 | + array('EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'), |
|
| 189 | + 10, |
|
| 190 | + 2 |
|
| 191 | + ); |
|
| 192 | + //actions |
|
| 193 | + add_action( |
|
| 194 | + 'AHEE__EE_Addon__initialize_default_data__begin', |
|
| 195 | + array('EE_Register_Message_Type', 'set_defaults') |
|
| 196 | + ); |
|
| 197 | 197 | |
| 198 | - //default template packs and variations related |
|
| 199 | - add_filter( |
|
| 200 | - 'FHEE__EE_Messages_Template_Pack_Default__get_supports', |
|
| 201 | - array('EE_Register_Message_Type', 'register_default_template_pack_supports') |
|
| 202 | - ); |
|
| 203 | - add_filter( |
|
| 204 | - 'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path', |
|
| 205 | - array('EE_Register_Message_Type', 'register_base_template_path'), |
|
| 206 | - 10, |
|
| 207 | - 6 |
|
| 208 | - ); |
|
| 209 | - add_filter( |
|
| 210 | - 'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', |
|
| 211 | - array('EE_Register_Message_Type', 'register_variation_base_path_or_url'), |
|
| 212 | - 10, |
|
| 213 | - 8 |
|
| 214 | - ); |
|
| 215 | - add_filter( |
|
| 216 | - 'FHEE__EE_Messages_Template_Pack__get_variation__base_path', |
|
| 217 | - array('EE_Register_Message_Type', 'register_variation_base_path_or_url'), |
|
| 218 | - 10, |
|
| 219 | - 8 |
|
| 220 | - ); |
|
| 221 | - } |
|
| 222 | - } |
|
| 198 | + //default template packs and variations related |
|
| 199 | + add_filter( |
|
| 200 | + 'FHEE__EE_Messages_Template_Pack_Default__get_supports', |
|
| 201 | + array('EE_Register_Message_Type', 'register_default_template_pack_supports') |
|
| 202 | + ); |
|
| 203 | + add_filter( |
|
| 204 | + 'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path', |
|
| 205 | + array('EE_Register_Message_Type', 'register_base_template_path'), |
|
| 206 | + 10, |
|
| 207 | + 6 |
|
| 208 | + ); |
|
| 209 | + add_filter( |
|
| 210 | + 'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', |
|
| 211 | + array('EE_Register_Message_Type', 'register_variation_base_path_or_url'), |
|
| 212 | + 10, |
|
| 213 | + 8 |
|
| 214 | + ); |
|
| 215 | + add_filter( |
|
| 216 | + 'FHEE__EE_Messages_Template_Pack__get_variation__base_path', |
|
| 217 | + array('EE_Register_Message_Type', 'register_variation_base_path_or_url'), |
|
| 218 | + 10, |
|
| 219 | + 8 |
|
| 220 | + ); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * This just ensures that when an addon registers a message type that on initial activation/reactivation the |
|
| 227 | - * defaults the addon sets are taken care of. |
|
| 228 | - */ |
|
| 229 | - public static function set_defaults() |
|
| 230 | - { |
|
| 231 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 232 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 225 | + /** |
|
| 226 | + * This just ensures that when an addon registers a message type that on initial activation/reactivation the |
|
| 227 | + * defaults the addon sets are taken care of. |
|
| 228 | + */ |
|
| 229 | + public static function set_defaults() |
|
| 230 | + { |
|
| 231 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 232 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 233 | 233 | |
| 234 | - //for any message types with force activation, let's ensure they are activated |
|
| 235 | - foreach (self::$_ee_message_type_registry as $message_type_name => $settings) { |
|
| 236 | - if ($settings['force_activation']) { |
|
| 237 | - foreach ($settings['messengers_to_activate_with'] as $messenger) { |
|
| 238 | - //DO not force activation if this message type has already been activated in the system |
|
| 239 | - if (! $message_resource_manager->has_message_type_been_activated_for_messenger($message_type_name, |
|
| 240 | - $messenger) |
|
| 241 | - ) { |
|
| 242 | - $message_resource_manager->ensure_message_type_is_active($message_type_name, $messenger); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 234 | + //for any message types with force activation, let's ensure they are activated |
|
| 235 | + foreach (self::$_ee_message_type_registry as $message_type_name => $settings) { |
|
| 236 | + if ($settings['force_activation']) { |
|
| 237 | + foreach ($settings['messengers_to_activate_with'] as $messenger) { |
|
| 238 | + //DO not force activation if this message type has already been activated in the system |
|
| 239 | + if (! $message_resource_manager->has_message_type_been_activated_for_messenger($message_type_name, |
|
| 240 | + $messenger) |
|
| 241 | + ) { |
|
| 242 | + $message_resource_manager->ensure_message_type_is_active($message_type_name, $messenger); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * This deregisters a message type that was previously registered with a specific message_type_name. |
|
| 252 | - * |
|
| 253 | - * @since 4.3.0 |
|
| 254 | - * @param string $message_type_name the name for the message type that was previously registered |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - public static function deregister($message_type_name = null) |
|
| 258 | - { |
|
| 259 | - if (! empty(self::$_ee_message_type_registry[$message_type_name])) { |
|
| 260 | - //let's make sure that we remove any place this message type was made active |
|
| 261 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 262 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 263 | - $Message_Resource_Manager->deactivate_message_type($message_type_name); |
|
| 264 | - unset(self::$_ee_message_type_registry[$message_type_name]); |
|
| 265 | - } |
|
| 266 | - } |
|
| 250 | + /** |
|
| 251 | + * This deregisters a message type that was previously registered with a specific message_type_name. |
|
| 252 | + * |
|
| 253 | + * @since 4.3.0 |
|
| 254 | + * @param string $message_type_name the name for the message type that was previously registered |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + public static function deregister($message_type_name = null) |
|
| 258 | + { |
|
| 259 | + if (! empty(self::$_ee_message_type_registry[$message_type_name])) { |
|
| 260 | + //let's make sure that we remove any place this message type was made active |
|
| 261 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 262 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 263 | + $Message_Resource_Manager->deactivate_message_type($message_type_name); |
|
| 264 | + unset(self::$_ee_message_type_registry[$message_type_name]); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * callback for FHEE__EE_messages__get_installed__messagetype_files filter. |
|
| 271 | - * |
|
| 272 | - * @since 4.3.0 |
|
| 273 | - * @param array $messagetype_files The current array of message type file names |
|
| 274 | - * @return array Array of message type file names |
|
| 275 | - */ |
|
| 276 | - public static function register_messagetype_files($messagetype_files) |
|
| 277 | - { |
|
| 278 | - if (empty(self::$_ee_message_type_registry)) { |
|
| 279 | - return $messagetype_files; |
|
| 280 | - } |
|
| 281 | - foreach (self::$_ee_message_type_registry as $mt_reg) { |
|
| 282 | - if (empty($mt_reg['mtfilename'])) { |
|
| 283 | - continue; |
|
| 284 | - } |
|
| 285 | - $messagetype_files[] = $mt_reg['mtfilename']; |
|
| 286 | - } |
|
| 287 | - return $messagetype_files; |
|
| 288 | - } |
|
| 269 | + /** |
|
| 270 | + * callback for FHEE__EE_messages__get_installed__messagetype_files filter. |
|
| 271 | + * |
|
| 272 | + * @since 4.3.0 |
|
| 273 | + * @param array $messagetype_files The current array of message type file names |
|
| 274 | + * @return array Array of message type file names |
|
| 275 | + */ |
|
| 276 | + public static function register_messagetype_files($messagetype_files) |
|
| 277 | + { |
|
| 278 | + if (empty(self::$_ee_message_type_registry)) { |
|
| 279 | + return $messagetype_files; |
|
| 280 | + } |
|
| 281 | + foreach (self::$_ee_message_type_registry as $mt_reg) { |
|
| 282 | + if (empty($mt_reg['mtfilename'])) { |
|
| 283 | + continue; |
|
| 284 | + } |
|
| 285 | + $messagetype_files[] = $mt_reg['mtfilename']; |
|
| 286 | + } |
|
| 287 | + return $messagetype_files; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. |
|
| 293 | - * |
|
| 294 | - * @since 4.3.0 |
|
| 295 | - * @param array $paths array of paths to be checked by EE_messages autoloader. |
|
| 296 | - * @return array |
|
| 297 | - */ |
|
| 298 | - public static function register_msgs_autoload_paths($paths) |
|
| 299 | - { |
|
| 300 | - if (! empty(self::$_ee_message_type_registry)) { |
|
| 301 | - foreach (self::$_ee_message_type_registry as $mt_reg) { |
|
| 302 | - if (empty($mt_reg['autoloadpaths'])) { |
|
| 303 | - continue; |
|
| 304 | - } |
|
| 305 | - $paths = array_merge($paths, $mt_reg['autoloadpaths']); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - return $paths; |
|
| 309 | - } |
|
| 291 | + /** |
|
| 292 | + * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. |
|
| 293 | + * |
|
| 294 | + * @since 4.3.0 |
|
| 295 | + * @param array $paths array of paths to be checked by EE_messages autoloader. |
|
| 296 | + * @return array |
|
| 297 | + */ |
|
| 298 | + public static function register_msgs_autoload_paths($paths) |
|
| 299 | + { |
|
| 300 | + if (! empty(self::$_ee_message_type_registry)) { |
|
| 301 | + foreach (self::$_ee_message_type_registry as $mt_reg) { |
|
| 302 | + if (empty($mt_reg['autoloadpaths'])) { |
|
| 303 | + continue; |
|
| 304 | + } |
|
| 305 | + $paths = array_merge($paths, $mt_reg['autoloadpaths']); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + return $paths; |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | 311 | |
| 312 | - /** |
|
| 313 | - * callback for FHEE__EE_messenger__get_default_message_types__default_types filter. |
|
| 314 | - * |
|
| 315 | - * @since 4.3.0 |
|
| 316 | - * @param array $default_types array of message types activated with messenger ( |
|
| 317 | - * corresponds to the $name property of message type) |
|
| 318 | - * @param EE_messenger $messenger The EE_messenger the filter is called from. |
|
| 319 | - * @return array |
|
| 320 | - */ |
|
| 321 | - public static function register_messengers_to_activate_mt_with($default_types, EE_messenger $messenger) |
|
| 322 | - { |
|
| 323 | - if (empty(self::$_ee_message_type_registry)) { |
|
| 324 | - return $default_types; |
|
| 325 | - } |
|
| 326 | - foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
|
| 327 | - if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) { |
|
| 328 | - continue; |
|
| 329 | - } |
|
| 330 | - // loop through each of the messengers and if it matches the loaded class |
|
| 331 | - // then we add this message type to the |
|
| 332 | - foreach ($mt_reg['messengers_to_activate_with'] as $msgr) { |
|
| 333 | - if ($messenger->name == $msgr) { |
|
| 334 | - $default_types[] = $message_type_name; |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - } |
|
| 312 | + /** |
|
| 313 | + * callback for FHEE__EE_messenger__get_default_message_types__default_types filter. |
|
| 314 | + * |
|
| 315 | + * @since 4.3.0 |
|
| 316 | + * @param array $default_types array of message types activated with messenger ( |
|
| 317 | + * corresponds to the $name property of message type) |
|
| 318 | + * @param EE_messenger $messenger The EE_messenger the filter is called from. |
|
| 319 | + * @return array |
|
| 320 | + */ |
|
| 321 | + public static function register_messengers_to_activate_mt_with($default_types, EE_messenger $messenger) |
|
| 322 | + { |
|
| 323 | + if (empty(self::$_ee_message_type_registry)) { |
|
| 324 | + return $default_types; |
|
| 325 | + } |
|
| 326 | + foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
|
| 327 | + if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) { |
|
| 328 | + continue; |
|
| 329 | + } |
|
| 330 | + // loop through each of the messengers and if it matches the loaded class |
|
| 331 | + // then we add this message type to the |
|
| 332 | + foreach ($mt_reg['messengers_to_activate_with'] as $msgr) { |
|
| 333 | + if ($messenger->name == $msgr) { |
|
| 334 | + $default_types[] = $message_type_name; |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - return $default_types; |
|
| 340 | - } |
|
| 339 | + return $default_types; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter. |
|
| 345 | - * |
|
| 346 | - * @since 4.3.0 |
|
| 347 | - * @param array $valid_types array of message types valid with messenger ( |
|
| 348 | - * corresponds to the $name property of message type) |
|
| 349 | - * @param EE_messenger $messenger The EE_messenger the filter is called from. |
|
| 350 | - * @return array |
|
| 351 | - */ |
|
| 352 | - public static function register_messengers_to_validate_mt_with($valid_types, EE_messenger $messenger) |
|
| 353 | - { |
|
| 354 | - if (empty(self::$_ee_message_type_registry)) { |
|
| 355 | - return $valid_types; |
|
| 356 | - } |
|
| 357 | - foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
|
| 358 | - if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) { |
|
| 359 | - continue; |
|
| 360 | - } |
|
| 361 | - // loop through each of the messengers and if it matches the loaded class |
|
| 362 | - // then we add this message type to the |
|
| 363 | - foreach ($mt_reg['messengers_to_validate_with'] as $msgr) { |
|
| 364 | - if ($messenger->name == $msgr) { |
|
| 365 | - $valid_types[] = $message_type_name; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 343 | + /** |
|
| 344 | + * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter. |
|
| 345 | + * |
|
| 346 | + * @since 4.3.0 |
|
| 347 | + * @param array $valid_types array of message types valid with messenger ( |
|
| 348 | + * corresponds to the $name property of message type) |
|
| 349 | + * @param EE_messenger $messenger The EE_messenger the filter is called from. |
|
| 350 | + * @return array |
|
| 351 | + */ |
|
| 352 | + public static function register_messengers_to_validate_mt_with($valid_types, EE_messenger $messenger) |
|
| 353 | + { |
|
| 354 | + if (empty(self::$_ee_message_type_registry)) { |
|
| 355 | + return $valid_types; |
|
| 356 | + } |
|
| 357 | + foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
|
| 358 | + if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) { |
|
| 359 | + continue; |
|
| 360 | + } |
|
| 361 | + // loop through each of the messengers and if it matches the loaded class |
|
| 362 | + // then we add this message type to the |
|
| 363 | + foreach ($mt_reg['messengers_to_validate_with'] as $msgr) { |
|
| 364 | + if ($messenger->name == $msgr) { |
|
| 365 | + $valid_types[] = $message_type_name; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | 369 | |
| 370 | - return $valid_types; |
|
| 371 | - } |
|
| 370 | + return $valid_types; |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | 373 | |
| 374 | - /** |
|
| 375 | - * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as |
|
| 376 | - * supporting the default template pack |
|
| 377 | - * |
|
| 378 | - * @param array $supports |
|
| 379 | - * |
|
| 380 | - * @return array |
|
| 381 | - */ |
|
| 382 | - public static function register_default_template_pack_supports($supports) |
|
| 383 | - { |
|
| 384 | - foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
|
| 385 | - if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) { |
|
| 386 | - continue; |
|
| 387 | - } |
|
| 388 | - foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) { |
|
| 389 | - $supports[$messenger_slug][] = $message_type_name; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - return $supports; |
|
| 393 | - } |
|
| 374 | + /** |
|
| 375 | + * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as |
|
| 376 | + * supporting the default template pack |
|
| 377 | + * |
|
| 378 | + * @param array $supports |
|
| 379 | + * |
|
| 380 | + * @return array |
|
| 381 | + */ |
|
| 382 | + public static function register_default_template_pack_supports($supports) |
|
| 383 | + { |
|
| 384 | + foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
|
| 385 | + if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) { |
|
| 386 | + continue; |
|
| 387 | + } |
|
| 388 | + foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) { |
|
| 389 | + $supports[$messenger_slug][] = $message_type_name; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + return $supports; |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | 395 | |
| 396 | - /** |
|
| 397 | - * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path |
|
| 398 | - * |
|
| 399 | - * @param string $base_path The original base path for message templates |
|
| 400 | - * @param EE_messenger $messenger |
|
| 401 | - * @param EE_message_type $message_type |
|
| 402 | - * @param string $field The field requesting a template |
|
| 403 | - * @param string $context The context requesting a template |
|
| 404 | - * @param EE_Messages_Template_Pack $template_pack |
|
| 405 | - * |
|
| 406 | - * @return string |
|
| 407 | - */ |
|
| 408 | - public static function register_base_template_path( |
|
| 409 | - $base_path, |
|
| 410 | - $messenger, |
|
| 411 | - $message_type, |
|
| 412 | - $field, |
|
| 413 | - $context, |
|
| 414 | - $template_pack |
|
| 415 | - ) { |
|
| 416 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default |
|
| 417 | - || ! $message_type instanceof EE_message_type |
|
| 418 | - ) { |
|
| 419 | - return $base_path; |
|
| 420 | - } |
|
| 421 | - foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
|
| 422 | - if ($message_type->name === $message_type_name |
|
| 423 | - && ! empty($mt_reg['base_path_for_default_templates']) |
|
| 424 | - ) { |
|
| 425 | - return $mt_reg['base_path_for_default_templates']; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - return $base_path; |
|
| 429 | - } |
|
| 396 | + /** |
|
| 397 | + * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path |
|
| 398 | + * |
|
| 399 | + * @param string $base_path The original base path for message templates |
|
| 400 | + * @param EE_messenger $messenger |
|
| 401 | + * @param EE_message_type $message_type |
|
| 402 | + * @param string $field The field requesting a template |
|
| 403 | + * @param string $context The context requesting a template |
|
| 404 | + * @param EE_Messages_Template_Pack $template_pack |
|
| 405 | + * |
|
| 406 | + * @return string |
|
| 407 | + */ |
|
| 408 | + public static function register_base_template_path( |
|
| 409 | + $base_path, |
|
| 410 | + $messenger, |
|
| 411 | + $message_type, |
|
| 412 | + $field, |
|
| 413 | + $context, |
|
| 414 | + $template_pack |
|
| 415 | + ) { |
|
| 416 | + if (! $template_pack instanceof EE_Messages_Template_Pack_Default |
|
| 417 | + || ! $message_type instanceof EE_message_type |
|
| 418 | + ) { |
|
| 419 | + return $base_path; |
|
| 420 | + } |
|
| 421 | + foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
|
| 422 | + if ($message_type->name === $message_type_name |
|
| 423 | + && ! empty($mt_reg['base_path_for_default_templates']) |
|
| 424 | + ) { |
|
| 425 | + return $mt_reg['base_path_for_default_templates']; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + return $base_path; |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | 431 | |
| 432 | - /** |
|
| 433 | - * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and |
|
| 434 | - * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks |
|
| 435 | - * |
|
| 436 | - * @param string $base_path_or_url The original incoming base url or path |
|
| 437 | - * @param string $messenger_slug The slug of the messenger the template is being generated for. |
|
| 438 | - * @param string $message_type_slug The slug of the message type the template is being generated for. |
|
| 439 | - * @param string $type The "type" of css being requested. |
|
| 440 | - * @param string $variation The variation being requested. |
|
| 441 | - * @param string $file_extension What file extension is expected for the variation file. |
|
| 442 | - * @param bool $url whether a url or path is being requested. |
|
| 443 | - * @param EE_Messages_Template_Pack $template_pack |
|
| 444 | - * |
|
| 445 | - * @return string |
|
| 446 | - */ |
|
| 447 | - public static function register_variation_base_path_or_url( |
|
| 448 | - $base_path_or_url, |
|
| 449 | - $messenger_slug, |
|
| 450 | - $message_type_slug, |
|
| 451 | - $type, |
|
| 452 | - $variation, |
|
| 453 | - $url, |
|
| 454 | - $file_extension, |
|
| 455 | - $template_pack |
|
| 456 | - ) { |
|
| 457 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
| 458 | - return $base_path_or_url; |
|
| 459 | - } |
|
| 460 | - foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
|
| 461 | - if ($message_type_name === $message_type_slug |
|
| 462 | - ) { |
|
| 463 | - if ($url |
|
| 464 | - && ! empty($mt_reg['base_url_for_default_variation']) |
|
| 465 | - ) { |
|
| 466 | - return $mt_reg['base_url_for_default_variation']; |
|
| 467 | - } elseif (! $url |
|
| 468 | - && ! empty($mt_reg['base_path_for_default_variation']) |
|
| 469 | - ) { |
|
| 470 | - return $mt_reg['base_path_for_default_variation']; |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - return $base_path_or_url; |
|
| 475 | - } |
|
| 432 | + /** |
|
| 433 | + * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and |
|
| 434 | + * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks |
|
| 435 | + * |
|
| 436 | + * @param string $base_path_or_url The original incoming base url or path |
|
| 437 | + * @param string $messenger_slug The slug of the messenger the template is being generated for. |
|
| 438 | + * @param string $message_type_slug The slug of the message type the template is being generated for. |
|
| 439 | + * @param string $type The "type" of css being requested. |
|
| 440 | + * @param string $variation The variation being requested. |
|
| 441 | + * @param string $file_extension What file extension is expected for the variation file. |
|
| 442 | + * @param bool $url whether a url or path is being requested. |
|
| 443 | + * @param EE_Messages_Template_Pack $template_pack |
|
| 444 | + * |
|
| 445 | + * @return string |
|
| 446 | + */ |
|
| 447 | + public static function register_variation_base_path_or_url( |
|
| 448 | + $base_path_or_url, |
|
| 449 | + $messenger_slug, |
|
| 450 | + $message_type_slug, |
|
| 451 | + $type, |
|
| 452 | + $variation, |
|
| 453 | + $url, |
|
| 454 | + $file_extension, |
|
| 455 | + $template_pack |
|
| 456 | + ) { |
|
| 457 | + if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
| 458 | + return $base_path_or_url; |
|
| 459 | + } |
|
| 460 | + foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
|
| 461 | + if ($message_type_name === $message_type_slug |
|
| 462 | + ) { |
|
| 463 | + if ($url |
|
| 464 | + && ! empty($mt_reg['base_url_for_default_variation']) |
|
| 465 | + ) { |
|
| 466 | + return $mt_reg['base_url_for_default_variation']; |
|
| 467 | + } elseif (! $url |
|
| 468 | + && ! empty($mt_reg['base_path_for_default_variation']) |
|
| 469 | + ) { |
|
| 470 | + return $mt_reg['base_path_for_default_variation']; |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + return $base_path_or_url; |
|
| 475 | + } |
|
| 476 | 476 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @subpackage plugin api, messages |
| 7 | 7 | * @since 4.3.0 |
| 8 | 8 | */ |
| 9 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 10 | 10 | exit('No direct script access allowed'); |
| 11 | 11 | } |
| 12 | 12 | |
@@ -93,20 +93,20 @@ discard block |
||
| 93 | 93 | * Required. |
| 94 | 94 | * @type string |
| 95 | 95 | */ |
| 96 | - 'mtfilename' => (string)$setup_args['mtfilename'], |
|
| 96 | + 'mtfilename' => (string) $setup_args['mtfilename'], |
|
| 97 | 97 | /** |
| 98 | 98 | * Autoload paths for classes used by the message type. |
| 99 | 99 | * Required. |
| 100 | 100 | * @type array |
| 101 | 101 | */ |
| 102 | - 'autoloadpaths' => (array)$setup_args['autoloadpaths'], |
|
| 102 | + 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
|
| 103 | 103 | /** |
| 104 | 104 | * Messengers that the message type should be able to activate with. |
| 105 | 105 | * Use messenger slugs. |
| 106 | 106 | * @type array |
| 107 | 107 | */ |
| 108 | 108 | 'messengers_to_activate_with' => ! empty($setup_args['messengers_to_activate_with']) |
| 109 | - ? (array)$setup_args['messengers_to_activate_with'] |
|
| 109 | + ? (array) $setup_args['messengers_to_activate_with'] |
|
| 110 | 110 | : array(), |
| 111 | 111 | /** |
| 112 | 112 | * Messengers that the message type should validate with. |
@@ -114,14 +114,14 @@ discard block |
||
| 114 | 114 | * @type array |
| 115 | 115 | */ |
| 116 | 116 | 'messengers_to_validate_with' => ! empty($setup_args['messengers_to_validate_with']) |
| 117 | - ? (array)$setup_args['messengers_to_validate_with'] |
|
| 117 | + ? (array) $setup_args['messengers_to_validate_with'] |
|
| 118 | 118 | : array(), |
| 119 | 119 | /** |
| 120 | 120 | * Whether to force activate this message type the first time it is registered. |
| 121 | 121 | * @type bool False means its not activated by default and left up to the end user to activate. |
| 122 | 122 | */ |
| 123 | 123 | 'force_activation' => ! empty($setup_args['force_activation']) |
| 124 | - ? (bool)$setup_args['force_activation'] |
|
| 124 | + ? (bool) $setup_args['force_activation'] |
|
| 125 | 125 | : false, |
| 126 | 126 | /** |
| 127 | 127 | * What messengers this message type supports the default template pack for. |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @type array Expect an array of messengers this supports default template packs for. |
| 137 | 137 | */ |
| 138 | 138 | 'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with']) |
| 139 | - ? (array)$setup_args['messengers_supporting_default_template_pack_with'] |
|
| 139 | + ? (array) $setup_args['messengers_supporting_default_template_pack_with'] |
|
| 140 | 140 | : array(), |
| 141 | 141 | /** |
| 142 | 142 | * The base path where the default templates for this message type can be found. |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | ); |
| 163 | 163 | //add filters but only if they haven't already been set (these filters only need to be registered ONCE because |
| 164 | 164 | //the callback handles all registered message types. |
| 165 | - if ( false === has_filter( |
|
| 165 | + if (false === has_filter( |
|
| 166 | 166 | 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
| 167 | 167 | array('EE_Register_Message_Type', 'register_msgs_autoload_paths') |
| 168 | 168 | )) { |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | if ($settings['force_activation']) { |
| 237 | 237 | foreach ($settings['messengers_to_activate_with'] as $messenger) { |
| 238 | 238 | //DO not force activation if this message type has already been activated in the system |
| 239 | - if (! $message_resource_manager->has_message_type_been_activated_for_messenger($message_type_name, |
|
| 239 | + if ( ! $message_resource_manager->has_message_type_been_activated_for_messenger($message_type_name, |
|
| 240 | 240 | $messenger) |
| 241 | 241 | ) { |
| 242 | 242 | $message_resource_manager->ensure_message_type_is_active($message_type_name, $messenger); |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public static function deregister($message_type_name = null) |
| 258 | 258 | { |
| 259 | - if (! empty(self::$_ee_message_type_registry[$message_type_name])) { |
|
| 259 | + if ( ! empty(self::$_ee_message_type_registry[$message_type_name])) { |
|
| 260 | 260 | //let's make sure that we remove any place this message type was made active |
| 261 | 261 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
| 262 | 262 | $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public static function register_msgs_autoload_paths($paths) |
| 299 | 299 | { |
| 300 | - if (! empty(self::$_ee_message_type_registry)) { |
|
| 300 | + if ( ! empty(self::$_ee_message_type_registry)) { |
|
| 301 | 301 | foreach (self::$_ee_message_type_registry as $mt_reg) { |
| 302 | 302 | if (empty($mt_reg['autoloadpaths'])) { |
| 303 | 303 | continue; |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | $context, |
| 414 | 414 | $template_pack |
| 415 | 415 | ) { |
| 416 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default |
|
| 416 | + if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default |
|
| 417 | 417 | || ! $message_type instanceof EE_message_type |
| 418 | 418 | ) { |
| 419 | 419 | return $base_path; |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | $file_extension, |
| 455 | 455 | $template_pack |
| 456 | 456 | ) { |
| 457 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
| 457 | + if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
| 458 | 458 | return $base_path_or_url; |
| 459 | 459 | } |
| 460 | 460 | foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) { |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | && ! empty($mt_reg['base_url_for_default_variation']) |
| 465 | 465 | ) { |
| 466 | 466 | return $mt_reg['base_url_for_default_variation']; |
| 467 | - } elseif (! $url |
|
| 467 | + } elseif ( ! $url |
|
| 468 | 468 | && ! empty($mt_reg['base_path_for_default_variation']) |
| 469 | 469 | ) { |
| 470 | 470 | return $mt_reg['base_path_for_default_variation']; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public static function instance() { |
| 75 | 75 | // check if class object is instantiated |
| 76 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Maintenance_Mode )) { |
|
| 76 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Maintenance_Mode)) { |
|
| 77 | 77 | self::$_instance = new self(); |
| 78 | 78 | } |
| 79 | 79 | return self::$_instance; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode) |
| 84 | 84 | * @return EE_Maintenance_Mode |
| 85 | 85 | */ |
| 86 | - public static function reset(){ |
|
| 86 | + public static function reset() { |
|
| 87 | 87 | self::instance()->set_maintenance_mode_if_db_old(); |
| 88 | 88 | return self::instance(); |
| 89 | 89 | } |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | private function __construct() { |
| 100 | 100 | // if M-Mode level 2 is engaged, we still need basic assets loaded |
| 101 | - add_action( 'wp_enqueue_scripts', array( $this, 'load_assets_required_for_m_mode' )); |
|
| 101 | + add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode')); |
|
| 102 | 102 | // shut 'er down down for maintenance ? |
| 103 | - add_filter( 'the_content', array( $this, 'the_content' ), 2 ); |
|
| 103 | + add_filter('the_content', array($this, 'the_content'), 2); |
|
| 104 | 104 | // add powered by EE msg |
| 105 | - add_action( 'shutdown', array( $this, 'display_maintenance_mode_notice' ), 10 ); |
|
| 105 | + add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | * retrieves the maintenance mode option value from the db |
| 113 | 113 | * @return int |
| 114 | 114 | */ |
| 115 | - public function real_level(){ |
|
| 116 | - return get_option( self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance ); |
|
| 115 | + public function real_level() { |
|
| 116 | + return get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * thinks their tables are present and up-to-date). |
| 122 | 122 | * @return boolean |
| 123 | 123 | */ |
| 124 | - public function models_can_query(){ |
|
| 124 | + public function models_can_query() { |
|
| 125 | 125 | return $this->real_level() != EE_Maintenance_Mode::level_2_complete_maintenance; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
| 135 | 135 | * @return int |
| 136 | 136 | */ |
| 137 | - public function level(){ |
|
| 137 | + public function level() { |
|
| 138 | 138 | $real_maintenance_mode_level = $this->real_level(); |
| 139 | 139 | //if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
| 140 | - if( ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) && //only on frontend or ajax requests |
|
| 140 | + if (( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) && //only on frontend or ajax requests |
|
| 141 | 141 | current_user_can('administrator') && //when the user is an admin |
| 142 | - $real_maintenance_mode_level == EE_Maintenance_Mode::level_1_frontend_only_maintenance){//and we're in level 1 |
|
| 142 | + $real_maintenance_mode_level == EE_Maintenance_Mode::level_1_frontend_only_maintenance) {//and we're in level 1 |
|
| 143 | 143 | $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
| 144 | - }else{ |
|
| 144 | + } else { |
|
| 145 | 145 | $maintenance_mode_level = $real_maintenance_mode_level; |
| 146 | 146 | } |
| 147 | 147 | return $maintenance_mode_level; |
@@ -151,17 +151,17 @@ discard block |
||
| 151 | 151 | * Determines if we need to put EE in maintenance mode because the database needs updating |
| 152 | 152 | * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
| 153 | 153 | */ |
| 154 | - public function set_maintenance_mode_if_db_old(){ |
|
| 155 | - EE_Registry::instance()->load_core( 'Data_Migration_Manager' ); |
|
| 156 | - if( EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()){ |
|
| 154 | + public function set_maintenance_mode_if_db_old() { |
|
| 155 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 156 | + if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
| 157 | 157 | update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
| 158 | 158 | return true; |
| 159 | - }elseif( $this->level() == self::level_2_complete_maintenance ){ |
|
| 159 | + }elseif ($this->level() == self::level_2_complete_maintenance) { |
|
| 160 | 160 | //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
| 161 | 161 | //then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
| 162 | - update_option( self::option_name_maintenance_mode, self::level_0_not_in_maintenance ); |
|
| 162 | + update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
| 163 | 163 | return false; |
| 164 | - }else{ |
|
| 164 | + } else { |
|
| 165 | 165 | return false; |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | * @param int $level |
| 172 | 172 | * @return void |
| 173 | 173 | */ |
| 174 | - public function set_maintenance_level($level){ |
|
| 175 | - do_action( 'AHEE__EE_Maintenance_Mode__set_maintenance_level', $level ); |
|
| 174 | + public function set_maintenance_level($level) { |
|
| 175 | + do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
| 176 | 176 | update_option(self::option_name_maintenance_mode, intval($level)); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | * @return string |
| 200 | 200 | */ |
| 201 | 201 | public function load_assets_required_for_m_mode() { |
| 202 | - if ( $this->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance && ! wp_script_is( 'espresso_core', 'enqueued' )) { |
|
| 203 | - wp_register_style( 'espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', array( 'dashicons' ), EVENT_ESPRESSO_VERSION ); |
|
| 202 | + if ($this->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance && ! wp_script_is('espresso_core', 'enqueued')) { |
|
| 203 | + wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
| 204 | 204 | wp_enqueue_style('espresso_default'); |
| 205 | - wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 206 | - wp_enqueue_script( 'espresso_core' ); |
|
| 205 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 206 | + wp_enqueue_script('espresso_core'); |
|
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | public static function template_include() { |
| 223 | 223 | // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints |
| 224 | - return get_template_directory() . '/index.php'; |
|
| 224 | + return get_template_directory().'/index.php'; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
@@ -235,12 +235,12 @@ discard block |
||
| 235 | 235 | * @param string $the_content |
| 236 | 236 | * @return string |
| 237 | 237 | */ |
| 238 | - public function the_content( $the_content ) { |
|
| 238 | + public function the_content($the_content) { |
|
| 239 | 239 | // check if M-mode is engaged and for EE shortcode |
| 240 | - if ( $this->level() && strpos( $the_content, '[ESPRESSO_' ) !== false ) { |
|
| 240 | + if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
| 241 | 241 | // this can eventually be moved to a template, or edited via admin. But for now... |
| 242 | 242 | $the_content = sprintf( |
| 243 | - __( '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', 'event_espresso' ), |
|
| 243 | + __('%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', 'event_espresso'), |
|
| 244 | 244 | '<h3>', |
| 245 | 245 | '</h3><p>', |
| 246 | 246 | '</p>' |
@@ -264,16 +264,16 @@ discard block |
||
| 264 | 264 | // check if M-mode is engaged and for EE shortcode |
| 265 | 265 | if ( |
| 266 | 266 | $this->real_level() && |
| 267 | - current_user_can( 'administrator' ) && |
|
| 267 | + current_user_can('administrator') && |
|
| 268 | 268 | ! is_admin() && |
| 269 | - ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
| 269 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 270 | 270 | && EE_Registry::instance()->REQ->is_espresso_page() |
| 271 | 271 | ) { |
| 272 | 272 | printf( |
| 273 | - __( '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', 'event_espresso' ), |
|
| 273 | + __('%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', 'event_espresso'), |
|
| 274 | 274 | '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
| 275 | 275 | '"><span class="dashicons dashicons-no"></span></a><p>', |
| 276 | - ' » <a href="' . add_query_arg( array( 'page' => 'espresso_maintenance_settings' ), admin_url( 'admin.php' )) . '">', |
|
| 276 | + ' » <a href="'.add_query_arg(array('page' => 'espresso_maintenance_settings'), admin_url('admin.php')).'">', |
|
| 277 | 277 | '</a></p></div>' |
| 278 | 278 | ); |
| 279 | 279 | } |
@@ -291,9 +291,9 @@ discard block |
||
| 291 | 291 | * @ return void |
| 292 | 292 | */ |
| 293 | 293 | final function __destruct() {} |
| 294 | - final function __call($a,$b) {} |
|
| 294 | + final function __call($a, $b) {} |
|
| 295 | 295 | final function __get($a) {} |
| 296 | - final function __set($a,$b) {} |
|
| 296 | + final function __set($a, $b) {} |
|
| 297 | 297 | final function __isset($a) {} |
| 298 | 298 | final function __unset($a) {} |
| 299 | 299 | final function __sleep() { |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | final function __invoke() {} |
| 305 | 305 | final static function __set_state() {} |
| 306 | 306 | final function __clone() {} |
| 307 | - final static function __callStatic($a,$b) {} |
|
| 307 | + final static function __callStatic($a, $b) {} |
|
| 308 | 308 | |
| 309 | 309 | } |
| 310 | 310 | // End of file EE_Maintenance_Mode.core.php |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use OutOfBoundsException; |
| 14 | 14 | |
| 15 | 15 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 16 | - exit('No direct script access allowed'); |
|
| 16 | + exit('No direct script access allowed'); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
@@ -32,502 +32,502 @@ discard block |
||
| 32 | 32 | { |
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * This was the best coffee related name I could think of to represent class name "aliases" |
|
| 37 | - * So classes can be found via an alias identifier, |
|
| 38 | - * that is revealed when it is run through... the filters... eh? get it? |
|
| 39 | - * |
|
| 40 | - * @var array $filters |
|
| 41 | - */ |
|
| 42 | - private $filters = array(); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * These are the classes that will actually build the objects (to order of course) |
|
| 46 | - * |
|
| 47 | - * @var array $coffee_makers |
|
| 48 | - */ |
|
| 49 | - private $coffee_makers = array(); |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * where the instantiated "singleton" objects are stored |
|
| 53 | - * |
|
| 54 | - * @var CollectionInterface $carafe |
|
| 55 | - */ |
|
| 56 | - private $carafe; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * collection of Recipes that instruct us how to brew objects |
|
| 60 | - * |
|
| 61 | - * @var CollectionInterface $recipes |
|
| 62 | - */ |
|
| 63 | - private $recipes; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * collection of closures for brewing objects |
|
| 67 | - * |
|
| 68 | - * @var CollectionInterface $reservoir |
|
| 69 | - */ |
|
| 70 | - private $reservoir; |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * CoffeeShop constructor |
|
| 76 | - */ |
|
| 77 | - public function __construct() |
|
| 78 | - { |
|
| 79 | - // array for storing class aliases |
|
| 80 | - $this->filters = array(); |
|
| 81 | - // create collection for storing shared services |
|
| 82 | - $this->carafe = new LooseCollection( '' ); |
|
| 83 | - // create collection for storing recipes that tell how to build services and entities |
|
| 84 | - $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface'); |
|
| 85 | - // create collection for storing closures for constructing new entities |
|
| 86 | - $this->reservoir = new Collection('Closure'); |
|
| 87 | - // create collection for storing the generators that build our services and entity closures |
|
| 88 | - $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Returns true if the container can return an entry for the given identifier. |
|
| 95 | - * Returns false otherwise. |
|
| 96 | - * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception. |
|
| 97 | - * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`. |
|
| 98 | - * |
|
| 99 | - * @param string $identifier Identifier of the entry to look for. |
|
| 100 | - * Typically a Fully Qualified Class Name |
|
| 101 | - * @return boolean |
|
| 102 | - */ |
|
| 103 | - public function has($identifier) |
|
| 104 | - { |
|
| 105 | - $identifier = $this->filterIdentifier($identifier); |
|
| 106 | - return $this->carafe->has($identifier); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * finds a previously brewed (SHARED) service and returns it |
|
| 113 | - * |
|
| 114 | - * @param string $identifier Identifier for the entity class to be constructed. |
|
| 115 | - * Typically a Fully Qualified Class Name |
|
| 116 | - * @return mixed |
|
| 117 | - * @throws ServiceNotFoundException No service was found for this identifier. |
|
| 118 | - */ |
|
| 119 | - public function get($identifier) |
|
| 120 | - { |
|
| 121 | - $identifier = $this->filterIdentifier($identifier); |
|
| 122 | - if ($this->carafe->has($identifier)) { |
|
| 123 | - return $this->carafe->get($identifier); |
|
| 124 | - } |
|
| 125 | - throw new ServiceNotFoundException($identifier); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * returns an instance of the requested entity type using the supplied arguments. |
|
| 132 | - * If a shared service is requested and an instance is already in the carafe, then it will be returned. |
|
| 133 | - * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned |
|
| 134 | - * If the request is for a new entity and a closure exists in the reservoir for creating it, |
|
| 135 | - * then a new entity will be instantiated from the closure and returned. |
|
| 136 | - * If a closure does not exist, then one will be built and added to the reservoir |
|
| 137 | - * before instantiating the requested entity. |
|
| 138 | - * |
|
| 139 | - * @param string $identifier Identifier for the entity class to be constructed. |
|
| 140 | - * Typically a Fully Qualified Class Name |
|
| 141 | - * @param array $arguments an array of arguments to be passed to the entity constructor |
|
| 142 | - * @param string $type |
|
| 143 | - * @return mixed |
|
| 144 | - * @throws ServiceNotFoundException No service was found for this identifier. |
|
| 145 | - */ |
|
| 146 | - public function brew($identifier, $arguments = array(), $type = '') |
|
| 147 | - { |
|
| 148 | - // resolve any class aliases that may exist |
|
| 149 | - $identifier = $this->filterIdentifier($identifier); |
|
| 150 | - try { |
|
| 151 | - // is a shared service being requested? |
|
| 152 | - if (empty($type) || $type === CoffeeMaker::BREW_SHARED) { |
|
| 153 | - // if a shared service was requested and an instance is in the carafe, then return it |
|
| 154 | - return $this->get($identifier); |
|
| 155 | - } |
|
| 156 | - } catch (ServiceNotFoundException $e) { |
|
| 157 | - // if not then we'll just catch the ServiceNotFoundException but not do anything just yet, |
|
| 158 | - // and instead, attempt to build whatever was requested |
|
| 159 | - } |
|
| 160 | - $brewed = false; |
|
| 161 | - // if the reservoir doesn't have a closure already for the requested identifier, |
|
| 162 | - // then neither a shared service nor a closure for making entities has been built yet |
|
| 163 | - if ( ! $this->reservoir->has($identifier)) { |
|
| 164 | - // so let's brew something up and add it to the proper collection |
|
| 165 | - $brewed = $this->makeCoffee($identifier, $arguments, $type); |
|
| 166 | - } |
|
| 167 | - // was the brewed item a callable factory function ? |
|
| 168 | - if (is_callable($brewed)) { |
|
| 169 | - // then instantiate a new entity from the cached closure |
|
| 170 | - $entity = $brewed($arguments); |
|
| 171 | - } else if ($brewed) { |
|
| 172 | - // requested object was a shared entity, so attempt to get it from the carafe again |
|
| 173 | - // because if it wasn't there before, then it should have just been brewed and added, |
|
| 174 | - // but if it still isn't there, then this time |
|
| 175 | - // the thrown ServiceNotFoundException will not be caught |
|
| 176 | - $entity = $this->get($identifier); |
|
| 177 | - } else { |
|
| 178 | - // if identifier is for a non-shared entity, |
|
| 179 | - // then either a cached closure already existed, or was just brewed |
|
| 180 | - $closure = $this->reservoir->get($identifier); |
|
| 181 | - $entity = $closure($arguments); |
|
| 182 | - } |
|
| 183 | - return $entity; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @param CoffeeMakerInterface $coffee_maker |
|
| 190 | - * @param string $type |
|
| 191 | - * @return bool |
|
| 192 | - */ |
|
| 193 | - public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type) |
|
| 194 | - { |
|
| 195 | - $type = CoffeeMaker::validateType($type); |
|
| 196 | - return $this->coffee_makers->add($coffee_maker, $type); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @param string $identifier |
|
| 203 | - * @param callable $closure |
|
| 204 | - * @return callable|null |
|
| 205 | - */ |
|
| 206 | - public function addClosure($identifier, $closure) |
|
| 207 | - { |
|
| 208 | - if ( ! is_callable($closure)) { |
|
| 209 | - throw new InvalidDataTypeException('$closure', $closure, 'Closure'); |
|
| 210 | - } |
|
| 211 | - $identifier = $this->processIdentifier($identifier); |
|
| 212 | - if ($this->reservoir->add($closure, $identifier)) { |
|
| 213 | - return $closure; |
|
| 214 | - } |
|
| 215 | - return null; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @param string $identifier |
|
| 222 | - * @return boolean |
|
| 223 | - */ |
|
| 224 | - public function removeClosure($identifier) |
|
| 225 | - { |
|
| 226 | - $identifier = $this->processIdentifier($identifier); |
|
| 227 | - if ($this->reservoir->has($identifier)) { |
|
| 228 | - $this->reservoir->remove($this->reservoir->get($identifier)); |
|
| 229 | - if ( ! $this->reservoir->has($identifier)) { |
|
| 230 | - return true; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - return false; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param string $identifier Identifier for the entity class that the service applies to |
|
| 240 | - * Typically a Fully Qualified Class Name |
|
| 241 | - * @param mixed $service |
|
| 242 | - * @return bool |
|
| 243 | - */ |
|
| 244 | - public function addService($identifier, $service) |
|
| 245 | - { |
|
| 246 | - $identifier = $this->processIdentifier($identifier); |
|
| 247 | - $service = $this->validateService($identifier, $service); |
|
| 248 | - return $this->carafe->add($service, $identifier); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * @param string $identifier |
|
| 255 | - * @return boolean |
|
| 256 | - */ |
|
| 257 | - public function removeService($identifier) |
|
| 258 | - { |
|
| 259 | - $identifier = $this->processIdentifier($identifier); |
|
| 260 | - if ($this->carafe->has($identifier)) { |
|
| 261 | - $this->carafe->remove($this->carafe->get($identifier)); |
|
| 262 | - if ( ! $this->carafe->has($identifier)) { |
|
| 263 | - return true; |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - return false; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Adds instructions on how to brew objects |
|
| 273 | - * |
|
| 274 | - * @param RecipeInterface $recipe |
|
| 275 | - * @return mixed |
|
| 276 | - */ |
|
| 277 | - public function addRecipe(RecipeInterface $recipe) |
|
| 278 | - { |
|
| 279 | - $this->addAliases($recipe->identifier(), $recipe->filters()); |
|
| 280 | - $identifier = $this->processIdentifier($recipe->identifier()); |
|
| 281 | - return $this->recipes->add($recipe, $identifier); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param string $identifier The Recipe's identifier |
|
| 288 | - * @return boolean |
|
| 289 | - */ |
|
| 290 | - public function removeRecipe($identifier) |
|
| 291 | - { |
|
| 292 | - $identifier = $this->processIdentifier($identifier); |
|
| 293 | - if ($this->recipes->has($identifier)) { |
|
| 294 | - $this->recipes->remove( |
|
| 295 | - $this->recipes->get($identifier) |
|
| 296 | - ); |
|
| 297 | - if ( ! $this->recipes->has($identifier)) { |
|
| 298 | - return true; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - return false; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Get instructions on how to brew objects |
|
| 308 | - * |
|
| 309 | - * @param string $identifier Identifier for the entity class that the recipe applies to |
|
| 310 | - * Typically a Fully Qualified Class Name |
|
| 311 | - * @param string $type |
|
| 312 | - * @return RecipeInterface |
|
| 313 | - */ |
|
| 314 | - public function getRecipe($identifier, $type = '') |
|
| 315 | - { |
|
| 316 | - $identifier = $this->processIdentifier($identifier); |
|
| 317 | - if ($this->recipes->has($identifier)) { |
|
| 318 | - return $this->recipes->get($identifier); |
|
| 319 | - } |
|
| 320 | - $default_recipes = $this->getDefaultRecipes(); |
|
| 321 | - $matches = array(); |
|
| 322 | - foreach ($default_recipes as $wildcard => $default_recipe) { |
|
| 323 | - // is the wildcard recipe prefix in the identifier ? |
|
| 324 | - if (strpos($identifier, $wildcard) !== false) { |
|
| 325 | - // track matches and use the number of wildcard characters matched for the key |
|
| 326 | - $matches[strlen($wildcard)] = $default_recipe; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - if (count($matches) > 0) { |
|
| 330 | - // sort our recipes by the number of wildcard characters matched |
|
| 331 | - ksort($matches); |
|
| 332 | - // then grab the last recipe form the list, since it had the most matching characters |
|
| 333 | - $match = array_pop($matches); |
|
| 334 | - // since we are using a default recipe, we need to set it's identifier and fqcn |
|
| 335 | - return $this->copyDefaultRecipe($match, $identifier, $type); |
|
| 336 | - } |
|
| 337 | - if ($this->recipes->has(Recipe::DEFAULT_ID)) { |
|
| 338 | - // since we are using a default recipe, we need to set it's identifier and fqcn |
|
| 339 | - return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type); |
|
| 340 | - } |
|
| 341 | - throw new OutOfBoundsException( |
|
| 342 | - sprintf( |
|
| 343 | - __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'), |
|
| 344 | - $identifier |
|
| 345 | - ) |
|
| 346 | - ); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * adds class name aliases to list of filters |
|
| 353 | - * |
|
| 354 | - * @param string $identifier Identifier for the entity class that the alias applies to |
|
| 355 | - * Typically a Fully Qualified Class Name |
|
| 356 | - * @param array $aliases |
|
| 357 | - * @return void |
|
| 358 | - * @throws InvalidIdentifierException |
|
| 359 | - */ |
|
| 360 | - public function addAliases($identifier, $aliases) |
|
| 361 | - { |
|
| 362 | - if (empty($aliases)) { |
|
| 363 | - return; |
|
| 364 | - } |
|
| 365 | - $identifier = $this->processIdentifier($identifier); |
|
| 366 | - foreach ((array)$aliases as $alias) { |
|
| 367 | - $this->filters[$this->processIdentifier($alias)] = $identifier; |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Adds a service to one of the internal collections |
|
| 375 | - * |
|
| 376 | - * @param $identifier |
|
| 377 | - * @param array $arguments |
|
| 378 | - * @param string $type |
|
| 379 | - * @return mixed |
|
| 380 | - * @throws ServiceExistsException |
|
| 381 | - */ |
|
| 382 | - private function makeCoffee($identifier, $arguments = array(), $type = '') |
|
| 383 | - { |
|
| 384 | - if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) { |
|
| 385 | - throw new ServiceExistsException($identifier); |
|
| 386 | - } |
|
| 387 | - $identifier = $this->filterIdentifier($identifier); |
|
| 388 | - $recipe = $this->getRecipe($identifier, $type); |
|
| 389 | - $type = ! empty($type) ? $type : $recipe->type(); |
|
| 390 | - $coffee_maker = $this->getCoffeeMaker($type); |
|
| 391 | - return $coffee_maker->brew($recipe, $arguments); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * filters alias identifiers to find the real class name |
|
| 398 | - * |
|
| 399 | - * @param string $identifier Identifier for the entity class that the filter applies to |
|
| 400 | - * Typically a Fully Qualified Class Name |
|
| 401 | - * @return string |
|
| 402 | - * @throws InvalidIdentifierException |
|
| 403 | - */ |
|
| 404 | - private function filterIdentifier($identifier) |
|
| 405 | - { |
|
| 406 | - $identifier = $this->processIdentifier($identifier); |
|
| 407 | - return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier]) |
|
| 408 | - ? $this->filters[$identifier] |
|
| 409 | - : $identifier; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * verifies and standardizes identifiers |
|
| 416 | - * |
|
| 417 | - * @param string $identifier Identifier for the entity class |
|
| 418 | - * Typically a Fully Qualified Class Name |
|
| 419 | - * @return string |
|
| 420 | - * @throws InvalidIdentifierException |
|
| 421 | - */ |
|
| 422 | - private function processIdentifier($identifier) |
|
| 423 | - { |
|
| 424 | - if ( ! is_string($identifier)) { |
|
| 425 | - throw new InvalidIdentifierException( |
|
| 426 | - is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
| 427 | - '\Fully\Qualified\ClassName' |
|
| 428 | - ); |
|
| 429 | - } |
|
| 430 | - return ltrim($identifier, '\\'); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * @param string $type |
|
| 437 | - * @return CoffeeMakerInterface |
|
| 438 | - * @throws InvalidDataTypeException |
|
| 439 | - * @throws InvalidClassException |
|
| 440 | - */ |
|
| 441 | - private function getCoffeeMaker($type) |
|
| 442 | - { |
|
| 443 | - if ( ! $this->coffee_makers->has($type)) { |
|
| 444 | - throw new OutOfBoundsException( |
|
| 445 | - __('The requested coffee maker is either missing or invalid.', 'event_espresso') |
|
| 446 | - ); |
|
| 447 | - } |
|
| 448 | - return $this->coffee_makers->get($type); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Retrieves all recipes that use a wildcard "*" in their identifier |
|
| 455 | - * This allows recipes to be set up for handling |
|
| 456 | - * legacy classes that do not support PSR-4 autoloading. |
|
| 457 | - * for example: |
|
| 458 | - * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee |
|
| 459 | - * |
|
| 460 | - * @return array |
|
| 461 | - */ |
|
| 462 | - private function getDefaultRecipes() |
|
| 463 | - { |
|
| 464 | - $default_recipes = array(); |
|
| 465 | - $this->recipes->rewind(); |
|
| 466 | - while ($this->recipes->valid()) { |
|
| 467 | - $identifier = $this->recipes->getInfo(); |
|
| 468 | - // does this recipe use a wildcard ? (but is NOT the global default) |
|
| 469 | - if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) { |
|
| 470 | - // strip the wildcard and use identifier as key |
|
| 471 | - $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current(); |
|
| 472 | - } |
|
| 473 | - $this->recipes->next(); |
|
| 474 | - } |
|
| 475 | - return $default_recipes; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * clones a default recipe and then copies details |
|
| 482 | - * from the incoming request to it so that it can be used |
|
| 483 | - * |
|
| 484 | - * @param RecipeInterface $default_recipe |
|
| 485 | - * @param string $identifier |
|
| 486 | - * @param string $type |
|
| 487 | - * @return RecipeInterface |
|
| 488 | - */ |
|
| 489 | - private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '') |
|
| 490 | - { |
|
| 491 | - $recipe = clone $default_recipe; |
|
| 492 | - if ( ! empty($type)) { |
|
| 493 | - $recipe->setType($type); |
|
| 494 | - } |
|
| 495 | - // is this the base default recipe ? |
|
| 496 | - if ($default_recipe->identifier() === Recipe::DEFAULT_ID) { |
|
| 497 | - $recipe->setIdentifier($identifier); |
|
| 498 | - $recipe->setFqcn($identifier); |
|
| 499 | - return $recipe; |
|
| 500 | - } |
|
| 501 | - $recipe->setIdentifier($identifier); |
|
| 502 | - foreach ($default_recipe->paths() as $path) { |
|
| 503 | - $path = str_replace('*', $identifier, $path); |
|
| 504 | - if (is_readable($path)) { |
|
| 505 | - $recipe->setPaths($path); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - $recipe->setFqcn($identifier); |
|
| 509 | - return $recipe; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * @param string $identifier Identifier for the entity class that the service applies to |
|
| 516 | - * Typically a Fully Qualified Class Name |
|
| 517 | - * @param mixed $service |
|
| 518 | - * @return object |
|
| 519 | - * @throws InvalidServiceException |
|
| 520 | - */ |
|
| 521 | - private function validateService($identifier, $service) |
|
| 522 | - { |
|
| 523 | - if ( ! is_object($service)) { |
|
| 524 | - throw new InvalidServiceException( |
|
| 525 | - $identifier, |
|
| 526 | - $service |
|
| 527 | - ); |
|
| 528 | - } |
|
| 529 | - return $service; |
|
| 530 | - } |
|
| 35 | + /** |
|
| 36 | + * This was the best coffee related name I could think of to represent class name "aliases" |
|
| 37 | + * So classes can be found via an alias identifier, |
|
| 38 | + * that is revealed when it is run through... the filters... eh? get it? |
|
| 39 | + * |
|
| 40 | + * @var array $filters |
|
| 41 | + */ |
|
| 42 | + private $filters = array(); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * These are the classes that will actually build the objects (to order of course) |
|
| 46 | + * |
|
| 47 | + * @var array $coffee_makers |
|
| 48 | + */ |
|
| 49 | + private $coffee_makers = array(); |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * where the instantiated "singleton" objects are stored |
|
| 53 | + * |
|
| 54 | + * @var CollectionInterface $carafe |
|
| 55 | + */ |
|
| 56 | + private $carafe; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * collection of Recipes that instruct us how to brew objects |
|
| 60 | + * |
|
| 61 | + * @var CollectionInterface $recipes |
|
| 62 | + */ |
|
| 63 | + private $recipes; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * collection of closures for brewing objects |
|
| 67 | + * |
|
| 68 | + * @var CollectionInterface $reservoir |
|
| 69 | + */ |
|
| 70 | + private $reservoir; |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * CoffeeShop constructor |
|
| 76 | + */ |
|
| 77 | + public function __construct() |
|
| 78 | + { |
|
| 79 | + // array for storing class aliases |
|
| 80 | + $this->filters = array(); |
|
| 81 | + // create collection for storing shared services |
|
| 82 | + $this->carafe = new LooseCollection( '' ); |
|
| 83 | + // create collection for storing recipes that tell how to build services and entities |
|
| 84 | + $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface'); |
|
| 85 | + // create collection for storing closures for constructing new entities |
|
| 86 | + $this->reservoir = new Collection('Closure'); |
|
| 87 | + // create collection for storing the generators that build our services and entity closures |
|
| 88 | + $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Returns true if the container can return an entry for the given identifier. |
|
| 95 | + * Returns false otherwise. |
|
| 96 | + * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception. |
|
| 97 | + * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`. |
|
| 98 | + * |
|
| 99 | + * @param string $identifier Identifier of the entry to look for. |
|
| 100 | + * Typically a Fully Qualified Class Name |
|
| 101 | + * @return boolean |
|
| 102 | + */ |
|
| 103 | + public function has($identifier) |
|
| 104 | + { |
|
| 105 | + $identifier = $this->filterIdentifier($identifier); |
|
| 106 | + return $this->carafe->has($identifier); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * finds a previously brewed (SHARED) service and returns it |
|
| 113 | + * |
|
| 114 | + * @param string $identifier Identifier for the entity class to be constructed. |
|
| 115 | + * Typically a Fully Qualified Class Name |
|
| 116 | + * @return mixed |
|
| 117 | + * @throws ServiceNotFoundException No service was found for this identifier. |
|
| 118 | + */ |
|
| 119 | + public function get($identifier) |
|
| 120 | + { |
|
| 121 | + $identifier = $this->filterIdentifier($identifier); |
|
| 122 | + if ($this->carafe->has($identifier)) { |
|
| 123 | + return $this->carafe->get($identifier); |
|
| 124 | + } |
|
| 125 | + throw new ServiceNotFoundException($identifier); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * returns an instance of the requested entity type using the supplied arguments. |
|
| 132 | + * If a shared service is requested and an instance is already in the carafe, then it will be returned. |
|
| 133 | + * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned |
|
| 134 | + * If the request is for a new entity and a closure exists in the reservoir for creating it, |
|
| 135 | + * then a new entity will be instantiated from the closure and returned. |
|
| 136 | + * If a closure does not exist, then one will be built and added to the reservoir |
|
| 137 | + * before instantiating the requested entity. |
|
| 138 | + * |
|
| 139 | + * @param string $identifier Identifier for the entity class to be constructed. |
|
| 140 | + * Typically a Fully Qualified Class Name |
|
| 141 | + * @param array $arguments an array of arguments to be passed to the entity constructor |
|
| 142 | + * @param string $type |
|
| 143 | + * @return mixed |
|
| 144 | + * @throws ServiceNotFoundException No service was found for this identifier. |
|
| 145 | + */ |
|
| 146 | + public function brew($identifier, $arguments = array(), $type = '') |
|
| 147 | + { |
|
| 148 | + // resolve any class aliases that may exist |
|
| 149 | + $identifier = $this->filterIdentifier($identifier); |
|
| 150 | + try { |
|
| 151 | + // is a shared service being requested? |
|
| 152 | + if (empty($type) || $type === CoffeeMaker::BREW_SHARED) { |
|
| 153 | + // if a shared service was requested and an instance is in the carafe, then return it |
|
| 154 | + return $this->get($identifier); |
|
| 155 | + } |
|
| 156 | + } catch (ServiceNotFoundException $e) { |
|
| 157 | + // if not then we'll just catch the ServiceNotFoundException but not do anything just yet, |
|
| 158 | + // and instead, attempt to build whatever was requested |
|
| 159 | + } |
|
| 160 | + $brewed = false; |
|
| 161 | + // if the reservoir doesn't have a closure already for the requested identifier, |
|
| 162 | + // then neither a shared service nor a closure for making entities has been built yet |
|
| 163 | + if ( ! $this->reservoir->has($identifier)) { |
|
| 164 | + // so let's brew something up and add it to the proper collection |
|
| 165 | + $brewed = $this->makeCoffee($identifier, $arguments, $type); |
|
| 166 | + } |
|
| 167 | + // was the brewed item a callable factory function ? |
|
| 168 | + if (is_callable($brewed)) { |
|
| 169 | + // then instantiate a new entity from the cached closure |
|
| 170 | + $entity = $brewed($arguments); |
|
| 171 | + } else if ($brewed) { |
|
| 172 | + // requested object was a shared entity, so attempt to get it from the carafe again |
|
| 173 | + // because if it wasn't there before, then it should have just been brewed and added, |
|
| 174 | + // but if it still isn't there, then this time |
|
| 175 | + // the thrown ServiceNotFoundException will not be caught |
|
| 176 | + $entity = $this->get($identifier); |
|
| 177 | + } else { |
|
| 178 | + // if identifier is for a non-shared entity, |
|
| 179 | + // then either a cached closure already existed, or was just brewed |
|
| 180 | + $closure = $this->reservoir->get($identifier); |
|
| 181 | + $entity = $closure($arguments); |
|
| 182 | + } |
|
| 183 | + return $entity; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @param CoffeeMakerInterface $coffee_maker |
|
| 190 | + * @param string $type |
|
| 191 | + * @return bool |
|
| 192 | + */ |
|
| 193 | + public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type) |
|
| 194 | + { |
|
| 195 | + $type = CoffeeMaker::validateType($type); |
|
| 196 | + return $this->coffee_makers->add($coffee_maker, $type); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @param string $identifier |
|
| 203 | + * @param callable $closure |
|
| 204 | + * @return callable|null |
|
| 205 | + */ |
|
| 206 | + public function addClosure($identifier, $closure) |
|
| 207 | + { |
|
| 208 | + if ( ! is_callable($closure)) { |
|
| 209 | + throw new InvalidDataTypeException('$closure', $closure, 'Closure'); |
|
| 210 | + } |
|
| 211 | + $identifier = $this->processIdentifier($identifier); |
|
| 212 | + if ($this->reservoir->add($closure, $identifier)) { |
|
| 213 | + return $closure; |
|
| 214 | + } |
|
| 215 | + return null; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @param string $identifier |
|
| 222 | + * @return boolean |
|
| 223 | + */ |
|
| 224 | + public function removeClosure($identifier) |
|
| 225 | + { |
|
| 226 | + $identifier = $this->processIdentifier($identifier); |
|
| 227 | + if ($this->reservoir->has($identifier)) { |
|
| 228 | + $this->reservoir->remove($this->reservoir->get($identifier)); |
|
| 229 | + if ( ! $this->reservoir->has($identifier)) { |
|
| 230 | + return true; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + return false; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param string $identifier Identifier for the entity class that the service applies to |
|
| 240 | + * Typically a Fully Qualified Class Name |
|
| 241 | + * @param mixed $service |
|
| 242 | + * @return bool |
|
| 243 | + */ |
|
| 244 | + public function addService($identifier, $service) |
|
| 245 | + { |
|
| 246 | + $identifier = $this->processIdentifier($identifier); |
|
| 247 | + $service = $this->validateService($identifier, $service); |
|
| 248 | + return $this->carafe->add($service, $identifier); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * @param string $identifier |
|
| 255 | + * @return boolean |
|
| 256 | + */ |
|
| 257 | + public function removeService($identifier) |
|
| 258 | + { |
|
| 259 | + $identifier = $this->processIdentifier($identifier); |
|
| 260 | + if ($this->carafe->has($identifier)) { |
|
| 261 | + $this->carafe->remove($this->carafe->get($identifier)); |
|
| 262 | + if ( ! $this->carafe->has($identifier)) { |
|
| 263 | + return true; |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Adds instructions on how to brew objects |
|
| 273 | + * |
|
| 274 | + * @param RecipeInterface $recipe |
|
| 275 | + * @return mixed |
|
| 276 | + */ |
|
| 277 | + public function addRecipe(RecipeInterface $recipe) |
|
| 278 | + { |
|
| 279 | + $this->addAliases($recipe->identifier(), $recipe->filters()); |
|
| 280 | + $identifier = $this->processIdentifier($recipe->identifier()); |
|
| 281 | + return $this->recipes->add($recipe, $identifier); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param string $identifier The Recipe's identifier |
|
| 288 | + * @return boolean |
|
| 289 | + */ |
|
| 290 | + public function removeRecipe($identifier) |
|
| 291 | + { |
|
| 292 | + $identifier = $this->processIdentifier($identifier); |
|
| 293 | + if ($this->recipes->has($identifier)) { |
|
| 294 | + $this->recipes->remove( |
|
| 295 | + $this->recipes->get($identifier) |
|
| 296 | + ); |
|
| 297 | + if ( ! $this->recipes->has($identifier)) { |
|
| 298 | + return true; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + return false; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Get instructions on how to brew objects |
|
| 308 | + * |
|
| 309 | + * @param string $identifier Identifier for the entity class that the recipe applies to |
|
| 310 | + * Typically a Fully Qualified Class Name |
|
| 311 | + * @param string $type |
|
| 312 | + * @return RecipeInterface |
|
| 313 | + */ |
|
| 314 | + public function getRecipe($identifier, $type = '') |
|
| 315 | + { |
|
| 316 | + $identifier = $this->processIdentifier($identifier); |
|
| 317 | + if ($this->recipes->has($identifier)) { |
|
| 318 | + return $this->recipes->get($identifier); |
|
| 319 | + } |
|
| 320 | + $default_recipes = $this->getDefaultRecipes(); |
|
| 321 | + $matches = array(); |
|
| 322 | + foreach ($default_recipes as $wildcard => $default_recipe) { |
|
| 323 | + // is the wildcard recipe prefix in the identifier ? |
|
| 324 | + if (strpos($identifier, $wildcard) !== false) { |
|
| 325 | + // track matches and use the number of wildcard characters matched for the key |
|
| 326 | + $matches[strlen($wildcard)] = $default_recipe; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + if (count($matches) > 0) { |
|
| 330 | + // sort our recipes by the number of wildcard characters matched |
|
| 331 | + ksort($matches); |
|
| 332 | + // then grab the last recipe form the list, since it had the most matching characters |
|
| 333 | + $match = array_pop($matches); |
|
| 334 | + // since we are using a default recipe, we need to set it's identifier and fqcn |
|
| 335 | + return $this->copyDefaultRecipe($match, $identifier, $type); |
|
| 336 | + } |
|
| 337 | + if ($this->recipes->has(Recipe::DEFAULT_ID)) { |
|
| 338 | + // since we are using a default recipe, we need to set it's identifier and fqcn |
|
| 339 | + return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type); |
|
| 340 | + } |
|
| 341 | + throw new OutOfBoundsException( |
|
| 342 | + sprintf( |
|
| 343 | + __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'), |
|
| 344 | + $identifier |
|
| 345 | + ) |
|
| 346 | + ); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * adds class name aliases to list of filters |
|
| 353 | + * |
|
| 354 | + * @param string $identifier Identifier for the entity class that the alias applies to |
|
| 355 | + * Typically a Fully Qualified Class Name |
|
| 356 | + * @param array $aliases |
|
| 357 | + * @return void |
|
| 358 | + * @throws InvalidIdentifierException |
|
| 359 | + */ |
|
| 360 | + public function addAliases($identifier, $aliases) |
|
| 361 | + { |
|
| 362 | + if (empty($aliases)) { |
|
| 363 | + return; |
|
| 364 | + } |
|
| 365 | + $identifier = $this->processIdentifier($identifier); |
|
| 366 | + foreach ((array)$aliases as $alias) { |
|
| 367 | + $this->filters[$this->processIdentifier($alias)] = $identifier; |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Adds a service to one of the internal collections |
|
| 375 | + * |
|
| 376 | + * @param $identifier |
|
| 377 | + * @param array $arguments |
|
| 378 | + * @param string $type |
|
| 379 | + * @return mixed |
|
| 380 | + * @throws ServiceExistsException |
|
| 381 | + */ |
|
| 382 | + private function makeCoffee($identifier, $arguments = array(), $type = '') |
|
| 383 | + { |
|
| 384 | + if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) { |
|
| 385 | + throw new ServiceExistsException($identifier); |
|
| 386 | + } |
|
| 387 | + $identifier = $this->filterIdentifier($identifier); |
|
| 388 | + $recipe = $this->getRecipe($identifier, $type); |
|
| 389 | + $type = ! empty($type) ? $type : $recipe->type(); |
|
| 390 | + $coffee_maker = $this->getCoffeeMaker($type); |
|
| 391 | + return $coffee_maker->brew($recipe, $arguments); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * filters alias identifiers to find the real class name |
|
| 398 | + * |
|
| 399 | + * @param string $identifier Identifier for the entity class that the filter applies to |
|
| 400 | + * Typically a Fully Qualified Class Name |
|
| 401 | + * @return string |
|
| 402 | + * @throws InvalidIdentifierException |
|
| 403 | + */ |
|
| 404 | + private function filterIdentifier($identifier) |
|
| 405 | + { |
|
| 406 | + $identifier = $this->processIdentifier($identifier); |
|
| 407 | + return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier]) |
|
| 408 | + ? $this->filters[$identifier] |
|
| 409 | + : $identifier; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * verifies and standardizes identifiers |
|
| 416 | + * |
|
| 417 | + * @param string $identifier Identifier for the entity class |
|
| 418 | + * Typically a Fully Qualified Class Name |
|
| 419 | + * @return string |
|
| 420 | + * @throws InvalidIdentifierException |
|
| 421 | + */ |
|
| 422 | + private function processIdentifier($identifier) |
|
| 423 | + { |
|
| 424 | + if ( ! is_string($identifier)) { |
|
| 425 | + throw new InvalidIdentifierException( |
|
| 426 | + is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
| 427 | + '\Fully\Qualified\ClassName' |
|
| 428 | + ); |
|
| 429 | + } |
|
| 430 | + return ltrim($identifier, '\\'); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * @param string $type |
|
| 437 | + * @return CoffeeMakerInterface |
|
| 438 | + * @throws InvalidDataTypeException |
|
| 439 | + * @throws InvalidClassException |
|
| 440 | + */ |
|
| 441 | + private function getCoffeeMaker($type) |
|
| 442 | + { |
|
| 443 | + if ( ! $this->coffee_makers->has($type)) { |
|
| 444 | + throw new OutOfBoundsException( |
|
| 445 | + __('The requested coffee maker is either missing or invalid.', 'event_espresso') |
|
| 446 | + ); |
|
| 447 | + } |
|
| 448 | + return $this->coffee_makers->get($type); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Retrieves all recipes that use a wildcard "*" in their identifier |
|
| 455 | + * This allows recipes to be set up for handling |
|
| 456 | + * legacy classes that do not support PSR-4 autoloading. |
|
| 457 | + * for example: |
|
| 458 | + * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee |
|
| 459 | + * |
|
| 460 | + * @return array |
|
| 461 | + */ |
|
| 462 | + private function getDefaultRecipes() |
|
| 463 | + { |
|
| 464 | + $default_recipes = array(); |
|
| 465 | + $this->recipes->rewind(); |
|
| 466 | + while ($this->recipes->valid()) { |
|
| 467 | + $identifier = $this->recipes->getInfo(); |
|
| 468 | + // does this recipe use a wildcard ? (but is NOT the global default) |
|
| 469 | + if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) { |
|
| 470 | + // strip the wildcard and use identifier as key |
|
| 471 | + $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current(); |
|
| 472 | + } |
|
| 473 | + $this->recipes->next(); |
|
| 474 | + } |
|
| 475 | + return $default_recipes; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * clones a default recipe and then copies details |
|
| 482 | + * from the incoming request to it so that it can be used |
|
| 483 | + * |
|
| 484 | + * @param RecipeInterface $default_recipe |
|
| 485 | + * @param string $identifier |
|
| 486 | + * @param string $type |
|
| 487 | + * @return RecipeInterface |
|
| 488 | + */ |
|
| 489 | + private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '') |
|
| 490 | + { |
|
| 491 | + $recipe = clone $default_recipe; |
|
| 492 | + if ( ! empty($type)) { |
|
| 493 | + $recipe->setType($type); |
|
| 494 | + } |
|
| 495 | + // is this the base default recipe ? |
|
| 496 | + if ($default_recipe->identifier() === Recipe::DEFAULT_ID) { |
|
| 497 | + $recipe->setIdentifier($identifier); |
|
| 498 | + $recipe->setFqcn($identifier); |
|
| 499 | + return $recipe; |
|
| 500 | + } |
|
| 501 | + $recipe->setIdentifier($identifier); |
|
| 502 | + foreach ($default_recipe->paths() as $path) { |
|
| 503 | + $path = str_replace('*', $identifier, $path); |
|
| 504 | + if (is_readable($path)) { |
|
| 505 | + $recipe->setPaths($path); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + $recipe->setFqcn($identifier); |
|
| 509 | + return $recipe; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * @param string $identifier Identifier for the entity class that the service applies to |
|
| 516 | + * Typically a Fully Qualified Class Name |
|
| 517 | + * @param mixed $service |
|
| 518 | + * @return object |
|
| 519 | + * @throws InvalidServiceException |
|
| 520 | + */ |
|
| 521 | + private function validateService($identifier, $service) |
|
| 522 | + { |
|
| 523 | + if ( ! is_object($service)) { |
|
| 524 | + throw new InvalidServiceException( |
|
| 525 | + $identifier, |
|
| 526 | + $service |
|
| 527 | + ); |
|
| 528 | + } |
|
| 529 | + return $service; |
|
| 530 | + } |
|
| 531 | 531 | |
| 532 | 532 | } |
| 533 | 533 | // End of file CoffeeShop.php |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -31,1533 +31,1533 @@ discard block |
||
| 31 | 31 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * This property is just used to hold the status of whether an event is currently being |
|
| 36 | - * created (true) or edited (false) |
|
| 37 | - * @access protected |
|
| 38 | - * @var bool |
|
| 39 | - */ |
|
| 40 | - protected $_is_creating_event; |
|
| 34 | + /** |
|
| 35 | + * This property is just used to hold the status of whether an event is currently being |
|
| 36 | + * created (true) or edited (false) |
|
| 37 | + * @access protected |
|
| 38 | + * @var bool |
|
| 39 | + */ |
|
| 40 | + protected $_is_creating_event; |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Used to contain the format strings for date and time that will be used for php date and |
|
| 45 | - * time. |
|
| 46 | - * |
|
| 47 | - * Is set in the _set_hooks_properties() method. |
|
| 48 | - * |
|
| 49 | - * @var array |
|
| 50 | - */ |
|
| 51 | - protected $_date_format_strings; |
|
| 43 | + /** |
|
| 44 | + * Used to contain the format strings for date and time that will be used for php date and |
|
| 45 | + * time. |
|
| 46 | + * |
|
| 47 | + * Is set in the _set_hooks_properties() method. |
|
| 48 | + * |
|
| 49 | + * @var array |
|
| 50 | + */ |
|
| 51 | + protected $_date_format_strings; |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - protected function _set_hooks_properties() |
|
| 55 | - { |
|
| 56 | - $this->_name = 'pricing'; |
|
| 57 | - |
|
| 58 | - //capability check |
|
| 59 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices', |
|
| 60 | - 'advanced_ticket_datetime_metabox') |
|
| 61 | - ) { |
|
| 62 | - return; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - //if we were going to add our own metaboxes we'd use the below. |
|
| 67 | - $this->_metaboxes = array( |
|
| 68 | - 0 => array( |
|
| 69 | - 'page_route' => array('edit', 'create_new'), |
|
| 70 | - 'func' => 'pricing_metabox', |
|
| 71 | - 'label' => __('Event Tickets & Datetimes', 'event_espresso'), |
|
| 72 | - 'priority' => 'high', |
|
| 73 | - 'context' => 'normal' |
|
| 74 | - ), |
|
| 75 | - |
|
| 76 | - );/**/ |
|
| 77 | - |
|
| 78 | - $this->_remove_metaboxes = array( |
|
| 79 | - 0 => array( |
|
| 80 | - 'page_route' => array('edit', 'create_new'), |
|
| 81 | - 'id' => 'espresso_event_editor_tickets', |
|
| 82 | - 'context' => 'normal' |
|
| 83 | - ) |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 88 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 89 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 90 | - * |
|
| 91 | - * @since 4.6.7 |
|
| 92 | - * |
|
| 93 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 94 | - */ |
|
| 95 | - $this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 96 | - array( |
|
| 97 | - 'date' => 'Y-m-d', |
|
| 98 | - 'time' => 'h:i a' |
|
| 99 | - )); |
|
| 100 | - |
|
| 101 | - //validate |
|
| 102 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null; |
|
| 103 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null; |
|
| 104 | - |
|
| 105 | - //validate format strings |
|
| 106 | - $format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 107 | - if (is_array($format_validation)) { |
|
| 108 | - $msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 109 | - 'event_espresso'), |
|
| 110 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>'; |
|
| 111 | - foreach ($format_validation as $error) { |
|
| 112 | - $msg .= '<li>' . $error . '</li>'; |
|
| 113 | - } |
|
| 114 | - $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 115 | - 'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>'; |
|
| 116 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 117 | - $this->_date_format_strings = array( |
|
| 118 | - 'date' => 'Y-m-d', |
|
| 119 | - 'time' => 'h:i a' |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - $this->_scripts_styles = array( |
|
| 125 | - 'registers' => array( |
|
| 126 | - 'ee-tickets-datetimes-css' => array( |
|
| 127 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 128 | - 'type' => 'css' |
|
| 129 | - ), |
|
| 130 | - 'ee-dtt-ticket-metabox' => array( |
|
| 131 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 132 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore') |
|
| 133 | - ) |
|
| 134 | - ), |
|
| 135 | - 'deregisters' => array( |
|
| 136 | - 'event-editor-css' => array('type' => 'css'), |
|
| 137 | - 'event-datetime-metabox' => array('type' => 'js') |
|
| 138 | - ), |
|
| 139 | - 'enqueues' => array( |
|
| 140 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 141 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new') |
|
| 142 | - ), |
|
| 143 | - 'localize' => array( |
|
| 144 | - 'ee-dtt-ticket-metabox' => array( |
|
| 145 | - 'DTT_TRASH_BLOCK' => array( |
|
| 146 | - 'main_warning' => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 147 | - 'event_espresso'), |
|
| 148 | - 'after_warning' => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 149 | - 'event_espresso'), |
|
| 150 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' . __('Cancel', |
|
| 151 | - 'event_espresso') . '</button>', |
|
| 152 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' . __('Close', |
|
| 153 | - 'event_espresso') . '</button>', |
|
| 154 | - 'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 155 | - 'event_espresso'), |
|
| 156 | - 'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 157 | - 'event_espresso'), |
|
| 158 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss', |
|
| 159 | - 'event_espresso') . '</button>' |
|
| 160 | - ), |
|
| 161 | - 'DTT_ERROR_MSG' => array( |
|
| 162 | - 'no_ticket_name' => __('General Admission', 'event_espresso'), |
|
| 163 | - 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss', |
|
| 164 | - 'event_espresso') . '</button></div>' |
|
| 165 | - ), |
|
| 166 | - 'DTT_OVERSELL_WARNING' => array( |
|
| 167 | - 'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
| 168 | - 'event_espresso'), |
|
| 169 | - 'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
| 170 | - 'event_espresso') |
|
| 171 | - ), |
|
| 172 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'], |
|
| 173 | - $this->_date_format_strings['time']), |
|
| 174 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')) |
|
| 175 | - ) |
|
| 176 | - ) |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 181 | - array($this, 'autosave_handling'), 10); |
|
| 182 | - add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 183 | - array($this, 'caf_updates'), 10); |
|
| 184 | - } |
|
| 54 | + protected function _set_hooks_properties() |
|
| 55 | + { |
|
| 56 | + $this->_name = 'pricing'; |
|
| 57 | + |
|
| 58 | + //capability check |
|
| 59 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices', |
|
| 60 | + 'advanced_ticket_datetime_metabox') |
|
| 61 | + ) { |
|
| 62 | + return; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + //if we were going to add our own metaboxes we'd use the below. |
|
| 67 | + $this->_metaboxes = array( |
|
| 68 | + 0 => array( |
|
| 69 | + 'page_route' => array('edit', 'create_new'), |
|
| 70 | + 'func' => 'pricing_metabox', |
|
| 71 | + 'label' => __('Event Tickets & Datetimes', 'event_espresso'), |
|
| 72 | + 'priority' => 'high', |
|
| 73 | + 'context' => 'normal' |
|
| 74 | + ), |
|
| 75 | + |
|
| 76 | + );/**/ |
|
| 77 | + |
|
| 78 | + $this->_remove_metaboxes = array( |
|
| 79 | + 0 => array( |
|
| 80 | + 'page_route' => array('edit', 'create_new'), |
|
| 81 | + 'id' => 'espresso_event_editor_tickets', |
|
| 82 | + 'context' => 'normal' |
|
| 83 | + ) |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 88 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 89 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 90 | + * |
|
| 91 | + * @since 4.6.7 |
|
| 92 | + * |
|
| 93 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 94 | + */ |
|
| 95 | + $this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 96 | + array( |
|
| 97 | + 'date' => 'Y-m-d', |
|
| 98 | + 'time' => 'h:i a' |
|
| 99 | + )); |
|
| 100 | + |
|
| 101 | + //validate |
|
| 102 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null; |
|
| 103 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null; |
|
| 104 | + |
|
| 105 | + //validate format strings |
|
| 106 | + $format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 107 | + if (is_array($format_validation)) { |
|
| 108 | + $msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 109 | + 'event_espresso'), |
|
| 110 | + $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>'; |
|
| 111 | + foreach ($format_validation as $error) { |
|
| 112 | + $msg .= '<li>' . $error . '</li>'; |
|
| 113 | + } |
|
| 114 | + $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 115 | + 'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>'; |
|
| 116 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 117 | + $this->_date_format_strings = array( |
|
| 118 | + 'date' => 'Y-m-d', |
|
| 119 | + 'time' => 'h:i a' |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + $this->_scripts_styles = array( |
|
| 125 | + 'registers' => array( |
|
| 126 | + 'ee-tickets-datetimes-css' => array( |
|
| 127 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 128 | + 'type' => 'css' |
|
| 129 | + ), |
|
| 130 | + 'ee-dtt-ticket-metabox' => array( |
|
| 131 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 132 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore') |
|
| 133 | + ) |
|
| 134 | + ), |
|
| 135 | + 'deregisters' => array( |
|
| 136 | + 'event-editor-css' => array('type' => 'css'), |
|
| 137 | + 'event-datetime-metabox' => array('type' => 'js') |
|
| 138 | + ), |
|
| 139 | + 'enqueues' => array( |
|
| 140 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 141 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new') |
|
| 142 | + ), |
|
| 143 | + 'localize' => array( |
|
| 144 | + 'ee-dtt-ticket-metabox' => array( |
|
| 145 | + 'DTT_TRASH_BLOCK' => array( |
|
| 146 | + 'main_warning' => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 147 | + 'event_espresso'), |
|
| 148 | + 'after_warning' => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 149 | + 'event_espresso'), |
|
| 150 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' . __('Cancel', |
|
| 151 | + 'event_espresso') . '</button>', |
|
| 152 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' . __('Close', |
|
| 153 | + 'event_espresso') . '</button>', |
|
| 154 | + 'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 155 | + 'event_espresso'), |
|
| 156 | + 'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 157 | + 'event_espresso'), |
|
| 158 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss', |
|
| 159 | + 'event_espresso') . '</button>' |
|
| 160 | + ), |
|
| 161 | + 'DTT_ERROR_MSG' => array( |
|
| 162 | + 'no_ticket_name' => __('General Admission', 'event_espresso'), |
|
| 163 | + 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss', |
|
| 164 | + 'event_espresso') . '</button></div>' |
|
| 165 | + ), |
|
| 166 | + 'DTT_OVERSELL_WARNING' => array( |
|
| 167 | + 'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
| 168 | + 'event_espresso'), |
|
| 169 | + 'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
| 170 | + 'event_espresso') |
|
| 171 | + ), |
|
| 172 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'], |
|
| 173 | + $this->_date_format_strings['time']), |
|
| 174 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')) |
|
| 175 | + ) |
|
| 176 | + ) |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 181 | + array($this, 'autosave_handling'), 10); |
|
| 182 | + add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 183 | + array($this, 'caf_updates'), 10); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | 186 | |
| 187 | - public function caf_updates($update_callbacks) |
|
| 188 | - { |
|
| 189 | - foreach ($update_callbacks as $key => $callback) { |
|
| 190 | - if ($callback[1] == '_default_tickets_update') { |
|
| 191 | - unset($update_callbacks[$key]); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - $update_callbacks[] = array($this, 'dtt_and_tickets_caf_update'); |
|
| 196 | - |
|
| 197 | - return $update_callbacks; |
|
| 198 | - } |
|
| 187 | + public function caf_updates($update_callbacks) |
|
| 188 | + { |
|
| 189 | + foreach ($update_callbacks as $key => $callback) { |
|
| 190 | + if ($callback[1] == '_default_tickets_update') { |
|
| 191 | + unset($update_callbacks[$key]); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + $update_callbacks[] = array($this, 'dtt_and_tickets_caf_update'); |
|
| 196 | + |
|
| 197 | + return $update_callbacks; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 203 | - * |
|
| 204 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 205 | - * @param array $data The request data from the form |
|
| 206 | - * |
|
| 207 | - * @return bool success or fail |
|
| 208 | - */ |
|
| 209 | - public function dtt_and_tickets_caf_update($evtobj, $data) |
|
| 210 | - { |
|
| 211 | - //first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 212 | - $saved_dtts = $this->_update_dtts($evtobj, $data); |
|
| 213 | - //next tackle the tickets (and prices?) |
|
| 214 | - $this->_update_tkts($evtobj, $saved_dtts, $data); |
|
| 215 | - } |
|
| 201 | + /** |
|
| 202 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 203 | + * |
|
| 204 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 205 | + * @param array $data The request data from the form |
|
| 206 | + * |
|
| 207 | + * @return bool success or fail |
|
| 208 | + */ |
|
| 209 | + public function dtt_and_tickets_caf_update($evtobj, $data) |
|
| 210 | + { |
|
| 211 | + //first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 212 | + $saved_dtts = $this->_update_dtts($evtobj, $data); |
|
| 213 | + //next tackle the tickets (and prices?) |
|
| 214 | + $this->_update_tkts($evtobj, $saved_dtts, $data); |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * update event_datetimes |
|
| 220 | - * |
|
| 221 | - * @param EE_Event $evt_obj Event being updated |
|
| 222 | - * @param array $data the request data from the form |
|
| 223 | - * |
|
| 224 | - * @return EE_Datetime[] |
|
| 225 | - */ |
|
| 226 | - protected function _update_dtts($evt_obj, $data) |
|
| 227 | - { |
|
| 228 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 229 | - $saved_dtt_ids = array(); |
|
| 230 | - $saved_dtt_objs = array(); |
|
| 231 | - |
|
| 232 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 233 | - //trim all values to ensure any excess whitespace is removed. |
|
| 234 | - $dtt = array_map( |
|
| 235 | - function ($datetime_data) { |
|
| 236 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 237 | - }, |
|
| 238 | - $dtt |
|
| 239 | - ); |
|
| 240 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start']; |
|
| 241 | - $datetime_values = array( |
|
| 242 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 243 | - 'DTT_name' => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '', |
|
| 244 | - 'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '', |
|
| 245 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 246 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 247 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 248 | - 'DTT_order' => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'], |
|
| 249 | - ); |
|
| 218 | + /** |
|
| 219 | + * update event_datetimes |
|
| 220 | + * |
|
| 221 | + * @param EE_Event $evt_obj Event being updated |
|
| 222 | + * @param array $data the request data from the form |
|
| 223 | + * |
|
| 224 | + * @return EE_Datetime[] |
|
| 225 | + */ |
|
| 226 | + protected function _update_dtts($evt_obj, $data) |
|
| 227 | + { |
|
| 228 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 229 | + $saved_dtt_ids = array(); |
|
| 230 | + $saved_dtt_objs = array(); |
|
| 231 | + |
|
| 232 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 233 | + //trim all values to ensure any excess whitespace is removed. |
|
| 234 | + $dtt = array_map( |
|
| 235 | + function ($datetime_data) { |
|
| 236 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 237 | + }, |
|
| 238 | + $dtt |
|
| 239 | + ); |
|
| 240 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start']; |
|
| 241 | + $datetime_values = array( |
|
| 242 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 243 | + 'DTT_name' => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '', |
|
| 244 | + 'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '', |
|
| 245 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 246 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 247 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 248 | + 'DTT_order' => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'], |
|
| 249 | + ); |
|
| 250 | 250 | |
| 251 | - //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 251 | + //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 252 | 252 | |
| 253 | - if ( ! empty($dtt['DTT_ID'])) { |
|
| 254 | - $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']); |
|
| 253 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 254 | + $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']); |
|
| 255 | 255 | |
| 256 | - //set date and time format according to what is set in this class. |
|
| 257 | - $DTM->set_date_format($this->_date_format_strings['date']); |
|
| 258 | - $DTM->set_time_format($this->_date_format_strings['time']); |
|
| 256 | + //set date and time format according to what is set in this class. |
|
| 257 | + $DTM->set_date_format($this->_date_format_strings['date']); |
|
| 258 | + $DTM->set_time_format($this->_date_format_strings['time']); |
|
| 259 | 259 | |
| 260 | - foreach ($datetime_values as $field => $value) { |
|
| 261 | - $DTM->set($field, $value); |
|
| 262 | - } |
|
| 260 | + foreach ($datetime_values as $field => $value) { |
|
| 261 | + $DTM->set($field, $value); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. |
|
| 265 | - // We need to do this so we dont' TRASH the parent DTT.(save the ID for both key and value to avoid duplications) |
|
| 266 | - $saved_dtt_ids[$DTM->ID()] = $DTM->ID(); |
|
| 264 | + // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. |
|
| 265 | + // We need to do this so we dont' TRASH the parent DTT.(save the ID for both key and value to avoid duplications) |
|
| 266 | + $saved_dtt_ids[$DTM->ID()] = $DTM->ID(); |
|
| 267 | 267 | |
| 268 | - } else { |
|
| 269 | - $DTM = EE_Registry::instance()->load_class( |
|
| 270 | - 'Datetime', |
|
| 271 | - array( |
|
| 272 | - $datetime_values, |
|
| 273 | - $timezone, |
|
| 274 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 275 | - ), |
|
| 276 | - false, |
|
| 277 | - false |
|
| 278 | - ); |
|
| 268 | + } else { |
|
| 269 | + $DTM = EE_Registry::instance()->load_class( |
|
| 270 | + 'Datetime', |
|
| 271 | + array( |
|
| 272 | + $datetime_values, |
|
| 273 | + $timezone, |
|
| 274 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 275 | + ), |
|
| 276 | + false, |
|
| 277 | + false |
|
| 278 | + ); |
|
| 279 | 279 | |
| 280 | - foreach ($datetime_values as $field => $value) { |
|
| 281 | - $DTM->set($field, $value); |
|
| 282 | - } |
|
| 283 | - } |
|
| 280 | + foreach ($datetime_values as $field => $value) { |
|
| 281 | + $DTM->set($field, $value); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | 285 | |
| 286 | - $DTM->save(); |
|
| 287 | - $DTM = $evt_obj->_add_relation_to($DTM, 'Datetime'); |
|
| 288 | - $evt_obj->save(); |
|
| 286 | + $DTM->save(); |
|
| 287 | + $DTM = $evt_obj->_add_relation_to($DTM, 'Datetime'); |
|
| 288 | + $evt_obj->save(); |
|
| 289 | 289 | |
| 290 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 291 | - if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) { |
|
| 292 | - $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start')); |
|
| 293 | - $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days'); |
|
| 294 | - $DTM->save(); |
|
| 295 | - } |
|
| 290 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 291 | + if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) { |
|
| 292 | + $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start')); |
|
| 293 | + $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days'); |
|
| 294 | + $DTM->save(); |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 298 | - // because it is possible there was a new one created for the autosave. |
|
| 299 | - // (save the ID for both key and value to avoid duplications) |
|
| 300 | - $saved_dtt_ids[$DTM->ID()] = $DTM->ID(); |
|
| 301 | - $saved_dtt_objs[$row] = $DTM; |
|
| 297 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 298 | + // because it is possible there was a new one created for the autosave. |
|
| 299 | + // (save the ID for both key and value to avoid duplications) |
|
| 300 | + $saved_dtt_ids[$DTM->ID()] = $DTM->ID(); |
|
| 301 | + $saved_dtt_objs[$row] = $DTM; |
|
| 302 | 302 | |
| 303 | - //todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - //now we need to REMOVE any dtts that got deleted. Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point. |
|
| 307 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 308 | - $old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes; |
|
| 309 | - |
|
| 310 | - if (is_array($old_datetimes)) { |
|
| 311 | - $dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 312 | - foreach ($dtts_to_delete as $id) { |
|
| 313 | - $id = absint($id); |
|
| 314 | - if (empty($id)) { |
|
| 315 | - continue; |
|
| 316 | - } |
|
| 303 | + //todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + //now we need to REMOVE any dtts that got deleted. Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point. |
|
| 307 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 308 | + $old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes; |
|
| 309 | + |
|
| 310 | + if (is_array($old_datetimes)) { |
|
| 311 | + $dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 312 | + foreach ($dtts_to_delete as $id) { |
|
| 313 | + $id = absint($id); |
|
| 314 | + if (empty($id)) { |
|
| 315 | + continue; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 318 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 319 | 319 | |
| 320 | - //remove tkt relationships. |
|
| 321 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 322 | - foreach ($related_tickets as $tkt) { |
|
| 323 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 324 | - } |
|
| 320 | + //remove tkt relationships. |
|
| 321 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 322 | + foreach ($related_tickets as $tkt) { |
|
| 323 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - $evt_obj->_remove_relation_to($id, 'Datetime'); |
|
| 327 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 326 | + $evt_obj->_remove_relation_to($id, 'Datetime'); |
|
| 327 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 328 | 328 | |
| 329 | - } |
|
| 330 | - } |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - return $saved_dtt_objs; |
|
| 333 | - } |
|
| 332 | + return $saved_dtt_objs; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * update tickets |
|
| 338 | - * |
|
| 339 | - * @param EE_Event $evtobj Event object being updated |
|
| 340 | - * @param EE_Datetime[] $saved_dtts an array of datetime ids being updated |
|
| 341 | - * @param array $data incoming request data |
|
| 342 | - * |
|
| 343 | - * @return EE_Ticket[] |
|
| 344 | - */ |
|
| 345 | - protected function _update_tkts($evtobj, $saved_dtts, $data) |
|
| 346 | - { |
|
| 347 | - |
|
| 348 | - $new_tkt = null; |
|
| 349 | - $new_default = null; |
|
| 350 | - //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 351 | - $data = stripslashes_deep($data); |
|
| 352 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 353 | - $saved_tickets = $dtts_on_existing = array(); |
|
| 354 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 355 | - |
|
| 356 | - //load money helper |
|
| 357 | - |
|
| 358 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 336 | + /** |
|
| 337 | + * update tickets |
|
| 338 | + * |
|
| 339 | + * @param EE_Event $evtobj Event object being updated |
|
| 340 | + * @param EE_Datetime[] $saved_dtts an array of datetime ids being updated |
|
| 341 | + * @param array $data incoming request data |
|
| 342 | + * |
|
| 343 | + * @return EE_Ticket[] |
|
| 344 | + */ |
|
| 345 | + protected function _update_tkts($evtobj, $saved_dtts, $data) |
|
| 346 | + { |
|
| 347 | + |
|
| 348 | + $new_tkt = null; |
|
| 349 | + $new_default = null; |
|
| 350 | + //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 351 | + $data = stripslashes_deep($data); |
|
| 352 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 353 | + $saved_tickets = $dtts_on_existing = array(); |
|
| 354 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 355 | + |
|
| 356 | + //load money helper |
|
| 357 | + |
|
| 358 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 359 | 359 | |
| 360 | - $update_prices = $create_new_TKT = false; |
|
| 360 | + $update_prices = $create_new_TKT = false; |
|
| 361 | 361 | |
| 362 | - //figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session. |
|
| 362 | + //figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session. |
|
| 363 | 363 | |
| 364 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
| 365 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
| 366 | - $dtts_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 367 | - $dtts_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 364 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
| 365 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
| 366 | + $dtts_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 367 | + $dtts_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 368 | 368 | |
| 369 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 370 | - $tkt = array_map( |
|
| 371 | - function ($ticket_data) { |
|
| 372 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 373 | - }, |
|
| 374 | - $tkt |
|
| 375 | - ); |
|
| 369 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 370 | + $tkt = array_map( |
|
| 371 | + function ($ticket_data) { |
|
| 372 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 373 | + }, |
|
| 374 | + $tkt |
|
| 375 | + ); |
|
| 376 | 376 | |
| 377 | - //note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models. |
|
| 378 | - //note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 379 | - $ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0; |
|
| 377 | + //note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models. |
|
| 378 | + //note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 379 | + $ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0; |
|
| 380 | 380 | |
| 381 | - //note incoming base price needs converted from localized value. |
|
| 382 | - $base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0; |
|
| 383 | - //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 384 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price; |
|
| 385 | - $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0; |
|
| 381 | + //note incoming base price needs converted from localized value. |
|
| 382 | + $base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0; |
|
| 383 | + //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 384 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price; |
|
| 385 | + $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0; |
|
| 386 | 386 | |
| 387 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array(); |
|
| 387 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array(); |
|
| 388 | 388 | |
| 389 | - $now = null; |
|
| 390 | - if (empty($tkt['TKT_start_date'])) { |
|
| 391 | - //lets' use now in the set timezone. |
|
| 392 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 393 | - $tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 394 | - } |
|
| 389 | + $now = null; |
|
| 390 | + if (empty($tkt['TKT_start_date'])) { |
|
| 391 | + //lets' use now in the set timezone. |
|
| 392 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 393 | + $tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - if (empty($tkt['TKT_end_date'])) { |
|
| 397 | - /** |
|
| 398 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 399 | - */ |
|
| 400 | - $first_dtt = $saved_dtts[reset($tkt_dtt_rows)]; |
|
| 401 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']); |
|
| 402 | - } |
|
| 396 | + if (empty($tkt['TKT_end_date'])) { |
|
| 397 | + /** |
|
| 398 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 399 | + */ |
|
| 400 | + $first_dtt = $saved_dtts[reset($tkt_dtt_rows)]; |
|
| 401 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']); |
|
| 402 | + } |
|
| 403 | 403 | |
| 404 | - $TKT_values = array( |
|
| 405 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 406 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 407 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 408 | - 'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description', |
|
| 409 | - 'event_espresso') ? $tkt['TKT_description'] : '', |
|
| 410 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 411 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 412 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 413 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 414 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 415 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 416 | - 'TKT_row' => $row, |
|
| 417 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
| 418 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 419 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 420 | - 'TKT_price' => $ticket_price |
|
| 421 | - ); |
|
| 404 | + $TKT_values = array( |
|
| 405 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 406 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 407 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 408 | + 'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description', |
|
| 409 | + 'event_espresso') ? $tkt['TKT_description'] : '', |
|
| 410 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 411 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 412 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 413 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 414 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 415 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 416 | + 'TKT_row' => $row, |
|
| 417 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
| 418 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 419 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 420 | + 'TKT_price' => $ticket_price |
|
| 421 | + ); |
|
| 422 | 422 | |
| 423 | 423 | |
| 424 | - //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 425 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 426 | - $TKT_values['TKT_ID'] = 0; |
|
| 427 | - $TKT_values['TKT_is_default'] = 0; |
|
| 428 | - $update_prices = true; |
|
| 429 | - } |
|
| 424 | + //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 425 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 426 | + $TKT_values['TKT_ID'] = 0; |
|
| 427 | + $TKT_values['TKT_is_default'] = 0; |
|
| 428 | + $update_prices = true; |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 432 | - // we actually do our saves ahead of doing any add_relations to |
|
| 433 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 434 | - // but DID have it's items modified. |
|
| 435 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 436 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 437 | - if (absint($TKT_values['TKT_ID'])) { |
|
| 438 | - $TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']); |
|
| 439 | - if ($TKT instanceof EE_Ticket) { |
|
| 431 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 432 | + // we actually do our saves ahead of doing any add_relations to |
|
| 433 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 434 | + // but DID have it's items modified. |
|
| 435 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 436 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 437 | + if (absint($TKT_values['TKT_ID'])) { |
|
| 438 | + $TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']); |
|
| 439 | + if ($TKT instanceof EE_Ticket) { |
|
| 440 | 440 | |
| 441 | - $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed); |
|
| 442 | - // are there any registrations using this ticket ? |
|
| 443 | - $tickets_sold = $TKT->count_related( |
|
| 444 | - 'Registration', |
|
| 445 | - array( |
|
| 446 | - array( |
|
| 447 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)) |
|
| 448 | - ) |
|
| 449 | - ) |
|
| 450 | - ); |
|
| 451 | - //set ticket formats |
|
| 452 | - $TKT->set_date_format($this->_date_format_strings['date']); |
|
| 453 | - $TKT->set_time_format($this->_date_format_strings['time']); |
|
| 441 | + $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed); |
|
| 442 | + // are there any registrations using this ticket ? |
|
| 443 | + $tickets_sold = $TKT->count_related( |
|
| 444 | + 'Registration', |
|
| 445 | + array( |
|
| 446 | + array( |
|
| 447 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)) |
|
| 448 | + ) |
|
| 449 | + ) |
|
| 450 | + ); |
|
| 451 | + //set ticket formats |
|
| 452 | + $TKT->set_date_format($this->_date_format_strings['date']); |
|
| 453 | + $TKT->set_time_format($this->_date_format_strings['time']); |
|
| 454 | 454 | |
| 455 | - // let's just check the total price for the existing ticket |
|
| 456 | - // and determine if it matches the new total price. |
|
| 457 | - // if they are different then we create a new ticket (if tkts sold) |
|
| 458 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 459 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price != $TKT->price() && ! $TKT->deleted() |
|
| 460 | - ? true : false; |
|
| 455 | + // let's just check the total price for the existing ticket |
|
| 456 | + // and determine if it matches the new total price. |
|
| 457 | + // if they are different then we create a new ticket (if tkts sold) |
|
| 458 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 459 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price != $TKT->price() && ! $TKT->deleted() |
|
| 460 | + ? true : false; |
|
| 461 | 461 | |
| 462 | - //set new values |
|
| 463 | - foreach ($TKT_values as $field => $value) { |
|
| 464 | - if ($field === 'TKT_qty') { |
|
| 465 | - $TKT->set_qty($value); |
|
| 466 | - } else { |
|
| 467 | - $TKT->set($field, $value); |
|
| 468 | - } |
|
| 469 | - } |
|
| 462 | + //set new values |
|
| 463 | + foreach ($TKT_values as $field => $value) { |
|
| 464 | + if ($field === 'TKT_qty') { |
|
| 465 | + $TKT->set_qty($value); |
|
| 466 | + } else { |
|
| 467 | + $TKT->set($field, $value); |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | 470 | |
| 471 | - //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 472 | - if ($create_new_TKT) { |
|
| 473 | - $new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price, |
|
| 474 | - $base_price_id); |
|
| 475 | - } |
|
| 476 | - } |
|
| 471 | + //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 472 | + if ($create_new_TKT) { |
|
| 473 | + $new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price, |
|
| 474 | + $base_price_id); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | 477 | |
| 478 | - } else { |
|
| 479 | - // no TKT_id so a new TKT |
|
| 480 | - $TKT = EE_Ticket::new_instance( |
|
| 481 | - $TKT_values, |
|
| 482 | - $timezone, |
|
| 483 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 484 | - ); |
|
| 485 | - if ($TKT instanceof EE_Ticket) { |
|
| 486 | - // make sure ticket has an ID of setting relations won't work |
|
| 487 | - $TKT->save(); |
|
| 488 | - $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed); |
|
| 489 | - $update_prices = true; |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - //make sure any current values have been saved. |
|
| 493 | - //$TKT->save(); |
|
| 478 | + } else { |
|
| 479 | + // no TKT_id so a new TKT |
|
| 480 | + $TKT = EE_Ticket::new_instance( |
|
| 481 | + $TKT_values, |
|
| 482 | + $timezone, |
|
| 483 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 484 | + ); |
|
| 485 | + if ($TKT instanceof EE_Ticket) { |
|
| 486 | + // make sure ticket has an ID of setting relations won't work |
|
| 487 | + $TKT->save(); |
|
| 488 | + $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed); |
|
| 489 | + $update_prices = true; |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + //make sure any current values have been saved. |
|
| 493 | + //$TKT->save(); |
|
| 494 | 494 | |
| 495 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 496 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 497 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 498 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 499 | - } |
|
| 495 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 496 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 497 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 498 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | - //let's make sure the base price is handled |
|
| 502 | - $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price, |
|
| 503 | - $base_price_id) : $TKT; |
|
| 501 | + //let's make sure the base price is handled |
|
| 502 | + $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price, |
|
| 503 | + $base_price_id) : $TKT; |
|
| 504 | 504 | |
| 505 | - //add/update price_modifiers |
|
| 506 | - $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT; |
|
| 505 | + //add/update price_modifiers |
|
| 506 | + $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT; |
|
| 507 | 507 | |
| 508 | - //need to make sue that the TKT_price is accurate after saving the prices. |
|
| 509 | - $TKT->ensure_TKT_Price_correct(); |
|
| 508 | + //need to make sue that the TKT_price is accurate after saving the prices. |
|
| 509 | + $TKT->ensure_TKT_Price_correct(); |
|
| 510 | 510 | |
| 511 | - //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 512 | - if ( ! defined('DOING_AUTOSAVE')) { |
|
| 513 | - if ( ! empty($tkt['TKT_is_default_selector'])) { |
|
| 514 | - $update_prices = true; |
|
| 515 | - $new_default = clone $TKT; |
|
| 516 | - $new_default->set('TKT_ID', 0); |
|
| 517 | - $new_default->set('TKT_is_default', 1); |
|
| 518 | - $new_default->set('TKT_row', 1); |
|
| 519 | - $new_default->set('TKT_price', $ticket_price); |
|
| 520 | - //remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object) |
|
| 521 | - $new_default->_remove_relations('Datetime'); |
|
| 522 | - //todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 523 | - $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
| 524 | - //don't forget the base price! |
|
| 525 | - $new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price, |
|
| 526 | - $base_price_id); |
|
| 527 | - $new_default->save(); |
|
| 528 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default, |
|
| 529 | - $row, $TKT, $data); |
|
| 530 | - } |
|
| 531 | - } |
|
| 511 | + //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 512 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
| 513 | + if ( ! empty($tkt['TKT_is_default_selector'])) { |
|
| 514 | + $update_prices = true; |
|
| 515 | + $new_default = clone $TKT; |
|
| 516 | + $new_default->set('TKT_ID', 0); |
|
| 517 | + $new_default->set('TKT_is_default', 1); |
|
| 518 | + $new_default->set('TKT_row', 1); |
|
| 519 | + $new_default->set('TKT_price', $ticket_price); |
|
| 520 | + //remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object) |
|
| 521 | + $new_default->_remove_relations('Datetime'); |
|
| 522 | + //todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 523 | + $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
| 524 | + //don't forget the base price! |
|
| 525 | + $new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price, |
|
| 526 | + $base_price_id); |
|
| 527 | + $new_default->save(); |
|
| 528 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default, |
|
| 529 | + $row, $TKT, $data); |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | 532 | |
| 533 | 533 | |
| 534 | - //DO ALL dtt relationships for both current tickets and any archived tickets for the given dtt that are related to the current ticket. TODO... not sure exactly how we're going to do this considering we don't know what current ticket the archived tickets are related to (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 534 | + //DO ALL dtt relationships for both current tickets and any archived tickets for the given dtt that are related to the current ticket. TODO... not sure exactly how we're going to do this considering we don't know what current ticket the archived tickets are related to (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 535 | 535 | |
| 536 | 536 | |
| 537 | - //let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 538 | - //save existing TKT |
|
| 539 | - $TKT->save(); |
|
| 540 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 541 | - //save new TKT |
|
| 542 | - $new_tkt->save(); |
|
| 543 | - //add new ticket to array |
|
| 544 | - $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
| 537 | + //let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 538 | + //save existing TKT |
|
| 539 | + $TKT->save(); |
|
| 540 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 541 | + //save new TKT |
|
| 542 | + $new_tkt->save(); |
|
| 543 | + //add new ticket to array |
|
| 544 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
| 545 | 545 | |
| 546 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data); |
|
| 546 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data); |
|
| 547 | 547 | |
| 548 | - } else { |
|
| 549 | - //add tkt to saved tkts |
|
| 550 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 548 | + } else { |
|
| 549 | + //add tkt to saved tkts |
|
| 550 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 551 | 551 | |
| 552 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data); |
|
| 553 | - } |
|
| 552 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data); |
|
| 553 | + } |
|
| 554 | 554 | |
| 555 | - } |
|
| 556 | - |
|
| 557 | - // now we need to handle tickets actually "deleted permanently". |
|
| 558 | - // There are cases where we'd want this to happen |
|
| 559 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 560 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 561 | - // No sense in keeping all the related data in the db! |
|
| 562 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 563 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 564 | - |
|
| 565 | - foreach ($tickets_removed as $id) { |
|
| 566 | - $id = absint($id); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + // now we need to handle tickets actually "deleted permanently". |
|
| 558 | + // There are cases where we'd want this to happen |
|
| 559 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 560 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 561 | + // No sense in keeping all the related data in the db! |
|
| 562 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 563 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 564 | + |
|
| 565 | + foreach ($tickets_removed as $id) { |
|
| 566 | + $id = absint($id); |
|
| 567 | 567 | |
| 568 | - //get the ticket for this id |
|
| 569 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 568 | + //get the ticket for this id |
|
| 569 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 570 | 570 | |
| 571 | - //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 572 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 573 | - continue; |
|
| 574 | - } |
|
| 571 | + //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 572 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 573 | + continue; |
|
| 574 | + } |
|
| 575 | 575 | |
| 576 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 577 | - // because we don't actually permanently delete these tickets. |
|
| 578 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 579 | - $tkt_to_remove->delete(); |
|
| 580 | - continue; |
|
| 581 | - } |
|
| 576 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 577 | + // because we don't actually permanently delete these tickets. |
|
| 578 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 579 | + $tkt_to_remove->delete(); |
|
| 580 | + continue; |
|
| 581 | + } |
|
| 582 | 582 | |
| 583 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 584 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 585 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 583 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 584 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 585 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 586 | 586 | |
| 587 | - foreach ($dtts as $dtt) { |
|
| 588 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 589 | - } |
|
| 587 | + foreach ($dtts as $dtt) { |
|
| 588 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 589 | + } |
|
| 590 | 590 | |
| 591 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
| 592 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 593 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 591 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
| 592 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 593 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 594 | 594 | |
| 595 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 595 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 596 | 596 | |
| 597 | - // finally let's delete this ticket |
|
| 598 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 599 | - $tkt_to_remove->delete_permanently(); |
|
| 600 | - } |
|
| 597 | + // finally let's delete this ticket |
|
| 598 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 599 | + $tkt_to_remove->delete_permanently(); |
|
| 600 | + } |
|
| 601 | 601 | |
| 602 | - return $saved_tickets; |
|
| 603 | - } |
|
| 602 | + return $saved_tickets; |
|
| 603 | + } |
|
| 604 | 604 | |
| 605 | 605 | |
| 606 | - /** |
|
| 607 | - * |
|
| 608 | - * @access protected |
|
| 609 | - * |
|
| 610 | - * @param \EE_Ticket $ticket |
|
| 611 | - * @param \EE_Datetime[] $saved_datetimes |
|
| 612 | - * @param \EE_Datetime[] $added_datetimes |
|
| 613 | - * @param \EE_Datetime[] $removed_datetimes |
|
| 614 | - * |
|
| 615 | - * @return \EE_Ticket |
|
| 616 | - * @throws \EE_Error |
|
| 617 | - */ |
|
| 618 | - protected function _update_ticket_datetimes( |
|
| 619 | - EE_Ticket $ticket, |
|
| 620 | - $saved_datetimes = array(), |
|
| 621 | - $added_datetimes = array(), |
|
| 622 | - $removed_datetimes = array() |
|
| 623 | - ) { |
|
| 624 | - |
|
| 625 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 626 | - // and removing the ticket from datetimes it got removed from. |
|
| 627 | - |
|
| 628 | - // first let's add datetimes |
|
| 629 | - if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 630 | - foreach ($added_datetimes as $row_id) { |
|
| 631 | - $row_id = (int)$row_id; |
|
| 632 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 633 | - $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 634 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 635 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 636 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 637 | - $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
| 638 | - $saved_datetimes[$row_id]->save(); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - // then remove datetimes |
|
| 644 | - if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 645 | - foreach ($removed_datetimes as $row_id) { |
|
| 646 | - $row_id = (int)$row_id; |
|
| 647 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 648 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 649 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 650 | - $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 651 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 652 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
| 653 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 654 | - $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
| 655 | - $saved_datetimes[$row_id]->save(); |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - } |
|
| 659 | - } |
|
| 660 | - // cap ticket qty by datetime reg limits |
|
| 661 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 662 | - |
|
| 663 | - return $ticket; |
|
| 664 | - } |
|
| 606 | + /** |
|
| 607 | + * |
|
| 608 | + * @access protected |
|
| 609 | + * |
|
| 610 | + * @param \EE_Ticket $ticket |
|
| 611 | + * @param \EE_Datetime[] $saved_datetimes |
|
| 612 | + * @param \EE_Datetime[] $added_datetimes |
|
| 613 | + * @param \EE_Datetime[] $removed_datetimes |
|
| 614 | + * |
|
| 615 | + * @return \EE_Ticket |
|
| 616 | + * @throws \EE_Error |
|
| 617 | + */ |
|
| 618 | + protected function _update_ticket_datetimes( |
|
| 619 | + EE_Ticket $ticket, |
|
| 620 | + $saved_datetimes = array(), |
|
| 621 | + $added_datetimes = array(), |
|
| 622 | + $removed_datetimes = array() |
|
| 623 | + ) { |
|
| 624 | + |
|
| 625 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 626 | + // and removing the ticket from datetimes it got removed from. |
|
| 627 | + |
|
| 628 | + // first let's add datetimes |
|
| 629 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 630 | + foreach ($added_datetimes as $row_id) { |
|
| 631 | + $row_id = (int)$row_id; |
|
| 632 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 633 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 634 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 635 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 636 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 637 | + $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
| 638 | + $saved_datetimes[$row_id]->save(); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + // then remove datetimes |
|
| 644 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 645 | + foreach ($removed_datetimes as $row_id) { |
|
| 646 | + $row_id = (int)$row_id; |
|
| 647 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 648 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 649 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 650 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 651 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 652 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
| 653 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 654 | + $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
| 655 | + $saved_datetimes[$row_id]->save(); |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + } |
|
| 659 | + } |
|
| 660 | + // cap ticket qty by datetime reg limits |
|
| 661 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 662 | + |
|
| 663 | + return $ticket; |
|
| 664 | + } |
|
| 665 | 665 | |
| 666 | 666 | |
| 667 | - /** |
|
| 668 | - * |
|
| 669 | - * @access protected |
|
| 670 | - * |
|
| 671 | - * @param \EE_Ticket $ticket |
|
| 672 | - * @param array $price_rows |
|
| 673 | - * @param int $ticket_price |
|
| 674 | - * @param int $base_price |
|
| 675 | - * @param int $base_price_id |
|
| 676 | - * |
|
| 677 | - * @return \EE_Ticket |
|
| 678 | - * @throws \EE_Error |
|
| 679 | - */ |
|
| 680 | - protected function _duplicate_ticket( |
|
| 681 | - EE_Ticket $ticket, |
|
| 682 | - $price_rows = array(), |
|
| 683 | - $ticket_price = 0, |
|
| 684 | - $base_price = 0, |
|
| 685 | - $base_price_id = 0 |
|
| 686 | - ) { |
|
| 687 | - |
|
| 688 | - // create new ticket that's a copy of the existing |
|
| 689 | - // except a new id of course (and not archived) |
|
| 690 | - // AND has the new TKT_price associated with it. |
|
| 691 | - $new_ticket = clone $ticket; |
|
| 692 | - $new_ticket->set('TKT_ID', 0); |
|
| 693 | - $new_ticket->set('TKT_deleted', 0); |
|
| 694 | - $new_ticket->set('TKT_price', $ticket_price); |
|
| 695 | - $new_ticket->set('TKT_sold', 0); |
|
| 696 | - // let's get a new ID for this ticket |
|
| 697 | - $new_ticket->save(); |
|
| 698 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 699 | - $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
| 700 | - $new_ticket = $this->_update_ticket_datetimes( |
|
| 701 | - $new_ticket, |
|
| 702 | - $datetimes_on_existing, |
|
| 703 | - array_keys($datetimes_on_existing) |
|
| 704 | - ); |
|
| 705 | - |
|
| 706 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 707 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 708 | - // available. |
|
| 709 | - if ($ticket->sold() > 0) { |
|
| 710 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 711 | - $new_ticket->set_qty($new_qty); |
|
| 712 | - } |
|
| 713 | - //now we update the prices just for this ticket |
|
| 714 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 715 | - //and we update the base price |
|
| 716 | - $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
| 717 | - |
|
| 718 | - return $new_ticket; |
|
| 719 | - } |
|
| 667 | + /** |
|
| 668 | + * |
|
| 669 | + * @access protected |
|
| 670 | + * |
|
| 671 | + * @param \EE_Ticket $ticket |
|
| 672 | + * @param array $price_rows |
|
| 673 | + * @param int $ticket_price |
|
| 674 | + * @param int $base_price |
|
| 675 | + * @param int $base_price_id |
|
| 676 | + * |
|
| 677 | + * @return \EE_Ticket |
|
| 678 | + * @throws \EE_Error |
|
| 679 | + */ |
|
| 680 | + protected function _duplicate_ticket( |
|
| 681 | + EE_Ticket $ticket, |
|
| 682 | + $price_rows = array(), |
|
| 683 | + $ticket_price = 0, |
|
| 684 | + $base_price = 0, |
|
| 685 | + $base_price_id = 0 |
|
| 686 | + ) { |
|
| 687 | + |
|
| 688 | + // create new ticket that's a copy of the existing |
|
| 689 | + // except a new id of course (and not archived) |
|
| 690 | + // AND has the new TKT_price associated with it. |
|
| 691 | + $new_ticket = clone $ticket; |
|
| 692 | + $new_ticket->set('TKT_ID', 0); |
|
| 693 | + $new_ticket->set('TKT_deleted', 0); |
|
| 694 | + $new_ticket->set('TKT_price', $ticket_price); |
|
| 695 | + $new_ticket->set('TKT_sold', 0); |
|
| 696 | + // let's get a new ID for this ticket |
|
| 697 | + $new_ticket->save(); |
|
| 698 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 699 | + $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
| 700 | + $new_ticket = $this->_update_ticket_datetimes( |
|
| 701 | + $new_ticket, |
|
| 702 | + $datetimes_on_existing, |
|
| 703 | + array_keys($datetimes_on_existing) |
|
| 704 | + ); |
|
| 705 | + |
|
| 706 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 707 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 708 | + // available. |
|
| 709 | + if ($ticket->sold() > 0) { |
|
| 710 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 711 | + $new_ticket->set_qty($new_qty); |
|
| 712 | + } |
|
| 713 | + //now we update the prices just for this ticket |
|
| 714 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 715 | + //and we update the base price |
|
| 716 | + $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
| 717 | + |
|
| 718 | + return $new_ticket; |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | 721 | |
| 722 | - /** |
|
| 723 | - * This attaches a list of given prices to a ticket. |
|
| 724 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 725 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 726 | - * price info and prices are automatically "archived" via the ticket. |
|
| 727 | - * |
|
| 728 | - * @access private |
|
| 729 | - * |
|
| 730 | - * @param array $prices Array of prices from the form. |
|
| 731 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 732 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 733 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 734 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 735 | - * |
|
| 736 | - * @return EE_Ticket |
|
| 737 | - */ |
|
| 738 | - protected function _add_prices_to_ticket( |
|
| 739 | - $prices = array(), |
|
| 740 | - EE_Ticket $ticket, |
|
| 741 | - $new_prices = false, |
|
| 742 | - $base_price = false, |
|
| 743 | - $base_price_id = false |
|
| 744 | - ) { |
|
| 745 | - |
|
| 746 | - //let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session. |
|
| 747 | - $current_prices_on_ticket = $base_price !== false ? $ticket->base_price(true) : $ticket->price_modifiers(); |
|
| 748 | - |
|
| 749 | - $updated_prices = array(); |
|
| 750 | - |
|
| 751 | - // if $base_price ! FALSE then updating a base price. |
|
| 752 | - if ($base_price !== false) { |
|
| 753 | - $prices[1] = array( |
|
| 754 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 755 | - 'PRT_ID' => 1, |
|
| 756 | - 'PRC_amount' => $base_price, |
|
| 757 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
| 758 | - 'PRC_desc' => $ticket->get('TKT_description') |
|
| 759 | - ); |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - //possibly need to save tkt |
|
| 763 | - if ( ! $ticket->ID()) { |
|
| 764 | - $ticket->save(); |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - foreach ($prices as $row => $prc) { |
|
| 768 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 769 | - if (empty($prt_id)) { |
|
| 770 | - continue; |
|
| 771 | - } //prices MUST have a price type id. |
|
| 772 | - $PRC_values = array( |
|
| 773 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 774 | - 'PRT_ID' => $prt_id, |
|
| 775 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 776 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 777 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 778 | - 'PRC_is_default' => false, |
|
| 779 | - //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 780 | - 'PRC_order' => $row |
|
| 781 | - ); |
|
| 782 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 783 | - $PRC_values['PRC_ID'] = 0; |
|
| 784 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 785 | - } else { |
|
| 786 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 787 | - //update this price with new values |
|
| 788 | - foreach ($PRC_values as $field => $newprc) { |
|
| 789 | - $PRC->set($field, $newprc); |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - $PRC->save(); |
|
| 793 | - $prcid = $PRC->ID(); |
|
| 794 | - $updated_prices[$prcid] = $PRC; |
|
| 795 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - //now let's remove any prices that got removed from the ticket |
|
| 799 | - if ( ! empty ($current_prices_on_ticket)) { |
|
| 800 | - $current = array_keys($current_prices_on_ticket); |
|
| 801 | - $updated = array_keys($updated_prices); |
|
| 802 | - $prices_to_remove = array_diff($current, $updated); |
|
| 803 | - if ( ! empty($prices_to_remove)) { |
|
| 804 | - foreach ($prices_to_remove as $prc_id) { |
|
| 805 | - $p = $current_prices_on_ticket[$prc_id]; |
|
| 806 | - $ticket->_remove_relation_to($p, 'Price'); |
|
| 722 | + /** |
|
| 723 | + * This attaches a list of given prices to a ticket. |
|
| 724 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 725 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 726 | + * price info and prices are automatically "archived" via the ticket. |
|
| 727 | + * |
|
| 728 | + * @access private |
|
| 729 | + * |
|
| 730 | + * @param array $prices Array of prices from the form. |
|
| 731 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 732 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 733 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 734 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 735 | + * |
|
| 736 | + * @return EE_Ticket |
|
| 737 | + */ |
|
| 738 | + protected function _add_prices_to_ticket( |
|
| 739 | + $prices = array(), |
|
| 740 | + EE_Ticket $ticket, |
|
| 741 | + $new_prices = false, |
|
| 742 | + $base_price = false, |
|
| 743 | + $base_price_id = false |
|
| 744 | + ) { |
|
| 745 | + |
|
| 746 | + //let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session. |
|
| 747 | + $current_prices_on_ticket = $base_price !== false ? $ticket->base_price(true) : $ticket->price_modifiers(); |
|
| 748 | + |
|
| 749 | + $updated_prices = array(); |
|
| 750 | + |
|
| 751 | + // if $base_price ! FALSE then updating a base price. |
|
| 752 | + if ($base_price !== false) { |
|
| 753 | + $prices[1] = array( |
|
| 754 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 755 | + 'PRT_ID' => 1, |
|
| 756 | + 'PRC_amount' => $base_price, |
|
| 757 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
| 758 | + 'PRC_desc' => $ticket->get('TKT_description') |
|
| 759 | + ); |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + //possibly need to save tkt |
|
| 763 | + if ( ! $ticket->ID()) { |
|
| 764 | + $ticket->save(); |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + foreach ($prices as $row => $prc) { |
|
| 768 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 769 | + if (empty($prt_id)) { |
|
| 770 | + continue; |
|
| 771 | + } //prices MUST have a price type id. |
|
| 772 | + $PRC_values = array( |
|
| 773 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 774 | + 'PRT_ID' => $prt_id, |
|
| 775 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 776 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 777 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 778 | + 'PRC_is_default' => false, |
|
| 779 | + //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 780 | + 'PRC_order' => $row |
|
| 781 | + ); |
|
| 782 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 783 | + $PRC_values['PRC_ID'] = 0; |
|
| 784 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 785 | + } else { |
|
| 786 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 787 | + //update this price with new values |
|
| 788 | + foreach ($PRC_values as $field => $newprc) { |
|
| 789 | + $PRC->set($field, $newprc); |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + $PRC->save(); |
|
| 793 | + $prcid = $PRC->ID(); |
|
| 794 | + $updated_prices[$prcid] = $PRC; |
|
| 795 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + //now let's remove any prices that got removed from the ticket |
|
| 799 | + if ( ! empty ($current_prices_on_ticket)) { |
|
| 800 | + $current = array_keys($current_prices_on_ticket); |
|
| 801 | + $updated = array_keys($updated_prices); |
|
| 802 | + $prices_to_remove = array_diff($current, $updated); |
|
| 803 | + if ( ! empty($prices_to_remove)) { |
|
| 804 | + foreach ($prices_to_remove as $prc_id) { |
|
| 805 | + $p = $current_prices_on_ticket[$prc_id]; |
|
| 806 | + $ticket->_remove_relation_to($p, 'Price'); |
|
| 807 | 807 | |
| 808 | - //delete permanently the price |
|
| 809 | - $p->delete_permanently(); |
|
| 810 | - } |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - return $ticket; |
|
| 815 | - } |
|
| 808 | + //delete permanently the price |
|
| 809 | + $p->delete_permanently(); |
|
| 810 | + } |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + return $ticket; |
|
| 815 | + } |
|
| 816 | 816 | |
| 817 | 817 | |
| 818 | - public function autosave_handling($event_admin_obj) |
|
| 819 | - { |
|
| 820 | - return $event_admin_obj; //doing nothing for the moment. |
|
| 821 | - //todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method) |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 825 | - * |
|
| 826 | - * 1. TKT_is_default_selector (visible) |
|
| 827 | - * 2. TKT_is_default (hidden) |
|
| 828 | - * |
|
| 829 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want this ticket to be saved as a default. |
|
| 830 | - * |
|
| 831 | - * The tricky part is, on an initial display on create or edit (or after manually updating), the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true if this is a create. However, after an autosave, users will want some sort of indicator that the TKT HAS been saved as a default.. in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 832 | - * On Autosave: |
|
| 833 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, then set the TKT_is_default to false. |
|
| 834 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 835 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 836 | - */ |
|
| 837 | - } |
|
| 818 | + public function autosave_handling($event_admin_obj) |
|
| 819 | + { |
|
| 820 | + return $event_admin_obj; //doing nothing for the moment. |
|
| 821 | + //todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method) |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 825 | + * |
|
| 826 | + * 1. TKT_is_default_selector (visible) |
|
| 827 | + * 2. TKT_is_default (hidden) |
|
| 828 | + * |
|
| 829 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want this ticket to be saved as a default. |
|
| 830 | + * |
|
| 831 | + * The tricky part is, on an initial display on create or edit (or after manually updating), the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true if this is a create. However, after an autosave, users will want some sort of indicator that the TKT HAS been saved as a default.. in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 832 | + * On Autosave: |
|
| 833 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, then set the TKT_is_default to false. |
|
| 834 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 835 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 836 | + */ |
|
| 837 | + } |
|
| 838 | 838 | |
| 839 | 839 | |
| 840 | - public function pricing_metabox() |
|
| 841 | - { |
|
| 842 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 843 | - |
|
| 844 | - $evtobj = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 845 | - |
|
| 846 | - //set is_creating_event property. |
|
| 847 | - $evtID = $evtobj->ID(); |
|
| 848 | - $this->_is_creating_event = absint($evtID) != 0 ? false : true; |
|
| 849 | - |
|
| 850 | - //default main template args |
|
| 851 | - $main_template_args = array( |
|
| 852 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab', |
|
| 853 | - $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 854 | - //todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help |
|
| 855 | - 'existing_datetime_ids' => '', |
|
| 856 | - 'total_dtt_rows' => 1, |
|
| 857 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link('add_new_dtt_info', |
|
| 858 | - $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 859 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 860 | - 'datetime_rows' => '', |
|
| 861 | - 'show_tickets_container' => '', |
|
| 862 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 863 | - 'ticket_rows' => '', |
|
| 864 | - 'existing_ticket_ids' => '', |
|
| 865 | - 'total_ticket_rows' => 1, |
|
| 866 | - 'ticket_js_structure' => '', |
|
| 867 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 868 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 869 | - ); |
|
| 870 | - |
|
| 871 | - $timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : null; |
|
| 872 | - |
|
| 873 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * 1. Start with retrieving Datetimes |
|
| 877 | - * 2. For each datetime get related tickets |
|
| 878 | - * 3. For each ticket get related prices |
|
| 879 | - */ |
|
| 880 | - |
|
| 881 | - $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 882 | - $times = $DTM->get_all_event_dates($evtID); |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - $main_template_args['total_dtt_rows'] = count($times); |
|
| 886 | - |
|
| 887 | - /** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */ |
|
| 888 | - $dttrow = 1; |
|
| 889 | - foreach ($times as $time) { |
|
| 890 | - $dttid = $time->get('DTT_ID'); |
|
| 891 | - $time->set('DTT_order', $dttrow); |
|
| 892 | - $existing_datetime_ids[] = $dttid; |
|
| 840 | + public function pricing_metabox() |
|
| 841 | + { |
|
| 842 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 843 | + |
|
| 844 | + $evtobj = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 845 | + |
|
| 846 | + //set is_creating_event property. |
|
| 847 | + $evtID = $evtobj->ID(); |
|
| 848 | + $this->_is_creating_event = absint($evtID) != 0 ? false : true; |
|
| 849 | + |
|
| 850 | + //default main template args |
|
| 851 | + $main_template_args = array( |
|
| 852 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab', |
|
| 853 | + $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 854 | + //todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help |
|
| 855 | + 'existing_datetime_ids' => '', |
|
| 856 | + 'total_dtt_rows' => 1, |
|
| 857 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link('add_new_dtt_info', |
|
| 858 | + $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 859 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 860 | + 'datetime_rows' => '', |
|
| 861 | + 'show_tickets_container' => '', |
|
| 862 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 863 | + 'ticket_rows' => '', |
|
| 864 | + 'existing_ticket_ids' => '', |
|
| 865 | + 'total_ticket_rows' => 1, |
|
| 866 | + 'ticket_js_structure' => '', |
|
| 867 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 868 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 869 | + ); |
|
| 870 | + |
|
| 871 | + $timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : null; |
|
| 872 | + |
|
| 873 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * 1. Start with retrieving Datetimes |
|
| 877 | + * 2. For each datetime get related tickets |
|
| 878 | + * 3. For each ticket get related prices |
|
| 879 | + */ |
|
| 880 | + |
|
| 881 | + $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 882 | + $times = $DTM->get_all_event_dates($evtID); |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + $main_template_args['total_dtt_rows'] = count($times); |
|
| 886 | + |
|
| 887 | + /** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */ |
|
| 888 | + $dttrow = 1; |
|
| 889 | + foreach ($times as $time) { |
|
| 890 | + $dttid = $time->get('DTT_ID'); |
|
| 891 | + $time->set('DTT_order', $dttrow); |
|
| 892 | + $existing_datetime_ids[] = $dttid; |
|
| 893 | 893 | |
| 894 | - //tickets attached |
|
| 895 | - $related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array( |
|
| 896 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 897 | - 'default_where_conditions' => 'none', |
|
| 898 | - 'order_by' => array('TKT_order' => 'ASC') |
|
| 899 | - )) : array(); |
|
| 894 | + //tickets attached |
|
| 895 | + $related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array( |
|
| 896 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 897 | + 'default_where_conditions' => 'none', |
|
| 898 | + 'order_by' => array('TKT_order' => 'ASC') |
|
| 899 | + )) : array(); |
|
| 900 | 900 | |
| 901 | - //if there are no related tickets this is likely a new event OR autodraft |
|
| 902 | - // event so we need to generate the default tickets because dtts |
|
| 903 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 904 | - // datetime on the event. |
|
| 905 | - if (empty ($related_tickets) && count($times) < 2) { |
|
| 906 | - $related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 901 | + //if there are no related tickets this is likely a new event OR autodraft |
|
| 902 | + // event so we need to generate the default tickets because dtts |
|
| 903 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 904 | + // datetime on the event. |
|
| 905 | + if (empty ($related_tickets) && count($times) < 2) { |
|
| 906 | + $related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 907 | 907 | |
| 908 | - //this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 909 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 908 | + //this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 909 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 910 | 910 | |
| 911 | - $main_default_ticket = reset($related_tickets); |
|
| 912 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
| 913 | - foreach ($default_prices as $default_price) { |
|
| 914 | - if ($default_price->is_base_price()) { |
|
| 915 | - continue; |
|
| 916 | - } |
|
| 917 | - $main_default_ticket->cache('Price', $default_price); |
|
| 918 | - } |
|
| 919 | - } |
|
| 920 | - } |
|
| 911 | + $main_default_ticket = reset($related_tickets); |
|
| 912 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
| 913 | + foreach ($default_prices as $default_price) { |
|
| 914 | + if ($default_price->is_base_price()) { |
|
| 915 | + continue; |
|
| 916 | + } |
|
| 917 | + $main_default_ticket->cache('Price', $default_price); |
|
| 918 | + } |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | 921 | |
| 922 | 922 | |
| 923 | - //we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information. |
|
| 923 | + //we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information. |
|
| 924 | 924 | |
| 925 | - //loop through and setup the ticket rows and make sure the order is set. |
|
| 926 | - foreach ($related_tickets as $ticket) { |
|
| 927 | - $tktid = $ticket->get('TKT_ID'); |
|
| 928 | - $tktrow = $ticket->get('TKT_row'); |
|
| 929 | - //we only want unique tickets in our final display!! |
|
| 930 | - if ( ! in_array($tktid, $existing_ticket_ids)) { |
|
| 931 | - $existing_ticket_ids[] = $tktid; |
|
| 932 | - $all_tickets[] = $ticket; |
|
| 933 | - } |
|
| 925 | + //loop through and setup the ticket rows and make sure the order is set. |
|
| 926 | + foreach ($related_tickets as $ticket) { |
|
| 927 | + $tktid = $ticket->get('TKT_ID'); |
|
| 928 | + $tktrow = $ticket->get('TKT_row'); |
|
| 929 | + //we only want unique tickets in our final display!! |
|
| 930 | + if ( ! in_array($tktid, $existing_ticket_ids)) { |
|
| 931 | + $existing_ticket_ids[] = $tktid; |
|
| 932 | + $all_tickets[] = $ticket; |
|
| 933 | + } |
|
| 934 | 934 | |
| 935 | - //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 936 | - $datetime_tickets[$dttid][] = $tktrow; |
|
| 935 | + //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 936 | + $datetime_tickets[$dttid][] = $tktrow; |
|
| 937 | 937 | |
| 938 | - //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 939 | - if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) { |
|
| 940 | - $ticket_datetimes[$tktid][] = $dttrow; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - $dttrow++; |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 947 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 948 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 949 | - |
|
| 950 | - //sort $all_tickets by order |
|
| 951 | - usort($all_tickets, function ($a, $b) { |
|
| 952 | - $a_order = (int)$a->get('TKT_order'); |
|
| 953 | - $b_order = (int)$b->get('TKT_order'); |
|
| 954 | - if ($a_order == $b_order) { |
|
| 955 | - return 0; |
|
| 956 | - } |
|
| 938 | + //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 939 | + if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) { |
|
| 940 | + $ticket_datetimes[$tktid][] = $dttrow; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + $dttrow++; |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 947 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 948 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 949 | + |
|
| 950 | + //sort $all_tickets by order |
|
| 951 | + usort($all_tickets, function ($a, $b) { |
|
| 952 | + $a_order = (int)$a->get('TKT_order'); |
|
| 953 | + $b_order = (int)$b->get('TKT_order'); |
|
| 954 | + if ($a_order == $b_order) { |
|
| 955 | + return 0; |
|
| 956 | + } |
|
| 957 | 957 | |
| 958 | - return ($a_order < $b_order) ? -1 : 1; |
|
| 959 | - }); |
|
| 960 | - |
|
| 961 | - //k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again. |
|
| 962 | - $dttrow = 1; |
|
| 963 | - foreach ($times as $time) { |
|
| 964 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets, |
|
| 965 | - $all_tickets, false, $times); |
|
| 966 | - $dttrow++; |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - //then loop through all tickets for the ticket rows. |
|
| 970 | - $tktrow = 1; |
|
| 971 | - foreach ($all_tickets as $ticket) { |
|
| 972 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times, |
|
| 973 | - false, $all_tickets); |
|
| 974 | - $tktrow++; |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets); |
|
| 978 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'; |
|
| 979 | - EEH_Template::display_template($template, $main_template_args); |
|
| 980 | - |
|
| 981 | - return; |
|
| 982 | - } |
|
| 958 | + return ($a_order < $b_order) ? -1 : 1; |
|
| 959 | + }); |
|
| 960 | + |
|
| 961 | + //k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again. |
|
| 962 | + $dttrow = 1; |
|
| 963 | + foreach ($times as $time) { |
|
| 964 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets, |
|
| 965 | + $all_tickets, false, $times); |
|
| 966 | + $dttrow++; |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + //then loop through all tickets for the ticket rows. |
|
| 970 | + $tktrow = 1; |
|
| 971 | + foreach ($all_tickets as $ticket) { |
|
| 972 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times, |
|
| 973 | + false, $all_tickets); |
|
| 974 | + $tktrow++; |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets); |
|
| 978 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'; |
|
| 979 | + EEH_Template::display_template($template, $main_template_args); |
|
| 980 | + |
|
| 981 | + return; |
|
| 982 | + } |
|
| 983 | 983 | |
| 984 | 984 | |
| 985 | - protected function _get_datetime_row( |
|
| 986 | - $dttrow, |
|
| 987 | - EE_Datetime $dtt, |
|
| 988 | - $datetime_tickets, |
|
| 989 | - $all_tickets, |
|
| 990 | - $default = false, |
|
| 991 | - $all_dtts = array() |
|
| 992 | - ) { |
|
| 993 | - |
|
| 994 | - $dtt_display_template_args = array( |
|
| 995 | - 'dtt_edit_row' => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts), |
|
| 996 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, |
|
| 997 | - $all_tickets, $default), |
|
| 998 | - 'dtt_row' => $default ? 'DTTNUM' : $dttrow |
|
| 999 | - ); |
|
| 1000 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php'; |
|
| 1001 | - |
|
| 1002 | - return EEH_Template::display_template($template, $dtt_display_template_args, true); |
|
| 1003 | - } |
|
| 985 | + protected function _get_datetime_row( |
|
| 986 | + $dttrow, |
|
| 987 | + EE_Datetime $dtt, |
|
| 988 | + $datetime_tickets, |
|
| 989 | + $all_tickets, |
|
| 990 | + $default = false, |
|
| 991 | + $all_dtts = array() |
|
| 992 | + ) { |
|
| 993 | + |
|
| 994 | + $dtt_display_template_args = array( |
|
| 995 | + 'dtt_edit_row' => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts), |
|
| 996 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, |
|
| 997 | + $all_tickets, $default), |
|
| 998 | + 'dtt_row' => $default ? 'DTTNUM' : $dttrow |
|
| 999 | + ); |
|
| 1000 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php'; |
|
| 1001 | + |
|
| 1002 | + return EEH_Template::display_template($template, $dtt_display_template_args, true); |
|
| 1003 | + } |
|
| 1004 | 1004 | |
| 1005 | 1005 | |
| 1006 | - /** |
|
| 1007 | - * This method is used to generate a dtt fields edit row. |
|
| 1008 | - * The same row is used to generate a row with valid DTT objects and the default row that is used as the |
|
| 1009 | - * skeleton by the js. |
|
| 1010 | - * |
|
| 1011 | - * @param int $dttrow The row number for the row being generated. |
|
| 1012 | - * @param mixed EE_Datetime|null $dtt If not default row being |
|
| 1013 | - * generated, this must be a EE_Datetime |
|
| 1014 | - * object. |
|
| 1015 | - * @param bool $default Whether a default row is being generated or not. |
|
| 1016 | - * @param EE_Datetime[] $all_dtts This is the array of all datetimes used in the editor. |
|
| 1017 | - * |
|
| 1018 | - * @return string Generated edit row. |
|
| 1019 | - */ |
|
| 1020 | - protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts) |
|
| 1021 | - { |
|
| 1022 | - |
|
| 1023 | - // if the incoming $dtt object is NOT an instance of EE_Datetime then force default to true. |
|
| 1024 | - $default = ! $dtt instanceof EE_Datetime ? true : false; |
|
| 1025 | - |
|
| 1026 | - $template_args = array( |
|
| 1027 | - 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1028 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1029 | - 'edit_dtt_expanded' => '', |
|
| 1030 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing', |
|
| 1031 | - 'DTT_ID' => $default ? '' : $dtt->ID(), |
|
| 1032 | - 'DTT_name' => $default ? '' : $dtt->name(), |
|
| 1033 | - 'DTT_description' => $default ? '' : $dtt->description(), |
|
| 1034 | - 'DTT_EVT_start' => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1035 | - 'DTT_EVT_end' => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1036 | - 'DTT_reg_limit' => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'), |
|
| 1037 | - 'DTT_order' => $default ? 'DTTNUM' : $dttrow, |
|
| 1038 | - 'dtt_sold' => $default ? '0' : $dtt->get('DTT_sold'), |
|
| 1039 | - 'clone_icon' => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1040 | - 'trash_icon' => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1041 | - 'reg_list_url' => $default || ! $dtt->event() instanceof \EE_Event |
|
| 1042 | - ? '' |
|
| 1043 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1044 | - array('event_id' => $dtt->event()->ID(), 'datetime_id' => $dtt->ID()), |
|
| 1045 | - REG_ADMIN_URL |
|
| 1046 | - ) |
|
| 1047 | - ); |
|
| 1048 | - |
|
| 1049 | - $template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
| 1050 | - |
|
| 1051 | - //allow filtering of template args at this point. |
|
| 1052 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1053 | - $template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event); |
|
| 1054 | - |
|
| 1055 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php'; |
|
| 1056 | - |
|
| 1057 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1058 | - } |
|
| 1006 | + /** |
|
| 1007 | + * This method is used to generate a dtt fields edit row. |
|
| 1008 | + * The same row is used to generate a row with valid DTT objects and the default row that is used as the |
|
| 1009 | + * skeleton by the js. |
|
| 1010 | + * |
|
| 1011 | + * @param int $dttrow The row number for the row being generated. |
|
| 1012 | + * @param mixed EE_Datetime|null $dtt If not default row being |
|
| 1013 | + * generated, this must be a EE_Datetime |
|
| 1014 | + * object. |
|
| 1015 | + * @param bool $default Whether a default row is being generated or not. |
|
| 1016 | + * @param EE_Datetime[] $all_dtts This is the array of all datetimes used in the editor. |
|
| 1017 | + * |
|
| 1018 | + * @return string Generated edit row. |
|
| 1019 | + */ |
|
| 1020 | + protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts) |
|
| 1021 | + { |
|
| 1022 | + |
|
| 1023 | + // if the incoming $dtt object is NOT an instance of EE_Datetime then force default to true. |
|
| 1024 | + $default = ! $dtt instanceof EE_Datetime ? true : false; |
|
| 1025 | + |
|
| 1026 | + $template_args = array( |
|
| 1027 | + 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1028 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1029 | + 'edit_dtt_expanded' => '', |
|
| 1030 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing', |
|
| 1031 | + 'DTT_ID' => $default ? '' : $dtt->ID(), |
|
| 1032 | + 'DTT_name' => $default ? '' : $dtt->name(), |
|
| 1033 | + 'DTT_description' => $default ? '' : $dtt->description(), |
|
| 1034 | + 'DTT_EVT_start' => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1035 | + 'DTT_EVT_end' => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1036 | + 'DTT_reg_limit' => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'), |
|
| 1037 | + 'DTT_order' => $default ? 'DTTNUM' : $dttrow, |
|
| 1038 | + 'dtt_sold' => $default ? '0' : $dtt->get('DTT_sold'), |
|
| 1039 | + 'clone_icon' => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1040 | + 'trash_icon' => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1041 | + 'reg_list_url' => $default || ! $dtt->event() instanceof \EE_Event |
|
| 1042 | + ? '' |
|
| 1043 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1044 | + array('event_id' => $dtt->event()->ID(), 'datetime_id' => $dtt->ID()), |
|
| 1045 | + REG_ADMIN_URL |
|
| 1046 | + ) |
|
| 1047 | + ); |
|
| 1048 | + |
|
| 1049 | + $template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
| 1050 | + |
|
| 1051 | + //allow filtering of template args at this point. |
|
| 1052 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1053 | + $template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event); |
|
| 1054 | + |
|
| 1055 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php'; |
|
| 1056 | + |
|
| 1057 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1058 | + } |
|
| 1059 | 1059 | |
| 1060 | 1060 | |
| 1061 | - protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default) |
|
| 1062 | - { |
|
| 1063 | - |
|
| 1064 | - $template_args = array( |
|
| 1065 | - 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1066 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1067 | - 'DTT_description' => $default ? '' : $dtt->description(), |
|
| 1068 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1069 | - 'show_tickets_row' => ' style="display:none;"', |
|
| 1070 | - //$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '', |
|
| 1071 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime', |
|
| 1072 | - $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 1073 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1074 | - 'DTT_ID' => $default ? '' : $dtt->ID() |
|
| 1075 | - ); |
|
| 1076 | - |
|
| 1077 | - //need to setup the list items (but only if this isnt' a default skeleton setup) |
|
| 1078 | - if ( ! $default) { |
|
| 1079 | - $tktrow = 1; |
|
| 1080 | - foreach ($all_tickets as $ticket) { |
|
| 1081 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow, |
|
| 1082 | - $dtt, $ticket, $datetime_tickets, $default); |
|
| 1083 | - $tktrow++; |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - //filter template args at this point |
|
| 1088 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1089 | - $template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event); |
|
| 1090 | - |
|
| 1091 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php'; |
|
| 1092 | - |
|
| 1093 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1094 | - } |
|
| 1061 | + protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default) |
|
| 1062 | + { |
|
| 1063 | + |
|
| 1064 | + $template_args = array( |
|
| 1065 | + 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1066 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1067 | + 'DTT_description' => $default ? '' : $dtt->description(), |
|
| 1068 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1069 | + 'show_tickets_row' => ' style="display:none;"', |
|
| 1070 | + //$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '', |
|
| 1071 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime', |
|
| 1072 | + $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false), |
|
| 1073 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1074 | + 'DTT_ID' => $default ? '' : $dtt->ID() |
|
| 1075 | + ); |
|
| 1076 | + |
|
| 1077 | + //need to setup the list items (but only if this isnt' a default skeleton setup) |
|
| 1078 | + if ( ! $default) { |
|
| 1079 | + $tktrow = 1; |
|
| 1080 | + foreach ($all_tickets as $ticket) { |
|
| 1081 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow, |
|
| 1082 | + $dtt, $ticket, $datetime_tickets, $default); |
|
| 1083 | + $tktrow++; |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + //filter template args at this point |
|
| 1088 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1089 | + $template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event); |
|
| 1090 | + |
|
| 1091 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php'; |
|
| 1092 | + |
|
| 1093 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1094 | + } |
|
| 1095 | 1095 | |
| 1096 | 1096 | |
| 1097 | - protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default) |
|
| 1098 | - { |
|
| 1099 | - $tktid = ! empty($ticket) ? $ticket->ID() : 0; |
|
| 1100 | - $dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array(); |
|
| 1101 | - |
|
| 1102 | - $displayrow = ! empty($ticket) ? $ticket->get('TKT_row') : 0; |
|
| 1103 | - $template_args = array( |
|
| 1104 | - 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1105 | - 'tkt_row' => $default && empty($ticket) ? 'TICKETNUM' : $tktrow, |
|
| 1106 | - 'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '', |
|
| 1107 | - 'ticket_selected' => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '', |
|
| 1108 | - 'TKT_name' => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'), |
|
| 1109 | - 'tkt_status_class' => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1110 | - ); |
|
| 1111 | - |
|
| 1112 | - //filter template args |
|
| 1113 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1114 | - $template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event); |
|
| 1115 | - |
|
| 1116 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php'; |
|
| 1117 | - |
|
| 1118 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1119 | - } |
|
| 1097 | + protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default) |
|
| 1098 | + { |
|
| 1099 | + $tktid = ! empty($ticket) ? $ticket->ID() : 0; |
|
| 1100 | + $dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array(); |
|
| 1101 | + |
|
| 1102 | + $displayrow = ! empty($ticket) ? $ticket->get('TKT_row') : 0; |
|
| 1103 | + $template_args = array( |
|
| 1104 | + 'dtt_row' => $default ? 'DTTNUM' : $dttrow, |
|
| 1105 | + 'tkt_row' => $default && empty($ticket) ? 'TICKETNUM' : $tktrow, |
|
| 1106 | + 'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '', |
|
| 1107 | + 'ticket_selected' => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '', |
|
| 1108 | + 'TKT_name' => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'), |
|
| 1109 | + 'tkt_status_class' => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1110 | + ); |
|
| 1111 | + |
|
| 1112 | + //filter template args |
|
| 1113 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1114 | + $template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event); |
|
| 1115 | + |
|
| 1116 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php'; |
|
| 1117 | + |
|
| 1118 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1119 | + } |
|
| 1120 | 1120 | |
| 1121 | 1121 | |
| 1122 | - /** |
|
| 1123 | - * This generates the ticket row for tickets. |
|
| 1124 | - * This same method is used to generate both the actual rows and the js skeleton row (when default == |
|
| 1125 | - * true) |
|
| 1126 | - * |
|
| 1127 | - * @param int $tktrow Represents the row number being generated. |
|
| 1128 | - * @param mixed null|EE_Ticket $ticket If default then this will |
|
| 1129 | - * be null. |
|
| 1130 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by |
|
| 1131 | - * each ticket or empty for default |
|
| 1132 | - * @param EE_Datetime[] $all_dtts All Datetimes on the event or empty for default. |
|
| 1133 | - * @param bool $default Whether default row being generated or not. |
|
| 1134 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event (or |
|
| 1135 | - * empty in the case of defaults) |
|
| 1136 | - * |
|
| 1137 | - * @return [type] [description] |
|
| 1138 | - */ |
|
| 1139 | - protected function _get_ticket_row( |
|
| 1140 | - $tktrow, |
|
| 1141 | - $ticket, |
|
| 1142 | - $ticket_datetimes, |
|
| 1143 | - $all_dtts, |
|
| 1144 | - $default = false, |
|
| 1145 | - $all_tickets = array() |
|
| 1146 | - ) { |
|
| 1147 | - |
|
| 1148 | - //if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1149 | - $default = ! $ticket instanceof EE_Ticket ? true : false; |
|
| 1150 | - |
|
| 1151 | - $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
| 1152 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
| 1153 | - |
|
| 1154 | - //if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on |
|
| 1155 | - //the object. This is done by not including any query_params. |
|
| 1156 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1157 | - $prices = $ticket->get_many_related('Price'); |
|
| 1158 | - } |
|
| 1159 | - |
|
| 1160 | - // check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket). This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1161 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? true : false; |
|
| 1162 | - |
|
| 1163 | - $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
| 1164 | - |
|
| 1165 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1166 | - $base_price = $default ? null : $ticket->base_price(); |
|
| 1167 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1168 | - |
|
| 1169 | - //breaking out complicated condition for ticket_status |
|
| 1170 | - if ($default) { |
|
| 1171 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1172 | - } else { |
|
| 1173 | - $ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - //breaking out complicated condition for TKT_taxable |
|
| 1177 | - if ($default) { |
|
| 1178 | - $TKT_taxable = ''; |
|
| 1179 | - } else { |
|
| 1180 | - $TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : ''; |
|
| 1181 | - } |
|
| 1122 | + /** |
|
| 1123 | + * This generates the ticket row for tickets. |
|
| 1124 | + * This same method is used to generate both the actual rows and the js skeleton row (when default == |
|
| 1125 | + * true) |
|
| 1126 | + * |
|
| 1127 | + * @param int $tktrow Represents the row number being generated. |
|
| 1128 | + * @param mixed null|EE_Ticket $ticket If default then this will |
|
| 1129 | + * be null. |
|
| 1130 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by |
|
| 1131 | + * each ticket or empty for default |
|
| 1132 | + * @param EE_Datetime[] $all_dtts All Datetimes on the event or empty for default. |
|
| 1133 | + * @param bool $default Whether default row being generated or not. |
|
| 1134 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event (or |
|
| 1135 | + * empty in the case of defaults) |
|
| 1136 | + * |
|
| 1137 | + * @return [type] [description] |
|
| 1138 | + */ |
|
| 1139 | + protected function _get_ticket_row( |
|
| 1140 | + $tktrow, |
|
| 1141 | + $ticket, |
|
| 1142 | + $ticket_datetimes, |
|
| 1143 | + $all_dtts, |
|
| 1144 | + $default = false, |
|
| 1145 | + $all_tickets = array() |
|
| 1146 | + ) { |
|
| 1147 | + |
|
| 1148 | + //if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1149 | + $default = ! $ticket instanceof EE_Ticket ? true : false; |
|
| 1150 | + |
|
| 1151 | + $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
| 1152 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
| 1153 | + |
|
| 1154 | + //if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on |
|
| 1155 | + //the object. This is done by not including any query_params. |
|
| 1156 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1157 | + $prices = $ticket->get_many_related('Price'); |
|
| 1158 | + } |
|
| 1159 | + |
|
| 1160 | + // check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket). This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1161 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? true : false; |
|
| 1162 | + |
|
| 1163 | + $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
| 1164 | + |
|
| 1165 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1166 | + $base_price = $default ? null : $ticket->base_price(); |
|
| 1167 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1168 | + |
|
| 1169 | + //breaking out complicated condition for ticket_status |
|
| 1170 | + if ($default) { |
|
| 1171 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1172 | + } else { |
|
| 1173 | + $ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + //breaking out complicated condition for TKT_taxable |
|
| 1177 | + if ($default) { |
|
| 1178 | + $TKT_taxable = ''; |
|
| 1179 | + } else { |
|
| 1180 | + $TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : ''; |
|
| 1181 | + } |
|
| 1182 | 1182 | |
| 1183 | 1183 | |
| 1184 | - $template_args = array( |
|
| 1185 | - 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1186 | - 'TKT_order' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1187 | - //on initial page load this will always be the correct order. |
|
| 1188 | - 'tkt_status_class' => $ticket_status_class, |
|
| 1189 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
| 1190 | - 'edit_tkt_expanded' => '', |
|
| 1191 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1192 | - 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
|
| 1193 | - 'TKT_start_date' => $default ? '' : $ticket->get_date('TKT_start_date', |
|
| 1194 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1195 | - 'TKT_end_date' => $default ? '' : $ticket->get_date('TKT_end_date', |
|
| 1196 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1197 | - 'TKT_status' => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false, |
|
| 1198 | - 'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false, |
|
| 1199 | - 'sentence') : $ticket->ticket_status(true), |
|
| 1200 | - 'TKT_price' => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(), |
|
| 1201 | - false, false), |
|
| 1202 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1203 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1204 | - 'TKT_qty' => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1205 | - 'TKT_qty_for_input' => $default ? '' : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1206 | - 'TKT_uses' => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1207 | - 'TKT_min' => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')), |
|
| 1208 | - 'TKT_max' => $default ? '' : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1209 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1210 | - 'TKT_registrations' => $default ? 0 : $ticket->count_registrations(array( |
|
| 1211 | - array( |
|
| 1212 | - 'STS_ID' => array( |
|
| 1213 | - '!=', |
|
| 1214 | - EEM_Registration::status_id_incomplete |
|
| 1215 | - ) |
|
| 1216 | - ) |
|
| 1217 | - )), |
|
| 1218 | - 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
|
| 1219 | - 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
|
| 1220 | - 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
|
| 1221 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1222 | - 'TKT_is_default_selector' => '', |
|
| 1223 | - 'ticket_price_rows' => '', |
|
| 1224 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount', |
|
| 1225 | - 'localized_float'), |
|
| 1226 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1227 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"', |
|
| 1228 | - 'show_price_mod_button' => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '', |
|
| 1229 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1230 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1231 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts), |
|
| 1232 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_dtts), |
|
| 1233 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
| 1234 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1235 | - 'TKT_taxable' => $TKT_taxable, |
|
| 1236 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"', |
|
| 1237 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1238 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency($ticket_subtotal, false, false), |
|
| 1239 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1240 | - 'tax_rows' => $this->_get_tax_rows($tktrow, $ticket), |
|
| 1241 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? true : false, |
|
| 1242 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '', |
|
| 1243 | - 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1244 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable' |
|
| 1245 | - ); |
|
| 1246 | - |
|
| 1247 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
| 1248 | - |
|
| 1249 | - //handle rows that should NOT be empty |
|
| 1250 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1251 | - //if empty then the start date will be now. |
|
| 1252 | - $template_args['TKT_start_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'], |
|
| 1253 | - current_time('timestamp')); |
|
| 1254 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1184 | + $template_args = array( |
|
| 1185 | + 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1186 | + 'TKT_order' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1187 | + //on initial page load this will always be the correct order. |
|
| 1188 | + 'tkt_status_class' => $ticket_status_class, |
|
| 1189 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
| 1190 | + 'edit_tkt_expanded' => '', |
|
| 1191 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1192 | + 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
|
| 1193 | + 'TKT_start_date' => $default ? '' : $ticket->get_date('TKT_start_date', |
|
| 1194 | + $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1195 | + 'TKT_end_date' => $default ? '' : $ticket->get_date('TKT_end_date', |
|
| 1196 | + $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']), |
|
| 1197 | + 'TKT_status' => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false, |
|
| 1198 | + 'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false, |
|
| 1199 | + 'sentence') : $ticket->ticket_status(true), |
|
| 1200 | + 'TKT_price' => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(), |
|
| 1201 | + false, false), |
|
| 1202 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1203 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1204 | + 'TKT_qty' => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1205 | + 'TKT_qty_for_input' => $default ? '' : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1206 | + 'TKT_uses' => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1207 | + 'TKT_min' => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')), |
|
| 1208 | + 'TKT_max' => $default ? '' : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1209 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1210 | + 'TKT_registrations' => $default ? 0 : $ticket->count_registrations(array( |
|
| 1211 | + array( |
|
| 1212 | + 'STS_ID' => array( |
|
| 1213 | + '!=', |
|
| 1214 | + EEM_Registration::status_id_incomplete |
|
| 1215 | + ) |
|
| 1216 | + ) |
|
| 1217 | + )), |
|
| 1218 | + 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
|
| 1219 | + 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
|
| 1220 | + 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
|
| 1221 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1222 | + 'TKT_is_default_selector' => '', |
|
| 1223 | + 'ticket_price_rows' => '', |
|
| 1224 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount', |
|
| 1225 | + 'localized_float'), |
|
| 1226 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1227 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"', |
|
| 1228 | + 'show_price_mod_button' => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '', |
|
| 1229 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1230 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1231 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts), |
|
| 1232 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_dtts), |
|
| 1233 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
| 1234 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1235 | + 'TKT_taxable' => $TKT_taxable, |
|
| 1236 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"', |
|
| 1237 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1238 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency($ticket_subtotal, false, false), |
|
| 1239 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1240 | + 'tax_rows' => $this->_get_tax_rows($tktrow, $ticket), |
|
| 1241 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? true : false, |
|
| 1242 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '', |
|
| 1243 | + 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1244 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable' |
|
| 1245 | + ); |
|
| 1246 | + |
|
| 1247 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : ''; |
|
| 1248 | + |
|
| 1249 | + //handle rows that should NOT be empty |
|
| 1250 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1251 | + //if empty then the start date will be now. |
|
| 1252 | + $template_args['TKT_start_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'], |
|
| 1253 | + current_time('timestamp')); |
|
| 1254 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1258 | 1258 | |
| 1259 | - //get the earliest datetime (if present); |
|
| 1260 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime', |
|
| 1261 | - array('order_by' => array('DTT_EVT_start' => 'ASC'))) : null; |
|
| 1259 | + //get the earliest datetime (if present); |
|
| 1260 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime', |
|
| 1261 | + array('order_by' => array('DTT_EVT_start' => 'ASC'))) : null; |
|
| 1262 | 1262 | |
| 1263 | - if ( ! empty($earliest_dtt)) { |
|
| 1264 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', |
|
| 1265 | - $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 1266 | - } else { |
|
| 1267 | - //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1268 | - $template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'], |
|
| 1269 | - mktime(24, 0, 0, date("m"), date("d") + 29, date("Y"))); |
|
| 1270 | - } |
|
| 1271 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - //generate ticket_datetime items |
|
| 1275 | - if ( ! $default) { |
|
| 1276 | - $dttrow = 1; |
|
| 1277 | - foreach ($all_dtts as $dtt) { |
|
| 1278 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, |
|
| 1279 | - $ticket, $ticket_datetimes, $default); |
|
| 1280 | - $dttrow++; |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - $prcrow = 1; |
|
| 1285 | - foreach ($prices as $price) { |
|
| 1286 | - if ($price->is_base_price()) { |
|
| 1287 | - $prcrow++; |
|
| 1288 | - continue; |
|
| 1289 | - } |
|
| 1290 | - $show_trash = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? false : true; |
|
| 1291 | - $show_create = count($prices) > 1 && count($prices) !== $prcrow ? false : true; |
|
| 1292 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default, |
|
| 1293 | - $ticket, $show_trash, $show_create); |
|
| 1294 | - $prcrow++; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - //filter $template_args |
|
| 1298 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1299 | - $template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets, |
|
| 1300 | - $this->_is_creating_event); |
|
| 1301 | - |
|
| 1302 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php'; |
|
| 1303 | - |
|
| 1304 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1305 | - } |
|
| 1263 | + if ( ! empty($earliest_dtt)) { |
|
| 1264 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', |
|
| 1265 | + $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']); |
|
| 1266 | + } else { |
|
| 1267 | + //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1268 | + $template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'], |
|
| 1269 | + mktime(24, 0, 0, date("m"), date("d") + 29, date("Y"))); |
|
| 1270 | + } |
|
| 1271 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + //generate ticket_datetime items |
|
| 1275 | + if ( ! $default) { |
|
| 1276 | + $dttrow = 1; |
|
| 1277 | + foreach ($all_dtts as $dtt) { |
|
| 1278 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, |
|
| 1279 | + $ticket, $ticket_datetimes, $default); |
|
| 1280 | + $dttrow++; |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + $prcrow = 1; |
|
| 1285 | + foreach ($prices as $price) { |
|
| 1286 | + if ($price->is_base_price()) { |
|
| 1287 | + $prcrow++; |
|
| 1288 | + continue; |
|
| 1289 | + } |
|
| 1290 | + $show_trash = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? false : true; |
|
| 1291 | + $show_create = count($prices) > 1 && count($prices) !== $prcrow ? false : true; |
|
| 1292 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default, |
|
| 1293 | + $ticket, $show_trash, $show_create); |
|
| 1294 | + $prcrow++; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + //filter $template_args |
|
| 1298 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1299 | + $template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets, |
|
| 1300 | + $this->_is_creating_event); |
|
| 1301 | + |
|
| 1302 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php'; |
|
| 1303 | + |
|
| 1304 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1305 | + } |
|
| 1306 | 1306 | |
| 1307 | 1307 | |
| 1308 | - protected function _get_tax_rows($tktrow, $ticket) |
|
| 1309 | - { |
|
| 1310 | - $tax_rows = ''; |
|
| 1311 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php'; |
|
| 1312 | - $template_args = array(); |
|
| 1313 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1314 | - foreach ($taxes as $tax) { |
|
| 1315 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1316 | - $template_args = array( |
|
| 1317 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"', |
|
| 1318 | - 'tax_id' => $tax->ID(), |
|
| 1319 | - 'tkt_row' => $tktrow, |
|
| 1320 | - 'tax_label' => $tax->get('PRC_name'), |
|
| 1321 | - 'tax_added' => $tax_added, |
|
| 1322 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1323 | - 'tax_amount' => $tax->get('PRC_amount') |
|
| 1324 | - ); |
|
| 1325 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1326 | - $template_args, $tktrow, $ticket, $this->_is_creating_event); |
|
| 1327 | - $tax_rows .= EEH_Template::display_template($template, $template_args, true); |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - return $tax_rows; |
|
| 1332 | - } |
|
| 1308 | + protected function _get_tax_rows($tktrow, $ticket) |
|
| 1309 | + { |
|
| 1310 | + $tax_rows = ''; |
|
| 1311 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php'; |
|
| 1312 | + $template_args = array(); |
|
| 1313 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1314 | + foreach ($taxes as $tax) { |
|
| 1315 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1316 | + $template_args = array( |
|
| 1317 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"', |
|
| 1318 | + 'tax_id' => $tax->ID(), |
|
| 1319 | + 'tkt_row' => $tktrow, |
|
| 1320 | + 'tax_label' => $tax->get('PRC_name'), |
|
| 1321 | + 'tax_added' => $tax_added, |
|
| 1322 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1323 | + 'tax_amount' => $tax->get('PRC_amount') |
|
| 1324 | + ); |
|
| 1325 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1326 | + $template_args, $tktrow, $ticket, $this->_is_creating_event); |
|
| 1327 | + $tax_rows .= EEH_Template::display_template($template, $template_args, true); |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + return $tax_rows; |
|
| 1332 | + } |
|
| 1333 | 1333 | |
| 1334 | 1334 | |
| 1335 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1336 | - { |
|
| 1337 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1335 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1336 | + { |
|
| 1337 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1338 | 1338 | |
| 1339 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1340 | - } |
|
| 1339 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1340 | + } |
|
| 1341 | 1341 | |
| 1342 | 1342 | |
| 1343 | - protected function _get_ticket_price_row( |
|
| 1344 | - $tktrow, |
|
| 1345 | - $prcrow, |
|
| 1346 | - $price, |
|
| 1347 | - $default, |
|
| 1348 | - $ticket, |
|
| 1349 | - $show_trash = true, |
|
| 1350 | - $show_create = true |
|
| 1351 | - ) { |
|
| 1352 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false; |
|
| 1353 | - $template_args = array( |
|
| 1354 | - 'tkt_row' => $default && empty($ticket) ? 'TICKETNUM' : $tktrow, |
|
| 1355 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1356 | - 'edit_prices_name' => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices', |
|
| 1357 | - 'price_type_selector' => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow, |
|
| 1358 | - $price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled), |
|
| 1359 | - 'PRC_ID' => $default && empty($price) ? 0 : $price->ID(), |
|
| 1360 | - 'PRC_is_default' => $default && empty($price) ? 0 : $price->get('PRC_is_default'), |
|
| 1361 | - 'PRC_name' => $default && empty($price) ? '' : $price->get('PRC_name'), |
|
| 1362 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1363 | - 'show_plus_or_minus' => $default && empty($price) ? '' : ' style="display:none;"', |
|
| 1364 | - 'show_plus' => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''), |
|
| 1365 | - 'show_minus' => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'), |
|
| 1366 | - 'show_currency_symbol' => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''), |
|
| 1367 | - 'PRC_amount' => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount', |
|
| 1368 | - 'localized_float'), |
|
| 1369 | - 'show_percentage' => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'), |
|
| 1370 | - 'show_trash_icon' => $show_trash ? '' : ' style="display:none;"', |
|
| 1371 | - 'show_create_button' => $show_create ? '' : ' style="display:none;"', |
|
| 1372 | - 'PRC_desc' => $default && empty($price) ? '' : $price->get('PRC_desc'), |
|
| 1373 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false |
|
| 1374 | - ); |
|
| 1375 | - |
|
| 1376 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1377 | - $template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create, |
|
| 1378 | - $this->_is_creating_event); |
|
| 1379 | - |
|
| 1380 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php'; |
|
| 1381 | - |
|
| 1382 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1383 | - } |
|
| 1343 | + protected function _get_ticket_price_row( |
|
| 1344 | + $tktrow, |
|
| 1345 | + $prcrow, |
|
| 1346 | + $price, |
|
| 1347 | + $default, |
|
| 1348 | + $ticket, |
|
| 1349 | + $show_trash = true, |
|
| 1350 | + $show_create = true |
|
| 1351 | + ) { |
|
| 1352 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false; |
|
| 1353 | + $template_args = array( |
|
| 1354 | + 'tkt_row' => $default && empty($ticket) ? 'TICKETNUM' : $tktrow, |
|
| 1355 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1356 | + 'edit_prices_name' => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices', |
|
| 1357 | + 'price_type_selector' => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow, |
|
| 1358 | + $price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled), |
|
| 1359 | + 'PRC_ID' => $default && empty($price) ? 0 : $price->ID(), |
|
| 1360 | + 'PRC_is_default' => $default && empty($price) ? 0 : $price->get('PRC_is_default'), |
|
| 1361 | + 'PRC_name' => $default && empty($price) ? '' : $price->get('PRC_name'), |
|
| 1362 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1363 | + 'show_plus_or_minus' => $default && empty($price) ? '' : ' style="display:none;"', |
|
| 1364 | + 'show_plus' => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''), |
|
| 1365 | + 'show_minus' => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'), |
|
| 1366 | + 'show_currency_symbol' => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''), |
|
| 1367 | + 'PRC_amount' => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount', |
|
| 1368 | + 'localized_float'), |
|
| 1369 | + 'show_percentage' => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'), |
|
| 1370 | + 'show_trash_icon' => $show_trash ? '' : ' style="display:none;"', |
|
| 1371 | + 'show_create_button' => $show_create ? '' : ' style="display:none;"', |
|
| 1372 | + 'PRC_desc' => $default && empty($price) ? '' : $price->get('PRC_desc'), |
|
| 1373 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false |
|
| 1374 | + ); |
|
| 1375 | + |
|
| 1376 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1377 | + $template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create, |
|
| 1378 | + $this->_is_creating_event); |
|
| 1379 | + |
|
| 1380 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php'; |
|
| 1381 | + |
|
| 1382 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1383 | + } |
|
| 1384 | 1384 | |
| 1385 | 1385 | |
| 1386 | - protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = false) |
|
| 1387 | - { |
|
| 1388 | - if ($price->is_base_price()) { |
|
| 1389 | - return $this->_get_base_price_template($tktrow, $prcrow, $price, $default); |
|
| 1390 | - } else { |
|
| 1391 | - return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled); |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - } |
|
| 1386 | + protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = false) |
|
| 1387 | + { |
|
| 1388 | + if ($price->is_base_price()) { |
|
| 1389 | + return $this->_get_base_price_template($tktrow, $prcrow, $price, $default); |
|
| 1390 | + } else { |
|
| 1391 | + return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled); |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + } |
|
| 1395 | 1395 | |
| 1396 | 1396 | |
| 1397 | - protected function _get_base_price_template($tktrow, $prcrow, $price, $default) |
|
| 1398 | - { |
|
| 1399 | - $template_args = array( |
|
| 1400 | - 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1401 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1402 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1403 | - 'PRT_name' => __('Price', 'event_espresso'), |
|
| 1404 | - 'price_selected_operator' => '+', |
|
| 1405 | - 'price_selected_is_percent' => 0 |
|
| 1406 | - ); |
|
| 1407 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php'; |
|
| 1408 | - |
|
| 1409 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1410 | - $template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event); |
|
| 1411 | - |
|
| 1412 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1413 | - } |
|
| 1397 | + protected function _get_base_price_template($tktrow, $prcrow, $price, $default) |
|
| 1398 | + { |
|
| 1399 | + $template_args = array( |
|
| 1400 | + 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1401 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1402 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1403 | + 'PRT_name' => __('Price', 'event_espresso'), |
|
| 1404 | + 'price_selected_operator' => '+', |
|
| 1405 | + 'price_selected_is_percent' => 0 |
|
| 1406 | + ); |
|
| 1407 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php'; |
|
| 1408 | + |
|
| 1409 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1410 | + $template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event); |
|
| 1411 | + |
|
| 1412 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1413 | + } |
|
| 1414 | 1414 | |
| 1415 | 1415 | |
| 1416 | - protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false) |
|
| 1417 | - { |
|
| 1418 | - $select_name = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]'; |
|
| 1419 | - $price_types = EE_Registry::instance()->load_model('Price_Type')->get_all(array( |
|
| 1420 | - array( |
|
| 1421 | - 'OR' => array( |
|
| 1422 | - 'PBT_ID' => '2', |
|
| 1423 | - 'PBT_ID*' => '3' |
|
| 1424 | - ) |
|
| 1425 | - ) |
|
| 1426 | - )); |
|
| 1427 | - $price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php'; |
|
| 1428 | - $all_price_types = $default && empty($price) ? array( |
|
| 1429 | - array( |
|
| 1430 | - 'id' => 0, |
|
| 1431 | - 'text' => __('Select Modifier', 'event_espresso') |
|
| 1432 | - ) |
|
| 1433 | - ) : array(); |
|
| 1434 | - $selected_price_type_id = $default && empty($price) ? 0 : $price->type(); |
|
| 1435 | - $price_option_spans = ''; |
|
| 1436 | - //setup pricetypes for selector |
|
| 1437 | - foreach ($price_types as $price_type) { |
|
| 1438 | - $all_price_types[] = array( |
|
| 1439 | - 'id' => $price_type->ID(), |
|
| 1440 | - 'text' => $price_type->get('PRT_name'), |
|
| 1441 | - ); |
|
| 1416 | + protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false) |
|
| 1417 | + { |
|
| 1418 | + $select_name = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]'; |
|
| 1419 | + $price_types = EE_Registry::instance()->load_model('Price_Type')->get_all(array( |
|
| 1420 | + array( |
|
| 1421 | + 'OR' => array( |
|
| 1422 | + 'PBT_ID' => '2', |
|
| 1423 | + 'PBT_ID*' => '3' |
|
| 1424 | + ) |
|
| 1425 | + ) |
|
| 1426 | + )); |
|
| 1427 | + $price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php'; |
|
| 1428 | + $all_price_types = $default && empty($price) ? array( |
|
| 1429 | + array( |
|
| 1430 | + 'id' => 0, |
|
| 1431 | + 'text' => __('Select Modifier', 'event_espresso') |
|
| 1432 | + ) |
|
| 1433 | + ) : array(); |
|
| 1434 | + $selected_price_type_id = $default && empty($price) ? 0 : $price->type(); |
|
| 1435 | + $price_option_spans = ''; |
|
| 1436 | + //setup pricetypes for selector |
|
| 1437 | + foreach ($price_types as $price_type) { |
|
| 1438 | + $all_price_types[] = array( |
|
| 1439 | + 'id' => $price_type->ID(), |
|
| 1440 | + 'text' => $price_type->get('PRT_name'), |
|
| 1441 | + ); |
|
| 1442 | 1442 | |
| 1443 | - //while we're in the loop let's setup the option spans used by js |
|
| 1444 | - $spanargs = array( |
|
| 1445 | - 'PRT_ID' => $price_type->ID(), |
|
| 1446 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1447 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0 |
|
| 1448 | - ); |
|
| 1449 | - $price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, true); |
|
| 1450 | - } |
|
| 1451 | - |
|
| 1452 | - $select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"'; |
|
| 1453 | - $main_name = $select_name; |
|
| 1454 | - $select_name = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name; |
|
| 1455 | - |
|
| 1456 | - $template_args = array( |
|
| 1457 | - 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1458 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1459 | - 'price_modifier_selector' => EEH_Form_Fields::select_input($select_name, $all_price_types, |
|
| 1460 | - $selected_price_type_id, $select_params, 'edit-price-PRT_ID'), |
|
| 1461 | - 'main_name' => $main_name, |
|
| 1462 | - 'selected_price_type_id' => $selected_price_type_id, |
|
| 1463 | - 'price_option_spans' => $price_option_spans, |
|
| 1464 | - 'price_selected_operator' => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'), |
|
| 1465 | - 'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0), |
|
| 1466 | - 'disabled' => $disabled |
|
| 1467 | - ); |
|
| 1468 | - |
|
| 1469 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 1470 | - $template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event); |
|
| 1471 | - |
|
| 1472 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php'; |
|
| 1473 | - |
|
| 1474 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1475 | - } |
|
| 1443 | + //while we're in the loop let's setup the option spans used by js |
|
| 1444 | + $spanargs = array( |
|
| 1445 | + 'PRT_ID' => $price_type->ID(), |
|
| 1446 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1447 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0 |
|
| 1448 | + ); |
|
| 1449 | + $price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, true); |
|
| 1450 | + } |
|
| 1451 | + |
|
| 1452 | + $select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"'; |
|
| 1453 | + $main_name = $select_name; |
|
| 1454 | + $select_name = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name; |
|
| 1455 | + |
|
| 1456 | + $template_args = array( |
|
| 1457 | + 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1458 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $prcrow, |
|
| 1459 | + 'price_modifier_selector' => EEH_Form_Fields::select_input($select_name, $all_price_types, |
|
| 1460 | + $selected_price_type_id, $select_params, 'edit-price-PRT_ID'), |
|
| 1461 | + 'main_name' => $main_name, |
|
| 1462 | + 'selected_price_type_id' => $selected_price_type_id, |
|
| 1463 | + 'price_option_spans' => $price_option_spans, |
|
| 1464 | + 'price_selected_operator' => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'), |
|
| 1465 | + 'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0), |
|
| 1466 | + 'disabled' => $disabled |
|
| 1467 | + ); |
|
| 1468 | + |
|
| 1469 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 1470 | + $template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event); |
|
| 1471 | + |
|
| 1472 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php'; |
|
| 1473 | + |
|
| 1474 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1475 | + } |
|
| 1476 | 1476 | |
| 1477 | 1477 | |
| 1478 | - protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default) |
|
| 1479 | - { |
|
| 1480 | - $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
| 1481 | - $template_args = array( |
|
| 1482 | - 'dtt_row' => $default && ! $dtt instanceof EE_Datetime ? 'DTTNUM' : $dttrow, |
|
| 1483 | - 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1484 | - 'ticket_datetime_selected' => in_array($dttrow, $tkt_dtts) ? ' ticket-selected' : '', |
|
| 1485 | - 'ticket_datetime_checked' => in_array($dttrow, $tkt_dtts) ? ' checked="checked"' : '', |
|
| 1486 | - 'DTT_name' => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(true), |
|
| 1487 | - 'tkt_status_class' => '', |
|
| 1488 | - ); |
|
| 1489 | - |
|
| 1490 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 1491 | - $template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event); |
|
| 1492 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php'; |
|
| 1493 | - |
|
| 1494 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1495 | - } |
|
| 1478 | + protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default) |
|
| 1479 | + { |
|
| 1480 | + $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array(); |
|
| 1481 | + $template_args = array( |
|
| 1482 | + 'dtt_row' => $default && ! $dtt instanceof EE_Datetime ? 'DTTNUM' : $dttrow, |
|
| 1483 | + 'tkt_row' => $default ? 'TICKETNUM' : $tktrow, |
|
| 1484 | + 'ticket_datetime_selected' => in_array($dttrow, $tkt_dtts) ? ' ticket-selected' : '', |
|
| 1485 | + 'ticket_datetime_checked' => in_array($dttrow, $tkt_dtts) ? ' checked="checked"' : '', |
|
| 1486 | + 'DTT_name' => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(true), |
|
| 1487 | + 'tkt_status_class' => '', |
|
| 1488 | + ); |
|
| 1489 | + |
|
| 1490 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 1491 | + $template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event); |
|
| 1492 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php'; |
|
| 1493 | + |
|
| 1494 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1495 | + } |
|
| 1496 | 1496 | |
| 1497 | 1497 | |
| 1498 | - protected function _get_ticket_js_structure($all_dtts, $all_tickets) |
|
| 1499 | - { |
|
| 1500 | - $template_args = array( |
|
| 1501 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row('DTTNUM', null, true, $all_dtts), |
|
| 1502 | - 'default_ticket_row' => $this->_get_ticket_row('TICKETNUM', null, array(), array(), |
|
| 1503 | - true), |
|
| 1504 | - 'default_price_row' => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', null, |
|
| 1505 | - true, null), |
|
| 1506 | - 'default_price_rows' => '', |
|
| 1507 | - 'default_base_price_amount' => 0, |
|
| 1508 | - 'default_base_price_name' => '', |
|
| 1509 | - 'default_base_price_description' => '', |
|
| 1510 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM', |
|
| 1511 | - null, true), |
|
| 1512 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row('DTTNUM', null, array(), |
|
| 1513 | - array(), true), |
|
| 1514 | - 'existing_available_datetime_tickets_list' => '', |
|
| 1515 | - 'existing_available_ticket_datetimes_list' => '', |
|
| 1516 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM', |
|
| 1517 | - null, null, array(), true), |
|
| 1518 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM', |
|
| 1519 | - null, null, array(), true) |
|
| 1520 | - ); |
|
| 1521 | - |
|
| 1522 | - $tktrow = 1; |
|
| 1523 | - foreach ($all_tickets as $ticket) { |
|
| 1524 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM', |
|
| 1525 | - $tktrow, null, $ticket, array(), true); |
|
| 1526 | - $tktrow++; |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - |
|
| 1530 | - $dttrow = 1; |
|
| 1531 | - foreach ($all_dtts as $dtt) { |
|
| 1532 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, |
|
| 1533 | - 'TICKETNUM', $dtt, null, array(), true); |
|
| 1534 | - $dttrow++; |
|
| 1535 | - } |
|
| 1536 | - |
|
| 1537 | - $default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices(); |
|
| 1538 | - $prcrow = 1; |
|
| 1539 | - foreach ($default_prices as $price) { |
|
| 1540 | - if ($price->is_base_price()) { |
|
| 1541 | - $template_args['default_base_price_amount'] = $price->get_pretty('PRC_amount', 'localized_float'); |
|
| 1542 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 1543 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 1544 | - $prcrow++; |
|
| 1545 | - continue; |
|
| 1546 | - } |
|
| 1547 | - $show_trash = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? false : true; |
|
| 1548 | - $show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? false : true; |
|
| 1549 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, true, |
|
| 1550 | - null, $show_trash, $show_create); |
|
| 1551 | - $prcrow++; |
|
| 1552 | - } |
|
| 1553 | - |
|
| 1554 | - $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 1555 | - $template_args, $all_dtts, $all_tickets, $this->_is_creating_event); |
|
| 1556 | - |
|
| 1557 | - $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php'; |
|
| 1558 | - |
|
| 1559 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1560 | - } |
|
| 1498 | + protected function _get_ticket_js_structure($all_dtts, $all_tickets) |
|
| 1499 | + { |
|
| 1500 | + $template_args = array( |
|
| 1501 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row('DTTNUM', null, true, $all_dtts), |
|
| 1502 | + 'default_ticket_row' => $this->_get_ticket_row('TICKETNUM', null, array(), array(), |
|
| 1503 | + true), |
|
| 1504 | + 'default_price_row' => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', null, |
|
| 1505 | + true, null), |
|
| 1506 | + 'default_price_rows' => '', |
|
| 1507 | + 'default_base_price_amount' => 0, |
|
| 1508 | + 'default_base_price_name' => '', |
|
| 1509 | + 'default_base_price_description' => '', |
|
| 1510 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM', |
|
| 1511 | + null, true), |
|
| 1512 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row('DTTNUM', null, array(), |
|
| 1513 | + array(), true), |
|
| 1514 | + 'existing_available_datetime_tickets_list' => '', |
|
| 1515 | + 'existing_available_ticket_datetimes_list' => '', |
|
| 1516 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM', |
|
| 1517 | + null, null, array(), true), |
|
| 1518 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM', |
|
| 1519 | + null, null, array(), true) |
|
| 1520 | + ); |
|
| 1521 | + |
|
| 1522 | + $tktrow = 1; |
|
| 1523 | + foreach ($all_tickets as $ticket) { |
|
| 1524 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM', |
|
| 1525 | + $tktrow, null, $ticket, array(), true); |
|
| 1526 | + $tktrow++; |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + $dttrow = 1; |
|
| 1531 | + foreach ($all_dtts as $dtt) { |
|
| 1532 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, |
|
| 1533 | + 'TICKETNUM', $dtt, null, array(), true); |
|
| 1534 | + $dttrow++; |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + $default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices(); |
|
| 1538 | + $prcrow = 1; |
|
| 1539 | + foreach ($default_prices as $price) { |
|
| 1540 | + if ($price->is_base_price()) { |
|
| 1541 | + $template_args['default_base_price_amount'] = $price->get_pretty('PRC_amount', 'localized_float'); |
|
| 1542 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 1543 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 1544 | + $prcrow++; |
|
| 1545 | + continue; |
|
| 1546 | + } |
|
| 1547 | + $show_trash = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? false : true; |
|
| 1548 | + $show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? false : true; |
|
| 1549 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, true, |
|
| 1550 | + null, $show_trash, $show_create); |
|
| 1551 | + $prcrow++; |
|
| 1552 | + } |
|
| 1553 | + |
|
| 1554 | + $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 1555 | + $template_args, $all_dtts, $all_tickets, $this->_is_creating_event); |
|
| 1556 | + |
|
| 1557 | + $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php'; |
|
| 1558 | + |
|
| 1559 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1560 | + } |
|
| 1561 | 1561 | |
| 1562 | 1562 | |
| 1563 | 1563 | } //end class espresso_events_Pricing_Hooks |
@@ -16,1372 +16,1372 @@ |
||
| 16 | 16 | class EE_Registry |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * EE_Registry Object |
|
| 21 | - * |
|
| 22 | - * @var EE_Registry $_instance |
|
| 23 | - * @access private |
|
| 24 | - */ |
|
| 25 | - private static $_instance = null; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var EE_Dependency_Map $_dependency_map |
|
| 29 | - * @access protected |
|
| 30 | - */ |
|
| 31 | - protected $_dependency_map = null; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var array $_class_abbreviations |
|
| 35 | - * @access protected |
|
| 36 | - */ |
|
| 37 | - protected $_class_abbreviations = array(); |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @access public |
|
| 41 | - * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
| 42 | - */ |
|
| 43 | - public $BUS; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * EE_Cart Object |
|
| 47 | - * |
|
| 48 | - * @access public |
|
| 49 | - * @var EE_Cart $CART |
|
| 50 | - */ |
|
| 51 | - public $CART = null; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * EE_Config Object |
|
| 55 | - * |
|
| 56 | - * @access public |
|
| 57 | - * @var EE_Config $CFG |
|
| 58 | - */ |
|
| 59 | - public $CFG = null; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * EE_Network_Config Object |
|
| 63 | - * |
|
| 64 | - * @access public |
|
| 65 | - * @var EE_Network_Config $NET_CFG |
|
| 66 | - */ |
|
| 67 | - public $NET_CFG = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * StdClass object for storing library classes in |
|
| 71 | - * |
|
| 72 | - * @public LIB |
|
| 73 | - * @var StdClass $LIB |
|
| 74 | - */ |
|
| 75 | - public $LIB = null; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * EE_Request_Handler Object |
|
| 79 | - * |
|
| 80 | - * @access public |
|
| 81 | - * @var EE_Request_Handler $REQ |
|
| 82 | - */ |
|
| 83 | - public $REQ = null; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * EE_Session Object |
|
| 87 | - * |
|
| 88 | - * @access public |
|
| 89 | - * @var EE_Session $SSN |
|
| 90 | - */ |
|
| 91 | - public $SSN = null; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * holds the ee capabilities object. |
|
| 95 | - * |
|
| 96 | - * @since 4.5.0 |
|
| 97 | - * @var EE_Capabilities |
|
| 98 | - */ |
|
| 99 | - public $CAP = null; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * holds the EE_Message_Resource_Manager object. |
|
| 103 | - * |
|
| 104 | - * @since 4.9.0 |
|
| 105 | - * @var EE_Message_Resource_Manager |
|
| 106 | - */ |
|
| 107 | - public $MRM = null; |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Holds the Assets Registry instance |
|
| 112 | - * @var Registry |
|
| 113 | - */ |
|
| 114 | - public $AssetsRegistry = null; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
| 118 | - * |
|
| 119 | - * @access public |
|
| 120 | - * @var EE_Addon[] |
|
| 121 | - */ |
|
| 122 | - public $addons = null; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * $models |
|
| 126 | - * @access public |
|
| 127 | - * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 128 | - */ |
|
| 129 | - public $models = array(); |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * $modules |
|
| 133 | - * @access public |
|
| 134 | - * @var EED_Module[] $modules |
|
| 135 | - */ |
|
| 136 | - public $modules = null; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * $shortcodes |
|
| 140 | - * @access public |
|
| 141 | - * @var EES_Shortcode[] $shortcodes |
|
| 142 | - */ |
|
| 143 | - public $shortcodes = null; |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * $widgets |
|
| 147 | - * @access public |
|
| 148 | - * @var WP_Widget[] $widgets |
|
| 149 | - */ |
|
| 150 | - public $widgets = null; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * $non_abstract_db_models |
|
| 154 | - * @access public |
|
| 155 | - * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 156 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 157 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 158 | - * classnames (eg "EEM_Event") |
|
| 159 | - */ |
|
| 160 | - public $non_abstract_db_models = array(); |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * $i18n_js_strings - internationalization for JS strings |
|
| 165 | - * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
| 166 | - * in js file: var translatedString = eei18n.string_key; |
|
| 167 | - * |
|
| 168 | - * @access public |
|
| 169 | - * @var array |
|
| 170 | - */ |
|
| 171 | - public static $i18n_js_strings = array(); |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * $main_file - path to espresso.php |
|
| 176 | - * |
|
| 177 | - * @access public |
|
| 178 | - * @var array |
|
| 179 | - */ |
|
| 180 | - public $main_file; |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * array of ReflectionClass objects where the key is the class name |
|
| 184 | - * |
|
| 185 | - * @access public |
|
| 186 | - * @var ReflectionClass[] |
|
| 187 | - */ |
|
| 188 | - public $_reflectors; |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 192 | - * |
|
| 193 | - * @access protected |
|
| 194 | - * @var boolean $_cache_on |
|
| 195 | - */ |
|
| 196 | - protected $_cache_on = true; |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @singleton method used to instantiate class object |
|
| 202 | - * @access public |
|
| 203 | - * @param \EE_Dependency_Map $dependency_map |
|
| 204 | - * @return \EE_Registry instance |
|
| 205 | - */ |
|
| 206 | - public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
| 207 | - { |
|
| 208 | - // check if class object is instantiated |
|
| 209 | - if ( ! self::$_instance instanceof EE_Registry) { |
|
| 210 | - self::$_instance = new EE_Registry($dependency_map); |
|
| 211 | - } |
|
| 212 | - return self::$_instance; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - *protected constructor to prevent direct creation |
|
| 219 | - * |
|
| 220 | - * @Constructor |
|
| 221 | - * @access protected |
|
| 222 | - * @param \EE_Dependency_Map $dependency_map |
|
| 223 | - * @return \EE_Registry |
|
| 224 | - */ |
|
| 225 | - protected function __construct(\EE_Dependency_Map $dependency_map) |
|
| 226 | - { |
|
| 227 | - $this->_dependency_map = $dependency_map; |
|
| 228 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * initialize |
|
| 235 | - */ |
|
| 236 | - public function initialize() |
|
| 237 | - { |
|
| 238 | - $this->_class_abbreviations = apply_filters( |
|
| 239 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 240 | - array( |
|
| 241 | - 'EE_Config' => 'CFG', |
|
| 242 | - 'EE_Session' => 'SSN', |
|
| 243 | - 'EE_Capabilities' => 'CAP', |
|
| 244 | - 'EE_Cart' => 'CART', |
|
| 245 | - 'EE_Network_Config' => 'NET_CFG', |
|
| 246 | - 'EE_Request_Handler' => 'REQ', |
|
| 247 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
| 248 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 249 | - ) |
|
| 250 | - ); |
|
| 251 | - // class library |
|
| 252 | - $this->LIB = new stdClass(); |
|
| 253 | - $this->addons = new stdClass(); |
|
| 254 | - $this->modules = new stdClass(); |
|
| 255 | - $this->shortcodes = new stdClass(); |
|
| 256 | - $this->widgets = new stdClass(); |
|
| 257 | - $this->load_core('Base', array(), true); |
|
| 258 | - // add our request and response objects to the cache |
|
| 259 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 260 | - $this->_set_cached_class( |
|
| 261 | - $request_loader(), |
|
| 262 | - 'EE_Request' |
|
| 263 | - ); |
|
| 264 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 265 | - $this->_set_cached_class( |
|
| 266 | - $response_loader(), |
|
| 267 | - 'EE_Response' |
|
| 268 | - ); |
|
| 269 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * init |
|
| 276 | - * |
|
| 277 | - * @access public |
|
| 278 | - * @return void |
|
| 279 | - */ |
|
| 280 | - public function init() |
|
| 281 | - { |
|
| 282 | - $this->AssetsRegistry = new Registry(); |
|
| 283 | - // Get current page protocol |
|
| 284 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 285 | - // Output admin-ajax.php URL with same protocol as current page |
|
| 286 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 287 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * localize_i18n_js_strings |
|
| 294 | - * |
|
| 295 | - * @return string |
|
| 296 | - */ |
|
| 297 | - public static function localize_i18n_js_strings() |
|
| 298 | - { |
|
| 299 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
| 300 | - foreach ($i18n_js_strings as $key => $value) { |
|
| 301 | - if (is_scalar($value)) { |
|
| 302 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @param mixed string | EED_Module $module |
|
| 312 | - */ |
|
| 313 | - public function add_module($module) |
|
| 314 | - { |
|
| 315 | - if ($module instanceof EED_Module) { |
|
| 316 | - $module_class = get_class($module); |
|
| 317 | - $this->modules->{$module_class} = $module; |
|
| 318 | - } else { |
|
| 319 | - if ( ! class_exists('EE_Module_Request_Router')) { |
|
| 320 | - $this->load_core('Module_Request_Router'); |
|
| 321 | - } |
|
| 322 | - $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @param string $module_name |
|
| 330 | - * @return mixed EED_Module | NULL |
|
| 331 | - */ |
|
| 332 | - public function get_module($module_name = '') |
|
| 333 | - { |
|
| 334 | - return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * loads core classes - must be singletons |
|
| 341 | - * |
|
| 342 | - * @access public |
|
| 343 | - * @param string $class_name - simple class name ie: session |
|
| 344 | - * @param mixed $arguments |
|
| 345 | - * @param bool $load_only |
|
| 346 | - * @return mixed |
|
| 347 | - */ |
|
| 348 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 349 | - { |
|
| 350 | - $core_paths = apply_filters( |
|
| 351 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
| 352 | - array( |
|
| 353 | - EE_CORE, |
|
| 354 | - EE_ADMIN, |
|
| 355 | - EE_CPTS, |
|
| 356 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 357 | - EE_CORE . 'request_stack' . DS, |
|
| 358 | - EE_CORE . 'middleware' . DS, |
|
| 359 | - ) |
|
| 360 | - ); |
|
| 361 | - // retrieve instantiated class |
|
| 362 | - return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * loads service classes |
|
| 369 | - * |
|
| 370 | - * @access public |
|
| 371 | - * @param string $class_name - simple class name ie: session |
|
| 372 | - * @param mixed $arguments |
|
| 373 | - * @param bool $load_only |
|
| 374 | - * @return mixed |
|
| 375 | - */ |
|
| 376 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 377 | - { |
|
| 378 | - $service_paths = apply_filters( |
|
| 379 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
| 380 | - array( |
|
| 381 | - EE_CORE . 'services' . DS, |
|
| 382 | - ) |
|
| 383 | - ); |
|
| 384 | - // retrieve instantiated class |
|
| 385 | - return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * loads data_migration_scripts |
|
| 392 | - * |
|
| 393 | - * @access public |
|
| 394 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 395 | - * @param mixed $arguments |
|
| 396 | - * @return EE_Data_Migration_Script_Base|mixed |
|
| 397 | - */ |
|
| 398 | - public function load_dms($class_name, $arguments = array()) |
|
| 399 | - { |
|
| 400 | - // retrieve instantiated class |
|
| 401 | - return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * loads object creating classes - must be singletons |
|
| 408 | - * |
|
| 409 | - * @param string $class_name - simple class name ie: attendee |
|
| 410 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
| 411 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
| 412 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 413 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
| 414 | - * @return EE_Base_Class | bool |
|
| 415 | - */ |
|
| 416 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 417 | - { |
|
| 418 | - $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
| 419 | - EE_CORE, |
|
| 420 | - EE_CLASSES, |
|
| 421 | - EE_BUSINESS, |
|
| 422 | - )); |
|
| 423 | - // retrieve instantiated class |
|
| 424 | - return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * loads helper classes - must be singletons |
|
| 431 | - * |
|
| 432 | - * @param string $class_name - simple class name ie: price |
|
| 433 | - * @param mixed $arguments |
|
| 434 | - * @param bool $load_only |
|
| 435 | - * @return EEH_Base | bool |
|
| 436 | - */ |
|
| 437 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 438 | - { |
|
| 439 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 440 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 441 | - // retrieve instantiated class |
|
| 442 | - return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * loads core classes - must be singletons |
|
| 449 | - * |
|
| 450 | - * @access public |
|
| 451 | - * @param string $class_name - simple class name ie: session |
|
| 452 | - * @param mixed $arguments |
|
| 453 | - * @param bool $load_only |
|
| 454 | - * @param bool $cache whether to cache the object or not. |
|
| 455 | - * @return mixed |
|
| 456 | - */ |
|
| 457 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 458 | - { |
|
| 459 | - $paths = array( |
|
| 460 | - EE_LIBRARIES, |
|
| 461 | - EE_LIBRARIES . 'messages' . DS, |
|
| 462 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 463 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 464 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 465 | - ); |
|
| 466 | - // retrieve instantiated class |
|
| 467 | - return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * loads model classes - must be singletons |
|
| 474 | - * |
|
| 475 | - * @param string $class_name - simple class name ie: price |
|
| 476 | - * @param mixed $arguments |
|
| 477 | - * @param bool $load_only |
|
| 478 | - * @return EEM_Base | bool |
|
| 479 | - */ |
|
| 480 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 481 | - { |
|
| 482 | - $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
| 483 | - EE_MODELS, |
|
| 484 | - EE_CORE, |
|
| 485 | - )); |
|
| 486 | - // retrieve instantiated class |
|
| 487 | - return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * loads model classes - must be singletons |
|
| 494 | - * |
|
| 495 | - * @param string $class_name - simple class name ie: price |
|
| 496 | - * @param mixed $arguments |
|
| 497 | - * @param bool $load_only |
|
| 498 | - * @return mixed | bool |
|
| 499 | - */ |
|
| 500 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 501 | - { |
|
| 502 | - $paths = array( |
|
| 503 | - EE_MODELS . 'fields' . DS, |
|
| 504 | - EE_MODELS . 'helpers' . DS, |
|
| 505 | - EE_MODELS . 'relations' . DS, |
|
| 506 | - EE_MODELS . 'strategies' . DS, |
|
| 507 | - ); |
|
| 508 | - // retrieve instantiated class |
|
| 509 | - return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Determines if $model_name is the name of an actual EE model. |
|
| 516 | - * |
|
| 517 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 518 | - * @return boolean |
|
| 519 | - */ |
|
| 520 | - public function is_model_name($model_name) |
|
| 521 | - { |
|
| 522 | - return isset($this->models[$model_name]) ? true : false; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * generic class loader |
|
| 529 | - * |
|
| 530 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 531 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
| 532 | - * @param string $type - file type - core? class? helper? model? |
|
| 533 | - * @param mixed $arguments |
|
| 534 | - * @param bool $load_only |
|
| 535 | - * @return mixed |
|
| 536 | - */ |
|
| 537 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 538 | - { |
|
| 539 | - // retrieve instantiated class |
|
| 540 | - return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * load_addon |
|
| 547 | - * |
|
| 548 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 549 | - * @param string $class_name - full class name ie: My_Class |
|
| 550 | - * @param string $type - file type - core? class? helper? model? |
|
| 551 | - * @param mixed $arguments |
|
| 552 | - * @param bool $load_only |
|
| 553 | - * @return EE_Addon |
|
| 554 | - */ |
|
| 555 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 556 | - { |
|
| 557 | - // retrieve instantiated class |
|
| 558 | - return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * instantiates, caches, and automatically resolves dependencies |
|
| 565 | - * for classes that use a Fully Qualified Class Name. |
|
| 566 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 567 | - * then you need to use one of the existing load_*() methods |
|
| 568 | - * which can resolve the classname and filepath from the passed arguments |
|
| 569 | - * |
|
| 570 | - * @param bool|string $class_name Fully Qualified Class Name |
|
| 571 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 572 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 573 | - * @param bool $from_db some classes are instantiated from the db |
|
| 574 | - * and thus call a different method to instantiate |
|
| 575 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 576 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 577 | - * @return mixed null = failure to load or instantiate class object. |
|
| 578 | - * object = class loaded and instantiated successfully. |
|
| 579 | - * bool = fail or success when $load_only is true |
|
| 580 | - */ |
|
| 581 | - public function create( |
|
| 582 | - $class_name = false, |
|
| 583 | - $arguments = array(), |
|
| 584 | - $cache = false, |
|
| 585 | - $from_db = false, |
|
| 586 | - $load_only = false, |
|
| 587 | - $addon = false |
|
| 588 | - ) { |
|
| 589 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 590 | - if ( ! class_exists($class_name)) { |
|
| 591 | - // maybe the class is registered with a preceding \ |
|
| 592 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
| 593 | - // still doesn't exist ? |
|
| 594 | - if ( ! class_exists($class_name)) { |
|
| 595 | - return null; |
|
| 596 | - } |
|
| 597 | - } |
|
| 598 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 599 | - if ($load_only) { |
|
| 600 | - return true; |
|
| 601 | - } |
|
| 602 | - $addon = $addon ? 'addon' : ''; |
|
| 603 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 604 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 605 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 606 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 607 | - // return object if it's already cached |
|
| 608 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 609 | - if ($cached_class !== null) { |
|
| 610 | - return $cached_class; |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - // instantiate the requested object |
|
| 614 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 615 | - if ($this->_cache_on && $cache) { |
|
| 616 | - // save it for later... kinda like gum { : $ |
|
| 617 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 618 | - } |
|
| 619 | - $this->_cache_on = true; |
|
| 620 | - return $class_obj; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - /** |
|
| 626 | - * instantiates, caches, and injects dependencies for classes |
|
| 627 | - * |
|
| 628 | - * @param array $file_paths an array of paths to folders to look in |
|
| 629 | - * @param string $class_prefix EE or EEM or... ??? |
|
| 630 | - * @param bool|string $class_name $class name |
|
| 631 | - * @param string $type file type - core? class? helper? model? |
|
| 632 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 633 | - * @param bool $from_db some classes are instantiated from the db |
|
| 634 | - * and thus call a different method to instantiate |
|
| 635 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 636 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 637 | - * @return null|object|bool null = failure to load or instantiate class object. |
|
| 638 | - * object = class loaded and instantiated successfully. |
|
| 639 | - * bool = fail or success when $load_only is true |
|
| 640 | - */ |
|
| 641 | - protected function _load( |
|
| 642 | - $file_paths = array(), |
|
| 643 | - $class_prefix = 'EE_', |
|
| 644 | - $class_name = false, |
|
| 645 | - $type = 'class', |
|
| 646 | - $arguments = array(), |
|
| 647 | - $from_db = false, |
|
| 648 | - $cache = true, |
|
| 649 | - $load_only = false |
|
| 650 | - ) { |
|
| 651 | - // strip php file extension |
|
| 652 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
| 653 | - // does the class have a prefix ? |
|
| 654 | - if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
| 655 | - // make sure $class_prefix is uppercase |
|
| 656 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
| 657 | - // add class prefix ONCE!!! |
|
| 658 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 659 | - } |
|
| 660 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 661 | - $class_exists = class_exists($class_name); |
|
| 662 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 663 | - if ($load_only && $class_exists) { |
|
| 664 | - return true; |
|
| 665 | - } |
|
| 666 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 667 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 668 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 669 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 670 | - // return object if it's already cached |
|
| 671 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 672 | - if ($cached_class !== null) { |
|
| 673 | - return $cached_class; |
|
| 674 | - } |
|
| 675 | - } |
|
| 676 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 677 | - if ( ! $class_exists) { |
|
| 678 | - // get full path to file |
|
| 679 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 680 | - // load the file |
|
| 681 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 682 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 683 | - if ( ! $loaded || $load_only) { |
|
| 684 | - // return boolean if only loading, or null if an object was expected |
|
| 685 | - return $load_only ? $loaded : null; |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - // instantiate the requested object |
|
| 689 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 690 | - if ($this->_cache_on && $cache) { |
|
| 691 | - // save it for later... kinda like gum { : $ |
|
| 692 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 693 | - } |
|
| 694 | - $this->_cache_on = true; |
|
| 695 | - return $class_obj; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * _get_cached_class |
|
| 702 | - * attempts to find a cached version of the requested class |
|
| 703 | - * by looking in the following places: |
|
| 704 | - * $this->{$class_abbreviation} ie: $this->CART |
|
| 705 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 706 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 707 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 708 | - * |
|
| 709 | - * @access protected |
|
| 710 | - * @param string $class_name |
|
| 711 | - * @param string $class_prefix |
|
| 712 | - * @return mixed |
|
| 713 | - */ |
|
| 714 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 715 | - { |
|
| 716 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
| 717 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
| 718 | - } else { |
|
| 719 | - // have to specify something, but not anything that will conflict |
|
| 720 | - $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
| 721 | - } |
|
| 722 | - // check if class has already been loaded, and return it if it has been |
|
| 723 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
| 724 | - return $this->{$class_abbreviation}; |
|
| 725 | - } else if (isset ($this->{$class_name})) { |
|
| 726 | - return $this->{$class_name}; |
|
| 727 | - } else if (isset ($this->LIB->{$class_name})) { |
|
| 728 | - return $this->LIB->{$class_name}; |
|
| 729 | - } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
| 730 | - return $this->addons->{$class_name}; |
|
| 731 | - } |
|
| 732 | - return null; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * _resolve_path |
|
| 739 | - * attempts to find a full valid filepath for the requested class. |
|
| 740 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 741 | - * then returns that path if the target file has been found and is readable |
|
| 742 | - * |
|
| 743 | - * @access protected |
|
| 744 | - * @param string $class_name |
|
| 745 | - * @param string $type |
|
| 746 | - * @param array $file_paths |
|
| 747 | - * @return string | bool |
|
| 748 | - */ |
|
| 749 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 750 | - { |
|
| 751 | - // make sure $file_paths is an array |
|
| 752 | - $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
| 753 | - // cycle thru paths |
|
| 754 | - foreach ($file_paths as $key => $file_path) { |
|
| 755 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 756 | - $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
| 757 | - // prep file type |
|
| 758 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
| 759 | - // build full file path |
|
| 760 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 761 | - //does the file exist and can be read ? |
|
| 762 | - if (is_readable($file_paths[$key])) { |
|
| 763 | - return $file_paths[$key]; |
|
| 764 | - } |
|
| 765 | - } |
|
| 766 | - return false; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * _require_file |
|
| 773 | - * basically just performs a require_once() |
|
| 774 | - * but with some error handling |
|
| 775 | - * |
|
| 776 | - * @access protected |
|
| 777 | - * @param string $path |
|
| 778 | - * @param string $class_name |
|
| 779 | - * @param string $type |
|
| 780 | - * @param array $file_paths |
|
| 781 | - * @return boolean |
|
| 782 | - * @throws \EE_Error |
|
| 783 | - */ |
|
| 784 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 785 | - { |
|
| 786 | - // don't give up! you gotta... |
|
| 787 | - try { |
|
| 788 | - //does the file exist and can it be read ? |
|
| 789 | - if ( ! $path) { |
|
| 790 | - // so sorry, can't find the file |
|
| 791 | - throw new EE_Error ( |
|
| 792 | - sprintf( |
|
| 793 | - __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
| 794 | - trim($type, '.'), |
|
| 795 | - $class_name, |
|
| 796 | - '<br />' . implode(',<br />', $file_paths) |
|
| 797 | - ) |
|
| 798 | - ); |
|
| 799 | - } |
|
| 800 | - // get the file |
|
| 801 | - require_once($path); |
|
| 802 | - // if the class isn't already declared somewhere |
|
| 803 | - if (class_exists($class_name, false) === false) { |
|
| 804 | - // so sorry, not a class |
|
| 805 | - throw new EE_Error( |
|
| 806 | - sprintf( |
|
| 807 | - __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 808 | - $type, |
|
| 809 | - $path, |
|
| 810 | - $class_name |
|
| 811 | - ) |
|
| 812 | - ); |
|
| 813 | - } |
|
| 814 | - } catch (EE_Error $e) { |
|
| 815 | - $e->get_error(); |
|
| 816 | - return false; |
|
| 817 | - } |
|
| 818 | - return true; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * _create_object |
|
| 825 | - * Attempts to instantiate the requested class via any of the |
|
| 826 | - * commonly used instantiation methods employed throughout EE. |
|
| 827 | - * The priority for instantiation is as follows: |
|
| 828 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 829 | - * - model objects via their 'new_instance_from_db' method |
|
| 830 | - * - model objects via their 'new_instance' method |
|
| 831 | - * - "singleton" classes" via their 'instance' method |
|
| 832 | - * - standard instantiable classes via their __constructor |
|
| 833 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 834 | - * then the constructor for the requested class will be examined to determine |
|
| 835 | - * if any dependencies exist, and if they can be injected. |
|
| 836 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 837 | - * |
|
| 838 | - * @access protected |
|
| 839 | - * @param string $class_name |
|
| 840 | - * @param array $arguments |
|
| 841 | - * @param string $type |
|
| 842 | - * @param bool $from_db |
|
| 843 | - * @return null | object |
|
| 844 | - * @throws \EE_Error |
|
| 845 | - */ |
|
| 846 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 847 | - { |
|
| 848 | - $class_obj = null; |
|
| 849 | - $instantiation_mode = '0) none'; |
|
| 850 | - // don't give up! you gotta... |
|
| 851 | - try { |
|
| 852 | - // create reflection |
|
| 853 | - $reflector = $this->get_ReflectionClass($class_name); |
|
| 854 | - // make sure arguments are an array |
|
| 855 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
| 856 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 857 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 858 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 859 | - ? $arguments |
|
| 860 | - : array($arguments); |
|
| 861 | - // attempt to inject dependencies ? |
|
| 862 | - if ($this->_dependency_map->has($class_name)) { |
|
| 863 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 864 | - } |
|
| 865 | - // instantiate the class if possible |
|
| 866 | - if ($reflector->isAbstract()) { |
|
| 867 | - // nothing to instantiate, loading file was enough |
|
| 868 | - // does not throw an exception so $instantiation_mode is unused |
|
| 869 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
| 870 | - $class_obj = true; |
|
| 871 | - } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
| 872 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 873 | - $instantiation_mode = "2) no constructor but instantiable"; |
|
| 874 | - $class_obj = $reflector->newInstance(); |
|
| 875 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 876 | - $instantiation_mode = "3) new_instance_from_db()"; |
|
| 877 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 878 | - } else if (method_exists($class_name, 'new_instance')) { |
|
| 879 | - $instantiation_mode = "4) new_instance()"; |
|
| 880 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 881 | - } else if (method_exists($class_name, 'instance')) { |
|
| 882 | - $instantiation_mode = "5) instance()"; |
|
| 883 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 884 | - } else if ($reflector->isInstantiable()) { |
|
| 885 | - $instantiation_mode = "6) constructor"; |
|
| 886 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
| 887 | - } else { |
|
| 888 | - // heh ? something's not right ! |
|
| 889 | - throw new EE_Error( |
|
| 890 | - sprintf( |
|
| 891 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 892 | - $type, |
|
| 893 | - $class_name |
|
| 894 | - ) |
|
| 895 | - ); |
|
| 896 | - } |
|
| 897 | - } catch (Exception $e) { |
|
| 898 | - if ( ! $e instanceof EE_Error) { |
|
| 899 | - $e = new EE_Error( |
|
| 900 | - sprintf( |
|
| 901 | - __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
| 902 | - $class_name, |
|
| 903 | - '<br />', |
|
| 904 | - $e->getMessage(), |
|
| 905 | - $instantiation_mode |
|
| 906 | - ) |
|
| 907 | - ); |
|
| 908 | - } |
|
| 909 | - $e->get_error(); |
|
| 910 | - } |
|
| 911 | - return $class_obj; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 918 | - * @param array $array |
|
| 919 | - * @return bool |
|
| 920 | - */ |
|
| 921 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 922 | - { |
|
| 923 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * getReflectionClass |
|
| 930 | - * checks if a ReflectionClass object has already been generated for a class |
|
| 931 | - * and returns that instead of creating a new one |
|
| 932 | - * |
|
| 933 | - * @access public |
|
| 934 | - * @param string $class_name |
|
| 935 | - * @return ReflectionClass |
|
| 936 | - */ |
|
| 937 | - public function get_ReflectionClass($class_name) |
|
| 938 | - { |
|
| 939 | - if ( |
|
| 940 | - ! isset($this->_reflectors[$class_name]) |
|
| 941 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 942 | - ) { |
|
| 943 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 944 | - } |
|
| 945 | - return $this->_reflectors[$class_name]; |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - |
|
| 949 | - |
|
| 950 | - /** |
|
| 951 | - * _resolve_dependencies |
|
| 952 | - * examines the constructor for the requested class to determine |
|
| 953 | - * if any dependencies exist, and if they can be injected. |
|
| 954 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 955 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 956 | - * For example: |
|
| 957 | - * if attempting to load a class "Foo" with the following constructor: |
|
| 958 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 959 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 960 | - * but only IF they are NOT already present in the incoming arguments array, |
|
| 961 | - * and the correct classes can be loaded |
|
| 962 | - * |
|
| 963 | - * @access protected |
|
| 964 | - * @param ReflectionClass $reflector |
|
| 965 | - * @param string $class_name |
|
| 966 | - * @param array $arguments |
|
| 967 | - * @return array |
|
| 968 | - * @throws \ReflectionException |
|
| 969 | - */ |
|
| 970 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 971 | - { |
|
| 972 | - // let's examine the constructor |
|
| 973 | - $constructor = $reflector->getConstructor(); |
|
| 974 | - // whu? huh? nothing? |
|
| 975 | - if ( ! $constructor) { |
|
| 976 | - return $arguments; |
|
| 977 | - } |
|
| 978 | - // get constructor parameters |
|
| 979 | - $params = $constructor->getParameters(); |
|
| 980 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 981 | - $argument_keys = array_keys($arguments); |
|
| 982 | - // now loop thru all of the constructors expected parameters |
|
| 983 | - foreach ($params as $index => $param) { |
|
| 984 | - // is this a dependency for a specific class ? |
|
| 985 | - $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
| 986 | - if ( |
|
| 987 | - // param is not even a class |
|
| 988 | - empty($param_class) |
|
| 989 | - // and something already exists in the incoming arguments for this param |
|
| 990 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 991 | - ) { |
|
| 992 | - // so let's skip this argument and move on to the next |
|
| 993 | - continue; |
|
| 994 | - } else if ( |
|
| 995 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 996 | - ! empty($param_class) |
|
| 997 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 998 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 999 | - ) { |
|
| 1000 | - // skip this argument and move on to the next |
|
| 1001 | - continue; |
|
| 1002 | - } else if ( |
|
| 1003 | - // parameter is type hinted as a class, and should be injected |
|
| 1004 | - ! empty($param_class) |
|
| 1005 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1006 | - ) { |
|
| 1007 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
| 1008 | - } else { |
|
| 1009 | - try { |
|
| 1010 | - $arguments[$index] = $param->getDefaultValue(); |
|
| 1011 | - } catch (ReflectionException $e) { |
|
| 1012 | - throw new ReflectionException( |
|
| 1013 | - sprintf( |
|
| 1014 | - __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
| 1015 | - $e->getMessage(), |
|
| 1016 | - $param->getName() |
|
| 1017 | - ) |
|
| 1018 | - ); |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1021 | - } |
|
| 1022 | - return $arguments; |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - /** |
|
| 1028 | - * @access protected |
|
| 1029 | - * @param string $class_name |
|
| 1030 | - * @param string $param_class |
|
| 1031 | - * @param array $arguments |
|
| 1032 | - * @param mixed $index |
|
| 1033 | - * @return array |
|
| 1034 | - */ |
|
| 1035 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
| 1036 | - { |
|
| 1037 | - $dependency = null; |
|
| 1038 | - // should dependency be loaded from cache ? |
|
| 1039 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
| 1040 | - !== EE_Dependency_Map::load_new_object |
|
| 1041 | - ? true |
|
| 1042 | - : false; |
|
| 1043 | - // we might have a dependency... |
|
| 1044 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1045 | - $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
| 1046 | - // and grab it if it exists |
|
| 1047 | - if ($cached_class instanceof $param_class) { |
|
| 1048 | - $dependency = $cached_class; |
|
| 1049 | - } else if ($param_class != $class_name) { |
|
| 1050 | - // obtain the loader method from the dependency map |
|
| 1051 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1052 | - // is loader a custom closure ? |
|
| 1053 | - if ($loader instanceof Closure) { |
|
| 1054 | - $dependency = $loader(); |
|
| 1055 | - } else { |
|
| 1056 | - // set the cache on property for the recursive loading call |
|
| 1057 | - $this->_cache_on = $cache_on; |
|
| 1058 | - // if not, then let's try and load it via the registry |
|
| 1059 | - if (method_exists($this, $loader)) { |
|
| 1060 | - $dependency = $this->{$loader}($param_class); |
|
| 1061 | - } else { |
|
| 1062 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
| 1063 | - } |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1066 | - // did we successfully find the correct dependency ? |
|
| 1067 | - if ($dependency instanceof $param_class) { |
|
| 1068 | - // then let's inject it into the incoming array of arguments at the correct location |
|
| 1069 | - if (isset($argument_keys[$index])) { |
|
| 1070 | - $arguments[$argument_keys[$index]] = $dependency; |
|
| 1071 | - } else { |
|
| 1072 | - $arguments[$index] = $dependency; |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1075 | - return $arguments; |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - |
|
| 1079 | - |
|
| 1080 | - /** |
|
| 1081 | - * _set_cached_class |
|
| 1082 | - * attempts to cache the instantiated class locally |
|
| 1083 | - * in one of the following places, in the following order: |
|
| 1084 | - * $this->{class_abbreviation} ie: $this->CART |
|
| 1085 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 1086 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1087 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1088 | - * |
|
| 1089 | - * @access protected |
|
| 1090 | - * @param object $class_obj |
|
| 1091 | - * @param string $class_name |
|
| 1092 | - * @param string $class_prefix |
|
| 1093 | - * @param bool $from_db |
|
| 1094 | - * @return void |
|
| 1095 | - */ |
|
| 1096 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1097 | - { |
|
| 1098 | - if (empty($class_obj)) { |
|
| 1099 | - return; |
|
| 1100 | - } |
|
| 1101 | - // return newly instantiated class |
|
| 1102 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
| 1103 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
| 1104 | - $this->{$class_abbreviation} = $class_obj; |
|
| 1105 | - } else if (property_exists($this, $class_name)) { |
|
| 1106 | - $this->{$class_name} = $class_obj; |
|
| 1107 | - } else if ($class_prefix == 'addon') { |
|
| 1108 | - $this->addons->{$class_name} = $class_obj; |
|
| 1109 | - } else if ( ! $from_db) { |
|
| 1110 | - $this->LIB->{$class_name} = $class_obj; |
|
| 1111 | - } |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - |
|
| 1115 | - |
|
| 1116 | - /** |
|
| 1117 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1118 | - * |
|
| 1119 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1120 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1121 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1122 | - * @param array $arguments |
|
| 1123 | - * @return object |
|
| 1124 | - */ |
|
| 1125 | - public static function factory($classname, $arguments = array()) |
|
| 1126 | - { |
|
| 1127 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1128 | - if ($loader instanceof Closure) { |
|
| 1129 | - return $loader($arguments); |
|
| 1130 | - } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
| 1131 | - return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
| 1132 | - } |
|
| 1133 | - return null; |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - |
|
| 1137 | - |
|
| 1138 | - /** |
|
| 1139 | - * Gets the addon by its name/slug (not classname. For that, just |
|
| 1140 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
| 1141 | - * |
|
| 1142 | - * @param string $name |
|
| 1143 | - * @return EE_Addon |
|
| 1144 | - */ |
|
| 1145 | - public function get_addon_by_name($name) |
|
| 1146 | - { |
|
| 1147 | - foreach ($this->addons as $addon) { |
|
| 1148 | - if ($addon->name() == $name) { |
|
| 1149 | - return $addon; |
|
| 1150 | - } |
|
| 1151 | - } |
|
| 1152 | - return null; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - |
|
| 1156 | - |
|
| 1157 | - /** |
|
| 1158 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
| 1159 | - * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
| 1160 | - * |
|
| 1161 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1162 | - */ |
|
| 1163 | - public function get_addons_by_name() |
|
| 1164 | - { |
|
| 1165 | - $addons = array(); |
|
| 1166 | - foreach ($this->addons as $addon) { |
|
| 1167 | - $addons[$addon->name()] = $addon; |
|
| 1168 | - } |
|
| 1169 | - return $addons; |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - |
|
| 1173 | - |
|
| 1174 | - /** |
|
| 1175 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1176 | - * a stale copy of it around |
|
| 1177 | - * |
|
| 1178 | - * @param string $model_name |
|
| 1179 | - * @return \EEM_Base |
|
| 1180 | - * @throws \EE_Error |
|
| 1181 | - */ |
|
| 1182 | - public function reset_model($model_name) |
|
| 1183 | - { |
|
| 1184 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
| 1185 | - if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1186 | - return null; |
|
| 1187 | - } |
|
| 1188 | - //get that model reset it and make sure we nuke the old reference to it |
|
| 1189 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
| 1190 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1191 | - } else { |
|
| 1192 | - throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1193 | - } |
|
| 1194 | - return $this->LIB->{$model_class_name}; |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - |
|
| 1198 | - |
|
| 1199 | - /** |
|
| 1200 | - * Resets the registry. |
|
| 1201 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
| 1202 | - * is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1203 | - * - $_dependency_map |
|
| 1204 | - * - $_class_abbreviations |
|
| 1205 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1206 | - * - $REQ: Still on the same request so no need to change. |
|
| 1207 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1208 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
| 1209 | - * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1210 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1211 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1212 | - * switch or on the restore. |
|
| 1213 | - * - $modules |
|
| 1214 | - * - $shortcodes |
|
| 1215 | - * - $widgets |
|
| 1216 | - * |
|
| 1217 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
| 1218 | - * the Registry to its state at the beginning of the request |
|
| 1219 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1220 | - * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
| 1221 | - * currently reinstantiate the singletons at the moment) |
|
| 1222 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
| 1223 | - * code instead can just change the model context to a different blog id if necessary |
|
| 1224 | - * @return EE_Registry |
|
| 1225 | - */ |
|
| 1226 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1227 | - { |
|
| 1228 | - $instance = self::instance(); |
|
| 1229 | - EEH_Activation::reset(); |
|
| 1230 | - //properties that get reset |
|
| 1231 | - $instance->_cache_on = true; |
|
| 1232 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1233 | - $instance->CART = null; |
|
| 1234 | - $instance->MRM = null; |
|
| 1235 | - $instance->AssetsRegistry = new Registry(); |
|
| 1236 | - //messages reset |
|
| 1237 | - EED_Messages::reset(); |
|
| 1238 | - if ($reset_models) { |
|
| 1239 | - foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
| 1240 | - $instance->reset_model($model_name); |
|
| 1241 | - } |
|
| 1242 | - } |
|
| 1243 | - $instance->LIB = new stdClass(); |
|
| 1244 | - return $instance; |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - |
|
| 1248 | - |
|
| 1249 | - /** |
|
| 1250 | - * @override magic methods |
|
| 1251 | - * @return void |
|
| 1252 | - */ |
|
| 1253 | - final function __destruct() |
|
| 1254 | - { |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - |
|
| 1258 | - |
|
| 1259 | - /** |
|
| 1260 | - * @param $a |
|
| 1261 | - * @param $b |
|
| 1262 | - */ |
|
| 1263 | - final function __call($a, $b) |
|
| 1264 | - { |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - |
|
| 1268 | - |
|
| 1269 | - /** |
|
| 1270 | - * @param $a |
|
| 1271 | - */ |
|
| 1272 | - final function __get($a) |
|
| 1273 | - { |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * @param $a |
|
| 1280 | - * @param $b |
|
| 1281 | - */ |
|
| 1282 | - final function __set($a, $b) |
|
| 1283 | - { |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - |
|
| 1287 | - |
|
| 1288 | - /** |
|
| 1289 | - * @param $a |
|
| 1290 | - */ |
|
| 1291 | - final function __isset($a) |
|
| 1292 | - { |
|
| 1293 | - } |
|
| 19 | + /** |
|
| 20 | + * EE_Registry Object |
|
| 21 | + * |
|
| 22 | + * @var EE_Registry $_instance |
|
| 23 | + * @access private |
|
| 24 | + */ |
|
| 25 | + private static $_instance = null; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var EE_Dependency_Map $_dependency_map |
|
| 29 | + * @access protected |
|
| 30 | + */ |
|
| 31 | + protected $_dependency_map = null; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var array $_class_abbreviations |
|
| 35 | + * @access protected |
|
| 36 | + */ |
|
| 37 | + protected $_class_abbreviations = array(); |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @access public |
|
| 41 | + * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
| 42 | + */ |
|
| 43 | + public $BUS; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * EE_Cart Object |
|
| 47 | + * |
|
| 48 | + * @access public |
|
| 49 | + * @var EE_Cart $CART |
|
| 50 | + */ |
|
| 51 | + public $CART = null; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * EE_Config Object |
|
| 55 | + * |
|
| 56 | + * @access public |
|
| 57 | + * @var EE_Config $CFG |
|
| 58 | + */ |
|
| 59 | + public $CFG = null; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * EE_Network_Config Object |
|
| 63 | + * |
|
| 64 | + * @access public |
|
| 65 | + * @var EE_Network_Config $NET_CFG |
|
| 66 | + */ |
|
| 67 | + public $NET_CFG = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * StdClass object for storing library classes in |
|
| 71 | + * |
|
| 72 | + * @public LIB |
|
| 73 | + * @var StdClass $LIB |
|
| 74 | + */ |
|
| 75 | + public $LIB = null; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * EE_Request_Handler Object |
|
| 79 | + * |
|
| 80 | + * @access public |
|
| 81 | + * @var EE_Request_Handler $REQ |
|
| 82 | + */ |
|
| 83 | + public $REQ = null; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * EE_Session Object |
|
| 87 | + * |
|
| 88 | + * @access public |
|
| 89 | + * @var EE_Session $SSN |
|
| 90 | + */ |
|
| 91 | + public $SSN = null; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * holds the ee capabilities object. |
|
| 95 | + * |
|
| 96 | + * @since 4.5.0 |
|
| 97 | + * @var EE_Capabilities |
|
| 98 | + */ |
|
| 99 | + public $CAP = null; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * holds the EE_Message_Resource_Manager object. |
|
| 103 | + * |
|
| 104 | + * @since 4.9.0 |
|
| 105 | + * @var EE_Message_Resource_Manager |
|
| 106 | + */ |
|
| 107 | + public $MRM = null; |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Holds the Assets Registry instance |
|
| 112 | + * @var Registry |
|
| 113 | + */ |
|
| 114 | + public $AssetsRegistry = null; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
| 118 | + * |
|
| 119 | + * @access public |
|
| 120 | + * @var EE_Addon[] |
|
| 121 | + */ |
|
| 122 | + public $addons = null; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * $models |
|
| 126 | + * @access public |
|
| 127 | + * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 128 | + */ |
|
| 129 | + public $models = array(); |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * $modules |
|
| 133 | + * @access public |
|
| 134 | + * @var EED_Module[] $modules |
|
| 135 | + */ |
|
| 136 | + public $modules = null; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * $shortcodes |
|
| 140 | + * @access public |
|
| 141 | + * @var EES_Shortcode[] $shortcodes |
|
| 142 | + */ |
|
| 143 | + public $shortcodes = null; |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * $widgets |
|
| 147 | + * @access public |
|
| 148 | + * @var WP_Widget[] $widgets |
|
| 149 | + */ |
|
| 150 | + public $widgets = null; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * $non_abstract_db_models |
|
| 154 | + * @access public |
|
| 155 | + * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 156 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 157 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 158 | + * classnames (eg "EEM_Event") |
|
| 159 | + */ |
|
| 160 | + public $non_abstract_db_models = array(); |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * $i18n_js_strings - internationalization for JS strings |
|
| 165 | + * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
| 166 | + * in js file: var translatedString = eei18n.string_key; |
|
| 167 | + * |
|
| 168 | + * @access public |
|
| 169 | + * @var array |
|
| 170 | + */ |
|
| 171 | + public static $i18n_js_strings = array(); |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * $main_file - path to espresso.php |
|
| 176 | + * |
|
| 177 | + * @access public |
|
| 178 | + * @var array |
|
| 179 | + */ |
|
| 180 | + public $main_file; |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * array of ReflectionClass objects where the key is the class name |
|
| 184 | + * |
|
| 185 | + * @access public |
|
| 186 | + * @var ReflectionClass[] |
|
| 187 | + */ |
|
| 188 | + public $_reflectors; |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 192 | + * |
|
| 193 | + * @access protected |
|
| 194 | + * @var boolean $_cache_on |
|
| 195 | + */ |
|
| 196 | + protected $_cache_on = true; |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @singleton method used to instantiate class object |
|
| 202 | + * @access public |
|
| 203 | + * @param \EE_Dependency_Map $dependency_map |
|
| 204 | + * @return \EE_Registry instance |
|
| 205 | + */ |
|
| 206 | + public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
| 207 | + { |
|
| 208 | + // check if class object is instantiated |
|
| 209 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
| 210 | + self::$_instance = new EE_Registry($dependency_map); |
|
| 211 | + } |
|
| 212 | + return self::$_instance; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + *protected constructor to prevent direct creation |
|
| 219 | + * |
|
| 220 | + * @Constructor |
|
| 221 | + * @access protected |
|
| 222 | + * @param \EE_Dependency_Map $dependency_map |
|
| 223 | + * @return \EE_Registry |
|
| 224 | + */ |
|
| 225 | + protected function __construct(\EE_Dependency_Map $dependency_map) |
|
| 226 | + { |
|
| 227 | + $this->_dependency_map = $dependency_map; |
|
| 228 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * initialize |
|
| 235 | + */ |
|
| 236 | + public function initialize() |
|
| 237 | + { |
|
| 238 | + $this->_class_abbreviations = apply_filters( |
|
| 239 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 240 | + array( |
|
| 241 | + 'EE_Config' => 'CFG', |
|
| 242 | + 'EE_Session' => 'SSN', |
|
| 243 | + 'EE_Capabilities' => 'CAP', |
|
| 244 | + 'EE_Cart' => 'CART', |
|
| 245 | + 'EE_Network_Config' => 'NET_CFG', |
|
| 246 | + 'EE_Request_Handler' => 'REQ', |
|
| 247 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
| 248 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 249 | + ) |
|
| 250 | + ); |
|
| 251 | + // class library |
|
| 252 | + $this->LIB = new stdClass(); |
|
| 253 | + $this->addons = new stdClass(); |
|
| 254 | + $this->modules = new stdClass(); |
|
| 255 | + $this->shortcodes = new stdClass(); |
|
| 256 | + $this->widgets = new stdClass(); |
|
| 257 | + $this->load_core('Base', array(), true); |
|
| 258 | + // add our request and response objects to the cache |
|
| 259 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 260 | + $this->_set_cached_class( |
|
| 261 | + $request_loader(), |
|
| 262 | + 'EE_Request' |
|
| 263 | + ); |
|
| 264 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 265 | + $this->_set_cached_class( |
|
| 266 | + $response_loader(), |
|
| 267 | + 'EE_Response' |
|
| 268 | + ); |
|
| 269 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * init |
|
| 276 | + * |
|
| 277 | + * @access public |
|
| 278 | + * @return void |
|
| 279 | + */ |
|
| 280 | + public function init() |
|
| 281 | + { |
|
| 282 | + $this->AssetsRegistry = new Registry(); |
|
| 283 | + // Get current page protocol |
|
| 284 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 285 | + // Output admin-ajax.php URL with same protocol as current page |
|
| 286 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 287 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * localize_i18n_js_strings |
|
| 294 | + * |
|
| 295 | + * @return string |
|
| 296 | + */ |
|
| 297 | + public static function localize_i18n_js_strings() |
|
| 298 | + { |
|
| 299 | + $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
| 300 | + foreach ($i18n_js_strings as $key => $value) { |
|
| 301 | + if (is_scalar($value)) { |
|
| 302 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @param mixed string | EED_Module $module |
|
| 312 | + */ |
|
| 313 | + public function add_module($module) |
|
| 314 | + { |
|
| 315 | + if ($module instanceof EED_Module) { |
|
| 316 | + $module_class = get_class($module); |
|
| 317 | + $this->modules->{$module_class} = $module; |
|
| 318 | + } else { |
|
| 319 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
| 320 | + $this->load_core('Module_Request_Router'); |
|
| 321 | + } |
|
| 322 | + $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @param string $module_name |
|
| 330 | + * @return mixed EED_Module | NULL |
|
| 331 | + */ |
|
| 332 | + public function get_module($module_name = '') |
|
| 333 | + { |
|
| 334 | + return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * loads core classes - must be singletons |
|
| 341 | + * |
|
| 342 | + * @access public |
|
| 343 | + * @param string $class_name - simple class name ie: session |
|
| 344 | + * @param mixed $arguments |
|
| 345 | + * @param bool $load_only |
|
| 346 | + * @return mixed |
|
| 347 | + */ |
|
| 348 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 349 | + { |
|
| 350 | + $core_paths = apply_filters( |
|
| 351 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
| 352 | + array( |
|
| 353 | + EE_CORE, |
|
| 354 | + EE_ADMIN, |
|
| 355 | + EE_CPTS, |
|
| 356 | + EE_CORE . 'data_migration_scripts' . DS, |
|
| 357 | + EE_CORE . 'request_stack' . DS, |
|
| 358 | + EE_CORE . 'middleware' . DS, |
|
| 359 | + ) |
|
| 360 | + ); |
|
| 361 | + // retrieve instantiated class |
|
| 362 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * loads service classes |
|
| 369 | + * |
|
| 370 | + * @access public |
|
| 371 | + * @param string $class_name - simple class name ie: session |
|
| 372 | + * @param mixed $arguments |
|
| 373 | + * @param bool $load_only |
|
| 374 | + * @return mixed |
|
| 375 | + */ |
|
| 376 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 377 | + { |
|
| 378 | + $service_paths = apply_filters( |
|
| 379 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
| 380 | + array( |
|
| 381 | + EE_CORE . 'services' . DS, |
|
| 382 | + ) |
|
| 383 | + ); |
|
| 384 | + // retrieve instantiated class |
|
| 385 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * loads data_migration_scripts |
|
| 392 | + * |
|
| 393 | + * @access public |
|
| 394 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 395 | + * @param mixed $arguments |
|
| 396 | + * @return EE_Data_Migration_Script_Base|mixed |
|
| 397 | + */ |
|
| 398 | + public function load_dms($class_name, $arguments = array()) |
|
| 399 | + { |
|
| 400 | + // retrieve instantiated class |
|
| 401 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * loads object creating classes - must be singletons |
|
| 408 | + * |
|
| 409 | + * @param string $class_name - simple class name ie: attendee |
|
| 410 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
| 411 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
| 412 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 413 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
| 414 | + * @return EE_Base_Class | bool |
|
| 415 | + */ |
|
| 416 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 417 | + { |
|
| 418 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
| 419 | + EE_CORE, |
|
| 420 | + EE_CLASSES, |
|
| 421 | + EE_BUSINESS, |
|
| 422 | + )); |
|
| 423 | + // retrieve instantiated class |
|
| 424 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * loads helper classes - must be singletons |
|
| 431 | + * |
|
| 432 | + * @param string $class_name - simple class name ie: price |
|
| 433 | + * @param mixed $arguments |
|
| 434 | + * @param bool $load_only |
|
| 435 | + * @return EEH_Base | bool |
|
| 436 | + */ |
|
| 437 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 438 | + { |
|
| 439 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 440 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 441 | + // retrieve instantiated class |
|
| 442 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * loads core classes - must be singletons |
|
| 449 | + * |
|
| 450 | + * @access public |
|
| 451 | + * @param string $class_name - simple class name ie: session |
|
| 452 | + * @param mixed $arguments |
|
| 453 | + * @param bool $load_only |
|
| 454 | + * @param bool $cache whether to cache the object or not. |
|
| 455 | + * @return mixed |
|
| 456 | + */ |
|
| 457 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 458 | + { |
|
| 459 | + $paths = array( |
|
| 460 | + EE_LIBRARIES, |
|
| 461 | + EE_LIBRARIES . 'messages' . DS, |
|
| 462 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
| 463 | + EE_LIBRARIES . 'qtips' . DS, |
|
| 464 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
| 465 | + ); |
|
| 466 | + // retrieve instantiated class |
|
| 467 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * loads model classes - must be singletons |
|
| 474 | + * |
|
| 475 | + * @param string $class_name - simple class name ie: price |
|
| 476 | + * @param mixed $arguments |
|
| 477 | + * @param bool $load_only |
|
| 478 | + * @return EEM_Base | bool |
|
| 479 | + */ |
|
| 480 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 481 | + { |
|
| 482 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
| 483 | + EE_MODELS, |
|
| 484 | + EE_CORE, |
|
| 485 | + )); |
|
| 486 | + // retrieve instantiated class |
|
| 487 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * loads model classes - must be singletons |
|
| 494 | + * |
|
| 495 | + * @param string $class_name - simple class name ie: price |
|
| 496 | + * @param mixed $arguments |
|
| 497 | + * @param bool $load_only |
|
| 498 | + * @return mixed | bool |
|
| 499 | + */ |
|
| 500 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 501 | + { |
|
| 502 | + $paths = array( |
|
| 503 | + EE_MODELS . 'fields' . DS, |
|
| 504 | + EE_MODELS . 'helpers' . DS, |
|
| 505 | + EE_MODELS . 'relations' . DS, |
|
| 506 | + EE_MODELS . 'strategies' . DS, |
|
| 507 | + ); |
|
| 508 | + // retrieve instantiated class |
|
| 509 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Determines if $model_name is the name of an actual EE model. |
|
| 516 | + * |
|
| 517 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 518 | + * @return boolean |
|
| 519 | + */ |
|
| 520 | + public function is_model_name($model_name) |
|
| 521 | + { |
|
| 522 | + return isset($this->models[$model_name]) ? true : false; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * generic class loader |
|
| 529 | + * |
|
| 530 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 531 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
| 532 | + * @param string $type - file type - core? class? helper? model? |
|
| 533 | + * @param mixed $arguments |
|
| 534 | + * @param bool $load_only |
|
| 535 | + * @return mixed |
|
| 536 | + */ |
|
| 537 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 538 | + { |
|
| 539 | + // retrieve instantiated class |
|
| 540 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * load_addon |
|
| 547 | + * |
|
| 548 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 549 | + * @param string $class_name - full class name ie: My_Class |
|
| 550 | + * @param string $type - file type - core? class? helper? model? |
|
| 551 | + * @param mixed $arguments |
|
| 552 | + * @param bool $load_only |
|
| 553 | + * @return EE_Addon |
|
| 554 | + */ |
|
| 555 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 556 | + { |
|
| 557 | + // retrieve instantiated class |
|
| 558 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * instantiates, caches, and automatically resolves dependencies |
|
| 565 | + * for classes that use a Fully Qualified Class Name. |
|
| 566 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 567 | + * then you need to use one of the existing load_*() methods |
|
| 568 | + * which can resolve the classname and filepath from the passed arguments |
|
| 569 | + * |
|
| 570 | + * @param bool|string $class_name Fully Qualified Class Name |
|
| 571 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 572 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 573 | + * @param bool $from_db some classes are instantiated from the db |
|
| 574 | + * and thus call a different method to instantiate |
|
| 575 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 576 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 577 | + * @return mixed null = failure to load or instantiate class object. |
|
| 578 | + * object = class loaded and instantiated successfully. |
|
| 579 | + * bool = fail or success when $load_only is true |
|
| 580 | + */ |
|
| 581 | + public function create( |
|
| 582 | + $class_name = false, |
|
| 583 | + $arguments = array(), |
|
| 584 | + $cache = false, |
|
| 585 | + $from_db = false, |
|
| 586 | + $load_only = false, |
|
| 587 | + $addon = false |
|
| 588 | + ) { |
|
| 589 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 590 | + if ( ! class_exists($class_name)) { |
|
| 591 | + // maybe the class is registered with a preceding \ |
|
| 592 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
| 593 | + // still doesn't exist ? |
|
| 594 | + if ( ! class_exists($class_name)) { |
|
| 595 | + return null; |
|
| 596 | + } |
|
| 597 | + } |
|
| 598 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 599 | + if ($load_only) { |
|
| 600 | + return true; |
|
| 601 | + } |
|
| 602 | + $addon = $addon ? 'addon' : ''; |
|
| 603 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 604 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 605 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 606 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 607 | + // return object if it's already cached |
|
| 608 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 609 | + if ($cached_class !== null) { |
|
| 610 | + return $cached_class; |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + // instantiate the requested object |
|
| 614 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 615 | + if ($this->_cache_on && $cache) { |
|
| 616 | + // save it for later... kinda like gum { : $ |
|
| 617 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 618 | + } |
|
| 619 | + $this->_cache_on = true; |
|
| 620 | + return $class_obj; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + /** |
|
| 626 | + * instantiates, caches, and injects dependencies for classes |
|
| 627 | + * |
|
| 628 | + * @param array $file_paths an array of paths to folders to look in |
|
| 629 | + * @param string $class_prefix EE or EEM or... ??? |
|
| 630 | + * @param bool|string $class_name $class name |
|
| 631 | + * @param string $type file type - core? class? helper? model? |
|
| 632 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 633 | + * @param bool $from_db some classes are instantiated from the db |
|
| 634 | + * and thus call a different method to instantiate |
|
| 635 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 636 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 637 | + * @return null|object|bool null = failure to load or instantiate class object. |
|
| 638 | + * object = class loaded and instantiated successfully. |
|
| 639 | + * bool = fail or success when $load_only is true |
|
| 640 | + */ |
|
| 641 | + protected function _load( |
|
| 642 | + $file_paths = array(), |
|
| 643 | + $class_prefix = 'EE_', |
|
| 644 | + $class_name = false, |
|
| 645 | + $type = 'class', |
|
| 646 | + $arguments = array(), |
|
| 647 | + $from_db = false, |
|
| 648 | + $cache = true, |
|
| 649 | + $load_only = false |
|
| 650 | + ) { |
|
| 651 | + // strip php file extension |
|
| 652 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
| 653 | + // does the class have a prefix ? |
|
| 654 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
| 655 | + // make sure $class_prefix is uppercase |
|
| 656 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
| 657 | + // add class prefix ONCE!!! |
|
| 658 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 659 | + } |
|
| 660 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 661 | + $class_exists = class_exists($class_name); |
|
| 662 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 663 | + if ($load_only && $class_exists) { |
|
| 664 | + return true; |
|
| 665 | + } |
|
| 666 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 667 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 668 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 669 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 670 | + // return object if it's already cached |
|
| 671 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 672 | + if ($cached_class !== null) { |
|
| 673 | + return $cached_class; |
|
| 674 | + } |
|
| 675 | + } |
|
| 676 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 677 | + if ( ! $class_exists) { |
|
| 678 | + // get full path to file |
|
| 679 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 680 | + // load the file |
|
| 681 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 682 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 683 | + if ( ! $loaded || $load_only) { |
|
| 684 | + // return boolean if only loading, or null if an object was expected |
|
| 685 | + return $load_only ? $loaded : null; |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + // instantiate the requested object |
|
| 689 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 690 | + if ($this->_cache_on && $cache) { |
|
| 691 | + // save it for later... kinda like gum { : $ |
|
| 692 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 693 | + } |
|
| 694 | + $this->_cache_on = true; |
|
| 695 | + return $class_obj; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * _get_cached_class |
|
| 702 | + * attempts to find a cached version of the requested class |
|
| 703 | + * by looking in the following places: |
|
| 704 | + * $this->{$class_abbreviation} ie: $this->CART |
|
| 705 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 706 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 707 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 708 | + * |
|
| 709 | + * @access protected |
|
| 710 | + * @param string $class_name |
|
| 711 | + * @param string $class_prefix |
|
| 712 | + * @return mixed |
|
| 713 | + */ |
|
| 714 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 715 | + { |
|
| 716 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
| 717 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
| 718 | + } else { |
|
| 719 | + // have to specify something, but not anything that will conflict |
|
| 720 | + $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
| 721 | + } |
|
| 722 | + // check if class has already been loaded, and return it if it has been |
|
| 723 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
| 724 | + return $this->{$class_abbreviation}; |
|
| 725 | + } else if (isset ($this->{$class_name})) { |
|
| 726 | + return $this->{$class_name}; |
|
| 727 | + } else if (isset ($this->LIB->{$class_name})) { |
|
| 728 | + return $this->LIB->{$class_name}; |
|
| 729 | + } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
| 730 | + return $this->addons->{$class_name}; |
|
| 731 | + } |
|
| 732 | + return null; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * _resolve_path |
|
| 739 | + * attempts to find a full valid filepath for the requested class. |
|
| 740 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 741 | + * then returns that path if the target file has been found and is readable |
|
| 742 | + * |
|
| 743 | + * @access protected |
|
| 744 | + * @param string $class_name |
|
| 745 | + * @param string $type |
|
| 746 | + * @param array $file_paths |
|
| 747 | + * @return string | bool |
|
| 748 | + */ |
|
| 749 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 750 | + { |
|
| 751 | + // make sure $file_paths is an array |
|
| 752 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
| 753 | + // cycle thru paths |
|
| 754 | + foreach ($file_paths as $key => $file_path) { |
|
| 755 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 756 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
| 757 | + // prep file type |
|
| 758 | + $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
| 759 | + // build full file path |
|
| 760 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 761 | + //does the file exist and can be read ? |
|
| 762 | + if (is_readable($file_paths[$key])) { |
|
| 763 | + return $file_paths[$key]; |
|
| 764 | + } |
|
| 765 | + } |
|
| 766 | + return false; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * _require_file |
|
| 773 | + * basically just performs a require_once() |
|
| 774 | + * but with some error handling |
|
| 775 | + * |
|
| 776 | + * @access protected |
|
| 777 | + * @param string $path |
|
| 778 | + * @param string $class_name |
|
| 779 | + * @param string $type |
|
| 780 | + * @param array $file_paths |
|
| 781 | + * @return boolean |
|
| 782 | + * @throws \EE_Error |
|
| 783 | + */ |
|
| 784 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 785 | + { |
|
| 786 | + // don't give up! you gotta... |
|
| 787 | + try { |
|
| 788 | + //does the file exist and can it be read ? |
|
| 789 | + if ( ! $path) { |
|
| 790 | + // so sorry, can't find the file |
|
| 791 | + throw new EE_Error ( |
|
| 792 | + sprintf( |
|
| 793 | + __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
| 794 | + trim($type, '.'), |
|
| 795 | + $class_name, |
|
| 796 | + '<br />' . implode(',<br />', $file_paths) |
|
| 797 | + ) |
|
| 798 | + ); |
|
| 799 | + } |
|
| 800 | + // get the file |
|
| 801 | + require_once($path); |
|
| 802 | + // if the class isn't already declared somewhere |
|
| 803 | + if (class_exists($class_name, false) === false) { |
|
| 804 | + // so sorry, not a class |
|
| 805 | + throw new EE_Error( |
|
| 806 | + sprintf( |
|
| 807 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 808 | + $type, |
|
| 809 | + $path, |
|
| 810 | + $class_name |
|
| 811 | + ) |
|
| 812 | + ); |
|
| 813 | + } |
|
| 814 | + } catch (EE_Error $e) { |
|
| 815 | + $e->get_error(); |
|
| 816 | + return false; |
|
| 817 | + } |
|
| 818 | + return true; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * _create_object |
|
| 825 | + * Attempts to instantiate the requested class via any of the |
|
| 826 | + * commonly used instantiation methods employed throughout EE. |
|
| 827 | + * The priority for instantiation is as follows: |
|
| 828 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 829 | + * - model objects via their 'new_instance_from_db' method |
|
| 830 | + * - model objects via their 'new_instance' method |
|
| 831 | + * - "singleton" classes" via their 'instance' method |
|
| 832 | + * - standard instantiable classes via their __constructor |
|
| 833 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 834 | + * then the constructor for the requested class will be examined to determine |
|
| 835 | + * if any dependencies exist, and if they can be injected. |
|
| 836 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 837 | + * |
|
| 838 | + * @access protected |
|
| 839 | + * @param string $class_name |
|
| 840 | + * @param array $arguments |
|
| 841 | + * @param string $type |
|
| 842 | + * @param bool $from_db |
|
| 843 | + * @return null | object |
|
| 844 | + * @throws \EE_Error |
|
| 845 | + */ |
|
| 846 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 847 | + { |
|
| 848 | + $class_obj = null; |
|
| 849 | + $instantiation_mode = '0) none'; |
|
| 850 | + // don't give up! you gotta... |
|
| 851 | + try { |
|
| 852 | + // create reflection |
|
| 853 | + $reflector = $this->get_ReflectionClass($class_name); |
|
| 854 | + // make sure arguments are an array |
|
| 855 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
| 856 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 857 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 858 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 859 | + ? $arguments |
|
| 860 | + : array($arguments); |
|
| 861 | + // attempt to inject dependencies ? |
|
| 862 | + if ($this->_dependency_map->has($class_name)) { |
|
| 863 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 864 | + } |
|
| 865 | + // instantiate the class if possible |
|
| 866 | + if ($reflector->isAbstract()) { |
|
| 867 | + // nothing to instantiate, loading file was enough |
|
| 868 | + // does not throw an exception so $instantiation_mode is unused |
|
| 869 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
| 870 | + $class_obj = true; |
|
| 871 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
| 872 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 873 | + $instantiation_mode = "2) no constructor but instantiable"; |
|
| 874 | + $class_obj = $reflector->newInstance(); |
|
| 875 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 876 | + $instantiation_mode = "3) new_instance_from_db()"; |
|
| 877 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 878 | + } else if (method_exists($class_name, 'new_instance')) { |
|
| 879 | + $instantiation_mode = "4) new_instance()"; |
|
| 880 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 881 | + } else if (method_exists($class_name, 'instance')) { |
|
| 882 | + $instantiation_mode = "5) instance()"; |
|
| 883 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 884 | + } else if ($reflector->isInstantiable()) { |
|
| 885 | + $instantiation_mode = "6) constructor"; |
|
| 886 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
| 887 | + } else { |
|
| 888 | + // heh ? something's not right ! |
|
| 889 | + throw new EE_Error( |
|
| 890 | + sprintf( |
|
| 891 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 892 | + $type, |
|
| 893 | + $class_name |
|
| 894 | + ) |
|
| 895 | + ); |
|
| 896 | + } |
|
| 897 | + } catch (Exception $e) { |
|
| 898 | + if ( ! $e instanceof EE_Error) { |
|
| 899 | + $e = new EE_Error( |
|
| 900 | + sprintf( |
|
| 901 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
| 902 | + $class_name, |
|
| 903 | + '<br />', |
|
| 904 | + $e->getMessage(), |
|
| 905 | + $instantiation_mode |
|
| 906 | + ) |
|
| 907 | + ); |
|
| 908 | + } |
|
| 909 | + $e->get_error(); |
|
| 910 | + } |
|
| 911 | + return $class_obj; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 918 | + * @param array $array |
|
| 919 | + * @return bool |
|
| 920 | + */ |
|
| 921 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 922 | + { |
|
| 923 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * getReflectionClass |
|
| 930 | + * checks if a ReflectionClass object has already been generated for a class |
|
| 931 | + * and returns that instead of creating a new one |
|
| 932 | + * |
|
| 933 | + * @access public |
|
| 934 | + * @param string $class_name |
|
| 935 | + * @return ReflectionClass |
|
| 936 | + */ |
|
| 937 | + public function get_ReflectionClass($class_name) |
|
| 938 | + { |
|
| 939 | + if ( |
|
| 940 | + ! isset($this->_reflectors[$class_name]) |
|
| 941 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 942 | + ) { |
|
| 943 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 944 | + } |
|
| 945 | + return $this->_reflectors[$class_name]; |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + |
|
| 949 | + |
|
| 950 | + /** |
|
| 951 | + * _resolve_dependencies |
|
| 952 | + * examines the constructor for the requested class to determine |
|
| 953 | + * if any dependencies exist, and if they can be injected. |
|
| 954 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 955 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 956 | + * For example: |
|
| 957 | + * if attempting to load a class "Foo" with the following constructor: |
|
| 958 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 959 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 960 | + * but only IF they are NOT already present in the incoming arguments array, |
|
| 961 | + * and the correct classes can be loaded |
|
| 962 | + * |
|
| 963 | + * @access protected |
|
| 964 | + * @param ReflectionClass $reflector |
|
| 965 | + * @param string $class_name |
|
| 966 | + * @param array $arguments |
|
| 967 | + * @return array |
|
| 968 | + * @throws \ReflectionException |
|
| 969 | + */ |
|
| 970 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 971 | + { |
|
| 972 | + // let's examine the constructor |
|
| 973 | + $constructor = $reflector->getConstructor(); |
|
| 974 | + // whu? huh? nothing? |
|
| 975 | + if ( ! $constructor) { |
|
| 976 | + return $arguments; |
|
| 977 | + } |
|
| 978 | + // get constructor parameters |
|
| 979 | + $params = $constructor->getParameters(); |
|
| 980 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 981 | + $argument_keys = array_keys($arguments); |
|
| 982 | + // now loop thru all of the constructors expected parameters |
|
| 983 | + foreach ($params as $index => $param) { |
|
| 984 | + // is this a dependency for a specific class ? |
|
| 985 | + $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
| 986 | + if ( |
|
| 987 | + // param is not even a class |
|
| 988 | + empty($param_class) |
|
| 989 | + // and something already exists in the incoming arguments for this param |
|
| 990 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 991 | + ) { |
|
| 992 | + // so let's skip this argument and move on to the next |
|
| 993 | + continue; |
|
| 994 | + } else if ( |
|
| 995 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 996 | + ! empty($param_class) |
|
| 997 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 998 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 999 | + ) { |
|
| 1000 | + // skip this argument and move on to the next |
|
| 1001 | + continue; |
|
| 1002 | + } else if ( |
|
| 1003 | + // parameter is type hinted as a class, and should be injected |
|
| 1004 | + ! empty($param_class) |
|
| 1005 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1006 | + ) { |
|
| 1007 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
| 1008 | + } else { |
|
| 1009 | + try { |
|
| 1010 | + $arguments[$index] = $param->getDefaultValue(); |
|
| 1011 | + } catch (ReflectionException $e) { |
|
| 1012 | + throw new ReflectionException( |
|
| 1013 | + sprintf( |
|
| 1014 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
| 1015 | + $e->getMessage(), |
|
| 1016 | + $param->getName() |
|
| 1017 | + ) |
|
| 1018 | + ); |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | + } |
|
| 1022 | + return $arguments; |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + /** |
|
| 1028 | + * @access protected |
|
| 1029 | + * @param string $class_name |
|
| 1030 | + * @param string $param_class |
|
| 1031 | + * @param array $arguments |
|
| 1032 | + * @param mixed $index |
|
| 1033 | + * @return array |
|
| 1034 | + */ |
|
| 1035 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
| 1036 | + { |
|
| 1037 | + $dependency = null; |
|
| 1038 | + // should dependency be loaded from cache ? |
|
| 1039 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
| 1040 | + !== EE_Dependency_Map::load_new_object |
|
| 1041 | + ? true |
|
| 1042 | + : false; |
|
| 1043 | + // we might have a dependency... |
|
| 1044 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1045 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
| 1046 | + // and grab it if it exists |
|
| 1047 | + if ($cached_class instanceof $param_class) { |
|
| 1048 | + $dependency = $cached_class; |
|
| 1049 | + } else if ($param_class != $class_name) { |
|
| 1050 | + // obtain the loader method from the dependency map |
|
| 1051 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1052 | + // is loader a custom closure ? |
|
| 1053 | + if ($loader instanceof Closure) { |
|
| 1054 | + $dependency = $loader(); |
|
| 1055 | + } else { |
|
| 1056 | + // set the cache on property for the recursive loading call |
|
| 1057 | + $this->_cache_on = $cache_on; |
|
| 1058 | + // if not, then let's try and load it via the registry |
|
| 1059 | + if (method_exists($this, $loader)) { |
|
| 1060 | + $dependency = $this->{$loader}($param_class); |
|
| 1061 | + } else { |
|
| 1062 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
| 1063 | + } |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | + // did we successfully find the correct dependency ? |
|
| 1067 | + if ($dependency instanceof $param_class) { |
|
| 1068 | + // then let's inject it into the incoming array of arguments at the correct location |
|
| 1069 | + if (isset($argument_keys[$index])) { |
|
| 1070 | + $arguments[$argument_keys[$index]] = $dependency; |
|
| 1071 | + } else { |
|
| 1072 | + $arguments[$index] = $dependency; |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | + return $arguments; |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + |
|
| 1079 | + |
|
| 1080 | + /** |
|
| 1081 | + * _set_cached_class |
|
| 1082 | + * attempts to cache the instantiated class locally |
|
| 1083 | + * in one of the following places, in the following order: |
|
| 1084 | + * $this->{class_abbreviation} ie: $this->CART |
|
| 1085 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 1086 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1087 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1088 | + * |
|
| 1089 | + * @access protected |
|
| 1090 | + * @param object $class_obj |
|
| 1091 | + * @param string $class_name |
|
| 1092 | + * @param string $class_prefix |
|
| 1093 | + * @param bool $from_db |
|
| 1094 | + * @return void |
|
| 1095 | + */ |
|
| 1096 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1097 | + { |
|
| 1098 | + if (empty($class_obj)) { |
|
| 1099 | + return; |
|
| 1100 | + } |
|
| 1101 | + // return newly instantiated class |
|
| 1102 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
| 1103 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
| 1104 | + $this->{$class_abbreviation} = $class_obj; |
|
| 1105 | + } else if (property_exists($this, $class_name)) { |
|
| 1106 | + $this->{$class_name} = $class_obj; |
|
| 1107 | + } else if ($class_prefix == 'addon') { |
|
| 1108 | + $this->addons->{$class_name} = $class_obj; |
|
| 1109 | + } else if ( ! $from_db) { |
|
| 1110 | + $this->LIB->{$class_name} = $class_obj; |
|
| 1111 | + } |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + |
|
| 1115 | + |
|
| 1116 | + /** |
|
| 1117 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1118 | + * |
|
| 1119 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1120 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1121 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1122 | + * @param array $arguments |
|
| 1123 | + * @return object |
|
| 1124 | + */ |
|
| 1125 | + public static function factory($classname, $arguments = array()) |
|
| 1126 | + { |
|
| 1127 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1128 | + if ($loader instanceof Closure) { |
|
| 1129 | + return $loader($arguments); |
|
| 1130 | + } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
| 1131 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
| 1132 | + } |
|
| 1133 | + return null; |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + |
|
| 1137 | + |
|
| 1138 | + /** |
|
| 1139 | + * Gets the addon by its name/slug (not classname. For that, just |
|
| 1140 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
| 1141 | + * |
|
| 1142 | + * @param string $name |
|
| 1143 | + * @return EE_Addon |
|
| 1144 | + */ |
|
| 1145 | + public function get_addon_by_name($name) |
|
| 1146 | + { |
|
| 1147 | + foreach ($this->addons as $addon) { |
|
| 1148 | + if ($addon->name() == $name) { |
|
| 1149 | + return $addon; |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1152 | + return null; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + |
|
| 1156 | + |
|
| 1157 | + /** |
|
| 1158 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
| 1159 | + * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
| 1160 | + * |
|
| 1161 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1162 | + */ |
|
| 1163 | + public function get_addons_by_name() |
|
| 1164 | + { |
|
| 1165 | + $addons = array(); |
|
| 1166 | + foreach ($this->addons as $addon) { |
|
| 1167 | + $addons[$addon->name()] = $addon; |
|
| 1168 | + } |
|
| 1169 | + return $addons; |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + |
|
| 1173 | + |
|
| 1174 | + /** |
|
| 1175 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1176 | + * a stale copy of it around |
|
| 1177 | + * |
|
| 1178 | + * @param string $model_name |
|
| 1179 | + * @return \EEM_Base |
|
| 1180 | + * @throws \EE_Error |
|
| 1181 | + */ |
|
| 1182 | + public function reset_model($model_name) |
|
| 1183 | + { |
|
| 1184 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
| 1185 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1186 | + return null; |
|
| 1187 | + } |
|
| 1188 | + //get that model reset it and make sure we nuke the old reference to it |
|
| 1189 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
| 1190 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1191 | + } else { |
|
| 1192 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1193 | + } |
|
| 1194 | + return $this->LIB->{$model_class_name}; |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + |
|
| 1198 | + |
|
| 1199 | + /** |
|
| 1200 | + * Resets the registry. |
|
| 1201 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
| 1202 | + * is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1203 | + * - $_dependency_map |
|
| 1204 | + * - $_class_abbreviations |
|
| 1205 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1206 | + * - $REQ: Still on the same request so no need to change. |
|
| 1207 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1208 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
| 1209 | + * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1210 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1211 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1212 | + * switch or on the restore. |
|
| 1213 | + * - $modules |
|
| 1214 | + * - $shortcodes |
|
| 1215 | + * - $widgets |
|
| 1216 | + * |
|
| 1217 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
| 1218 | + * the Registry to its state at the beginning of the request |
|
| 1219 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1220 | + * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
| 1221 | + * currently reinstantiate the singletons at the moment) |
|
| 1222 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
| 1223 | + * code instead can just change the model context to a different blog id if necessary |
|
| 1224 | + * @return EE_Registry |
|
| 1225 | + */ |
|
| 1226 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1227 | + { |
|
| 1228 | + $instance = self::instance(); |
|
| 1229 | + EEH_Activation::reset(); |
|
| 1230 | + //properties that get reset |
|
| 1231 | + $instance->_cache_on = true; |
|
| 1232 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1233 | + $instance->CART = null; |
|
| 1234 | + $instance->MRM = null; |
|
| 1235 | + $instance->AssetsRegistry = new Registry(); |
|
| 1236 | + //messages reset |
|
| 1237 | + EED_Messages::reset(); |
|
| 1238 | + if ($reset_models) { |
|
| 1239 | + foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
| 1240 | + $instance->reset_model($model_name); |
|
| 1241 | + } |
|
| 1242 | + } |
|
| 1243 | + $instance->LIB = new stdClass(); |
|
| 1244 | + return $instance; |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + |
|
| 1248 | + |
|
| 1249 | + /** |
|
| 1250 | + * @override magic methods |
|
| 1251 | + * @return void |
|
| 1252 | + */ |
|
| 1253 | + final function __destruct() |
|
| 1254 | + { |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + |
|
| 1258 | + |
|
| 1259 | + /** |
|
| 1260 | + * @param $a |
|
| 1261 | + * @param $b |
|
| 1262 | + */ |
|
| 1263 | + final function __call($a, $b) |
|
| 1264 | + { |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * @param $a |
|
| 1271 | + */ |
|
| 1272 | + final function __get($a) |
|
| 1273 | + { |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * @param $a |
|
| 1280 | + * @param $b |
|
| 1281 | + */ |
|
| 1282 | + final function __set($a, $b) |
|
| 1283 | + { |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + |
|
| 1287 | + |
|
| 1288 | + /** |
|
| 1289 | + * @param $a |
|
| 1290 | + */ |
|
| 1291 | + final function __isset($a) |
|
| 1292 | + { |
|
| 1293 | + } |
|
| 1294 | 1294 | |
| 1295 | 1295 | |
| 1296 | 1296 | |
| 1297 | - /** |
|
| 1298 | - * @param $a |
|
| 1299 | - */ |
|
| 1300 | - final function __unset($a) |
|
| 1301 | - { |
|
| 1302 | - } |
|
| 1297 | + /** |
|
| 1298 | + * @param $a |
|
| 1299 | + */ |
|
| 1300 | + final function __unset($a) |
|
| 1301 | + { |
|
| 1302 | + } |
|
| 1303 | 1303 | |
| 1304 | 1304 | |
| 1305 | 1305 | |
| 1306 | - /** |
|
| 1307 | - * @return array |
|
| 1308 | - */ |
|
| 1309 | - final function __sleep() |
|
| 1310 | - { |
|
| 1311 | - return array(); |
|
| 1312 | - } |
|
| 1306 | + /** |
|
| 1307 | + * @return array |
|
| 1308 | + */ |
|
| 1309 | + final function __sleep() |
|
| 1310 | + { |
|
| 1311 | + return array(); |
|
| 1312 | + } |
|
| 1313 | 1313 | |
| 1314 | 1314 | |
| 1315 | 1315 | |
| 1316 | - final function __wakeup() |
|
| 1317 | - { |
|
| 1318 | - } |
|
| 1316 | + final function __wakeup() |
|
| 1317 | + { |
|
| 1318 | + } |
|
| 1319 | 1319 | |
| 1320 | 1320 | |
| 1321 | 1321 | |
| 1322 | - /** |
|
| 1323 | - * @return string |
|
| 1324 | - */ |
|
| 1325 | - final function __toString() |
|
| 1326 | - { |
|
| 1327 | - return ''; |
|
| 1328 | - } |
|
| 1322 | + /** |
|
| 1323 | + * @return string |
|
| 1324 | + */ |
|
| 1325 | + final function __toString() |
|
| 1326 | + { |
|
| 1327 | + return ''; |
|
| 1328 | + } |
|
| 1329 | 1329 | |
| 1330 | 1330 | |
| 1331 | 1331 | |
| 1332 | - final function __invoke() |
|
| 1333 | - { |
|
| 1334 | - } |
|
| 1332 | + final function __invoke() |
|
| 1333 | + { |
|
| 1334 | + } |
|
| 1335 | 1335 | |
| 1336 | 1336 | |
| 1337 | 1337 | |
| 1338 | - final static function __set_state() |
|
| 1339 | - { |
|
| 1340 | - } |
|
| 1338 | + final static function __set_state() |
|
| 1339 | + { |
|
| 1340 | + } |
|
| 1341 | 1341 | |
| 1342 | 1342 | |
| 1343 | 1343 | |
| 1344 | - final function __clone() |
|
| 1345 | - { |
|
| 1346 | - } |
|
| 1344 | + final function __clone() |
|
| 1345 | + { |
|
| 1346 | + } |
|
| 1347 | 1347 | |
| 1348 | 1348 | |
| 1349 | 1349 | |
| 1350 | - /** |
|
| 1351 | - * @param $a |
|
| 1352 | - * @param $b |
|
| 1353 | - */ |
|
| 1354 | - final static function __callStatic($a, $b) |
|
| 1355 | - { |
|
| 1356 | - } |
|
| 1350 | + /** |
|
| 1351 | + * @param $a |
|
| 1352 | + * @param $b |
|
| 1353 | + */ |
|
| 1354 | + final static function __callStatic($a, $b) |
|
| 1355 | + { |
|
| 1356 | + } |
|
| 1357 | 1357 | |
| 1358 | 1358 | |
| 1359 | 1359 | |
| 1360 | - /** |
|
| 1361 | - * Gets all the custom post type models defined |
|
| 1362 | - * |
|
| 1363 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1364 | - */ |
|
| 1365 | - public function cpt_models() |
|
| 1366 | - { |
|
| 1367 | - $cpt_models = array(); |
|
| 1368 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1369 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1370 | - $cpt_models[$short_name] = $classname; |
|
| 1371 | - } |
|
| 1372 | - } |
|
| 1373 | - return $cpt_models; |
|
| 1374 | - } |
|
| 1360 | + /** |
|
| 1361 | + * Gets all the custom post type models defined |
|
| 1362 | + * |
|
| 1363 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1364 | + */ |
|
| 1365 | + public function cpt_models() |
|
| 1366 | + { |
|
| 1367 | + $cpt_models = array(); |
|
| 1368 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1369 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1370 | + $cpt_models[$short_name] = $classname; |
|
| 1371 | + } |
|
| 1372 | + } |
|
| 1373 | + return $cpt_models; |
|
| 1374 | + } |
|
| 1375 | 1375 | |
| 1376 | 1376 | |
| 1377 | 1377 | |
| 1378 | - /** |
|
| 1379 | - * @return \EE_Config |
|
| 1380 | - */ |
|
| 1381 | - public static function CFG() |
|
| 1382 | - { |
|
| 1383 | - return self::instance()->CFG; |
|
| 1384 | - } |
|
| 1378 | + /** |
|
| 1379 | + * @return \EE_Config |
|
| 1380 | + */ |
|
| 1381 | + public static function CFG() |
|
| 1382 | + { |
|
| 1383 | + return self::instance()->CFG; |
|
| 1384 | + } |
|
| 1385 | 1385 | |
| 1386 | 1386 | |
| 1387 | 1387 | } |