Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Registrations_Admin_Page often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Registrations_Admin_Page, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class Registrations_Admin_Page extends EE_Admin_Page_CPT |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var EE_Registration |
||
23 | */ |
||
24 | private $_registration; |
||
25 | |||
26 | /** |
||
27 | * @var EE_Event |
||
28 | */ |
||
29 | private $_reg_event; |
||
30 | |||
31 | /** |
||
32 | * @var EE_Session |
||
33 | */ |
||
34 | private $_session; |
||
35 | |||
36 | private static $_reg_status; |
||
37 | |||
38 | /** |
||
39 | * Form for displaying the custom questions for this registration. |
||
40 | * This gets used a few times throughout the request so its best to cache it |
||
41 | * |
||
42 | * @var EE_Registration_Custom_Questions_Form |
||
43 | */ |
||
44 | protected $_reg_custom_questions_form = null; |
||
45 | |||
46 | /** |
||
47 | * @var EEM_Registration $registration_model |
||
48 | */ |
||
49 | private $registration_model; |
||
50 | |||
51 | /** |
||
52 | * @var EEM_Attendee $attendee_model |
||
53 | */ |
||
54 | private $attendee_model; |
||
55 | |||
56 | /** |
||
57 | * @var EEM_Event $event_model |
||
58 | */ |
||
59 | private $event_model; |
||
60 | |||
61 | /** |
||
62 | * @var EEM_Status $status_model |
||
63 | */ |
||
64 | private $status_model; |
||
65 | |||
66 | |||
67 | /** |
||
68 | * @param bool $routing |
||
69 | * @throws EE_Error |
||
70 | * @throws InvalidArgumentException |
||
71 | * @throws InvalidDataTypeException |
||
72 | * @throws InvalidInterfaceException |
||
73 | * @throws ReflectionException |
||
74 | */ |
||
75 | public function __construct($routing = true) |
||
80 | |||
81 | /** |
||
82 | * @return EEM_Registration |
||
83 | * @throws InvalidArgumentException |
||
84 | * @throws InvalidDataTypeException |
||
85 | * @throws InvalidInterfaceException |
||
86 | * @since $VID:$ |
||
87 | */ |
||
88 | protected function getRegistrationModel() |
||
95 | |||
96 | /** |
||
97 | * @return EEM_Attendee |
||
98 | * @throws InvalidArgumentException |
||
99 | * @throws InvalidDataTypeException |
||
100 | * @throws InvalidInterfaceException |
||
101 | * @since $VID:$ |
||
102 | */ |
||
103 | protected function getAttendeeModel() |
||
110 | |||
111 | |||
112 | /** |
||
113 | * @return EEM_Event |
||
114 | * @throws InvalidArgumentException |
||
115 | * @throws InvalidDataTypeException |
||
116 | * @throws InvalidInterfaceException |
||
117 | * @since $VID:$ |
||
118 | */ |
||
119 | protected function getEventModel() |
||
126 | |||
127 | /** |
||
128 | * @return EEM_Status |
||
129 | * @throws InvalidArgumentException |
||
130 | * @throws InvalidDataTypeException |
||
131 | * @throws InvalidInterfaceException |
||
132 | * @since $VID:$ |
||
133 | */ |
||
134 | protected function getStatusModel() |
||
141 | |||
142 | |||
143 | public function wp_loaded() |
||
159 | |||
160 | |||
161 | protected function _init_page_props() |
||
189 | |||
190 | |||
191 | public function clear_comment_link($link, $comment, $args) |
||
200 | |||
201 | |||
202 | protected function _ajax_hooks() |
||
207 | |||
208 | |||
209 | protected function _define_page_props() |
||
232 | |||
233 | |||
234 | /** |
||
235 | * grab url requests and route them |
||
236 | * |
||
237 | * @access private |
||
238 | * @return void |
||
239 | * @throws EE_Error |
||
240 | */ |
||
241 | public function _set_page_routes() |
||
534 | |||
535 | |||
536 | protected function _set_page_config() |
||
675 | |||
676 | |||
677 | /** |
||
678 | * The below methods aren't used by this class currently |
||
679 | */ |
||
680 | protected function _add_screen_options() |
||
683 | |||
684 | |||
685 | protected function _add_feature_pointers() |
||
688 | |||
689 | |||
690 | public function admin_init() |
||
697 | |||
698 | |||
699 | public function admin_notices() |
||
702 | |||
703 | |||
704 | public function admin_footer_scripts() |
||
707 | |||
708 | |||
709 | /** |
||
710 | * get list of registration statuses |
||
711 | * |
||
712 | * @access private |
||
713 | * @return void |
||
714 | * @throws EE_Error |
||
715 | */ |
||
716 | private function _get_registration_status_array() |
||
720 | |||
721 | |||
722 | /** |
||
723 | * @throws InvalidArgumentException |
||
724 | * @throws InvalidDataTypeException |
||
725 | * @throws InvalidInterfaceException |
||
726 | * @since $VID:$ |
||
727 | */ |
||
728 | protected function _add_screen_options_default() |
||
732 | |||
733 | |||
734 | /** |
||
735 | * @throws InvalidArgumentException |
||
736 | * @throws InvalidDataTypeException |
||
737 | * @throws InvalidInterfaceException |
||
738 | * @since $VID:$ |
||
739 | */ |
||
740 | View Code Duplication | protected function _add_screen_options_contact_list() |
|
747 | |||
748 | |||
749 | View Code Duplication | public function load_scripts_styles() |
|
769 | |||
770 | |||
771 | /** |
||
772 | * @throws EE_Error |
||
773 | * @throws InvalidArgumentException |
||
774 | * @throws InvalidDataTypeException |
||
775 | * @throws InvalidInterfaceException |
||
776 | * @throws ReflectionException |
||
777 | * @since $VID:$ |
||
778 | */ |
||
779 | public function load_scripts_styles_edit_attendee() |
||
792 | |||
793 | |||
794 | /** |
||
795 | * @throws EE_Error |
||
796 | * @throws InvalidArgumentException |
||
797 | * @throws InvalidDataTypeException |
||
798 | * @throws InvalidInterfaceException |
||
799 | * @throws ReflectionException |
||
800 | * @since $VID:$ |
||
801 | */ |
||
802 | public function load_scripts_styles_view_registration() |
||
810 | |||
811 | |||
812 | public function load_scripts_styles_contact_list() |
||
823 | |||
824 | |||
825 | public function load_scripts_styles_new_registration() |
||
840 | |||
841 | |||
842 | public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
||
846 | |||
847 | |||
848 | public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
||
852 | |||
853 | |||
854 | /** |
||
855 | * @throws EE_Error |
||
856 | * @throws InvalidArgumentException |
||
857 | * @throws InvalidDataTypeException |
||
858 | * @throws InvalidInterfaceException |
||
859 | * @throws ReflectionException |
||
860 | * @since $VID:$ |
||
861 | */ |
||
862 | protected function _set_list_table_views_default() |
||
991 | |||
992 | |||
993 | protected function _set_list_table_views_contact_list() |
||
1020 | |||
1021 | |||
1022 | protected function _registration_legend_items() |
||
1129 | |||
1130 | |||
1131 | |||
1132 | /*************************************** REGISTRATION OVERVIEW **************************************/ |
||
1133 | |||
1134 | |||
1135 | |||
1136 | /** |
||
1137 | * @throws DomainException |
||
1138 | * @throws EE_Error |
||
1139 | * @throws InvalidArgumentException |
||
1140 | * @throws InvalidDataTypeException |
||
1141 | * @throws InvalidInterfaceException |
||
1142 | * @throws ReflectionException |
||
1143 | */ |
||
1144 | protected function _registrations_overview_list_table() |
||
1162 | |||
1163 | |||
1164 | /** |
||
1165 | * @throws EE_Error |
||
1166 | * @throws InvalidArgumentException |
||
1167 | * @throws InvalidDataTypeException |
||
1168 | * @throws InvalidInterfaceException |
||
1169 | */ |
||
1170 | private function appendAddNewRegistrationButtonToPageTitle() |
||
1190 | |||
1191 | |||
1192 | /** |
||
1193 | * This sets the _registration property for the registration details screen |
||
1194 | * |
||
1195 | * @access private |
||
1196 | * @return bool |
||
1197 | * @throws EE_Error |
||
1198 | * @throws InvalidArgumentException |
||
1199 | * @throws InvalidDataTypeException |
||
1200 | * @throws InvalidInterfaceException |
||
1201 | */ |
||
1202 | private function _set_registration_object() |
||
1223 | |||
1224 | |||
1225 | /** |
||
1226 | * Used to retrieve registrations for the list table. |
||
1227 | * |
||
1228 | * @param int $per_page |
||
1229 | * @param bool $count |
||
1230 | * @param bool $this_month |
||
1231 | * @param bool $today |
||
1232 | * @return EE_Registration[]|int |
||
1233 | * @throws EE_Error |
||
1234 | * @throws InvalidArgumentException |
||
1235 | * @throws InvalidDataTypeException |
||
1236 | * @throws InvalidInterfaceException |
||
1237 | */ |
||
1238 | public function get_registrations( |
||
1266 | |||
1267 | |||
1268 | /** |
||
1269 | * Retrieves the query parameters to be used by the Registration model for getting registrations. |
||
1270 | * Note: this listens to values on the request for some of the query parameters. |
||
1271 | * |
||
1272 | * @param array $request |
||
1273 | * @param int $per_page |
||
1274 | * @param bool $count |
||
1275 | * @return array |
||
1276 | * @throws EE_Error |
||
1277 | * @throws InvalidArgumentException |
||
1278 | * @throws InvalidDataTypeException |
||
1279 | * @throws InvalidInterfaceException |
||
1280 | */ |
||
1281 | protected function _get_registration_query_parameters( |
||
1282 | $request = array(), |
||
1283 | $per_page = 10, |
||
1284 | $count = false |
||
1285 | ) { |
||
1286 | /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */ |
||
1287 | $list_table_query_builder = $this->getLoader()->getNew( |
||
1288 | 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder', |
||
1289 | [ $request ] |
||
1290 | ); |
||
1291 | return $list_table_query_builder->getQueryParams($per_page, $count); |
||
1292 | } |
||
1293 | |||
1294 | |||
1295 | public function get_registration_status_array() |
||
1296 | { |
||
1297 | return self::$_reg_status; |
||
1298 | } |
||
1299 | |||
1300 | |||
1301 | |||
1302 | |||
1303 | /*************************************** REGISTRATION DETAILS ***************************************/ |
||
1304 | /** |
||
1305 | * generates HTML for the View Registration Details Admin page |
||
1306 | * |
||
1307 | * @access protected |
||
1308 | * @return void |
||
1309 | * @throws DomainException |
||
1310 | * @throws EE_Error |
||
1311 | * @throws InvalidArgumentException |
||
1312 | * @throws InvalidDataTypeException |
||
1313 | * @throws InvalidInterfaceException |
||
1314 | * @throws EntityNotFoundException |
||
1315 | * @throws ReflectionException |
||
1316 | */ |
||
1317 | protected function _registration_details() |
||
1318 | { |
||
1319 | $this->_template_args = array(); |
||
1320 | $this->_set_registration_object(); |
||
1321 | if (is_object($this->_registration)) { |
||
1322 | $transaction = $this->_registration->transaction() |
||
1323 | ? $this->_registration->transaction() |
||
1324 | : EE_Transaction::new_instance(); |
||
1325 | $this->_session = $transaction->session_data(); |
||
1326 | $event_id = $this->_registration->event_ID(); |
||
1327 | $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
||
1328 | $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
||
1329 | $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
||
1330 | $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
||
1331 | $this->_template_args['grand_total'] = $transaction->total(); |
||
1332 | $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
||
1333 | // link back to overview |
||
1334 | $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
||
1335 | $this->_template_args['registration'] = $this->_registration; |
||
1336 | $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
||
1337 | array( |
||
1338 | 'action' => 'default', |
||
1339 | 'event_id' => $event_id, |
||
1340 | ), |
||
1341 | REG_ADMIN_URL |
||
1342 | ); |
||
1343 | $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
||
1344 | array( |
||
1345 | 'action' => 'default', |
||
1346 | 'EVT_ID' => $event_id, |
||
1347 | 'page' => 'espresso_transactions', |
||
1348 | ), |
||
1349 | admin_url('admin.php') |
||
1350 | ); |
||
1351 | $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
||
1352 | array( |
||
1353 | 'page' => 'espresso_events', |
||
1354 | 'action' => 'edit', |
||
1355 | 'post' => $event_id, |
||
1356 | ), |
||
1357 | admin_url('admin.php') |
||
1358 | ); |
||
1359 | // next and previous links |
||
1360 | $next_reg = $this->_registration->next( |
||
1361 | null, |
||
1362 | array(), |
||
1363 | 'REG_ID' |
||
1364 | ); |
||
1365 | $this->_template_args['next_registration'] = $next_reg |
||
1366 | ? $this->_next_link( |
||
1367 | EE_Admin_Page::add_query_args_and_nonce( |
||
1368 | array( |
||
1369 | 'action' => 'view_registration', |
||
1370 | '_REG_ID' => $next_reg['REG_ID'], |
||
1371 | ), |
||
1372 | REG_ADMIN_URL |
||
1373 | ), |
||
1374 | 'dashicons dashicons-arrow-right ee-icon-size-22' |
||
1375 | ) |
||
1376 | : ''; |
||
1377 | $previous_reg = $this->_registration->previous( |
||
1378 | null, |
||
1379 | array(), |
||
1380 | 'REG_ID' |
||
1381 | ); |
||
1382 | $this->_template_args['previous_registration'] = $previous_reg |
||
1383 | ? $this->_previous_link( |
||
1384 | EE_Admin_Page::add_query_args_and_nonce( |
||
1385 | array( |
||
1386 | 'action' => 'view_registration', |
||
1387 | '_REG_ID' => $previous_reg['REG_ID'], |
||
1388 | ), |
||
1389 | REG_ADMIN_URL |
||
1390 | ), |
||
1391 | 'dashicons dashicons-arrow-left ee-icon-size-22' |
||
1392 | ) |
||
1393 | : ''; |
||
1394 | // grab header |
||
1395 | $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
||
1396 | $this->_template_args['REG_ID'] = $this->_registration->ID(); |
||
1397 | $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
||
1398 | $template_path, |
||
1399 | $this->_template_args, |
||
1400 | true |
||
1401 | ); |
||
1402 | } else { |
||
1403 | $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
||
1404 | } |
||
1405 | // the details template wrapper |
||
1406 | $this->display_admin_page_with_sidebar(); |
||
1407 | } |
||
1408 | |||
1409 | |||
1410 | /** |
||
1411 | * @throws EE_Error |
||
1412 | * @throws InvalidArgumentException |
||
1413 | * @throws InvalidDataTypeException |
||
1414 | * @throws InvalidInterfaceException |
||
1415 | * @throws ReflectionException |
||
1416 | * @since $VID:$ |
||
1417 | */ |
||
1418 | protected function _registration_details_metaboxes() |
||
1419 | { |
||
1420 | do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
||
1421 | $this->_set_registration_object(); |
||
1422 | $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
||
1423 | add_meta_box( |
||
1424 | 'edit-reg-status-mbox', |
||
1425 | esc_html__('Registration Status', 'event_espresso'), |
||
1426 | array($this, 'set_reg_status_buttons_metabox'), |
||
1427 | $this->wp_page_slug, |
||
1428 | 'normal', |
||
1429 | 'high' |
||
1430 | ); |
||
1431 | add_meta_box( |
||
1432 | 'edit-reg-details-mbox', |
||
1433 | esc_html__('Registration Details', 'event_espresso'), |
||
1434 | array($this, '_reg_details_meta_box'), |
||
1435 | $this->wp_page_slug, |
||
1436 | 'normal', |
||
1437 | 'high' |
||
1438 | ); |
||
1439 | if ($attendee instanceof EE_Attendee |
||
1440 | && EE_Registry::instance()->CAP->current_user_can( |
||
1441 | 'ee_read_registration', |
||
1442 | 'edit-reg-questions-mbox', |
||
1443 | $this->_registration->ID() |
||
1444 | ) |
||
1445 | ) { |
||
1446 | add_meta_box( |
||
1447 | 'edit-reg-questions-mbox', |
||
1448 | esc_html__('Registration Form Answers', 'event_espresso'), |
||
1449 | array($this, '_reg_questions_meta_box'), |
||
1450 | $this->wp_page_slug, |
||
1451 | 'normal', |
||
1452 | 'high' |
||
1453 | ); |
||
1454 | } |
||
1455 | add_meta_box( |
||
1456 | 'edit-reg-registrant-mbox', |
||
1457 | esc_html__('Contact Details', 'event_espresso'), |
||
1458 | array($this, '_reg_registrant_side_meta_box'), |
||
1459 | $this->wp_page_slug, |
||
1460 | 'side', |
||
1461 | 'high' |
||
1462 | ); |
||
1463 | if ($this->_registration->group_size() > 1) { |
||
1464 | add_meta_box( |
||
1465 | 'edit-reg-attendees-mbox', |
||
1466 | esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
||
1467 | array($this, '_reg_attendees_meta_box'), |
||
1468 | $this->wp_page_slug, |
||
1469 | 'normal', |
||
1470 | 'high' |
||
1471 | ); |
||
1472 | } |
||
1473 | } |
||
1474 | |||
1475 | |||
1476 | /** |
||
1477 | * set_reg_status_buttons_metabox |
||
1478 | * |
||
1479 | * @access protected |
||
1480 | * @return string |
||
1481 | * @throws EE_Error |
||
1482 | * @throws EntityNotFoundException |
||
1483 | * @throws InvalidArgumentException |
||
1484 | * @throws InvalidDataTypeException |
||
1485 | * @throws InvalidInterfaceException |
||
1486 | * @throws ReflectionException |
||
1487 | */ |
||
1488 | public function set_reg_status_buttons_metabox() |
||
1489 | { |
||
1490 | $this->_set_registration_object(); |
||
1491 | $change_reg_status_form = $this->_generate_reg_status_change_form(); |
||
1492 | echo $change_reg_status_form->form_open( |
||
1493 | self::add_query_args_and_nonce( |
||
1494 | array( |
||
1495 | 'action' => 'change_reg_status', |
||
1496 | ), |
||
1497 | REG_ADMIN_URL |
||
1498 | ) |
||
1499 | ); |
||
1500 | echo $change_reg_status_form->get_html(); |
||
1501 | echo $change_reg_status_form->form_close(); |
||
1502 | } |
||
1503 | |||
1504 | |||
1505 | /** |
||
1506 | * @return EE_Form_Section_Proper |
||
1507 | * @throws EE_Error |
||
1508 | * @throws InvalidArgumentException |
||
1509 | * @throws InvalidDataTypeException |
||
1510 | * @throws InvalidInterfaceException |
||
1511 | * @throws EntityNotFoundException |
||
1512 | * @throws ReflectionException |
||
1513 | */ |
||
1514 | protected function _generate_reg_status_change_form() |
||
1515 | { |
||
1516 | $reg_status_change_form_array = array( |
||
1517 | 'name' => 'reg_status_change_form', |
||
1518 | 'html_id' => 'reg-status-change-form', |
||
1519 | 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
||
1520 | 'subsections' => array( |
||
1521 | 'return' => new EE_Hidden_Input( |
||
1522 | array( |
||
1523 | 'name' => 'return', |
||
1524 | 'default' => 'view_registration', |
||
1525 | ) |
||
1526 | ), |
||
1527 | 'REG_ID' => new EE_Hidden_Input( |
||
1528 | array( |
||
1529 | 'name' => 'REG_ID', |
||
1530 | 'default' => $this->_registration->ID(), |
||
1531 | ) |
||
1532 | ), |
||
1533 | 'current_status' => new EE_Form_Section_HTML( |
||
1534 | EEH_HTML::table( |
||
1535 | EEH_HTML::tr( |
||
1536 | EEH_HTML::th( |
||
1537 | EEH_HTML::label( |
||
1538 | EEH_HTML::strong( |
||
1539 | esc_html__('Current Registration Status', 'event_espresso') |
||
1540 | ) |
||
1541 | ) |
||
1542 | ) |
||
1543 | . EEH_HTML::td( |
||
1544 | EEH_HTML::strong( |
||
1545 | $this->_registration->pretty_status(), |
||
1546 | '', |
||
1547 | 'status-' . $this->_registration->status_ID(), |
||
1548 | 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
||
1549 | ) |
||
1550 | ) |
||
1551 | ) |
||
1552 | ) |
||
1553 | ) |
||
1554 | ) |
||
1555 | ); |
||
1556 | if (EE_Registry::instance()->CAP->current_user_can( |
||
1557 | 'ee_edit_registration', |
||
1558 | 'toggle_registration_status', |
||
1559 | $this->_registration->ID() |
||
1560 | )) { |
||
1561 | $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input( |
||
1562 | $this->_get_reg_statuses(), |
||
1563 | array( |
||
1564 | 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
||
1565 | 'default' => $this->_registration->status_ID(), |
||
1566 | ) |
||
1567 | ); |
||
1568 | $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input( |
||
1569 | array( |
||
1570 | 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
||
1571 | 'default' => false, |
||
1572 | 'html_help_text' => esc_html__( |
||
1573 | 'If set to "Yes", then the related messages will be sent to the registrant.', |
||
1574 | 'event_espresso' |
||
1575 | ) |
||
1576 | ) |
||
1577 | ); |
||
1578 | $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input( |
||
1579 | array( |
||
1580 | 'html_class' => 'button-primary', |
||
1581 | 'html_label_text' => ' ', |
||
1582 | 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
||
1583 | ) |
||
1584 | ); |
||
1585 | } |
||
1586 | return new EE_Form_Section_Proper($reg_status_change_form_array); |
||
1587 | } |
||
1588 | |||
1589 | |||
1590 | /** |
||
1591 | * Returns an array of all the buttons for the various statuses and switch status actions |
||
1592 | * |
||
1593 | * @return array |
||
1594 | * @throws EE_Error |
||
1595 | * @throws InvalidArgumentException |
||
1596 | * @throws InvalidDataTypeException |
||
1597 | * @throws InvalidInterfaceException |
||
1598 | * @throws EntityNotFoundException |
||
1599 | */ |
||
1600 | protected function _get_reg_statuses() |
||
1601 | { |
||
1602 | $reg_status_array = $this->getRegistrationModel()->reg_status_array(); |
||
1603 | unset($reg_status_array[ EEM_Registration::status_id_incomplete ]); |
||
1604 | // get current reg status |
||
1605 | $current_status = $this->_registration->status_ID(); |
||
1606 | // is registration for free event? This will determine whether to display the pending payment option |
||
1607 | if ($current_status !== EEM_Registration::status_id_pending_payment |
||
1608 | && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00) |
||
1609 | ) { |
||
1610 | unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]); |
||
1611 | } |
||
1612 | return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence'); |
||
1613 | } |
||
1614 | |||
1615 | |||
1616 | /** |
||
1617 | * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
||
1618 | * |
||
1619 | * @param bool $status REG status given for changing registrations to. |
||
1620 | * @param bool $notify Whether to send messages notifications or not. |
||
1621 | * @return array (array with reg_id(s) updated and whether update was successful. |
||
1622 | * @throws DomainException |
||
1623 | * @throws EE_Error |
||
1624 | * @throws EntityNotFoundException |
||
1625 | * @throws InvalidArgumentException |
||
1626 | * @throws InvalidDataTypeException |
||
1627 | * @throws InvalidInterfaceException |
||
1628 | * @throws ReflectionException |
||
1629 | * @throws RuntimeException |
||
1630 | */ |
||
1631 | protected function _set_registration_status_from_request($status = false, $notify = false) |
||
1632 | { |
||
1633 | if (isset($this->_req_data['reg_status_change_form'])) { |
||
1634 | $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
||
1635 | ? (array) $this->_req_data['reg_status_change_form']['REG_ID'] |
||
1636 | : array(); |
||
1637 | } else { |
||
1638 | $REG_IDs = isset($this->_req_data['_REG_ID']) |
||
1639 | ? (array) $this->_req_data['_REG_ID'] |
||
1640 | : array(); |
||
1641 | } |
||
1642 | // sanitize $REG_IDs |
||
1643 | $REG_IDs = array_map('absint', $REG_IDs); |
||
1644 | // and remove empty entries |
||
1645 | $REG_IDs = array_filter($REG_IDs); |
||
1646 | |||
1647 | $result = $this->_set_registration_status($REG_IDs, $status, $notify); |
||
1648 | |||
1649 | /** |
||
1650 | * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications. |
||
1651 | * Currently this value is used downstream by the _process_resend_registration method. |
||
1652 | * |
||
1653 | * @param int|array $registration_ids The registration ids that have had their status changed successfully. |
||
1654 | * @param bool $status The status registrations were changed to. |
||
1655 | * @param bool $success If the status was changed successfully for all registrations. |
||
1656 | * @param Registrations_Admin_Page $admin_page_object |
||
1657 | */ |
||
1658 | $this->_req_data['_REG_ID'] = apply_filters( |
||
1659 | 'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs', |
||
1660 | $result['REG_ID'], |
||
1661 | $status, |
||
1662 | $result['success'], |
||
1663 | $this |
||
1664 | ); |
||
1665 | |||
1666 | // notify? |
||
1667 | if ($notify |
||
1668 | && $result['success'] |
||
1669 | && ! empty($this->_req_data['_REG_ID']) |
||
1670 | && EE_Registry::instance()->CAP->current_user_can( |
||
1671 | 'ee_send_message', |
||
1672 | 'espresso_registrations_resend_registration' |
||
1673 | ) |
||
1674 | ) { |
||
1675 | $this->_process_resend_registration(); |
||
1676 | } |
||
1677 | return $result; |
||
1678 | } |
||
1679 | |||
1680 | |||
1681 | /** |
||
1682 | * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
||
1683 | * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
||
1684 | * |
||
1685 | * @param array $REG_IDs |
||
1686 | * @param string $status |
||
1687 | * @param bool $notify Used to indicate whether notification was requested or not. This determines the context |
||
1688 | * slug sent with setting the registration status. |
||
1689 | * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
||
1690 | * @throws EE_Error |
||
1691 | * @throws InvalidArgumentException |
||
1692 | * @throws InvalidDataTypeException |
||
1693 | * @throws InvalidInterfaceException |
||
1694 | * @throws ReflectionException |
||
1695 | * @throws RuntimeException |
||
1696 | * @throws EntityNotFoundException |
||
1697 | * @throws DomainException |
||
1698 | */ |
||
1699 | protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false) |
||
1700 | { |
||
1701 | $success = false; |
||
1702 | // typecast $REG_IDs |
||
1703 | $REG_IDs = (array) $REG_IDs; |
||
1704 | if (! empty($REG_IDs)) { |
||
1705 | $success = true; |
||
1706 | // set default status if none is passed |
||
1707 | $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
||
1708 | $status_context = $notify |
||
1709 | ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
||
1710 | : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN; |
||
1711 | // loop through REG_ID's and change status |
||
1712 | foreach ($REG_IDs as $REG_ID) { |
||
1713 | $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID); |
||
1714 | if ($registration instanceof EE_Registration) { |
||
1715 | $registration->set_status( |
||
1716 | $status, |
||
1717 | false, |
||
1718 | new Context( |
||
1719 | $status_context, |
||
1720 | esc_html__( |
||
1721 | 'Manually triggered status change on a Registration Admin Page route.', |
||
1722 | 'event_espresso' |
||
1723 | ) |
||
1724 | ) |
||
1725 | ); |
||
1726 | $result = $registration->save(); |
||
1727 | // verifying explicit fails because update *may* just return 0 for 0 rows affected |
||
1728 | $success = $result !== false ? $success : false; |
||
1729 | } |
||
1730 | } |
||
1731 | } |
||
1732 | |||
1733 | // return $success and processed registrations |
||
1734 | return array('REG_ID' => $REG_IDs, 'success' => $success); |
||
1735 | } |
||
1736 | |||
1737 | |||
1738 | /** |
||
1739 | * Common logic for setting up success message and redirecting to appropriate route |
||
1740 | * |
||
1741 | * @param string $STS_ID status id for the registration changed to |
||
1742 | * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
||
1743 | * @return void |
||
1744 | * @throws DomainException |
||
1745 | * @throws EE_Error |
||
1746 | * @throws EntityNotFoundException |
||
1747 | * @throws InvalidArgumentException |
||
1748 | * @throws InvalidDataTypeException |
||
1749 | * @throws InvalidInterfaceException |
||
1750 | * @throws ReflectionException |
||
1751 | * @throws RuntimeException |
||
1752 | */ |
||
1753 | protected function _reg_status_change_return($STS_ID, $notify = false) |
||
1754 | { |
||
1755 | $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
||
1756 | : array('success' => false); |
||
1757 | $success = isset($result['success']) && $result['success']; |
||
1758 | // setup success message |
||
1759 | if ($success) { |
||
1760 | if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
||
1761 | $msg = sprintf( |
||
1762 | esc_html__('Registration status has been set to %s', 'event_espresso'), |
||
1763 | EEH_Template::pretty_status($STS_ID, false, 'lower') |
||
1764 | ); |
||
1765 | } else { |
||
1766 | $msg = sprintf( |
||
1767 | esc_html__('Registrations have been set to %s.', 'event_espresso'), |
||
1768 | EEH_Template::pretty_status($STS_ID, false, 'lower') |
||
1769 | ); |
||
1770 | } |
||
1771 | EE_Error::add_success($msg); |
||
1772 | } else { |
||
1773 | EE_Error::add_error( |
||
1774 | esc_html__( |
||
1775 | 'Something went wrong, and the status was not changed', |
||
1776 | 'event_espresso' |
||
1777 | ), |
||
1778 | __FILE__, |
||
1779 | __LINE__, |
||
1780 | __FUNCTION__ |
||
1781 | ); |
||
1782 | } |
||
1783 | if (isset($this->_req_data['return']) && $this->_req_data['return'] === 'view_registration') { |
||
1784 | $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
||
1785 | } else { |
||
1786 | $route = array('action' => 'default'); |
||
1787 | } |
||
1788 | $route = $this->mergeExistingRequestParamsWithRedirectArgs($route); |
||
1789 | $this->_redirect_after_action($success, '', '', $route, true); |
||
1790 | } |
||
1791 | |||
1792 | |||
1793 | /** |
||
1794 | * incoming reg status change from reg details page. |
||
1795 | * |
||
1796 | * @return void |
||
1797 | * @throws EE_Error |
||
1798 | * @throws EntityNotFoundException |
||
1799 | * @throws InvalidArgumentException |
||
1800 | * @throws InvalidDataTypeException |
||
1801 | * @throws InvalidInterfaceException |
||
1802 | * @throws ReflectionException |
||
1803 | * @throws RuntimeException |
||
1804 | * @throws DomainException |
||
1805 | */ |
||
1806 | protected function _change_reg_status() |
||
1807 | { |
||
1808 | $this->_req_data['return'] = 'view_registration'; |
||
1809 | // set notify based on whether the send notifications toggle is set or not |
||
1810 | $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
||
1811 | // $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
||
1812 | $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
||
1813 | ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
||
1814 | switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
||
1815 | case EEM_Registration::status_id_approved: |
||
1816 | case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'): |
||
1817 | $this->approve_registration($notify); |
||
1818 | break; |
||
1819 | case EEM_Registration::status_id_pending_payment: |
||
1820 | case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'): |
||
1821 | $this->pending_registration($notify); |
||
1822 | break; |
||
1823 | case EEM_Registration::status_id_not_approved: |
||
1824 | case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'): |
||
1825 | $this->not_approve_registration($notify); |
||
1826 | break; |
||
1827 | case EEM_Registration::status_id_declined: |
||
1828 | case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'): |
||
1829 | $this->decline_registration($notify); |
||
1830 | break; |
||
1831 | case EEM_Registration::status_id_cancelled: |
||
1832 | case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'): |
||
1833 | $this->cancel_registration($notify); |
||
1834 | break; |
||
1835 | case EEM_Registration::status_id_wait_list: |
||
1836 | case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'): |
||
1837 | $this->wait_list_registration($notify); |
||
1838 | break; |
||
1839 | case EEM_Registration::status_id_incomplete: |
||
1840 | default: |
||
1841 | $result['success'] = false; |
||
1842 | unset($this->_req_data['return']); |
||
1843 | $this->_reg_status_change_return('', false); |
||
1844 | break; |
||
1845 | } |
||
1846 | } |
||
1847 | |||
1848 | |||
1849 | /** |
||
1850 | * Callback for bulk action routes. |
||
1851 | * Note: although we could just register the singular route callbacks for each bulk action route as well, this |
||
1852 | * method was chosen so there is one central place all the registration status bulk actions are going through. |
||
1853 | * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to |
||
1854 | * when an action is happening on just a single registration). |
||
1855 | * |
||
1856 | * @param $action |
||
1857 | * @param bool $notify |
||
1858 | */ |
||
1859 | protected function bulk_action_on_registrations($action, $notify = false) |
||
1860 | { |
||
1861 | do_action( |
||
1862 | 'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution', |
||
1863 | $this, |
||
1864 | $action, |
||
1865 | $notify |
||
1866 | ); |
||
1867 | $method = $action . '_registration'; |
||
1868 | if (method_exists($this, $method)) { |
||
1869 | $this->$method($notify); |
||
1870 | } |
||
1871 | } |
||
1872 | |||
1873 | |||
1874 | /** |
||
1875 | * approve_registration |
||
1876 | * |
||
1877 | * @access protected |
||
1878 | * @param bool $notify whether or not to notify the registrant about their approval. |
||
1879 | * @return void |
||
1880 | * @throws EE_Error |
||
1881 | * @throws EntityNotFoundException |
||
1882 | * @throws InvalidArgumentException |
||
1883 | * @throws InvalidDataTypeException |
||
1884 | * @throws InvalidInterfaceException |
||
1885 | * @throws ReflectionException |
||
1886 | * @throws RuntimeException |
||
1887 | * @throws DomainException |
||
1888 | */ |
||
1889 | protected function approve_registration($notify = false) |
||
1890 | { |
||
1891 | $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
||
1892 | } |
||
1893 | |||
1894 | |||
1895 | /** |
||
1896 | * decline_registration |
||
1897 | * |
||
1898 | * @access protected |
||
1899 | * @param bool $notify whether or not to notify the registrant about their status change. |
||
1900 | * @return void |
||
1901 | * @throws EE_Error |
||
1902 | * @throws EntityNotFoundException |
||
1903 | * @throws InvalidArgumentException |
||
1904 | * @throws InvalidDataTypeException |
||
1905 | * @throws InvalidInterfaceException |
||
1906 | * @throws ReflectionException |
||
1907 | * @throws RuntimeException |
||
1908 | * @throws DomainException |
||
1909 | */ |
||
1910 | protected function decline_registration($notify = false) |
||
1911 | { |
||
1912 | $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
||
1913 | } |
||
1914 | |||
1915 | |||
1916 | /** |
||
1917 | * cancel_registration |
||
1918 | * |
||
1919 | * @access protected |
||
1920 | * @param bool $notify whether or not to notify the registrant about their status change. |
||
1921 | * @return void |
||
1922 | * @throws EE_Error |
||
1923 | * @throws EntityNotFoundException |
||
1924 | * @throws InvalidArgumentException |
||
1925 | * @throws InvalidDataTypeException |
||
1926 | * @throws InvalidInterfaceException |
||
1927 | * @throws ReflectionException |
||
1928 | * @throws RuntimeException |
||
1929 | * @throws DomainException |
||
1930 | */ |
||
1931 | protected function cancel_registration($notify = false) |
||
1932 | { |
||
1933 | $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
||
1934 | } |
||
1935 | |||
1936 | |||
1937 | /** |
||
1938 | * not_approve_registration |
||
1939 | * |
||
1940 | * @access protected |
||
1941 | * @param bool $notify whether or not to notify the registrant about their status change. |
||
1942 | * @return void |
||
1943 | * @throws EE_Error |
||
1944 | * @throws EntityNotFoundException |
||
1945 | * @throws InvalidArgumentException |
||
1946 | * @throws InvalidDataTypeException |
||
1947 | * @throws InvalidInterfaceException |
||
1948 | * @throws ReflectionException |
||
1949 | * @throws RuntimeException |
||
1950 | * @throws DomainException |
||
1951 | */ |
||
1952 | protected function not_approve_registration($notify = false) |
||
1953 | { |
||
1954 | $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
||
1955 | } |
||
1956 | |||
1957 | |||
1958 | /** |
||
1959 | * decline_registration |
||
1960 | * |
||
1961 | * @access protected |
||
1962 | * @param bool $notify whether or not to notify the registrant about their status change. |
||
1963 | * @return void |
||
1964 | * @throws EE_Error |
||
1965 | * @throws EntityNotFoundException |
||
1966 | * @throws InvalidArgumentException |
||
1967 | * @throws InvalidDataTypeException |
||
1968 | * @throws InvalidInterfaceException |
||
1969 | * @throws ReflectionException |
||
1970 | * @throws RuntimeException |
||
1971 | * @throws DomainException |
||
1972 | */ |
||
1973 | protected function pending_registration($notify = false) |
||
1974 | { |
||
1975 | $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
||
1976 | } |
||
1977 | |||
1978 | |||
1979 | /** |
||
1980 | * waitlist_registration |
||
1981 | * |
||
1982 | * @access protected |
||
1983 | * @param bool $notify whether or not to notify the registrant about their status change. |
||
1984 | * @return void |
||
1985 | * @throws EE_Error |
||
1986 | * @throws EntityNotFoundException |
||
1987 | * @throws InvalidArgumentException |
||
1988 | * @throws InvalidDataTypeException |
||
1989 | * @throws InvalidInterfaceException |
||
1990 | * @throws ReflectionException |
||
1991 | * @throws RuntimeException |
||
1992 | * @throws DomainException |
||
1993 | */ |
||
1994 | protected function wait_list_registration($notify = false) |
||
1995 | { |
||
1996 | $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
||
1997 | } |
||
1998 | |||
1999 | |||
2000 | /** |
||
2001 | * generates HTML for the Registration main meta box |
||
2002 | * |
||
2003 | * @access public |
||
2004 | * @return void |
||
2005 | * @throws DomainException |
||
2006 | * @throws EE_Error |
||
2007 | * @throws InvalidArgumentException |
||
2008 | * @throws InvalidDataTypeException |
||
2009 | * @throws InvalidInterfaceException |
||
2010 | * @throws ReflectionException |
||
2011 | * @throws EntityNotFoundException |
||
2012 | */ |
||
2013 | public function _reg_details_meta_box() |
||
2014 | { |
||
2015 | EEH_Autoloader::register_line_item_display_autoloaders(); |
||
2016 | EEH_Autoloader::register_line_item_filter_autoloaders(); |
||
2017 | EE_Registry::instance()->load_helper('Line_Item'); |
||
2018 | $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
||
2019 | : EE_Transaction::new_instance(); |
||
2020 | $this->_session = $transaction->session_data(); |
||
2021 | $filters = new EE_Line_Item_Filter_Collection(); |
||
2022 | $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
||
2023 | $filters->add(new EE_Non_Zero_Line_Item_Filter()); |
||
2024 | $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
||
2025 | $filters, |
||
2026 | $transaction->total_line_item() |
||
2027 | ); |
||
2028 | $filtered_line_item_tree = $line_item_filter_processor->process(); |
||
2029 | $line_item_display = new EE_Line_Item_Display( |
||
2030 | 'reg_admin_table', |
||
2031 | 'EE_Admin_Table_Registration_Line_Item_Display_Strategy' |
||
2032 | ); |
||
2033 | $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
||
2034 | $filtered_line_item_tree, |
||
2035 | array('EE_Registration' => $this->_registration) |
||
2036 | ); |
||
2037 | $attendee = $this->_registration->attendee(); |
||
2038 | View Code Duplication | if (EE_Registry::instance()->CAP->current_user_can( |
|
2039 | 'ee_read_transaction', |
||
2040 | 'espresso_transactions_view_transaction' |
||
2041 | )) { |
||
2042 | $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
||
2043 | EE_Admin_Page::add_query_args_and_nonce( |
||
2044 | array( |
||
2045 | 'action' => 'view_transaction', |
||
2046 | 'TXN_ID' => $transaction->ID(), |
||
2047 | ), |
||
2048 | TXN_ADMIN_URL |
||
2049 | ), |
||
2050 | esc_html__(' View Transaction', 'event_espresso'), |
||
2051 | 'button secondary-button right', |
||
2052 | 'dashicons dashicons-cart' |
||
2053 | ); |
||
2054 | } else { |
||
2055 | $this->_template_args['view_transaction_button'] = ''; |
||
2056 | } |
||
2057 | if ($attendee instanceof EE_Attendee |
||
2058 | && EE_Registry::instance()->CAP->current_user_can( |
||
2059 | 'ee_send_message', |
||
2060 | 'espresso_registrations_resend_registration' |
||
2061 | ) |
||
2062 | ) { |
||
2063 | $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
||
2064 | EE_Admin_Page::add_query_args_and_nonce( |
||
2065 | array( |
||
2066 | 'action' => 'resend_registration', |
||
2067 | '_REG_ID' => $this->_registration->ID(), |
||
2068 | 'redirect_to' => 'view_registration', |
||
2069 | ), |
||
2070 | REG_ADMIN_URL |
||
2071 | ), |
||
2072 | esc_html__(' Resend Registration', 'event_espresso'), |
||
2073 | 'button secondary-button right', |
||
2074 | 'dashicons dashicons-email-alt' |
||
2075 | ); |
||
2076 | } else { |
||
2077 | $this->_template_args['resend_registration_button'] = ''; |
||
2078 | } |
||
2079 | $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
||
2080 | $payment = $transaction->get_first_related('Payment'); |
||
2081 | $payment = ! $payment instanceof EE_Payment |
||
2082 | ? EE_Payment::new_instance() |
||
2083 | : $payment; |
||
2084 | $payment_method = $payment->get_first_related('Payment_Method'); |
||
2085 | $payment_method = ! $payment_method instanceof EE_Payment_Method |
||
2086 | ? EE_Payment_Method::new_instance() |
||
2087 | : $payment_method; |
||
2088 | $reg_details = array( |
||
2089 | 'payment_method' => $payment_method->name(), |
||
2090 | 'response_msg' => $payment->gateway_response(), |
||
2091 | 'registration_id' => $this->_registration->get('REG_code'), |
||
2092 | 'registration_session' => $this->_registration->session_ID(), |
||
2093 | 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
||
2094 | 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
||
2095 | ); |
||
2096 | if (isset($reg_details['registration_id'])) { |
||
2097 | $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
||
2098 | $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
||
2099 | 'Registration ID', |
||
2100 | 'event_espresso' |
||
2101 | ); |
||
2102 | $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
||
2103 | } |
||
2104 | if (isset($reg_details['payment_method'])) { |
||
2105 | $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
||
2106 | $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
||
2107 | 'Most Recent Payment Method', |
||
2108 | 'event_espresso' |
||
2109 | ); |
||
2110 | $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
||
2111 | $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
||
2112 | $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
||
2113 | 'Payment method response', |
||
2114 | 'event_espresso' |
||
2115 | ); |
||
2116 | $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
||
2117 | } |
||
2118 | $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
||
2119 | $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
||
2120 | 'Registration Session', |
||
2121 | 'event_espresso' |
||
2122 | ); |
||
2123 | $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
||
2124 | $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
||
2125 | $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
||
2126 | 'Registration placed from IP', |
||
2127 | 'event_espresso' |
||
2128 | ); |
||
2129 | $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
||
2130 | $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
||
2131 | $this->_template_args['reg_details']['user_agent']['label'] = esc_html__( |
||
2132 | 'Registrant User Agent', |
||
2133 | 'event_espresso' |
||
2134 | ); |
||
2135 | $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
||
2136 | $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
||
2137 | array( |
||
2138 | 'action' => 'default', |
||
2139 | 'event_id' => $this->_registration->event_ID(), |
||
2140 | ), |
||
2141 | REG_ADMIN_URL |
||
2142 | ); |
||
2143 | $this->_template_args['REG_ID'] = $this->_registration->ID(); |
||
2144 | $this->_template_args['event_id'] = $this->_registration->event_ID(); |
||
2145 | $template_path = |
||
2146 | REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
||
2147 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
||
2148 | } |
||
2149 | |||
2150 | |||
2151 | /** |
||
2152 | * generates HTML for the Registration Questions meta box. |
||
2153 | * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
||
2154 | * otherwise uses new forms system |
||
2155 | * |
||
2156 | * @access public |
||
2157 | * @return void |
||
2158 | * @throws DomainException |
||
2159 | * @throws EE_Error |
||
2160 | * @throws InvalidArgumentException |
||
2161 | * @throws InvalidDataTypeException |
||
2162 | * @throws InvalidInterfaceException |
||
2163 | * @throws ReflectionException |
||
2164 | */ |
||
2165 | public function _reg_questions_meta_box() |
||
2166 | { |
||
2167 | // allow someone to override this method entirely |
||
2168 | if (apply_filters( |
||
2169 | 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', |
||
2170 | true, |
||
2171 | $this, |
||
2172 | $this->_registration |
||
2173 | )) { |
||
2174 | $form = $this->_get_reg_custom_questions_form( |
||
2175 | $this->_registration->ID() |
||
2176 | ); |
||
2177 | $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
||
2178 | ? $form->get_html_and_js() |
||
2179 | : ''; |
||
2180 | $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
||
2181 | $this->_template_args['REG_ID'] = $this->_registration->ID(); |
||
2182 | $template_path = |
||
2183 | REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
||
2184 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
||
2185 | } |
||
2186 | } |
||
2187 | |||
2188 | |||
2189 | /** |
||
2190 | * form_before_question_group |
||
2191 | * |
||
2192 | * @deprecated as of 4.8.32.rc.000 |
||
2193 | * @access public |
||
2194 | * @param string $output |
||
2195 | * @return string |
||
2196 | */ |
||
2197 | public function form_before_question_group($output) |
||
2198 | { |
||
2199 | EE_Error::doing_it_wrong( |
||
2200 | __CLASS__ . '::' . __FUNCTION__, |
||
2201 | esc_html__( |
||
2202 | 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
||
2203 | 'event_espresso' |
||
2204 | ), |
||
2205 | '4.8.32.rc.000' |
||
2206 | ); |
||
2207 | return ' |
||
2208 | <table class="form-table ee-width-100"> |
||
2209 | <tbody> |
||
2210 | '; |
||
2211 | } |
||
2212 | |||
2213 | |||
2214 | /** |
||
2215 | * form_after_question_group |
||
2216 | * |
||
2217 | * @deprecated as of 4.8.32.rc.000 |
||
2218 | * @access public |
||
2219 | * @param string $output |
||
2220 | * @return string |
||
2221 | */ |
||
2222 | public function form_after_question_group($output) |
||
2223 | { |
||
2224 | EE_Error::doing_it_wrong( |
||
2225 | __CLASS__ . '::' . __FUNCTION__, |
||
2226 | esc_html__( |
||
2227 | 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
||
2228 | 'event_espresso' |
||
2229 | ), |
||
2230 | '4.8.32.rc.000' |
||
2231 | ); |
||
2232 | return ' |
||
2233 | <tr class="hide-if-no-js"> |
||
2234 | <th> </th> |
||
2235 | <td class="reg-admin-edit-attendee-question-td"> |
||
2236 | <a class="reg-admin-edit-attendee-question-lnk" href="#" title="' |
||
2237 | . esc_attr__('click to edit question', 'event_espresso') |
||
2238 | . '"> |
||
2239 | <span class="reg-admin-edit-question-group-spn lt-grey-txt">' |
||
2240 | . esc_html__('edit the above question group', 'event_espresso') |
||
2241 | . '</span> |
||
2242 | <div class="dashicons dashicons-edit"></div> |
||
2243 | </a> |
||
2244 | </td> |
||
2245 | </tr> |
||
2246 | </tbody> |
||
2247 | </table> |
||
2248 | '; |
||
2249 | } |
||
2250 | |||
2251 | |||
2252 | /** |
||
2253 | * form_form_field_label_wrap |
||
2254 | * |
||
2255 | * @deprecated as of 4.8.32.rc.000 |
||
2256 | * @access public |
||
2257 | * @param string $label |
||
2258 | * @return string |
||
2259 | */ |
||
2260 | View Code Duplication | public function form_form_field_label_wrap($label) |
|
2261 | { |
||
2262 | EE_Error::doing_it_wrong( |
||
2263 | __CLASS__ . '::' . __FUNCTION__, |
||
2264 | esc_html__( |
||
2265 | 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
||
2266 | 'event_espresso' |
||
2267 | ), |
||
2268 | '4.8.32.rc.000' |
||
2269 | ); |
||
2270 | return ' |
||
2271 | <tr> |
||
2272 | <th> |
||
2273 | ' . $label . ' |
||
2274 | </th>'; |
||
2275 | } |
||
2276 | |||
2277 | |||
2278 | /** |
||
2279 | * form_form_field_input__wrap |
||
2280 | * |
||
2281 | * @deprecated as of 4.8.32.rc.000 |
||
2282 | * @access public |
||
2283 | * @param string $input |
||
2284 | * @return string |
||
2285 | */ |
||
2286 | View Code Duplication | public function form_form_field_input__wrap($input) |
|
2287 | { |
||
2288 | EE_Error::doing_it_wrong( |
||
2289 | __CLASS__ . '::' . __FUNCTION__, |
||
2290 | esc_html__( |
||
2291 | 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
||
2292 | 'event_espresso' |
||
2293 | ), |
||
2294 | '4.8.32.rc.000' |
||
2295 | ); |
||
2296 | return ' |
||
2297 | <td class="reg-admin-attendee-questions-input-td disabled-input"> |
||
2298 | ' . $input . ' |
||
2299 | </td> |
||
2300 | </tr>'; |
||
2301 | } |
||
2302 | |||
2303 | |||
2304 | /** |
||
2305 | * Updates the registration's custom questions according to the form info, if the form is submitted. |
||
2306 | * If it's not a post, the "view_registrations" route will be called next on the SAME request |
||
2307 | * to display the page |
||
2308 | * |
||
2309 | * @access protected |
||
2310 | * @return void |
||
2311 | * @throws EE_Error |
||
2312 | * @throws InvalidArgumentException |
||
2313 | * @throws InvalidDataTypeException |
||
2314 | * @throws InvalidInterfaceException |
||
2315 | * @throws ReflectionException |
||
2316 | */ |
||
2317 | protected function _update_attendee_registration_form() |
||
2318 | { |
||
2319 | do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
||
2320 | if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
||
2321 | $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
||
2322 | $success = $this->_save_reg_custom_questions_form($REG_ID); |
||
2323 | if ($success) { |
||
2324 | $what = esc_html__('Registration Form', 'event_espresso'); |
||
2325 | $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
||
2326 | : array('action' => 'default'); |
||
2327 | $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route); |
||
2328 | } |
||
2329 | } |
||
2330 | } |
||
2331 | |||
2332 | |||
2333 | /** |
||
2334 | * Gets the form for saving registrations custom questions (if done |
||
2335 | * previously retrieves the cached form object, which may have validation errors in it) |
||
2336 | * |
||
2337 | * @param int $REG_ID |
||
2338 | * @return EE_Registration_Custom_Questions_Form |
||
2339 | * @throws EE_Error |
||
2340 | * @throws InvalidArgumentException |
||
2341 | * @throws InvalidDataTypeException |
||
2342 | * @throws InvalidInterfaceException |
||
2343 | */ |
||
2344 | protected function _get_reg_custom_questions_form($REG_ID) |
||
2345 | { |
||
2346 | if (! $this->_reg_custom_questions_form) { |
||
2347 | require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php'); |
||
2348 | $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
||
2349 | $this->getRegistrationModel()->get_one_by_ID($REG_ID) |
||
2350 | ); |
||
2351 | $this->_reg_custom_questions_form->_construct_finalize(null, null); |
||
2352 | } |
||
2353 | return $this->_reg_custom_questions_form; |
||
2354 | } |
||
2355 | |||
2356 | |||
2357 | /** |
||
2358 | * Saves |
||
2359 | * |
||
2360 | * @access private |
||
2361 | * @param bool $REG_ID |
||
2362 | * @return bool |
||
2363 | * @throws EE_Error |
||
2364 | * @throws InvalidArgumentException |
||
2365 | * @throws InvalidDataTypeException |
||
2366 | * @throws InvalidInterfaceException |
||
2367 | * @throws ReflectionException |
||
2368 | */ |
||
2369 | private function _save_reg_custom_questions_form($REG_ID = false) |
||
2370 | { |
||
2371 | if (! $REG_ID) { |
||
2372 | EE_Error::add_error( |
||
2373 | esc_html__( |
||
2374 | 'An error occurred. No registration ID was received.', |
||
2375 | 'event_espresso' |
||
2376 | ), |
||
2377 | __FILE__, |
||
2378 | __FUNCTION__, |
||
2379 | __LINE__ |
||
2380 | ); |
||
2381 | } |
||
2382 | $form = $this->_get_reg_custom_questions_form($REG_ID); |
||
2383 | $form->receive_form_submission($this->_req_data); |
||
2384 | $success = false; |
||
2385 | if ($form->is_valid()) { |
||
2386 | foreach ($form->subforms() as $question_group_id => $question_group_form) { |
||
2387 | foreach ($question_group_form->inputs() as $question_id => $input) { |
||
2388 | $where_conditions = array( |
||
2389 | 'QST_ID' => $question_id, |
||
2390 | 'REG_ID' => $REG_ID, |
||
2391 | ); |
||
2392 | $possibly_new_values = array( |
||
2393 | 'ANS_value' => $input->normalized_value(), |
||
2394 | ); |
||
2395 | $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
||
2396 | if ($answer instanceof EE_Answer) { |
||
2397 | $success = $answer->save($possibly_new_values); |
||
2398 | } else { |
||
2399 | // insert it then |
||
2400 | $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
||
2401 | $answer = EE_Answer::new_instance($cols_n_vals); |
||
2402 | $success = $answer->save(); |
||
2403 | } |
||
2404 | } |
||
2405 | } |
||
2406 | } else { |
||
2407 | EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
||
2408 | } |
||
2409 | return $success; |
||
2410 | } |
||
2411 | |||
2412 | |||
2413 | /** |
||
2414 | * generates HTML for the Registration main meta box |
||
2415 | * |
||
2416 | * @access public |
||
2417 | * @return void |
||
2418 | * @throws DomainException |
||
2419 | * @throws EE_Error |
||
2420 | * @throws InvalidArgumentException |
||
2421 | * @throws InvalidDataTypeException |
||
2422 | * @throws InvalidInterfaceException |
||
2423 | * @throws ReflectionException |
||
2424 | */ |
||
2425 | public function _reg_attendees_meta_box() |
||
2426 | { |
||
2427 | $REG = $this->getRegistrationModel(); |
||
2428 | // get all other registrations on this transaction, and cache |
||
2429 | // the attendees for them so we don't have to run another query using force_join |
||
2430 | $registrations = $REG->get_all( |
||
2431 | array( |
||
2432 | array( |
||
2433 | 'TXN_ID' => $this->_registration->transaction_ID(), |
||
2434 | 'REG_ID' => array('!=', $this->_registration->ID()), |
||
2435 | ), |
||
2436 | 'force_join' => array('Attendee'), |
||
2437 | 'default_where_conditions' => 'other_models_only', |
||
2438 | ) |
||
2439 | ); |
||
2440 | $this->_template_args['attendees'] = array(); |
||
2441 | $this->_template_args['attendee_notice'] = ''; |
||
2442 | if (empty($registrations) |
||
2443 | || (is_array($registrations) |
||
2444 | && ! EEH_Array::get_one_item_from_array($registrations)) |
||
2445 | ) { |
||
2446 | EE_Error::add_error( |
||
2447 | esc_html__( |
||
2448 | 'There are no records attached to this registration. Something may have gone wrong with the registration', |
||
2449 | 'event_espresso' |
||
2450 | ), |
||
2451 | __FILE__, |
||
2452 | __FUNCTION__, |
||
2453 | __LINE__ |
||
2454 | ); |
||
2455 | $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
||
2456 | } else { |
||
2457 | $att_nmbr = 1; |
||
2458 | foreach ($registrations as $registration) { |
||
2459 | /* @var $registration EE_Registration */ |
||
2460 | $attendee = $registration->attendee() |
||
2461 | ? $registration->attendee() |
||
2462 | : $this->getAttendeeModel()->create_default_object(); |
||
2463 | $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID(); |
||
2464 | $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname(); |
||
2465 | $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname(); |
||
2466 | $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email(); |
||
2467 | $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price(); |
||
2468 | $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode( |
||
2469 | ', ', |
||
2470 | $attendee->full_address_as_array() |
||
2471 | ); |
||
2472 | $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce( |
||
2473 | array( |
||
2474 | 'action' => 'edit_attendee', |
||
2475 | 'post' => $attendee->ID(), |
||
2476 | ), |
||
2477 | REG_ADMIN_URL |
||
2478 | ); |
||
2479 | $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event |
||
2480 | ? $registration->event_obj()->name() |
||
2481 | : ''; |
||
2482 | $att_nmbr++; |
||
2483 | } |
||
2484 | $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
||
2485 | } |
||
2486 | $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
||
2487 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
||
2488 | } |
||
2489 | |||
2490 | |||
2491 | /** |
||
2492 | * generates HTML for the Edit Registration side meta box |
||
2493 | * |
||
2494 | * @access public |
||
2495 | * @return void |
||
2496 | * @throws DomainException |
||
2497 | * @throws EE_Error |
||
2498 | * @throws InvalidArgumentException |
||
2499 | * @throws InvalidDataTypeException |
||
2500 | * @throws InvalidInterfaceException |
||
2501 | * @throws ReflectionException |
||
2502 | */ |
||
2503 | public function _reg_registrant_side_meta_box() |
||
2504 | { |
||
2505 | /*@var $attendee EE_Attendee */ |
||
2506 | $att_check = $this->_registration->attendee(); |
||
2507 | $attendee = $att_check instanceof EE_Attendee |
||
2508 | ? $att_check |
||
2509 | : $this->getAttendeeModel()->create_default_object(); |
||
2510 | // now let's determine if this is not the primary registration. If it isn't then we set the |
||
2511 | // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
||
2512 | // primary registration object (that way we know if we need to show create button or not) |
||
2513 | if (! $this->_registration->is_primary_registrant()) { |
||
2514 | $primary_registration = $this->_registration->get_primary_registration(); |
||
2515 | $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
||
2516 | : null; |
||
2517 | if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
||
2518 | // in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
||
2519 | // custom attendee object so let's not worry about the primary reg. |
||
2520 | $primary_registration = null; |
||
2521 | } |
||
2522 | } else { |
||
2523 | $primary_registration = null; |
||
2524 | } |
||
2525 | $this->_template_args['ATT_ID'] = $attendee->ID(); |
||
2526 | $this->_template_args['fname'] = $attendee->fname(); |
||
2527 | $this->_template_args['lname'] = $attendee->lname(); |
||
2528 | $this->_template_args['email'] = $attendee->email(); |
||
2529 | $this->_template_args['phone'] = $attendee->phone(); |
||
2530 | $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
||
2531 | // edit link |
||
2532 | $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce( |
||
2533 | array( |
||
2534 | 'action' => 'edit_attendee', |
||
2535 | 'post' => $attendee->ID(), |
||
2536 | ), |
||
2537 | REG_ADMIN_URL |
||
2538 | ); |
||
2539 | $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
||
2540 | // create link |
||
2541 | $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
||
2542 | ? EE_Admin_Page::add_query_args_and_nonce( |
||
2543 | array( |
||
2544 | 'action' => 'duplicate_attendee', |
||
2545 | '_REG_ID' => $this->_registration->ID(), |
||
2546 | ), |
||
2547 | REG_ADMIN_URL |
||
2548 | ) : ''; |
||
2549 | $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
||
2550 | $this->_template_args['att_check'] = $att_check; |
||
2551 | $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
||
2552 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
||
2553 | } |
||
2554 | |||
2555 | |||
2556 | /** |
||
2557 | * trash or restore registrations |
||
2558 | * |
||
2559 | * @param boolean $trash whether to archive or restore |
||
2560 | * @return void |
||
2561 | * @throws EE_Error |
||
2562 | * @throws InvalidArgumentException |
||
2563 | * @throws InvalidDataTypeException |
||
2564 | * @throws InvalidInterfaceException |
||
2565 | * @throws RuntimeException |
||
2566 | * @access protected |
||
2567 | */ |
||
2568 | protected function _trash_or_restore_registrations($trash = true) |
||
2569 | { |
||
2570 | // if empty _REG_ID then get out because there's nothing to do |
||
2571 | View Code Duplication | if (empty($this->_req_data['_REG_ID'])) { |
|
2572 | EE_Error::add_error( |
||
2573 | sprintf( |
||
2574 | esc_html__( |
||
2575 | 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
||
2576 | 'event_espresso' |
||
2577 | ), |
||
2578 | $trash ? 'trash' : 'restore' |
||
2579 | ), |
||
2580 | __FILE__, |
||
2581 | __LINE__, |
||
2582 | __FUNCTION__ |
||
2583 | ); |
||
2584 | $this->_redirect_after_action(false, '', '', array(), true); |
||
2585 | } |
||
2586 | $success = 0; |
||
2587 | $overwrite_msgs = false; |
||
2588 | // Checkboxes |
||
2589 | if (! is_array($this->_req_data['_REG_ID'])) { |
||
2590 | $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
||
2591 | } |
||
2592 | $reg_count = count($this->_req_data['_REG_ID']); |
||
2593 | // cycle thru checkboxes |
||
2594 | foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
||
2595 | /** @var EE_Registration $REG */ |
||
2596 | $REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID); |
||
2597 | $payments = $REG->registration_payments(); |
||
2598 | if (! empty($payments)) { |
||
2599 | $name = $REG->attendee() instanceof EE_Attendee |
||
2600 | ? $REG->attendee()->full_name() |
||
2601 | : esc_html__('Unknown Attendee', 'event_espresso'); |
||
2602 | $overwrite_msgs = true; |
||
2603 | EE_Error::add_error( |
||
2604 | sprintf( |
||
2605 | esc_html__( |
||
2606 | '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.', |
||
2607 | 'event_espresso' |
||
2608 | ), |
||
2609 | $name |
||
2610 | ), |
||
2611 | __FILE__, |
||
2612 | __FUNCTION__, |
||
2613 | __LINE__ |
||
2614 | ); |
||
2615 | // can't trash this registration because it has payments. |
||
2616 | continue; |
||
2617 | } |
||
2618 | $updated = $trash ? $REG->delete() : $REG->restore(); |
||
2619 | if ($updated) { |
||
2620 | $success++; |
||
2621 | } |
||
2622 | } |
||
2623 | $this->_redirect_after_action( |
||
2624 | $success === $reg_count, // were ALL registrations affected? |
||
2625 | $success > 1 |
||
2626 | ? esc_html__('Registrations', 'event_espresso') |
||
2627 | : esc_html__('Registration', 'event_espresso'), |
||
2628 | $trash |
||
2629 | ? esc_html__('moved to the trash', 'event_espresso') |
||
2630 | : esc_html__('restored', 'event_espresso'), |
||
2631 | $this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')), |
||
2632 | $overwrite_msgs |
||
2633 | ); |
||
2634 | } |
||
2635 | |||
2636 | |||
2637 | /** |
||
2638 | * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
||
2639 | * registration but also. |
||
2640 | * 1. Removing relations to EE_Attendee |
||
2641 | * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
||
2642 | * ALSO trashed. |
||
2643 | * 3. Deleting permanently any related Line items but only if the above conditions are met. |
||
2644 | * 4. Removing relationships between all tickets and the related registrations |
||
2645 | * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
||
2646 | * 6. Deleting permanently any related Checkins. |
||
2647 | * |
||
2648 | * @return void |
||
2649 | * @throws EE_Error |
||
2650 | * @throws InvalidArgumentException |
||
2651 | * @throws InvalidDataTypeException |
||
2652 | * @throws InvalidInterfaceException |
||
2653 | * @throws ReflectionException |
||
2654 | */ |
||
2655 | protected function _delete_registrations() |
||
2656 | { |
||
2657 | $REG_MDL = $this->getRegistrationModel(); |
||
2658 | $success = 1; |
||
2659 | // Checkboxes |
||
2660 | if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
||
2661 | // if array has more than one element than success message should be plural |
||
2662 | $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
||
2663 | // cycle thru checkboxes |
||
2664 | foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
||
2665 | $REG = $REG_MDL->get_one_by_ID($REG_ID); |
||
2666 | if (! $REG instanceof EE_Registration) { |
||
2667 | continue; |
||
2668 | } |
||
2669 | $deleted = $this->_delete_registration($REG); |
||
2670 | if (! $deleted) { |
||
2671 | $success = 0; |
||
2672 | } |
||
2673 | } |
||
2674 | } else { |
||
2675 | // grab single id and delete |
||
2676 | $REG_ID = $this->_req_data['_REG_ID']; |
||
2677 | /** @var EE_Registration $REG */ |
||
2678 | $REG = $REG_MDL->get_one_by_ID($REG_ID); |
||
2679 | $deleted = $this->_delete_registration($REG); |
||
2680 | if (! $deleted) { |
||
2681 | $success = 0; |
||
2682 | } |
||
2683 | } |
||
2684 | $what = $success > 1 |
||
2685 | ? esc_html__('Registrations', 'event_espresso') |
||
2686 | : esc_html__('Registration', 'event_espresso'); |
||
2687 | $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
||
2688 | $this->_redirect_after_action( |
||
2689 | $success, |
||
2690 | $what, |
||
2691 | $action_desc, |
||
2692 | $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']), |
||
2693 | true |
||
2694 | ); |
||
2695 | } |
||
2696 | |||
2697 | |||
2698 | /** |
||
2699 | * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
||
2700 | * models get affected. |
||
2701 | * |
||
2702 | * @param EE_Registration $REG registration to be deleted permanently |
||
2703 | * @return bool true = successful deletion, false = fail. |
||
2704 | * @throws EE_Error |
||
2705 | * @throws InvalidArgumentException |
||
2706 | * @throws InvalidDataTypeException |
||
2707 | * @throws InvalidInterfaceException |
||
2708 | * @throws ReflectionException |
||
2709 | */ |
||
2710 | protected function _delete_registration(EE_Registration $REG) |
||
2770 | |||
2771 | |||
2772 | /** |
||
2773 | * generates HTML for the Register New Attendee Admin page |
||
2774 | * |
||
2775 | * @access private |
||
2776 | * @throws DomainException |
||
2777 | * @throws EE_Error |
||
2778 | * @throws InvalidArgumentException |
||
2779 | * @throws InvalidDataTypeException |
||
2780 | * @throws InvalidInterfaceException |
||
2781 | * @throws ReflectionException |
||
2782 | */ |
||
2783 | public function new_registration() |
||
2839 | |||
2840 | |||
2841 | /** |
||
2842 | * This returns the content for a registration step |
||
2843 | * |
||
2844 | * @access protected |
||
2845 | * @return string html |
||
2846 | * @throws DomainException |
||
2847 | * @throws EE_Error |
||
2848 | * @throws InvalidArgumentException |
||
2849 | * @throws InvalidDataTypeException |
||
2850 | * @throws InvalidInterfaceException |
||
2851 | */ |
||
2852 | protected function _get_registration_step_content() |
||
2944 | |||
2945 | |||
2946 | /** |
||
2947 | * set_reg_event |
||
2948 | * |
||
2949 | * @access private |
||
2950 | * @return bool |
||
2951 | * @throws EE_Error |
||
2952 | * @throws InvalidArgumentException |
||
2953 | * @throws InvalidDataTypeException |
||
2954 | * @throws InvalidInterfaceException |
||
2955 | */ |
||
2956 | private function _set_reg_event() |
||
2968 | |||
2969 | |||
2970 | /** |
||
2971 | * process_reg_step |
||
2972 | * |
||
2973 | * @access public |
||
2974 | * @return string |
||
2975 | * @throws DomainException |
||
2976 | * @throws EE_Error |
||
2977 | * @throws InvalidArgumentException |
||
2978 | * @throws InvalidDataTypeException |
||
2979 | * @throws InvalidInterfaceException |
||
2980 | * @throws ReflectionException |
||
2981 | * @throws RuntimeException |
||
2982 | */ |
||
2983 | public function process_reg_step() |
||
3085 | |||
3086 | |||
3087 | /** |
||
3088 | * redirect_to_txn |
||
3089 | * |
||
3090 | * @access public |
||
3091 | * @return void |
||
3092 | * @throws EE_Error |
||
3093 | * @throws InvalidArgumentException |
||
3094 | * @throws InvalidDataTypeException |
||
3095 | * @throws InvalidInterfaceException |
||
3096 | * @throws ReflectionException |
||
3097 | */ |
||
3098 | public function redirect_to_txn() |
||
3120 | |||
3121 | |||
3122 | /** |
||
3123 | * generates HTML for the Attendee Contact List |
||
3124 | * |
||
3125 | * @access protected |
||
3126 | * @return void |
||
3127 | * @throws DomainException |
||
3128 | * @throws EE_Error |
||
3129 | */ |
||
3130 | protected function _attendee_contact_list_table() |
||
3136 | |||
3137 | |||
3138 | /** |
||
3139 | * get_attendees |
||
3140 | * |
||
3141 | * @param $per_page |
||
3142 | * @param bool $count whether to return count or data. |
||
3143 | * @param bool $trash |
||
3144 | * @return array |
||
3145 | * @throws EE_Error |
||
3146 | * @throws InvalidArgumentException |
||
3147 | * @throws InvalidDataTypeException |
||
3148 | * @throws InvalidInterfaceException |
||
3149 | * @access public |
||
3150 | */ |
||
3151 | public function get_attendees($per_page, $count = false, $trash = false) |
||
3236 | |||
3237 | |||
3238 | /** |
||
3239 | * This is just taking care of resending the registration confirmation |
||
3240 | * |
||
3241 | * @access protected |
||
3242 | * @return void |
||
3243 | * @throws EE_Error |
||
3244 | * @throws InvalidArgumentException |
||
3245 | * @throws InvalidDataTypeException |
||
3246 | * @throws InvalidInterfaceException |
||
3247 | * @throws ReflectionException |
||
3248 | */ |
||
3249 | protected function _resend_registration() |
||
3257 | |||
3258 | /** |
||
3259 | * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
||
3260 | * to use when selecting registrations |
||
3261 | * |
||
3262 | * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
||
3263 | * the query parameters from the request |
||
3264 | * @return void ends the request with a redirect or download |
||
3265 | */ |
||
3266 | public function _registrations_report_base($method_name_for_getting_query_params) |
||
3306 | |||
3307 | |||
3308 | /** |
||
3309 | * Creates a registration report using only query parameters in the request |
||
3310 | * |
||
3311 | * @return void |
||
3312 | */ |
||
3313 | public function _registrations_report() |
||
3317 | |||
3318 | |||
3319 | public function _contact_list_export() |
||
3327 | |||
3328 | |||
3329 | public function _contact_list_report() |
||
3350 | |||
3351 | |||
3352 | |||
3353 | |||
3354 | |||
3355 | /*************************************** ATTENDEE DETAILS ***************************************/ |
||
3356 | /** |
||
3357 | * This duplicates the attendee object for the given incoming registration id and attendee_id. |
||
3358 | * |
||
3359 | * @return void |
||
3360 | * @throws EE_Error |
||
3361 | * @throws InvalidArgumentException |
||
3362 | * @throws InvalidDataTypeException |
||
3363 | * @throws InvalidInterfaceException |
||
3364 | * @throws ReflectionException |
||
3365 | */ |
||
3366 | protected function _duplicate_attendee() |
||
3404 | |||
3405 | |||
3406 | /** |
||
3407 | * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook. |
||
3408 | * |
||
3409 | * @param int $post_id |
||
3410 | * @param WP_POST $post |
||
3411 | * @throws DomainException |
||
3412 | * @throws EE_Error |
||
3413 | * @throws InvalidArgumentException |
||
3414 | * @throws InvalidDataTypeException |
||
3415 | * @throws InvalidInterfaceException |
||
3416 | * @throws LogicException |
||
3417 | * @throws InvalidFormSubmissionException |
||
3418 | * @throws ReflectionException |
||
3419 | */ |
||
3420 | protected function _insert_update_cpt_item($post_id, $post) |
||
3479 | |||
3480 | |||
3481 | public function trash_cpt_item($post_id) |
||
3484 | |||
3485 | |||
3486 | public function delete_cpt_item($post_id) |
||
3489 | |||
3490 | |||
3491 | public function restore_cpt_item($post_id) |
||
3494 | |||
3495 | |||
3496 | protected function _restore_cpt_item($post_id, $revision_id) |
||
3499 | |||
3500 | |||
3501 | /** |
||
3502 | * @throws EE_Error |
||
3503 | * @since $VID:$ |
||
3504 | */ |
||
3505 | public function attendee_editor_metaboxes() |
||
3558 | |||
3559 | |||
3560 | /** |
||
3561 | * Metabox for attendee contact info |
||
3562 | * |
||
3563 | * @param WP_Post $post wp post object |
||
3564 | * @return string attendee contact info ( and form ) |
||
3565 | * @throws EE_Error |
||
3566 | * @throws InvalidArgumentException |
||
3567 | * @throws InvalidDataTypeException |
||
3568 | * @throws InvalidInterfaceException |
||
3569 | * @throws LogicException |
||
3570 | * @throws DomainException |
||
3571 | */ |
||
3572 | public function attendee_contact_info($post) |
||
3579 | |||
3580 | |||
3581 | /** |
||
3582 | * Return form handler for the contact details metabox |
||
3583 | * |
||
3584 | * @param EE_Attendee $attendee |
||
3585 | * @return AttendeeContactDetailsMetaboxFormHandler |
||
3586 | * @throws DomainException |
||
3587 | * @throws InvalidArgumentException |
||
3588 | * @throws InvalidDataTypeException |
||
3589 | * @throws InvalidInterfaceException |
||
3590 | */ |
||
3591 | protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee) |
||
3595 | |||
3596 | |||
3597 | /** |
||
3598 | * Metabox for attendee details |
||
3599 | * |
||
3600 | * @param WP_Post $post wp post object |
||
3601 | * @throws DomainException |
||
3602 | */ |
||
3603 | public function attendee_address_details($post) |
||
3657 | |||
3658 | |||
3659 | /** |
||
3660 | * _attendee_details |
||
3661 | * |
||
3662 | * @access protected |
||
3663 | * @param $post |
||
3664 | * @return void |
||
3665 | * @throws DomainException |
||
3666 | * @throws EE_Error |
||
3667 | * @throws InvalidArgumentException |
||
3668 | * @throws InvalidDataTypeException |
||
3669 | * @throws InvalidInterfaceException |
||
3670 | * @throws ReflectionException |
||
3671 | */ |
||
3672 | public function attendee_registrations_meta_box($post) |
||
3680 | |||
3681 | |||
3682 | /** |
||
3683 | * add in the form fields for the attendee edit |
||
3684 | * |
||
3685 | * @param WP_Post $post wp post object |
||
3686 | * @return string html for new form. |
||
3687 | * @throws DomainException |
||
3688 | */ |
||
3689 | public function after_title_form_fields($post) |
||
3697 | |||
3698 | |||
3699 | /** |
||
3700 | * _trash_or_restore_attendee |
||
3701 | * |
||
3702 | * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
||
3703 | * @return void |
||
3704 | * @throws EE_Error |
||
3705 | * @throws InvalidArgumentException |
||
3706 | * @throws InvalidDataTypeException |
||
3707 | * @throws InvalidInterfaceException |
||
3708 | * @throws ReflectionException |
||
3709 | * @access protected |
||
3710 | */ |
||
3711 | protected function _trash_or_restore_attendees($trash = true) |
||
3746 | } |
||
3747 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.