@@ -24,49 +24,49 @@ |
||
24 | 24 | class VsprintfFilter extends FormHtmlFilter |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var string $format |
|
29 | - */ |
|
30 | - protected $format = ''; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array $args |
|
35 | - */ |
|
36 | - protected $args = array(); |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * VsprintfFilter constructor. |
|
42 | - * |
|
43 | - * @param string $format |
|
44 | - * @param array $args |
|
45 | - */ |
|
46 | - public function __construct($format, array $args) |
|
47 | - { |
|
48 | - $this->format = $format; |
|
49 | - $this->args = $args; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param $html |
|
56 | - * @param EE_Form_Section_Validatable $form_section |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function filterHtml($html, EE_Form_Section_Validatable $form_section) |
|
60 | - { |
|
61 | - $this->args[] = $html; |
|
62 | - if ($form_section instanceof EE_Form_Section_Proper) { |
|
63 | - $subsections = $form_section->subsections(); |
|
64 | - foreach ((array)$subsections as $subsection) { |
|
65 | - $this->args[] = $subsection->get_html(); |
|
66 | - } |
|
67 | - } |
|
68 | - return vsprintf($this->format, $this->args); |
|
69 | - } |
|
27 | + /** |
|
28 | + * @var string $format |
|
29 | + */ |
|
30 | + protected $format = ''; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array $args |
|
35 | + */ |
|
36 | + protected $args = array(); |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * VsprintfFilter constructor. |
|
42 | + * |
|
43 | + * @param string $format |
|
44 | + * @param array $args |
|
45 | + */ |
|
46 | + public function __construct($format, array $args) |
|
47 | + { |
|
48 | + $this->format = $format; |
|
49 | + $this->args = $args; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param $html |
|
56 | + * @param EE_Form_Section_Validatable $form_section |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function filterHtml($html, EE_Form_Section_Validatable $form_section) |
|
60 | + { |
|
61 | + $this->args[] = $html; |
|
62 | + if ($form_section instanceof EE_Form_Section_Proper) { |
|
63 | + $subsections = $form_section->subsections(); |
|
64 | + foreach ((array)$subsections as $subsection) { |
|
65 | + $this->args[] = $subsection->get_html(); |
|
66 | + } |
|
67 | + } |
|
68 | + return vsprintf($this->format, $this->args); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | 72 |
@@ -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 | ); |
@@ -656,8 +656,8 @@ discard block |
||
656 | 656 | } |
657 | 657 | |
658 | 658 | //reset contexts and addressees |
659 | - $this->_contexts = $original_contexts; |
|
660 | - $this->_addressees = array(); |
|
659 | + $this->_contexts = $original_contexts; |
|
660 | + $this->_addressees = array(); |
|
661 | 661 | return $addressees; |
662 | 662 | } |
663 | 663 | |
@@ -874,8 +874,8 @@ discard block |
||
874 | 874 | //set the attendee array to blank on each loop; |
875 | 875 | $aee = array(); |
876 | 876 | if ( isset( $this->_data->reg_obj ) |
877 | - && ( $this->_data->reg_obj->attendee_ID() != $att_id ) |
|
878 | - && $this->_single_message |
|
877 | + && ( $this->_data->reg_obj->attendee_ID() != $att_id ) |
|
878 | + && $this->_single_message |
|
879 | 879 | ) { |
880 | 880 | continue; |
881 | 881 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'NO direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | * EE_Base_Class_Object |
280 | 280 | * @return mixed ( EE_Base_Class||EE_Base_Class[] ) |
281 | 281 | */ |
282 | - abstract protected function _get_data_for_context( $context, EE_Registration $registration, $id ); |
|
282 | + abstract protected function _get_data_for_context($context, EE_Registration $registration, $id); |
|
283 | 283 | |
284 | 284 | |
285 | 285 | |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * @deprecated 4.9.0 |
307 | 307 | * @return int |
308 | 308 | */ |
309 | - protected function _get_id_for_msg_url( $context, EE_Registration $registration ) { |
|
309 | + protected function _get_id_for_msg_url($context, EE_Registration $registration) { |
|
310 | 310 | return 0; |
311 | 311 | } |
312 | 312 | |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * sending. |
336 | 336 | * @since 4.9.0 |
337 | 337 | */ |
338 | - public function do_messenger_hooks( $messenger = null ) { |
|
338 | + public function do_messenger_hooks($messenger = null) { |
|
339 | 339 | $this->_active_messenger = $messenger; |
340 | 340 | $this->_do_messenger_hooks(); |
341 | 341 | } |
@@ -384,10 +384,10 @@ discard block |
||
384 | 384 | * @param mixed $data This sets the data property for the message type with the incoming data used for generating. |
385 | 385 | * @return string (the reference for the data handler) (will be an empty string if could not be determined). |
386 | 386 | */ |
387 | - public function get_data_handler( $data ) { |
|
387 | + public function get_data_handler($data) { |
|
388 | 388 | $this->_data = $data; |
389 | 389 | $this->_set_data_handler(); |
390 | - return apply_filters( 'FHEE__EE_message_type__get_data_handler', $this->_data_handler, $this ); |
|
390 | + return apply_filters('FHEE__EE_message_type__get_data_handler', $this->_data_handler, $this); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | |
@@ -424,26 +424,26 @@ discard block |
||
424 | 424 | * @deprecated 4.9.0 Likely 4.9.10 or 4.10.0 will remove this method completely |
425 | 425 | * @return string generated url |
426 | 426 | */ |
427 | - public function get_url_trigger( $context, $sending_messenger, EE_Registration $registration ) { |
|
427 | + public function get_url_trigger($context, $sending_messenger, EE_Registration $registration) { |
|
428 | 428 | //validate context |
429 | 429 | //valid context? |
430 | - if ( ! isset( $this->_contexts[ $context ] ) ) { |
|
430 | + if ( ! isset($this->_contexts[$context])) { |
|
431 | 431 | throw new EE_Error( |
432 | 432 | sprintf( |
433 | - __( 'The context %s is not a valid context for %s.', 'event_espresso' ), |
|
433 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
434 | 434 | $context, |
435 | - get_class( $this ) |
|
435 | + get_class($this) |
|
436 | 436 | ) |
437 | 437 | ); |
438 | 438 | } |
439 | 439 | //valid sending_messenger? |
440 | 440 | $not_valid_msgr = false; |
441 | - foreach ( $this->_with_messengers as $generating => $sendings ) { |
|
442 | - if ( empty( $sendings ) || array_search( $sending_messenger, $sendings ) === false ) { |
|
441 | + foreach ($this->_with_messengers as $generating => $sendings) { |
|
442 | + if (empty($sendings) || array_search($sending_messenger, $sendings) === false) { |
|
443 | 443 | $not_valid_msgr = true; |
444 | 444 | } |
445 | 445 | } |
446 | - if ( $not_valid_msgr ) { |
|
446 | + if ($not_valid_msgr) { |
|
447 | 447 | throw new EE_Error( |
448 | 448 | sprintf( |
449 | 449 | __( |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | 'event_espresso' |
452 | 452 | ), |
453 | 453 | $sending_messenger, |
454 | - get_class( $this ) |
|
454 | + get_class($this) |
|
455 | 455 | ) |
456 | 456 | ); |
457 | 457 | } |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | $this->name, |
463 | 463 | $registration, |
464 | 464 | $this->_GRP_ID, |
465 | - $this->_get_id_for_msg_url( $context, $registration ) |
|
465 | + $this->_get_id_for_msg_url($context, $registration) |
|
466 | 466 | ); |
467 | 467 | } |
468 | 468 | |
@@ -481,26 +481,26 @@ discard block |
||
481 | 481 | * EE_Base_Class_Object |
482 | 482 | * @return mixed (EE_Base_Class||EE_Base_Class[]) |
483 | 483 | */ |
484 | - public function get_data_for_context( $context, EE_Registration $registration, $id = 0 ) { |
|
484 | + public function get_data_for_context($context, EE_Registration $registration, $id = 0) { |
|
485 | 485 | //valid context? |
486 | - if ( ! isset( $this->_contexts[ $context ] ) ) { |
|
486 | + if ( ! isset($this->_contexts[$context])) { |
|
487 | 487 | throw new EE_Error( |
488 | 488 | sprintf( |
489 | - __( 'The context %s is not a valid context for %s.', 'event_espresso' ), |
|
489 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
490 | 490 | $context, |
491 | - get_class( $this ) |
|
491 | + get_class($this) |
|
492 | 492 | ) |
493 | 493 | ); |
494 | 494 | } |
495 | 495 | //get data and apply global and class specific filters on it. |
496 | 496 | $data = apply_filters( |
497 | 497 | 'FHEE__EE_message_type__get_data_for_context__data', |
498 | - $this->_get_data_for_context( $context, $registration, $id ), |
|
498 | + $this->_get_data_for_context($context, $registration, $id), |
|
499 | 499 | $this |
500 | 500 | ); |
501 | - $data = apply_filters( 'FHEE__' . get_class( $this ) . '__get_data_for_context__data', $data, $this ); |
|
501 | + $data = apply_filters('FHEE__'.get_class($this).'__get_data_for_context__data', $data, $this); |
|
502 | 502 | //if empty then something went wrong! |
503 | - if ( empty( $data ) ) { |
|
503 | + if (empty($data)) { |
|
504 | 504 | throw new EE_Error( |
505 | 505 | sprintf( |
506 | 506 | __( |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | */ |
545 | 545 | protected function _set_with_messengers() { |
546 | 546 | $this->_with_messengers = array( |
547 | - 'email' => array( 'html' ), |
|
547 | + 'email' => array('html'), |
|
548 | 548 | ); |
549 | 549 | } |
550 | 550 | |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | */ |
559 | 559 | public function with_messengers() { |
560 | 560 | return apply_filters( |
561 | - 'FHEE__EE_message_type__get_with_messengers__with_messengers__' . get_class( $this ), |
|
561 | + 'FHEE__EE_message_type__get_with_messengers__with_messengers__'.get_class($this), |
|
562 | 562 | $this->_with_messengers |
563 | 563 | ); |
564 | 564 | } |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | $messengers = array() |
586 | 586 | ) { |
587 | 587 | //we can also further refine the context by action (if present). |
588 | - return $this->_get_admin_page_content( $page, $action, $extra, $messengers ); |
|
588 | + return $this->_get_admin_page_content($page, $action, $extra, $messengers); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | |
@@ -620,10 +620,10 @@ discard block |
||
620 | 620 | public function get_master_templates() { |
621 | 621 | //first class specific filter then filter that by the global filter. |
622 | 622 | $master_templates = apply_filters( |
623 | - 'FHEE__' . get_class( $this ) . '__get_master_templates', |
|
623 | + 'FHEE__'.get_class($this).'__get_master_templates', |
|
624 | 624 | $this->_master_templates |
625 | 625 | ); |
626 | - return apply_filters( 'FHEE__EE_message_type__get_master_templates', $master_templates, $this ); |
|
626 | + return apply_filters('FHEE__EE_message_type__get_master_templates', $master_templates, $this); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | |
@@ -637,21 +637,21 @@ discard block |
||
637 | 637 | * @return array An array indexed by context where each context is an array of EE_Messages_Addressee objects for |
638 | 638 | * that context |
639 | 639 | */ |
640 | - public function get_addressees( EE_Messages_incoming_data $data, $context = '' ) { |
|
640 | + public function get_addressees(EE_Messages_incoming_data $data, $context = '') { |
|
641 | 641 | //override _data |
642 | 642 | $this->_data = $data; |
643 | 643 | $addressees = array(); |
644 | 644 | $original_contexts = $this->_contexts; |
645 | 645 | //if incoming context then limit to that context |
646 | - if ( ! empty( $context ) ) { |
|
647 | - $cntxt = ! empty( $this->_contexts[ $context ] ) ? $this->_contexts[ $context ] : ''; |
|
648 | - if ( ! empty( $cntxt ) ) { |
|
646 | + if ( ! empty($context)) { |
|
647 | + $cntxt = ! empty($this->_contexts[$context]) ? $this->_contexts[$context] : ''; |
|
648 | + if ( ! empty($cntxt)) { |
|
649 | 649 | $this->_contexts = array(); |
650 | - $this->_contexts[ $context ] = $cntxt; |
|
650 | + $this->_contexts[$context] = $cntxt; |
|
651 | 651 | } |
652 | 652 | } |
653 | 653 | $this->_set_default_addressee_data(); |
654 | - if ( $this->_process_data() ) { |
|
654 | + if ($this->_process_data()) { |
|
655 | 655 | $addressees = $this->_addressees; |
656 | 656 | } |
657 | 657 | |
@@ -671,14 +671,14 @@ discard block |
||
671 | 671 | */ |
672 | 672 | protected function _process_data() { |
673 | 673 | //at a minimum, we NEED EE_Attendee objects. |
674 | - if ( empty( $this->_data->attendees ) ) { |
|
675 | - return false; //there's no data to process! |
|
674 | + if (empty($this->_data->attendees)) { |
|
675 | + return false; //there's no data to process! |
|
676 | 676 | } |
677 | 677 | // process addressees for each context. Child classes will have to have methods for |
678 | 678 | // each context defined to handle the processing of the data object within them |
679 | - foreach ( $this->_contexts as $context => $details ) { |
|
680 | - $xpctd_method = '_' . $context . '_addressees'; |
|
681 | - if ( ! method_exists( $this, $xpctd_method ) ) { |
|
679 | + foreach ($this->_contexts as $context => $details) { |
|
680 | + $xpctd_method = '_'.$context.'_addressees'; |
|
681 | + if ( ! method_exists($this, $xpctd_method)) { |
|
682 | 682 | throw new EE_Error( |
683 | 683 | sprintf( |
684 | 684 | __( |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | ) |
691 | 691 | ); |
692 | 692 | } |
693 | - $this->_addressees[ $context ] = call_user_func( array( $this, $xpctd_method ) ); |
|
693 | + $this->_addressees[$context] = call_user_func(array($this, $xpctd_method)); |
|
694 | 694 | } |
695 | 695 | return true; //data was processed successfully. |
696 | 696 | } |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | 'grand_total_line_item' => $this->_data->grand_total_line_item, |
713 | 713 | 'txn' => $this->_data->txn, |
714 | 714 | 'payments' => $this->_data->payments, |
715 | - 'payment' => isset( $this->_data->payment ) && $this->_data->payment instanceof EE_Payment |
|
715 | + 'payment' => isset($this->_data->payment) && $this->_data->payment instanceof EE_Payment |
|
716 | 716 | ? $this->_data->payment |
717 | 717 | : null, |
718 | 718 | 'reg_objs' => $this->_data->reg_objs, |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | 'txn_status' => $this->_data->txn_status, |
726 | 726 | 'total_ticket_count' => $this->_data->total_ticket_count, |
727 | 727 | ); |
728 | - if ( is_array( $this->_data->primary_attendee_data ) ) { |
|
728 | + if (is_array($this->_data->primary_attendee_data)) { |
|
729 | 729 | $this->_default_addressee_data = array_merge( |
730 | 730 | $this->_default_addressee_data, |
731 | 731 | $this->_data->primary_attendee_data |
@@ -769,24 +769,24 @@ discard block |
||
769 | 769 | 'messenger', |
770 | 770 | ); |
771 | 771 | $contexts = $this->get_contexts(); |
772 | - foreach ( $contexts as $context => $details ) { |
|
773 | - $this->_valid_shortcodes[ $context ] = $all_shortcodes; |
|
772 | + foreach ($contexts as $context => $details) { |
|
773 | + $this->_valid_shortcodes[$context] = $all_shortcodes; |
|
774 | 774 | //make sure non admin context does not include the event_author shortcodes |
775 | - if ( $context != 'admin' ) { |
|
776 | - if ( ( $key = array_search( 'event_author', $this->_valid_shortcodes[ $context ] ) ) !== false ) { |
|
777 | - unset( $this->_valid_shortcodes[ $context ][ $key ] ); |
|
775 | + if ($context != 'admin') { |
|
776 | + if (($key = array_search('event_author', $this->_valid_shortcodes[$context])) !== false) { |
|
777 | + unset($this->_valid_shortcodes[$context][$key]); |
|
778 | 778 | } |
779 | 779 | } |
780 | 780 | } |
781 | 781 | // make sure admin context does not include the recipient_details shortcodes |
782 | 782 | // IF we have admin context hooked in message types might not have that context. |
783 | - if ( ! empty( $this->_valid_shortcodes['admin'] ) ) { |
|
784 | - if ( ( $key = array_search( 'recipient_details', $this->_valid_shortcodes['admin'] ) ) !== false ) { |
|
785 | - unset( $this->_valid_shortcodes['admin'][ $key ] ); |
|
783 | + if ( ! empty($this->_valid_shortcodes['admin'])) { |
|
784 | + if (($key = array_search('recipient_details', $this->_valid_shortcodes['admin'])) !== false) { |
|
785 | + unset($this->_valid_shortcodes['admin'][$key]); |
|
786 | 786 | } |
787 | 787 | //make sure admin context does not include the recipient_details shortcodes |
788 | - if ( ( $key = array_search( 'recipient_list', $this->_valid_shortcodes['admin'] ) ) !== false ) { |
|
789 | - unset( $this->_valid_shortcodes['admin'][ $key ] ); |
|
788 | + if (($key = array_search('recipient_list', $this->_valid_shortcodes['admin'])) !== false) { |
|
789 | + unset($this->_valid_shortcodes['admin'][$key]); |
|
790 | 790 | } |
791 | 791 | } |
792 | 792 | } |
@@ -799,9 +799,9 @@ discard block |
||
799 | 799 | * @param array $new_config array of valid shortcodes (by context) |
800 | 800 | * @return void sets valid_shortcodes property |
801 | 801 | */ |
802 | - public function reset_valid_shortcodes_config( $new_config ) { |
|
803 | - foreach ( $new_config as $context => $shortcodes ) { |
|
804 | - $this->_valid_shortcodes[ $context ] = $shortcodes; |
|
802 | + public function reset_valid_shortcodes_config($new_config) { |
|
803 | + foreach ($new_config as $context => $shortcodes) { |
|
804 | + $this->_valid_shortcodes[$context] = $shortcodes; |
|
805 | 805 | } |
806 | 806 | } |
807 | 807 | |
@@ -818,13 +818,13 @@ discard block |
||
818 | 818 | $addressees = array(); |
819 | 819 | // first we need to get the event admin user id for all the events |
820 | 820 | // and setup an addressee object for each unique admin user. |
821 | - foreach ( $this->_data->events as $line_ref => $event ) { |
|
822 | - $admin_id = $this->_get_event_admin_id( $event['ID'] ); |
|
821 | + foreach ($this->_data->events as $line_ref => $event) { |
|
822 | + $admin_id = $this->_get_event_admin_id($event['ID']); |
|
823 | 823 | //make sure we are just including the events that belong to this admin! |
824 | - $admin_events[ $admin_id ][ $line_ref ] = $event; |
|
824 | + $admin_events[$admin_id][$line_ref] = $event; |
|
825 | 825 | } |
826 | 826 | //k now we can loop through the event_admins and setup the addressee data. |
827 | - foreach ( $admin_events as $admin_id => $event_details ) { |
|
827 | + foreach ($admin_events as $admin_id => $event_details) { |
|
828 | 828 | $aee = array( |
829 | 829 | 'user_id' => $admin_id, |
830 | 830 | 'events' => $event_details, |
@@ -832,8 +832,8 @@ discard block |
||
832 | 832 | 'recipient_id' => $admin_id, |
833 | 833 | 'recipient_type' => 'WP_User', |
834 | 834 | ); |
835 | - $aee = array_merge( $this->_default_addressee_data, $aee ); |
|
836 | - $addressees[] = new EE_Messages_Addressee( $aee ); |
|
835 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
836 | + $addressees[] = new EE_Messages_Addressee($aee); |
|
837 | 837 | } |
838 | 838 | return $addressees; |
839 | 839 | } |
@@ -853,7 +853,7 @@ discard block |
||
853 | 853 | $aee['recipient_id'] = $aee['primary_att_obj'] instanceof EE_Attendee ? $aee['primary_att_obj']->ID() : 0; |
854 | 854 | $aee['recipient_type'] = 'Attendee'; |
855 | 855 | //great now we can instantiate the $addressee object and return (as an array); |
856 | - $add[] = new EE_Messages_Addressee( $aee ); |
|
856 | + $add[] = new EE_Messages_Addressee($aee); |
|
857 | 857 | return $add; |
858 | 858 | } |
859 | 859 | |
@@ -870,25 +870,25 @@ discard block |
||
870 | 870 | //we just have to loop through the attendees. We'll also set the attached events for each attendee. |
871 | 871 | //use to verify unique attendee emails... we don't want to sent multiple copies to the same attendee do we? |
872 | 872 | $already_processed = array(); |
873 | - foreach ( $this->_data->attendees as $att_id => $details ) { |
|
873 | + foreach ($this->_data->attendees as $att_id => $details) { |
|
874 | 874 | //set the attendee array to blank on each loop; |
875 | 875 | $aee = array(); |
876 | - if ( isset( $this->_data->reg_obj ) |
|
877 | - && ( $this->_data->reg_obj->attendee_ID() != $att_id ) |
|
876 | + if (isset($this->_data->reg_obj) |
|
877 | + && ($this->_data->reg_obj->attendee_ID() != $att_id) |
|
878 | 878 | && $this->_single_message |
879 | 879 | ) { |
880 | 880 | continue; |
881 | 881 | } |
882 | 882 | // is $this->_regs_for_sending present? |
883 | 883 | // If so, let's make sure we ONLY generate addressee for registrations in that array. |
884 | - if ( ! empty( $this->_regs_for_sending ) && is_array( $this->_regs_for_sending ) ) { |
|
885 | - $regs_allowed = array_intersect_key( array_flip( $this->_regs_for_sending ), $details['reg_objs'] ); |
|
886 | - if ( empty( $regs_allowed ) ) { |
|
884 | + if ( ! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
885 | + $regs_allowed = array_intersect_key(array_flip($this->_regs_for_sending), $details['reg_objs']); |
|
886 | + if (empty($regs_allowed)) { |
|
887 | 887 | continue; |
888 | 888 | } |
889 | 889 | } |
890 | 890 | if ( |
891 | - in_array( $details['attendee_email'], $already_processed ) |
|
891 | + in_array($details['attendee_email'], $already_processed) |
|
892 | 892 | && apply_filters( |
893 | 893 | 'FHEE__EE_message_type___attendee_addressees__prevent_duplicate_email_sends', |
894 | 894 | true, |
@@ -899,14 +899,14 @@ discard block |
||
899 | 899 | continue; |
900 | 900 | } |
901 | 901 | $already_processed[] = $details['attendee_email']; |
902 | - foreach ( $details as $item => $value ) { |
|
903 | - $aee[ $item ] = $value; |
|
904 | - if ( $item == 'line_ref' ) { |
|
905 | - foreach ( $value as $event_id ) { |
|
906 | - $aee['events'][ $event_id ] = $this->_data->events[ $event_id ]; |
|
902 | + foreach ($details as $item => $value) { |
|
903 | + $aee[$item] = $value; |
|
904 | + if ($item == 'line_ref') { |
|
905 | + foreach ($value as $event_id) { |
|
906 | + $aee['events'][$event_id] = $this->_data->events[$event_id]; |
|
907 | 907 | } |
908 | 908 | } |
909 | - if ( $item == 'attendee_email' ) { |
|
909 | + if ($item == 'attendee_email') { |
|
910 | 910 | $aee['attendee_email'] = $value; |
911 | 911 | } |
912 | 912 | /*if ( $item == 'registration_id' ) { |
@@ -915,13 +915,13 @@ discard block |
||
915 | 915 | } |
916 | 916 | // note the FIRST reg object in this array is the one |
917 | 917 | // we'll use for this attendee as the primary registration for this attendee. |
918 | - $aee['reg_obj'] = reset( $this->_data->attendees[ $att_id ]['reg_objs'] ); |
|
918 | + $aee['reg_obj'] = reset($this->_data->attendees[$att_id]['reg_objs']); |
|
919 | 919 | $aee['attendees'] = $this->_data->attendees; |
920 | 920 | $aee['recipient_id'] = $att_id; |
921 | 921 | $aee['recipient_type'] = 'Attendee'; |
922 | 922 | //merge in the primary attendee data |
923 | - $aee = array_merge( $this->_default_addressee_data, $aee ); |
|
924 | - $add[] = new EE_Messages_Addressee( $aee ); |
|
923 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
924 | + $add[] = new EE_Messages_Addressee($aee); |
|
925 | 925 | } |
926 | 926 | return $add; |
927 | 927 | } |
@@ -932,8 +932,8 @@ discard block |
||
932 | 932 | * @param $event_id |
933 | 933 | * @return int |
934 | 934 | */ |
935 | - protected function _get_event_admin_id( $event_id ) { |
|
936 | - $event = EEM_Event::instance()->get_one_by_ID( $event_id ); |
|
935 | + protected function _get_event_admin_id($event_id) { |
|
936 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
937 | 937 | return $event instanceof EE_Event ? $event->wp_user() : 0; |
938 | 938 | } |
939 | 939 |
@@ -14,283 +14,283 @@ |
||
14 | 14 | class MessagesAdmin extends CoreAdmin |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Context slug for the admin messages context. |
|
19 | - */ |
|
20 | - const ADMIN_CONTEXT_SLUG = 'admin'; |
|
17 | + /** |
|
18 | + * Context slug for the admin messages context. |
|
19 | + */ |
|
20 | + const ADMIN_CONTEXT_SLUG = 'admin'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Context slug for the primary attendee messages context |
|
24 | - */ |
|
25 | - const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
|
22 | + /** |
|
23 | + * Context slug for the primary attendee messages context |
|
24 | + */ |
|
25 | + const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * Context slug for the attendee messages context |
|
30 | - */ |
|
31 | - const ATTENDEE_CONTEXT_SLUG = 'attendee'; |
|
28 | + /** |
|
29 | + * Context slug for the attendee messages context |
|
30 | + */ |
|
31 | + const ATTENDEE_CONTEXT_SLUG = 'attendee'; |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Status reference for the EEM_Message::status_sent status. |
|
36 | - */ |
|
37 | - const MESSAGE_STATUS_SENT = 'MSN'; |
|
34 | + /** |
|
35 | + * Status reference for the EEM_Message::status_sent status. |
|
36 | + */ |
|
37 | + const MESSAGE_STATUS_SENT = 'MSN'; |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Message type slug for the Payment Failed message type |
|
42 | - */ |
|
43 | - const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
|
40 | + /** |
|
41 | + * Message type slug for the Payment Failed message type |
|
42 | + */ |
|
43 | + const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
|
48 | - */ |
|
49 | - const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = |
|
50 | - '#global_messages_settings-do-messages-on-same-request'; |
|
46 | + /** |
|
47 | + * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
|
48 | + */ |
|
49 | + const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = |
|
50 | + '#global_messages_settings-do-messages-on-same-request'; |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
|
55 | - */ |
|
56 | - const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
|
53 | + /** |
|
54 | + * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
|
55 | + */ |
|
56 | + const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * This is the container where active message types for a messenger are found/dragged to. |
|
61 | - */ |
|
62 | - const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
|
59 | + /** |
|
60 | + * This is the container where active message types for a messenger are found/dragged to. |
|
61 | + */ |
|
62 | + const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * Locator for the context switcher selector on the Message Template Editor page. |
|
67 | - */ |
|
68 | - const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select"; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Locator for the context switcher submit button in the Message Template Editor page. |
|
73 | - */ |
|
74 | - const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt"; |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * Locator for the dialog container used for housing viewed messages in the message activity list table. |
|
79 | - */ |
|
80 | - const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content'; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns the selector for the on/off toggle for context on the message template editor. |
|
85 | - */ |
|
86 | - const MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE = |
|
87 | - "//div[@class='activate_context_on_off_toggle_container']/div[@class='switch']/label"; |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
93 | - * a string. |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public static function messageActivityListTableUrl($additional_params = '') |
|
97 | - { |
|
98 | - return self::adminUrl('espresso_messages', 'default', $additional_params); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
104 | - * a string. |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public static function defaultMessageTemplateListTableUrl($additional_params = '') |
|
108 | - { |
|
109 | - return self::adminUrl('espresso_messages', 'global_mtps', $additional_params); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
115 | - * a string. |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public static function customMessageTemplateListTableUrl($additional_params = '') |
|
119 | - { |
|
120 | - return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public static function messageSettingsUrl() |
|
128 | - { |
|
129 | - return self::adminUrl('espresso_messages', 'settings'); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
|
135 | - $message_type_slug, |
|
136 | - $messenger_slug = 'email' |
|
137 | - ) { |
|
138 | - return "#$message_type_slug-messagetype-$messenger_slug"; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param string $message_type_slug |
|
144 | - * @param string $context |
|
145 | - * @return string |
|
146 | - */ |
|
147 | - public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
|
148 | - { |
|
149 | - return $context |
|
150 | - ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
151 | - : '.' . $message_type_slug . '-edit-link'; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
|
157 | - * |
|
158 | - * @param $field |
|
159 | - * @param $message_type_label |
|
160 | - * @param string $message_status |
|
161 | - * @param string $messenger |
|
162 | - * @param string $context |
|
163 | - * @param string $table_cell_content_for_field |
|
164 | - * @param int $number_in_set It's possible that the given parameters could match multiple items in the view. |
|
165 | - * This allows you to indicate which item from the set to match. If this is set to 0 |
|
166 | - * then all matches for the locator will be returned. |
|
167 | - * @return string |
|
168 | - * @throws \InvalidArgumentException |
|
169 | - */ |
|
170 | - public static function messagesActivityListTableCellSelectorFor( |
|
171 | - $field, |
|
172 | - $message_type_label, |
|
173 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
174 | - $messenger = 'Email', |
|
175 | - $context = 'Event Admin', |
|
176 | - $table_cell_content_for_field = '', |
|
177 | - $number_in_set = 1 |
|
178 | - ) { |
|
179 | - $selector = "//tbody[@id='the-list']"; |
|
180 | - $selector .= "//tr[contains(@class, 'msg-status-$message_status')]" |
|
181 | - . "//td[contains(@class, 'message_type') and text()='$message_type_label']"; |
|
182 | - if ($messenger) { |
|
183 | - $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']"; |
|
184 | - } |
|
185 | - $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']"; |
|
186 | - $selector .= $table_cell_content_for_field |
|
187 | - ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']" |
|
188 | - : "/ancestor::tr/td[contains(@class, 'column-$field')]"; |
|
189 | - return $number_in_set > 0 ? Locator::elementAt($selector, $number_in_set) : $selector; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Selector for the Create Custom button found in the message template list table. |
|
195 | - * @param string $message_type_label |
|
196 | - * @param string $messenger_label |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label) |
|
200 | - { |
|
201 | - $selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']" |
|
202 | - . "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]" |
|
203 | - . "//ancestor::tr/td/a[@class='button button-small']"; |
|
204 | - return $selector; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to |
|
210 | - * the FIRST match (which will be the latest message sent if the table is default sorted). |
|
211 | - * |
|
212 | - * @param string $message_type_label The visible message type label for the row you want to match |
|
213 | - * @param string $message_status The status of the message for the row you want to match. |
|
214 | - * @param string $messenger The visible messenger label for the row you want to match. |
|
215 | - * @param string $context The visible context label for the row you want to match. |
|
216 | - * @param int $number_in_set It's possible that the given parameters could match multiple items in the |
|
217 | - * view. This allows you to indicate which item from the set to match. |
|
218 | - * @return string |
|
219 | - * @throws \InvalidArgumentException |
|
220 | - */ |
|
221 | - public static function messagesActivityListTableViewButtonSelectorFor( |
|
222 | - $message_type_label, |
|
223 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
224 | - $messenger = 'Email', |
|
225 | - $context = 'Event Admin', |
|
226 | - $number_in_set = 1 |
|
227 | - ) { |
|
228 | - $selector = self::messagesActivityListTableCellSelectorFor( |
|
229 | - 'action', |
|
230 | - $message_type_label, |
|
231 | - $message_status, |
|
232 | - $messenger, |
|
233 | - $context, |
|
234 | - '', |
|
235 | - $number_in_set |
|
236 | - ); |
|
237 | - $selector .= "/a/span[contains(@class, 'ee-message-action-link-view')" |
|
238 | - . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]"; |
|
239 | - return $selector; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Locator for the delete action link for a message item in the message activity list table. |
|
245 | - * Note: The link is not visible by default, so the column would need hovered over for the link to appear. |
|
246 | - * |
|
247 | - * @param $message_type_label |
|
248 | - * @param string $message_status |
|
249 | - * @param string $messenger |
|
250 | - * @param string $context |
|
251 | - * @param int $number_in_set |
|
252 | - * @return string |
|
253 | - * @throws \InvalidArgumentException |
|
254 | - */ |
|
255 | - public static function messagesActivityListTableDeleteActionSelectorFor( |
|
256 | - $message_type_label, |
|
257 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
258 | - $messenger = 'Email', |
|
259 | - $context = 'Event Admin', |
|
260 | - $number_in_set = 1 |
|
261 | - ) { |
|
262 | - $selector = self::messagesActivityListTableCellSelectorFor( |
|
263 | - 'to', |
|
264 | - $message_type_label, |
|
265 | - $message_status, |
|
266 | - $messenger, |
|
267 | - $context, |
|
268 | - '', |
|
269 | - $number_in_set |
|
270 | - ); |
|
271 | - $selector .= "/div/span[@class='delete']/a"; |
|
272 | - return $selector; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * Returns the input selector for a given field in the message template editor. |
|
279 | - * Assumes one is already viewing the Message Template Editor. |
|
280 | - * @param string $field |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - public static function messageInputFieldSelectorFor($field) |
|
284 | - { |
|
285 | - return "//div[@id='post-body']//input[@id='$field-content']"; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * Wrapper for self::messageInputFieldSelectorFor('to') that takes care of getting the input for the To field. |
|
291 | - */ |
|
292 | - public static function messageTemplateToFieldSelector() |
|
293 | - { |
|
294 | - return self::messageInputFieldSelectorFor('to'); |
|
295 | - } |
|
65 | + /** |
|
66 | + * Locator for the context switcher selector on the Message Template Editor page. |
|
67 | + */ |
|
68 | + const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select"; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Locator for the context switcher submit button in the Message Template Editor page. |
|
73 | + */ |
|
74 | + const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt"; |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * Locator for the dialog container used for housing viewed messages in the message activity list table. |
|
79 | + */ |
|
80 | + const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content'; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns the selector for the on/off toggle for context on the message template editor. |
|
85 | + */ |
|
86 | + const MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE = |
|
87 | + "//div[@class='activate_context_on_off_toggle_container']/div[@class='switch']/label"; |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
93 | + * a string. |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public static function messageActivityListTableUrl($additional_params = '') |
|
97 | + { |
|
98 | + return self::adminUrl('espresso_messages', 'default', $additional_params); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
104 | + * a string. |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public static function defaultMessageTemplateListTableUrl($additional_params = '') |
|
108 | + { |
|
109 | + return self::adminUrl('espresso_messages', 'global_mtps', $additional_params); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
115 | + * a string. |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + public static function customMessageTemplateListTableUrl($additional_params = '') |
|
119 | + { |
|
120 | + return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public static function messageSettingsUrl() |
|
128 | + { |
|
129 | + return self::adminUrl('espresso_messages', 'settings'); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
|
135 | + $message_type_slug, |
|
136 | + $messenger_slug = 'email' |
|
137 | + ) { |
|
138 | + return "#$message_type_slug-messagetype-$messenger_slug"; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param string $message_type_slug |
|
144 | + * @param string $context |
|
145 | + * @return string |
|
146 | + */ |
|
147 | + public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
|
148 | + { |
|
149 | + return $context |
|
150 | + ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
151 | + : '.' . $message_type_slug . '-edit-link'; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
|
157 | + * |
|
158 | + * @param $field |
|
159 | + * @param $message_type_label |
|
160 | + * @param string $message_status |
|
161 | + * @param string $messenger |
|
162 | + * @param string $context |
|
163 | + * @param string $table_cell_content_for_field |
|
164 | + * @param int $number_in_set It's possible that the given parameters could match multiple items in the view. |
|
165 | + * This allows you to indicate which item from the set to match. If this is set to 0 |
|
166 | + * then all matches for the locator will be returned. |
|
167 | + * @return string |
|
168 | + * @throws \InvalidArgumentException |
|
169 | + */ |
|
170 | + public static function messagesActivityListTableCellSelectorFor( |
|
171 | + $field, |
|
172 | + $message_type_label, |
|
173 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
174 | + $messenger = 'Email', |
|
175 | + $context = 'Event Admin', |
|
176 | + $table_cell_content_for_field = '', |
|
177 | + $number_in_set = 1 |
|
178 | + ) { |
|
179 | + $selector = "//tbody[@id='the-list']"; |
|
180 | + $selector .= "//tr[contains(@class, 'msg-status-$message_status')]" |
|
181 | + . "//td[contains(@class, 'message_type') and text()='$message_type_label']"; |
|
182 | + if ($messenger) { |
|
183 | + $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']"; |
|
184 | + } |
|
185 | + $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']"; |
|
186 | + $selector .= $table_cell_content_for_field |
|
187 | + ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']" |
|
188 | + : "/ancestor::tr/td[contains(@class, 'column-$field')]"; |
|
189 | + return $number_in_set > 0 ? Locator::elementAt($selector, $number_in_set) : $selector; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Selector for the Create Custom button found in the message template list table. |
|
195 | + * @param string $message_type_label |
|
196 | + * @param string $messenger_label |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label) |
|
200 | + { |
|
201 | + $selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']" |
|
202 | + . "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]" |
|
203 | + . "//ancestor::tr/td/a[@class='button button-small']"; |
|
204 | + return $selector; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to |
|
210 | + * the FIRST match (which will be the latest message sent if the table is default sorted). |
|
211 | + * |
|
212 | + * @param string $message_type_label The visible message type label for the row you want to match |
|
213 | + * @param string $message_status The status of the message for the row you want to match. |
|
214 | + * @param string $messenger The visible messenger label for the row you want to match. |
|
215 | + * @param string $context The visible context label for the row you want to match. |
|
216 | + * @param int $number_in_set It's possible that the given parameters could match multiple items in the |
|
217 | + * view. This allows you to indicate which item from the set to match. |
|
218 | + * @return string |
|
219 | + * @throws \InvalidArgumentException |
|
220 | + */ |
|
221 | + public static function messagesActivityListTableViewButtonSelectorFor( |
|
222 | + $message_type_label, |
|
223 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
224 | + $messenger = 'Email', |
|
225 | + $context = 'Event Admin', |
|
226 | + $number_in_set = 1 |
|
227 | + ) { |
|
228 | + $selector = self::messagesActivityListTableCellSelectorFor( |
|
229 | + 'action', |
|
230 | + $message_type_label, |
|
231 | + $message_status, |
|
232 | + $messenger, |
|
233 | + $context, |
|
234 | + '', |
|
235 | + $number_in_set |
|
236 | + ); |
|
237 | + $selector .= "/a/span[contains(@class, 'ee-message-action-link-view')" |
|
238 | + . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]"; |
|
239 | + return $selector; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Locator for the delete action link for a message item in the message activity list table. |
|
245 | + * Note: The link is not visible by default, so the column would need hovered over for the link to appear. |
|
246 | + * |
|
247 | + * @param $message_type_label |
|
248 | + * @param string $message_status |
|
249 | + * @param string $messenger |
|
250 | + * @param string $context |
|
251 | + * @param int $number_in_set |
|
252 | + * @return string |
|
253 | + * @throws \InvalidArgumentException |
|
254 | + */ |
|
255 | + public static function messagesActivityListTableDeleteActionSelectorFor( |
|
256 | + $message_type_label, |
|
257 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
258 | + $messenger = 'Email', |
|
259 | + $context = 'Event Admin', |
|
260 | + $number_in_set = 1 |
|
261 | + ) { |
|
262 | + $selector = self::messagesActivityListTableCellSelectorFor( |
|
263 | + 'to', |
|
264 | + $message_type_label, |
|
265 | + $message_status, |
|
266 | + $messenger, |
|
267 | + $context, |
|
268 | + '', |
|
269 | + $number_in_set |
|
270 | + ); |
|
271 | + $selector .= "/div/span[@class='delete']/a"; |
|
272 | + return $selector; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * Returns the input selector for a given field in the message template editor. |
|
279 | + * Assumes one is already viewing the Message Template Editor. |
|
280 | + * @param string $field |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + public static function messageInputFieldSelectorFor($field) |
|
284 | + { |
|
285 | + return "//div[@id='post-body']//input[@id='$field-content']"; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * Wrapper for self::messageInputFieldSelectorFor('to') that takes care of getting the input for the To field. |
|
291 | + */ |
|
292 | + public static function messageTemplateToFieldSelector() |
|
293 | + { |
|
294 | + return self::messageInputFieldSelectorFor('to'); |
|
295 | + } |
|
296 | 296 | } |
297 | 297 | \ No newline at end of file |
@@ -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 |