@@ -15,61 +15,61 @@ |
||
15 | 15 | class EE_Checkbox_Display_Strategy extends EE_Compound_Input_Display_Strategy |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @throws EE_Error |
|
20 | - * @return string of html to display the field |
|
21 | - */ |
|
22 | - public function display() |
|
23 | - { |
|
24 | - $input = $this->get_input(); |
|
25 | - $multi = count($input->options()) > 1; |
|
26 | - $input->set_label_sizes(); |
|
27 | - $label_size_class = $input->get_label_size_class(); |
|
28 | - $html = ''; |
|
29 | - if (! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
30 | - EE_Error::doing_it_wrong( |
|
31 | - 'EE_Checkbox_Display_Strategy::display()', |
|
32 | - sprintf( |
|
33 | - esc_html__( |
|
34 | - 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
|
35 | - 'event_espresso' |
|
36 | - ), |
|
37 | - $input->html_id(), |
|
38 | - var_export($input->raw_value(), true), |
|
39 | - $input->html_name() . '[]' |
|
40 | - ), |
|
41 | - '4.8.1' |
|
42 | - ); |
|
43 | - } |
|
44 | - $input_raw_value = (array)$input->raw_value(); |
|
45 | - foreach ($input->options() as $value => $display_text) { |
|
46 | - $value = $input->get_normalization_strategy()->unnormalize_one($value); |
|
47 | - $html_id = $this->get_sub_input_id($value); |
|
48 | - $html .= EEH_HTML::nl(0, 'checkbox'); |
|
49 | - $html .= '<label for="' |
|
50 | - . $html_id |
|
51 | - . '" id="' |
|
52 | - . $html_id |
|
53 | - . '-lbl" class="ee-checkbox-label-after' |
|
54 | - . $label_size_class |
|
55 | - . '">'; |
|
56 | - $html .= EEH_HTML::nl(1, 'checkbox'); |
|
57 | - $html .= '<input type="checkbox"'; |
|
58 | - $html .= ' name="' . $input->html_name() . '[]"'; |
|
59 | - $html .= ' id="' . $html_id . '"'; |
|
60 | - $html .= ' class="' . $input->html_class() . '"'; |
|
61 | - $html .= ' style="' . $input->html_style() . '"'; |
|
62 | - $html .= ' value="' . esc_attr($value) . '"'; |
|
63 | - $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
|
64 | - ? ' checked="checked"' |
|
65 | - : ''; |
|
66 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
67 | - $html .= '> '; |
|
68 | - $html .= $display_text; |
|
69 | - $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
70 | - } |
|
71 | - return $html; |
|
72 | - } |
|
18 | + /** |
|
19 | + * @throws EE_Error |
|
20 | + * @return string of html to display the field |
|
21 | + */ |
|
22 | + public function display() |
|
23 | + { |
|
24 | + $input = $this->get_input(); |
|
25 | + $multi = count($input->options()) > 1; |
|
26 | + $input->set_label_sizes(); |
|
27 | + $label_size_class = $input->get_label_size_class(); |
|
28 | + $html = ''; |
|
29 | + if (! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
30 | + EE_Error::doing_it_wrong( |
|
31 | + 'EE_Checkbox_Display_Strategy::display()', |
|
32 | + sprintf( |
|
33 | + esc_html__( |
|
34 | + 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
|
35 | + 'event_espresso' |
|
36 | + ), |
|
37 | + $input->html_id(), |
|
38 | + var_export($input->raw_value(), true), |
|
39 | + $input->html_name() . '[]' |
|
40 | + ), |
|
41 | + '4.8.1' |
|
42 | + ); |
|
43 | + } |
|
44 | + $input_raw_value = (array)$input->raw_value(); |
|
45 | + foreach ($input->options() as $value => $display_text) { |
|
46 | + $value = $input->get_normalization_strategy()->unnormalize_one($value); |
|
47 | + $html_id = $this->get_sub_input_id($value); |
|
48 | + $html .= EEH_HTML::nl(0, 'checkbox'); |
|
49 | + $html .= '<label for="' |
|
50 | + . $html_id |
|
51 | + . '" id="' |
|
52 | + . $html_id |
|
53 | + . '-lbl" class="ee-checkbox-label-after' |
|
54 | + . $label_size_class |
|
55 | + . '">'; |
|
56 | + $html .= EEH_HTML::nl(1, 'checkbox'); |
|
57 | + $html .= '<input type="checkbox"'; |
|
58 | + $html .= ' name="' . $input->html_name() . '[]"'; |
|
59 | + $html .= ' id="' . $html_id . '"'; |
|
60 | + $html .= ' class="' . $input->html_class() . '"'; |
|
61 | + $html .= ' style="' . $input->html_style() . '"'; |
|
62 | + $html .= ' value="' . esc_attr($value) . '"'; |
|
63 | + $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
|
64 | + ? ' checked="checked"' |
|
65 | + : ''; |
|
66 | + $html .= ' ' . $this->_input->other_html_attributes(); |
|
67 | + $html .= '> '; |
|
68 | + $html .= $display_text; |
|
69 | + $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
70 | + } |
|
71 | + return $html; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | 75 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $input->set_label_sizes(); |
27 | 27 | $label_size_class = $input->get_label_size_class(); |
28 | 28 | $html = ''; |
29 | - if (! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
29 | + if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
30 | 30 | EE_Error::doing_it_wrong( |
31 | 31 | 'EE_Checkbox_Display_Strategy::display()', |
32 | 32 | sprintf( |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | ), |
37 | 37 | $input->html_id(), |
38 | 38 | var_export($input->raw_value(), true), |
39 | - $input->html_name() . '[]' |
|
39 | + $input->html_name().'[]' |
|
40 | 40 | ), |
41 | 41 | '4.8.1' |
42 | 42 | ); |
43 | 43 | } |
44 | - $input_raw_value = (array)$input->raw_value(); |
|
44 | + $input_raw_value = (array) $input->raw_value(); |
|
45 | 45 | foreach ($input->options() as $value => $display_text) { |
46 | 46 | $value = $input->get_normalization_strategy()->unnormalize_one($value); |
47 | 47 | $html_id = $this->get_sub_input_id($value); |
@@ -55,18 +55,18 @@ discard block |
||
55 | 55 | . '">'; |
56 | 56 | $html .= EEH_HTML::nl(1, 'checkbox'); |
57 | 57 | $html .= '<input type="checkbox"'; |
58 | - $html .= ' name="' . $input->html_name() . '[]"'; |
|
59 | - $html .= ' id="' . $html_id . '"'; |
|
60 | - $html .= ' class="' . $input->html_class() . '"'; |
|
61 | - $html .= ' style="' . $input->html_style() . '"'; |
|
62 | - $html .= ' value="' . esc_attr($value) . '"'; |
|
58 | + $html .= ' name="'.$input->html_name().'[]"'; |
|
59 | + $html .= ' id="'.$html_id.'"'; |
|
60 | + $html .= ' class="'.$input->html_class().'"'; |
|
61 | + $html .= ' style="'.$input->html_style().'"'; |
|
62 | + $html .= ' value="'.esc_attr($value).'"'; |
|
63 | 63 | $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
64 | 64 | ? ' checked="checked"' |
65 | 65 | : ''; |
66 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
66 | + $html .= ' '.$this->_input->other_html_attributes(); |
|
67 | 67 | $html .= '> '; |
68 | 68 | $html .= $display_text; |
69 | - $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
69 | + $html .= EEH_HTML::nl(-1, 'checkbox').'</label>'; |
|
70 | 70 | } |
71 | 71 | return $html; |
72 | 72 | } |
@@ -15,22 +15,22 @@ |
||
15 | 15 | class EE_Radio_Button_Input extends EE_Form_Input_With_Options_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param array $answer_options |
|
20 | - * @param array $input_settings |
|
21 | - */ |
|
22 | - public function __construct($answer_options, $input_settings = array()) |
|
23 | - { |
|
24 | - $this->_set_display_strategy(new EE_Radio_Button_Display_Strategy()); |
|
25 | - $this->_add_validation_strategy( |
|
26 | - new EE_Enum_Validation_Strategy( |
|
27 | - isset($input_settings['validation_error_message']) |
|
28 | - ? $input_settings['validation_error_message'] |
|
29 | - : null |
|
30 | - ) |
|
31 | - ); |
|
32 | - $this->_multiple_selections = false; |
|
33 | - parent::__construct($answer_options, $input_settings); |
|
34 | - } |
|
18 | + /** |
|
19 | + * @param array $answer_options |
|
20 | + * @param array $input_settings |
|
21 | + */ |
|
22 | + public function __construct($answer_options, $input_settings = array()) |
|
23 | + { |
|
24 | + $this->_set_display_strategy(new EE_Radio_Button_Display_Strategy()); |
|
25 | + $this->_add_validation_strategy( |
|
26 | + new EE_Enum_Validation_Strategy( |
|
27 | + isset($input_settings['validation_error_message']) |
|
28 | + ? $input_settings['validation_error_message'] |
|
29 | + : null |
|
30 | + ) |
|
31 | + ); |
|
32 | + $this->_multiple_selections = false; |
|
33 | + parent::__construct($answer_options, $input_settings); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |
@@ -13,47 +13,47 @@ |
||
13 | 13 | class EE_Datepicker_Input extends EE_Form_Input_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $input_settings |
|
18 | - */ |
|
19 | - public function __construct($input_settings = array()) |
|
20 | - { |
|
21 | - $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('datepicker')); |
|
22 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
23 | - //we could do better for validation, but at least verify its plaintext |
|
24 | - $this->_add_validation_strategy( |
|
25 | - new EE_Plaintext_Validation_Strategy( |
|
26 | - isset($input_settings['validation_error_message']) |
|
27 | - ? $input_settings['validation_error_message'] |
|
28 | - : null |
|
29 | - ) |
|
30 | - ); |
|
31 | - parent::__construct($input_settings); |
|
32 | - $this->set_html_class($this->html_class() . ' datepicker'); |
|
33 | - // add some style and make it dance |
|
34 | - add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
35 | - add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * enqueue_styles_and_scripts |
|
42 | - * |
|
43 | - * @access public |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public static function enqueue_styles_and_scripts() |
|
47 | - { |
|
48 | - // load css |
|
49 | - wp_register_style( |
|
50 | - 'espresso-ui-theme', |
|
51 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
52 | - array(), |
|
53 | - EVENT_ESPRESSO_VERSION |
|
54 | - ); |
|
55 | - wp_enqueue_style('espresso-ui-theme'); |
|
56 | - } |
|
16 | + /** |
|
17 | + * @param array $input_settings |
|
18 | + */ |
|
19 | + public function __construct($input_settings = array()) |
|
20 | + { |
|
21 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('datepicker')); |
|
22 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
23 | + //we could do better for validation, but at least verify its plaintext |
|
24 | + $this->_add_validation_strategy( |
|
25 | + new EE_Plaintext_Validation_Strategy( |
|
26 | + isset($input_settings['validation_error_message']) |
|
27 | + ? $input_settings['validation_error_message'] |
|
28 | + : null |
|
29 | + ) |
|
30 | + ); |
|
31 | + parent::__construct($input_settings); |
|
32 | + $this->set_html_class($this->html_class() . ' datepicker'); |
|
33 | + // add some style and make it dance |
|
34 | + add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
35 | + add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * enqueue_styles_and_scripts |
|
42 | + * |
|
43 | + * @access public |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public static function enqueue_styles_and_scripts() |
|
47 | + { |
|
48 | + // load css |
|
49 | + wp_register_style( |
|
50 | + 'espresso-ui-theme', |
|
51 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
52 | + array(), |
|
53 | + EVENT_ESPRESSO_VERSION |
|
54 | + ); |
|
55 | + wp_enqueue_style('espresso-ui-theme'); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | 59 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | ) |
30 | 30 | ); |
31 | 31 | parent::__construct($input_settings); |
32 | - $this->set_html_class($this->html_class() . ' datepicker'); |
|
32 | + $this->set_html_class($this->html_class().' datepicker'); |
|
33 | 33 | // add some style and make it dance |
34 | 34 | add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
35 | 35 | add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | // load css |
49 | 49 | wp_register_style( |
50 | 50 | 'espresso-ui-theme', |
51 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
51 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
52 | 52 | array(), |
53 | 53 | EVENT_ESPRESSO_VERSION |
54 | 54 | ); |
@@ -17,1335 +17,1335 @@ |
||
17 | 17 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @type bool $_print_copy_info |
|
22 | - */ |
|
23 | - private $_print_copy_info = false; |
|
24 | - |
|
25 | - /** |
|
26 | - * @type array $_attendee_data |
|
27 | - */ |
|
28 | - private $_attendee_data = array(); |
|
29 | - |
|
30 | - /** |
|
31 | - * @type array $_required_questions |
|
32 | - */ |
|
33 | - private $_required_questions = array(); |
|
34 | - |
|
35 | - /** |
|
36 | - * @type array $_registration_answers |
|
37 | - */ |
|
38 | - private $_registration_answers = array(); |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * class constructor |
|
43 | - * |
|
44 | - * @access public |
|
45 | - * @param EE_Checkout $checkout |
|
46 | - */ |
|
47 | - public function __construct(EE_Checkout $checkout) |
|
48 | - { |
|
49 | - $this->_slug = 'attendee_information'; |
|
50 | - $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
51 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
52 | - $this->checkout = $checkout; |
|
53 | - $this->_reset_success_message(); |
|
54 | - $this->set_instructions( |
|
55 | - esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - public function translate_js_strings() |
|
61 | - { |
|
62 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
63 | - ' is a required question.', |
|
64 | - 'event_espresso' |
|
65 | - ); |
|
66 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
67 | - ' is a required question. Please enter a value for at least one of the options.', |
|
68 | - 'event_espresso' |
|
69 | - ); |
|
70 | - EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
71 | - 'Please answer all required questions correctly before proceeding.', |
|
72 | - 'event_espresso' |
|
73 | - ); |
|
74 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
75 | - esc_html__( |
|
76 | - 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - '<br/>' |
|
80 | - ); |
|
81 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
82 | - 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
83 | - 'event_espresso' |
|
84 | - ); |
|
85 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
86 | - 'You must enter a valid email address.', |
|
87 | - 'event_espresso' |
|
88 | - ); |
|
89 | - EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
90 | - 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
91 | - 'event_espresso' |
|
92 | - ); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - public function enqueue_styles_and_scripts() |
|
97 | - { |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return boolean |
|
103 | - */ |
|
104 | - public function initialize_reg_step() |
|
105 | - { |
|
106 | - return true; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return EE_Form_Section_Proper |
|
112 | - * @throws EE_Error |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
115 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
116 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
117 | - */ |
|
118 | - public function generate_reg_form() |
|
119 | - { |
|
120 | - $this->_print_copy_info = false; |
|
121 | - $primary_registrant = null; |
|
122 | - // autoload Line_Item_Display classes |
|
123 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
124 | - $Line_Item_Display = new EE_Line_Item_Display(); |
|
125 | - // calculate taxes |
|
126 | - $Line_Item_Display->display_line_item( |
|
127 | - $this->checkout->cart->get_grand_total(), |
|
128 | - array('set_tax_rate' => true) |
|
129 | - ); |
|
130 | - /** @var $subsections EE_Form_Section_Proper[] */ |
|
131 | - $subsections = array( |
|
132 | - 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
133 | - ); |
|
134 | - $template_args = array( |
|
135 | - 'revisit' => $this->checkout->revisit, |
|
136 | - 'registrations' => array(), |
|
137 | - 'ticket_count' => array(), |
|
138 | - ); |
|
139 | - // grab the saved registrations from the transaction |
|
140 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
141 | - if ($registrations) { |
|
142 | - foreach ($registrations as $registration) { |
|
143 | - // can this registration be processed during this visit ? |
|
144 | - if ($registration instanceof EE_Registration |
|
145 | - && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
146 | - ) { |
|
147 | - $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
148 | - if (! $this->checkout->admin_request) { |
|
149 | - $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
150 | - $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
151 | - $template_args['ticket_count'][$registration->ticket()->ID()] |
|
152 | - ) |
|
153 | - ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
154 | - : 1; |
|
155 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
156 | - $this->checkout->cart->get_grand_total(), |
|
157 | - 'Ticket', |
|
158 | - array($registration->ticket()->ID()) |
|
159 | - ); |
|
160 | - $ticket_line_item = is_array($ticket_line_item) |
|
161 | - ? reset($ticket_line_item) |
|
162 | - : $ticket_line_item; |
|
163 | - $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
164 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
165 | - } |
|
166 | - if ($registration->is_primary_registrant()) { |
|
167 | - $primary_registrant = $registration->reg_url_link(); |
|
168 | - } |
|
169 | - } |
|
170 | - } |
|
171 | - // print_copy_info ? |
|
172 | - if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
173 | - // TODO: add admin option for toggling copy attendee info, |
|
174 | - // then use that value to change $this->_print_copy_info |
|
175 | - $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
176 | - ? $this->_copy_attendee_info_form() |
|
177 | - : $this->_auto_copy_attendee_info(); |
|
178 | - // generate hidden input |
|
179 | - if (isset($subsections[$primary_registrant]) |
|
180 | - && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
181 | - ) { |
|
182 | - $subsections[$primary_registrant]->add_subsections( |
|
183 | - $copy_options, |
|
184 | - 'primary_registrant', |
|
185 | - false |
|
186 | - ); |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - return new EE_Form_Section_Proper( |
|
192 | - array( |
|
193 | - 'name' => $this->reg_form_name(), |
|
194 | - 'html_id' => $this->reg_form_name(), |
|
195 | - 'subsections' => $subsections, |
|
196 | - 'layout_strategy' => $this->checkout->admin_request ? |
|
197 | - new EE_Div_Per_Section_Layout() : |
|
198 | - new EE_Template_Layout( |
|
199 | - array( |
|
200 | - 'layout_template_file' => $this->_template, // layout_template |
|
201 | - 'template_args' => $template_args, |
|
202 | - ) |
|
203 | - ), |
|
204 | - ) |
|
205 | - ); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * @param EE_Registration $registration |
|
211 | - * @return EE_Form_Section_Base |
|
212 | - * @throws EE_Error |
|
213 | - * @throws InvalidArgumentException |
|
214 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
215 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
216 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
217 | - */ |
|
218 | - private function _registrations_reg_form(EE_Registration $registration) |
|
219 | - { |
|
220 | - static $attendee_nmbr = 1; |
|
221 | - $form_args = array(); |
|
222 | - // verify that registration has valid event |
|
223 | - if ($registration->event() instanceof EE_Event) { |
|
224 | - $question_groups = $registration->event()->question_groups( |
|
225 | - apply_filters( |
|
226 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
227 | - array( |
|
228 | - array( |
|
229 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
230 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
231 | - ), |
|
232 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
233 | - ), |
|
234 | - $registration, |
|
235 | - $this |
|
236 | - ) |
|
237 | - ); |
|
238 | - if ($question_groups) { |
|
239 | - // array of params to pass to parent constructor |
|
240 | - $form_args = array( |
|
241 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
242 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
243 | - 'html_style' => $this->checkout->admin_request |
|
244 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
245 | - : '', |
|
246 | - 'subsections' => array(), |
|
247 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
248 | - array( |
|
249 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
250 | - 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr), |
|
251 | - ) |
|
252 | - ), |
|
253 | - ); |
|
254 | - foreach ($question_groups as $question_group) { |
|
255 | - if ($question_group instanceof EE_Question_Group) { |
|
256 | - $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
257 | - $registration, |
|
258 | - $question_group |
|
259 | - ); |
|
260 | - } |
|
261 | - } |
|
262 | - // add hidden input |
|
263 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
264 | - $registration |
|
265 | - ); |
|
266 | - // if we have question groups for additional attendees, then display the copy options |
|
267 | - $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
|
268 | - if ($registration->is_primary_registrant()) { |
|
269 | - // generate hidden input |
|
270 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
271 | - $registration |
|
272 | - ); |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
276 | - $attendee_nmbr++; |
|
277 | - return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML(); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * _additional_attendee_reg_info_input |
|
283 | - * |
|
284 | - * @access public |
|
285 | - * @param EE_Registration $registration |
|
286 | - * @param bool $additional_attendee_reg_info |
|
287 | - * @return EE_Form_Input_Base |
|
288 | - * @throws \EE_Error |
|
289 | - */ |
|
290 | - private function _additional_attendee_reg_info_input( |
|
291 | - EE_Registration $registration, |
|
292 | - $additional_attendee_reg_info = true |
|
293 | - ) { |
|
294 | - // generate hidden input |
|
295 | - return new EE_Hidden_Input( |
|
296 | - array( |
|
297 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
298 | - 'default' => $additional_attendee_reg_info, |
|
299 | - ) |
|
300 | - ); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * @param EE_Registration $registration |
|
306 | - * @param EE_Question_Group $question_group |
|
307 | - * @return EE_Form_Section_Proper |
|
308 | - * @throws EE_Error |
|
309 | - * @throws InvalidArgumentException |
|
310 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
311 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
312 | - */ |
|
313 | - private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
314 | - { |
|
315 | - // array of params to pass to parent constructor |
|
316 | - $form_args = array( |
|
317 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier(), |
|
318 | - 'html_class' => $this->checkout->admin_request |
|
319 | - ? 'form-table ee-reg-form-qstn-grp-dv' |
|
320 | - : 'ee-reg-form-qstn-grp-dv', |
|
321 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-lbl', |
|
322 | - 'subsections' => array( |
|
323 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
324 | - ), |
|
325 | - 'layout_strategy' => $this->checkout->admin_request |
|
326 | - ? new EE_Admin_Two_Column_Layout() |
|
327 | - : new EE_Div_Per_Section_Layout(), |
|
328 | - ); |
|
329 | - // where params |
|
330 | - $query_params = array('QST_deleted' => 0); |
|
331 | - // don't load admin only questions on the frontend |
|
332 | - if (! $this->checkout->admin_request) { |
|
333 | - $query_params['QST_admin_only'] = array('!=', true); |
|
334 | - } |
|
335 | - $questions = $question_group->get_many_related( |
|
336 | - 'Question', |
|
337 | - apply_filters( |
|
338 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
339 | - array( |
|
340 | - $query_params, |
|
341 | - 'order_by' => array( |
|
342 | - 'Question_Group_Question.QGQ_order' => 'ASC', |
|
343 | - ), |
|
344 | - ), |
|
345 | - $question_group, |
|
346 | - $registration, |
|
347 | - $this |
|
348 | - ) |
|
349 | - ); |
|
350 | - // filter for additional content before questions |
|
351 | - $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
352 | - apply_filters( |
|
353 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
354 | - '', |
|
355 | - $registration, |
|
356 | - $question_group, |
|
357 | - $this |
|
358 | - ) |
|
359 | - ); |
|
360 | - // loop thru questions |
|
361 | - foreach ($questions as $question) { |
|
362 | - if ($question instanceof EE_Question) { |
|
363 | - $identifier = $question->is_system_question() |
|
364 | - ? $question->system_ID() |
|
365 | - : $question->ID(); |
|
366 | - $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
367 | - } |
|
368 | - } |
|
369 | - $form_args['subsections'] = apply_filters( |
|
370 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
371 | - $form_args['subsections'], |
|
372 | - $registration, |
|
373 | - $question_group, |
|
374 | - $this |
|
375 | - ); |
|
376 | - // filter for additional content after questions |
|
377 | - $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
378 | - apply_filters( |
|
379 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
380 | - '', |
|
381 | - $registration, |
|
382 | - $question_group, |
|
383 | - $this |
|
384 | - ) |
|
385 | - ); |
|
20 | + /** |
|
21 | + * @type bool $_print_copy_info |
|
22 | + */ |
|
23 | + private $_print_copy_info = false; |
|
24 | + |
|
25 | + /** |
|
26 | + * @type array $_attendee_data |
|
27 | + */ |
|
28 | + private $_attendee_data = array(); |
|
29 | + |
|
30 | + /** |
|
31 | + * @type array $_required_questions |
|
32 | + */ |
|
33 | + private $_required_questions = array(); |
|
34 | + |
|
35 | + /** |
|
36 | + * @type array $_registration_answers |
|
37 | + */ |
|
38 | + private $_registration_answers = array(); |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * class constructor |
|
43 | + * |
|
44 | + * @access public |
|
45 | + * @param EE_Checkout $checkout |
|
46 | + */ |
|
47 | + public function __construct(EE_Checkout $checkout) |
|
48 | + { |
|
49 | + $this->_slug = 'attendee_information'; |
|
50 | + $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
51 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
52 | + $this->checkout = $checkout; |
|
53 | + $this->_reset_success_message(); |
|
54 | + $this->set_instructions( |
|
55 | + esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + public function translate_js_strings() |
|
61 | + { |
|
62 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
63 | + ' is a required question.', |
|
64 | + 'event_espresso' |
|
65 | + ); |
|
66 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
67 | + ' is a required question. Please enter a value for at least one of the options.', |
|
68 | + 'event_espresso' |
|
69 | + ); |
|
70 | + EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
71 | + 'Please answer all required questions correctly before proceeding.', |
|
72 | + 'event_espresso' |
|
73 | + ); |
|
74 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
75 | + esc_html__( |
|
76 | + 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + '<br/>' |
|
80 | + ); |
|
81 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
82 | + 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
83 | + 'event_espresso' |
|
84 | + ); |
|
85 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
86 | + 'You must enter a valid email address.', |
|
87 | + 'event_espresso' |
|
88 | + ); |
|
89 | + EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
90 | + 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
91 | + 'event_espresso' |
|
92 | + ); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + public function enqueue_styles_and_scripts() |
|
97 | + { |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return boolean |
|
103 | + */ |
|
104 | + public function initialize_reg_step() |
|
105 | + { |
|
106 | + return true; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return EE_Form_Section_Proper |
|
112 | + * @throws EE_Error |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
115 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
116 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
117 | + */ |
|
118 | + public function generate_reg_form() |
|
119 | + { |
|
120 | + $this->_print_copy_info = false; |
|
121 | + $primary_registrant = null; |
|
122 | + // autoload Line_Item_Display classes |
|
123 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
124 | + $Line_Item_Display = new EE_Line_Item_Display(); |
|
125 | + // calculate taxes |
|
126 | + $Line_Item_Display->display_line_item( |
|
127 | + $this->checkout->cart->get_grand_total(), |
|
128 | + array('set_tax_rate' => true) |
|
129 | + ); |
|
130 | + /** @var $subsections EE_Form_Section_Proper[] */ |
|
131 | + $subsections = array( |
|
132 | + 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
133 | + ); |
|
134 | + $template_args = array( |
|
135 | + 'revisit' => $this->checkout->revisit, |
|
136 | + 'registrations' => array(), |
|
137 | + 'ticket_count' => array(), |
|
138 | + ); |
|
139 | + // grab the saved registrations from the transaction |
|
140 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
141 | + if ($registrations) { |
|
142 | + foreach ($registrations as $registration) { |
|
143 | + // can this registration be processed during this visit ? |
|
144 | + if ($registration instanceof EE_Registration |
|
145 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
146 | + ) { |
|
147 | + $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
148 | + if (! $this->checkout->admin_request) { |
|
149 | + $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
150 | + $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
151 | + $template_args['ticket_count'][$registration->ticket()->ID()] |
|
152 | + ) |
|
153 | + ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
154 | + : 1; |
|
155 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
156 | + $this->checkout->cart->get_grand_total(), |
|
157 | + 'Ticket', |
|
158 | + array($registration->ticket()->ID()) |
|
159 | + ); |
|
160 | + $ticket_line_item = is_array($ticket_line_item) |
|
161 | + ? reset($ticket_line_item) |
|
162 | + : $ticket_line_item; |
|
163 | + $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
164 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
165 | + } |
|
166 | + if ($registration->is_primary_registrant()) { |
|
167 | + $primary_registrant = $registration->reg_url_link(); |
|
168 | + } |
|
169 | + } |
|
170 | + } |
|
171 | + // print_copy_info ? |
|
172 | + if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
173 | + // TODO: add admin option for toggling copy attendee info, |
|
174 | + // then use that value to change $this->_print_copy_info |
|
175 | + $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
176 | + ? $this->_copy_attendee_info_form() |
|
177 | + : $this->_auto_copy_attendee_info(); |
|
178 | + // generate hidden input |
|
179 | + if (isset($subsections[$primary_registrant]) |
|
180 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
181 | + ) { |
|
182 | + $subsections[$primary_registrant]->add_subsections( |
|
183 | + $copy_options, |
|
184 | + 'primary_registrant', |
|
185 | + false |
|
186 | + ); |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + return new EE_Form_Section_Proper( |
|
192 | + array( |
|
193 | + 'name' => $this->reg_form_name(), |
|
194 | + 'html_id' => $this->reg_form_name(), |
|
195 | + 'subsections' => $subsections, |
|
196 | + 'layout_strategy' => $this->checkout->admin_request ? |
|
197 | + new EE_Div_Per_Section_Layout() : |
|
198 | + new EE_Template_Layout( |
|
199 | + array( |
|
200 | + 'layout_template_file' => $this->_template, // layout_template |
|
201 | + 'template_args' => $template_args, |
|
202 | + ) |
|
203 | + ), |
|
204 | + ) |
|
205 | + ); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * @param EE_Registration $registration |
|
211 | + * @return EE_Form_Section_Base |
|
212 | + * @throws EE_Error |
|
213 | + * @throws InvalidArgumentException |
|
214 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
215 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
216 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
217 | + */ |
|
218 | + private function _registrations_reg_form(EE_Registration $registration) |
|
219 | + { |
|
220 | + static $attendee_nmbr = 1; |
|
221 | + $form_args = array(); |
|
222 | + // verify that registration has valid event |
|
223 | + if ($registration->event() instanceof EE_Event) { |
|
224 | + $question_groups = $registration->event()->question_groups( |
|
225 | + apply_filters( |
|
226 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
227 | + array( |
|
228 | + array( |
|
229 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
230 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
231 | + ), |
|
232 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
233 | + ), |
|
234 | + $registration, |
|
235 | + $this |
|
236 | + ) |
|
237 | + ); |
|
238 | + if ($question_groups) { |
|
239 | + // array of params to pass to parent constructor |
|
240 | + $form_args = array( |
|
241 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
242 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
243 | + 'html_style' => $this->checkout->admin_request |
|
244 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
245 | + : '', |
|
246 | + 'subsections' => array(), |
|
247 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
248 | + array( |
|
249 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
250 | + 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr), |
|
251 | + ) |
|
252 | + ), |
|
253 | + ); |
|
254 | + foreach ($question_groups as $question_group) { |
|
255 | + if ($question_group instanceof EE_Question_Group) { |
|
256 | + $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
257 | + $registration, |
|
258 | + $question_group |
|
259 | + ); |
|
260 | + } |
|
261 | + } |
|
262 | + // add hidden input |
|
263 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
264 | + $registration |
|
265 | + ); |
|
266 | + // if we have question groups for additional attendees, then display the copy options |
|
267 | + $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
|
268 | + if ($registration->is_primary_registrant()) { |
|
269 | + // generate hidden input |
|
270 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
271 | + $registration |
|
272 | + ); |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | + $attendee_nmbr++; |
|
277 | + return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML(); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * _additional_attendee_reg_info_input |
|
283 | + * |
|
284 | + * @access public |
|
285 | + * @param EE_Registration $registration |
|
286 | + * @param bool $additional_attendee_reg_info |
|
287 | + * @return EE_Form_Input_Base |
|
288 | + * @throws \EE_Error |
|
289 | + */ |
|
290 | + private function _additional_attendee_reg_info_input( |
|
291 | + EE_Registration $registration, |
|
292 | + $additional_attendee_reg_info = true |
|
293 | + ) { |
|
294 | + // generate hidden input |
|
295 | + return new EE_Hidden_Input( |
|
296 | + array( |
|
297 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
298 | + 'default' => $additional_attendee_reg_info, |
|
299 | + ) |
|
300 | + ); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * @param EE_Registration $registration |
|
306 | + * @param EE_Question_Group $question_group |
|
307 | + * @return EE_Form_Section_Proper |
|
308 | + * @throws EE_Error |
|
309 | + * @throws InvalidArgumentException |
|
310 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
311 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
312 | + */ |
|
313 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
314 | + { |
|
315 | + // array of params to pass to parent constructor |
|
316 | + $form_args = array( |
|
317 | + 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier(), |
|
318 | + 'html_class' => $this->checkout->admin_request |
|
319 | + ? 'form-table ee-reg-form-qstn-grp-dv' |
|
320 | + : 'ee-reg-form-qstn-grp-dv', |
|
321 | + 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-lbl', |
|
322 | + 'subsections' => array( |
|
323 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
324 | + ), |
|
325 | + 'layout_strategy' => $this->checkout->admin_request |
|
326 | + ? new EE_Admin_Two_Column_Layout() |
|
327 | + : new EE_Div_Per_Section_Layout(), |
|
328 | + ); |
|
329 | + // where params |
|
330 | + $query_params = array('QST_deleted' => 0); |
|
331 | + // don't load admin only questions on the frontend |
|
332 | + if (! $this->checkout->admin_request) { |
|
333 | + $query_params['QST_admin_only'] = array('!=', true); |
|
334 | + } |
|
335 | + $questions = $question_group->get_many_related( |
|
336 | + 'Question', |
|
337 | + apply_filters( |
|
338 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
339 | + array( |
|
340 | + $query_params, |
|
341 | + 'order_by' => array( |
|
342 | + 'Question_Group_Question.QGQ_order' => 'ASC', |
|
343 | + ), |
|
344 | + ), |
|
345 | + $question_group, |
|
346 | + $registration, |
|
347 | + $this |
|
348 | + ) |
|
349 | + ); |
|
350 | + // filter for additional content before questions |
|
351 | + $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
352 | + apply_filters( |
|
353 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
354 | + '', |
|
355 | + $registration, |
|
356 | + $question_group, |
|
357 | + $this |
|
358 | + ) |
|
359 | + ); |
|
360 | + // loop thru questions |
|
361 | + foreach ($questions as $question) { |
|
362 | + if ($question instanceof EE_Question) { |
|
363 | + $identifier = $question->is_system_question() |
|
364 | + ? $question->system_ID() |
|
365 | + : $question->ID(); |
|
366 | + $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
367 | + } |
|
368 | + } |
|
369 | + $form_args['subsections'] = apply_filters( |
|
370 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
371 | + $form_args['subsections'], |
|
372 | + $registration, |
|
373 | + $question_group, |
|
374 | + $this |
|
375 | + ); |
|
376 | + // filter for additional content after questions |
|
377 | + $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
378 | + apply_filters( |
|
379 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
380 | + '', |
|
381 | + $registration, |
|
382 | + $question_group, |
|
383 | + $this |
|
384 | + ) |
|
385 | + ); |
|
386 | 386 | // d( $form_args ); |
387 | - $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
388 | - return apply_filters( |
|
389 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
390 | - $question_group_reg_form, |
|
391 | - $registration, |
|
392 | - $question_group, |
|
393 | - $this |
|
394 | - ); |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * @access public |
|
400 | - * @param EE_Question_Group $question_group |
|
401 | - * @return EE_Form_Section_HTML |
|
402 | - */ |
|
403 | - private function _question_group_header(EE_Question_Group $question_group) |
|
404 | - { |
|
405 | - $html = ''; |
|
406 | - // group_name |
|
407 | - if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
408 | - if ($this->checkout->admin_request) { |
|
409 | - $html .= EEH_HTML::br(); |
|
410 | - $html .= EEH_HTML::h3( |
|
411 | - $question_group->name(), |
|
412 | - '', |
|
413 | - 'ee-reg-form-qstn-grp-title title', |
|
414 | - 'font-size: 1.3em; padding-left:0;' |
|
415 | - ); |
|
416 | - } else { |
|
417 | - $html .= EEH_HTML::h4( |
|
418 | - $question_group->name(), |
|
419 | - '', |
|
420 | - 'ee-reg-form-qstn-grp-title section-title' |
|
421 | - ); |
|
422 | - } |
|
423 | - } |
|
424 | - // group_desc |
|
425 | - if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
426 | - $html .= EEH_HTML::p( |
|
427 | - $question_group->desc(), |
|
428 | - '', |
|
429 | - $this->checkout->admin_request |
|
430 | - ? 'ee-reg-form-qstn-grp-desc-pg' |
|
431 | - : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
432 | - ); |
|
433 | - } |
|
434 | - return new EE_Form_Section_HTML($html); |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * @access public |
|
440 | - * @return EE_Form_Section_Proper |
|
441 | - * @throws \EE_Error |
|
442 | - */ |
|
443 | - private function _copy_attendee_info_form() |
|
444 | - { |
|
445 | - // array of params to pass to parent constructor |
|
446 | - return new EE_Form_Section_Proper( |
|
447 | - array( |
|
448 | - 'subsections' => $this->_copy_attendee_info_inputs(), |
|
449 | - 'layout_strategy' => new EE_Template_Layout( |
|
450 | - array( |
|
451 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
452 | - . $this->_slug |
|
453 | - . DS |
|
454 | - . 'copy_attendee_info.template.php', |
|
455 | - 'begin_template_file' => null, |
|
456 | - 'input_template_file' => null, |
|
457 | - 'subsection_template_file' => null, |
|
458 | - 'end_template_file' => null, |
|
459 | - ) |
|
460 | - ), |
|
461 | - ) |
|
462 | - ); |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * _auto_copy_attendee_info |
|
468 | - * |
|
469 | - * @access public |
|
470 | - * @return EE_Form_Section_HTML |
|
471 | - */ |
|
472 | - private function _auto_copy_attendee_info() |
|
473 | - { |
|
474 | - return new EE_Form_Section_HTML( |
|
475 | - EEH_Template::locate_template( |
|
476 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
477 | - apply_filters( |
|
478 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
479 | - array() |
|
480 | - ), |
|
481 | - true, |
|
482 | - true |
|
483 | - ) |
|
484 | - ); |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * _copy_attendee_info_inputs |
|
490 | - * |
|
491 | - * @access public |
|
492 | - * @return array |
|
493 | - * @throws \EE_Error |
|
494 | - */ |
|
495 | - private function _copy_attendee_info_inputs() |
|
496 | - { |
|
497 | - $copy_attendee_info_inputs = array(); |
|
498 | - $prev_ticket = null; |
|
499 | - // grab the saved registrations from the transaction |
|
500 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
501 | - foreach ($registrations as $registration) { |
|
502 | - // for all attendees other than the primary attendee |
|
503 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
504 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
505 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
506 | - $item_name = $registration->ticket()->name(); |
|
507 | - $item_name .= $registration->ticket()->description() !== '' |
|
508 | - ? ' - ' . $registration->ticket()->description() |
|
509 | - : ''; |
|
510 | - $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] = |
|
511 | - new EE_Form_Section_HTML( |
|
512 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
513 | - ); |
|
514 | - $prev_ticket = $registration->ticket()->ID(); |
|
515 | - } |
|
516 | - |
|
517 | - $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] = |
|
518 | - new EE_Checkbox_Multi_Input( |
|
519 | - array( |
|
520 | - $registration->ID() => sprintf( |
|
521 | - esc_html__('Attendee #%s', 'event_espresso'), |
|
522 | - $registration->count() |
|
523 | - ), |
|
524 | - ), |
|
525 | - array( |
|
526 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
527 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
528 | - 'display_html_label_text' => false, |
|
529 | - ) |
|
530 | - ); |
|
531 | - } |
|
532 | - } |
|
533 | - return $copy_attendee_info_inputs; |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * _additional_primary_registrant_inputs |
|
539 | - * |
|
540 | - * @access public |
|
541 | - * @param EE_Registration $registration |
|
542 | - * @return EE_Form_Input_Base |
|
543 | - * @throws \EE_Error |
|
544 | - */ |
|
545 | - private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
546 | - { |
|
547 | - // generate hidden input |
|
548 | - return new EE_Hidden_Input( |
|
549 | - array( |
|
550 | - 'html_id' => 'primary_registrant', |
|
551 | - 'default' => $registration->reg_url_link(), |
|
552 | - ) |
|
553 | - ); |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * @access public |
|
559 | - * @param EE_Registration $registration |
|
560 | - * @param EE_Question $question |
|
561 | - * @return EE_Form_Input_Base |
|
562 | - * @throws EE_Error |
|
563 | - * @throws InvalidArgumentException |
|
564 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
565 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
566 | - */ |
|
567 | - public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
568 | - { |
|
569 | - |
|
570 | - // if this question was for an attendee detail, then check for that answer |
|
571 | - $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
572 | - $registration, |
|
573 | - $question->system_ID() |
|
574 | - ); |
|
575 | - $answer = $answer_value === null |
|
576 | - ? EEM_Answer::instance()->get_one( |
|
577 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
578 | - ) |
|
579 | - : null; |
|
580 | - // if NOT returning to edit an existing registration |
|
581 | - // OR if this question is for an attendee property |
|
582 | - // OR we still don't have an EE_Answer object |
|
583 | - if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
584 | - // create an EE_Answer object for storing everything in |
|
585 | - $answer = EE_Answer::new_instance(array( |
|
586 | - 'QST_ID' => $question->ID(), |
|
587 | - 'REG_ID' => $registration->ID(), |
|
588 | - )); |
|
589 | - } |
|
590 | - // verify instance |
|
591 | - if ($answer instanceof EE_Answer) { |
|
592 | - if (! empty($answer_value)) { |
|
593 | - $answer->set('ANS_value', $answer_value); |
|
594 | - } |
|
595 | - $answer->cache('Question', $question); |
|
596 | - //remember system ID had a bug where sometimes it could be null |
|
597 | - $answer_cache_id = $question->is_system_question() |
|
598 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
599 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
600 | - $registration->cache('Answer', $answer, $answer_cache_id); |
|
601 | - } |
|
602 | - return $this->_generate_question_input($registration, $question, $answer); |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - /** |
|
607 | - * @param EE_Registration $registration |
|
608 | - * @param EE_Question $question |
|
609 | - * @param mixed EE_Answer|NULL $answer |
|
610 | - * @return EE_Form_Input_Base |
|
611 | - * @throws \EE_Error |
|
612 | - */ |
|
613 | - private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
614 | - { |
|
615 | - $identifier = $question->is_system_question() |
|
616 | - ? $question->system_ID() |
|
617 | - : $question->ID(); |
|
618 | - $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
619 | - add_filter( |
|
620 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
621 | - array($this, 'use_cached_countries_for_form_input'), |
|
622 | - 10, |
|
623 | - 4 |
|
624 | - ); |
|
625 | - add_filter( |
|
626 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
627 | - array($this, 'use_cached_states_for_form_input'), |
|
628 | - 10, |
|
629 | - 4 |
|
630 | - ); |
|
631 | - $input_constructor_args = array( |
|
632 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
633 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
634 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
635 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
636 | - 'html_label_class' => 'ee-reg-qstn', |
|
637 | - ); |
|
638 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
639 | - if ($answer instanceof EE_Answer && $answer->ID()) { |
|
640 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
641 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
642 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
643 | - } |
|
644 | - $form_input = $question->generate_form_input( |
|
645 | - $registration, |
|
646 | - $answer, |
|
647 | - $input_constructor_args |
|
648 | - ); |
|
649 | - remove_filter( |
|
650 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
651 | - array($this, 'use_cached_countries_for_form_input') |
|
652 | - ); |
|
653 | - remove_filter( |
|
654 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
655 | - array($this, 'use_cached_states_for_form_input') |
|
656 | - ); |
|
657 | - return $form_input; |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * Gets the list of countries for the form input |
|
663 | - * |
|
664 | - * @param array|null $countries_list |
|
665 | - * @param \EE_Question $question |
|
666 | - * @param \EE_Registration $registration |
|
667 | - * @param \EE_Answer $answer |
|
668 | - * @return array 2d keys are country IDs, values are their names |
|
669 | - * @throws EE_Error |
|
670 | - * @throws InvalidArgumentException |
|
671 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
672 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
673 | - */ |
|
674 | - public function use_cached_countries_for_form_input( |
|
675 | - $countries_list, |
|
676 | - \EE_Question $question = null, |
|
677 | - \EE_Registration $registration = null, |
|
678 | - \EE_Answer $answer = null |
|
679 | - ) { |
|
680 | - $country_options = array('' => ''); |
|
681 | - // get possibly cached list of countries |
|
682 | - $countries = $this->checkout->action === 'process_reg_step' |
|
683 | - ? EEM_Country::instance()->get_all_countries() |
|
684 | - : EEM_Country::instance()->get_all_active_countries(); |
|
685 | - if (! empty($countries)) { |
|
686 | - foreach ($countries as $country) { |
|
687 | - if ($country instanceof EE_Country) { |
|
688 | - $country_options[$country->ID()] = $country->name(); |
|
689 | - } |
|
690 | - } |
|
691 | - } |
|
692 | - if ($question instanceof EE_Question |
|
693 | - && $registration instanceof EE_Registration) { |
|
694 | - $answer = EEM_Answer::instance()->get_one( |
|
695 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
696 | - ); |
|
697 | - } else { |
|
698 | - $answer = EE_Answer::new_instance(); |
|
699 | - } |
|
700 | - $country_options = apply_filters( |
|
701 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
702 | - $country_options, |
|
703 | - $this, |
|
704 | - $registration, |
|
705 | - $question, |
|
706 | - $answer |
|
707 | - ); |
|
708 | - return $country_options; |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - /** |
|
713 | - * Gets the list of states for the form input |
|
714 | - * |
|
715 | - * @param array|null $states_list |
|
716 | - * @param \EE_Question $question |
|
717 | - * @param \EE_Registration $registration |
|
718 | - * @param \EE_Answer $answer |
|
719 | - * @return array 2d keys are state IDs, values are their names |
|
720 | - * @throws EE_Error |
|
721 | - * @throws InvalidArgumentException |
|
722 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
723 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
724 | - */ |
|
725 | - public function use_cached_states_for_form_input( |
|
726 | - $states_list, |
|
727 | - \EE_Question $question = null, |
|
728 | - \EE_Registration $registration = null, |
|
729 | - \EE_Answer $answer = null |
|
730 | - ) { |
|
731 | - $state_options = array('' => array('' => '')); |
|
732 | - $states = $this->checkout->action === 'process_reg_step' |
|
733 | - ? EEM_State::instance()->get_all_states() |
|
734 | - : EEM_State::instance()->get_all_active_states(); |
|
735 | - if (! empty($states)) { |
|
736 | - foreach ($states as $state) { |
|
737 | - if ($state instanceof EE_State) { |
|
738 | - $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
739 | - } |
|
740 | - } |
|
741 | - } |
|
742 | - $state_options = apply_filters( |
|
743 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
744 | - $state_options, |
|
745 | - $this, |
|
746 | - $registration, |
|
747 | - $question, |
|
748 | - $answer |
|
749 | - ); |
|
750 | - return $state_options; |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - |
|
758 | - /********************************************************************************************************/ |
|
759 | - /**************************************** PROCESS REG STEP ****************************************/ |
|
760 | - /********************************************************************************************************/ |
|
761 | - /** |
|
762 | - * @return bool |
|
763 | - * @throws EE_Error |
|
764 | - * @throws InvalidArgumentException |
|
765 | - * @throws ReflectionException |
|
766 | - * @throws RuntimeException |
|
767 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
768 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
769 | - */ |
|
770 | - public function process_reg_step() |
|
771 | - { |
|
772 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
773 | - // grab validated data from form |
|
774 | - $valid_data = $this->checkout->current_step->valid_data(); |
|
775 | - // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
776 | - // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
777 | - // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
778 | - if (empty($valid_data)) { |
|
779 | - EE_Error::add_error( |
|
780 | - esc_html__('No valid question responses were received.', 'event_espresso'), |
|
781 | - __FILE__, |
|
782 | - __FUNCTION__, |
|
783 | - __LINE__ |
|
784 | - ); |
|
785 | - return false; |
|
786 | - } |
|
787 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
788 | - EE_Error::add_error( |
|
789 | - esc_html__( |
|
790 | - 'A valid transaction could not be initiated for processing your registrations.', |
|
791 | - 'event_espresso' |
|
792 | - ), |
|
793 | - __FILE__, |
|
794 | - __FUNCTION__, |
|
795 | - __LINE__ |
|
796 | - ); |
|
797 | - return false; |
|
798 | - } |
|
799 | - // get cached registrations |
|
800 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
801 | - // verify we got the goods |
|
802 | - if (empty($registrations)) { |
|
803 | - EE_Error::add_error( |
|
804 | - esc_html__('Your form data could not be applied to any valid registrations.', 'event_espresso'), |
|
805 | - __FILE__, |
|
806 | - __FUNCTION__, |
|
807 | - __LINE__ |
|
808 | - ); |
|
809 | - return false; |
|
810 | - } |
|
811 | - // extract attendee info from form data and save to model objects |
|
812 | - $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
813 | - // if first pass thru SPCO, |
|
814 | - // then let's check processed registrations against the total number of tickets in the cart |
|
815 | - if ($registrations_processed === false) { |
|
816 | - // but return immediately if the previous step exited early due to errors |
|
817 | - return false; |
|
818 | - } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
819 | - // generate a correctly translated string for all possible singular/plural combinations |
|
820 | - if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
821 | - $error_msg = sprintf( |
|
822 | - esc_html__( |
|
823 | - 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
824 | - 'event_espresso' |
|
825 | - ), |
|
826 | - $this->checkout->total_ticket_count, |
|
827 | - $registrations_processed |
|
828 | - ); |
|
829 | - } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
830 | - $error_msg = sprintf( |
|
831 | - esc_html__( |
|
832 | - 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
833 | - 'event_espresso' |
|
834 | - ), |
|
835 | - $this->checkout->total_ticket_count, |
|
836 | - $registrations_processed |
|
837 | - ); |
|
838 | - } else { |
|
839 | - $error_msg = sprintf( |
|
840 | - esc_html__( |
|
841 | - 'There was a total of %1$d tickets in the Event Queue, but %2$ds registrations were processed', |
|
842 | - 'event_espresso' |
|
843 | - ), |
|
844 | - $this->checkout->total_ticket_count, |
|
845 | - $registrations_processed |
|
846 | - ); |
|
847 | - } |
|
848 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
849 | - return false; |
|
850 | - } |
|
851 | - // mark this reg step as completed |
|
852 | - $this->set_completed(); |
|
853 | - $this->_set_success_message( |
|
854 | - esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
855 | - ); |
|
856 | - //do action in case a plugin wants to do something with the data submitted in step 1. |
|
857 | - //passes EE_Single_Page_Checkout, and it's posted data |
|
858 | - do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
859 | - return true; |
|
860 | - } |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * _process_registrations |
|
865 | - * |
|
866 | - * @param EE_Registration[] $registrations |
|
867 | - * @param array $valid_data |
|
868 | - * @return bool|int |
|
869 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
870 | - * @throws EE_Error |
|
871 | - * @throws InvalidArgumentException |
|
872 | - * @throws ReflectionException |
|
873 | - * @throws RuntimeException |
|
874 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
875 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
876 | - */ |
|
877 | - private function _process_registrations($registrations = array(), $valid_data = array()) |
|
878 | - { |
|
879 | - // load resources and set some defaults |
|
880 | - EE_Registry::instance()->load_model('Attendee'); |
|
881 | - // holder for primary registrant attendee object |
|
882 | - $this->checkout->primary_attendee_obj = null; |
|
883 | - // array for tracking reg form data for the primary registrant |
|
884 | - $primary_registrant = array( |
|
885 | - 'line_item_id' => null, |
|
886 | - ); |
|
887 | - $copy_primary = false; |
|
888 | - // reg form sections that do not contain inputs |
|
889 | - $non_input_form_sections = array( |
|
890 | - 'primary_registrant', |
|
891 | - 'additional_attendee_reg_info', |
|
892 | - 'spco_copy_attendee_chk', |
|
893 | - ); |
|
894 | - // attendee counter |
|
895 | - $att_nmbr = 0; |
|
896 | - // grab the saved registrations from the transaction |
|
897 | - foreach ($registrations as $registration) { |
|
898 | - // verify EE_Registration object |
|
899 | - if (! $registration instanceof EE_Registration) { |
|
900 | - EE_Error::add_error( |
|
901 | - esc_html__( |
|
902 | - 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
903 | - 'event_espresso' |
|
904 | - ), |
|
905 | - __FILE__, |
|
906 | - __FUNCTION__, |
|
907 | - __LINE__ |
|
908 | - ); |
|
909 | - return false; |
|
910 | - } |
|
911 | - /** @var string $reg_url_link */ |
|
912 | - $reg_url_link = $registration->reg_url_link(); |
|
913 | - // reg_url_link exists ? |
|
914 | - if (! empty($reg_url_link)) { |
|
915 | - // should this registration be processed during this visit ? |
|
916 | - if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
917 | - // if NOT revisiting, then let's save the registration now, |
|
918 | - // so that we have a REG_ID to use when generating other objects |
|
919 | - if (! $this->checkout->revisit) { |
|
920 | - $registration->save(); |
|
921 | - } |
|
922 | - /** |
|
923 | - * This allows plugins to trigger a fail on processing of a |
|
924 | - * registration for any conditions they may have for it to pass. |
|
925 | - * |
|
926 | - * @var bool if true is returned by the plugin then the |
|
927 | - * registration processing is halted. |
|
928 | - */ |
|
929 | - if (apply_filters( |
|
930 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
931 | - false, |
|
932 | - $att_nmbr, |
|
933 | - $registration, |
|
934 | - $registrations, |
|
935 | - $valid_data, |
|
936 | - $this |
|
937 | - )) { |
|
938 | - return false; |
|
939 | - } |
|
940 | - |
|
941 | - // Houston, we have a registration! |
|
942 | - $att_nmbr++; |
|
943 | - $this->_attendee_data[$reg_url_link] = array(); |
|
944 | - // grab any existing related answer objects |
|
945 | - $this->_registration_answers = $registration->answers(); |
|
946 | - // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
947 | - if (isset($valid_data[$reg_url_link])) { |
|
948 | - // do we need to copy basic info from primary attendee ? |
|
949 | - $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
950 | - && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0 |
|
951 | - ? true |
|
952 | - : false; |
|
953 | - // filter form input data for this registration |
|
954 | - $valid_data[$reg_url_link] = (array)apply_filters( |
|
955 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
956 | - $valid_data[$reg_url_link] |
|
957 | - ); |
|
958 | - if (isset($valid_data['primary_attendee'])) { |
|
959 | - $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
960 | - ? $valid_data['primary_attendee'] |
|
961 | - : false; |
|
962 | - unset($valid_data['primary_attendee']); |
|
963 | - } |
|
964 | - // now loop through our array of valid post data && process attendee reg forms |
|
965 | - foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
966 | - if (! in_array($form_section, $non_input_form_sections)) { |
|
967 | - foreach ($form_inputs as $form_input => $input_value) { |
|
968 | - // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
969 | - // check for critical inputs |
|
970 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
971 | - $form_input, |
|
972 | - $input_value |
|
973 | - ) |
|
974 | - ) { |
|
975 | - return false; |
|
976 | - } |
|
977 | - // store a bit of data about the primary attendee |
|
978 | - if ($att_nmbr === 1 |
|
979 | - && ! empty($input_value) |
|
980 | - && $reg_url_link === $primary_registrant['line_item_id'] |
|
981 | - ) { |
|
982 | - $primary_registrant[$form_input] = $input_value; |
|
983 | - } elseif ($copy_primary |
|
984 | - && $input_value === null |
|
985 | - && isset($primary_registrant[$form_input]) |
|
986 | - ) { |
|
987 | - $input_value = $primary_registrant[$form_input]; |
|
988 | - } |
|
989 | - // now attempt to save the input data |
|
990 | - if (! $this->_save_registration_form_input( |
|
991 | - $registration, |
|
992 | - $form_input, |
|
993 | - $input_value |
|
994 | - ) |
|
995 | - ) { |
|
996 | - EE_Error::add_error( |
|
997 | - sprintf( |
|
998 | - esc_html__( |
|
999 | - 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
1000 | - 'event_espresso' |
|
1001 | - ), |
|
1002 | - $form_input, |
|
1003 | - $input_value |
|
1004 | - ), |
|
1005 | - __FILE__, |
|
1006 | - __FUNCTION__, |
|
1007 | - __LINE__ |
|
1008 | - ); |
|
1009 | - return false; |
|
1010 | - } |
|
1011 | - } |
|
1012 | - } |
|
1013 | - } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
1014 | - } |
|
1015 | - //EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
1016 | - // this registration does not require additional attendee information ? |
|
1017 | - if ($copy_primary |
|
1018 | - && $att_nmbr > 1 |
|
1019 | - && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
1020 | - ) { |
|
1021 | - // just copy the primary registrant |
|
1022 | - $attendee = $this->checkout->primary_attendee_obj; |
|
1023 | - } else { |
|
1024 | - // ensure critical details are set for additional attendees |
|
1025 | - $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
1026 | - ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
1027 | - $this->_attendee_data[$reg_url_link] |
|
1028 | - ) |
|
1029 | - : $this->_attendee_data[$reg_url_link]; |
|
1030 | - // execute create attendee command (which may return an existing attendee) |
|
1031 | - $attendee = EE_Registry::instance()->BUS->execute( |
|
1032 | - new CreateAttendeeCommand( |
|
1033 | - $this->_attendee_data[$reg_url_link], |
|
1034 | - $registration |
|
1035 | - ) |
|
1036 | - ); |
|
1037 | - // who's #1 ? |
|
1038 | - if ($att_nmbr === 1) { |
|
1039 | - $this->checkout->primary_attendee_obj = $attendee; |
|
1040 | - } |
|
1041 | - } |
|
1042 | - // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
1043 | - // add relation to registration, set attendee ID, and cache attendee |
|
1044 | - $this->_associate_attendee_with_registration($registration, $attendee); |
|
1045 | - // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
1046 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
1047 | - EE_Error::add_error( |
|
1048 | - sprintf( |
|
1049 | - esc_html__( |
|
1050 | - 'Registration %s has an invalid or missing Attendee object.', |
|
1051 | - 'event_espresso' |
|
1052 | - ), |
|
1053 | - $reg_url_link |
|
1054 | - ), |
|
1055 | - __FILE__, |
|
1056 | - __FUNCTION__, |
|
1057 | - __LINE__ |
|
1058 | - ); |
|
1059 | - return false; |
|
1060 | - } |
|
1061 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1062 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1063 | - // at this point, we should have enough details about the registrant to consider the registration |
|
1064 | - // NOT incomplete |
|
1065 | - $registration_processor->toggle_incomplete_registration_status_to_default( |
|
1066 | - $registration, |
|
1067 | - false, |
|
1068 | - new Context( |
|
1069 | - 'spco_reg_step_attendee_information_process_registrations', |
|
1070 | - esc_html__( |
|
1071 | - 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
1072 | - 'event_espresso' |
|
1073 | - ) |
|
1074 | - ) |
|
1075 | - ); |
|
1076 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
1077 | - // abandoned |
|
1078 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1079 | - // if we've gotten this far, then let's save what we have |
|
1080 | - $registration->save(); |
|
1081 | - // add relation between TXN and registration |
|
1082 | - $this->_associate_registration_with_transaction($registration); |
|
1083 | - } |
|
1084 | - } else { |
|
1085 | - EE_Error::add_error( |
|
1086 | - esc_html__( |
|
1087 | - 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
1088 | - 'event_espresso' |
|
1089 | - ), |
|
1090 | - __FILE__, |
|
1091 | - __FUNCTION__, |
|
1092 | - __LINE__ |
|
1093 | - ); |
|
1094 | - // remove malformed data |
|
1095 | - unset($valid_data[$reg_url_link]); |
|
1096 | - return false; |
|
1097 | - } |
|
1098 | - |
|
1099 | - } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
1100 | - return $att_nmbr; |
|
1101 | - } |
|
1102 | - |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * _save_registration_form_input |
|
1106 | - * |
|
1107 | - * @param EE_Registration $registration |
|
1108 | - * @param string $form_input |
|
1109 | - * @param string $input_value |
|
1110 | - * @return bool |
|
1111 | - * @throws EE_Error |
|
1112 | - * @throws InvalidArgumentException |
|
1113 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1114 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1115 | - */ |
|
1116 | - private function _save_registration_form_input( |
|
1117 | - EE_Registration $registration, |
|
1118 | - $form_input = '', |
|
1119 | - $input_value = '' |
|
1120 | - ) { |
|
1121 | - // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
1122 | - // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
1123 | - // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
1124 | - // allow for plugins to hook in and do their own processing of the form input. |
|
1125 | - // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
1126 | - if (apply_filters( |
|
1127 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
1128 | - false, |
|
1129 | - $registration, |
|
1130 | - $form_input, |
|
1131 | - $input_value, |
|
1132 | - $this |
|
1133 | - )) { |
|
1134 | - return true; |
|
1135 | - } |
|
1136 | - /* |
|
387 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
388 | + return apply_filters( |
|
389 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
390 | + $question_group_reg_form, |
|
391 | + $registration, |
|
392 | + $question_group, |
|
393 | + $this |
|
394 | + ); |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * @access public |
|
400 | + * @param EE_Question_Group $question_group |
|
401 | + * @return EE_Form_Section_HTML |
|
402 | + */ |
|
403 | + private function _question_group_header(EE_Question_Group $question_group) |
|
404 | + { |
|
405 | + $html = ''; |
|
406 | + // group_name |
|
407 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
408 | + if ($this->checkout->admin_request) { |
|
409 | + $html .= EEH_HTML::br(); |
|
410 | + $html .= EEH_HTML::h3( |
|
411 | + $question_group->name(), |
|
412 | + '', |
|
413 | + 'ee-reg-form-qstn-grp-title title', |
|
414 | + 'font-size: 1.3em; padding-left:0;' |
|
415 | + ); |
|
416 | + } else { |
|
417 | + $html .= EEH_HTML::h4( |
|
418 | + $question_group->name(), |
|
419 | + '', |
|
420 | + 'ee-reg-form-qstn-grp-title section-title' |
|
421 | + ); |
|
422 | + } |
|
423 | + } |
|
424 | + // group_desc |
|
425 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
426 | + $html .= EEH_HTML::p( |
|
427 | + $question_group->desc(), |
|
428 | + '', |
|
429 | + $this->checkout->admin_request |
|
430 | + ? 'ee-reg-form-qstn-grp-desc-pg' |
|
431 | + : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
432 | + ); |
|
433 | + } |
|
434 | + return new EE_Form_Section_HTML($html); |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * @access public |
|
440 | + * @return EE_Form_Section_Proper |
|
441 | + * @throws \EE_Error |
|
442 | + */ |
|
443 | + private function _copy_attendee_info_form() |
|
444 | + { |
|
445 | + // array of params to pass to parent constructor |
|
446 | + return new EE_Form_Section_Proper( |
|
447 | + array( |
|
448 | + 'subsections' => $this->_copy_attendee_info_inputs(), |
|
449 | + 'layout_strategy' => new EE_Template_Layout( |
|
450 | + array( |
|
451 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
452 | + . $this->_slug |
|
453 | + . DS |
|
454 | + . 'copy_attendee_info.template.php', |
|
455 | + 'begin_template_file' => null, |
|
456 | + 'input_template_file' => null, |
|
457 | + 'subsection_template_file' => null, |
|
458 | + 'end_template_file' => null, |
|
459 | + ) |
|
460 | + ), |
|
461 | + ) |
|
462 | + ); |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * _auto_copy_attendee_info |
|
468 | + * |
|
469 | + * @access public |
|
470 | + * @return EE_Form_Section_HTML |
|
471 | + */ |
|
472 | + private function _auto_copy_attendee_info() |
|
473 | + { |
|
474 | + return new EE_Form_Section_HTML( |
|
475 | + EEH_Template::locate_template( |
|
476 | + SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
477 | + apply_filters( |
|
478 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
479 | + array() |
|
480 | + ), |
|
481 | + true, |
|
482 | + true |
|
483 | + ) |
|
484 | + ); |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * _copy_attendee_info_inputs |
|
490 | + * |
|
491 | + * @access public |
|
492 | + * @return array |
|
493 | + * @throws \EE_Error |
|
494 | + */ |
|
495 | + private function _copy_attendee_info_inputs() |
|
496 | + { |
|
497 | + $copy_attendee_info_inputs = array(); |
|
498 | + $prev_ticket = null; |
|
499 | + // grab the saved registrations from the transaction |
|
500 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
501 | + foreach ($registrations as $registration) { |
|
502 | + // for all attendees other than the primary attendee |
|
503 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
504 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
505 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
506 | + $item_name = $registration->ticket()->name(); |
|
507 | + $item_name .= $registration->ticket()->description() !== '' |
|
508 | + ? ' - ' . $registration->ticket()->description() |
|
509 | + : ''; |
|
510 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] = |
|
511 | + new EE_Form_Section_HTML( |
|
512 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
513 | + ); |
|
514 | + $prev_ticket = $registration->ticket()->ID(); |
|
515 | + } |
|
516 | + |
|
517 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] = |
|
518 | + new EE_Checkbox_Multi_Input( |
|
519 | + array( |
|
520 | + $registration->ID() => sprintf( |
|
521 | + esc_html__('Attendee #%s', 'event_espresso'), |
|
522 | + $registration->count() |
|
523 | + ), |
|
524 | + ), |
|
525 | + array( |
|
526 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
527 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
528 | + 'display_html_label_text' => false, |
|
529 | + ) |
|
530 | + ); |
|
531 | + } |
|
532 | + } |
|
533 | + return $copy_attendee_info_inputs; |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * _additional_primary_registrant_inputs |
|
539 | + * |
|
540 | + * @access public |
|
541 | + * @param EE_Registration $registration |
|
542 | + * @return EE_Form_Input_Base |
|
543 | + * @throws \EE_Error |
|
544 | + */ |
|
545 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
546 | + { |
|
547 | + // generate hidden input |
|
548 | + return new EE_Hidden_Input( |
|
549 | + array( |
|
550 | + 'html_id' => 'primary_registrant', |
|
551 | + 'default' => $registration->reg_url_link(), |
|
552 | + ) |
|
553 | + ); |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * @access public |
|
559 | + * @param EE_Registration $registration |
|
560 | + * @param EE_Question $question |
|
561 | + * @return EE_Form_Input_Base |
|
562 | + * @throws EE_Error |
|
563 | + * @throws InvalidArgumentException |
|
564 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
565 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
566 | + */ |
|
567 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
568 | + { |
|
569 | + |
|
570 | + // if this question was for an attendee detail, then check for that answer |
|
571 | + $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
572 | + $registration, |
|
573 | + $question->system_ID() |
|
574 | + ); |
|
575 | + $answer = $answer_value === null |
|
576 | + ? EEM_Answer::instance()->get_one( |
|
577 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
578 | + ) |
|
579 | + : null; |
|
580 | + // if NOT returning to edit an existing registration |
|
581 | + // OR if this question is for an attendee property |
|
582 | + // OR we still don't have an EE_Answer object |
|
583 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
584 | + // create an EE_Answer object for storing everything in |
|
585 | + $answer = EE_Answer::new_instance(array( |
|
586 | + 'QST_ID' => $question->ID(), |
|
587 | + 'REG_ID' => $registration->ID(), |
|
588 | + )); |
|
589 | + } |
|
590 | + // verify instance |
|
591 | + if ($answer instanceof EE_Answer) { |
|
592 | + if (! empty($answer_value)) { |
|
593 | + $answer->set('ANS_value', $answer_value); |
|
594 | + } |
|
595 | + $answer->cache('Question', $question); |
|
596 | + //remember system ID had a bug where sometimes it could be null |
|
597 | + $answer_cache_id = $question->is_system_question() |
|
598 | + ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
599 | + : $question->ID() . '-' . $registration->reg_url_link(); |
|
600 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
601 | + } |
|
602 | + return $this->_generate_question_input($registration, $question, $answer); |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + /** |
|
607 | + * @param EE_Registration $registration |
|
608 | + * @param EE_Question $question |
|
609 | + * @param mixed EE_Answer|NULL $answer |
|
610 | + * @return EE_Form_Input_Base |
|
611 | + * @throws \EE_Error |
|
612 | + */ |
|
613 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
614 | + { |
|
615 | + $identifier = $question->is_system_question() |
|
616 | + ? $question->system_ID() |
|
617 | + : $question->ID(); |
|
618 | + $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
619 | + add_filter( |
|
620 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
621 | + array($this, 'use_cached_countries_for_form_input'), |
|
622 | + 10, |
|
623 | + 4 |
|
624 | + ); |
|
625 | + add_filter( |
|
626 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
627 | + array($this, 'use_cached_states_for_form_input'), |
|
628 | + 10, |
|
629 | + 4 |
|
630 | + ); |
|
631 | + $input_constructor_args = array( |
|
632 | + 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
633 | + 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
634 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
635 | + 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
636 | + 'html_label_class' => 'ee-reg-qstn', |
|
637 | + ); |
|
638 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
639 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
640 | + $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
641 | + $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
642 | + $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
643 | + } |
|
644 | + $form_input = $question->generate_form_input( |
|
645 | + $registration, |
|
646 | + $answer, |
|
647 | + $input_constructor_args |
|
648 | + ); |
|
649 | + remove_filter( |
|
650 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
651 | + array($this, 'use_cached_countries_for_form_input') |
|
652 | + ); |
|
653 | + remove_filter( |
|
654 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
655 | + array($this, 'use_cached_states_for_form_input') |
|
656 | + ); |
|
657 | + return $form_input; |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * Gets the list of countries for the form input |
|
663 | + * |
|
664 | + * @param array|null $countries_list |
|
665 | + * @param \EE_Question $question |
|
666 | + * @param \EE_Registration $registration |
|
667 | + * @param \EE_Answer $answer |
|
668 | + * @return array 2d keys are country IDs, values are their names |
|
669 | + * @throws EE_Error |
|
670 | + * @throws InvalidArgumentException |
|
671 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
672 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
673 | + */ |
|
674 | + public function use_cached_countries_for_form_input( |
|
675 | + $countries_list, |
|
676 | + \EE_Question $question = null, |
|
677 | + \EE_Registration $registration = null, |
|
678 | + \EE_Answer $answer = null |
|
679 | + ) { |
|
680 | + $country_options = array('' => ''); |
|
681 | + // get possibly cached list of countries |
|
682 | + $countries = $this->checkout->action === 'process_reg_step' |
|
683 | + ? EEM_Country::instance()->get_all_countries() |
|
684 | + : EEM_Country::instance()->get_all_active_countries(); |
|
685 | + if (! empty($countries)) { |
|
686 | + foreach ($countries as $country) { |
|
687 | + if ($country instanceof EE_Country) { |
|
688 | + $country_options[$country->ID()] = $country->name(); |
|
689 | + } |
|
690 | + } |
|
691 | + } |
|
692 | + if ($question instanceof EE_Question |
|
693 | + && $registration instanceof EE_Registration) { |
|
694 | + $answer = EEM_Answer::instance()->get_one( |
|
695 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
696 | + ); |
|
697 | + } else { |
|
698 | + $answer = EE_Answer::new_instance(); |
|
699 | + } |
|
700 | + $country_options = apply_filters( |
|
701 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
702 | + $country_options, |
|
703 | + $this, |
|
704 | + $registration, |
|
705 | + $question, |
|
706 | + $answer |
|
707 | + ); |
|
708 | + return $country_options; |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + /** |
|
713 | + * Gets the list of states for the form input |
|
714 | + * |
|
715 | + * @param array|null $states_list |
|
716 | + * @param \EE_Question $question |
|
717 | + * @param \EE_Registration $registration |
|
718 | + * @param \EE_Answer $answer |
|
719 | + * @return array 2d keys are state IDs, values are their names |
|
720 | + * @throws EE_Error |
|
721 | + * @throws InvalidArgumentException |
|
722 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
723 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
724 | + */ |
|
725 | + public function use_cached_states_for_form_input( |
|
726 | + $states_list, |
|
727 | + \EE_Question $question = null, |
|
728 | + \EE_Registration $registration = null, |
|
729 | + \EE_Answer $answer = null |
|
730 | + ) { |
|
731 | + $state_options = array('' => array('' => '')); |
|
732 | + $states = $this->checkout->action === 'process_reg_step' |
|
733 | + ? EEM_State::instance()->get_all_states() |
|
734 | + : EEM_State::instance()->get_all_active_states(); |
|
735 | + if (! empty($states)) { |
|
736 | + foreach ($states as $state) { |
|
737 | + if ($state instanceof EE_State) { |
|
738 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
739 | + } |
|
740 | + } |
|
741 | + } |
|
742 | + $state_options = apply_filters( |
|
743 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
744 | + $state_options, |
|
745 | + $this, |
|
746 | + $registration, |
|
747 | + $question, |
|
748 | + $answer |
|
749 | + ); |
|
750 | + return $state_options; |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + |
|
758 | + /********************************************************************************************************/ |
|
759 | + /**************************************** PROCESS REG STEP ****************************************/ |
|
760 | + /********************************************************************************************************/ |
|
761 | + /** |
|
762 | + * @return bool |
|
763 | + * @throws EE_Error |
|
764 | + * @throws InvalidArgumentException |
|
765 | + * @throws ReflectionException |
|
766 | + * @throws RuntimeException |
|
767 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
768 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
769 | + */ |
|
770 | + public function process_reg_step() |
|
771 | + { |
|
772 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
773 | + // grab validated data from form |
|
774 | + $valid_data = $this->checkout->current_step->valid_data(); |
|
775 | + // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
776 | + // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
777 | + // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
778 | + if (empty($valid_data)) { |
|
779 | + EE_Error::add_error( |
|
780 | + esc_html__('No valid question responses were received.', 'event_espresso'), |
|
781 | + __FILE__, |
|
782 | + __FUNCTION__, |
|
783 | + __LINE__ |
|
784 | + ); |
|
785 | + return false; |
|
786 | + } |
|
787 | + if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
788 | + EE_Error::add_error( |
|
789 | + esc_html__( |
|
790 | + 'A valid transaction could not be initiated for processing your registrations.', |
|
791 | + 'event_espresso' |
|
792 | + ), |
|
793 | + __FILE__, |
|
794 | + __FUNCTION__, |
|
795 | + __LINE__ |
|
796 | + ); |
|
797 | + return false; |
|
798 | + } |
|
799 | + // get cached registrations |
|
800 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
801 | + // verify we got the goods |
|
802 | + if (empty($registrations)) { |
|
803 | + EE_Error::add_error( |
|
804 | + esc_html__('Your form data could not be applied to any valid registrations.', 'event_espresso'), |
|
805 | + __FILE__, |
|
806 | + __FUNCTION__, |
|
807 | + __LINE__ |
|
808 | + ); |
|
809 | + return false; |
|
810 | + } |
|
811 | + // extract attendee info from form data and save to model objects |
|
812 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
813 | + // if first pass thru SPCO, |
|
814 | + // then let's check processed registrations against the total number of tickets in the cart |
|
815 | + if ($registrations_processed === false) { |
|
816 | + // but return immediately if the previous step exited early due to errors |
|
817 | + return false; |
|
818 | + } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
819 | + // generate a correctly translated string for all possible singular/plural combinations |
|
820 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
821 | + $error_msg = sprintf( |
|
822 | + esc_html__( |
|
823 | + 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
824 | + 'event_espresso' |
|
825 | + ), |
|
826 | + $this->checkout->total_ticket_count, |
|
827 | + $registrations_processed |
|
828 | + ); |
|
829 | + } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
830 | + $error_msg = sprintf( |
|
831 | + esc_html__( |
|
832 | + 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
833 | + 'event_espresso' |
|
834 | + ), |
|
835 | + $this->checkout->total_ticket_count, |
|
836 | + $registrations_processed |
|
837 | + ); |
|
838 | + } else { |
|
839 | + $error_msg = sprintf( |
|
840 | + esc_html__( |
|
841 | + 'There was a total of %1$d tickets in the Event Queue, but %2$ds registrations were processed', |
|
842 | + 'event_espresso' |
|
843 | + ), |
|
844 | + $this->checkout->total_ticket_count, |
|
845 | + $registrations_processed |
|
846 | + ); |
|
847 | + } |
|
848 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
849 | + return false; |
|
850 | + } |
|
851 | + // mark this reg step as completed |
|
852 | + $this->set_completed(); |
|
853 | + $this->_set_success_message( |
|
854 | + esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
855 | + ); |
|
856 | + //do action in case a plugin wants to do something with the data submitted in step 1. |
|
857 | + //passes EE_Single_Page_Checkout, and it's posted data |
|
858 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
859 | + return true; |
|
860 | + } |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * _process_registrations |
|
865 | + * |
|
866 | + * @param EE_Registration[] $registrations |
|
867 | + * @param array $valid_data |
|
868 | + * @return bool|int |
|
869 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
870 | + * @throws EE_Error |
|
871 | + * @throws InvalidArgumentException |
|
872 | + * @throws ReflectionException |
|
873 | + * @throws RuntimeException |
|
874 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
875 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
876 | + */ |
|
877 | + private function _process_registrations($registrations = array(), $valid_data = array()) |
|
878 | + { |
|
879 | + // load resources and set some defaults |
|
880 | + EE_Registry::instance()->load_model('Attendee'); |
|
881 | + // holder for primary registrant attendee object |
|
882 | + $this->checkout->primary_attendee_obj = null; |
|
883 | + // array for tracking reg form data for the primary registrant |
|
884 | + $primary_registrant = array( |
|
885 | + 'line_item_id' => null, |
|
886 | + ); |
|
887 | + $copy_primary = false; |
|
888 | + // reg form sections that do not contain inputs |
|
889 | + $non_input_form_sections = array( |
|
890 | + 'primary_registrant', |
|
891 | + 'additional_attendee_reg_info', |
|
892 | + 'spco_copy_attendee_chk', |
|
893 | + ); |
|
894 | + // attendee counter |
|
895 | + $att_nmbr = 0; |
|
896 | + // grab the saved registrations from the transaction |
|
897 | + foreach ($registrations as $registration) { |
|
898 | + // verify EE_Registration object |
|
899 | + if (! $registration instanceof EE_Registration) { |
|
900 | + EE_Error::add_error( |
|
901 | + esc_html__( |
|
902 | + 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
903 | + 'event_espresso' |
|
904 | + ), |
|
905 | + __FILE__, |
|
906 | + __FUNCTION__, |
|
907 | + __LINE__ |
|
908 | + ); |
|
909 | + return false; |
|
910 | + } |
|
911 | + /** @var string $reg_url_link */ |
|
912 | + $reg_url_link = $registration->reg_url_link(); |
|
913 | + // reg_url_link exists ? |
|
914 | + if (! empty($reg_url_link)) { |
|
915 | + // should this registration be processed during this visit ? |
|
916 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
917 | + // if NOT revisiting, then let's save the registration now, |
|
918 | + // so that we have a REG_ID to use when generating other objects |
|
919 | + if (! $this->checkout->revisit) { |
|
920 | + $registration->save(); |
|
921 | + } |
|
922 | + /** |
|
923 | + * This allows plugins to trigger a fail on processing of a |
|
924 | + * registration for any conditions they may have for it to pass. |
|
925 | + * |
|
926 | + * @var bool if true is returned by the plugin then the |
|
927 | + * registration processing is halted. |
|
928 | + */ |
|
929 | + if (apply_filters( |
|
930 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
931 | + false, |
|
932 | + $att_nmbr, |
|
933 | + $registration, |
|
934 | + $registrations, |
|
935 | + $valid_data, |
|
936 | + $this |
|
937 | + )) { |
|
938 | + return false; |
|
939 | + } |
|
940 | + |
|
941 | + // Houston, we have a registration! |
|
942 | + $att_nmbr++; |
|
943 | + $this->_attendee_data[$reg_url_link] = array(); |
|
944 | + // grab any existing related answer objects |
|
945 | + $this->_registration_answers = $registration->answers(); |
|
946 | + // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
947 | + if (isset($valid_data[$reg_url_link])) { |
|
948 | + // do we need to copy basic info from primary attendee ? |
|
949 | + $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
950 | + && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0 |
|
951 | + ? true |
|
952 | + : false; |
|
953 | + // filter form input data for this registration |
|
954 | + $valid_data[$reg_url_link] = (array)apply_filters( |
|
955 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
956 | + $valid_data[$reg_url_link] |
|
957 | + ); |
|
958 | + if (isset($valid_data['primary_attendee'])) { |
|
959 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
960 | + ? $valid_data['primary_attendee'] |
|
961 | + : false; |
|
962 | + unset($valid_data['primary_attendee']); |
|
963 | + } |
|
964 | + // now loop through our array of valid post data && process attendee reg forms |
|
965 | + foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
966 | + if (! in_array($form_section, $non_input_form_sections)) { |
|
967 | + foreach ($form_inputs as $form_input => $input_value) { |
|
968 | + // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
969 | + // check for critical inputs |
|
970 | + if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
971 | + $form_input, |
|
972 | + $input_value |
|
973 | + ) |
|
974 | + ) { |
|
975 | + return false; |
|
976 | + } |
|
977 | + // store a bit of data about the primary attendee |
|
978 | + if ($att_nmbr === 1 |
|
979 | + && ! empty($input_value) |
|
980 | + && $reg_url_link === $primary_registrant['line_item_id'] |
|
981 | + ) { |
|
982 | + $primary_registrant[$form_input] = $input_value; |
|
983 | + } elseif ($copy_primary |
|
984 | + && $input_value === null |
|
985 | + && isset($primary_registrant[$form_input]) |
|
986 | + ) { |
|
987 | + $input_value = $primary_registrant[$form_input]; |
|
988 | + } |
|
989 | + // now attempt to save the input data |
|
990 | + if (! $this->_save_registration_form_input( |
|
991 | + $registration, |
|
992 | + $form_input, |
|
993 | + $input_value |
|
994 | + ) |
|
995 | + ) { |
|
996 | + EE_Error::add_error( |
|
997 | + sprintf( |
|
998 | + esc_html__( |
|
999 | + 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
1000 | + 'event_espresso' |
|
1001 | + ), |
|
1002 | + $form_input, |
|
1003 | + $input_value |
|
1004 | + ), |
|
1005 | + __FILE__, |
|
1006 | + __FUNCTION__, |
|
1007 | + __LINE__ |
|
1008 | + ); |
|
1009 | + return false; |
|
1010 | + } |
|
1011 | + } |
|
1012 | + } |
|
1013 | + } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
1014 | + } |
|
1015 | + //EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
1016 | + // this registration does not require additional attendee information ? |
|
1017 | + if ($copy_primary |
|
1018 | + && $att_nmbr > 1 |
|
1019 | + && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
1020 | + ) { |
|
1021 | + // just copy the primary registrant |
|
1022 | + $attendee = $this->checkout->primary_attendee_obj; |
|
1023 | + } else { |
|
1024 | + // ensure critical details are set for additional attendees |
|
1025 | + $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
1026 | + ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
1027 | + $this->_attendee_data[$reg_url_link] |
|
1028 | + ) |
|
1029 | + : $this->_attendee_data[$reg_url_link]; |
|
1030 | + // execute create attendee command (which may return an existing attendee) |
|
1031 | + $attendee = EE_Registry::instance()->BUS->execute( |
|
1032 | + new CreateAttendeeCommand( |
|
1033 | + $this->_attendee_data[$reg_url_link], |
|
1034 | + $registration |
|
1035 | + ) |
|
1036 | + ); |
|
1037 | + // who's #1 ? |
|
1038 | + if ($att_nmbr === 1) { |
|
1039 | + $this->checkout->primary_attendee_obj = $attendee; |
|
1040 | + } |
|
1041 | + } |
|
1042 | + // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
1043 | + // add relation to registration, set attendee ID, and cache attendee |
|
1044 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
1045 | + // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
1046 | + if (! $registration->attendee() instanceof EE_Attendee) { |
|
1047 | + EE_Error::add_error( |
|
1048 | + sprintf( |
|
1049 | + esc_html__( |
|
1050 | + 'Registration %s has an invalid or missing Attendee object.', |
|
1051 | + 'event_espresso' |
|
1052 | + ), |
|
1053 | + $reg_url_link |
|
1054 | + ), |
|
1055 | + __FILE__, |
|
1056 | + __FUNCTION__, |
|
1057 | + __LINE__ |
|
1058 | + ); |
|
1059 | + return false; |
|
1060 | + } |
|
1061 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1062 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1063 | + // at this point, we should have enough details about the registrant to consider the registration |
|
1064 | + // NOT incomplete |
|
1065 | + $registration_processor->toggle_incomplete_registration_status_to_default( |
|
1066 | + $registration, |
|
1067 | + false, |
|
1068 | + new Context( |
|
1069 | + 'spco_reg_step_attendee_information_process_registrations', |
|
1070 | + esc_html__( |
|
1071 | + 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
1072 | + 'event_espresso' |
|
1073 | + ) |
|
1074 | + ) |
|
1075 | + ); |
|
1076 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
1077 | + // abandoned |
|
1078 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1079 | + // if we've gotten this far, then let's save what we have |
|
1080 | + $registration->save(); |
|
1081 | + // add relation between TXN and registration |
|
1082 | + $this->_associate_registration_with_transaction($registration); |
|
1083 | + } |
|
1084 | + } else { |
|
1085 | + EE_Error::add_error( |
|
1086 | + esc_html__( |
|
1087 | + 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
1088 | + 'event_espresso' |
|
1089 | + ), |
|
1090 | + __FILE__, |
|
1091 | + __FUNCTION__, |
|
1092 | + __LINE__ |
|
1093 | + ); |
|
1094 | + // remove malformed data |
|
1095 | + unset($valid_data[$reg_url_link]); |
|
1096 | + return false; |
|
1097 | + } |
|
1098 | + |
|
1099 | + } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
1100 | + return $att_nmbr; |
|
1101 | + } |
|
1102 | + |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * _save_registration_form_input |
|
1106 | + * |
|
1107 | + * @param EE_Registration $registration |
|
1108 | + * @param string $form_input |
|
1109 | + * @param string $input_value |
|
1110 | + * @return bool |
|
1111 | + * @throws EE_Error |
|
1112 | + * @throws InvalidArgumentException |
|
1113 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1114 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1115 | + */ |
|
1116 | + private function _save_registration_form_input( |
|
1117 | + EE_Registration $registration, |
|
1118 | + $form_input = '', |
|
1119 | + $input_value = '' |
|
1120 | + ) { |
|
1121 | + // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
1122 | + // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
1123 | + // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
1124 | + // allow for plugins to hook in and do their own processing of the form input. |
|
1125 | + // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
1126 | + if (apply_filters( |
|
1127 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
1128 | + false, |
|
1129 | + $registration, |
|
1130 | + $form_input, |
|
1131 | + $input_value, |
|
1132 | + $this |
|
1133 | + )) { |
|
1134 | + return true; |
|
1135 | + } |
|
1136 | + /* |
|
1137 | 1137 | * $answer_cache_id is the key used to find the EE_Answer we want |
1138 | 1138 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
1139 | 1139 | */ |
1140 | - $answer_cache_id = $this->checkout->reg_url_link |
|
1141 | - ? $form_input . '-' . $registration->reg_url_link() |
|
1142 | - : $form_input; |
|
1143 | - $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
1144 | - && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
1145 | - ? true |
|
1146 | - : false; |
|
1147 | - //rename form_inputs if they are EE_Attendee properties |
|
1148 | - switch ((string) $form_input) { |
|
1149 | - case 'state': |
|
1150 | - case 'STA_ID': |
|
1151 | - $attendee_property = true; |
|
1152 | - $form_input = 'STA_ID'; |
|
1153 | - break; |
|
1154 | - |
|
1155 | - case 'country': |
|
1156 | - case 'CNT_ISO': |
|
1157 | - $attendee_property = true; |
|
1158 | - $form_input = 'CNT_ISO'; |
|
1159 | - break; |
|
1160 | - |
|
1161 | - default: |
|
1162 | - $ATT_input = 'ATT_' . $form_input; |
|
1163 | - //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
1164 | - $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1165 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1166 | - } |
|
1167 | - // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
1168 | - // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
1169 | - // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
1170 | - // if this form input has a corresponding attendee property |
|
1171 | - if ($attendee_property) { |
|
1172 | - $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
1173 | - if ($answer_is_obj) { |
|
1174 | - // and delete the corresponding answer since we won't be storing this data in that object |
|
1175 | - $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
1176 | - $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
1177 | - } |
|
1178 | - return true; |
|
1179 | - } elseif ($answer_is_obj) { |
|
1180 | - // save this data to the answer object |
|
1181 | - $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
1182 | - $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
1183 | - return $result !== false ? true : false; |
|
1184 | - } else { |
|
1185 | - foreach ($this->_registration_answers as $answer) { |
|
1186 | - if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1187 | - $answer->set_value($input_value); |
|
1188 | - $result = $answer->save(); |
|
1189 | - return $result !== false ? true : false; |
|
1190 | - } |
|
1191 | - } |
|
1192 | - } |
|
1193 | - return false; |
|
1194 | - } |
|
1195 | - |
|
1196 | - |
|
1197 | - /** |
|
1198 | - * _verify_critical_attendee_details_are_set |
|
1199 | - * |
|
1200 | - * @param string $form_input |
|
1201 | - * @param string $input_value |
|
1202 | - * @return boolean |
|
1203 | - */ |
|
1204 | - private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
1205 | - $form_input = '', |
|
1206 | - $input_value = '' |
|
1207 | - ) { |
|
1208 | - if (empty($input_value)) { |
|
1209 | - // if the form input isn't marked as being required, then just return |
|
1210 | - if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1211 | - return true; |
|
1212 | - } |
|
1213 | - switch ($form_input) { |
|
1214 | - case 'fname': |
|
1215 | - EE_Error::add_error( |
|
1216 | - esc_html__('First Name is a required value.', 'event_espresso'), |
|
1217 | - __FILE__, |
|
1218 | - __FUNCTION__, |
|
1219 | - __LINE__ |
|
1220 | - ); |
|
1221 | - return false; |
|
1222 | - break; |
|
1223 | - case 'lname': |
|
1224 | - EE_Error::add_error( |
|
1225 | - esc_html__('Last Name is a required value.', 'event_espresso'), |
|
1226 | - __FILE__, |
|
1227 | - __FUNCTION__, |
|
1228 | - __LINE__ |
|
1229 | - ); |
|
1230 | - return false; |
|
1231 | - break; |
|
1232 | - case 'email': |
|
1233 | - EE_Error::add_error( |
|
1234 | - esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
1235 | - __FILE__, |
|
1236 | - __FUNCTION__, |
|
1237 | - __LINE__ |
|
1238 | - ); |
|
1239 | - return false; |
|
1240 | - break; |
|
1241 | - } |
|
1242 | - } |
|
1243 | - return true; |
|
1244 | - } |
|
1245 | - |
|
1246 | - |
|
1247 | - /** |
|
1248 | - * _associate_attendee_with_registration |
|
1249 | - * |
|
1250 | - * @param EE_Registration $registration |
|
1251 | - * @param EE_Attendee $attendee |
|
1252 | - * @return void |
|
1253 | - * @throws EE_Error |
|
1254 | - * @throws RuntimeException |
|
1255 | - */ |
|
1256 | - private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
1257 | - { |
|
1258 | - // add relation to attendee |
|
1259 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
1260 | - $registration->set_attendee_id($attendee->ID()); |
|
1261 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1262 | - } |
|
1263 | - |
|
1264 | - |
|
1265 | - /** |
|
1266 | - * _associate_registration_with_transaction |
|
1267 | - * |
|
1268 | - * @param EE_Registration $registration |
|
1269 | - * @return void |
|
1270 | - * @throws \EE_Error |
|
1271 | - */ |
|
1272 | - private function _associate_registration_with_transaction(EE_Registration $registration) |
|
1273 | - { |
|
1274 | - // add relation to registration |
|
1275 | - $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1276 | - $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1277 | - } |
|
1278 | - |
|
1279 | - |
|
1280 | - /** |
|
1281 | - * _copy_critical_attendee_details_from_primary_registrant |
|
1282 | - * ensures that all attendees at least have data for first name, last name, and email address |
|
1283 | - * |
|
1284 | - * @param array $attendee_data |
|
1285 | - * @return array |
|
1286 | - * @throws \EE_Error |
|
1287 | - */ |
|
1288 | - private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
1289 | - { |
|
1290 | - // bare minimum critical details include first name, last name, email address |
|
1291 | - $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1292 | - // add address info to critical details? |
|
1293 | - if (apply_filters( |
|
1294 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
1295 | - false |
|
1296 | - )) { |
|
1297 | - $address_details = array( |
|
1298 | - 'ATT_address', |
|
1299 | - 'ATT_address2', |
|
1300 | - 'ATT_city', |
|
1301 | - 'STA_ID', |
|
1302 | - 'CNT_ISO', |
|
1303 | - 'ATT_zip', |
|
1304 | - 'ATT_phone', |
|
1305 | - ); |
|
1306 | - $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1307 | - } |
|
1308 | - foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1309 | - if (! isset($attendee_data[$critical_attendee_detail]) |
|
1310 | - || empty($attendee_data[$critical_attendee_detail]) |
|
1311 | - ) { |
|
1312 | - $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
1313 | - $critical_attendee_detail |
|
1314 | - ); |
|
1315 | - } |
|
1316 | - } |
|
1317 | - return $attendee_data; |
|
1318 | - } |
|
1319 | - |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * update_reg_step |
|
1323 | - * this is the final step after a user revisits the site to edit their attendee information |
|
1324 | - * this gets called AFTER the process_reg_step() method above |
|
1325 | - * |
|
1326 | - * @return bool |
|
1327 | - * @throws EE_Error |
|
1328 | - * @throws InvalidArgumentException |
|
1329 | - * @throws ReflectionException |
|
1330 | - * @throws RuntimeException |
|
1331 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1332 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1333 | - */ |
|
1334 | - public function update_reg_step() |
|
1335 | - { |
|
1336 | - // save everything |
|
1337 | - if ($this->process_reg_step()) { |
|
1338 | - $this->checkout->redirect = true; |
|
1339 | - $this->checkout->redirect_url = add_query_arg( |
|
1340 | - array( |
|
1341 | - 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
1342 | - 'revisit' => true, |
|
1343 | - ), |
|
1344 | - $this->checkout->thank_you_page_url |
|
1345 | - ); |
|
1346 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1347 | - return true; |
|
1348 | - } |
|
1349 | - return false; |
|
1350 | - } |
|
1140 | + $answer_cache_id = $this->checkout->reg_url_link |
|
1141 | + ? $form_input . '-' . $registration->reg_url_link() |
|
1142 | + : $form_input; |
|
1143 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
1144 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
1145 | + ? true |
|
1146 | + : false; |
|
1147 | + //rename form_inputs if they are EE_Attendee properties |
|
1148 | + switch ((string) $form_input) { |
|
1149 | + case 'state': |
|
1150 | + case 'STA_ID': |
|
1151 | + $attendee_property = true; |
|
1152 | + $form_input = 'STA_ID'; |
|
1153 | + break; |
|
1154 | + |
|
1155 | + case 'country': |
|
1156 | + case 'CNT_ISO': |
|
1157 | + $attendee_property = true; |
|
1158 | + $form_input = 'CNT_ISO'; |
|
1159 | + break; |
|
1160 | + |
|
1161 | + default: |
|
1162 | + $ATT_input = 'ATT_' . $form_input; |
|
1163 | + //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
1164 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1165 | + $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1166 | + } |
|
1167 | + // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
1168 | + // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
1169 | + // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
1170 | + // if this form input has a corresponding attendee property |
|
1171 | + if ($attendee_property) { |
|
1172 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
1173 | + if ($answer_is_obj) { |
|
1174 | + // and delete the corresponding answer since we won't be storing this data in that object |
|
1175 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
1176 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
1177 | + } |
|
1178 | + return true; |
|
1179 | + } elseif ($answer_is_obj) { |
|
1180 | + // save this data to the answer object |
|
1181 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
1182 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
1183 | + return $result !== false ? true : false; |
|
1184 | + } else { |
|
1185 | + foreach ($this->_registration_answers as $answer) { |
|
1186 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1187 | + $answer->set_value($input_value); |
|
1188 | + $result = $answer->save(); |
|
1189 | + return $result !== false ? true : false; |
|
1190 | + } |
|
1191 | + } |
|
1192 | + } |
|
1193 | + return false; |
|
1194 | + } |
|
1195 | + |
|
1196 | + |
|
1197 | + /** |
|
1198 | + * _verify_critical_attendee_details_are_set |
|
1199 | + * |
|
1200 | + * @param string $form_input |
|
1201 | + * @param string $input_value |
|
1202 | + * @return boolean |
|
1203 | + */ |
|
1204 | + private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
1205 | + $form_input = '', |
|
1206 | + $input_value = '' |
|
1207 | + ) { |
|
1208 | + if (empty($input_value)) { |
|
1209 | + // if the form input isn't marked as being required, then just return |
|
1210 | + if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1211 | + return true; |
|
1212 | + } |
|
1213 | + switch ($form_input) { |
|
1214 | + case 'fname': |
|
1215 | + EE_Error::add_error( |
|
1216 | + esc_html__('First Name is a required value.', 'event_espresso'), |
|
1217 | + __FILE__, |
|
1218 | + __FUNCTION__, |
|
1219 | + __LINE__ |
|
1220 | + ); |
|
1221 | + return false; |
|
1222 | + break; |
|
1223 | + case 'lname': |
|
1224 | + EE_Error::add_error( |
|
1225 | + esc_html__('Last Name is a required value.', 'event_espresso'), |
|
1226 | + __FILE__, |
|
1227 | + __FUNCTION__, |
|
1228 | + __LINE__ |
|
1229 | + ); |
|
1230 | + return false; |
|
1231 | + break; |
|
1232 | + case 'email': |
|
1233 | + EE_Error::add_error( |
|
1234 | + esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
1235 | + __FILE__, |
|
1236 | + __FUNCTION__, |
|
1237 | + __LINE__ |
|
1238 | + ); |
|
1239 | + return false; |
|
1240 | + break; |
|
1241 | + } |
|
1242 | + } |
|
1243 | + return true; |
|
1244 | + } |
|
1245 | + |
|
1246 | + |
|
1247 | + /** |
|
1248 | + * _associate_attendee_with_registration |
|
1249 | + * |
|
1250 | + * @param EE_Registration $registration |
|
1251 | + * @param EE_Attendee $attendee |
|
1252 | + * @return void |
|
1253 | + * @throws EE_Error |
|
1254 | + * @throws RuntimeException |
|
1255 | + */ |
|
1256 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
1257 | + { |
|
1258 | + // add relation to attendee |
|
1259 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1260 | + $registration->set_attendee_id($attendee->ID()); |
|
1261 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1262 | + } |
|
1263 | + |
|
1264 | + |
|
1265 | + /** |
|
1266 | + * _associate_registration_with_transaction |
|
1267 | + * |
|
1268 | + * @param EE_Registration $registration |
|
1269 | + * @return void |
|
1270 | + * @throws \EE_Error |
|
1271 | + */ |
|
1272 | + private function _associate_registration_with_transaction(EE_Registration $registration) |
|
1273 | + { |
|
1274 | + // add relation to registration |
|
1275 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1276 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1277 | + } |
|
1278 | + |
|
1279 | + |
|
1280 | + /** |
|
1281 | + * _copy_critical_attendee_details_from_primary_registrant |
|
1282 | + * ensures that all attendees at least have data for first name, last name, and email address |
|
1283 | + * |
|
1284 | + * @param array $attendee_data |
|
1285 | + * @return array |
|
1286 | + * @throws \EE_Error |
|
1287 | + */ |
|
1288 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
1289 | + { |
|
1290 | + // bare minimum critical details include first name, last name, email address |
|
1291 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1292 | + // add address info to critical details? |
|
1293 | + if (apply_filters( |
|
1294 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
1295 | + false |
|
1296 | + )) { |
|
1297 | + $address_details = array( |
|
1298 | + 'ATT_address', |
|
1299 | + 'ATT_address2', |
|
1300 | + 'ATT_city', |
|
1301 | + 'STA_ID', |
|
1302 | + 'CNT_ISO', |
|
1303 | + 'ATT_zip', |
|
1304 | + 'ATT_phone', |
|
1305 | + ); |
|
1306 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1307 | + } |
|
1308 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1309 | + if (! isset($attendee_data[$critical_attendee_detail]) |
|
1310 | + || empty($attendee_data[$critical_attendee_detail]) |
|
1311 | + ) { |
|
1312 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
1313 | + $critical_attendee_detail |
|
1314 | + ); |
|
1315 | + } |
|
1316 | + } |
|
1317 | + return $attendee_data; |
|
1318 | + } |
|
1319 | + |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * update_reg_step |
|
1323 | + * this is the final step after a user revisits the site to edit their attendee information |
|
1324 | + * this gets called AFTER the process_reg_step() method above |
|
1325 | + * |
|
1326 | + * @return bool |
|
1327 | + * @throws EE_Error |
|
1328 | + * @throws InvalidArgumentException |
|
1329 | + * @throws ReflectionException |
|
1330 | + * @throws RuntimeException |
|
1331 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1332 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1333 | + */ |
|
1334 | + public function update_reg_step() |
|
1335 | + { |
|
1336 | + // save everything |
|
1337 | + if ($this->process_reg_step()) { |
|
1338 | + $this->checkout->redirect = true; |
|
1339 | + $this->checkout->redirect_url = add_query_arg( |
|
1340 | + array( |
|
1341 | + 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
1342 | + 'revisit' => true, |
|
1343 | + ), |
|
1344 | + $this->checkout->thank_you_page_url |
|
1345 | + ); |
|
1346 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1347 | + return true; |
|
1348 | + } |
|
1349 | + return false; |
|
1350 | + } |
|
1351 | 1351 | } |
@@ -15,258 +15,258 @@ |
||
15 | 15 | abstract class EE_Form_Section_Layout_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Form form section to lay out |
|
20 | - * |
|
21 | - * @var EE_Form_Section_Proper |
|
22 | - */ |
|
23 | - protected $_form_section; |
|
24 | - |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * __construct |
|
29 | - */ |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * The form section on which this strategy is to perform |
|
38 | - * |
|
39 | - * @param EE_Form_Section_Proper $form |
|
40 | - */ |
|
41 | - public function _construct_finalize(EE_Form_Section_Proper $form) |
|
42 | - { |
|
43 | - $this->_form_section = $form; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @return EE_Form_Section_Proper |
|
50 | - */ |
|
51 | - public function form_section() |
|
52 | - { |
|
53 | - return $this->_form_section; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * Also has teh side effect of enqueuing any needed JS and CSS for |
|
60 | - * this form. |
|
61 | - * Creates all the HTML necessary for displaying this form, its inputs, and |
|
62 | - * proper subsections. |
|
63 | - * Returns the HTML |
|
64 | - * |
|
65 | - * @return string HTML for displaying |
|
66 | - * @throws EE_Error |
|
67 | - */ |
|
68 | - public function layout_form() |
|
69 | - { |
|
70 | - $html = ''; |
|
71 | - // layout_form_begin |
|
72 | - $html .= apply_filters( |
|
73 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
74 | - $this->layout_form_begin(), |
|
75 | - $this->_form_section |
|
76 | - ); |
|
77 | - // layout_form_loop |
|
78 | - $html .= apply_filters( |
|
79 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
80 | - $this->layout_form_loop(), |
|
81 | - $this->_form_section |
|
82 | - ); |
|
83 | - // layout_form_end |
|
84 | - $html .= apply_filters( |
|
85 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
86 | - $this->layout_form_end(), |
|
87 | - $this->_form_section |
|
88 | - ); |
|
89 | - $html = $this->add_form_section_hooks_and_filters($html); |
|
90 | - return $html; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @return string |
|
97 | - * @throws EE_Error |
|
98 | - */ |
|
99 | - public function layout_form_loop() |
|
100 | - { |
|
101 | - $html = ''; |
|
102 | - foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
103 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
104 | - $html .= apply_filters( |
|
105 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
106 | - . $name . '__in_' . $this->_form_section->name(), |
|
107 | - $this->layout_input($subsection), |
|
108 | - $this->_form_section, |
|
109 | - $subsection |
|
110 | - ); |
|
111 | - } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
112 | - $html .= apply_filters( |
|
113 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
114 | - . $name . '__in_' . $this->_form_section->name(), |
|
115 | - $this->layout_subsection($subsection), |
|
116 | - $this->_form_section, |
|
117 | - $subsection |
|
118 | - ); |
|
119 | - } |
|
120 | - } |
|
121 | - return $html; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
128 | - * |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - abstract public function layout_form_begin(); |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
137 | - * |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - abstract public function layout_form_end(); |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
146 | - * is putting each input in a row of its own, this should probably be called by a |
|
147 | - * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
148 | - * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
149 | - * customize the form's layout, but would like to make use of it for laying out |
|
150 | - * 'easy-to-layout' inputs |
|
151 | - * |
|
152 | - * @param EE_Form_Input_Base $input |
|
153 | - * @return string html |
|
154 | - */ |
|
155 | - abstract public function layout_input($input); |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Similar to layout_input(), should be used internally by layout_form() within a |
|
161 | - * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
162 | - * that the proper subsection will layout its container, label, etc on its own. |
|
163 | - * |
|
164 | - * @param EE_Form_Section_Base $subsection |
|
165 | - * @return string html |
|
166 | - */ |
|
167 | - abstract public function layout_subsection($subsection); |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Gets the HTML for the label tag and its contents for the input |
|
173 | - * |
|
174 | - * @param EE_Form_Input_Base $input |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - public function display_label($input) |
|
178 | - { |
|
179 | - $class = $input->required() |
|
180 | - ? 'ee-required-label ' . $input->html_label_class() |
|
181 | - : $input->html_label_class(); |
|
182 | - $label_text = $input->required() |
|
183 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
184 | - : $input->html_label_text(); |
|
185 | - return '<label id="' |
|
186 | - . $input->html_label_id() |
|
187 | - . '" class="' |
|
188 | - . $class |
|
189 | - . '" style="' |
|
190 | - . $input->html_label_style() |
|
191 | - . '" for="' . $input->html_name() |
|
192 | - . '">' |
|
193 | - . $label_text |
|
194 | - . '</label>'; |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * returns the HTML for the server-side validation errors for the specified input |
|
201 | - * Note that if JS is enabled, it should remove these and instead |
|
202 | - * populate the form's errors in the jquery validate fashion |
|
203 | - * using the localized data provided to the JS |
|
204 | - * |
|
205 | - * @param EE_Form_Input_Base $input |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public function display_errors($input) |
|
209 | - { |
|
210 | - if ($input->get_validation_errors()) { |
|
211 | - return "<label id='" |
|
212 | - . $input->html_id() |
|
213 | - . "-error' class='error' for='{$input->html_name()}'>" |
|
214 | - . $input->get_validation_error_string() |
|
215 | - . '</label>'; |
|
216 | - } |
|
217 | - return ''; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * Displays the help span for the specified input |
|
224 | - * |
|
225 | - * @param EE_Form_Input_Base $input |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public function display_help_text($input) |
|
229 | - { |
|
230 | - $help_text = $input->html_help_text(); |
|
231 | - if ($help_text !== '' && $help_text !== null) { |
|
232 | - $tag = is_admin() ? 'p' : 'span'; |
|
233 | - return '<' |
|
234 | - . $tag |
|
235 | - . ' id="' |
|
236 | - . $input->html_id() |
|
237 | - . '-help" class="' |
|
238 | - . $input->html_help_class() |
|
239 | - . '" style="' |
|
240 | - . $input->html_help_style() |
|
241 | - . '">' |
|
242 | - . $help_text |
|
243 | - . '</' |
|
244 | - . $tag |
|
245 | - . '>'; |
|
246 | - } |
|
247 | - return ''; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Does an action and hook onto the end of teh form |
|
254 | - * |
|
255 | - * @param string $html |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - public function add_form_section_hooks_and_filters($html) |
|
259 | - { |
|
260 | - // replace dashes and spaces with underscores |
|
261 | - $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
262 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
263 | - $html = (string) apply_filters( |
|
264 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
265 | - $html, |
|
266 | - $this->_form_section |
|
267 | - ); |
|
268 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
269 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
270 | - return $html; |
|
271 | - } |
|
18 | + /** |
|
19 | + * Form form section to lay out |
|
20 | + * |
|
21 | + * @var EE_Form_Section_Proper |
|
22 | + */ |
|
23 | + protected $_form_section; |
|
24 | + |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * __construct |
|
29 | + */ |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * The form section on which this strategy is to perform |
|
38 | + * |
|
39 | + * @param EE_Form_Section_Proper $form |
|
40 | + */ |
|
41 | + public function _construct_finalize(EE_Form_Section_Proper $form) |
|
42 | + { |
|
43 | + $this->_form_section = $form; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @return EE_Form_Section_Proper |
|
50 | + */ |
|
51 | + public function form_section() |
|
52 | + { |
|
53 | + return $this->_form_section; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * Also has teh side effect of enqueuing any needed JS and CSS for |
|
60 | + * this form. |
|
61 | + * Creates all the HTML necessary for displaying this form, its inputs, and |
|
62 | + * proper subsections. |
|
63 | + * Returns the HTML |
|
64 | + * |
|
65 | + * @return string HTML for displaying |
|
66 | + * @throws EE_Error |
|
67 | + */ |
|
68 | + public function layout_form() |
|
69 | + { |
|
70 | + $html = ''; |
|
71 | + // layout_form_begin |
|
72 | + $html .= apply_filters( |
|
73 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
74 | + $this->layout_form_begin(), |
|
75 | + $this->_form_section |
|
76 | + ); |
|
77 | + // layout_form_loop |
|
78 | + $html .= apply_filters( |
|
79 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
80 | + $this->layout_form_loop(), |
|
81 | + $this->_form_section |
|
82 | + ); |
|
83 | + // layout_form_end |
|
84 | + $html .= apply_filters( |
|
85 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
86 | + $this->layout_form_end(), |
|
87 | + $this->_form_section |
|
88 | + ); |
|
89 | + $html = $this->add_form_section_hooks_and_filters($html); |
|
90 | + return $html; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + * @throws EE_Error |
|
98 | + */ |
|
99 | + public function layout_form_loop() |
|
100 | + { |
|
101 | + $html = ''; |
|
102 | + foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
103 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
104 | + $html .= apply_filters( |
|
105 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
106 | + . $name . '__in_' . $this->_form_section->name(), |
|
107 | + $this->layout_input($subsection), |
|
108 | + $this->_form_section, |
|
109 | + $subsection |
|
110 | + ); |
|
111 | + } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
112 | + $html .= apply_filters( |
|
113 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
114 | + . $name . '__in_' . $this->_form_section->name(), |
|
115 | + $this->layout_subsection($subsection), |
|
116 | + $this->_form_section, |
|
117 | + $subsection |
|
118 | + ); |
|
119 | + } |
|
120 | + } |
|
121 | + return $html; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
128 | + * |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + abstract public function layout_form_begin(); |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
137 | + * |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + abstract public function layout_form_end(); |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
146 | + * is putting each input in a row of its own, this should probably be called by a |
|
147 | + * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
148 | + * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
149 | + * customize the form's layout, but would like to make use of it for laying out |
|
150 | + * 'easy-to-layout' inputs |
|
151 | + * |
|
152 | + * @param EE_Form_Input_Base $input |
|
153 | + * @return string html |
|
154 | + */ |
|
155 | + abstract public function layout_input($input); |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Similar to layout_input(), should be used internally by layout_form() within a |
|
161 | + * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
162 | + * that the proper subsection will layout its container, label, etc on its own. |
|
163 | + * |
|
164 | + * @param EE_Form_Section_Base $subsection |
|
165 | + * @return string html |
|
166 | + */ |
|
167 | + abstract public function layout_subsection($subsection); |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Gets the HTML for the label tag and its contents for the input |
|
173 | + * |
|
174 | + * @param EE_Form_Input_Base $input |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + public function display_label($input) |
|
178 | + { |
|
179 | + $class = $input->required() |
|
180 | + ? 'ee-required-label ' . $input->html_label_class() |
|
181 | + : $input->html_label_class(); |
|
182 | + $label_text = $input->required() |
|
183 | + ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
184 | + : $input->html_label_text(); |
|
185 | + return '<label id="' |
|
186 | + . $input->html_label_id() |
|
187 | + . '" class="' |
|
188 | + . $class |
|
189 | + . '" style="' |
|
190 | + . $input->html_label_style() |
|
191 | + . '" for="' . $input->html_name() |
|
192 | + . '">' |
|
193 | + . $label_text |
|
194 | + . '</label>'; |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * returns the HTML for the server-side validation errors for the specified input |
|
201 | + * Note that if JS is enabled, it should remove these and instead |
|
202 | + * populate the form's errors in the jquery validate fashion |
|
203 | + * using the localized data provided to the JS |
|
204 | + * |
|
205 | + * @param EE_Form_Input_Base $input |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public function display_errors($input) |
|
209 | + { |
|
210 | + if ($input->get_validation_errors()) { |
|
211 | + return "<label id='" |
|
212 | + . $input->html_id() |
|
213 | + . "-error' class='error' for='{$input->html_name()}'>" |
|
214 | + . $input->get_validation_error_string() |
|
215 | + . '</label>'; |
|
216 | + } |
|
217 | + return ''; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * Displays the help span for the specified input |
|
224 | + * |
|
225 | + * @param EE_Form_Input_Base $input |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public function display_help_text($input) |
|
229 | + { |
|
230 | + $help_text = $input->html_help_text(); |
|
231 | + if ($help_text !== '' && $help_text !== null) { |
|
232 | + $tag = is_admin() ? 'p' : 'span'; |
|
233 | + return '<' |
|
234 | + . $tag |
|
235 | + . ' id="' |
|
236 | + . $input->html_id() |
|
237 | + . '-help" class="' |
|
238 | + . $input->html_help_class() |
|
239 | + . '" style="' |
|
240 | + . $input->html_help_style() |
|
241 | + . '">' |
|
242 | + . $help_text |
|
243 | + . '</' |
|
244 | + . $tag |
|
245 | + . '>'; |
|
246 | + } |
|
247 | + return ''; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Does an action and hook onto the end of teh form |
|
254 | + * |
|
255 | + * @param string $html |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + public function add_form_section_hooks_and_filters($html) |
|
259 | + { |
|
260 | + // replace dashes and spaces with underscores |
|
261 | + $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
262 | + do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
263 | + $html = (string) apply_filters( |
|
264 | + 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
265 | + $html, |
|
266 | + $this->_form_section |
|
267 | + ); |
|
268 | + $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
269 | + $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
270 | + return $html; |
|
271 | + } |
|
272 | 272 | } |
@@ -70,19 +70,19 @@ discard block |
||
70 | 70 | $html = ''; |
71 | 71 | // layout_form_begin |
72 | 72 | $html .= apply_filters( |
73 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
73 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(), |
|
74 | 74 | $this->layout_form_begin(), |
75 | 75 | $this->_form_section |
76 | 76 | ); |
77 | 77 | // layout_form_loop |
78 | 78 | $html .= apply_filters( |
79 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
79 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(), |
|
80 | 80 | $this->layout_form_loop(), |
81 | 81 | $this->_form_section |
82 | 82 | ); |
83 | 83 | // layout_form_end |
84 | 84 | $html .= apply_filters( |
85 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
85 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(), |
|
86 | 86 | $this->layout_form_end(), |
87 | 87 | $this->_form_section |
88 | 88 | ); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | if ($subsection instanceof EE_Form_Input_Base) { |
104 | 104 | $html .= apply_filters( |
105 | 105 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
106 | - . $name . '__in_' . $this->_form_section->name(), |
|
106 | + . $name.'__in_'.$this->_form_section->name(), |
|
107 | 107 | $this->layout_input($subsection), |
108 | 108 | $this->_form_section, |
109 | 109 | $subsection |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } elseif ($subsection instanceof EE_Form_Section_Base) { |
112 | 112 | $html .= apply_filters( |
113 | 113 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
114 | - . $name . '__in_' . $this->_form_section->name(), |
|
114 | + . $name.'__in_'.$this->_form_section->name(), |
|
115 | 115 | $this->layout_subsection($subsection), |
116 | 116 | $this->_form_section, |
117 | 117 | $subsection |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | public function display_label($input) |
178 | 178 | { |
179 | 179 | $class = $input->required() |
180 | - ? 'ee-required-label ' . $input->html_label_class() |
|
180 | + ? 'ee-required-label '.$input->html_label_class() |
|
181 | 181 | : $input->html_label_class(); |
182 | 182 | $label_text = $input->required() |
183 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
183 | + ? $input->html_label_text().'<span class="ee-asterisk">*</span>' |
|
184 | 184 | : $input->html_label_text(); |
185 | 185 | return '<label id="' |
186 | 186 | . $input->html_label_id() |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | . $class |
189 | 189 | . '" style="' |
190 | 190 | . $input->html_label_style() |
191 | - . '" for="' . $input->html_name() |
|
191 | + . '" for="'.$input->html_name() |
|
192 | 192 | . '">' |
193 | 193 | . $label_text |
194 | 194 | . '</label>'; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function display_help_text($input) |
229 | 229 | { |
230 | - $help_text = $input->html_help_text(); |
|
230 | + $help_text = $input->html_help_text(); |
|
231 | 231 | if ($help_text !== '' && $help_text !== null) { |
232 | 232 | $tag = is_admin() ? 'p' : 'span'; |
233 | 233 | return '<' |
@@ -259,14 +259,14 @@ discard block |
||
259 | 259 | { |
260 | 260 | // replace dashes and spaces with underscores |
261 | 261 | $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
262 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
262 | + do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section); |
|
263 | 263 | $html = (string) apply_filters( |
264 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
264 | + 'AFEE__Form_Section_Layout__'.$hook_name.'__html', |
|
265 | 265 | $html, |
266 | 266 | $this->_form_section |
267 | 267 | ); |
268 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
269 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
268 | + $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->'; |
|
269 | + $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->'; |
|
270 | 270 | return $html; |
271 | 271 | } |
272 | 272 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\ui\browser\checkins\entities\CheckinStatusDashicon; |
4 | 4 | |
5 | 5 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('NO direct script access allowed'); |
|
6 | + exit('NO direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -20,1186 +20,1186 @@ discard block |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * This is used to hold the reports template data which is setup early in the request. |
|
25 | - * |
|
26 | - * @type array |
|
27 | - */ |
|
28 | - protected $_reports_template_data = array(); |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Extend_Registrations_Admin_Page constructor. |
|
34 | - * |
|
35 | - * @param bool $routing |
|
36 | - */ |
|
37 | - public function __construct($routing = true) |
|
38 | - { |
|
39 | - parent::__construct($routing); |
|
40 | - if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
41 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
42 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
43 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - protected function _extend_page_config() |
|
50 | - { |
|
51 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
52 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
53 | - ? $this->_req_data['_REG_ID'] |
|
54 | - : 0; |
|
55 | - // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0; |
|
56 | - // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) |
|
57 | - // ? $this->_req_data['post'] : $att_id; |
|
58 | - $new_page_routes = array( |
|
59 | - 'reports' => array( |
|
60 | - 'func' => '_registration_reports', |
|
61 | - 'capability' => 'ee_read_registrations', |
|
62 | - ), |
|
63 | - 'registration_checkins' => array( |
|
64 | - 'func' => '_registration_checkin_list_table', |
|
65 | - 'capability' => 'ee_read_checkins', |
|
66 | - ), |
|
67 | - 'newsletter_selected_send' => array( |
|
68 | - 'func' => '_newsletter_selected_send', |
|
69 | - 'noheader' => true, |
|
70 | - 'capability' => 'ee_send_message', |
|
71 | - ), |
|
72 | - 'delete_checkin_rows' => array( |
|
73 | - 'func' => '_delete_checkin_rows', |
|
74 | - 'noheader' => true, |
|
75 | - 'capability' => 'ee_delete_checkins', |
|
76 | - ), |
|
77 | - 'delete_checkin_row' => array( |
|
78 | - 'func' => '_delete_checkin_row', |
|
79 | - 'noheader' => true, |
|
80 | - 'capability' => 'ee_delete_checkin', |
|
81 | - 'obj_id' => $reg_id, |
|
82 | - ), |
|
83 | - 'toggle_checkin_status' => array( |
|
84 | - 'func' => '_toggle_checkin_status', |
|
85 | - 'noheader' => true, |
|
86 | - 'capability' => 'ee_edit_checkin', |
|
87 | - 'obj_id' => $reg_id, |
|
88 | - ), |
|
89 | - 'toggle_checkin_status_bulk' => array( |
|
90 | - 'func' => '_toggle_checkin_status', |
|
91 | - 'noheader' => true, |
|
92 | - 'capability' => 'ee_edit_checkins' |
|
93 | - ), |
|
94 | - 'event_registrations' => array( |
|
95 | - 'func' => '_event_registrations_list_table', |
|
96 | - 'capability' => 'ee_read_checkins', |
|
97 | - ), |
|
98 | - 'registrations_checkin_report' => array( |
|
99 | - 'func' => '_registrations_checkin_report', |
|
100 | - 'noheader' => true, |
|
101 | - 'capability' => 'ee_read_registrations', |
|
102 | - ), |
|
103 | - ); |
|
104 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
105 | - $new_page_config = array( |
|
106 | - 'reports' => array( |
|
107 | - 'nav' => array( |
|
108 | - 'label' => __('Reports', 'event_espresso'), |
|
109 | - 'order' => 30, |
|
110 | - ), |
|
111 | - 'help_tabs' => array( |
|
112 | - 'registrations_reports_help_tab' => array( |
|
113 | - 'title' => __('Registration Reports', 'event_espresso'), |
|
114 | - 'filename' => 'registrations_reports', |
|
115 | - ), |
|
116 | - ), |
|
117 | - /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
118 | - 'require_nonce' => false, |
|
119 | - ), |
|
120 | - 'event_registrations' => array( |
|
121 | - 'nav' => array( |
|
122 | - 'label' => __('Event Check-In', 'event_espresso'), |
|
123 | - 'order' => 10, |
|
124 | - 'persistent' => true, |
|
125 | - ), |
|
126 | - 'help_tabs' => array( |
|
127 | - 'registrations_event_checkin_help_tab' => array( |
|
128 | - 'title' => __('Registrations Event Check-In', 'event_espresso'), |
|
129 | - 'filename' => 'registrations_event_checkin', |
|
130 | - ), |
|
131 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
132 | - 'title' => __('Event Check-In Table Column Headings', 'event_espresso'), |
|
133 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
134 | - ), |
|
135 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
136 | - 'title' => __('Event Check-In Filters', 'event_espresso'), |
|
137 | - 'filename' => 'registrations_event_checkin_filters', |
|
138 | - ), |
|
139 | - 'registrations_event_checkin_views_help_tab' => array( |
|
140 | - 'title' => __('Event Check-In Views', 'event_espresso'), |
|
141 | - 'filename' => 'registrations_event_checkin_views', |
|
142 | - ), |
|
143 | - 'registrations_event_checkin_other_help_tab' => array( |
|
144 | - 'title' => __('Event Check-In Other', 'event_espresso'), |
|
145 | - 'filename' => 'registrations_event_checkin_other', |
|
146 | - ), |
|
147 | - ), |
|
148 | - 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
149 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
150 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
151 | - 'metaboxes' => array(), |
|
152 | - 'require_nonce' => false, |
|
153 | - ), |
|
154 | - 'registration_checkins' => array( |
|
155 | - 'nav' => array( |
|
156 | - 'label' => __('Check-In Records', 'event_espresso'), |
|
157 | - 'order' => 15, |
|
158 | - 'persistent' => false, |
|
159 | - ), |
|
160 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
161 | - //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
162 | - 'metaboxes' => array(), |
|
163 | - 'require_nonce' => false, |
|
164 | - ), |
|
165 | - ); |
|
166 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
167 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
168 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - protected function _ajax_hooks() |
|
174 | - { |
|
175 | - parent::_ajax_hooks(); |
|
176 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - public function load_scripts_styles() |
|
182 | - { |
|
183 | - parent::load_scripts_styles(); |
|
184 | - //if newsletter message type is active then let's add filter and load js for it. |
|
185 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
186 | - //enqueue newsletter js |
|
187 | - wp_enqueue_script( |
|
188 | - 'ee-newsletter-trigger', |
|
189 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
190 | - array('ee-dialog'), |
|
191 | - EVENT_ESPRESSO_VERSION, |
|
192 | - true |
|
193 | - ); |
|
194 | - wp_enqueue_style( |
|
195 | - 'ee-newsletter-trigger-css', |
|
196 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
197 | - array(), |
|
198 | - EVENT_ESPRESSO_VERSION |
|
199 | - ); |
|
200 | - //hook in buttons for newsletter message type trigger. |
|
201 | - add_action( |
|
202 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
203 | - array($this, 'add_newsletter_action_buttons'), |
|
204 | - 10 |
|
205 | - ); |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - public function load_scripts_styles_reports() |
|
212 | - { |
|
213 | - wp_register_script( |
|
214 | - 'ee-reg-reports-js', |
|
215 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
216 | - array('google-charts'), |
|
217 | - EVENT_ESPRESSO_VERSION, |
|
218 | - true |
|
219 | - ); |
|
220 | - wp_enqueue_script('ee-reg-reports-js'); |
|
221 | - $this->_registration_reports_js_setup(); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - protected function _add_screen_options_event_registrations() |
|
227 | - { |
|
228 | - $this->_per_page_screen_option(); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - protected function _add_screen_options_registration_checkins() |
|
234 | - { |
|
235 | - $page_title = $this->_admin_page_title; |
|
236 | - $this->_admin_page_title = __('Check-In Records', 'event_espresso'); |
|
237 | - $this->_per_page_screen_option(); |
|
238 | - $this->_admin_page_title = $page_title; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - protected function _set_list_table_views_event_registrations() |
|
244 | - { |
|
245 | - $this->_views = array( |
|
246 | - 'all' => array( |
|
247 | - 'slug' => 'all', |
|
248 | - 'label' => __('All', 'event_espresso'), |
|
249 | - 'count' => 0, |
|
250 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
251 | - ? array() |
|
252 | - : array( |
|
253 | - 'toggle_checkin_status_bulk' => __('Toggle Check-In', 'event_espresso'), |
|
254 | - ), |
|
255 | - ), |
|
256 | - ); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - |
|
261 | - protected function _set_list_table_views_registration_checkins() |
|
262 | - { |
|
263 | - $this->_views = array( |
|
264 | - 'all' => array( |
|
265 | - 'slug' => 'all', |
|
266 | - 'label' => __('All', 'event_espresso'), |
|
267 | - 'count' => 0, |
|
268 | - 'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')), |
|
269 | - ), |
|
270 | - ); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * callback for ajax action. |
|
277 | - * |
|
278 | - * @since 4.3.0 |
|
279 | - * @return void (JSON) |
|
280 | - * @throws \EE_Error |
|
281 | - */ |
|
282 | - public function get_newsletter_form_content() |
|
283 | - { |
|
284 | - //do a nonce check cause we're not coming in from an normal route here. |
|
285 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
286 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
287 | - ) : ''; |
|
288 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
289 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
290 | - //let's get the mtp for the incoming MTP_ ID |
|
291 | - if ( ! isset($this->_req_data['GRP_ID'])) { |
|
292 | - EE_Error::add_error( |
|
293 | - __( |
|
294 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
295 | - 'event_espresso' |
|
296 | - ), |
|
297 | - __FILE__, |
|
298 | - __FUNCTION__, |
|
299 | - __LINE__ |
|
300 | - ); |
|
301 | - $this->_template_args['success'] = false; |
|
302 | - $this->_template_args['error'] = true; |
|
303 | - $this->_return_json(); |
|
304 | - } |
|
305 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
306 | - if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
307 | - EE_Error::add_error( |
|
308 | - sprintf( |
|
309 | - __( |
|
310 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
311 | - 'event_espresso' |
|
312 | - ), |
|
313 | - $this->_req_data['GRP_ID'] |
|
314 | - ), |
|
315 | - __FILE__, |
|
316 | - __FUNCTION__, |
|
317 | - __LINE__ |
|
318 | - ); |
|
319 | - $this->_template_args['success'] = false; |
|
320 | - $this->_template_args['error'] = true; |
|
321 | - $this->_return_json(); |
|
322 | - } |
|
323 | - $MTPs = $MTPG->context_templates(); |
|
324 | - $MTPs = $MTPs['attendee']; |
|
325 | - $template_fields = array(); |
|
326 | - /** @var EE_Message_Template $MTP */ |
|
327 | - foreach ($MTPs as $MTP) { |
|
328 | - $field = $MTP->get('MTP_template_field'); |
|
329 | - if ($field === 'content') { |
|
330 | - $content = $MTP->get('MTP_content'); |
|
331 | - if ( ! empty($content['newsletter_content'])) { |
|
332 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
333 | - } |
|
334 | - continue; |
|
335 | - } |
|
336 | - $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
337 | - } |
|
338 | - $this->_template_args['success'] = true; |
|
339 | - $this->_template_args['error'] = false; |
|
340 | - $this->_template_args['data'] = array( |
|
341 | - 'batch_message_from' => isset($template_fields['from']) |
|
342 | - ? $template_fields['from'] |
|
343 | - : '', |
|
344 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
345 | - ? $template_fields['subject'] |
|
346 | - : '', |
|
347 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
348 | - ? $template_fields['newsletter_content'] |
|
349 | - : '', |
|
350 | - ); |
|
351 | - $this->_return_json(); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
358 | - * |
|
359 | - * @since 4.3.0 |
|
360 | - * @param EE_Admin_List_Table $list_table |
|
361 | - * @return void |
|
362 | - */ |
|
363 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
364 | - { |
|
365 | - if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
366 | - 'ee_send_message', |
|
367 | - 'espresso_registrations_newsletter_selected_send' |
|
368 | - ) |
|
369 | - ) { |
|
370 | - return; |
|
371 | - } |
|
372 | - $routes_to_add_to = array( |
|
373 | - 'contact_list', |
|
374 | - 'event_registrations', |
|
375 | - 'default', |
|
376 | - ); |
|
377 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
378 | - if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
379 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
380 | - ) { |
|
381 | - echo ''; |
|
382 | - } else { |
|
383 | - $button_text = sprintf( |
|
384 | - __('Send Batch Message (%s selected)', 'event_espresso'), |
|
385 | - '<span class="send-selected-newsletter-count">0</span>' |
|
386 | - ); |
|
387 | - echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>' |
|
388 | - . $button_text |
|
389 | - . '</button>'; |
|
390 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
391 | - } |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - public function newsletter_send_form_skeleton() |
|
398 | - { |
|
399 | - $list_table = $this->_list_table_object; |
|
400 | - $codes = array(); |
|
401 | - //need to templates for the newsletter message type for the template selector. |
|
402 | - $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
403 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
404 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
405 | - ); |
|
406 | - foreach ($mtps as $mtp) { |
|
407 | - $name = $mtp->name(); |
|
408 | - $values[] = array( |
|
409 | - 'text' => empty($name) ? __('Global', 'event_espresso') : $name, |
|
410 | - 'id' => $mtp->ID(), |
|
411 | - ); |
|
412 | - } |
|
413 | - //need to get a list of shortcodes that are available for the newsletter message type. |
|
414 | - $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false); |
|
415 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
416 | - $codes[$field] = implode(', ', array_keys($shortcode_array)); |
|
417 | - } |
|
418 | - $shortcodes = $codes; |
|
419 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
420 | - $form_template_args = array( |
|
421 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
422 | - 'form_route' => 'newsletter_selected_send', |
|
423 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
424 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
425 | - 'redirect_back_to' => $this->_req_action, |
|
426 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
427 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
428 | - 'shortcodes' => $shortcodes, |
|
429 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
430 | - ); |
|
431 | - EEH_Template::display_template($form_template, $form_template_args); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Handles sending selected registrations/contacts a newsletter. |
|
438 | - * |
|
439 | - * @since 4.3.0 |
|
440 | - * @return void |
|
441 | - * @throws \EE_Error |
|
442 | - */ |
|
443 | - protected function _newsletter_selected_send() |
|
444 | - { |
|
445 | - $success = true; |
|
446 | - //first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
447 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
448 | - EE_Error::add_error( |
|
449 | - __( |
|
450 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
451 | - 'event_espresso' |
|
452 | - ), |
|
453 | - __FILE__, |
|
454 | - __FUNCTION__, |
|
455 | - __LINE__ |
|
456 | - ); |
|
457 | - $success = false; |
|
458 | - } |
|
459 | - if ($success) { |
|
460 | - //update Message template in case there are any changes |
|
461 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
462 | - $this->_req_data['newsletter_mtp_selected'] |
|
463 | - ); |
|
464 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
465 | - ? $Message_Template_Group->context_templates() |
|
466 | - : array(); |
|
467 | - if (empty($Message_Templates)) { |
|
468 | - EE_Error::add_error( |
|
469 | - __( |
|
470 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
471 | - 'event_espresso' |
|
472 | - ), |
|
473 | - __FILE__, |
|
474 | - __FUNCTION__, |
|
475 | - __LINE__ |
|
476 | - ); |
|
477 | - } |
|
478 | - //let's just update the specific fields |
|
479 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
480 | - if ($Message_Template instanceof EE_Message_Template) { |
|
481 | - $field = $Message_Template->get('MTP_template_field'); |
|
482 | - $content = $Message_Template->get('MTP_content'); |
|
483 | - $new_content = $content; |
|
484 | - switch ($field) { |
|
485 | - case 'from' : |
|
486 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
487 | - ? $this->_req_data['batch_message']['from'] |
|
488 | - : $content; |
|
489 | - break; |
|
490 | - case 'subject' : |
|
491 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
492 | - ? $this->_req_data['batch_message']['subject'] |
|
493 | - : $content; |
|
494 | - break; |
|
495 | - case 'content' : |
|
496 | - $new_content = $content; |
|
497 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
498 | - ? $this->_req_data['batch_message']['content'] |
|
499 | - : $content['newsletter_content']; |
|
500 | - break; |
|
501 | - default : |
|
502 | - //continue the foreach loop, we don't want to set $new_content nor save. |
|
503 | - continue 2; |
|
504 | - } |
|
505 | - $Message_Template->set('MTP_content', $new_content); |
|
506 | - $Message_Template->save(); |
|
507 | - } |
|
508 | - } |
|
509 | - //great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
510 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
511 | - ? $this->_req_data['batch_message']['id_type'] |
|
512 | - : 'registration'; |
|
513 | - //id_type will affect how we assemble the ids. |
|
514 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
515 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
516 | - : array(); |
|
517 | - $registrations_used_for_contact_data = array(); |
|
518 | - //using switch because eventually we'll have other contexts that will be used for generating messages. |
|
519 | - switch ($id_type) { |
|
520 | - case 'registration' : |
|
521 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
522 | - array( |
|
523 | - array( |
|
524 | - 'REG_ID' => array('IN', $ids), |
|
525 | - ), |
|
526 | - ) |
|
527 | - ); |
|
528 | - break; |
|
529 | - case 'contact' : |
|
530 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
531 | - ->get_latest_registration_for_each_of_given_contacts($ids); |
|
532 | - break; |
|
533 | - } |
|
534 | - do_action_ref_array( |
|
535 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
536 | - array( |
|
537 | - $registrations_used_for_contact_data, |
|
538 | - $Message_Template_Group->ID() |
|
539 | - ) |
|
540 | - ); |
|
541 | - //kept for backward compat, internally we no longer use this action. |
|
542 | - //@deprecated 4.8.36.rc.002 |
|
543 | - $contacts = $id_type === 'registration' |
|
544 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
545 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
546 | - do_action_ref_array( |
|
547 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
548 | - array( |
|
549 | - $contacts, |
|
550 | - $Message_Template_Group->ID() |
|
551 | - ) |
|
552 | - ); |
|
553 | - } |
|
554 | - $query_args = array( |
|
555 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
556 | - ? $this->_req_data['redirect_back_to'] |
|
557 | - : 'default', |
|
558 | - ); |
|
559 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
566 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
567 | - */ |
|
568 | - protected function _registration_reports_js_setup() |
|
569 | - { |
|
570 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
571 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * generates Business Reports regarding Registrations |
|
578 | - * |
|
579 | - * @access protected |
|
580 | - * @return void |
|
581 | - */ |
|
582 | - protected function _registration_reports() |
|
583 | - { |
|
584 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
585 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
586 | - $template_path, |
|
587 | - $this->_reports_template_data, |
|
588 | - true |
|
589 | - ); |
|
590 | - // the final template wrapper |
|
591 | - $this->display_admin_page_with_no_sidebar(); |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - |
|
596 | - /** |
|
597 | - * Generates Business Report showing total registrations per day. |
|
598 | - * |
|
599 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
600 | - * @return string |
|
601 | - */ |
|
602 | - private function _registrations_per_day_report($period = '-1 month') |
|
603 | - { |
|
604 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
605 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
606 | - $results = (array)$results; |
|
607 | - $regs = array(); |
|
608 | - $subtitle = ''; |
|
609 | - if ($results) { |
|
610 | - $column_titles = array(); |
|
611 | - $tracker = 0; |
|
612 | - foreach ($results as $result) { |
|
613 | - $report_column_values = array(); |
|
614 | - foreach ($result as $property_name => $property_value) { |
|
615 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
616 | - : (int)$property_value; |
|
617 | - $report_column_values[] = $property_value; |
|
618 | - if ($tracker === 0) { |
|
619 | - if ($property_name === 'Registration_REG_date') { |
|
620 | - $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso'); |
|
621 | - } else { |
|
622 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
623 | - } |
|
624 | - } |
|
625 | - } |
|
626 | - $tracker++; |
|
627 | - $regs[] = $report_column_values; |
|
628 | - } |
|
629 | - //make sure the column_titles is pushed to the beginning of the array |
|
630 | - array_unshift($regs, $column_titles); |
|
631 | - //setup the date range. |
|
632 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
633 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
634 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
635 | - $subtitle = sprintf( |
|
636 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
637 | - $beginning_date->format('Y-m-d'), |
|
638 | - $ending_date->format('Y-m-d') |
|
639 | - ); |
|
640 | - } |
|
641 | - $report_title = __('Total Registrations per Day', 'event_espresso'); |
|
642 | - $report_params = array( |
|
643 | - 'title' => $report_title, |
|
644 | - 'subtitle' => $subtitle, |
|
645 | - 'id' => $report_ID, |
|
646 | - 'regs' => $regs, |
|
647 | - 'noResults' => empty($regs), |
|
648 | - 'noRegsMsg' => sprintf( |
|
649 | - __( |
|
650 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
651 | - 'event_espresso' |
|
652 | - ), |
|
653 | - '<h2>' . $report_title . '</h2><p>', |
|
654 | - '</p>' |
|
655 | - ), |
|
656 | - ); |
|
657 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
658 | - return $report_ID; |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * Generates Business Report showing total registrations per event. |
|
665 | - * |
|
666 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
667 | - * @return string |
|
668 | - */ |
|
669 | - private function _registrations_per_event_report($period = '-1 month') |
|
670 | - { |
|
671 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
672 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
673 | - $results = (array)$results; |
|
674 | - $regs = array(); |
|
675 | - $subtitle = ''; |
|
676 | - if ($results) { |
|
677 | - $column_titles = array(); |
|
678 | - $tracker = 0; |
|
679 | - foreach ($results as $result) { |
|
680 | - $report_column_values = array(); |
|
681 | - foreach ($result as $property_name => $property_value) { |
|
682 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
683 | - $property_value, |
|
684 | - 4, |
|
685 | - '...' |
|
686 | - ) : (int)$property_value; |
|
687 | - $report_column_values[] = $property_value; |
|
688 | - if ($tracker === 0) { |
|
689 | - if ($property_name === 'Registration_Event') { |
|
690 | - $column_titles[] = __('Event', 'event_espresso'); |
|
691 | - } else { |
|
692 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
693 | - } |
|
694 | - } |
|
695 | - } |
|
696 | - $tracker++; |
|
697 | - $regs[] = $report_column_values; |
|
698 | - } |
|
699 | - //make sure the column_titles is pushed to the beginning of the array |
|
700 | - array_unshift($regs, $column_titles); |
|
701 | - //setup the date range. |
|
702 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
703 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
704 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
705 | - $subtitle = sprintf( |
|
706 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
707 | - $beginning_date->format('Y-m-d'), |
|
708 | - $ending_date->format('Y-m-d') |
|
709 | - ); |
|
710 | - } |
|
711 | - $report_title = __('Total Registrations per Event', 'event_espresso'); |
|
712 | - $report_params = array( |
|
713 | - 'title' => $report_title, |
|
714 | - 'subtitle' => $subtitle, |
|
715 | - 'id' => $report_ID, |
|
716 | - 'regs' => $regs, |
|
717 | - 'noResults' => empty($regs), |
|
718 | - 'noRegsMsg' => sprintf( |
|
719 | - __( |
|
720 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
721 | - 'event_espresso' |
|
722 | - ), |
|
723 | - '<h2>' . $report_title . '</h2><p>', |
|
724 | - '</p>' |
|
725 | - ), |
|
726 | - ); |
|
727 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
728 | - return $report_ID; |
|
729 | - } |
|
730 | - |
|
731 | - |
|
732 | - |
|
733 | - /** |
|
734 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
735 | - * |
|
736 | - * @access protected |
|
737 | - * @return void |
|
738 | - * @throws \EE_Error |
|
739 | - */ |
|
740 | - protected function _registration_checkin_list_table() |
|
741 | - { |
|
742 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
743 | - $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null; |
|
744 | - /** @var EE_Registration $registration */ |
|
745 | - $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
746 | - $attendee = $registration->attendee(); |
|
747 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
748 | - 'new_registration', |
|
749 | - 'add-registrant', |
|
750 | - array('event_id' => $registration->event_ID()), |
|
751 | - 'add-new-h2' |
|
752 | - ); |
|
753 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
754 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
755 | - $legend_items = array( |
|
756 | - 'checkin' => array( |
|
757 | - 'class' => $checked_in->cssClasses(), |
|
758 | - 'desc' => $checked_in->legendLabel(), |
|
759 | - ), |
|
760 | - 'checkout' => array( |
|
761 | - 'class' => $checked_out->cssClasses(), |
|
762 | - 'desc' => $checked_out->legendLabel(), |
|
763 | - ), |
|
764 | - ); |
|
765 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
766 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
767 | - /** @var EE_Datetime $datetime */ |
|
768 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
769 | - $datetime_label = ''; |
|
770 | - if ($datetime instanceof EE_Datetime) { |
|
771 | - $datetime_label = $datetime->get_dtt_display_name(true); |
|
772 | - $datetime_label .= ! empty($datetime_label) |
|
773 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
774 | - : $datetime->get_dtt_display_name(); |
|
775 | - } |
|
776 | - $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
777 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
778 | - array( |
|
779 | - 'action' => 'event_registrations', |
|
780 | - 'event_id' => $registration->event_ID(), |
|
781 | - 'DTT_ID' => $dtt_id, |
|
782 | - ), |
|
783 | - $this->_admin_base_url |
|
784 | - ) |
|
785 | - : ''; |
|
786 | - $datetime_link = ! empty($datetime_link) |
|
787 | - ? '<a href="' . $datetime_link . '">' |
|
788 | - . '<span id="checkin-dtt">' |
|
789 | - . $datetime_label |
|
790 | - . '</span></a>' |
|
791 | - : $datetime_label; |
|
792 | - $attendee_name = $attendee instanceof EE_Attendee |
|
793 | - ? $attendee->full_name() |
|
794 | - : ''; |
|
795 | - $attendee_link = $attendee instanceof EE_Attendee |
|
796 | - ? $attendee->get_admin_details_link() |
|
797 | - : ''; |
|
798 | - $attendee_link = ! empty($attendee_link) |
|
799 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
800 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
801 | - . '<span id="checkin-attendee-name">' |
|
802 | - . $attendee_name |
|
803 | - . '</span></a>' |
|
804 | - : ''; |
|
805 | - $event_link = $registration->event() instanceof EE_Event |
|
806 | - ? $registration->event()->get_admin_details_link() |
|
807 | - : ''; |
|
808 | - $event_link = ! empty($event_link) |
|
809 | - ? '<a href="' . $event_link . '"' |
|
810 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
811 | - . '<span id="checkin-event-name">' |
|
812 | - . $registration->event_name() |
|
813 | - . '</span>' |
|
814 | - . '</a>' |
|
815 | - : ''; |
|
816 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
817 | - ? '<h2>' . sprintf( |
|
818 | - esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
819 | - $attendee_link, |
|
820 | - $datetime_link, |
|
821 | - $event_link |
|
822 | - ) . '</h2>' |
|
823 | - : ''; |
|
824 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
825 | - ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
826 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
827 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
828 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
829 | - } |
|
830 | - |
|
831 | - |
|
832 | - |
|
833 | - /** |
|
834 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
835 | - * |
|
836 | - * @return void (JSON) |
|
837 | - */ |
|
838 | - public function toggle_checkin_status() |
|
839 | - { |
|
840 | - //first make sure we have the necessary data |
|
841 | - if ( ! isset($this->_req_data['_regid'])) { |
|
842 | - EE_Error::add_error( |
|
843 | - __( |
|
844 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
845 | - 'event_espresso' |
|
846 | - ), |
|
847 | - __FILE__, |
|
848 | - __FUNCTION__, |
|
849 | - __LINE__ |
|
850 | - ); |
|
851 | - $this->_template_args['success'] = false; |
|
852 | - $this->_template_args['error'] = true; |
|
853 | - $this->_return_json(); |
|
854 | - }; |
|
855 | - //do a nonce check cause we're not coming in from an normal route here. |
|
856 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
857 | - : ''; |
|
858 | - $nonce_ref = 'checkin_nonce'; |
|
859 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
860 | - //beautiful! Made it this far so let's get the status. |
|
861 | - $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
862 | - //setup new class to return via ajax |
|
863 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
864 | - $this->_template_args['success'] = true; |
|
865 | - $this->_return_json(); |
|
866 | - } |
|
867 | - |
|
868 | - |
|
869 | - |
|
870 | - /** |
|
871 | - * handles toggling the checkin status for the registration, |
|
872 | - * |
|
873 | - * @access protected |
|
874 | - * @return int|void |
|
875 | - */ |
|
876 | - protected function _toggle_checkin_status() |
|
877 | - { |
|
878 | - //first let's get the query args out of the way for the redirect |
|
879 | - $query_args = array( |
|
880 | - 'action' => 'event_registrations', |
|
881 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
882 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
883 | - ); |
|
884 | - $new_status = false; |
|
885 | - // bulk action check in toggle |
|
886 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
887 | - // cycle thru checkboxes |
|
888 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
889 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
890 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
891 | - } |
|
892 | - } elseif (isset($this->_req_data['_regid'])) { |
|
893 | - //coming from ajax request |
|
894 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
895 | - $query_args['DTT_ID'] = $DTT_ID; |
|
896 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
897 | - } else { |
|
898 | - EE_Error::add_error( |
|
899 | - __('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
900 | - __FILE__, |
|
901 | - __FUNCTION__, |
|
902 | - __LINE__ |
|
903 | - ); |
|
904 | - } |
|
905 | - if (defined('DOING_AJAX')) { |
|
906 | - return $new_status; |
|
907 | - } |
|
908 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
909 | - } |
|
910 | - |
|
911 | - |
|
912 | - |
|
913 | - /** |
|
914 | - * This is toggles a single Check-in for the given registration and datetime. |
|
915 | - * |
|
916 | - * @param int $REG_ID The registration we're toggling |
|
917 | - * @param int $DTT_ID The datetime we're toggling |
|
918 | - * @return int The new status toggled to. |
|
919 | - * @throws \EE_Error |
|
920 | - */ |
|
921 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
922 | - { |
|
923 | - /** @var EE_Registration $REG */ |
|
924 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
925 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
926 | - if ($new_status !== false) { |
|
927 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
928 | - } else { |
|
929 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
930 | - $new_status = false; |
|
931 | - } |
|
932 | - return $new_status; |
|
933 | - } |
|
934 | - |
|
935 | - |
|
936 | - |
|
937 | - /** |
|
938 | - * Takes care of deleting multiple EE_Checkin table rows |
|
939 | - * |
|
940 | - * @access protected |
|
941 | - * @return void |
|
942 | - * @throws \EE_Error |
|
943 | - */ |
|
944 | - protected function _delete_checkin_rows() |
|
945 | - { |
|
946 | - $query_args = array( |
|
947 | - 'action' => 'registration_checkins', |
|
948 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
949 | - '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
950 | - ); |
|
951 | - $errors = 0; |
|
952 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
953 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
954 | - if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
955 | - $errors++; |
|
956 | - } |
|
957 | - } |
|
958 | - } else { |
|
959 | - EE_Error::add_error( |
|
960 | - __( |
|
961 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
962 | - 'event_espresso' |
|
963 | - ), |
|
964 | - __FILE__, |
|
965 | - __FUNCTION__, |
|
966 | - __LINE__ |
|
967 | - ); |
|
968 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
969 | - } |
|
970 | - if ($errors > 0) { |
|
971 | - EE_Error::add_error( |
|
972 | - sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
973 | - __FILE__, |
|
974 | - __FUNCTION__, |
|
975 | - __LINE__ |
|
976 | - ); |
|
977 | - } else { |
|
978 | - EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
979 | - } |
|
980 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
981 | - } |
|
982 | - |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * Deletes a single EE_Checkin row |
|
987 | - * |
|
988 | - * @return void |
|
989 | - * @throws \EE_Error |
|
990 | - */ |
|
991 | - protected function _delete_checkin_row() |
|
992 | - { |
|
993 | - $query_args = array( |
|
994 | - 'action' => 'registration_checkins', |
|
995 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
996 | - '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
997 | - ); |
|
998 | - if ( ! empty($this->_req_data['CHK_ID'])) { |
|
999 | - if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
1000 | - EE_Error::add_error( |
|
1001 | - __('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
1002 | - __FILE__, |
|
1003 | - __FUNCTION__, |
|
1004 | - __LINE__ |
|
1005 | - ); |
|
1006 | - } else { |
|
1007 | - EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
1008 | - } |
|
1009 | - } else { |
|
1010 | - EE_Error::add_error( |
|
1011 | - __( |
|
1012 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1013 | - 'event_espresso' |
|
1014 | - ), |
|
1015 | - __FILE__, |
|
1016 | - __FUNCTION__, |
|
1017 | - __LINE__ |
|
1018 | - ); |
|
1019 | - } |
|
1020 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * generates HTML for the Event Registrations List Table |
|
1027 | - * |
|
1028 | - * @access protected |
|
1029 | - * @return void |
|
1030 | - * @throws \EE_Error |
|
1031 | - */ |
|
1032 | - protected function _event_registrations_list_table() |
|
1033 | - { |
|
1034 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1035 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1036 | - ? $this->get_action_link_or_button( |
|
1037 | - 'new_registration', |
|
1038 | - 'add-registrant', |
|
1039 | - array('event_id' => $this->_req_data['event_id']), |
|
1040 | - 'add-new-h2', |
|
1041 | - '', |
|
1042 | - false |
|
1043 | - ) |
|
1044 | - : ''; |
|
1045 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
1046 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
1047 | - $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
1048 | - $legend_items = array( |
|
1049 | - 'star-icon' => array( |
|
1050 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1051 | - 'desc' => __('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1052 | - ), |
|
1053 | - 'checkin' => array( |
|
1054 | - 'class' => $checked_in->cssClasses(), |
|
1055 | - 'desc' => $checked_in->legendLabel(), |
|
1056 | - ), |
|
1057 | - 'checkout' => array( |
|
1058 | - 'class' => $checked_out->cssClasses(), |
|
1059 | - 'desc' => $checked_out->legendLabel(), |
|
1060 | - ), |
|
1061 | - 'nocheckinrecord' => array( |
|
1062 | - 'class' => $checked_never->cssClasses(), |
|
1063 | - 'desc' => $checked_never->legendLabel(), |
|
1064 | - ), |
|
1065 | - 'view_details' => array( |
|
1066 | - 'class' => 'dashicons dashicons-search', |
|
1067 | - 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
|
1068 | - ), |
|
1069 | - 'approved_status' => array( |
|
1070 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1071 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1072 | - ), |
|
1073 | - 'cancelled_status' => array( |
|
1074 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1075 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1076 | - ), |
|
1077 | - 'declined_status' => array( |
|
1078 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1079 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1080 | - ), |
|
1081 | - 'not_approved' => array( |
|
1082 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1083 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1084 | - ), |
|
1085 | - 'pending_status' => array( |
|
1086 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1087 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1088 | - ), |
|
1089 | - 'wait_list' => array( |
|
1090 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1091 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1092 | - ), |
|
1093 | - ); |
|
1094 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1095 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1096 | - $this->_template_args['before_list_table'] = ! empty($event_id) |
|
1097 | - ? '<h2>' . sprintf( |
|
1098 | - __('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1099 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1100 | - ) . '</h2>' |
|
1101 | - : ''; |
|
1102 | - //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
|
1103 | - /** @var EE_Event $event */ |
|
1104 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1105 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1106 | - $datetime = null; |
|
1107 | - if ($event instanceof EE_Event) { |
|
1108 | - $datetimes_on_event = $event->datetimes(); |
|
1109 | - if (count($datetimes_on_event) === 1) { |
|
1110 | - $datetime = reset($datetimes_on_event); |
|
1111 | - } |
|
1112 | - } |
|
1113 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1114 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1115 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1116 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1117 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1118 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1119 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1120 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1121 | - } |
|
1122 | - //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
|
1123 | - //represents |
|
1124 | - if ( ! $datetime instanceof EE_Datetime) { |
|
1125 | - $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1126 | - . __('In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1127 | - 'event_espresso') |
|
1128 | - . '</p>'; |
|
1129 | - } |
|
1130 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1131 | - } |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1135 | - * conditions) |
|
1136 | - * |
|
1137 | - * @return void ends the request by a redirect or download |
|
1138 | - */ |
|
1139 | - public function _registrations_checkin_report() |
|
1140 | - { |
|
1141 | - $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1142 | - } |
|
1143 | - |
|
1144 | - /** |
|
1145 | - * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1146 | - * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1147 | - * |
|
1148 | - * @param array $request |
|
1149 | - * @param int $per_page |
|
1150 | - * @param bool $count |
|
1151 | - * @return array |
|
1152 | - */ |
|
1153 | - protected function _get_checkin_query_params_from_request( |
|
1154 | - $request, |
|
1155 | - $per_page = 10, |
|
1156 | - $count = false |
|
1157 | - ) { |
|
1158 | - $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1159 | - //unlike the regular registrations list table, |
|
1160 | - $status_ids_array = apply_filters( |
|
1161 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1162 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1163 | - ); |
|
1164 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1165 | - return $query_params; |
|
1166 | - } |
|
1167 | - |
|
1168 | - |
|
1169 | - |
|
1170 | - |
|
1171 | - /** |
|
1172 | - * Gets registrations for an event |
|
1173 | - * |
|
1174 | - * @param int $per_page |
|
1175 | - * @param bool $count whether to return count or data. |
|
1176 | - * @param bool $trash |
|
1177 | - * @param string $orderby |
|
1178 | - * @return EE_Registration[]|int |
|
1179 | - * @throws \EE_Error |
|
1180 | - */ |
|
1181 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1182 | - { |
|
1183 | - //normalize some request params that get setup by the parent `get_registrations` method. |
|
1184 | - $request = $this->_req_data; |
|
1185 | - $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1186 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1187 | - if($trash){ |
|
1188 | - $request['status'] = 'trash'; |
|
1189 | - } |
|
1190 | - $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count ); |
|
1191 | - /** |
|
1192 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1193 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1194 | - * @see EEM_Base::get_all() |
|
1195 | - */ |
|
1196 | - $query_params['group_by'] = ''; |
|
1197 | - |
|
1198 | - return $count |
|
1199 | - ? EEM_Registration::instance()->count($query_params) |
|
1200 | - /** @type EE_Registration[] */ |
|
1201 | - : EEM_Registration::instance()->get_all($query_params); |
|
1202 | - } |
|
23 | + /** |
|
24 | + * This is used to hold the reports template data which is setup early in the request. |
|
25 | + * |
|
26 | + * @type array |
|
27 | + */ |
|
28 | + protected $_reports_template_data = array(); |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Extend_Registrations_Admin_Page constructor. |
|
34 | + * |
|
35 | + * @param bool $routing |
|
36 | + */ |
|
37 | + public function __construct($routing = true) |
|
38 | + { |
|
39 | + parent::__construct($routing); |
|
40 | + if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
41 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
42 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
43 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + protected function _extend_page_config() |
|
50 | + { |
|
51 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
52 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
53 | + ? $this->_req_data['_REG_ID'] |
|
54 | + : 0; |
|
55 | + // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0; |
|
56 | + // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) |
|
57 | + // ? $this->_req_data['post'] : $att_id; |
|
58 | + $new_page_routes = array( |
|
59 | + 'reports' => array( |
|
60 | + 'func' => '_registration_reports', |
|
61 | + 'capability' => 'ee_read_registrations', |
|
62 | + ), |
|
63 | + 'registration_checkins' => array( |
|
64 | + 'func' => '_registration_checkin_list_table', |
|
65 | + 'capability' => 'ee_read_checkins', |
|
66 | + ), |
|
67 | + 'newsletter_selected_send' => array( |
|
68 | + 'func' => '_newsletter_selected_send', |
|
69 | + 'noheader' => true, |
|
70 | + 'capability' => 'ee_send_message', |
|
71 | + ), |
|
72 | + 'delete_checkin_rows' => array( |
|
73 | + 'func' => '_delete_checkin_rows', |
|
74 | + 'noheader' => true, |
|
75 | + 'capability' => 'ee_delete_checkins', |
|
76 | + ), |
|
77 | + 'delete_checkin_row' => array( |
|
78 | + 'func' => '_delete_checkin_row', |
|
79 | + 'noheader' => true, |
|
80 | + 'capability' => 'ee_delete_checkin', |
|
81 | + 'obj_id' => $reg_id, |
|
82 | + ), |
|
83 | + 'toggle_checkin_status' => array( |
|
84 | + 'func' => '_toggle_checkin_status', |
|
85 | + 'noheader' => true, |
|
86 | + 'capability' => 'ee_edit_checkin', |
|
87 | + 'obj_id' => $reg_id, |
|
88 | + ), |
|
89 | + 'toggle_checkin_status_bulk' => array( |
|
90 | + 'func' => '_toggle_checkin_status', |
|
91 | + 'noheader' => true, |
|
92 | + 'capability' => 'ee_edit_checkins' |
|
93 | + ), |
|
94 | + 'event_registrations' => array( |
|
95 | + 'func' => '_event_registrations_list_table', |
|
96 | + 'capability' => 'ee_read_checkins', |
|
97 | + ), |
|
98 | + 'registrations_checkin_report' => array( |
|
99 | + 'func' => '_registrations_checkin_report', |
|
100 | + 'noheader' => true, |
|
101 | + 'capability' => 'ee_read_registrations', |
|
102 | + ), |
|
103 | + ); |
|
104 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
105 | + $new_page_config = array( |
|
106 | + 'reports' => array( |
|
107 | + 'nav' => array( |
|
108 | + 'label' => __('Reports', 'event_espresso'), |
|
109 | + 'order' => 30, |
|
110 | + ), |
|
111 | + 'help_tabs' => array( |
|
112 | + 'registrations_reports_help_tab' => array( |
|
113 | + 'title' => __('Registration Reports', 'event_espresso'), |
|
114 | + 'filename' => 'registrations_reports', |
|
115 | + ), |
|
116 | + ), |
|
117 | + /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
118 | + 'require_nonce' => false, |
|
119 | + ), |
|
120 | + 'event_registrations' => array( |
|
121 | + 'nav' => array( |
|
122 | + 'label' => __('Event Check-In', 'event_espresso'), |
|
123 | + 'order' => 10, |
|
124 | + 'persistent' => true, |
|
125 | + ), |
|
126 | + 'help_tabs' => array( |
|
127 | + 'registrations_event_checkin_help_tab' => array( |
|
128 | + 'title' => __('Registrations Event Check-In', 'event_espresso'), |
|
129 | + 'filename' => 'registrations_event_checkin', |
|
130 | + ), |
|
131 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
132 | + 'title' => __('Event Check-In Table Column Headings', 'event_espresso'), |
|
133 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
134 | + ), |
|
135 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
136 | + 'title' => __('Event Check-In Filters', 'event_espresso'), |
|
137 | + 'filename' => 'registrations_event_checkin_filters', |
|
138 | + ), |
|
139 | + 'registrations_event_checkin_views_help_tab' => array( |
|
140 | + 'title' => __('Event Check-In Views', 'event_espresso'), |
|
141 | + 'filename' => 'registrations_event_checkin_views', |
|
142 | + ), |
|
143 | + 'registrations_event_checkin_other_help_tab' => array( |
|
144 | + 'title' => __('Event Check-In Other', 'event_espresso'), |
|
145 | + 'filename' => 'registrations_event_checkin_other', |
|
146 | + ), |
|
147 | + ), |
|
148 | + 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
149 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
150 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
151 | + 'metaboxes' => array(), |
|
152 | + 'require_nonce' => false, |
|
153 | + ), |
|
154 | + 'registration_checkins' => array( |
|
155 | + 'nav' => array( |
|
156 | + 'label' => __('Check-In Records', 'event_espresso'), |
|
157 | + 'order' => 15, |
|
158 | + 'persistent' => false, |
|
159 | + ), |
|
160 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
161 | + //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
162 | + 'metaboxes' => array(), |
|
163 | + 'require_nonce' => false, |
|
164 | + ), |
|
165 | + ); |
|
166 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
167 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
168 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + protected function _ajax_hooks() |
|
174 | + { |
|
175 | + parent::_ajax_hooks(); |
|
176 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + public function load_scripts_styles() |
|
182 | + { |
|
183 | + parent::load_scripts_styles(); |
|
184 | + //if newsletter message type is active then let's add filter and load js for it. |
|
185 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
186 | + //enqueue newsletter js |
|
187 | + wp_enqueue_script( |
|
188 | + 'ee-newsletter-trigger', |
|
189 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
190 | + array('ee-dialog'), |
|
191 | + EVENT_ESPRESSO_VERSION, |
|
192 | + true |
|
193 | + ); |
|
194 | + wp_enqueue_style( |
|
195 | + 'ee-newsletter-trigger-css', |
|
196 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
197 | + array(), |
|
198 | + EVENT_ESPRESSO_VERSION |
|
199 | + ); |
|
200 | + //hook in buttons for newsletter message type trigger. |
|
201 | + add_action( |
|
202 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
203 | + array($this, 'add_newsletter_action_buttons'), |
|
204 | + 10 |
|
205 | + ); |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + public function load_scripts_styles_reports() |
|
212 | + { |
|
213 | + wp_register_script( |
|
214 | + 'ee-reg-reports-js', |
|
215 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
216 | + array('google-charts'), |
|
217 | + EVENT_ESPRESSO_VERSION, |
|
218 | + true |
|
219 | + ); |
|
220 | + wp_enqueue_script('ee-reg-reports-js'); |
|
221 | + $this->_registration_reports_js_setup(); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + protected function _add_screen_options_event_registrations() |
|
227 | + { |
|
228 | + $this->_per_page_screen_option(); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + protected function _add_screen_options_registration_checkins() |
|
234 | + { |
|
235 | + $page_title = $this->_admin_page_title; |
|
236 | + $this->_admin_page_title = __('Check-In Records', 'event_espresso'); |
|
237 | + $this->_per_page_screen_option(); |
|
238 | + $this->_admin_page_title = $page_title; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + protected function _set_list_table_views_event_registrations() |
|
244 | + { |
|
245 | + $this->_views = array( |
|
246 | + 'all' => array( |
|
247 | + 'slug' => 'all', |
|
248 | + 'label' => __('All', 'event_espresso'), |
|
249 | + 'count' => 0, |
|
250 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
251 | + ? array() |
|
252 | + : array( |
|
253 | + 'toggle_checkin_status_bulk' => __('Toggle Check-In', 'event_espresso'), |
|
254 | + ), |
|
255 | + ), |
|
256 | + ); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + |
|
261 | + protected function _set_list_table_views_registration_checkins() |
|
262 | + { |
|
263 | + $this->_views = array( |
|
264 | + 'all' => array( |
|
265 | + 'slug' => 'all', |
|
266 | + 'label' => __('All', 'event_espresso'), |
|
267 | + 'count' => 0, |
|
268 | + 'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')), |
|
269 | + ), |
|
270 | + ); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * callback for ajax action. |
|
277 | + * |
|
278 | + * @since 4.3.0 |
|
279 | + * @return void (JSON) |
|
280 | + * @throws \EE_Error |
|
281 | + */ |
|
282 | + public function get_newsletter_form_content() |
|
283 | + { |
|
284 | + //do a nonce check cause we're not coming in from an normal route here. |
|
285 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
286 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
287 | + ) : ''; |
|
288 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
289 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
290 | + //let's get the mtp for the incoming MTP_ ID |
|
291 | + if ( ! isset($this->_req_data['GRP_ID'])) { |
|
292 | + EE_Error::add_error( |
|
293 | + __( |
|
294 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
295 | + 'event_espresso' |
|
296 | + ), |
|
297 | + __FILE__, |
|
298 | + __FUNCTION__, |
|
299 | + __LINE__ |
|
300 | + ); |
|
301 | + $this->_template_args['success'] = false; |
|
302 | + $this->_template_args['error'] = true; |
|
303 | + $this->_return_json(); |
|
304 | + } |
|
305 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
306 | + if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
307 | + EE_Error::add_error( |
|
308 | + sprintf( |
|
309 | + __( |
|
310 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
311 | + 'event_espresso' |
|
312 | + ), |
|
313 | + $this->_req_data['GRP_ID'] |
|
314 | + ), |
|
315 | + __FILE__, |
|
316 | + __FUNCTION__, |
|
317 | + __LINE__ |
|
318 | + ); |
|
319 | + $this->_template_args['success'] = false; |
|
320 | + $this->_template_args['error'] = true; |
|
321 | + $this->_return_json(); |
|
322 | + } |
|
323 | + $MTPs = $MTPG->context_templates(); |
|
324 | + $MTPs = $MTPs['attendee']; |
|
325 | + $template_fields = array(); |
|
326 | + /** @var EE_Message_Template $MTP */ |
|
327 | + foreach ($MTPs as $MTP) { |
|
328 | + $field = $MTP->get('MTP_template_field'); |
|
329 | + if ($field === 'content') { |
|
330 | + $content = $MTP->get('MTP_content'); |
|
331 | + if ( ! empty($content['newsletter_content'])) { |
|
332 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
333 | + } |
|
334 | + continue; |
|
335 | + } |
|
336 | + $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
337 | + } |
|
338 | + $this->_template_args['success'] = true; |
|
339 | + $this->_template_args['error'] = false; |
|
340 | + $this->_template_args['data'] = array( |
|
341 | + 'batch_message_from' => isset($template_fields['from']) |
|
342 | + ? $template_fields['from'] |
|
343 | + : '', |
|
344 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
345 | + ? $template_fields['subject'] |
|
346 | + : '', |
|
347 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
348 | + ? $template_fields['newsletter_content'] |
|
349 | + : '', |
|
350 | + ); |
|
351 | + $this->_return_json(); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
358 | + * |
|
359 | + * @since 4.3.0 |
|
360 | + * @param EE_Admin_List_Table $list_table |
|
361 | + * @return void |
|
362 | + */ |
|
363 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
364 | + { |
|
365 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
366 | + 'ee_send_message', |
|
367 | + 'espresso_registrations_newsletter_selected_send' |
|
368 | + ) |
|
369 | + ) { |
|
370 | + return; |
|
371 | + } |
|
372 | + $routes_to_add_to = array( |
|
373 | + 'contact_list', |
|
374 | + 'event_registrations', |
|
375 | + 'default', |
|
376 | + ); |
|
377 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
378 | + if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
379 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
380 | + ) { |
|
381 | + echo ''; |
|
382 | + } else { |
|
383 | + $button_text = sprintf( |
|
384 | + __('Send Batch Message (%s selected)', 'event_espresso'), |
|
385 | + '<span class="send-selected-newsletter-count">0</span>' |
|
386 | + ); |
|
387 | + echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>' |
|
388 | + . $button_text |
|
389 | + . '</button>'; |
|
390 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
391 | + } |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + public function newsletter_send_form_skeleton() |
|
398 | + { |
|
399 | + $list_table = $this->_list_table_object; |
|
400 | + $codes = array(); |
|
401 | + //need to templates for the newsletter message type for the template selector. |
|
402 | + $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
403 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
404 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
405 | + ); |
|
406 | + foreach ($mtps as $mtp) { |
|
407 | + $name = $mtp->name(); |
|
408 | + $values[] = array( |
|
409 | + 'text' => empty($name) ? __('Global', 'event_espresso') : $name, |
|
410 | + 'id' => $mtp->ID(), |
|
411 | + ); |
|
412 | + } |
|
413 | + //need to get a list of shortcodes that are available for the newsletter message type. |
|
414 | + $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false); |
|
415 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
416 | + $codes[$field] = implode(', ', array_keys($shortcode_array)); |
|
417 | + } |
|
418 | + $shortcodes = $codes; |
|
419 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
420 | + $form_template_args = array( |
|
421 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
422 | + 'form_route' => 'newsletter_selected_send', |
|
423 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
424 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
425 | + 'redirect_back_to' => $this->_req_action, |
|
426 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
427 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
428 | + 'shortcodes' => $shortcodes, |
|
429 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
430 | + ); |
|
431 | + EEH_Template::display_template($form_template, $form_template_args); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Handles sending selected registrations/contacts a newsletter. |
|
438 | + * |
|
439 | + * @since 4.3.0 |
|
440 | + * @return void |
|
441 | + * @throws \EE_Error |
|
442 | + */ |
|
443 | + protected function _newsletter_selected_send() |
|
444 | + { |
|
445 | + $success = true; |
|
446 | + //first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
447 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
448 | + EE_Error::add_error( |
|
449 | + __( |
|
450 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
451 | + 'event_espresso' |
|
452 | + ), |
|
453 | + __FILE__, |
|
454 | + __FUNCTION__, |
|
455 | + __LINE__ |
|
456 | + ); |
|
457 | + $success = false; |
|
458 | + } |
|
459 | + if ($success) { |
|
460 | + //update Message template in case there are any changes |
|
461 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
462 | + $this->_req_data['newsletter_mtp_selected'] |
|
463 | + ); |
|
464 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
465 | + ? $Message_Template_Group->context_templates() |
|
466 | + : array(); |
|
467 | + if (empty($Message_Templates)) { |
|
468 | + EE_Error::add_error( |
|
469 | + __( |
|
470 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
471 | + 'event_espresso' |
|
472 | + ), |
|
473 | + __FILE__, |
|
474 | + __FUNCTION__, |
|
475 | + __LINE__ |
|
476 | + ); |
|
477 | + } |
|
478 | + //let's just update the specific fields |
|
479 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
480 | + if ($Message_Template instanceof EE_Message_Template) { |
|
481 | + $field = $Message_Template->get('MTP_template_field'); |
|
482 | + $content = $Message_Template->get('MTP_content'); |
|
483 | + $new_content = $content; |
|
484 | + switch ($field) { |
|
485 | + case 'from' : |
|
486 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
487 | + ? $this->_req_data['batch_message']['from'] |
|
488 | + : $content; |
|
489 | + break; |
|
490 | + case 'subject' : |
|
491 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
492 | + ? $this->_req_data['batch_message']['subject'] |
|
493 | + : $content; |
|
494 | + break; |
|
495 | + case 'content' : |
|
496 | + $new_content = $content; |
|
497 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
498 | + ? $this->_req_data['batch_message']['content'] |
|
499 | + : $content['newsletter_content']; |
|
500 | + break; |
|
501 | + default : |
|
502 | + //continue the foreach loop, we don't want to set $new_content nor save. |
|
503 | + continue 2; |
|
504 | + } |
|
505 | + $Message_Template->set('MTP_content', $new_content); |
|
506 | + $Message_Template->save(); |
|
507 | + } |
|
508 | + } |
|
509 | + //great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
510 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
511 | + ? $this->_req_data['batch_message']['id_type'] |
|
512 | + : 'registration'; |
|
513 | + //id_type will affect how we assemble the ids. |
|
514 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
515 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
516 | + : array(); |
|
517 | + $registrations_used_for_contact_data = array(); |
|
518 | + //using switch because eventually we'll have other contexts that will be used for generating messages. |
|
519 | + switch ($id_type) { |
|
520 | + case 'registration' : |
|
521 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
522 | + array( |
|
523 | + array( |
|
524 | + 'REG_ID' => array('IN', $ids), |
|
525 | + ), |
|
526 | + ) |
|
527 | + ); |
|
528 | + break; |
|
529 | + case 'contact' : |
|
530 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
531 | + ->get_latest_registration_for_each_of_given_contacts($ids); |
|
532 | + break; |
|
533 | + } |
|
534 | + do_action_ref_array( |
|
535 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
536 | + array( |
|
537 | + $registrations_used_for_contact_data, |
|
538 | + $Message_Template_Group->ID() |
|
539 | + ) |
|
540 | + ); |
|
541 | + //kept for backward compat, internally we no longer use this action. |
|
542 | + //@deprecated 4.8.36.rc.002 |
|
543 | + $contacts = $id_type === 'registration' |
|
544 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
545 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
546 | + do_action_ref_array( |
|
547 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
548 | + array( |
|
549 | + $contacts, |
|
550 | + $Message_Template_Group->ID() |
|
551 | + ) |
|
552 | + ); |
|
553 | + } |
|
554 | + $query_args = array( |
|
555 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
556 | + ? $this->_req_data['redirect_back_to'] |
|
557 | + : 'default', |
|
558 | + ); |
|
559 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
566 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
567 | + */ |
|
568 | + protected function _registration_reports_js_setup() |
|
569 | + { |
|
570 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
571 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * generates Business Reports regarding Registrations |
|
578 | + * |
|
579 | + * @access protected |
|
580 | + * @return void |
|
581 | + */ |
|
582 | + protected function _registration_reports() |
|
583 | + { |
|
584 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
585 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
586 | + $template_path, |
|
587 | + $this->_reports_template_data, |
|
588 | + true |
|
589 | + ); |
|
590 | + // the final template wrapper |
|
591 | + $this->display_admin_page_with_no_sidebar(); |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + |
|
596 | + /** |
|
597 | + * Generates Business Report showing total registrations per day. |
|
598 | + * |
|
599 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
600 | + * @return string |
|
601 | + */ |
|
602 | + private function _registrations_per_day_report($period = '-1 month') |
|
603 | + { |
|
604 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
605 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
606 | + $results = (array)$results; |
|
607 | + $regs = array(); |
|
608 | + $subtitle = ''; |
|
609 | + if ($results) { |
|
610 | + $column_titles = array(); |
|
611 | + $tracker = 0; |
|
612 | + foreach ($results as $result) { |
|
613 | + $report_column_values = array(); |
|
614 | + foreach ($result as $property_name => $property_value) { |
|
615 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
616 | + : (int)$property_value; |
|
617 | + $report_column_values[] = $property_value; |
|
618 | + if ($tracker === 0) { |
|
619 | + if ($property_name === 'Registration_REG_date') { |
|
620 | + $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso'); |
|
621 | + } else { |
|
622 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
623 | + } |
|
624 | + } |
|
625 | + } |
|
626 | + $tracker++; |
|
627 | + $regs[] = $report_column_values; |
|
628 | + } |
|
629 | + //make sure the column_titles is pushed to the beginning of the array |
|
630 | + array_unshift($regs, $column_titles); |
|
631 | + //setup the date range. |
|
632 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
633 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
634 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
635 | + $subtitle = sprintf( |
|
636 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
637 | + $beginning_date->format('Y-m-d'), |
|
638 | + $ending_date->format('Y-m-d') |
|
639 | + ); |
|
640 | + } |
|
641 | + $report_title = __('Total Registrations per Day', 'event_espresso'); |
|
642 | + $report_params = array( |
|
643 | + 'title' => $report_title, |
|
644 | + 'subtitle' => $subtitle, |
|
645 | + 'id' => $report_ID, |
|
646 | + 'regs' => $regs, |
|
647 | + 'noResults' => empty($regs), |
|
648 | + 'noRegsMsg' => sprintf( |
|
649 | + __( |
|
650 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
651 | + 'event_espresso' |
|
652 | + ), |
|
653 | + '<h2>' . $report_title . '</h2><p>', |
|
654 | + '</p>' |
|
655 | + ), |
|
656 | + ); |
|
657 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
658 | + return $report_ID; |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * Generates Business Report showing total registrations per event. |
|
665 | + * |
|
666 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
667 | + * @return string |
|
668 | + */ |
|
669 | + private function _registrations_per_event_report($period = '-1 month') |
|
670 | + { |
|
671 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
672 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
673 | + $results = (array)$results; |
|
674 | + $regs = array(); |
|
675 | + $subtitle = ''; |
|
676 | + if ($results) { |
|
677 | + $column_titles = array(); |
|
678 | + $tracker = 0; |
|
679 | + foreach ($results as $result) { |
|
680 | + $report_column_values = array(); |
|
681 | + foreach ($result as $property_name => $property_value) { |
|
682 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
683 | + $property_value, |
|
684 | + 4, |
|
685 | + '...' |
|
686 | + ) : (int)$property_value; |
|
687 | + $report_column_values[] = $property_value; |
|
688 | + if ($tracker === 0) { |
|
689 | + if ($property_name === 'Registration_Event') { |
|
690 | + $column_titles[] = __('Event', 'event_espresso'); |
|
691 | + } else { |
|
692 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
693 | + } |
|
694 | + } |
|
695 | + } |
|
696 | + $tracker++; |
|
697 | + $regs[] = $report_column_values; |
|
698 | + } |
|
699 | + //make sure the column_titles is pushed to the beginning of the array |
|
700 | + array_unshift($regs, $column_titles); |
|
701 | + //setup the date range. |
|
702 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
703 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
704 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
705 | + $subtitle = sprintf( |
|
706 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
707 | + $beginning_date->format('Y-m-d'), |
|
708 | + $ending_date->format('Y-m-d') |
|
709 | + ); |
|
710 | + } |
|
711 | + $report_title = __('Total Registrations per Event', 'event_espresso'); |
|
712 | + $report_params = array( |
|
713 | + 'title' => $report_title, |
|
714 | + 'subtitle' => $subtitle, |
|
715 | + 'id' => $report_ID, |
|
716 | + 'regs' => $regs, |
|
717 | + 'noResults' => empty($regs), |
|
718 | + 'noRegsMsg' => sprintf( |
|
719 | + __( |
|
720 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
721 | + 'event_espresso' |
|
722 | + ), |
|
723 | + '<h2>' . $report_title . '</h2><p>', |
|
724 | + '</p>' |
|
725 | + ), |
|
726 | + ); |
|
727 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
728 | + return $report_ID; |
|
729 | + } |
|
730 | + |
|
731 | + |
|
732 | + |
|
733 | + /** |
|
734 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
735 | + * |
|
736 | + * @access protected |
|
737 | + * @return void |
|
738 | + * @throws \EE_Error |
|
739 | + */ |
|
740 | + protected function _registration_checkin_list_table() |
|
741 | + { |
|
742 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
743 | + $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null; |
|
744 | + /** @var EE_Registration $registration */ |
|
745 | + $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
746 | + $attendee = $registration->attendee(); |
|
747 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
748 | + 'new_registration', |
|
749 | + 'add-registrant', |
|
750 | + array('event_id' => $registration->event_ID()), |
|
751 | + 'add-new-h2' |
|
752 | + ); |
|
753 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
754 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
755 | + $legend_items = array( |
|
756 | + 'checkin' => array( |
|
757 | + 'class' => $checked_in->cssClasses(), |
|
758 | + 'desc' => $checked_in->legendLabel(), |
|
759 | + ), |
|
760 | + 'checkout' => array( |
|
761 | + 'class' => $checked_out->cssClasses(), |
|
762 | + 'desc' => $checked_out->legendLabel(), |
|
763 | + ), |
|
764 | + ); |
|
765 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
766 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
767 | + /** @var EE_Datetime $datetime */ |
|
768 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
769 | + $datetime_label = ''; |
|
770 | + if ($datetime instanceof EE_Datetime) { |
|
771 | + $datetime_label = $datetime->get_dtt_display_name(true); |
|
772 | + $datetime_label .= ! empty($datetime_label) |
|
773 | + ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
774 | + : $datetime->get_dtt_display_name(); |
|
775 | + } |
|
776 | + $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
777 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
778 | + array( |
|
779 | + 'action' => 'event_registrations', |
|
780 | + 'event_id' => $registration->event_ID(), |
|
781 | + 'DTT_ID' => $dtt_id, |
|
782 | + ), |
|
783 | + $this->_admin_base_url |
|
784 | + ) |
|
785 | + : ''; |
|
786 | + $datetime_link = ! empty($datetime_link) |
|
787 | + ? '<a href="' . $datetime_link . '">' |
|
788 | + . '<span id="checkin-dtt">' |
|
789 | + . $datetime_label |
|
790 | + . '</span></a>' |
|
791 | + : $datetime_label; |
|
792 | + $attendee_name = $attendee instanceof EE_Attendee |
|
793 | + ? $attendee->full_name() |
|
794 | + : ''; |
|
795 | + $attendee_link = $attendee instanceof EE_Attendee |
|
796 | + ? $attendee->get_admin_details_link() |
|
797 | + : ''; |
|
798 | + $attendee_link = ! empty($attendee_link) |
|
799 | + ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
800 | + . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
801 | + . '<span id="checkin-attendee-name">' |
|
802 | + . $attendee_name |
|
803 | + . '</span></a>' |
|
804 | + : ''; |
|
805 | + $event_link = $registration->event() instanceof EE_Event |
|
806 | + ? $registration->event()->get_admin_details_link() |
|
807 | + : ''; |
|
808 | + $event_link = ! empty($event_link) |
|
809 | + ? '<a href="' . $event_link . '"' |
|
810 | + . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
811 | + . '<span id="checkin-event-name">' |
|
812 | + . $registration->event_name() |
|
813 | + . '</span>' |
|
814 | + . '</a>' |
|
815 | + : ''; |
|
816 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
817 | + ? '<h2>' . sprintf( |
|
818 | + esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
819 | + $attendee_link, |
|
820 | + $datetime_link, |
|
821 | + $event_link |
|
822 | + ) . '</h2>' |
|
823 | + : ''; |
|
824 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
825 | + ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
826 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
827 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
828 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
829 | + } |
|
830 | + |
|
831 | + |
|
832 | + |
|
833 | + /** |
|
834 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
835 | + * |
|
836 | + * @return void (JSON) |
|
837 | + */ |
|
838 | + public function toggle_checkin_status() |
|
839 | + { |
|
840 | + //first make sure we have the necessary data |
|
841 | + if ( ! isset($this->_req_data['_regid'])) { |
|
842 | + EE_Error::add_error( |
|
843 | + __( |
|
844 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
845 | + 'event_espresso' |
|
846 | + ), |
|
847 | + __FILE__, |
|
848 | + __FUNCTION__, |
|
849 | + __LINE__ |
|
850 | + ); |
|
851 | + $this->_template_args['success'] = false; |
|
852 | + $this->_template_args['error'] = true; |
|
853 | + $this->_return_json(); |
|
854 | + }; |
|
855 | + //do a nonce check cause we're not coming in from an normal route here. |
|
856 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
857 | + : ''; |
|
858 | + $nonce_ref = 'checkin_nonce'; |
|
859 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
860 | + //beautiful! Made it this far so let's get the status. |
|
861 | + $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
862 | + //setup new class to return via ajax |
|
863 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
864 | + $this->_template_args['success'] = true; |
|
865 | + $this->_return_json(); |
|
866 | + } |
|
867 | + |
|
868 | + |
|
869 | + |
|
870 | + /** |
|
871 | + * handles toggling the checkin status for the registration, |
|
872 | + * |
|
873 | + * @access protected |
|
874 | + * @return int|void |
|
875 | + */ |
|
876 | + protected function _toggle_checkin_status() |
|
877 | + { |
|
878 | + //first let's get the query args out of the way for the redirect |
|
879 | + $query_args = array( |
|
880 | + 'action' => 'event_registrations', |
|
881 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
882 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
883 | + ); |
|
884 | + $new_status = false; |
|
885 | + // bulk action check in toggle |
|
886 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
887 | + // cycle thru checkboxes |
|
888 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
889 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
890 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
891 | + } |
|
892 | + } elseif (isset($this->_req_data['_regid'])) { |
|
893 | + //coming from ajax request |
|
894 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
895 | + $query_args['DTT_ID'] = $DTT_ID; |
|
896 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
897 | + } else { |
|
898 | + EE_Error::add_error( |
|
899 | + __('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
900 | + __FILE__, |
|
901 | + __FUNCTION__, |
|
902 | + __LINE__ |
|
903 | + ); |
|
904 | + } |
|
905 | + if (defined('DOING_AJAX')) { |
|
906 | + return $new_status; |
|
907 | + } |
|
908 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
909 | + } |
|
910 | + |
|
911 | + |
|
912 | + |
|
913 | + /** |
|
914 | + * This is toggles a single Check-in for the given registration and datetime. |
|
915 | + * |
|
916 | + * @param int $REG_ID The registration we're toggling |
|
917 | + * @param int $DTT_ID The datetime we're toggling |
|
918 | + * @return int The new status toggled to. |
|
919 | + * @throws \EE_Error |
|
920 | + */ |
|
921 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
922 | + { |
|
923 | + /** @var EE_Registration $REG */ |
|
924 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
925 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
926 | + if ($new_status !== false) { |
|
927 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
928 | + } else { |
|
929 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
930 | + $new_status = false; |
|
931 | + } |
|
932 | + return $new_status; |
|
933 | + } |
|
934 | + |
|
935 | + |
|
936 | + |
|
937 | + /** |
|
938 | + * Takes care of deleting multiple EE_Checkin table rows |
|
939 | + * |
|
940 | + * @access protected |
|
941 | + * @return void |
|
942 | + * @throws \EE_Error |
|
943 | + */ |
|
944 | + protected function _delete_checkin_rows() |
|
945 | + { |
|
946 | + $query_args = array( |
|
947 | + 'action' => 'registration_checkins', |
|
948 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
949 | + '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
950 | + ); |
|
951 | + $errors = 0; |
|
952 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
953 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
954 | + if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
955 | + $errors++; |
|
956 | + } |
|
957 | + } |
|
958 | + } else { |
|
959 | + EE_Error::add_error( |
|
960 | + __( |
|
961 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
962 | + 'event_espresso' |
|
963 | + ), |
|
964 | + __FILE__, |
|
965 | + __FUNCTION__, |
|
966 | + __LINE__ |
|
967 | + ); |
|
968 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
969 | + } |
|
970 | + if ($errors > 0) { |
|
971 | + EE_Error::add_error( |
|
972 | + sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
973 | + __FILE__, |
|
974 | + __FUNCTION__, |
|
975 | + __LINE__ |
|
976 | + ); |
|
977 | + } else { |
|
978 | + EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
979 | + } |
|
980 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
981 | + } |
|
982 | + |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * Deletes a single EE_Checkin row |
|
987 | + * |
|
988 | + * @return void |
|
989 | + * @throws \EE_Error |
|
990 | + */ |
|
991 | + protected function _delete_checkin_row() |
|
992 | + { |
|
993 | + $query_args = array( |
|
994 | + 'action' => 'registration_checkins', |
|
995 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
996 | + '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
997 | + ); |
|
998 | + if ( ! empty($this->_req_data['CHK_ID'])) { |
|
999 | + if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
1000 | + EE_Error::add_error( |
|
1001 | + __('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
1002 | + __FILE__, |
|
1003 | + __FUNCTION__, |
|
1004 | + __LINE__ |
|
1005 | + ); |
|
1006 | + } else { |
|
1007 | + EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
1008 | + } |
|
1009 | + } else { |
|
1010 | + EE_Error::add_error( |
|
1011 | + __( |
|
1012 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1013 | + 'event_espresso' |
|
1014 | + ), |
|
1015 | + __FILE__, |
|
1016 | + __FUNCTION__, |
|
1017 | + __LINE__ |
|
1018 | + ); |
|
1019 | + } |
|
1020 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * generates HTML for the Event Registrations List Table |
|
1027 | + * |
|
1028 | + * @access protected |
|
1029 | + * @return void |
|
1030 | + * @throws \EE_Error |
|
1031 | + */ |
|
1032 | + protected function _event_registrations_list_table() |
|
1033 | + { |
|
1034 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1035 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1036 | + ? $this->get_action_link_or_button( |
|
1037 | + 'new_registration', |
|
1038 | + 'add-registrant', |
|
1039 | + array('event_id' => $this->_req_data['event_id']), |
|
1040 | + 'add-new-h2', |
|
1041 | + '', |
|
1042 | + false |
|
1043 | + ) |
|
1044 | + : ''; |
|
1045 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
1046 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
1047 | + $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
1048 | + $legend_items = array( |
|
1049 | + 'star-icon' => array( |
|
1050 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1051 | + 'desc' => __('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1052 | + ), |
|
1053 | + 'checkin' => array( |
|
1054 | + 'class' => $checked_in->cssClasses(), |
|
1055 | + 'desc' => $checked_in->legendLabel(), |
|
1056 | + ), |
|
1057 | + 'checkout' => array( |
|
1058 | + 'class' => $checked_out->cssClasses(), |
|
1059 | + 'desc' => $checked_out->legendLabel(), |
|
1060 | + ), |
|
1061 | + 'nocheckinrecord' => array( |
|
1062 | + 'class' => $checked_never->cssClasses(), |
|
1063 | + 'desc' => $checked_never->legendLabel(), |
|
1064 | + ), |
|
1065 | + 'view_details' => array( |
|
1066 | + 'class' => 'dashicons dashicons-search', |
|
1067 | + 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
|
1068 | + ), |
|
1069 | + 'approved_status' => array( |
|
1070 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1071 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1072 | + ), |
|
1073 | + 'cancelled_status' => array( |
|
1074 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1075 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1076 | + ), |
|
1077 | + 'declined_status' => array( |
|
1078 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1079 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1080 | + ), |
|
1081 | + 'not_approved' => array( |
|
1082 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1083 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1084 | + ), |
|
1085 | + 'pending_status' => array( |
|
1086 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1087 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1088 | + ), |
|
1089 | + 'wait_list' => array( |
|
1090 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1091 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1092 | + ), |
|
1093 | + ); |
|
1094 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1095 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1096 | + $this->_template_args['before_list_table'] = ! empty($event_id) |
|
1097 | + ? '<h2>' . sprintf( |
|
1098 | + __('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1099 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1100 | + ) . '</h2>' |
|
1101 | + : ''; |
|
1102 | + //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
|
1103 | + /** @var EE_Event $event */ |
|
1104 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1105 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1106 | + $datetime = null; |
|
1107 | + if ($event instanceof EE_Event) { |
|
1108 | + $datetimes_on_event = $event->datetimes(); |
|
1109 | + if (count($datetimes_on_event) === 1) { |
|
1110 | + $datetime = reset($datetimes_on_event); |
|
1111 | + } |
|
1112 | + } |
|
1113 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1114 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1115 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1116 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1117 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1118 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1119 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1120 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1121 | + } |
|
1122 | + //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
|
1123 | + //represents |
|
1124 | + if ( ! $datetime instanceof EE_Datetime) { |
|
1125 | + $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1126 | + . __('In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1127 | + 'event_espresso') |
|
1128 | + . '</p>'; |
|
1129 | + } |
|
1130 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1131 | + } |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1135 | + * conditions) |
|
1136 | + * |
|
1137 | + * @return void ends the request by a redirect or download |
|
1138 | + */ |
|
1139 | + public function _registrations_checkin_report() |
|
1140 | + { |
|
1141 | + $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1142 | + } |
|
1143 | + |
|
1144 | + /** |
|
1145 | + * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1146 | + * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1147 | + * |
|
1148 | + * @param array $request |
|
1149 | + * @param int $per_page |
|
1150 | + * @param bool $count |
|
1151 | + * @return array |
|
1152 | + */ |
|
1153 | + protected function _get_checkin_query_params_from_request( |
|
1154 | + $request, |
|
1155 | + $per_page = 10, |
|
1156 | + $count = false |
|
1157 | + ) { |
|
1158 | + $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1159 | + //unlike the regular registrations list table, |
|
1160 | + $status_ids_array = apply_filters( |
|
1161 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1162 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1163 | + ); |
|
1164 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1165 | + return $query_params; |
|
1166 | + } |
|
1167 | + |
|
1168 | + |
|
1169 | + |
|
1170 | + |
|
1171 | + /** |
|
1172 | + * Gets registrations for an event |
|
1173 | + * |
|
1174 | + * @param int $per_page |
|
1175 | + * @param bool $count whether to return count or data. |
|
1176 | + * @param bool $trash |
|
1177 | + * @param string $orderby |
|
1178 | + * @return EE_Registration[]|int |
|
1179 | + * @throws \EE_Error |
|
1180 | + */ |
|
1181 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1182 | + { |
|
1183 | + //normalize some request params that get setup by the parent `get_registrations` method. |
|
1184 | + $request = $this->_req_data; |
|
1185 | + $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1186 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1187 | + if($trash){ |
|
1188 | + $request['status'] = 'trash'; |
|
1189 | + } |
|
1190 | + $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count ); |
|
1191 | + /** |
|
1192 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1193 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1194 | + * @see EEM_Base::get_all() |
|
1195 | + */ |
|
1196 | + $query_params['group_by'] = ''; |
|
1197 | + |
|
1198 | + return $count |
|
1199 | + ? EEM_Registration::instance()->count($query_params) |
|
1200 | + /** @type EE_Registration[] */ |
|
1201 | + : EEM_Registration::instance()->get_all($query_params); |
|
1202 | + } |
|
1203 | 1203 | |
1204 | 1204 | |
1205 | 1205 | } //end class Registrations Admin Page |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | |
23 | 23 | <div class="event-attendees"> |
24 | 24 | <?php do_action_ref_array( |
25 | - 'AHEE__loop-espresso_event_attendees__before', |
|
26 | - array( |
|
27 | - $contacts, |
|
28 | - $event, |
|
29 | - $datetime, |
|
30 | - $ticket, |
|
31 | - $show_gravatar, |
|
32 | - ) |
|
33 | - ); ?> |
|
25 | + 'AHEE__loop-espresso_event_attendees__before', |
|
26 | + array( |
|
27 | + $contacts, |
|
28 | + $event, |
|
29 | + $datetime, |
|
30 | + $ticket, |
|
31 | + $show_gravatar, |
|
32 | + ) |
|
33 | + ); ?> |
|
34 | 34 | <?php if ( $contacts ) : ?> |
35 | 35 | <ul class="event-attendees-list"> |
36 | 36 | <?php foreach( $contacts as $contact ) : |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | <p><?php echo $no_attendees_message; ?></p> |
48 | 48 | <?php endif; ?> |
49 | 49 | <?php do_action_ref_array( |
50 | - 'AHEE__loop-espresso_event_attendees__after', |
|
51 | - array( |
|
52 | - $contacts, |
|
53 | - $event, |
|
54 | - $datetime, |
|
55 | - $ticket, |
|
56 | - $show_gravatar, |
|
57 | - ) |
|
58 | - ); ?> |
|
50 | + 'AHEE__loop-espresso_event_attendees__after', |
|
51 | + array( |
|
52 | + $contacts, |
|
53 | + $event, |
|
54 | + $datetime, |
|
55 | + $ticket, |
|
56 | + $show_gravatar, |
|
57 | + ) |
|
58 | + ); ?> |
|
59 | 59 | </div> |
60 | 60 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @type bool $show_gravatar whether to show gravatar or not. |
16 | 16 | */ |
17 | 17 | |
18 | -$no_attendees_message = apply_filters( 'FHEE__loop-espresso_attendees-shortcode__template__no_attendees_message', __('No Attendees Yet', 'event_espresso' ) ); |
|
18 | +$no_attendees_message = apply_filters('FHEE__loop-espresso_attendees-shortcode__template__no_attendees_message', __('No Attendees Yet', 'event_espresso')); |
|
19 | 19 | |
20 | 20 | |
21 | 21 | ?> |
@@ -31,16 +31,16 @@ discard block |
||
31 | 31 | $show_gravatar, |
32 | 32 | ) |
33 | 33 | ); ?> |
34 | - <?php if ( $contacts ) : ?> |
|
34 | + <?php if ($contacts) : ?> |
|
35 | 35 | <ul class="event-attendees-list"> |
36 | - <?php foreach( $contacts as $contact ) : |
|
37 | - EEH_Template::get_template_part( 'content', 'espresso_event_attendees', array( |
|
36 | + <?php foreach ($contacts as $contact) : |
|
37 | + EEH_Template::get_template_part('content', 'espresso_event_attendees', array( |
|
38 | 38 | 'contact' => $contact, |
39 | 39 | 'event' => $event, |
40 | 40 | 'datetime' => $datetime, |
41 | 41 | 'ticket' => $ticket, |
42 | 42 | 'show_gravatar' => $show_gravatar |
43 | - ) ); |
|
43 | + )); |
|
44 | 44 | endforeach; ?> |
45 | 45 | </ul> |
46 | 46 | <?php else : ?> |
@@ -43,8 +43,11 @@ |
||
43 | 43 | ) ); |
44 | 44 | endforeach; ?> |
45 | 45 | </ul> |
46 | - <?php else : ?> |
|
47 | - <p><?php echo $no_attendees_message; ?></p> |
|
46 | + <?php else { |
|
47 | + : ?> |
|
48 | + <p><?php echo $no_attendees_message; |
|
49 | +} |
|
50 | +?></p> |
|
48 | 51 | <?php endif; ?> |
49 | 52 | <?php do_action_ref_array( |
50 | 53 | 'AHEE__loop-espresso_event_attendees__after', |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @param EE_Ticket $ticket |
311 | 311 | * @param int $quantity |
312 | - * @return bool |
|
312 | + * @return integer |
|
313 | 313 | * @throws EE_Error |
314 | 314 | */ |
315 | 315 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | /** |
327 | 327 | * @param EE_Ticket $ticket |
328 | 328 | * @param int $quantity |
329 | - * @return bool |
|
329 | + * @return integer |
|
330 | 330 | * @throws EE_Error |
331 | 331 | */ |
332 | 332 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
4 | 4 | |
5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | 6 | exit('No direct script access allowed'); |
7 | 7 | } |
8 | 8 | |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | class EED_Ticket_Sales_Monitor extends EED_Module |
23 | 23 | { |
24 | 24 | |
25 | - const debug = false; // true false |
|
25 | + const debug = false; // true false |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * an array of raw ticket data from EED_Ticket_Selector |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | /** @var EE_Line_Item $total_line_item */ |
200 | 200 | $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
201 | 201 | foreach ($ticket_line_items as $ticket_line_item) { |
202 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
202 | + if ( ! $ticket_line_item instanceof EE_Line_Item) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | if ($total_line_item->timestamp(true) <= $expired) { |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | } |
210 | 210 | } |
211 | 211 | } |
212 | - if (! empty($expired_ticket_IDs)) { |
|
212 | + if ( ! empty($expired_ticket_IDs)) { |
|
213 | 213 | EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
214 | 214 | \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
215 | 215 | $valid_ticket_line_items |
@@ -245,8 +245,8 @@ discard block |
||
245 | 245 | $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
246 | 246 | } |
247 | 247 | if (self::debug) { |
248 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
249 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
248 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'()'; |
|
249 | + echo '<br /><br /><b> RETURNED QTY: '.$qty.'</b>'; |
|
250 | 250 | } |
251 | 251 | return $qty; |
252 | 252 | } |
@@ -265,36 +265,36 @@ discard block |
||
265 | 265 | protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
266 | 266 | { |
267 | 267 | if (self::debug) { |
268 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
268 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
269 | 269 | } |
270 | - if (! $ticket instanceof EE_Ticket) { |
|
270 | + if ( ! $ticket instanceof EE_Ticket) { |
|
271 | 271 | return 0; |
272 | 272 | } |
273 | 273 | if (self::debug) { |
274 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
275 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
274 | + echo '<br /><b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
275 | + echo '<br /> . original ticket->reserved: '.$ticket->reserved(); |
|
276 | 276 | } |
277 | 277 | $ticket->refresh_from_db(); |
278 | 278 | // first let's determine the ticket availability based on sales |
279 | 279 | $available = $ticket->qty('saleable'); |
280 | 280 | if (self::debug) { |
281 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
282 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
283 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
284 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
285 | - echo '<br /> . . . available: ' . $available; |
|
281 | + echo '<br /> . . . ticket->qty: '.$ticket->qty(); |
|
282 | + echo '<br /> . . . ticket->sold: '.$ticket->sold(); |
|
283 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
284 | + echo '<br /> . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
285 | + echo '<br /> . . . available: '.$available; |
|
286 | 286 | } |
287 | 287 | if ($available < 1) { |
288 | 288 | $this->_ticket_sold_out($ticket); |
289 | 289 | return 0; |
290 | 290 | } |
291 | 291 | if (self::debug) { |
292 | - echo '<br /> . . . qty: ' . $qty; |
|
292 | + echo '<br /> . . . qty: '.$qty; |
|
293 | 293 | } |
294 | 294 | if ($available < $qty) { |
295 | 295 | $qty = $available; |
296 | 296 | if (self::debug) { |
297 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
297 | + echo '<br /> . . . QTY ADJUSTED: '.$qty; |
|
298 | 298 | } |
299 | 299 | $this->_ticket_quantity_decremented($ticket); |
300 | 300 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
316 | 316 | { |
317 | 317 | if (self::debug) { |
318 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
318 | + echo '<br /><br /> . . . INCREASE RESERVED: '.$quantity; |
|
319 | 319 | } |
320 | 320 | $ticket->increase_reserved($quantity); |
321 | 321 | return $ticket->save(); |
@@ -332,12 +332,12 @@ discard block |
||
332 | 332 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
333 | 333 | { |
334 | 334 | if (self::debug) { |
335 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
336 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
335 | + echo '<br /> . . . ticket->ID: '.$ticket->ID(); |
|
336 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
337 | 337 | } |
338 | 338 | $ticket->decrease_reserved($quantity); |
339 | 339 | if (self::debug) { |
340 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
340 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
341 | 341 | } |
342 | 342 | return $ticket->save() ? 1 : 0; |
343 | 343 | } |
@@ -355,8 +355,8 @@ discard block |
||
355 | 355 | protected function _ticket_sold_out(EE_Ticket $ticket) |
356 | 356 | { |
357 | 357 | if (self::debug) { |
358 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
359 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
358 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
359 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
360 | 360 | } |
361 | 361 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
362 | 362 | } |
@@ -374,8 +374,8 @@ discard block |
||
374 | 374 | protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
375 | 375 | { |
376 | 376 | if (self::debug) { |
377 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
378 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
377 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
378 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
379 | 379 | } |
380 | 380 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
381 | 381 | } |
@@ -481,18 +481,18 @@ discard block |
||
481 | 481 | protected function _post_notices() |
482 | 482 | { |
483 | 483 | if (self::debug) { |
484 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
484 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
485 | 485 | } |
486 | 486 | $refresh_msg = ''; |
487 | 487 | $none_added_msg = ''; |
488 | 488 | if (defined('DOING_AJAX') && DOING_AJAX) { |
489 | - $refresh_msg = __( |
|
489 | + $refresh_msg = __( |
|
490 | 490 | 'Please refresh the page to view updated ticket quantities.', |
491 | 491 | 'event_espresso' |
492 | 492 | ); |
493 | 493 | $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
494 | 494 | } |
495 | - if (! empty($this->sold_out_tickets)) { |
|
495 | + if ( ! empty($this->sold_out_tickets)) { |
|
496 | 496 | EE_Error::add_attention( |
497 | 497 | sprintf( |
498 | 498 | apply_filters( |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | // and reset the cart |
516 | 516 | EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
517 | 517 | } |
518 | - if (! empty($this->decremented_tickets)) { |
|
518 | + if ( ! empty($this->decremented_tickets)) { |
|
519 | 519 | EE_Error::add_attention( |
520 | 520 | sprintf( |
521 | 521 | apply_filters( |
@@ -553,8 +553,8 @@ discard block |
||
553 | 553 | protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
554 | 554 | { |
555 | 555 | if (self::debug) { |
556 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
557 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
556 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
557 | + echo '<br /> . transaction->ID: '.$transaction->ID(); |
|
558 | 558 | } |
559 | 559 | // check if 'finalize_registration' step has been completed... |
560 | 560 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -566,13 +566,13 @@ discard block |
||
566 | 566 | __LINE__, |
567 | 567 | array('finalized' => $finalized), |
568 | 568 | false, |
569 | - 'EE_Transaction: ' . $transaction->ID() |
|
569 | + 'EE_Transaction: '.$transaction->ID() |
|
570 | 570 | ); |
571 | 571 | } |
572 | 572 | // how many tickets were released |
573 | 573 | $count = 0; |
574 | 574 | if (self::debug) { |
575 | - echo '<br /> . . . finalized: ' . $finalized; |
|
575 | + echo '<br /> . . . finalized: '.$finalized; |
|
576 | 576 | } |
577 | 577 | $release_tickets_with_TXN_status = array( |
578 | 578 | EEM_Transaction::failed_status_code, |
@@ -580,10 +580,10 @@ discard block |
||
580 | 580 | EEM_Transaction::incomplete_status_code, |
581 | 581 | ); |
582 | 582 | // if the session is getting cleared BEFORE the TXN has been finalized |
583 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
583 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
584 | 584 | // let's cancel any reserved tickets |
585 | 585 | $registrations = $transaction->registrations(); |
586 | - if (! empty($registrations)) { |
|
586 | + if ( ! empty($registrations)) { |
|
587 | 587 | foreach ($registrations as $registration) { |
588 | 588 | if ($registration instanceof EE_Registration) { |
589 | 589 | $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
@@ -611,10 +611,10 @@ discard block |
||
611 | 611 | ) { |
612 | 612 | $STS_ID = $transaction->status_ID(); |
613 | 613 | if (self::debug) { |
614 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
615 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
616 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
617 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
614 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
615 | + echo '<br /> . . registration->ID: '.$registration->ID(); |
|
616 | + echo '<br /> . . registration->status_ID: '.$registration->status_ID(); |
|
617 | + echo '<br /> . . transaction->status_ID(): '.$STS_ID; |
|
618 | 618 | } |
619 | 619 | if ( |
620 | 620 | // release Tickets for Failed Transactions and Abandoned Transactions |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | public static function session_cart_reset(EE_Session $session) |
655 | 655 | { |
656 | 656 | if (self::debug) { |
657 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
657 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
658 | 658 | } |
659 | 659 | $cart = $session->cart(); |
660 | 660 | if ($cart instanceof EE_Cart) { |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | protected function _session_cart_reset(EE_Cart $cart) |
687 | 687 | { |
688 | 688 | if (self::debug) { |
689 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
689 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
690 | 690 | } |
691 | 691 | EE_Registry::instance()->load_helper('Line_Item'); |
692 | 692 | $ticket_line_items = $cart->get_tickets(); |
@@ -695,17 +695,17 @@ discard block |
||
695 | 695 | } |
696 | 696 | foreach ($ticket_line_items as $ticket_line_item) { |
697 | 697 | if (self::debug) { |
698 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
698 | + echo '<br /> . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
699 | 699 | } |
700 | 700 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
701 | 701 | if (self::debug) { |
702 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
702 | + echo '<br /> . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
703 | 703 | } |
704 | 704 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
705 | 705 | if ($ticket instanceof EE_Ticket) { |
706 | 706 | if (self::debug) { |
707 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
708 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
707 | + echo '<br /> . . ticket->ID(): '.$ticket->ID(); |
|
708 | + echo '<br /> . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
709 | 709 | } |
710 | 710 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
711 | 711 | } |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | protected function _session_checkout_reset(EE_Checkout $checkout) |
752 | 752 | { |
753 | 753 | if (self::debug) { |
754 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
754 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
755 | 755 | } |
756 | 756 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
757 | 757 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -801,7 +801,7 @@ discard block |
||
801 | 801 | __LINE__, |
802 | 802 | array($transaction), |
803 | 803 | false, |
804 | - 'EE_Transaction: ' . $transaction->ID() |
|
804 | + 'EE_Transaction: '.$transaction->ID() |
|
805 | 805 | ); |
806 | 806 | } |
807 | 807 | return; |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | __LINE__, |
819 | 819 | array($payment), |
820 | 820 | false, |
821 | - 'EE_Transaction: ' . $transaction->ID() |
|
821 | + 'EE_Transaction: '.$transaction->ID() |
|
822 | 822 | ); |
823 | 823 | } |
824 | 824 | return; |
@@ -874,7 +874,7 @@ discard block |
||
874 | 874 | /** @var EE_Transaction $transaction_in_progress */ |
875 | 875 | $total_line_item = $transaction_in_progress->total_line_item(); |
876 | 876 | // $transaction_in_progress->line |
877 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
877 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
878 | 878 | throw new DomainException( |
879 | 879 | esc_html__( |
880 | 880 | 'Transaction does not have a valid Total Line Item associated with it.', |
@@ -931,7 +931,7 @@ discard block |
||
931 | 931 | ) { |
932 | 932 | $total_tickets_released = 0; |
933 | 933 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
934 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
934 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
935 | 935 | continue; |
936 | 936 | } |
937 | 937 | $reserved_qty = $ticket_with_reservations->reserved(); |
@@ -971,7 +971,7 @@ discard block |
||
971 | 971 | global $wpdb; |
972 | 972 | return $wpdb->query( |
973 | 973 | $wpdb->prepare( |
974 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
974 | + 'DELETE FROM '.EEM_Line_Item::instance()->table().' |
|
975 | 975 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
976 | 976 | // use GMT time because that's what LIN_timestamps are in |
977 | 977 | date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
4 | 4 | |
5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -22,962 +22,962 @@ discard block |
||
22 | 22 | class EED_Ticket_Sales_Monitor extends EED_Module |
23 | 23 | { |
24 | 24 | |
25 | - const debug = false; // true false |
|
26 | - |
|
27 | - /** |
|
28 | - * an array of raw ticket data from EED_Ticket_Selector |
|
29 | - * |
|
30 | - * @var array $ticket_selections |
|
31 | - */ |
|
32 | - protected $ticket_selections = array(); |
|
33 | - |
|
34 | - /** |
|
35 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
36 | - * according to how they are displayed in the actual Ticket_Selector |
|
37 | - * this tracks the current row being processed |
|
38 | - * |
|
39 | - * @var int $current_row |
|
40 | - */ |
|
41 | - protected $current_row = 0; |
|
42 | - |
|
43 | - /** |
|
44 | - * an array for tracking names of tickets that have sold out |
|
45 | - * |
|
46 | - * @var array $sold_out_tickets |
|
47 | - */ |
|
48 | - protected $sold_out_tickets = array(); |
|
49 | - |
|
50 | - /** |
|
51 | - * an array for tracking names of tickets that have had their quantities reduced |
|
52 | - * |
|
53 | - * @var array $decremented_tickets |
|
54 | - */ |
|
55 | - protected $decremented_tickets = array(); |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public static function set_hooks() |
|
65 | - { |
|
66 | - // release tickets for expired carts |
|
67 | - add_action( |
|
68 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
69 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
70 | - 1 |
|
71 | - ); |
|
72 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
73 | - add_filter( |
|
74 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
75 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
76 | - 20, |
|
77 | - 3 |
|
78 | - ); |
|
79 | - // add notices for sold out tickets |
|
80 | - add_action( |
|
81 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
82 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
83 | - 10 |
|
84 | - ); |
|
85 | - // handle ticket quantities adjusted in cart |
|
86 | - //add_action( |
|
87 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
88 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
89 | - // 10, 2 |
|
90 | - //); |
|
91 | - // handle tickets deleted from cart |
|
92 | - add_action( |
|
93 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
94 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
95 | - 10, |
|
96 | - 2 |
|
97 | - ); |
|
98 | - // handle emptied carts |
|
99 | - add_action( |
|
100 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
101 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
102 | - 10, |
|
103 | - 1 |
|
104 | - ); |
|
105 | - add_action( |
|
106 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
107 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
108 | - 10, |
|
109 | - 1 |
|
110 | - ); |
|
111 | - // handle cancelled registrations |
|
112 | - add_action( |
|
113 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
114 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
115 | - 10, |
|
116 | - 1 |
|
117 | - ); |
|
118 | - // cron tasks |
|
119 | - add_action( |
|
120 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
121 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
122 | - 10, |
|
123 | - 1 |
|
124 | - ); |
|
125 | - add_action( |
|
126 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
127 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
128 | - 10, |
|
129 | - 1 |
|
130 | - ); |
|
131 | - add_action( |
|
132 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
133 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
134 | - 10, |
|
135 | - 1 |
|
136 | - ); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
143 | - * |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public static function set_hooks_admin() |
|
147 | - { |
|
148 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
155 | - */ |
|
156 | - public static function instance() |
|
157 | - { |
|
158 | - return parent::get_instance(__CLASS__); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param WP_Query $WP_Query |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public function run($WP_Query) |
|
168 | - { |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Retrieves grand totals from the line items that have no TXN ID |
|
179 | - * and timestamps less than the current time minus the session lifespan. |
|
180 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
181 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
182 | - * |
|
183 | - * @return void |
|
184 | - * @throws EE_Error |
|
185 | - * @throws InvalidArgumentException |
|
186 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
187 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
188 | - */ |
|
189 | - public static function release_tickets_for_expired_carts() |
|
190 | - { |
|
191 | - $expired_ticket_IDs = array(); |
|
192 | - $valid_ticket_line_items = array(); |
|
193 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
194 | - if (empty($total_line_items)) { |
|
195 | - return; |
|
196 | - } |
|
197 | - $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
198 | - foreach ($total_line_items as $total_line_item) { |
|
199 | - /** @var EE_Line_Item $total_line_item */ |
|
200 | - $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
201 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
202 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
203 | - continue; |
|
204 | - } |
|
205 | - if ($total_line_item->timestamp(true) <= $expired) { |
|
206 | - $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
207 | - } else { |
|
208 | - $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - if (! empty($expired_ticket_IDs)) { |
|
213 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
214 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
215 | - $valid_ticket_line_items |
|
216 | - ); |
|
217 | - // let's get rid of expired line items so that they can't interfere with tracking |
|
218 | - add_action( |
|
219 | - 'shutdown', |
|
220 | - array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
221 | - 999 |
|
222 | - ); |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - |
|
228 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
229 | - |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
234 | - * |
|
235 | - * @param int $qty |
|
236 | - * @param EE_Ticket $ticket |
|
237 | - * @return bool |
|
238 | - * @throws UnexpectedEntityException |
|
239 | - * @throws EE_Error |
|
240 | - */ |
|
241 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
242 | - { |
|
243 | - $qty = absint($qty); |
|
244 | - if ($qty > 0) { |
|
245 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
246 | - } |
|
247 | - if (self::debug) { |
|
248 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
249 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
250 | - } |
|
251 | - return $qty; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
258 | - * |
|
259 | - * @param EE_Ticket $ticket |
|
260 | - * @param int $qty |
|
261 | - * @return int |
|
262 | - * @throws UnexpectedEntityException |
|
263 | - * @throws EE_Error |
|
264 | - */ |
|
265 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
266 | - { |
|
267 | - if (self::debug) { |
|
268 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
269 | - } |
|
270 | - if (! $ticket instanceof EE_Ticket) { |
|
271 | - return 0; |
|
272 | - } |
|
273 | - if (self::debug) { |
|
274 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
275 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
276 | - } |
|
277 | - $ticket->refresh_from_db(); |
|
278 | - // first let's determine the ticket availability based on sales |
|
279 | - $available = $ticket->qty('saleable'); |
|
280 | - if (self::debug) { |
|
281 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
282 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
283 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
284 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
285 | - echo '<br /> . . . available: ' . $available; |
|
286 | - } |
|
287 | - if ($available < 1) { |
|
288 | - $this->_ticket_sold_out($ticket); |
|
289 | - return 0; |
|
290 | - } |
|
291 | - if (self::debug) { |
|
292 | - echo '<br /> . . . qty: ' . $qty; |
|
293 | - } |
|
294 | - if ($available < $qty) { |
|
295 | - $qty = $available; |
|
296 | - if (self::debug) { |
|
297 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
298 | - } |
|
299 | - $this->_ticket_quantity_decremented($ticket); |
|
300 | - } |
|
301 | - $this->_reserve_ticket($ticket, $qty); |
|
302 | - return $qty; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * increments ticket reserved based on quantity passed |
|
309 | - * |
|
310 | - * @param EE_Ticket $ticket |
|
311 | - * @param int $quantity |
|
312 | - * @return bool |
|
313 | - * @throws EE_Error |
|
314 | - */ |
|
315 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
316 | - { |
|
317 | - if (self::debug) { |
|
318 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
319 | - } |
|
320 | - $ticket->increase_reserved($quantity); |
|
321 | - return $ticket->save(); |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @param EE_Ticket $ticket |
|
328 | - * @param int $quantity |
|
329 | - * @return bool |
|
330 | - * @throws EE_Error |
|
331 | - */ |
|
332 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
333 | - { |
|
334 | - if (self::debug) { |
|
335 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
336 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
337 | - } |
|
338 | - $ticket->decrease_reserved($quantity); |
|
339 | - if (self::debug) { |
|
340 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
341 | - } |
|
342 | - return $ticket->save() ? 1 : 0; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * removes quantities within the ticket selector based on zero ticket availability |
|
349 | - * |
|
350 | - * @param EE_Ticket $ticket |
|
351 | - * @return void |
|
352 | - * @throws UnexpectedEntityException |
|
353 | - * @throws EE_Error |
|
354 | - */ |
|
355 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
356 | - { |
|
357 | - if (self::debug) { |
|
358 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
359 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
360 | - } |
|
361 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
368 | - * |
|
369 | - * @param EE_Ticket $ticket |
|
370 | - * @return void |
|
371 | - * @throws UnexpectedEntityException |
|
372 | - * @throws EE_Error |
|
373 | - */ |
|
374 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
375 | - { |
|
376 | - if (self::debug) { |
|
377 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
378 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
379 | - } |
|
380 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * builds string out of ticket and event name |
|
387 | - * |
|
388 | - * @param EE_Ticket $ticket |
|
389 | - * @return string |
|
390 | - * @throws UnexpectedEntityException |
|
391 | - * @throws EE_Error |
|
392 | - */ |
|
393 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
394 | - { |
|
395 | - $event = $ticket->get_related_event(); |
|
396 | - if ($event instanceof EE_Event) { |
|
397 | - $ticket_name = sprintf( |
|
398 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
399 | - $ticket->name(), |
|
400 | - $event->name() |
|
401 | - ); |
|
402 | - } else { |
|
403 | - $ticket_name = $ticket->name(); |
|
404 | - } |
|
405 | - return $ticket_name; |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - |
|
410 | - /********************************** EVENT CART **********************************/ |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * releases or reserves ticket(s) based on quantity passed |
|
416 | - * |
|
417 | - * @param EE_Line_Item $line_item |
|
418 | - * @param int $quantity |
|
419 | - * @return void |
|
420 | - * @throws EE_Error |
|
421 | - * @throws InvalidArgumentException |
|
422 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
423 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
424 | - */ |
|
425 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
426 | - { |
|
427 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
428 | - if ($ticket instanceof EE_Ticket) { |
|
429 | - if ($quantity > 0) { |
|
430 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
431 | - } else { |
|
432 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
433 | - } |
|
434 | - } |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * releases reserved ticket(s) based on quantity passed |
|
441 | - * |
|
442 | - * @param EE_Ticket $ticket |
|
443 | - * @param int $quantity |
|
444 | - * @return void |
|
445 | - * @throws EE_Error |
|
446 | - */ |
|
447 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
448 | - { |
|
449 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - |
|
454 | - /********************************** POST_NOTICES **********************************/ |
|
455 | - |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * @return void |
|
460 | - * @throws EE_Error |
|
461 | - * @throws InvalidArgumentException |
|
462 | - * @throws ReflectionException |
|
463 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
464 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
465 | - */ |
|
466 | - public static function post_notices() |
|
467 | - { |
|
468 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
469 | - } |
|
470 | - |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * @return void |
|
475 | - * @throws EE_Error |
|
476 | - * @throws InvalidArgumentException |
|
477 | - * @throws ReflectionException |
|
478 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
479 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
480 | - */ |
|
481 | - protected function _post_notices() |
|
482 | - { |
|
483 | - if (self::debug) { |
|
484 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
485 | - } |
|
486 | - $refresh_msg = ''; |
|
487 | - $none_added_msg = ''; |
|
488 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
489 | - $refresh_msg = __( |
|
490 | - 'Please refresh the page to view updated ticket quantities.', |
|
491 | - 'event_espresso' |
|
492 | - ); |
|
493 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
494 | - } |
|
495 | - if (! empty($this->sold_out_tickets)) { |
|
496 | - EE_Error::add_attention( |
|
497 | - sprintf( |
|
498 | - apply_filters( |
|
499 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
500 | - __( |
|
501 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
502 | - 'event_espresso' |
|
503 | - ) |
|
504 | - ), |
|
505 | - '<br />', |
|
506 | - implode('<br />', $this->sold_out_tickets), |
|
507 | - $none_added_msg, |
|
508 | - $refresh_msg |
|
509 | - ) |
|
510 | - ); |
|
511 | - // alter code flow in the Ticket Selector for better UX |
|
512 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
513 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
514 | - $this->sold_out_tickets = array(); |
|
515 | - // and reset the cart |
|
516 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
517 | - } |
|
518 | - if (! empty($this->decremented_tickets)) { |
|
519 | - EE_Error::add_attention( |
|
520 | - sprintf( |
|
521 | - apply_filters( |
|
522 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
523 | - __( |
|
524 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
525 | - 'event_espresso' |
|
526 | - ) |
|
527 | - ), |
|
528 | - '<br />', |
|
529 | - implode('<br />', $this->decremented_tickets), |
|
530 | - $none_added_msg, |
|
531 | - $refresh_msg |
|
532 | - ) |
|
533 | - ); |
|
534 | - $this->decremented_tickets = array(); |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - |
|
540 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
541 | - |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
546 | - * by default, will NOT release tickets for finalized transactions |
|
547 | - * |
|
548 | - * @param EE_Transaction $transaction |
|
549 | - * @return int |
|
550 | - * @throws EE_Error |
|
551 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
552 | - */ |
|
553 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
554 | - { |
|
555 | - if (self::debug) { |
|
556 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
557 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
558 | - } |
|
559 | - // check if 'finalize_registration' step has been completed... |
|
560 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
561 | - if (self::debug) { |
|
562 | - // DEBUG LOG |
|
563 | - EEH_Debug_Tools::log( |
|
564 | - __CLASS__, |
|
565 | - __FUNCTION__, |
|
566 | - __LINE__, |
|
567 | - array('finalized' => $finalized), |
|
568 | - false, |
|
569 | - 'EE_Transaction: ' . $transaction->ID() |
|
570 | - ); |
|
571 | - } |
|
572 | - // how many tickets were released |
|
573 | - $count = 0; |
|
574 | - if (self::debug) { |
|
575 | - echo '<br /> . . . finalized: ' . $finalized; |
|
576 | - } |
|
577 | - $release_tickets_with_TXN_status = array( |
|
578 | - EEM_Transaction::failed_status_code, |
|
579 | - EEM_Transaction::abandoned_status_code, |
|
580 | - EEM_Transaction::incomplete_status_code, |
|
581 | - ); |
|
582 | - // if the session is getting cleared BEFORE the TXN has been finalized |
|
583 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
584 | - // let's cancel any reserved tickets |
|
585 | - $registrations = $transaction->registrations(); |
|
586 | - if (! empty($registrations)) { |
|
587 | - foreach ($registrations as $registration) { |
|
588 | - if ($registration instanceof EE_Registration) { |
|
589 | - $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
590 | - } |
|
591 | - } |
|
592 | - } |
|
593 | - } |
|
594 | - return $count; |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * releases reserved tickets for an EE_Registration |
|
601 | - * by default, will NOT release tickets for APPROVED registrations |
|
602 | - * |
|
603 | - * @param EE_Registration $registration |
|
604 | - * @param EE_Transaction $transaction |
|
605 | - * @return int |
|
606 | - * @throws EE_Error |
|
607 | - */ |
|
608 | - protected function _release_reserved_ticket_for_registration( |
|
609 | - EE_Registration $registration, |
|
610 | - EE_Transaction $transaction |
|
611 | - ) { |
|
612 | - $STS_ID = $transaction->status_ID(); |
|
613 | - if (self::debug) { |
|
614 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
615 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
616 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
617 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
618 | - } |
|
619 | - if ( |
|
620 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
621 | - $STS_ID === EEM_Transaction::failed_status_code |
|
622 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
623 | - || ( |
|
624 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
625 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
626 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
627 | - ) |
|
628 | - ) { |
|
629 | - $ticket = $registration->ticket(); |
|
630 | - if ($ticket instanceof EE_Ticket) { |
|
631 | - return $this->_release_reserved_ticket($ticket); |
|
632 | - } |
|
633 | - } |
|
634 | - return 0; |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - |
|
639 | - /********************************** SESSION_CART_RESET **********************************/ |
|
640 | - |
|
641 | - |
|
642 | - |
|
643 | - /** |
|
644 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
645 | - * |
|
646 | - * @param EE_Session $session |
|
647 | - * @return void |
|
648 | - * @throws EE_Error |
|
649 | - * @throws InvalidArgumentException |
|
650 | - * @throws ReflectionException |
|
651 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
652 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
653 | - */ |
|
654 | - public static function session_cart_reset(EE_Session $session) |
|
655 | - { |
|
656 | - if (self::debug) { |
|
657 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
658 | - } |
|
659 | - $cart = $session->cart(); |
|
660 | - if ($cart instanceof EE_Cart) { |
|
661 | - if (self::debug) { |
|
662 | - echo '<br /><br /> cart instance of EE_Cart: '; |
|
663 | - } |
|
664 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
665 | - } else { |
|
666 | - if (self::debug) { |
|
667 | - echo '<br /><br /> invalid EE_Cart: '; |
|
668 | - var_export($cart, true); |
|
669 | - } |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * releases reserved tickets in the EE_Cart |
|
677 | - * |
|
678 | - * @param EE_Cart $cart |
|
679 | - * @return void |
|
680 | - * @throws EE_Error |
|
681 | - * @throws InvalidArgumentException |
|
682 | - * @throws ReflectionException |
|
683 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
684 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
685 | - */ |
|
686 | - protected function _session_cart_reset(EE_Cart $cart) |
|
687 | - { |
|
688 | - if (self::debug) { |
|
689 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
690 | - } |
|
691 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
692 | - $ticket_line_items = $cart->get_tickets(); |
|
693 | - if (empty($ticket_line_items)) { |
|
694 | - return; |
|
695 | - } |
|
696 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
697 | - if (self::debug) { |
|
698 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
699 | - } |
|
700 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
701 | - if (self::debug) { |
|
702 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
703 | - } |
|
704 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
705 | - if ($ticket instanceof EE_Ticket) { |
|
706 | - if (self::debug) { |
|
707 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
708 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
709 | - } |
|
710 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
711 | - } |
|
712 | - } |
|
713 | - } |
|
714 | - if (self::debug) { |
|
715 | - echo '<br /><br /> RESET COMPLETED '; |
|
716 | - } |
|
717 | - } |
|
718 | - |
|
719 | - |
|
720 | - |
|
721 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
722 | - |
|
723 | - |
|
724 | - |
|
725 | - /** |
|
726 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
727 | - * |
|
728 | - * @param EE_Session $session |
|
729 | - * @return void |
|
730 | - * @throws EE_Error |
|
731 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
732 | - */ |
|
733 | - public static function session_checkout_reset(EE_Session $session) |
|
734 | - { |
|
735 | - $checkout = $session->checkout(); |
|
736 | - if ($checkout instanceof EE_Checkout) { |
|
737 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
738 | - } |
|
739 | - } |
|
740 | - |
|
741 | - |
|
742 | - |
|
743 | - /** |
|
744 | - * releases reserved tickets for the EE_Checkout->transaction |
|
745 | - * |
|
746 | - * @param EE_Checkout $checkout |
|
747 | - * @return void |
|
748 | - * @throws EE_Error |
|
749 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
750 | - */ |
|
751 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
752 | - { |
|
753 | - if (self::debug) { |
|
754 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
755 | - } |
|
756 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
757 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
758 | - return; |
|
759 | - } |
|
760 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
761 | - } |
|
762 | - |
|
763 | - |
|
764 | - |
|
765 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
766 | - |
|
767 | - |
|
768 | - |
|
769 | - /** |
|
770 | - * @param EE_Session $session |
|
771 | - * @return void |
|
772 | - */ |
|
773 | - public static function session_expired_reset(EE_Session $session) |
|
774 | - { |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - |
|
779 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
780 | - |
|
781 | - |
|
782 | - |
|
783 | - /** |
|
784 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
785 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
786 | - * |
|
787 | - * @param EE_Transaction $transaction |
|
788 | - * @return void |
|
789 | - * @throws EE_Error |
|
790 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
791 | - */ |
|
792 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
793 | - { |
|
794 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
795 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
796 | - if (self::debug) { |
|
797 | - // DEBUG LOG |
|
798 | - EEH_Debug_Tools::log( |
|
799 | - __CLASS__, |
|
800 | - __FUNCTION__, |
|
801 | - __LINE__, |
|
802 | - array($transaction), |
|
803 | - false, |
|
804 | - 'EE_Transaction: ' . $transaction->ID() |
|
805 | - ); |
|
806 | - } |
|
807 | - return; |
|
808 | - } |
|
809 | - // have their been any successful payments made ? |
|
810 | - $payments = $transaction->payments(); |
|
811 | - foreach ($payments as $payment) { |
|
812 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
813 | - if (self::debug) { |
|
814 | - // DEBUG LOG |
|
815 | - EEH_Debug_Tools::log( |
|
816 | - __CLASS__, |
|
817 | - __FUNCTION__, |
|
818 | - __LINE__, |
|
819 | - array($payment), |
|
820 | - false, |
|
821 | - 'EE_Transaction: ' . $transaction->ID() |
|
822 | - ); |
|
823 | - } |
|
824 | - return; |
|
825 | - } |
|
826 | - } |
|
827 | - // since you haven't even attempted to pay for your ticket... |
|
828 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
829 | - } |
|
830 | - |
|
831 | - |
|
832 | - |
|
833 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
834 | - |
|
835 | - |
|
836 | - |
|
837 | - /** |
|
838 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
839 | - * |
|
840 | - * @param EE_Transaction $transaction |
|
841 | - * @return void |
|
842 | - * @throws EE_Error |
|
843 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
844 | - */ |
|
845 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
846 | - { |
|
847 | - // since you haven't even attempted to pay for your ticket... |
|
848 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
849 | - } |
|
850 | - |
|
851 | - |
|
852 | - |
|
853 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
854 | - /** |
|
855 | - * Resets all ticket and datetime reserved counts to zero |
|
856 | - * Tickets that are currently associated with a Transaction that is in progress |
|
857 | - * |
|
858 | - * @throws \EE_Error |
|
859 | - * @throws \DomainException |
|
860 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
861 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
862 | - * @throws \InvalidArgumentException |
|
863 | - */ |
|
864 | - public static function reset_reservation_counts() |
|
865 | - { |
|
866 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
867 | - $valid_reserved_tickets = array(); |
|
868 | - $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
869 | - foreach ($transactions_in_progress as $transaction_in_progress) { |
|
870 | - // if this TXN has been fully completed, then skip it |
|
871 | - if ($transaction_in_progress->reg_step_completed('finalize_registration')) { |
|
872 | - continue; |
|
873 | - } |
|
874 | - /** @var EE_Transaction $transaction_in_progress */ |
|
875 | - $total_line_item = $transaction_in_progress->total_line_item(); |
|
876 | - // $transaction_in_progress->line |
|
877 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
878 | - throw new DomainException( |
|
879 | - esc_html__( |
|
880 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
881 | - 'event_espresso' |
|
882 | - ) |
|
883 | - ); |
|
884 | - } |
|
885 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
886 | - $total_line_item |
|
887 | - ); |
|
888 | - } |
|
889 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
890 | - foreach ($total_line_items as $total_line_item) { |
|
891 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
892 | - $total_line_item |
|
893 | - ); |
|
894 | - } |
|
895 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
896 | - EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
897 | - $valid_reserved_tickets |
|
898 | - ); |
|
899 | - } |
|
900 | - |
|
901 | - |
|
902 | - |
|
903 | - /** |
|
904 | - * @param EE_Line_Item $total_line_item |
|
905 | - * @return EE_Line_Item[] |
|
906 | - */ |
|
907 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
908 | - { |
|
909 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
910 | - $valid_reserved_tickets = array(); |
|
911 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
912 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
913 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
914 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
915 | - } |
|
916 | - } |
|
917 | - return $valid_reserved_tickets; |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - |
|
922 | - /** |
|
923 | - * @param EE_Ticket[] $tickets_with_reservations |
|
924 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
925 | - * @return int |
|
926 | - * @throws \EE_Error |
|
927 | - */ |
|
928 | - private static function release_reservations_for_tickets( |
|
929 | - array $tickets_with_reservations, |
|
930 | - $valid_reserved_ticket_line_items = array() |
|
931 | - ) { |
|
932 | - $total_tickets_released = 0; |
|
933 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
934 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
935 | - continue; |
|
936 | - } |
|
937 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
938 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
939 | - if ( |
|
940 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
941 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
942 | - ) { |
|
943 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
944 | - } |
|
945 | - } |
|
946 | - if ($reserved_qty > 0) { |
|
947 | - $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
948 | - $ticket_with_reservations->save(); |
|
949 | - $total_tickets_released += $reserved_qty; |
|
950 | - } |
|
951 | - } |
|
952 | - return $total_tickets_released; |
|
953 | - } |
|
954 | - |
|
955 | - |
|
956 | - |
|
957 | - /********************************** SHUTDOWN **********************************/ |
|
958 | - |
|
959 | - |
|
960 | - |
|
961 | - /** |
|
962 | - * @return false|int |
|
963 | - * @throws EE_Error |
|
964 | - * @throws InvalidArgumentException |
|
965 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
966 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
967 | - */ |
|
968 | - public static function clear_expired_line_items_with_no_transaction() |
|
969 | - { |
|
970 | - /** @type WPDB $wpdb */ |
|
971 | - global $wpdb; |
|
972 | - return $wpdb->query( |
|
973 | - $wpdb->prepare( |
|
974 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
25 | + const debug = false; // true false |
|
26 | + |
|
27 | + /** |
|
28 | + * an array of raw ticket data from EED_Ticket_Selector |
|
29 | + * |
|
30 | + * @var array $ticket_selections |
|
31 | + */ |
|
32 | + protected $ticket_selections = array(); |
|
33 | + |
|
34 | + /** |
|
35 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
36 | + * according to how they are displayed in the actual Ticket_Selector |
|
37 | + * this tracks the current row being processed |
|
38 | + * |
|
39 | + * @var int $current_row |
|
40 | + */ |
|
41 | + protected $current_row = 0; |
|
42 | + |
|
43 | + /** |
|
44 | + * an array for tracking names of tickets that have sold out |
|
45 | + * |
|
46 | + * @var array $sold_out_tickets |
|
47 | + */ |
|
48 | + protected $sold_out_tickets = array(); |
|
49 | + |
|
50 | + /** |
|
51 | + * an array for tracking names of tickets that have had their quantities reduced |
|
52 | + * |
|
53 | + * @var array $decremented_tickets |
|
54 | + */ |
|
55 | + protected $decremented_tickets = array(); |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public static function set_hooks() |
|
65 | + { |
|
66 | + // release tickets for expired carts |
|
67 | + add_action( |
|
68 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
69 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
70 | + 1 |
|
71 | + ); |
|
72 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
73 | + add_filter( |
|
74 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
75 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
76 | + 20, |
|
77 | + 3 |
|
78 | + ); |
|
79 | + // add notices for sold out tickets |
|
80 | + add_action( |
|
81 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
82 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
83 | + 10 |
|
84 | + ); |
|
85 | + // handle ticket quantities adjusted in cart |
|
86 | + //add_action( |
|
87 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
88 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
89 | + // 10, 2 |
|
90 | + //); |
|
91 | + // handle tickets deleted from cart |
|
92 | + add_action( |
|
93 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
94 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
95 | + 10, |
|
96 | + 2 |
|
97 | + ); |
|
98 | + // handle emptied carts |
|
99 | + add_action( |
|
100 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
101 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
102 | + 10, |
|
103 | + 1 |
|
104 | + ); |
|
105 | + add_action( |
|
106 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
107 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
108 | + 10, |
|
109 | + 1 |
|
110 | + ); |
|
111 | + // handle cancelled registrations |
|
112 | + add_action( |
|
113 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
114 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
115 | + 10, |
|
116 | + 1 |
|
117 | + ); |
|
118 | + // cron tasks |
|
119 | + add_action( |
|
120 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
121 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
122 | + 10, |
|
123 | + 1 |
|
124 | + ); |
|
125 | + add_action( |
|
126 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
127 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
128 | + 10, |
|
129 | + 1 |
|
130 | + ); |
|
131 | + add_action( |
|
132 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
133 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
134 | + 10, |
|
135 | + 1 |
|
136 | + ); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
143 | + * |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public static function set_hooks_admin() |
|
147 | + { |
|
148 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
155 | + */ |
|
156 | + public static function instance() |
|
157 | + { |
|
158 | + return parent::get_instance(__CLASS__); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param WP_Query $WP_Query |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public function run($WP_Query) |
|
168 | + { |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Retrieves grand totals from the line items that have no TXN ID |
|
179 | + * and timestamps less than the current time minus the session lifespan. |
|
180 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
181 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
182 | + * |
|
183 | + * @return void |
|
184 | + * @throws EE_Error |
|
185 | + * @throws InvalidArgumentException |
|
186 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
187 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
188 | + */ |
|
189 | + public static function release_tickets_for_expired_carts() |
|
190 | + { |
|
191 | + $expired_ticket_IDs = array(); |
|
192 | + $valid_ticket_line_items = array(); |
|
193 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
194 | + if (empty($total_line_items)) { |
|
195 | + return; |
|
196 | + } |
|
197 | + $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
198 | + foreach ($total_line_items as $total_line_item) { |
|
199 | + /** @var EE_Line_Item $total_line_item */ |
|
200 | + $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
201 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
202 | + if (! $ticket_line_item instanceof EE_Line_Item) { |
|
203 | + continue; |
|
204 | + } |
|
205 | + if ($total_line_item->timestamp(true) <= $expired) { |
|
206 | + $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
207 | + } else { |
|
208 | + $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + if (! empty($expired_ticket_IDs)) { |
|
213 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
214 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
215 | + $valid_ticket_line_items |
|
216 | + ); |
|
217 | + // let's get rid of expired line items so that they can't interfere with tracking |
|
218 | + add_action( |
|
219 | + 'shutdown', |
|
220 | + array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
221 | + 999 |
|
222 | + ); |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + |
|
228 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
229 | + |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
234 | + * |
|
235 | + * @param int $qty |
|
236 | + * @param EE_Ticket $ticket |
|
237 | + * @return bool |
|
238 | + * @throws UnexpectedEntityException |
|
239 | + * @throws EE_Error |
|
240 | + */ |
|
241 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
242 | + { |
|
243 | + $qty = absint($qty); |
|
244 | + if ($qty > 0) { |
|
245 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
246 | + } |
|
247 | + if (self::debug) { |
|
248 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
249 | + echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
250 | + } |
|
251 | + return $qty; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
258 | + * |
|
259 | + * @param EE_Ticket $ticket |
|
260 | + * @param int $qty |
|
261 | + * @return int |
|
262 | + * @throws UnexpectedEntityException |
|
263 | + * @throws EE_Error |
|
264 | + */ |
|
265 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
266 | + { |
|
267 | + if (self::debug) { |
|
268 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
269 | + } |
|
270 | + if (! $ticket instanceof EE_Ticket) { |
|
271 | + return 0; |
|
272 | + } |
|
273 | + if (self::debug) { |
|
274 | + echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
275 | + echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
276 | + } |
|
277 | + $ticket->refresh_from_db(); |
|
278 | + // first let's determine the ticket availability based on sales |
|
279 | + $available = $ticket->qty('saleable'); |
|
280 | + if (self::debug) { |
|
281 | + echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
282 | + echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
283 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
284 | + echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
285 | + echo '<br /> . . . available: ' . $available; |
|
286 | + } |
|
287 | + if ($available < 1) { |
|
288 | + $this->_ticket_sold_out($ticket); |
|
289 | + return 0; |
|
290 | + } |
|
291 | + if (self::debug) { |
|
292 | + echo '<br /> . . . qty: ' . $qty; |
|
293 | + } |
|
294 | + if ($available < $qty) { |
|
295 | + $qty = $available; |
|
296 | + if (self::debug) { |
|
297 | + echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
298 | + } |
|
299 | + $this->_ticket_quantity_decremented($ticket); |
|
300 | + } |
|
301 | + $this->_reserve_ticket($ticket, $qty); |
|
302 | + return $qty; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * increments ticket reserved based on quantity passed |
|
309 | + * |
|
310 | + * @param EE_Ticket $ticket |
|
311 | + * @param int $quantity |
|
312 | + * @return bool |
|
313 | + * @throws EE_Error |
|
314 | + */ |
|
315 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
316 | + { |
|
317 | + if (self::debug) { |
|
318 | + echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
319 | + } |
|
320 | + $ticket->increase_reserved($quantity); |
|
321 | + return $ticket->save(); |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @param EE_Ticket $ticket |
|
328 | + * @param int $quantity |
|
329 | + * @return bool |
|
330 | + * @throws EE_Error |
|
331 | + */ |
|
332 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
333 | + { |
|
334 | + if (self::debug) { |
|
335 | + echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
336 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
337 | + } |
|
338 | + $ticket->decrease_reserved($quantity); |
|
339 | + if (self::debug) { |
|
340 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
341 | + } |
|
342 | + return $ticket->save() ? 1 : 0; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * removes quantities within the ticket selector based on zero ticket availability |
|
349 | + * |
|
350 | + * @param EE_Ticket $ticket |
|
351 | + * @return void |
|
352 | + * @throws UnexpectedEntityException |
|
353 | + * @throws EE_Error |
|
354 | + */ |
|
355 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
356 | + { |
|
357 | + if (self::debug) { |
|
358 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
359 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
360 | + } |
|
361 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
368 | + * |
|
369 | + * @param EE_Ticket $ticket |
|
370 | + * @return void |
|
371 | + * @throws UnexpectedEntityException |
|
372 | + * @throws EE_Error |
|
373 | + */ |
|
374 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
375 | + { |
|
376 | + if (self::debug) { |
|
377 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
378 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
379 | + } |
|
380 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * builds string out of ticket and event name |
|
387 | + * |
|
388 | + * @param EE_Ticket $ticket |
|
389 | + * @return string |
|
390 | + * @throws UnexpectedEntityException |
|
391 | + * @throws EE_Error |
|
392 | + */ |
|
393 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
394 | + { |
|
395 | + $event = $ticket->get_related_event(); |
|
396 | + if ($event instanceof EE_Event) { |
|
397 | + $ticket_name = sprintf( |
|
398 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
399 | + $ticket->name(), |
|
400 | + $event->name() |
|
401 | + ); |
|
402 | + } else { |
|
403 | + $ticket_name = $ticket->name(); |
|
404 | + } |
|
405 | + return $ticket_name; |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + |
|
410 | + /********************************** EVENT CART **********************************/ |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * releases or reserves ticket(s) based on quantity passed |
|
416 | + * |
|
417 | + * @param EE_Line_Item $line_item |
|
418 | + * @param int $quantity |
|
419 | + * @return void |
|
420 | + * @throws EE_Error |
|
421 | + * @throws InvalidArgumentException |
|
422 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
423 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
424 | + */ |
|
425 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
426 | + { |
|
427 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
428 | + if ($ticket instanceof EE_Ticket) { |
|
429 | + if ($quantity > 0) { |
|
430 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
431 | + } else { |
|
432 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
433 | + } |
|
434 | + } |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * releases reserved ticket(s) based on quantity passed |
|
441 | + * |
|
442 | + * @param EE_Ticket $ticket |
|
443 | + * @param int $quantity |
|
444 | + * @return void |
|
445 | + * @throws EE_Error |
|
446 | + */ |
|
447 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
448 | + { |
|
449 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + |
|
454 | + /********************************** POST_NOTICES **********************************/ |
|
455 | + |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * @return void |
|
460 | + * @throws EE_Error |
|
461 | + * @throws InvalidArgumentException |
|
462 | + * @throws ReflectionException |
|
463 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
464 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
465 | + */ |
|
466 | + public static function post_notices() |
|
467 | + { |
|
468 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
469 | + } |
|
470 | + |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * @return void |
|
475 | + * @throws EE_Error |
|
476 | + * @throws InvalidArgumentException |
|
477 | + * @throws ReflectionException |
|
478 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
479 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
480 | + */ |
|
481 | + protected function _post_notices() |
|
482 | + { |
|
483 | + if (self::debug) { |
|
484 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
485 | + } |
|
486 | + $refresh_msg = ''; |
|
487 | + $none_added_msg = ''; |
|
488 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
489 | + $refresh_msg = __( |
|
490 | + 'Please refresh the page to view updated ticket quantities.', |
|
491 | + 'event_espresso' |
|
492 | + ); |
|
493 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
494 | + } |
|
495 | + if (! empty($this->sold_out_tickets)) { |
|
496 | + EE_Error::add_attention( |
|
497 | + sprintf( |
|
498 | + apply_filters( |
|
499 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
500 | + __( |
|
501 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
502 | + 'event_espresso' |
|
503 | + ) |
|
504 | + ), |
|
505 | + '<br />', |
|
506 | + implode('<br />', $this->sold_out_tickets), |
|
507 | + $none_added_msg, |
|
508 | + $refresh_msg |
|
509 | + ) |
|
510 | + ); |
|
511 | + // alter code flow in the Ticket Selector for better UX |
|
512 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
513 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
514 | + $this->sold_out_tickets = array(); |
|
515 | + // and reset the cart |
|
516 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
517 | + } |
|
518 | + if (! empty($this->decremented_tickets)) { |
|
519 | + EE_Error::add_attention( |
|
520 | + sprintf( |
|
521 | + apply_filters( |
|
522 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
523 | + __( |
|
524 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
525 | + 'event_espresso' |
|
526 | + ) |
|
527 | + ), |
|
528 | + '<br />', |
|
529 | + implode('<br />', $this->decremented_tickets), |
|
530 | + $none_added_msg, |
|
531 | + $refresh_msg |
|
532 | + ) |
|
533 | + ); |
|
534 | + $this->decremented_tickets = array(); |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + |
|
540 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
541 | + |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
546 | + * by default, will NOT release tickets for finalized transactions |
|
547 | + * |
|
548 | + * @param EE_Transaction $transaction |
|
549 | + * @return int |
|
550 | + * @throws EE_Error |
|
551 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
552 | + */ |
|
553 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
554 | + { |
|
555 | + if (self::debug) { |
|
556 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
557 | + echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
558 | + } |
|
559 | + // check if 'finalize_registration' step has been completed... |
|
560 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
561 | + if (self::debug) { |
|
562 | + // DEBUG LOG |
|
563 | + EEH_Debug_Tools::log( |
|
564 | + __CLASS__, |
|
565 | + __FUNCTION__, |
|
566 | + __LINE__, |
|
567 | + array('finalized' => $finalized), |
|
568 | + false, |
|
569 | + 'EE_Transaction: ' . $transaction->ID() |
|
570 | + ); |
|
571 | + } |
|
572 | + // how many tickets were released |
|
573 | + $count = 0; |
|
574 | + if (self::debug) { |
|
575 | + echo '<br /> . . . finalized: ' . $finalized; |
|
576 | + } |
|
577 | + $release_tickets_with_TXN_status = array( |
|
578 | + EEM_Transaction::failed_status_code, |
|
579 | + EEM_Transaction::abandoned_status_code, |
|
580 | + EEM_Transaction::incomplete_status_code, |
|
581 | + ); |
|
582 | + // if the session is getting cleared BEFORE the TXN has been finalized |
|
583 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
584 | + // let's cancel any reserved tickets |
|
585 | + $registrations = $transaction->registrations(); |
|
586 | + if (! empty($registrations)) { |
|
587 | + foreach ($registrations as $registration) { |
|
588 | + if ($registration instanceof EE_Registration) { |
|
589 | + $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
590 | + } |
|
591 | + } |
|
592 | + } |
|
593 | + } |
|
594 | + return $count; |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * releases reserved tickets for an EE_Registration |
|
601 | + * by default, will NOT release tickets for APPROVED registrations |
|
602 | + * |
|
603 | + * @param EE_Registration $registration |
|
604 | + * @param EE_Transaction $transaction |
|
605 | + * @return int |
|
606 | + * @throws EE_Error |
|
607 | + */ |
|
608 | + protected function _release_reserved_ticket_for_registration( |
|
609 | + EE_Registration $registration, |
|
610 | + EE_Transaction $transaction |
|
611 | + ) { |
|
612 | + $STS_ID = $transaction->status_ID(); |
|
613 | + if (self::debug) { |
|
614 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
615 | + echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
616 | + echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
617 | + echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
618 | + } |
|
619 | + if ( |
|
620 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
621 | + $STS_ID === EEM_Transaction::failed_status_code |
|
622 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
623 | + || ( |
|
624 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
625 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
626 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
627 | + ) |
|
628 | + ) { |
|
629 | + $ticket = $registration->ticket(); |
|
630 | + if ($ticket instanceof EE_Ticket) { |
|
631 | + return $this->_release_reserved_ticket($ticket); |
|
632 | + } |
|
633 | + } |
|
634 | + return 0; |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + |
|
639 | + /********************************** SESSION_CART_RESET **********************************/ |
|
640 | + |
|
641 | + |
|
642 | + |
|
643 | + /** |
|
644 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
645 | + * |
|
646 | + * @param EE_Session $session |
|
647 | + * @return void |
|
648 | + * @throws EE_Error |
|
649 | + * @throws InvalidArgumentException |
|
650 | + * @throws ReflectionException |
|
651 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
652 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
653 | + */ |
|
654 | + public static function session_cart_reset(EE_Session $session) |
|
655 | + { |
|
656 | + if (self::debug) { |
|
657 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
658 | + } |
|
659 | + $cart = $session->cart(); |
|
660 | + if ($cart instanceof EE_Cart) { |
|
661 | + if (self::debug) { |
|
662 | + echo '<br /><br /> cart instance of EE_Cart: '; |
|
663 | + } |
|
664 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
665 | + } else { |
|
666 | + if (self::debug) { |
|
667 | + echo '<br /><br /> invalid EE_Cart: '; |
|
668 | + var_export($cart, true); |
|
669 | + } |
|
670 | + } |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * releases reserved tickets in the EE_Cart |
|
677 | + * |
|
678 | + * @param EE_Cart $cart |
|
679 | + * @return void |
|
680 | + * @throws EE_Error |
|
681 | + * @throws InvalidArgumentException |
|
682 | + * @throws ReflectionException |
|
683 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
684 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
685 | + */ |
|
686 | + protected function _session_cart_reset(EE_Cart $cart) |
|
687 | + { |
|
688 | + if (self::debug) { |
|
689 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
690 | + } |
|
691 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
692 | + $ticket_line_items = $cart->get_tickets(); |
|
693 | + if (empty($ticket_line_items)) { |
|
694 | + return; |
|
695 | + } |
|
696 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
697 | + if (self::debug) { |
|
698 | + echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
699 | + } |
|
700 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
701 | + if (self::debug) { |
|
702 | + echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
703 | + } |
|
704 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
705 | + if ($ticket instanceof EE_Ticket) { |
|
706 | + if (self::debug) { |
|
707 | + echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
708 | + echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
709 | + } |
|
710 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
711 | + } |
|
712 | + } |
|
713 | + } |
|
714 | + if (self::debug) { |
|
715 | + echo '<br /><br /> RESET COMPLETED '; |
|
716 | + } |
|
717 | + } |
|
718 | + |
|
719 | + |
|
720 | + |
|
721 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
722 | + |
|
723 | + |
|
724 | + |
|
725 | + /** |
|
726 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
727 | + * |
|
728 | + * @param EE_Session $session |
|
729 | + * @return void |
|
730 | + * @throws EE_Error |
|
731 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
732 | + */ |
|
733 | + public static function session_checkout_reset(EE_Session $session) |
|
734 | + { |
|
735 | + $checkout = $session->checkout(); |
|
736 | + if ($checkout instanceof EE_Checkout) { |
|
737 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
738 | + } |
|
739 | + } |
|
740 | + |
|
741 | + |
|
742 | + |
|
743 | + /** |
|
744 | + * releases reserved tickets for the EE_Checkout->transaction |
|
745 | + * |
|
746 | + * @param EE_Checkout $checkout |
|
747 | + * @return void |
|
748 | + * @throws EE_Error |
|
749 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
750 | + */ |
|
751 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
752 | + { |
|
753 | + if (self::debug) { |
|
754 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
755 | + } |
|
756 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
757 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
758 | + return; |
|
759 | + } |
|
760 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
761 | + } |
|
762 | + |
|
763 | + |
|
764 | + |
|
765 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
766 | + |
|
767 | + |
|
768 | + |
|
769 | + /** |
|
770 | + * @param EE_Session $session |
|
771 | + * @return void |
|
772 | + */ |
|
773 | + public static function session_expired_reset(EE_Session $session) |
|
774 | + { |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + |
|
779 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
780 | + |
|
781 | + |
|
782 | + |
|
783 | + /** |
|
784 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
785 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
786 | + * |
|
787 | + * @param EE_Transaction $transaction |
|
788 | + * @return void |
|
789 | + * @throws EE_Error |
|
790 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
791 | + */ |
|
792 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
793 | + { |
|
794 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
795 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
796 | + if (self::debug) { |
|
797 | + // DEBUG LOG |
|
798 | + EEH_Debug_Tools::log( |
|
799 | + __CLASS__, |
|
800 | + __FUNCTION__, |
|
801 | + __LINE__, |
|
802 | + array($transaction), |
|
803 | + false, |
|
804 | + 'EE_Transaction: ' . $transaction->ID() |
|
805 | + ); |
|
806 | + } |
|
807 | + return; |
|
808 | + } |
|
809 | + // have their been any successful payments made ? |
|
810 | + $payments = $transaction->payments(); |
|
811 | + foreach ($payments as $payment) { |
|
812 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
813 | + if (self::debug) { |
|
814 | + // DEBUG LOG |
|
815 | + EEH_Debug_Tools::log( |
|
816 | + __CLASS__, |
|
817 | + __FUNCTION__, |
|
818 | + __LINE__, |
|
819 | + array($payment), |
|
820 | + false, |
|
821 | + 'EE_Transaction: ' . $transaction->ID() |
|
822 | + ); |
|
823 | + } |
|
824 | + return; |
|
825 | + } |
|
826 | + } |
|
827 | + // since you haven't even attempted to pay for your ticket... |
|
828 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
829 | + } |
|
830 | + |
|
831 | + |
|
832 | + |
|
833 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
834 | + |
|
835 | + |
|
836 | + |
|
837 | + /** |
|
838 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
839 | + * |
|
840 | + * @param EE_Transaction $transaction |
|
841 | + * @return void |
|
842 | + * @throws EE_Error |
|
843 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
844 | + */ |
|
845 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
846 | + { |
|
847 | + // since you haven't even attempted to pay for your ticket... |
|
848 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
849 | + } |
|
850 | + |
|
851 | + |
|
852 | + |
|
853 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
854 | + /** |
|
855 | + * Resets all ticket and datetime reserved counts to zero |
|
856 | + * Tickets that are currently associated with a Transaction that is in progress |
|
857 | + * |
|
858 | + * @throws \EE_Error |
|
859 | + * @throws \DomainException |
|
860 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
861 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
862 | + * @throws \InvalidArgumentException |
|
863 | + */ |
|
864 | + public static function reset_reservation_counts() |
|
865 | + { |
|
866 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
867 | + $valid_reserved_tickets = array(); |
|
868 | + $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
869 | + foreach ($transactions_in_progress as $transaction_in_progress) { |
|
870 | + // if this TXN has been fully completed, then skip it |
|
871 | + if ($transaction_in_progress->reg_step_completed('finalize_registration')) { |
|
872 | + continue; |
|
873 | + } |
|
874 | + /** @var EE_Transaction $transaction_in_progress */ |
|
875 | + $total_line_item = $transaction_in_progress->total_line_item(); |
|
876 | + // $transaction_in_progress->line |
|
877 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
878 | + throw new DomainException( |
|
879 | + esc_html__( |
|
880 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
881 | + 'event_espresso' |
|
882 | + ) |
|
883 | + ); |
|
884 | + } |
|
885 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
886 | + $total_line_item |
|
887 | + ); |
|
888 | + } |
|
889 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
890 | + foreach ($total_line_items as $total_line_item) { |
|
891 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
892 | + $total_line_item |
|
893 | + ); |
|
894 | + } |
|
895 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
896 | + EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
897 | + $valid_reserved_tickets |
|
898 | + ); |
|
899 | + } |
|
900 | + |
|
901 | + |
|
902 | + |
|
903 | + /** |
|
904 | + * @param EE_Line_Item $total_line_item |
|
905 | + * @return EE_Line_Item[] |
|
906 | + */ |
|
907 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
908 | + { |
|
909 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
910 | + $valid_reserved_tickets = array(); |
|
911 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
912 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
913 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
914 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
915 | + } |
|
916 | + } |
|
917 | + return $valid_reserved_tickets; |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + |
|
922 | + /** |
|
923 | + * @param EE_Ticket[] $tickets_with_reservations |
|
924 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
925 | + * @return int |
|
926 | + * @throws \EE_Error |
|
927 | + */ |
|
928 | + private static function release_reservations_for_tickets( |
|
929 | + array $tickets_with_reservations, |
|
930 | + $valid_reserved_ticket_line_items = array() |
|
931 | + ) { |
|
932 | + $total_tickets_released = 0; |
|
933 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
934 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
935 | + continue; |
|
936 | + } |
|
937 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
938 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
939 | + if ( |
|
940 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
941 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
942 | + ) { |
|
943 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
944 | + } |
|
945 | + } |
|
946 | + if ($reserved_qty > 0) { |
|
947 | + $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
948 | + $ticket_with_reservations->save(); |
|
949 | + $total_tickets_released += $reserved_qty; |
|
950 | + } |
|
951 | + } |
|
952 | + return $total_tickets_released; |
|
953 | + } |
|
954 | + |
|
955 | + |
|
956 | + |
|
957 | + /********************************** SHUTDOWN **********************************/ |
|
958 | + |
|
959 | + |
|
960 | + |
|
961 | + /** |
|
962 | + * @return false|int |
|
963 | + * @throws EE_Error |
|
964 | + * @throws InvalidArgumentException |
|
965 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
966 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
967 | + */ |
|
968 | + public static function clear_expired_line_items_with_no_transaction() |
|
969 | + { |
|
970 | + /** @type WPDB $wpdb */ |
|
971 | + global $wpdb; |
|
972 | + return $wpdb->query( |
|
973 | + $wpdb->prepare( |
|
974 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
975 | 975 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
976 | - // use GMT time because that's what LIN_timestamps are in |
|
977 | - date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
978 | - ) |
|
979 | - ); |
|
980 | - } |
|
976 | + // use GMT time because that's what LIN_timestamps are in |
|
977 | + date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
978 | + ) |
|
979 | + ); |
|
980 | + } |
|
981 | 981 | |
982 | 982 | } |
983 | 983 | // End of file EED_Ticket_Sales_Monitor.module.php |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | * @return string |
32 | 32 | */ |
33 | 33 | public static function get_column_name_for_field(EE_Model_Field_Base $field){ |
34 | - return wp_specialchars_decode($field->get_nicename(), ENT_QUOTES) |
|
35 | - . "[" . wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
36 | - . "]"; |
|
34 | + return wp_specialchars_decode($field->get_nicename(), ENT_QUOTES) |
|
35 | + . "[" . wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
36 | + . "]"; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | |
89 | 89 | /** |
90 | 90 | * |
91 | - * Writes a row to the csv file |
|
92 | - * @param array $row - individual row of csv data |
|
93 | - * @param string $delimiter - csv delimiter |
|
94 | - * @param string $enclosure - csv enclosure |
|
95 | - * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
96 | - * @return string of text for teh csv file |
|
97 | - */ |
|
91 | + * Writes a row to the csv file |
|
92 | + * @param array $row - individual row of csv data |
|
93 | + * @param string $delimiter - csv delimiter |
|
94 | + * @param string $enclosure - csv enclosure |
|
95 | + * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
96 | + * @return string of text for teh csv file |
|
97 | + */ |
|
98 | 98 | public static function get_csv_row ( array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false ) { |
99 | 99 | //Allow user to filter the csv delimiter and enclosure for other countries csv standards |
100 | 100 | $delimiter = apply_filters( 'FHEE__EE_CSV__fputcsv2__delimiter', $delimiter ); |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * @param EE_Model_Field_Base $field |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - public static function get_column_name_for_field(EE_Model_Field_Base $field){ |
|
33 | + public static function get_column_name_for_field(EE_Model_Field_Base $field) { |
|
34 | 34 | return wp_specialchars_decode($field->get_nicename(), ENT_QUOTES) |
35 | - . "[" . wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
35 | + . "[".wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
36 | 36 | . "]"; |
37 | 37 | } |
38 | 38 | |
@@ -54,31 +54,31 @@ discard block |
||
54 | 54 | * we consider that a success (because we wrote everything there was...nothing) |
55 | 55 | * @throws EE_Error |
56 | 56 | */ |
57 | - public static function write_data_array_to_csv( $filepath, $data, $write_column_headers = true ){ |
|
57 | + public static function write_data_array_to_csv($filepath, $data, $write_column_headers = true) { |
|
58 | 58 | |
59 | 59 | $new_file_contents = ''; |
60 | 60 | //determine if $data is actually a 2d array |
61 | - if ( $data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))){ |
|
61 | + if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
62 | 62 | //make sure top level is numerically indexed, |
63 | 63 | |
64 | - if( EEH_Array::is_associative_array($data)){ |
|
65 | - throw new EE_Error(sprintf(__("top-level array must be numerically indexed. Does these look like numbers to you? %s","event_espresso"),implode(",",array_keys($data)))); |
|
64 | + if (EEH_Array::is_associative_array($data)) { |
|
65 | + throw new EE_Error(sprintf(__("top-level array must be numerically indexed. Does these look like numbers to you? %s", "event_espresso"), implode(",", array_keys($data)))); |
|
66 | 66 | } |
67 | 67 | $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
68 | 68 | //now, is the last item in the top-level array of $data an associative or numeric array? |
69 | - if( $write_column_headers && |
|
70 | - EEH_Array::is_associative_array($item_in_top_level_array)){ |
|
69 | + if ($write_column_headers && |
|
70 | + EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
71 | 71 | //its associative, so we want to output its keys as column headers |
72 | 72 | $keys = array_keys($item_in_top_level_array); |
73 | - $new_file_contents .= EEH_Export::get_csv_row( $keys ); |
|
73 | + $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
74 | 74 | |
75 | 75 | } |
76 | 76 | //start writing data |
77 | - foreach($data as $data_row){ |
|
78 | - $new_file_contents .= EEH_Export::get_csv_row( $data_row); |
|
77 | + foreach ($data as $data_row) { |
|
78 | + $new_file_contents .= EEH_Export::get_csv_row($data_row); |
|
79 | 79 | } |
80 | - return EEH_File::write_to_file( $filepath, EEH_File::get_file_contents( $filepath ) . $new_file_contents ); |
|
81 | - }else{ |
|
80 | + return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath).$new_file_contents); |
|
81 | + } else { |
|
82 | 82 | //no data TO write... so we can assume that's a success |
83 | 83 | return true; |
84 | 84 | } |
@@ -95,29 +95,29 @@ discard block |
||
95 | 95 | * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
96 | 96 | * @return string of text for teh csv file |
97 | 97 | */ |
98 | - public static function get_csv_row ( array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false ) { |
|
98 | + public static function get_csv_row(array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false) { |
|
99 | 99 | //Allow user to filter the csv delimiter and enclosure for other countries csv standards |
100 | - $delimiter = apply_filters( 'FHEE__EE_CSV__fputcsv2__delimiter', $delimiter ); |
|
101 | - $enclosure = apply_filters( 'FHEE__EE_CSV__fputcsv2__enclosure', $enclosure ); |
|
100 | + $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
101 | + $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
102 | 102 | |
103 | 103 | $delimiter_esc = preg_quote($delimiter, '/'); |
104 | 104 | $enclosure_esc = preg_quote($enclosure, '/'); |
105 | 105 | |
106 | 106 | $output = array(); |
107 | 107 | foreach ($row as $field_value) { |
108 | - if(is_object($field_value) || is_array($field_value)){ |
|
108 | + if (is_object($field_value) || is_array($field_value)) { |
|
109 | 109 | $field_value = serialize($field_value); |
110 | 110 | } |
111 | - if ($field_value === null && $mysql_null ) { |
|
111 | + if ($field_value === null && $mysql_null) { |
|
112 | 112 | $output[] = 'NULL'; |
113 | 113 | continue; |
114 | 114 | } |
115 | 115 | |
116 | 116 | $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
117 | - ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; |
|
117 | + ($enclosure.str_replace($enclosure, $enclosure.$enclosure, $field_value).$enclosure) : $field_value; |
|
118 | 118 | } |
119 | 119 | |
120 | - return implode($delimiter, $output) . PHP_EOL; |
|
120 | + return implode($delimiter, $output).PHP_EOL; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty |
131 | 131 | * @return string |
132 | 132 | */ |
133 | - public static function prepare_value_from_db_for_display( $model, $field_name, $raw_db_value, $pretty_schema = true ) { |
|
134 | - $field_obj = $model->field_settings_for( $field_name ); |
|
135 | - $value_on_model_obj = $field_obj->prepare_for_set_from_db( $raw_db_value ); |
|
136 | - if( $field_obj instanceof EE_Datetime_Field ) { |
|
137 | - $field_obj->set_date_format( EEH_Export::get_date_format_for_export( $field_obj->get_date_format( $pretty_schema ) ), $pretty_schema ); |
|
138 | - $field_obj->set_time_format( EEH_Export::get_time_format_for_export( $field_obj->get_time_format( $pretty_schema ) ), $pretty_schema ); |
|
133 | + public static function prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) { |
|
134 | + $field_obj = $model->field_settings_for($field_name); |
|
135 | + $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
136 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
137 | + $field_obj->set_date_format(EEH_Export::get_date_format_for_export($field_obj->get_date_format($pretty_schema)), $pretty_schema); |
|
138 | + $field_obj->set_time_format(EEH_Export::get_time_format_for_export($field_obj->get_time_format($pretty_schema)), $pretty_schema); |
|
139 | 139 | } |
140 | - if( $pretty_schema === true){ |
|
141 | - return $field_obj->prepare_for_pretty_echoing( $value_on_model_obj ); |
|
142 | - }elseif( is_string( $pretty_schema ) ) { |
|
143 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema ); |
|
144 | - }else{ |
|
145 | - return $field_obj->prepare_for_get( $value_on_model_obj ); |
|
140 | + if ($pretty_schema === true) { |
|
141 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
142 | + }elseif (is_string($pretty_schema)) { |
|
143 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
144 | + } else { |
|
145 | + return $field_obj->prepare_for_get($value_on_model_obj); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | * @param string $current_format |
154 | 154 | * @return string |
155 | 155 | */ |
156 | - public static function get_date_format_for_export( $current_format = null ) { |
|
157 | - return apply_filters( 'FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format ); |
|
156 | + public static function get_date_format_for_export($current_format = null) { |
|
157 | + return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | * @param string $current_format |
165 | 165 | * @return string |
166 | 166 | */ |
167 | - public static function get_time_format_for_export( $current_format = null ) { |
|
168 | - return apply_filters( 'FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format ); |
|
167 | + public static function get_time_format_for_export($current_format = null) { |
|
168 | + return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 |