Completed
Branch EDTR/refactor-fast-api-fetch (5d445e)
by
unknown
17:57 queued 09:42
created
form_sections/strategies/layout/EE_Div_Per_Section_Layout.strategy.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -14,136 +14,136 @@
 block discarded – undo
14 14
 class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base
15 15
 {
16 16
 
17
-    /**
18
-     * opening div tag for a form
19
-     *
20
-     * @return string
21
-     */
22
-    public function layout_form_begin()
23
-    {
24
-        return EEH_HTML::div(
25
-            '',
26
-            $this->_form_section->html_id(),
27
-            $this->_form_section->html_class(),
28
-            $this->_form_section->html_style()
29
-        );
30
-    }
31
-
32
-
33
-
34
-    /**
35
-     * Lays out the row for the input, including label and errors
36
-     *
37
-     * @param EE_Form_Input_Base $input
38
-     * @return string
39
-     * @throws \EE_Error
40
-     */
41
-    public function layout_input($input)
42
-    {
43
-        $html = '';
44
-        // set something unique for the id
45
-        $html_id = (string) $input->html_id() !== ''
46
-            ? (string) $input->html_id()
47
-            : spl_object_hash($input);
48
-        // and add a generic input type class
49
-        $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
50
-        if ($input instanceof EE_Hidden_Input) {
51
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
52
-        } elseif ($input instanceof EE_Submit_Input) {
53
-            $html .= EEH_HTML::div(
54
-                $input->get_html_for_input(),
55
-                $html_id . '-submit-dv',
56
-                "{$input->html_class()}-submit-dv {$html_class}"
57
-            );
58
-        } elseif ($input instanceof EE_Select_Input) {
59
-            $html .= EEH_HTML::div(
60
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
61
-                EEH_HTML::nl() . $input->get_html_for_errors() .
62
-                EEH_HTML::nl() . $input->get_html_for_input() .
63
-                EEH_HTML::nl() . $input->get_html_for_help(),
64
-                $html_id . '-input-dv',
65
-                "{$input->html_class()}-input-dv {$html_class}"
66
-            );
67
-        } elseif ($input instanceof EE_Form_Input_With_Options_Base) {
68
-            $html .= EEH_HTML::div(
69
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
70
-                EEH_HTML::nl() . $input->get_html_for_errors() .
71
-                EEH_HTML::nl() . $input->get_html_for_input() .
72
-                EEH_HTML::nl() . $input->get_html_for_help(),
73
-                $html_id . '-input-dv',
74
-                "{$input->html_class()}-input-dv {$html_class}"
75
-            );
76
-        } else {
77
-            $html .= EEH_HTML::div(
78
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
79
-                EEH_HTML::nl() . $input->get_html_for_errors() .
80
-                EEH_HTML::nl() . $input->get_html_for_input() .
81
-                EEH_HTML::nl() . $input->get_html_for_help(),
82
-                $html_id . '-input-dv',
83
-                "{$input->html_class()}-input-dv {$html_class}"
84
-            );
85
-        }
86
-        return $html;
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     *
93
-     * _display_label_for_option_type_question
94
-     * Gets the HTML for the 'label', which is just text for this (because labels
95
-     * should be for each input)
96
-     *
97
-     * @param EE_Form_Input_With_Options_Base $input
98
-     * @return string
99
-     */
100
-    protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
101
-    {
102
-        if ($input->display_html_label_text()) {
103
-            $html_label_text = $input->html_label_text();
104
-            $label_html = EEH_HTML::div(
105
-                $input->required()
106
-                    ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
107
-                    : $html_label_text,
108
-                $input->html_label_id(),
109
-                $input->required()
110
-                    ? 'ee-required-label ' . $input->html_label_class()
111
-                    : $input->html_label_class(),
112
-                $input->html_label_style(),
113
-                $input->other_html_attributes()
114
-            );
115
-            // if no content was provided to EEH_HTML::div() above (ie: an empty label),
116
-            // then we need to close the div manually
117
-            if (empty($html_label_text)) {
118
-                $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class());
119
-            }
120
-            return $label_html;
121
-        }
122
-        return '';
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * Lays out a row for the subsection
129
-     *
130
-     * @param EE_Form_Section_Proper $form_section
131
-     * @return string
132
-     */
133
-    public function layout_subsection($form_section)
134
-    {
135
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * closing div tag for a form
142
-     *
143
-     * @return string
144
-     */
145
-    public function layout_form_end()
146
-    {
147
-        return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
148
-    }
17
+	/**
18
+	 * opening div tag for a form
19
+	 *
20
+	 * @return string
21
+	 */
22
+	public function layout_form_begin()
23
+	{
24
+		return EEH_HTML::div(
25
+			'',
26
+			$this->_form_section->html_id(),
27
+			$this->_form_section->html_class(),
28
+			$this->_form_section->html_style()
29
+		);
30
+	}
31
+
32
+
33
+
34
+	/**
35
+	 * Lays out the row for the input, including label and errors
36
+	 *
37
+	 * @param EE_Form_Input_Base $input
38
+	 * @return string
39
+	 * @throws \EE_Error
40
+	 */
41
+	public function layout_input($input)
42
+	{
43
+		$html = '';
44
+		// set something unique for the id
45
+		$html_id = (string) $input->html_id() !== ''
46
+			? (string) $input->html_id()
47
+			: spl_object_hash($input);
48
+		// and add a generic input type class
49
+		$html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
50
+		if ($input instanceof EE_Hidden_Input) {
51
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
52
+		} elseif ($input instanceof EE_Submit_Input) {
53
+			$html .= EEH_HTML::div(
54
+				$input->get_html_for_input(),
55
+				$html_id . '-submit-dv',
56
+				"{$input->html_class()}-submit-dv {$html_class}"
57
+			);
58
+		} elseif ($input instanceof EE_Select_Input) {
59
+			$html .= EEH_HTML::div(
60
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
61
+				EEH_HTML::nl() . $input->get_html_for_errors() .
62
+				EEH_HTML::nl() . $input->get_html_for_input() .
63
+				EEH_HTML::nl() . $input->get_html_for_help(),
64
+				$html_id . '-input-dv',
65
+				"{$input->html_class()}-input-dv {$html_class}"
66
+			);
67
+		} elseif ($input instanceof EE_Form_Input_With_Options_Base) {
68
+			$html .= EEH_HTML::div(
69
+				EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
70
+				EEH_HTML::nl() . $input->get_html_for_errors() .
71
+				EEH_HTML::nl() . $input->get_html_for_input() .
72
+				EEH_HTML::nl() . $input->get_html_for_help(),
73
+				$html_id . '-input-dv',
74
+				"{$input->html_class()}-input-dv {$html_class}"
75
+			);
76
+		} else {
77
+			$html .= EEH_HTML::div(
78
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
79
+				EEH_HTML::nl() . $input->get_html_for_errors() .
80
+				EEH_HTML::nl() . $input->get_html_for_input() .
81
+				EEH_HTML::nl() . $input->get_html_for_help(),
82
+				$html_id . '-input-dv',
83
+				"{$input->html_class()}-input-dv {$html_class}"
84
+			);
85
+		}
86
+		return $html;
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 *
93
+	 * _display_label_for_option_type_question
94
+	 * Gets the HTML for the 'label', which is just text for this (because labels
95
+	 * should be for each input)
96
+	 *
97
+	 * @param EE_Form_Input_With_Options_Base $input
98
+	 * @return string
99
+	 */
100
+	protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
101
+	{
102
+		if ($input->display_html_label_text()) {
103
+			$html_label_text = $input->html_label_text();
104
+			$label_html = EEH_HTML::div(
105
+				$input->required()
106
+					? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
107
+					: $html_label_text,
108
+				$input->html_label_id(),
109
+				$input->required()
110
+					? 'ee-required-label ' . $input->html_label_class()
111
+					: $input->html_label_class(),
112
+				$input->html_label_style(),
113
+				$input->other_html_attributes()
114
+			);
115
+			// if no content was provided to EEH_HTML::div() above (ie: an empty label),
116
+			// then we need to close the div manually
117
+			if (empty($html_label_text)) {
118
+				$label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class());
119
+			}
120
+			return $label_html;
121
+		}
122
+		return '';
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * Lays out a row for the subsection
129
+	 *
130
+	 * @param EE_Form_Section_Proper $form_section
131
+	 * @return string
132
+	 */
133
+	public function layout_subsection($form_section)
134
+	{
135
+		return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * closing div tag for a form
142
+	 *
143
+	 * @return string
144
+	 */
145
+	public function layout_form_end()
146
+	{
147
+		return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
148
+	}
149 149
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -46,40 +46,40 @@  discard block
 block discarded – undo
46 46
             ? (string) $input->html_id()
47 47
             : spl_object_hash($input);
48 48
         // and add a generic input type class
49
-        $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
49
+        $html_class = sanitize_key(str_replace('_', '-', get_class($input))).'-dv';
50 50
         if ($input instanceof EE_Hidden_Input) {
51
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
51
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
52 52
         } elseif ($input instanceof EE_Submit_Input) {
53 53
             $html .= EEH_HTML::div(
54 54
                 $input->get_html_for_input(),
55
-                $html_id . '-submit-dv',
55
+                $html_id.'-submit-dv',
56 56
                 "{$input->html_class()}-submit-dv {$html_class}"
57 57
             );
58 58
         } elseif ($input instanceof EE_Select_Input) {
59 59
             $html .= EEH_HTML::div(
60
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
61
-                EEH_HTML::nl() . $input->get_html_for_errors() .
62
-                EEH_HTML::nl() . $input->get_html_for_input() .
63
-                EEH_HTML::nl() . $input->get_html_for_help(),
64
-                $html_id . '-input-dv',
60
+                EEH_HTML::nl(1).$input->get_html_for_label().
61
+                EEH_HTML::nl().$input->get_html_for_errors().
62
+                EEH_HTML::nl().$input->get_html_for_input().
63
+                EEH_HTML::nl().$input->get_html_for_help(),
64
+                $html_id.'-input-dv',
65 65
                 "{$input->html_class()}-input-dv {$html_class}"
66 66
             );
67 67
         } elseif ($input instanceof EE_Form_Input_With_Options_Base) {
68 68
             $html .= EEH_HTML::div(
69
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
70
-                EEH_HTML::nl() . $input->get_html_for_errors() .
71
-                EEH_HTML::nl() . $input->get_html_for_input() .
72
-                EEH_HTML::nl() . $input->get_html_for_help(),
73
-                $html_id . '-input-dv',
69
+                EEH_HTML::nl().$this->_display_label_for_option_type_question($input).
70
+                EEH_HTML::nl().$input->get_html_for_errors().
71
+                EEH_HTML::nl().$input->get_html_for_input().
72
+                EEH_HTML::nl().$input->get_html_for_help(),
73
+                $html_id.'-input-dv',
74 74
                 "{$input->html_class()}-input-dv {$html_class}"
75 75
             );
76 76
         } else {
77 77
             $html .= EEH_HTML::div(
78
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
79
-                EEH_HTML::nl() . $input->get_html_for_errors() .
80
-                EEH_HTML::nl() . $input->get_html_for_input() .
81
-                EEH_HTML::nl() . $input->get_html_for_help(),
82
-                $html_id . '-input-dv',
78
+                EEH_HTML::nl(1).$input->get_html_for_label().
79
+                EEH_HTML::nl().$input->get_html_for_errors().
80
+                EEH_HTML::nl().$input->get_html_for_input().
81
+                EEH_HTML::nl().$input->get_html_for_help(),
82
+                $html_id.'-input-dv',
83 83
                 "{$input->html_class()}-input-dv {$html_class}"
84 84
             );
85 85
         }
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
             $html_label_text = $input->html_label_text();
104 104
             $label_html = EEH_HTML::div(
105 105
                 $input->required()
106
-                    ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
106
+                    ? $html_label_text.EEH_HTML::span('*', '', 'ee-asterisk')
107 107
                     : $html_label_text,
108 108
                 $input->html_label_id(),
109 109
                 $input->required()
110
-                    ? 'ee-required-label ' . $input->html_label_class()
110
+                    ? 'ee-required-label '.$input->html_label_class()
111 111
                     : $input->html_label_class(),
112 112
                 $input->html_label_style(),
113 113
                 $input->other_html_attributes()
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      */
133 133
     public function layout_subsection($form_section)
134 134
     {
135
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
135
+        return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1);
136 136
     }
137 137
 
138 138
 
Please login to merge, or discard this patch.
display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php 2 patches
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -12,180 +12,180 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * enqueues css and js, so that this can be called statically
17
-     */
18
-    public static function enqueue_styles_and_scripts()
19
-    {
20
-        wp_register_style(
21
-            'checkbox_dropdown_selector',
22
-            EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css',
23
-            array('espresso_default'),
24
-            EVENT_ESPRESSO_VERSION
25
-        );
26
-        wp_register_style(
27
-            'espresso_default',
28
-            EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
29
-            array('dashicons'),
30
-            EVENT_ESPRESSO_VERSION
31
-        );
32
-        wp_enqueue_style('checkbox_dropdown_selector');
33
-        wp_register_script(
34
-            'checkbox_dropdown_selector',
35
-            EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js',
36
-            array('jquery'),
37
-            EVENT_ESPRESSO_VERSION,
38
-            true
39
-        );
40
-        wp_localize_script(
41
-            'ticket_selector',
42
-            'eeDTS',
43
-            array(
44
-                'maxChecked' => EE_Registry::instance()
45
-                    ->CFG
46
-                    ->template_settings
47
-                    ->EED_Ticket_Selector
48
-                    ->getDatetimeSelectorMaxChecked()
49
-            )
50
-        );
51
-        wp_enqueue_script('checkbox_dropdown_selector');
52
-    }
15
+	/**
16
+	 * enqueues css and js, so that this can be called statically
17
+	 */
18
+	public static function enqueue_styles_and_scripts()
19
+	{
20
+		wp_register_style(
21
+			'checkbox_dropdown_selector',
22
+			EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css',
23
+			array('espresso_default'),
24
+			EVENT_ESPRESSO_VERSION
25
+		);
26
+		wp_register_style(
27
+			'espresso_default',
28
+			EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
29
+			array('dashicons'),
30
+			EVENT_ESPRESSO_VERSION
31
+		);
32
+		wp_enqueue_style('checkbox_dropdown_selector');
33
+		wp_register_script(
34
+			'checkbox_dropdown_selector',
35
+			EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js',
36
+			array('jquery'),
37
+			EVENT_ESPRESSO_VERSION,
38
+			true
39
+		);
40
+		wp_localize_script(
41
+			'ticket_selector',
42
+			'eeDTS',
43
+			array(
44
+				'maxChecked' => EE_Registry::instance()
45
+					->CFG
46
+					->template_settings
47
+					->EED_Ticket_Selector
48
+					->getDatetimeSelectorMaxChecked()
49
+			)
50
+		);
51
+		wp_enqueue_script('checkbox_dropdown_selector');
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
58
-     */
59
-    public function enqueue_js()
60
-    {
61
-        EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
62
-    }
56
+	/**
57
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
58
+	 */
59
+	public function enqueue_js()
60
+	{
61
+		EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
62
+	}
63 63
 
64 64
 
65 65
 
66
-    /**
67
-     * callback for Iframe::addStylesheets() child class methods
68
-     *
69
-     * @param array $iframe_css
70
-     * @return array
71
-     */
72
-    public function iframe_css(array $iframe_css)
73
-    {
74
-        $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css';
75
-        return $iframe_css;
76
-    }
66
+	/**
67
+	 * callback for Iframe::addStylesheets() child class methods
68
+	 *
69
+	 * @param array $iframe_css
70
+	 * @return array
71
+	 */
72
+	public function iframe_css(array $iframe_css)
73
+	{
74
+		$iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css';
75
+		return $iframe_css;
76
+	}
77 77
 
78 78
 
79 79
 
80
-    /**
81
-     * callback for Iframe::addScripts() child class methods
82
-     *
83
-     * @param array $iframe_js
84
-     * @return array
85
-     */
86
-    public function iframe_js(array $iframe_js)
87
-    {
88
-        $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js';
89
-        return $iframe_js;
90
-    }
80
+	/**
81
+	 * callback for Iframe::addScripts() child class methods
82
+	 *
83
+	 * @param array $iframe_js
84
+	 * @return array
85
+	 */
86
+	public function iframe_js(array $iframe_js)
87
+	{
88
+		$iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js';
89
+		return $iframe_js;
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * @throws EE_Error
95
-     * @return string of html to display the field
96
-     */
97
-    public function display()
98
-    {
99
-        $input = $this->get_input();
100
-        $select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : '';
101
-        // $multi = count( $input->options() ) > 1 ? TRUE : FALSE;
102
-        $input->set_label_sizes();
103
-        $label_size_class = $input->get_label_size_class();
104
-        if (! is_array($input->raw_value()) && $input->raw_value() !== null) {
105
-            EE_Error::doing_it_wrong(
106
-                'EE_Checkbox_Display_Strategy::display()',
107
-                sprintf(
108
-                    esc_html__(
109
-                        '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"',
110
-                        'event_espresso'
111
-                    ),
112
-                    $input->html_id(),
113
-                    var_export($input->raw_value(), true),
114
-                    $input->html_name() . '[]'
115
-                ),
116
-                '4.8.1'
117
-            );
118
-        }
93
+	/**
94
+	 * @throws EE_Error
95
+	 * @return string of html to display the field
96
+	 */
97
+	public function display()
98
+	{
99
+		$input = $this->get_input();
100
+		$select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : '';
101
+		// $multi = count( $input->options() ) > 1 ? TRUE : FALSE;
102
+		$input->set_label_sizes();
103
+		$label_size_class = $input->get_label_size_class();
104
+		if (! is_array($input->raw_value()) && $input->raw_value() !== null) {
105
+			EE_Error::doing_it_wrong(
106
+				'EE_Checkbox_Display_Strategy::display()',
107
+				sprintf(
108
+					esc_html__(
109
+						'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"',
110
+						'event_espresso'
111
+					),
112
+					$input->html_id(),
113
+					var_export($input->raw_value(), true),
114
+					$input->html_name() . '[]'
115
+				),
116
+				'4.8.1'
117
+			);
118
+		}
119 119
 
120 120
 
121
-        $html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv');
122
-        $html .= '<button id="' . $input->html_id() . '-btn"';
123
-        // $html .= ' name="' . $input->html_name() . '"';
124
-        $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"';
125
-        $html .= ' style="' . $input->html_style() . '"';
126
-        $html .= ' data-target="' . $input->html_id() . '-options-dv"';
127
-        $html .= ' ' . $input->other_html_attributes() . '>';
128
-        $html .= '<span class="checkbox-dropdown-selector-selected-spn">';
129
-        $html .= $select_button_text;
130
-        $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>';
131
-        $html .= '</button>';
132
-        $html .= EEH_HTML::div(
133
-            '',
134
-            $input->html_id() . '-options-dv',
135
-            'checkbox-dropdown-selector'
136
-        );
137
-        $html .= EEH_HTML::link(
138
-            '',
139
-            '<span class="dashicons dashicons-no"></span>',
140
-            esc_html__('close datetime selector', 'event_espresso'),
141
-            '',
142
-            'close-espresso-notice'
143
-        );
144
-        $html .= EEH_HTML::ul();
145
-        $input_raw_value = (array) $input->raw_value();
146
-        foreach ($input->options() as $value => $display_text) {
147
-            $html .= EEH_HTML::li();
148
-            $value = $input->get_normalization_strategy()->unnormalize_one($value);
149
-            $html_id = $this->get_sub_input_id($value);
150
-            $html .= EEH_HTML::nl(0, 'checkbox');
151
-            $html .= '<label for="'
152
-                     . $html_id
153
-                     . '" id="'
154
-                     . $html_id
155
-                     . '-lbl" class="ee-checkbox-label-after'
156
-                     . $label_size_class
157
-                     . '">';
158
-            $html .= EEH_HTML::nl(1, 'checkbox');
159
-            $html .= '<input type="checkbox"';
160
-            $html .= ' name="' . $input->html_name() . '[]"';
161
-            $html .= ' id="' . $html_id . '"';
162
-            $html .= ' class="' . $input->html_class() . '-option"';
163
-            $html .= $input->html_style() ? ' style="' . $input->html_style() . '"' : '';
164
-            $html .= ' value="' . esc_attr($value) . '"';
165
-            $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true)
166
-                ? ' checked="checked"'
167
-                : '';
168
-            $html .= ' ' . $this->_input->other_html_attributes();
169
-            $html .= '>';
170
-            $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>';
171
-            $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>';
172
-            $html .= EEH_HTML::lix();
173
-        }
174
-        $html .= EEH_HTML::ulx();
175
-        $html .= EEH_HTML::divx();
176
-        $html .= EEH_HTML::divx();
177
-        $html .= EEH_HTML::p(
178
-            apply_filters(
179
-                'FHEE__EE_Checkbox_Dropdown_Selector_Display_Strategy__display__html',
180
-                esc_html__(
181
-                    'To view additional ticket options, click the "Filter by Date" button and select more dates.',
182
-                    'event_espresso'
183
-                )
184
-            ),
185
-            $input->html_id() . '-date-time-filter-notice-pg',
186
-            'date-time-filter-notice-pg small-text lt-grey-text'
187
-        );
188
-        $html .= \EEH_HTML::br();
189
-        return $html;
190
-    }
121
+		$html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv');
122
+		$html .= '<button id="' . $input->html_id() . '-btn"';
123
+		// $html .= ' name="' . $input->html_name() . '"';
124
+		$html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"';
125
+		$html .= ' style="' . $input->html_style() . '"';
126
+		$html .= ' data-target="' . $input->html_id() . '-options-dv"';
127
+		$html .= ' ' . $input->other_html_attributes() . '>';
128
+		$html .= '<span class="checkbox-dropdown-selector-selected-spn">';
129
+		$html .= $select_button_text;
130
+		$html .= '</span> <span class="dashicons dashicons-arrow-down"></span>';
131
+		$html .= '</button>';
132
+		$html .= EEH_HTML::div(
133
+			'',
134
+			$input->html_id() . '-options-dv',
135
+			'checkbox-dropdown-selector'
136
+		);
137
+		$html .= EEH_HTML::link(
138
+			'',
139
+			'<span class="dashicons dashicons-no"></span>',
140
+			esc_html__('close datetime selector', 'event_espresso'),
141
+			'',
142
+			'close-espresso-notice'
143
+		);
144
+		$html .= EEH_HTML::ul();
145
+		$input_raw_value = (array) $input->raw_value();
146
+		foreach ($input->options() as $value => $display_text) {
147
+			$html .= EEH_HTML::li();
148
+			$value = $input->get_normalization_strategy()->unnormalize_one($value);
149
+			$html_id = $this->get_sub_input_id($value);
150
+			$html .= EEH_HTML::nl(0, 'checkbox');
151
+			$html .= '<label for="'
152
+					 . $html_id
153
+					 . '" id="'
154
+					 . $html_id
155
+					 . '-lbl" class="ee-checkbox-label-after'
156
+					 . $label_size_class
157
+					 . '">';
158
+			$html .= EEH_HTML::nl(1, 'checkbox');
159
+			$html .= '<input type="checkbox"';
160
+			$html .= ' name="' . $input->html_name() . '[]"';
161
+			$html .= ' id="' . $html_id . '"';
162
+			$html .= ' class="' . $input->html_class() . '-option"';
163
+			$html .= $input->html_style() ? ' style="' . $input->html_style() . '"' : '';
164
+			$html .= ' value="' . esc_attr($value) . '"';
165
+			$html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true)
166
+				? ' checked="checked"'
167
+				: '';
168
+			$html .= ' ' . $this->_input->other_html_attributes();
169
+			$html .= '>';
170
+			$html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>';
171
+			$html .= EEH_HTML::nl(-1, 'checkbox') . '</label>';
172
+			$html .= EEH_HTML::lix();
173
+		}
174
+		$html .= EEH_HTML::ulx();
175
+		$html .= EEH_HTML::divx();
176
+		$html .= EEH_HTML::divx();
177
+		$html .= EEH_HTML::p(
178
+			apply_filters(
179
+				'FHEE__EE_Checkbox_Dropdown_Selector_Display_Strategy__display__html',
180
+				esc_html__(
181
+					'To view additional ticket options, click the "Filter by Date" button and select more dates.',
182
+					'event_espresso'
183
+				)
184
+			),
185
+			$input->html_id() . '-date-time-filter-notice-pg',
186
+			'date-time-filter-notice-pg small-text lt-grey-text'
187
+		);
188
+		$html .= \EEH_HTML::br();
189
+		return $html;
190
+	}
191 191
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -19,20 +19,20 @@  discard block
 block discarded – undo
19 19
     {
20 20
         wp_register_style(
21 21
             'checkbox_dropdown_selector',
22
-            EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css',
22
+            EE_GLOBAL_ASSETS_URL.'css/checkbox_dropdown_selector.css',
23 23
             array('espresso_default'),
24 24
             EVENT_ESPRESSO_VERSION
25 25
         );
26 26
         wp_register_style(
27 27
             'espresso_default',
28
-            EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
28
+            EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
29 29
             array('dashicons'),
30 30
             EVENT_ESPRESSO_VERSION
31 31
         );
32 32
         wp_enqueue_style('checkbox_dropdown_selector');
33 33
         wp_register_script(
34 34
             'checkbox_dropdown_selector',
35
-            EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js',
35
+            EE_GLOBAL_ASSETS_URL.'scripts/checkbox_dropdown_selector.js',
36 36
             array('jquery'),
37 37
             EVENT_ESPRESSO_VERSION,
38 38
             true
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function iframe_css(array $iframe_css)
73 73
     {
74
-        $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css';
74
+        $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL.'css/checkbox_dropdown_selector.css';
75 75
         return $iframe_css;
76 76
     }
77 77
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public function iframe_js(array $iframe_js)
87 87
     {
88
-        $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js';
88
+        $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL.'scripts/checkbox_dropdown_selector.js';
89 89
         return $iframe_js;
90 90
     }
91 91
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
         // $multi = count( $input->options() ) > 1 ? TRUE : FALSE;
102 102
         $input->set_label_sizes();
103 103
         $label_size_class = $input->get_label_size_class();
104
-        if (! is_array($input->raw_value()) && $input->raw_value() !== null) {
104
+        if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) {
105 105
             EE_Error::doing_it_wrong(
106 106
                 'EE_Checkbox_Display_Strategy::display()',
107 107
                 sprintf(
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
                     ),
112 112
                     $input->html_id(),
113 113
                     var_export($input->raw_value(), true),
114
-                    $input->html_name() . '[]'
114
+                    $input->html_name().'[]'
115 115
                 ),
116 116
                 '4.8.1'
117 117
             );
@@ -119,19 +119,19 @@  discard block
 block discarded – undo
119 119
 
120 120
 
121 121
         $html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv');
122
-        $html .= '<button id="' . $input->html_id() . '-btn"';
122
+        $html .= '<button id="'.$input->html_id().'-btn"';
123 123
         // $html .= ' name="' . $input->html_name() . '"';
124
-        $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"';
125
-        $html .= ' style="' . $input->html_style() . '"';
126
-        $html .= ' data-target="' . $input->html_id() . '-options-dv"';
127
-        $html .= ' ' . $input->other_html_attributes() . '>';
124
+        $html .= ' class="'.$input->html_class().' checkbox-dropdown-selector-btn button-secondary button"';
125
+        $html .= ' style="'.$input->html_style().'"';
126
+        $html .= ' data-target="'.$input->html_id().'-options-dv"';
127
+        $html .= ' '.$input->other_html_attributes().'>';
128 128
         $html .= '<span class="checkbox-dropdown-selector-selected-spn">';
129 129
         $html .= $select_button_text;
130 130
         $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>';
131 131
         $html .= '</button>';
132 132
         $html .= EEH_HTML::div(
133 133
             '',
134
-            $input->html_id() . '-options-dv',
134
+            $input->html_id().'-options-dv',
135 135
             'checkbox-dropdown-selector'
136 136
         );
137 137
         $html .= EEH_HTML::link(
@@ -157,18 +157,18 @@  discard block
 block discarded – undo
157 157
                      . '">';
158 158
             $html .= EEH_HTML::nl(1, 'checkbox');
159 159
             $html .= '<input type="checkbox"';
160
-            $html .= ' name="' . $input->html_name() . '[]"';
161
-            $html .= ' id="' . $html_id . '"';
162
-            $html .= ' class="' . $input->html_class() . '-option"';
163
-            $html .= $input->html_style() ? ' style="' . $input->html_style() . '"' : '';
164
-            $html .= ' value="' . esc_attr($value) . '"';
160
+            $html .= ' name="'.$input->html_name().'[]"';
161
+            $html .= ' id="'.$html_id.'"';
162
+            $html .= ' class="'.$input->html_class().'-option"';
163
+            $html .= $input->html_style() ? ' style="'.$input->html_style().'"' : '';
164
+            $html .= ' value="'.esc_attr($value).'"';
165 165
             $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true)
166 166
                 ? ' checked="checked"'
167 167
                 : '';
168
-            $html .= ' ' . $this->_input->other_html_attributes();
168
+            $html .= ' '.$this->_input->other_html_attributes();
169 169
             $html .= '>';
170
-            $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>';
171
-            $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>';
170
+            $html .= '<span class="datetime-selector-option-text-spn">'.$display_text.'</span>';
171
+            $html .= EEH_HTML::nl(-1, 'checkbox').'</label>';
172 172
             $html .= EEH_HTML::lix();
173 173
         }
174 174
         $html .= EEH_HTML::ulx();
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
                     'event_espresso'
183 183
                 )
184 184
             ),
185
-            $input->html_id() . '-date-time-filter-notice-pg',
185
+            $input->html_id().'-date-time-filter-notice-pg',
186 186
             'date-time-filter-notice-pg small-text lt-grey-text'
187 187
         );
188 188
         $html .= \EEH_HTML::br();
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Form_Input_Base.input.php 2 patches
Indentation   +1253 added lines, -1253 removed lines patch added patch discarded remove patch
@@ -11,1257 +11,1257 @@
 block discarded – undo
11 11
 abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable
12 12
 {
13 13
 
14
-    /**
15
-     * the input's name attribute
16
-     *
17
-     * @var string
18
-     */
19
-    protected $_html_name;
20
-
21
-    /**
22
-     * id for the html label tag
23
-     *
24
-     * @var string
25
-     */
26
-    protected $_html_label_id;
27
-
28
-    /**
29
-     * class for teh html label tag
30
-     *
31
-     * @var string
32
-     */
33
-    protected $_html_label_class;
34
-
35
-    /**
36
-     * style for teh html label tag
37
-     *
38
-     * @var string
39
-     */
40
-    protected $_html_label_style;
41
-
42
-    /**
43
-     * text to be placed in the html label
44
-     *
45
-     * @var string
46
-     */
47
-    protected $_html_label_text;
48
-
49
-    /**
50
-     * the full html label. If used, all other html_label_* properties are invalid
51
-     *
52
-     * @var string
53
-     */
54
-    protected $_html_label;
55
-
56
-    /**
57
-     * HTML to use for help text (normally placed below form input), in a span which normally
58
-     * has a class of 'description'
59
-     *
60
-     * @var string
61
-     */
62
-    protected $_html_help_text;
63
-
64
-    /**
65
-     * CSS classes for displaying the help span
66
-     *
67
-     * @var string
68
-     */
69
-    protected $_html_help_class = 'description';
70
-
71
-    /**
72
-     * CSS to put in the style attribute on the help span
73
-     *
74
-     * @var string
75
-     */
76
-    protected $_html_help_style;
77
-
78
-    /**
79
-     * Stores whether or not this input's response is required.
80
-     * Because certain styling elements may also want to know that this
81
-     * input is required etc.
82
-     *
83
-     * @var boolean
84
-     */
85
-    protected $_required;
86
-
87
-    /**
88
-     * css class added to required inputs
89
-     *
90
-     * @var string
91
-     */
92
-    protected $_required_css_class = 'ee-required';
93
-
94
-    /**
95
-     * css styles applied to button type inputs
96
-     *
97
-     * @var string
98
-     */
99
-    protected $_button_css_attributes;
100
-
101
-    /**
102
-     * The raw data submitted for this, like in the $_POST super global.
103
-     * Generally unsafe for usage in client code
104
-     *
105
-     * @var mixed string or array
106
-     */
107
-    protected $_raw_value;
108
-
109
-    /**
110
-     * Value normalized according to the input's normalization strategy.
111
-     * The normalization strategy dictates whether this is a string, int, float,
112
-     * boolean, or array of any of those.
113
-     *
114
-     * @var mixed
115
-     */
116
-    protected $_normalized_value;
117
-
118
-
119
-    /**
120
-     * Normalized default value either initially set on the input, or provided by calling
121
-     * set_default().
122
-     * @var mixed
123
-     */
124
-    protected $_default;
125
-
126
-    /**
127
-     * Strategy used for displaying this field.
128
-     * Child classes must use _get_display_strategy to access it.
129
-     *
130
-     * @var EE_Display_Strategy_Base
131
-     */
132
-    private $_display_strategy;
133
-
134
-    /**
135
-     * Gets all the validation strategies used on this field
136
-     *
137
-     * @var EE_Validation_Strategy_Base[]
138
-     */
139
-    private $_validation_strategies = array();
140
-
141
-    /**
142
-     * The normalization strategy for this field
143
-     *
144
-     * @var EE_Normalization_Strategy_Base
145
-     */
146
-    private $_normalization_strategy;
147
-
148
-    /**
149
-     * Strategy for removing sensitive data after we're done with the form input
150
-     *
151
-     * @var EE_Sensitive_Data_Removal_Base
152
-     */
153
-    protected $_sensitive_data_removal_strategy;
154
-
155
-    /**
156
-     * Whether this input has been disabled or not.
157
-     * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled.
158
-     * (Client-side code that wants to dynamically disable it must also add this hidden input).
159
-     * When the form is submitted, if the input is disabled in the PHP formsection, then input is ignored.
160
-     * If the input is missing from the $_REQUEST data but the hidden input indicating the input is disabled, then the input is again ignored.
161
-     *
162
-     * @var boolean
163
-     */
164
-    protected $disabled = false;
165
-
166
-
167
-
168
-    /**
169
-     * @param array                         $input_args       {
170
-     * @type string                         $html_name        the html name for the input
171
-     * @type string                         $html_label_id    the id attribute to give to the html label tag
172
-     * @type string                         $html_label_class the class attribute to give to the html label tag
173
-     * @type string                         $html_label_style the style attribute to give ot teh label tag
174
-     * @type string                         $html_label_text  the text to put in the label tag
175
-     * @type string                         $html_label       the full html label. If used,
176
-     *                                                        all other html_label_* args are invalid
177
-     * @type string                         $html_help_text   text to put in help element
178
-     * @type string                         $html_help_style  style attribute to give to teh help element
179
-     * @type string                         $html_help_class  class attribute to give to the help element
180
-     * @type string                         $default          default value NORMALIZED (eg, if providing the default
181
-     *       for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0')
182
-     * @type EE_Display_Strategy_Base       $display          strategy
183
-     * @type EE_Normalization_Strategy_Base $normalization_strategy
184
-     * @type EE_Validation_Strategy_Base[]  $validation_strategies
185
-     * @type boolean                        $ignore_input special argument which can be used to avoid adding any validation strategies,
186
-     *                                                    and sets the normalization strategy to the Null normalization. This is good
187
-     *                                                    when you want the input to be totally ignored server-side (like when using
188
-     *                                                    React.js form inputs)
189
-     *                                                        }
190
-     */
191
-    public function __construct($input_args = array())
192
-    {
193
-        $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
194
-        // the following properties must be cast as arrays
195
-        if (isset($input_args['validation_strategies'])) {
196
-            foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
197
-                if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
198
-                    $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
199
-                }
200
-            }
201
-            unset($input_args['validation_strategies']);
202
-        }
203
-        if (isset($input_args['ignore_input'])) {
204
-            $this->_validation_strategies = array();
205
-        }
206
-        // loop thru incoming options
207
-        foreach ($input_args as $key => $value) {
208
-            // add underscore to $key to match property names
209
-            $_key = '_' . $key;
210
-            if (property_exists($this, $_key)) {
211
-                $this->{$_key} = $value;
212
-            }
213
-        }
214
-        // ensure that "required" is set correctly
215
-        $this->set_required(
216
-            $this->_required,
217
-            isset($input_args['required_validation_error_message'])
218
-            ? $input_args['required_validation_error_message']
219
-            : null
220
-        );
221
-        // $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
222
-        $this->_display_strategy->_construct_finalize($this);
223
-        foreach ($this->_validation_strategies as $validation_strategy) {
224
-            $validation_strategy->_construct_finalize($this);
225
-        }
226
-        if (isset($input_args['ignore_input'])) {
227
-            $this->_normalization_strategy = new EE_Null_Normalization();
228
-        }
229
-        if (! $this->_normalization_strategy) {
230
-                $this->_normalization_strategy = new EE_Text_Normalization();
231
-        }
232
-        $this->_normalization_strategy->_construct_finalize($this);
233
-        // at least we can use the normalization strategy to populate the default
234
-        if (isset($input_args['default'])) {
235
-            $this->set_default($input_args['default']);
236
-            unset($input_args['default']);
237
-        }
238
-        if (! $this->_sensitive_data_removal_strategy) {
239
-            $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
240
-        }
241
-        $this->_sensitive_data_removal_strategy->_construct_finalize($this);
242
-        parent::__construct($input_args);
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * Sets the html_name to its default value, if none was specified in teh constructor.
249
-     * Calculation involves using the name and the parent's html_name
250
-     *
251
-     * @throws \EE_Error
252
-     */
253
-    protected function _set_default_html_name_if_empty()
254
-    {
255
-        if (! $this->_html_name) {
256
-            $this->_html_name = $this->name();
257
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
258
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
259
-            }
260
-        }
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @param $parent_form_section
267
-     * @param $name
268
-     * @throws \EE_Error
269
-     */
270
-    public function _construct_finalize($parent_form_section, $name)
271
-    {
272
-        parent::_construct_finalize($parent_form_section, $name);
273
-        if ($this->_html_label === null && $this->_html_label_text === null) {
274
-            $this->_html_label_text = ucwords(str_replace("_", " ", $name));
275
-        }
276
-        do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * Returns the strategy for displaying this form input. If none is set, throws an exception.
283
-     *
284
-     * @return EE_Display_Strategy_Base
285
-     * @throws EE_Error
286
-     */
287
-    protected function _get_display_strategy()
288
-    {
289
-        $this->ensure_construct_finalized_called();
290
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
291
-            throw new EE_Error(
292
-                sprintf(
293
-                    __(
294
-                        "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
295
-                        "event_espresso"
296
-                    ),
297
-                    $this->html_name(),
298
-                    $this->html_id()
299
-                )
300
-            );
301
-        } else {
302
-            return $this->_display_strategy;
303
-        }
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * Sets the display strategy.
310
-     *
311
-     * @param EE_Display_Strategy_Base $strategy
312
-     */
313
-    protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
314
-    {
315
-        $this->_display_strategy = $strategy;
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * Sets the sanitization strategy
322
-     *
323
-     * @param EE_Normalization_Strategy_Base $strategy
324
-     */
325
-    protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
326
-    {
327
-        $this->_normalization_strategy = $strategy;
328
-    }
329
-
330
-
331
-
332
-    /**
333
-     * Gets sensitive_data_removal_strategy
334
-     *
335
-     * @return EE_Sensitive_Data_Removal_Base
336
-     */
337
-    public function get_sensitive_data_removal_strategy()
338
-    {
339
-        return $this->_sensitive_data_removal_strategy;
340
-    }
341
-
342
-
343
-
344
-    /**
345
-     * Sets sensitive_data_removal_strategy
346
-     *
347
-     * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
348
-     * @return boolean
349
-     */
350
-    public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
351
-    {
352
-        $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * Gets the display strategy for this input
359
-     *
360
-     * @return EE_Display_Strategy_Base
361
-     */
362
-    public function get_display_strategy()
363
-    {
364
-        return $this->_display_strategy;
365
-    }
366
-
367
-
368
-
369
-    /**
370
-     * Overwrites the display strategy
371
-     *
372
-     * @param EE_Display_Strategy_Base $display_strategy
373
-     */
374
-    public function set_display_strategy($display_strategy)
375
-    {
376
-        $this->_display_strategy = $display_strategy;
377
-        $this->_display_strategy->_construct_finalize($this);
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * Gets the normalization strategy set on this input
384
-     *
385
-     * @return EE_Normalization_Strategy_Base
386
-     */
387
-    public function get_normalization_strategy()
388
-    {
389
-        return $this->_normalization_strategy;
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * Overwrites the normalization strategy
396
-     *
397
-     * @param EE_Normalization_Strategy_Base $normalization_strategy
398
-     */
399
-    public function set_normalization_strategy($normalization_strategy)
400
-    {
401
-        $this->_normalization_strategy = $normalization_strategy;
402
-        $this->_normalization_strategy->_construct_finalize($this);
403
-    }
404
-
405
-
406
-
407
-    /**
408
-     * Returns all teh validation strategies which apply to this field, numerically indexed
409
-     *
410
-     * @return EE_Validation_Strategy_Base[]
411
-     */
412
-    public function get_validation_strategies()
413
-    {
414
-        return $this->_validation_strategies;
415
-    }
416
-
417
-
418
-
419
-    /**
420
-     * Adds this strategy to the field so it will be used in both JS validation and server-side validation
421
-     *
422
-     * @param EE_Validation_Strategy_Base $validation_strategy
423
-     * @return void
424
-     */
425
-    protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
426
-    {
427
-        $validation_strategy->_construct_finalize($this);
428
-        $this->_validation_strategies[] = $validation_strategy;
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * Adds a new validation strategy onto the form input
435
-     *
436
-     * @param EE_Validation_Strategy_Base $validation_strategy
437
-     * @return void
438
-     */
439
-    public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
440
-    {
441
-        $this->_add_validation_strategy($validation_strategy);
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     * The classname of the validation strategy to remove
448
-     *
449
-     * @param string $validation_strategy_classname
450
-     */
451
-    public function remove_validation_strategy($validation_strategy_classname)
452
-    {
453
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
454
-            if ($validation_strategy instanceof $validation_strategy_classname
455
-                || is_subclass_of($validation_strategy, $validation_strategy_classname)
456
-            ) {
457
-                unset($this->_validation_strategies[ $key ]);
458
-            }
459
-        }
460
-    }
461
-
462
-
463
-
464
-    /**
465
-     * returns true if input employs any of the validation strategy defined by the supplied array of classnames
466
-     *
467
-     * @param array $validation_strategy_classnames
468
-     * @return bool
469
-     */
470
-    public function has_validation_strategy($validation_strategy_classnames)
471
-    {
472
-        $validation_strategy_classnames = is_array($validation_strategy_classnames)
473
-            ? $validation_strategy_classnames
474
-            : array($validation_strategy_classnames);
475
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
476
-            if (in_array($key, $validation_strategy_classnames)) {
477
-                return true;
478
-            }
479
-        }
480
-        return false;
481
-    }
482
-
483
-
484
-
485
-    /**
486
-     * Gets the HTML
487
-     *
488
-     * @return string
489
-     */
490
-    public function get_html()
491
-    {
492
-        return $this->_parent_section->get_html_for_input($this);
493
-    }
494
-
495
-
496
-
497
-    /**
498
-     * Gets the HTML for the input itself (no label or errors) according to the
499
-     * input's display strategy
500
-     * Makes sure the JS and CSS are enqueued for it
501
-     *
502
-     * @return string
503
-     * @throws \EE_Error
504
-     */
505
-    public function get_html_for_input()
506
-    {
507
-        return $this->_form_html_filter
508
-            ? $this->_form_html_filter->filterHtml(
509
-                $this->_get_display_strategy()->display(),
510
-                $this
511
-            )
512
-            : $this->_get_display_strategy()->display();
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     * @return string
519
-     */
520
-    public function html_other_attributes()
521
-    {
522
-        EE_Error::doing_it_wrong(
523
-            __METHOD__,
524
-            sprintf(
525
-                esc_html__(
526
-                    'This method is no longer in use. You should replace it by %s',
527
-                    'event_espresso'
528
-                ),
529
-                'EE_Form_Section_Base::other_html_attributes()'
530
-            ),
531
-            '$VID:$'
532
-        );
533
-
534
-        return $this->other_html_attributes();
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * @param string $html_other_attributes
541
-     */
542
-    public function set_html_other_attributes($html_other_attributes)
543
-    {
544
-        EE_Error::doing_it_wrong(
545
-            __METHOD__,
546
-            sprintf(
547
-                esc_html__(
548
-                    'This method is no longer in use. You should replace it by %s',
549
-                    'event_espresso'
550
-                ),
551
-                'EE_Form_Section_Base::set_other_html_attributes()'
552
-            ),
553
-            '$VID:$'
554
-        );
555
-
556
-        $this->set_other_html_attributes($html_other_attributes);
557
-    }
558
-
559
-
560
-
561
-    /**
562
-     * Gets the HTML for displaying the label for this form input
563
-     * according to the form section's layout strategy
564
-     *
565
-     * @return string
566
-     */
567
-    public function get_html_for_label()
568
-    {
569
-        return $this->_parent_section->get_layout_strategy()->display_label($this);
570
-    }
571
-
572
-
573
-
574
-    /**
575
-     * Gets the HTML for displaying the errors section for this form input
576
-     * according to the form section's layout strategy
577
-     *
578
-     * @return string
579
-     */
580
-    public function get_html_for_errors()
581
-    {
582
-        return $this->_parent_section->get_layout_strategy()->display_errors($this);
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     * Gets the HTML for displaying the help text for this form input
589
-     * according to the form section's layout strategy
590
-     *
591
-     * @return string
592
-     */
593
-    public function get_html_for_help()
594
-    {
595
-        return $this->_parent_section->get_layout_strategy()->display_help_text($this);
596
-    }
597
-
598
-
599
-
600
-    /**
601
-     * Validates the input's sanitized value (assumes _sanitize() has already been called)
602
-     * and returns whether or not the form input's submitted value is value
603
-     *
604
-     * @return boolean
605
-     */
606
-    protected function _validate()
607
-    {
608
-        if ($this->isDisabled()) {
609
-            return true;
610
-        }
611
-        foreach ($this->_validation_strategies as $validation_strategy) {
612
-            if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
613
-                try {
614
-                    $validation_strategy->validate($this->normalized_value());
615
-                } catch (EE_Validation_Error $e) {
616
-                    $this->add_validation_error($e);
617
-                }
618
-            }
619
-        }
620
-        if ($this->get_validation_errors()) {
621
-            return false;
622
-        } else {
623
-            return true;
624
-        }
625
-    }
626
-
627
-
628
-
629
-    /**
630
-     * Performs basic sanitization on this value. But what sanitization can be performed anyways?
631
-     * This value MIGHT be allowed to have tags, so we can't really remove them.
632
-     *
633
-     * @param string $value
634
-     * @return null|string
635
-     */
636
-    protected function _sanitize($value)
637
-    {
638
-        return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null;
639
-    }
640
-
641
-
642
-
643
-    /**
644
-     * Picks out the form value that relates to this form input,
645
-     * and stores it as the sanitized value on the form input, and sets the normalized value.
646
-     * Returns whether or not any validation errors occurred
647
-     *
648
-     * @param array $req_data like $_POST
649
-     * @return boolean whether or not there was an error
650
-     * @throws \EE_Error
651
-     */
652
-    protected function _normalize($req_data)
653
-    {
654
-        // any existing validation errors don't apply so clear them
655
-        $this->_validation_errors = array();
656
-        // if the input is disabled, ignore whatever input was sent in
657
-        if ($this->isDisabled()) {
658
-            $this->_set_raw_value(null);
659
-            $this->_set_normalized_value($this->get_default());
660
-            return false;
661
-        }
662
-        try {
663
-            $raw_input = $this->find_form_data_for_this_section($req_data);
664
-            // super simple sanitization for now
665
-            if (is_array($raw_input)) {
666
-                $raw_value = array();
667
-                foreach ($raw_input as $key => $value) {
668
-                    $raw_value[ $key ] = $this->_sanitize($value);
669
-                }
670
-                $this->_set_raw_value($raw_value);
671
-            } else {
672
-                $this->_set_raw_value($this->_sanitize($raw_input));
673
-            }
674
-            // we want to mostly leave the input alone in case we need to re-display it to the user
675
-            $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
676
-            return false;
677
-        } catch (EE_Validation_Error $e) {
678
-            $this->add_validation_error($e);
679
-            return true;
680
-        }
681
-    }
682
-
683
-
684
-
685
-    /**
686
-     * @return string
687
-     */
688
-    public function html_name()
689
-    {
690
-        $this->_set_default_html_name_if_empty();
691
-        return $this->_html_name;
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * @return string
698
-     */
699
-    public function html_label_id()
700
-    {
701
-        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
702
-    }
703
-
704
-
705
-
706
-    /**
707
-     * @return string
708
-     */
709
-    public function html_label_class()
710
-    {
711
-        return $this->_html_label_class;
712
-    }
713
-
714
-
715
-
716
-    /**
717
-     * @return string
718
-     */
719
-    public function html_label_style()
720
-    {
721
-        return $this->_html_label_style;
722
-    }
723
-
724
-
725
-
726
-    /**
727
-     * @return string
728
-     */
729
-    public function html_label_text()
730
-    {
731
-        return $this->_html_label_text;
732
-    }
733
-
734
-
735
-
736
-    /**
737
-     * @return string
738
-     */
739
-    public function html_help_text()
740
-    {
741
-        return $this->_html_help_text;
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * @return string
748
-     */
749
-    public function html_help_class()
750
-    {
751
-        return $this->_html_help_class;
752
-    }
753
-
754
-
755
-
756
-    /**
757
-     * @return string
758
-     */
759
-    public function html_help_style()
760
-    {
761
-        return $this->_html_style;
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
768
-     * Please note that almost all client code should instead use the normalized_value;
769
-     * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
770
-     * mostly by escaping quotes)
771
-     * Note, we do not store the exact original value sent in the user's request because
772
-     * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
773
-     * in which case, we would have stored the malicious content to our database.
774
-     *
775
-     * @return string
776
-     */
777
-    public function raw_value()
778
-    {
779
-        return $this->_raw_value;
780
-    }
781
-
782
-
783
-
784
-    /**
785
-     * Returns a string safe to usage in form inputs when displaying, because
786
-     * it escapes all html entities
787
-     *
788
-     * @return string
789
-     */
790
-    public function raw_value_in_form()
791
-    {
792
-        return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8');
793
-    }
794
-
795
-
796
-
797
-    /**
798
-     * returns the value after it's been sanitized, and then converted into it's proper type
799
-     * in PHP. Eg, a string, an int, an array,
800
-     *
801
-     * @return mixed
802
-     */
803
-    public function normalized_value()
804
-    {
805
-        return $this->_normalized_value;
806
-    }
807
-
808
-
809
-
810
-    /**
811
-     * Returns the normalized value is a presentable way. By default this is just
812
-     * the normalized value by itself, but it can be overridden for when that's not
813
-     * the best thing to display
814
-     *
815
-     * @return string
816
-     */
817
-    public function pretty_value()
818
-    {
819
-        return $this->_normalized_value;
820
-    }
821
-
822
-
823
-
824
-    /**
825
-     * When generating the JS for the jquery validation rules like<br>
826
-     * <code>$( "#myform" ).validate({
827
-     * rules: {
828
-     * password: "required",
829
-     * password_again: {
830
-     * equalTo: "#password"
831
-     * }
832
-     * }
833
-     * });</code>
834
-     * if this field had the name 'password_again', it should return
835
-     * <br><code>password_again: {
836
-     * equalTo: "#password"
837
-     * }</code>
838
-     *
839
-     * @return array
840
-     */
841
-    public function get_jquery_validation_rules()
842
-    {
843
-        $jquery_validation_js = array();
844
-        $jquery_validation_rules = array();
845
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
846
-            $jquery_validation_rules = array_replace_recursive(
847
-                $jquery_validation_rules,
848
-                $validation_strategy->get_jquery_validation_rule_array()
849
-            );
850
-        }
851
-        if (! empty($jquery_validation_rules)) {
852
-            foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
853
-                $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
854
-            }
855
-        }
856
-        return $jquery_validation_js;
857
-    }
858
-
859
-
860
-
861
-    /**
862
-     * Sets the input's default value for use in displaying in the form. Note: value should be
863
-     * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
864
-     *
865
-     * @param mixed $value
866
-     * @return void
867
-     */
868
-    public function set_default($value)
869
-    {
870
-        $this->_default = $value;
871
-        $this->_set_normalized_value($value);
872
-        $this->_set_raw_value($value);
873
-    }
874
-
875
-
876
-
877
-    /**
878
-     * Sets the normalized value on this input
879
-     *
880
-     * @param mixed $value
881
-     */
882
-    protected function _set_normalized_value($value)
883
-    {
884
-        $this->_normalized_value = $value;
885
-    }
886
-
887
-
888
-
889
-    /**
890
-     * Sets the raw value on this input (ie, exactly as the user submitted it)
891
-     *
892
-     * @param mixed $value
893
-     */
894
-    protected function _set_raw_value($value)
895
-    {
896
-        $this->_raw_value = $this->_normalization_strategy->unnormalize($value);
897
-    }
898
-
899
-
900
-
901
-    /**
902
-     * Sets the HTML label text after it has already been defined
903
-     *
904
-     * @param string $label
905
-     * @return void
906
-     */
907
-    public function set_html_label_text($label)
908
-    {
909
-        $this->_html_label_text = $label;
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     * Sets whether or not this field is required, and adjusts the validation strategy.
916
-     * If you want to use the EE_Conditionally_Required_Validation_Strategy,
917
-     * please add it as a validation strategy using add_validation_strategy as normal
918
-     *
919
-     * @param boolean $required boolean
920
-     * @param null    $required_text
921
-     */
922
-    public function set_required($required = true, $required_text = null)
923
-    {
924
-        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
925
-        // whether $required is a string or a boolean, we want to add a required validation strategy
926
-        if ($required) {
927
-            $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
928
-        } else {
929
-            $this->remove_validation_strategy('EE_Required_Validation_Strategy');
930
-        }
931
-        $this->_required = $required;
932
-    }
933
-
934
-
935
-
936
-    /**
937
-     * Returns whether or not this field is required
938
-     *
939
-     * @return boolean
940
-     */
941
-    public function required()
942
-    {
943
-        return $this->_required;
944
-    }
945
-
946
-
947
-
948
-    /**
949
-     * @param string $required_css_class
950
-     */
951
-    public function set_required_css_class($required_css_class)
952
-    {
953
-        $this->_required_css_class = $required_css_class;
954
-    }
955
-
956
-
957
-
958
-    /**
959
-     * @return string
960
-     */
961
-    public function required_css_class()
962
-    {
963
-        return $this->_required_css_class;
964
-    }
965
-
966
-
967
-
968
-    /**
969
-     * @param bool $add_required
970
-     * @return string
971
-     */
972
-    public function html_class($add_required = false)
973
-    {
974
-        return $add_required && $this->required()
975
-            ? $this->required_css_class() . ' ' . $this->_html_class
976
-            : $this->_html_class;
977
-    }
978
-
979
-
980
-    /**
981
-     * Sets the help text, in case
982
-     *
983
-     * @param string $text
984
-     */
985
-    public function set_html_help_text($text)
986
-    {
987
-        $this->_html_help_text = $text;
988
-    }
989
-
990
-
991
-
992
-    /**
993
-     * Uses the sensitive data removal strategy to remove the sensitive data from this
994
-     * input. If there is any kind of sensitive data removal on this input, we clear
995
-     * out the raw value completely
996
-     *
997
-     * @return void
998
-     */
999
-    public function clean_sensitive_data()
1000
-    {
1001
-        // if we do ANY kind of sensitive data removal on this, then just clear out the raw value
1002
-        // if we need more logic than this we'll make a strategy for it
1003
-        if ($this->_sensitive_data_removal_strategy
1004
-            && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
1005
-        ) {
1006
-            $this->_set_raw_value(null);
1007
-        }
1008
-        // and clean the normalized value according to the appropriate strategy
1009
-        $this->_set_normalized_value(
1010
-            $this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
1011
-                $this->_normalized_value
1012
-            )
1013
-        );
1014
-    }
1015
-
1016
-
1017
-
1018
-    /**
1019
-     * @param bool   $primary
1020
-     * @param string $button_size
1021
-     * @param string $other_attributes
1022
-     */
1023
-    public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
1024
-    {
1025
-        $button_css_attributes = 'button';
1026
-        $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary';
1027
-        switch ($button_size) {
1028
-            case 'xs':
1029
-            case 'extra-small':
1030
-                $button_css_attributes .= ' button-xs';
1031
-                break;
1032
-            case 'sm':
1033
-            case 'small':
1034
-                $button_css_attributes .= ' button-sm';
1035
-                break;
1036
-            case 'lg':
1037
-            case 'large':
1038
-                $button_css_attributes .= ' button-lg';
1039
-                break;
1040
-            case 'block':
1041
-                $button_css_attributes .= ' button-block';
1042
-                break;
1043
-            case 'md':
1044
-            case 'medium':
1045
-            default:
1046
-                $button_css_attributes .= '';
1047
-        }
1048
-        $this->_button_css_attributes .= ! empty($other_attributes)
1049
-            ? $button_css_attributes . ' ' . $other_attributes
1050
-            : $button_css_attributes;
1051
-    }
1052
-
1053
-
1054
-
1055
-    /**
1056
-     * @return string
1057
-     */
1058
-    public function button_css_attributes()
1059
-    {
1060
-        if (empty($this->_button_css_attributes)) {
1061
-            $this->set_button_css_attributes();
1062
-        }
1063
-        return $this->_button_css_attributes;
1064
-    }
1065
-
1066
-
1067
-
1068
-    /**
1069
-     * find_form_data_for_this_section
1070
-     * using this section's name and its parents, finds the value of the form data that corresponds to it.
1071
-     * For example, if this form section's HTML name is my_form[subform][form_input_1],
1072
-     * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1'].
1073
-     * (If that doesn't exist, we also check for this subsection's name
1074
-     * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].)
1075
-     * This function finds its value in the form.
1076
-     *
1077
-     * @param array $req_data
1078
-     * @return mixed whatever the raw value of this form section is in the request data
1079
-     * @throws \EE_Error
1080
-     */
1081
-    public function find_form_data_for_this_section($req_data)
1082
-    {
1083
-        $name_parts = $this->getInputNameParts();
1084
-        // now get the value for the input
1085
-        $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1086
-        // check if this thing's name is at the TOP level of the request data
1087
-        if ($value === null && isset($req_data[ $this->name() ])) {
1088
-            $value = $req_data[ $this->name() ];
1089
-        }
1090
-        return $value;
1091
-    }
1092
-
1093
-
1094
-
1095
-    /**
1096
-     * If this input's name is something like "foo[bar][baz]"
1097
-     * returns an array like `array('foo','bar',baz')`
1098
-     * @return array
1099
-     */
1100
-    protected function getInputNameParts()
1101
-    {
1102
-        // break up the html name by "[]"
1103
-        if (strpos($this->html_name(), '[') !== false) {
1104
-            $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '['));
1105
-        } else {
1106
-            $before_any_brackets = $this->html_name();
1107
-        }
1108
-        // grab all of the segments
1109
-        preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches);
1110
-        if (isset($matches[1]) && is_array($matches[1])) {
1111
-            $name_parts = $matches[1];
1112
-            array_unshift($name_parts, $before_any_brackets);
1113
-        } else {
1114
-            $name_parts = array($before_any_brackets);
1115
-        }
1116
-        return $name_parts;
1117
-    }
1118
-
1119
-
1120
-
1121
-    /**
1122
-     * @param array $html_name_parts
1123
-     * @param array $req_data
1124
-     * @return array | NULL
1125
-     */
1126
-    public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1127
-    {
1128
-        $first_part_to_consider = array_shift($html_name_parts);
1129
-        if (isset($req_data[ $first_part_to_consider ])) {
1130
-            if (empty($html_name_parts)) {
1131
-                return $req_data[ $first_part_to_consider ];
1132
-            } else {
1133
-                return $this->findRequestForSectionUsingNameParts(
1134
-                    $html_name_parts,
1135
-                    $req_data[ $first_part_to_consider ]
1136
-                );
1137
-            }
1138
-        } else {
1139
-            return null;
1140
-        }
1141
-    }
1142
-
1143
-
1144
-
1145
-    /**
1146
-     * Checks if this form input's data is in the request data
1147
-     *
1148
-     * @param array $req_data like $_POST
1149
-     * @return boolean
1150
-     * @throws \EE_Error
1151
-     */
1152
-    public function form_data_present_in($req_data = null)
1153
-    {
1154
-        if ($req_data === null) {
1155
-            $req_data = $_POST;
1156
-        }
1157
-        $checked_value = $this->find_form_data_for_this_section($req_data);
1158
-        if ($checked_value !== null) {
1159
-            return true;
1160
-        } else {
1161
-            return false;
1162
-        }
1163
-    }
1164
-
1165
-
1166
-
1167
-    /**
1168
-     * Overrides parent to add js data from validation and display strategies
1169
-     *
1170
-     * @param array $form_other_js_data
1171
-     * @return array
1172
-     */
1173
-    public function get_other_js_data($form_other_js_data = array())
1174
-    {
1175
-        $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data);
1176
-        return $form_other_js_data;
1177
-    }
1178
-
1179
-
1180
-
1181
-    /**
1182
-     * Gets other JS data for localization from this input's strategies, like
1183
-     * the validation strategies and the display strategy
1184
-     *
1185
-     * @param array $form_other_js_data
1186
-     * @return array
1187
-     */
1188
-    public function get_other_js_data_from_strategies($form_other_js_data = array())
1189
-    {
1190
-        $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1191
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1192
-            $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1193
-        }
1194
-        return $form_other_js_data;
1195
-    }
1196
-
1197
-
1198
-
1199
-    /**
1200
-     * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1201
-     *
1202
-     * @return void
1203
-     */
1204
-    public function enqueue_js()
1205
-    {
1206
-        // ask our display strategy and validation strategies if they have js to enqueue
1207
-        $this->enqueue_js_from_strategies();
1208
-    }
1209
-
1210
-
1211
-
1212
-    /**
1213
-     * Tells strategies when its ok to enqueue their js and css
1214
-     *
1215
-     * @return void
1216
-     */
1217
-    public function enqueue_js_from_strategies()
1218
-    {
1219
-        $this->get_display_strategy()->enqueue_js();
1220
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1221
-            $validation_strategy->enqueue_js();
1222
-        }
1223
-    }
1224
-
1225
-
1226
-
1227
-    /**
1228
-     * Gets the default value set on the input (not the current value, which may have been
1229
-     * changed because of a form submission). If no default was set, this us null.
1230
-     * @return mixed
1231
-     */
1232
-    public function get_default()
1233
-    {
1234
-        return $this->_default;
1235
-    }
1236
-
1237
-
1238
-
1239
-    /**
1240
-     * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"',
1241
-     * and server-side if any input was received it will be ignored
1242
-     */
1243
-    public function disable($disable = true)
1244
-    {
1245
-        $disabled_attribute = ' disabled="disabled"';
1246
-        $this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1247
-        if ($this->disabled) {
1248
-            if (strpos($this->_other_html_attributes, $disabled_attribute) === false) {
1249
-                $this->_other_html_attributes .= $disabled_attribute;
1250
-            }
1251
-            $this->_set_normalized_value($this->get_default());
1252
-        } else {
1253
-            $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes);
1254
-        }
1255
-    }
1256
-
1257
-
1258
-
1259
-    /**
1260
-     * Returns whether or not this input is currently disabled.
1261
-     * @return bool
1262
-     */
1263
-    public function isDisabled()
1264
-    {
1265
-        return $this->disabled;
1266
-    }
14
+	/**
15
+	 * the input's name attribute
16
+	 *
17
+	 * @var string
18
+	 */
19
+	protected $_html_name;
20
+
21
+	/**
22
+	 * id for the html label tag
23
+	 *
24
+	 * @var string
25
+	 */
26
+	protected $_html_label_id;
27
+
28
+	/**
29
+	 * class for teh html label tag
30
+	 *
31
+	 * @var string
32
+	 */
33
+	protected $_html_label_class;
34
+
35
+	/**
36
+	 * style for teh html label tag
37
+	 *
38
+	 * @var string
39
+	 */
40
+	protected $_html_label_style;
41
+
42
+	/**
43
+	 * text to be placed in the html label
44
+	 *
45
+	 * @var string
46
+	 */
47
+	protected $_html_label_text;
48
+
49
+	/**
50
+	 * the full html label. If used, all other html_label_* properties are invalid
51
+	 *
52
+	 * @var string
53
+	 */
54
+	protected $_html_label;
55
+
56
+	/**
57
+	 * HTML to use for help text (normally placed below form input), in a span which normally
58
+	 * has a class of 'description'
59
+	 *
60
+	 * @var string
61
+	 */
62
+	protected $_html_help_text;
63
+
64
+	/**
65
+	 * CSS classes for displaying the help span
66
+	 *
67
+	 * @var string
68
+	 */
69
+	protected $_html_help_class = 'description';
70
+
71
+	/**
72
+	 * CSS to put in the style attribute on the help span
73
+	 *
74
+	 * @var string
75
+	 */
76
+	protected $_html_help_style;
77
+
78
+	/**
79
+	 * Stores whether or not this input's response is required.
80
+	 * Because certain styling elements may also want to know that this
81
+	 * input is required etc.
82
+	 *
83
+	 * @var boolean
84
+	 */
85
+	protected $_required;
86
+
87
+	/**
88
+	 * css class added to required inputs
89
+	 *
90
+	 * @var string
91
+	 */
92
+	protected $_required_css_class = 'ee-required';
93
+
94
+	/**
95
+	 * css styles applied to button type inputs
96
+	 *
97
+	 * @var string
98
+	 */
99
+	protected $_button_css_attributes;
100
+
101
+	/**
102
+	 * The raw data submitted for this, like in the $_POST super global.
103
+	 * Generally unsafe for usage in client code
104
+	 *
105
+	 * @var mixed string or array
106
+	 */
107
+	protected $_raw_value;
108
+
109
+	/**
110
+	 * Value normalized according to the input's normalization strategy.
111
+	 * The normalization strategy dictates whether this is a string, int, float,
112
+	 * boolean, or array of any of those.
113
+	 *
114
+	 * @var mixed
115
+	 */
116
+	protected $_normalized_value;
117
+
118
+
119
+	/**
120
+	 * Normalized default value either initially set on the input, or provided by calling
121
+	 * set_default().
122
+	 * @var mixed
123
+	 */
124
+	protected $_default;
125
+
126
+	/**
127
+	 * Strategy used for displaying this field.
128
+	 * Child classes must use _get_display_strategy to access it.
129
+	 *
130
+	 * @var EE_Display_Strategy_Base
131
+	 */
132
+	private $_display_strategy;
133
+
134
+	/**
135
+	 * Gets all the validation strategies used on this field
136
+	 *
137
+	 * @var EE_Validation_Strategy_Base[]
138
+	 */
139
+	private $_validation_strategies = array();
140
+
141
+	/**
142
+	 * The normalization strategy for this field
143
+	 *
144
+	 * @var EE_Normalization_Strategy_Base
145
+	 */
146
+	private $_normalization_strategy;
147
+
148
+	/**
149
+	 * Strategy for removing sensitive data after we're done with the form input
150
+	 *
151
+	 * @var EE_Sensitive_Data_Removal_Base
152
+	 */
153
+	protected $_sensitive_data_removal_strategy;
154
+
155
+	/**
156
+	 * Whether this input has been disabled or not.
157
+	 * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled.
158
+	 * (Client-side code that wants to dynamically disable it must also add this hidden input).
159
+	 * When the form is submitted, if the input is disabled in the PHP formsection, then input is ignored.
160
+	 * If the input is missing from the $_REQUEST data but the hidden input indicating the input is disabled, then the input is again ignored.
161
+	 *
162
+	 * @var boolean
163
+	 */
164
+	protected $disabled = false;
165
+
166
+
167
+
168
+	/**
169
+	 * @param array                         $input_args       {
170
+	 * @type string                         $html_name        the html name for the input
171
+	 * @type string                         $html_label_id    the id attribute to give to the html label tag
172
+	 * @type string                         $html_label_class the class attribute to give to the html label tag
173
+	 * @type string                         $html_label_style the style attribute to give ot teh label tag
174
+	 * @type string                         $html_label_text  the text to put in the label tag
175
+	 * @type string                         $html_label       the full html label. If used,
176
+	 *                                                        all other html_label_* args are invalid
177
+	 * @type string                         $html_help_text   text to put in help element
178
+	 * @type string                         $html_help_style  style attribute to give to teh help element
179
+	 * @type string                         $html_help_class  class attribute to give to the help element
180
+	 * @type string                         $default          default value NORMALIZED (eg, if providing the default
181
+	 *       for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0')
182
+	 * @type EE_Display_Strategy_Base       $display          strategy
183
+	 * @type EE_Normalization_Strategy_Base $normalization_strategy
184
+	 * @type EE_Validation_Strategy_Base[]  $validation_strategies
185
+	 * @type boolean                        $ignore_input special argument which can be used to avoid adding any validation strategies,
186
+	 *                                                    and sets the normalization strategy to the Null normalization. This is good
187
+	 *                                                    when you want the input to be totally ignored server-side (like when using
188
+	 *                                                    React.js form inputs)
189
+	 *                                                        }
190
+	 */
191
+	public function __construct($input_args = array())
192
+	{
193
+		$input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
194
+		// the following properties must be cast as arrays
195
+		if (isset($input_args['validation_strategies'])) {
196
+			foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
197
+				if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
198
+					$this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
199
+				}
200
+			}
201
+			unset($input_args['validation_strategies']);
202
+		}
203
+		if (isset($input_args['ignore_input'])) {
204
+			$this->_validation_strategies = array();
205
+		}
206
+		// loop thru incoming options
207
+		foreach ($input_args as $key => $value) {
208
+			// add underscore to $key to match property names
209
+			$_key = '_' . $key;
210
+			if (property_exists($this, $_key)) {
211
+				$this->{$_key} = $value;
212
+			}
213
+		}
214
+		// ensure that "required" is set correctly
215
+		$this->set_required(
216
+			$this->_required,
217
+			isset($input_args['required_validation_error_message'])
218
+			? $input_args['required_validation_error_message']
219
+			: null
220
+		);
221
+		// $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
222
+		$this->_display_strategy->_construct_finalize($this);
223
+		foreach ($this->_validation_strategies as $validation_strategy) {
224
+			$validation_strategy->_construct_finalize($this);
225
+		}
226
+		if (isset($input_args['ignore_input'])) {
227
+			$this->_normalization_strategy = new EE_Null_Normalization();
228
+		}
229
+		if (! $this->_normalization_strategy) {
230
+				$this->_normalization_strategy = new EE_Text_Normalization();
231
+		}
232
+		$this->_normalization_strategy->_construct_finalize($this);
233
+		// at least we can use the normalization strategy to populate the default
234
+		if (isset($input_args['default'])) {
235
+			$this->set_default($input_args['default']);
236
+			unset($input_args['default']);
237
+		}
238
+		if (! $this->_sensitive_data_removal_strategy) {
239
+			$this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
240
+		}
241
+		$this->_sensitive_data_removal_strategy->_construct_finalize($this);
242
+		parent::__construct($input_args);
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * Sets the html_name to its default value, if none was specified in teh constructor.
249
+	 * Calculation involves using the name and the parent's html_name
250
+	 *
251
+	 * @throws \EE_Error
252
+	 */
253
+	protected function _set_default_html_name_if_empty()
254
+	{
255
+		if (! $this->_html_name) {
256
+			$this->_html_name = $this->name();
257
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
258
+				$this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
259
+			}
260
+		}
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @param $parent_form_section
267
+	 * @param $name
268
+	 * @throws \EE_Error
269
+	 */
270
+	public function _construct_finalize($parent_form_section, $name)
271
+	{
272
+		parent::_construct_finalize($parent_form_section, $name);
273
+		if ($this->_html_label === null && $this->_html_label_text === null) {
274
+			$this->_html_label_text = ucwords(str_replace("_", " ", $name));
275
+		}
276
+		do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * Returns the strategy for displaying this form input. If none is set, throws an exception.
283
+	 *
284
+	 * @return EE_Display_Strategy_Base
285
+	 * @throws EE_Error
286
+	 */
287
+	protected function _get_display_strategy()
288
+	{
289
+		$this->ensure_construct_finalized_called();
290
+		if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
291
+			throw new EE_Error(
292
+				sprintf(
293
+					__(
294
+						"Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
295
+						"event_espresso"
296
+					),
297
+					$this->html_name(),
298
+					$this->html_id()
299
+				)
300
+			);
301
+		} else {
302
+			return $this->_display_strategy;
303
+		}
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * Sets the display strategy.
310
+	 *
311
+	 * @param EE_Display_Strategy_Base $strategy
312
+	 */
313
+	protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
314
+	{
315
+		$this->_display_strategy = $strategy;
316
+	}
317
+
318
+
319
+
320
+	/**
321
+	 * Sets the sanitization strategy
322
+	 *
323
+	 * @param EE_Normalization_Strategy_Base $strategy
324
+	 */
325
+	protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
326
+	{
327
+		$this->_normalization_strategy = $strategy;
328
+	}
329
+
330
+
331
+
332
+	/**
333
+	 * Gets sensitive_data_removal_strategy
334
+	 *
335
+	 * @return EE_Sensitive_Data_Removal_Base
336
+	 */
337
+	public function get_sensitive_data_removal_strategy()
338
+	{
339
+		return $this->_sensitive_data_removal_strategy;
340
+	}
341
+
342
+
343
+
344
+	/**
345
+	 * Sets sensitive_data_removal_strategy
346
+	 *
347
+	 * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
348
+	 * @return boolean
349
+	 */
350
+	public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
351
+	{
352
+		$this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * Gets the display strategy for this input
359
+	 *
360
+	 * @return EE_Display_Strategy_Base
361
+	 */
362
+	public function get_display_strategy()
363
+	{
364
+		return $this->_display_strategy;
365
+	}
366
+
367
+
368
+
369
+	/**
370
+	 * Overwrites the display strategy
371
+	 *
372
+	 * @param EE_Display_Strategy_Base $display_strategy
373
+	 */
374
+	public function set_display_strategy($display_strategy)
375
+	{
376
+		$this->_display_strategy = $display_strategy;
377
+		$this->_display_strategy->_construct_finalize($this);
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * Gets the normalization strategy set on this input
384
+	 *
385
+	 * @return EE_Normalization_Strategy_Base
386
+	 */
387
+	public function get_normalization_strategy()
388
+	{
389
+		return $this->_normalization_strategy;
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * Overwrites the normalization strategy
396
+	 *
397
+	 * @param EE_Normalization_Strategy_Base $normalization_strategy
398
+	 */
399
+	public function set_normalization_strategy($normalization_strategy)
400
+	{
401
+		$this->_normalization_strategy = $normalization_strategy;
402
+		$this->_normalization_strategy->_construct_finalize($this);
403
+	}
404
+
405
+
406
+
407
+	/**
408
+	 * Returns all teh validation strategies which apply to this field, numerically indexed
409
+	 *
410
+	 * @return EE_Validation_Strategy_Base[]
411
+	 */
412
+	public function get_validation_strategies()
413
+	{
414
+		return $this->_validation_strategies;
415
+	}
416
+
417
+
418
+
419
+	/**
420
+	 * Adds this strategy to the field so it will be used in both JS validation and server-side validation
421
+	 *
422
+	 * @param EE_Validation_Strategy_Base $validation_strategy
423
+	 * @return void
424
+	 */
425
+	protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
426
+	{
427
+		$validation_strategy->_construct_finalize($this);
428
+		$this->_validation_strategies[] = $validation_strategy;
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * Adds a new validation strategy onto the form input
435
+	 *
436
+	 * @param EE_Validation_Strategy_Base $validation_strategy
437
+	 * @return void
438
+	 */
439
+	public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
440
+	{
441
+		$this->_add_validation_strategy($validation_strategy);
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 * The classname of the validation strategy to remove
448
+	 *
449
+	 * @param string $validation_strategy_classname
450
+	 */
451
+	public function remove_validation_strategy($validation_strategy_classname)
452
+	{
453
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
454
+			if ($validation_strategy instanceof $validation_strategy_classname
455
+				|| is_subclass_of($validation_strategy, $validation_strategy_classname)
456
+			) {
457
+				unset($this->_validation_strategies[ $key ]);
458
+			}
459
+		}
460
+	}
461
+
462
+
463
+
464
+	/**
465
+	 * returns true if input employs any of the validation strategy defined by the supplied array of classnames
466
+	 *
467
+	 * @param array $validation_strategy_classnames
468
+	 * @return bool
469
+	 */
470
+	public function has_validation_strategy($validation_strategy_classnames)
471
+	{
472
+		$validation_strategy_classnames = is_array($validation_strategy_classnames)
473
+			? $validation_strategy_classnames
474
+			: array($validation_strategy_classnames);
475
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
476
+			if (in_array($key, $validation_strategy_classnames)) {
477
+				return true;
478
+			}
479
+		}
480
+		return false;
481
+	}
482
+
483
+
484
+
485
+	/**
486
+	 * Gets the HTML
487
+	 *
488
+	 * @return string
489
+	 */
490
+	public function get_html()
491
+	{
492
+		return $this->_parent_section->get_html_for_input($this);
493
+	}
494
+
495
+
496
+
497
+	/**
498
+	 * Gets the HTML for the input itself (no label or errors) according to the
499
+	 * input's display strategy
500
+	 * Makes sure the JS and CSS are enqueued for it
501
+	 *
502
+	 * @return string
503
+	 * @throws \EE_Error
504
+	 */
505
+	public function get_html_for_input()
506
+	{
507
+		return $this->_form_html_filter
508
+			? $this->_form_html_filter->filterHtml(
509
+				$this->_get_display_strategy()->display(),
510
+				$this
511
+			)
512
+			: $this->_get_display_strategy()->display();
513
+	}
514
+
515
+
516
+
517
+	/**
518
+	 * @return string
519
+	 */
520
+	public function html_other_attributes()
521
+	{
522
+		EE_Error::doing_it_wrong(
523
+			__METHOD__,
524
+			sprintf(
525
+				esc_html__(
526
+					'This method is no longer in use. You should replace it by %s',
527
+					'event_espresso'
528
+				),
529
+				'EE_Form_Section_Base::other_html_attributes()'
530
+			),
531
+			'$VID:$'
532
+		);
533
+
534
+		return $this->other_html_attributes();
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * @param string $html_other_attributes
541
+	 */
542
+	public function set_html_other_attributes($html_other_attributes)
543
+	{
544
+		EE_Error::doing_it_wrong(
545
+			__METHOD__,
546
+			sprintf(
547
+				esc_html__(
548
+					'This method is no longer in use. You should replace it by %s',
549
+					'event_espresso'
550
+				),
551
+				'EE_Form_Section_Base::set_other_html_attributes()'
552
+			),
553
+			'$VID:$'
554
+		);
555
+
556
+		$this->set_other_html_attributes($html_other_attributes);
557
+	}
558
+
559
+
560
+
561
+	/**
562
+	 * Gets the HTML for displaying the label for this form input
563
+	 * according to the form section's layout strategy
564
+	 *
565
+	 * @return string
566
+	 */
567
+	public function get_html_for_label()
568
+	{
569
+		return $this->_parent_section->get_layout_strategy()->display_label($this);
570
+	}
571
+
572
+
573
+
574
+	/**
575
+	 * Gets the HTML for displaying the errors section for this form input
576
+	 * according to the form section's layout strategy
577
+	 *
578
+	 * @return string
579
+	 */
580
+	public function get_html_for_errors()
581
+	{
582
+		return $this->_parent_section->get_layout_strategy()->display_errors($this);
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 * Gets the HTML for displaying the help text for this form input
589
+	 * according to the form section's layout strategy
590
+	 *
591
+	 * @return string
592
+	 */
593
+	public function get_html_for_help()
594
+	{
595
+		return $this->_parent_section->get_layout_strategy()->display_help_text($this);
596
+	}
597
+
598
+
599
+
600
+	/**
601
+	 * Validates the input's sanitized value (assumes _sanitize() has already been called)
602
+	 * and returns whether or not the form input's submitted value is value
603
+	 *
604
+	 * @return boolean
605
+	 */
606
+	protected function _validate()
607
+	{
608
+		if ($this->isDisabled()) {
609
+			return true;
610
+		}
611
+		foreach ($this->_validation_strategies as $validation_strategy) {
612
+			if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
613
+				try {
614
+					$validation_strategy->validate($this->normalized_value());
615
+				} catch (EE_Validation_Error $e) {
616
+					$this->add_validation_error($e);
617
+				}
618
+			}
619
+		}
620
+		if ($this->get_validation_errors()) {
621
+			return false;
622
+		} else {
623
+			return true;
624
+		}
625
+	}
626
+
627
+
628
+
629
+	/**
630
+	 * Performs basic sanitization on this value. But what sanitization can be performed anyways?
631
+	 * This value MIGHT be allowed to have tags, so we can't really remove them.
632
+	 *
633
+	 * @param string $value
634
+	 * @return null|string
635
+	 */
636
+	protected function _sanitize($value)
637
+	{
638
+		return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null;
639
+	}
640
+
641
+
642
+
643
+	/**
644
+	 * Picks out the form value that relates to this form input,
645
+	 * and stores it as the sanitized value on the form input, and sets the normalized value.
646
+	 * Returns whether or not any validation errors occurred
647
+	 *
648
+	 * @param array $req_data like $_POST
649
+	 * @return boolean whether or not there was an error
650
+	 * @throws \EE_Error
651
+	 */
652
+	protected function _normalize($req_data)
653
+	{
654
+		// any existing validation errors don't apply so clear them
655
+		$this->_validation_errors = array();
656
+		// if the input is disabled, ignore whatever input was sent in
657
+		if ($this->isDisabled()) {
658
+			$this->_set_raw_value(null);
659
+			$this->_set_normalized_value($this->get_default());
660
+			return false;
661
+		}
662
+		try {
663
+			$raw_input = $this->find_form_data_for_this_section($req_data);
664
+			// super simple sanitization for now
665
+			if (is_array($raw_input)) {
666
+				$raw_value = array();
667
+				foreach ($raw_input as $key => $value) {
668
+					$raw_value[ $key ] = $this->_sanitize($value);
669
+				}
670
+				$this->_set_raw_value($raw_value);
671
+			} else {
672
+				$this->_set_raw_value($this->_sanitize($raw_input));
673
+			}
674
+			// we want to mostly leave the input alone in case we need to re-display it to the user
675
+			$this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
676
+			return false;
677
+		} catch (EE_Validation_Error $e) {
678
+			$this->add_validation_error($e);
679
+			return true;
680
+		}
681
+	}
682
+
683
+
684
+
685
+	/**
686
+	 * @return string
687
+	 */
688
+	public function html_name()
689
+	{
690
+		$this->_set_default_html_name_if_empty();
691
+		return $this->_html_name;
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * @return string
698
+	 */
699
+	public function html_label_id()
700
+	{
701
+		return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
702
+	}
703
+
704
+
705
+
706
+	/**
707
+	 * @return string
708
+	 */
709
+	public function html_label_class()
710
+	{
711
+		return $this->_html_label_class;
712
+	}
713
+
714
+
715
+
716
+	/**
717
+	 * @return string
718
+	 */
719
+	public function html_label_style()
720
+	{
721
+		return $this->_html_label_style;
722
+	}
723
+
724
+
725
+
726
+	/**
727
+	 * @return string
728
+	 */
729
+	public function html_label_text()
730
+	{
731
+		return $this->_html_label_text;
732
+	}
733
+
734
+
735
+
736
+	/**
737
+	 * @return string
738
+	 */
739
+	public function html_help_text()
740
+	{
741
+		return $this->_html_help_text;
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * @return string
748
+	 */
749
+	public function html_help_class()
750
+	{
751
+		return $this->_html_help_class;
752
+	}
753
+
754
+
755
+
756
+	/**
757
+	 * @return string
758
+	 */
759
+	public function html_help_style()
760
+	{
761
+		return $this->_html_style;
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
768
+	 * Please note that almost all client code should instead use the normalized_value;
769
+	 * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
770
+	 * mostly by escaping quotes)
771
+	 * Note, we do not store the exact original value sent in the user's request because
772
+	 * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
773
+	 * in which case, we would have stored the malicious content to our database.
774
+	 *
775
+	 * @return string
776
+	 */
777
+	public function raw_value()
778
+	{
779
+		return $this->_raw_value;
780
+	}
781
+
782
+
783
+
784
+	/**
785
+	 * Returns a string safe to usage in form inputs when displaying, because
786
+	 * it escapes all html entities
787
+	 *
788
+	 * @return string
789
+	 */
790
+	public function raw_value_in_form()
791
+	{
792
+		return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8');
793
+	}
794
+
795
+
796
+
797
+	/**
798
+	 * returns the value after it's been sanitized, and then converted into it's proper type
799
+	 * in PHP. Eg, a string, an int, an array,
800
+	 *
801
+	 * @return mixed
802
+	 */
803
+	public function normalized_value()
804
+	{
805
+		return $this->_normalized_value;
806
+	}
807
+
808
+
809
+
810
+	/**
811
+	 * Returns the normalized value is a presentable way. By default this is just
812
+	 * the normalized value by itself, but it can be overridden for when that's not
813
+	 * the best thing to display
814
+	 *
815
+	 * @return string
816
+	 */
817
+	public function pretty_value()
818
+	{
819
+		return $this->_normalized_value;
820
+	}
821
+
822
+
823
+
824
+	/**
825
+	 * When generating the JS for the jquery validation rules like<br>
826
+	 * <code>$( "#myform" ).validate({
827
+	 * rules: {
828
+	 * password: "required",
829
+	 * password_again: {
830
+	 * equalTo: "#password"
831
+	 * }
832
+	 * }
833
+	 * });</code>
834
+	 * if this field had the name 'password_again', it should return
835
+	 * <br><code>password_again: {
836
+	 * equalTo: "#password"
837
+	 * }</code>
838
+	 *
839
+	 * @return array
840
+	 */
841
+	public function get_jquery_validation_rules()
842
+	{
843
+		$jquery_validation_js = array();
844
+		$jquery_validation_rules = array();
845
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
846
+			$jquery_validation_rules = array_replace_recursive(
847
+				$jquery_validation_rules,
848
+				$validation_strategy->get_jquery_validation_rule_array()
849
+			);
850
+		}
851
+		if (! empty($jquery_validation_rules)) {
852
+			foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
853
+				$jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
854
+			}
855
+		}
856
+		return $jquery_validation_js;
857
+	}
858
+
859
+
860
+
861
+	/**
862
+	 * Sets the input's default value for use in displaying in the form. Note: value should be
863
+	 * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
864
+	 *
865
+	 * @param mixed $value
866
+	 * @return void
867
+	 */
868
+	public function set_default($value)
869
+	{
870
+		$this->_default = $value;
871
+		$this->_set_normalized_value($value);
872
+		$this->_set_raw_value($value);
873
+	}
874
+
875
+
876
+
877
+	/**
878
+	 * Sets the normalized value on this input
879
+	 *
880
+	 * @param mixed $value
881
+	 */
882
+	protected function _set_normalized_value($value)
883
+	{
884
+		$this->_normalized_value = $value;
885
+	}
886
+
887
+
888
+
889
+	/**
890
+	 * Sets the raw value on this input (ie, exactly as the user submitted it)
891
+	 *
892
+	 * @param mixed $value
893
+	 */
894
+	protected function _set_raw_value($value)
895
+	{
896
+		$this->_raw_value = $this->_normalization_strategy->unnormalize($value);
897
+	}
898
+
899
+
900
+
901
+	/**
902
+	 * Sets the HTML label text after it has already been defined
903
+	 *
904
+	 * @param string $label
905
+	 * @return void
906
+	 */
907
+	public function set_html_label_text($label)
908
+	{
909
+		$this->_html_label_text = $label;
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 * Sets whether or not this field is required, and adjusts the validation strategy.
916
+	 * If you want to use the EE_Conditionally_Required_Validation_Strategy,
917
+	 * please add it as a validation strategy using add_validation_strategy as normal
918
+	 *
919
+	 * @param boolean $required boolean
920
+	 * @param null    $required_text
921
+	 */
922
+	public function set_required($required = true, $required_text = null)
923
+	{
924
+		$required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
925
+		// whether $required is a string or a boolean, we want to add a required validation strategy
926
+		if ($required) {
927
+			$this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
928
+		} else {
929
+			$this->remove_validation_strategy('EE_Required_Validation_Strategy');
930
+		}
931
+		$this->_required = $required;
932
+	}
933
+
934
+
935
+
936
+	/**
937
+	 * Returns whether or not this field is required
938
+	 *
939
+	 * @return boolean
940
+	 */
941
+	public function required()
942
+	{
943
+		return $this->_required;
944
+	}
945
+
946
+
947
+
948
+	/**
949
+	 * @param string $required_css_class
950
+	 */
951
+	public function set_required_css_class($required_css_class)
952
+	{
953
+		$this->_required_css_class = $required_css_class;
954
+	}
955
+
956
+
957
+
958
+	/**
959
+	 * @return string
960
+	 */
961
+	public function required_css_class()
962
+	{
963
+		return $this->_required_css_class;
964
+	}
965
+
966
+
967
+
968
+	/**
969
+	 * @param bool $add_required
970
+	 * @return string
971
+	 */
972
+	public function html_class($add_required = false)
973
+	{
974
+		return $add_required && $this->required()
975
+			? $this->required_css_class() . ' ' . $this->_html_class
976
+			: $this->_html_class;
977
+	}
978
+
979
+
980
+	/**
981
+	 * Sets the help text, in case
982
+	 *
983
+	 * @param string $text
984
+	 */
985
+	public function set_html_help_text($text)
986
+	{
987
+		$this->_html_help_text = $text;
988
+	}
989
+
990
+
991
+
992
+	/**
993
+	 * Uses the sensitive data removal strategy to remove the sensitive data from this
994
+	 * input. If there is any kind of sensitive data removal on this input, we clear
995
+	 * out the raw value completely
996
+	 *
997
+	 * @return void
998
+	 */
999
+	public function clean_sensitive_data()
1000
+	{
1001
+		// if we do ANY kind of sensitive data removal on this, then just clear out the raw value
1002
+		// if we need more logic than this we'll make a strategy for it
1003
+		if ($this->_sensitive_data_removal_strategy
1004
+			&& ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
1005
+		) {
1006
+			$this->_set_raw_value(null);
1007
+		}
1008
+		// and clean the normalized value according to the appropriate strategy
1009
+		$this->_set_normalized_value(
1010
+			$this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
1011
+				$this->_normalized_value
1012
+			)
1013
+		);
1014
+	}
1015
+
1016
+
1017
+
1018
+	/**
1019
+	 * @param bool   $primary
1020
+	 * @param string $button_size
1021
+	 * @param string $other_attributes
1022
+	 */
1023
+	public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
1024
+	{
1025
+		$button_css_attributes = 'button';
1026
+		$button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary';
1027
+		switch ($button_size) {
1028
+			case 'xs':
1029
+			case 'extra-small':
1030
+				$button_css_attributes .= ' button-xs';
1031
+				break;
1032
+			case 'sm':
1033
+			case 'small':
1034
+				$button_css_attributes .= ' button-sm';
1035
+				break;
1036
+			case 'lg':
1037
+			case 'large':
1038
+				$button_css_attributes .= ' button-lg';
1039
+				break;
1040
+			case 'block':
1041
+				$button_css_attributes .= ' button-block';
1042
+				break;
1043
+			case 'md':
1044
+			case 'medium':
1045
+			default:
1046
+				$button_css_attributes .= '';
1047
+		}
1048
+		$this->_button_css_attributes .= ! empty($other_attributes)
1049
+			? $button_css_attributes . ' ' . $other_attributes
1050
+			: $button_css_attributes;
1051
+	}
1052
+
1053
+
1054
+
1055
+	/**
1056
+	 * @return string
1057
+	 */
1058
+	public function button_css_attributes()
1059
+	{
1060
+		if (empty($this->_button_css_attributes)) {
1061
+			$this->set_button_css_attributes();
1062
+		}
1063
+		return $this->_button_css_attributes;
1064
+	}
1065
+
1066
+
1067
+
1068
+	/**
1069
+	 * find_form_data_for_this_section
1070
+	 * using this section's name and its parents, finds the value of the form data that corresponds to it.
1071
+	 * For example, if this form section's HTML name is my_form[subform][form_input_1],
1072
+	 * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1'].
1073
+	 * (If that doesn't exist, we also check for this subsection's name
1074
+	 * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].)
1075
+	 * This function finds its value in the form.
1076
+	 *
1077
+	 * @param array $req_data
1078
+	 * @return mixed whatever the raw value of this form section is in the request data
1079
+	 * @throws \EE_Error
1080
+	 */
1081
+	public function find_form_data_for_this_section($req_data)
1082
+	{
1083
+		$name_parts = $this->getInputNameParts();
1084
+		// now get the value for the input
1085
+		$value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1086
+		// check if this thing's name is at the TOP level of the request data
1087
+		if ($value === null && isset($req_data[ $this->name() ])) {
1088
+			$value = $req_data[ $this->name() ];
1089
+		}
1090
+		return $value;
1091
+	}
1092
+
1093
+
1094
+
1095
+	/**
1096
+	 * If this input's name is something like "foo[bar][baz]"
1097
+	 * returns an array like `array('foo','bar',baz')`
1098
+	 * @return array
1099
+	 */
1100
+	protected function getInputNameParts()
1101
+	{
1102
+		// break up the html name by "[]"
1103
+		if (strpos($this->html_name(), '[') !== false) {
1104
+			$before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '['));
1105
+		} else {
1106
+			$before_any_brackets = $this->html_name();
1107
+		}
1108
+		// grab all of the segments
1109
+		preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches);
1110
+		if (isset($matches[1]) && is_array($matches[1])) {
1111
+			$name_parts = $matches[1];
1112
+			array_unshift($name_parts, $before_any_brackets);
1113
+		} else {
1114
+			$name_parts = array($before_any_brackets);
1115
+		}
1116
+		return $name_parts;
1117
+	}
1118
+
1119
+
1120
+
1121
+	/**
1122
+	 * @param array $html_name_parts
1123
+	 * @param array $req_data
1124
+	 * @return array | NULL
1125
+	 */
1126
+	public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1127
+	{
1128
+		$first_part_to_consider = array_shift($html_name_parts);
1129
+		if (isset($req_data[ $first_part_to_consider ])) {
1130
+			if (empty($html_name_parts)) {
1131
+				return $req_data[ $first_part_to_consider ];
1132
+			} else {
1133
+				return $this->findRequestForSectionUsingNameParts(
1134
+					$html_name_parts,
1135
+					$req_data[ $first_part_to_consider ]
1136
+				);
1137
+			}
1138
+		} else {
1139
+			return null;
1140
+		}
1141
+	}
1142
+
1143
+
1144
+
1145
+	/**
1146
+	 * Checks if this form input's data is in the request data
1147
+	 *
1148
+	 * @param array $req_data like $_POST
1149
+	 * @return boolean
1150
+	 * @throws \EE_Error
1151
+	 */
1152
+	public function form_data_present_in($req_data = null)
1153
+	{
1154
+		if ($req_data === null) {
1155
+			$req_data = $_POST;
1156
+		}
1157
+		$checked_value = $this->find_form_data_for_this_section($req_data);
1158
+		if ($checked_value !== null) {
1159
+			return true;
1160
+		} else {
1161
+			return false;
1162
+		}
1163
+	}
1164
+
1165
+
1166
+
1167
+	/**
1168
+	 * Overrides parent to add js data from validation and display strategies
1169
+	 *
1170
+	 * @param array $form_other_js_data
1171
+	 * @return array
1172
+	 */
1173
+	public function get_other_js_data($form_other_js_data = array())
1174
+	{
1175
+		$form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data);
1176
+		return $form_other_js_data;
1177
+	}
1178
+
1179
+
1180
+
1181
+	/**
1182
+	 * Gets other JS data for localization from this input's strategies, like
1183
+	 * the validation strategies and the display strategy
1184
+	 *
1185
+	 * @param array $form_other_js_data
1186
+	 * @return array
1187
+	 */
1188
+	public function get_other_js_data_from_strategies($form_other_js_data = array())
1189
+	{
1190
+		$form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1191
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1192
+			$form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1193
+		}
1194
+		return $form_other_js_data;
1195
+	}
1196
+
1197
+
1198
+
1199
+	/**
1200
+	 * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1201
+	 *
1202
+	 * @return void
1203
+	 */
1204
+	public function enqueue_js()
1205
+	{
1206
+		// ask our display strategy and validation strategies if they have js to enqueue
1207
+		$this->enqueue_js_from_strategies();
1208
+	}
1209
+
1210
+
1211
+
1212
+	/**
1213
+	 * Tells strategies when its ok to enqueue their js and css
1214
+	 *
1215
+	 * @return void
1216
+	 */
1217
+	public function enqueue_js_from_strategies()
1218
+	{
1219
+		$this->get_display_strategy()->enqueue_js();
1220
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1221
+			$validation_strategy->enqueue_js();
1222
+		}
1223
+	}
1224
+
1225
+
1226
+
1227
+	/**
1228
+	 * Gets the default value set on the input (not the current value, which may have been
1229
+	 * changed because of a form submission). If no default was set, this us null.
1230
+	 * @return mixed
1231
+	 */
1232
+	public function get_default()
1233
+	{
1234
+		return $this->_default;
1235
+	}
1236
+
1237
+
1238
+
1239
+	/**
1240
+	 * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"',
1241
+	 * and server-side if any input was received it will be ignored
1242
+	 */
1243
+	public function disable($disable = true)
1244
+	{
1245
+		$disabled_attribute = ' disabled="disabled"';
1246
+		$this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1247
+		if ($this->disabled) {
1248
+			if (strpos($this->_other_html_attributes, $disabled_attribute) === false) {
1249
+				$this->_other_html_attributes .= $disabled_attribute;
1250
+			}
1251
+			$this->_set_normalized_value($this->get_default());
1252
+		} else {
1253
+			$this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes);
1254
+		}
1255
+	}
1256
+
1257
+
1258
+
1259
+	/**
1260
+	 * Returns whether or not this input is currently disabled.
1261
+	 * @return bool
1262
+	 */
1263
+	public function isDisabled()
1264
+	{
1265
+		return $this->disabled;
1266
+	}
1267 1267
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
         if (isset($input_args['validation_strategies'])) {
196 196
             foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
197 197
                 if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
198
-                    $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
198
+                    $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy;
199 199
                 }
200 200
             }
201 201
             unset($input_args['validation_strategies']);
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
         // loop thru incoming options
207 207
         foreach ($input_args as $key => $value) {
208 208
             // add underscore to $key to match property names
209
-            $_key = '_' . $key;
209
+            $_key = '_'.$key;
210 210
             if (property_exists($this, $_key)) {
211 211
                 $this->{$_key} = $value;
212 212
             }
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
         if (isset($input_args['ignore_input'])) {
227 227
             $this->_normalization_strategy = new EE_Null_Normalization();
228 228
         }
229
-        if (! $this->_normalization_strategy) {
229
+        if ( ! $this->_normalization_strategy) {
230 230
                 $this->_normalization_strategy = new EE_Text_Normalization();
231 231
         }
232 232
         $this->_normalization_strategy->_construct_finalize($this);
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
             $this->set_default($input_args['default']);
236 236
             unset($input_args['default']);
237 237
         }
238
-        if (! $this->_sensitive_data_removal_strategy) {
238
+        if ( ! $this->_sensitive_data_removal_strategy) {
239 239
             $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
240 240
         }
241 241
         $this->_sensitive_data_removal_strategy->_construct_finalize($this);
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
      */
253 253
     protected function _set_default_html_name_if_empty()
254 254
     {
255
-        if (! $this->_html_name) {
255
+        if ( ! $this->_html_name) {
256 256
             $this->_html_name = $this->name();
257 257
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
258
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
258
+                $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]";
259 259
             }
260 260
         }
261 261
     }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
     protected function _get_display_strategy()
288 288
     {
289 289
         $this->ensure_construct_finalized_called();
290
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
290
+        if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
291 291
             throw new EE_Error(
292 292
                 sprintf(
293 293
                     __(
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
             if ($validation_strategy instanceof $validation_strategy_classname
455 455
                 || is_subclass_of($validation_strategy, $validation_strategy_classname)
456 456
             ) {
457
-                unset($this->_validation_strategies[ $key ]);
457
+                unset($this->_validation_strategies[$key]);
458 458
             }
459 459
         }
460 460
     }
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
             if (is_array($raw_input)) {
666 666
                 $raw_value = array();
667 667
                 foreach ($raw_input as $key => $value) {
668
-                    $raw_value[ $key ] = $this->_sanitize($value);
668
+                    $raw_value[$key] = $this->_sanitize($value);
669 669
                 }
670 670
                 $this->_set_raw_value($raw_value);
671 671
             } else {
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
      */
699 699
     public function html_label_id()
700 700
     {
701
-        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
701
+        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id().'-lbl';
702 702
     }
703 703
 
704 704
 
@@ -848,9 +848,9 @@  discard block
 block discarded – undo
848 848
                 $validation_strategy->get_jquery_validation_rule_array()
849 849
             );
850 850
         }
851
-        if (! empty($jquery_validation_rules)) {
851
+        if ( ! empty($jquery_validation_rules)) {
852 852
             foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
853
-                $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
853
+                $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules;
854 854
             }
855 855
         }
856 856
         return $jquery_validation_js;
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
     public function html_class($add_required = false)
973 973
     {
974 974
         return $add_required && $this->required()
975
-            ? $this->required_css_class() . ' ' . $this->_html_class
975
+            ? $this->required_css_class().' '.$this->_html_class
976 976
             : $this->_html_class;
977 977
     }
978 978
 
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
                 $button_css_attributes .= '';
1047 1047
         }
1048 1048
         $this->_button_css_attributes .= ! empty($other_attributes)
1049
-            ? $button_css_attributes . ' ' . $other_attributes
1049
+            ? $button_css_attributes.' '.$other_attributes
1050 1050
             : $button_css_attributes;
1051 1051
     }
1052 1052
 
@@ -1084,8 +1084,8 @@  discard block
 block discarded – undo
1084 1084
         // now get the value for the input
1085 1085
         $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1086 1086
         // check if this thing's name is at the TOP level of the request data
1087
-        if ($value === null && isset($req_data[ $this->name() ])) {
1088
-            $value = $req_data[ $this->name() ];
1087
+        if ($value === null && isset($req_data[$this->name()])) {
1088
+            $value = $req_data[$this->name()];
1089 1089
         }
1090 1090
         return $value;
1091 1091
     }
@@ -1126,13 +1126,13 @@  discard block
 block discarded – undo
1126 1126
     public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1127 1127
     {
1128 1128
         $first_part_to_consider = array_shift($html_name_parts);
1129
-        if (isset($req_data[ $first_part_to_consider ])) {
1129
+        if (isset($req_data[$first_part_to_consider])) {
1130 1130
             if (empty($html_name_parts)) {
1131
-                return $req_data[ $first_part_to_consider ];
1131
+                return $req_data[$first_part_to_consider];
1132 1132
             } else {
1133 1133
                 return $this->findRequestForSectionUsingNameParts(
1134 1134
                     $html_name_parts,
1135
-                    $req_data[ $first_part_to_consider ]
1135
+                    $req_data[$first_part_to_consider]
1136 1136
                 );
1137 1137
             }
1138 1138
         } else {
Please login to merge, or discard this patch.
modules/add_new_state/EED_Add_New_State.module.php 2 patches
Indentation   +814 added lines, -814 removed lines patch added patch discarded remove patch
@@ -17,818 +17,818 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @return EED_Module|EED_Add_New_State
22
-     */
23
-    public static function instance()
24
-    {
25
-        return parent::get_instance(__CLASS__);
26
-    }
27
-
28
-
29
-    /**
30
-     * set_hooks - for hooking into EE Core, other modules, etc
31
-     *
32
-     * @return void
33
-     */
34
-    public static function set_hooks()
35
-    {
36
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
37
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
38
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
39
-        add_filter(
40
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
41
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
42
-            1,
43
-            1
44
-        );
45
-        add_filter(
46
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
47
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
48
-            1,
49
-            1
50
-        );
51
-        add_filter(
52
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
53
-            array('EED_Add_New_State', 'unset_new_state_request_params'),
54
-            10,
55
-            1
56
-        );
57
-        add_filter(
58
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
59
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
60
-            10,
61
-            5
62
-        );
63
-        add_filter(
64
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
65
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
66
-            10,
67
-            5
68
-        );
69
-        add_filter(
70
-            'FHEE__EE_State_Select_Input____construct__state_options',
71
-            array('EED_Add_New_State', 'state_options'),
72
-            10,
73
-            1
74
-        );
75
-        add_filter(
76
-            'FHEE__EE_Country_Select_Input____construct__country_options',
77
-            array('EED_Add_New_State', 'country_options'),
78
-            10,
79
-            1
80
-        );
81
-    }
82
-
83
-
84
-    /**
85
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
86
-     *
87
-     * @return void
88
-     */
89
-    public static function set_hooks_admin()
90
-    {
91
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
92
-        add_filter(
93
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
94
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
95
-            1,
96
-            1
97
-        );
98
-        add_filter(
99
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
100
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
101
-            1,
102
-            1
103
-        );
104
-        add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
105
-        add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
106
-        add_filter(
107
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
108
-            array('EED_Add_New_State', 'unset_new_state_request_params'),
109
-            10,
110
-            1
111
-        );
112
-        add_action(
113
-            'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
114
-            array('EED_Add_New_State', 'update_country_settings'),
115
-            10,
116
-            3
117
-        );
118
-        add_action(
119
-            'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
120
-            array('EED_Add_New_State', 'update_country_settings'),
121
-            10,
122
-            3
123
-        );
124
-        add_filter(
125
-            'FHEE__EE_State_Select_Input____construct__state_options',
126
-            array('EED_Add_New_State', 'state_options'),
127
-            10,
128
-            1
129
-        );
130
-        add_filter(
131
-            'FHEE__EE_Country_Select_Input____construct__country_options',
132
-            array('EED_Add_New_State', 'country_options'),
133
-            10,
134
-            1
135
-        );
136
-        add_filter(
137
-            'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
138
-            array('EED_Add_New_State', 'filter_checkout_request_params'),
139
-            10,
140
-            1
141
-        );
142
-        add_filter(
143
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
144
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
145
-            10,
146
-            5
147
-        );
148
-        add_filter(
149
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
150
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
151
-            10,
152
-            5
153
-        );
154
-    }
155
-
156
-
157
-    /**
158
-     * @return void
159
-     */
160
-    public static function set_definitions()
161
-    {
162
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
163
-        define(
164
-            'ANS_TEMPLATES_PATH',
165
-            str_replace(
166
-                '\\',
167
-                '/',
168
-                plugin_dir_path(__FILE__)
169
-            ) . 'templates/'
170
-        );
171
-    }
172
-
173
-
174
-    /**
175
-     * @param WP $WP
176
-     * @return void
177
-     */
178
-    public function run($WP)
179
-    {
180
-    }
181
-
182
-
183
-    /**
184
-     * @return void
185
-     */
186
-    public static function translate_js_strings()
187
-    {
188
-        EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
189
-            'In order to proceed, you need to select the Country that your State/Province belongs to.',
190
-            'event_espresso'
191
-        );
192
-        EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
193
-            'In order to proceed, you need to enter the name of your State/Province.',
194
-            'event_espresso'
195
-        );
196
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
197
-            'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
198
-            'event_espresso'
199
-        );
200
-        EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
201
-            'The new state was successfully saved to the database.',
202
-            'event_espresso'
203
-        );
204
-        EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
205
-            'An unknown error has occurred on the server while saving the new state to the database.',
206
-            'event_espresso'
207
-        );
208
-    }
209
-
210
-
211
-    /**
212
-     * @return void
213
-     */
214
-    public static function wp_enqueue_scripts()
215
-    {
216
-        if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
217
-            wp_register_script(
218
-                'add_new_state',
219
-                ANS_ASSETS_URL . 'add_new_state.js',
220
-                array('espresso_core', 'single_page_checkout'),
221
-                EVENT_ESPRESSO_VERSION,
222
-                true
223
-            );
224
-            wp_enqueue_script('add_new_state');
225
-        }
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * display_add_new_state_micro_form
232
-     *
233
-     * @param EE_Form_Section_Proper $question_group_reg_form
234
-     * @return string
235
-     * @throws EE_Error
236
-     * @throws InvalidArgumentException
237
-     * @throws InvalidDataTypeException
238
-     * @throws InvalidInterfaceException
239
-     */
240
-    public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
241
-    {
242
-        // only add the 'new_state_micro_form' when displaying reg forms,
243
-        // not during processing since we process the 'new_state_micro_form' in it's own AJAX request
244
-        $action = EE_Registry::instance()->REQ->get('action', '');
245
-        // is the "state" question in this form section?
246
-        $input = $question_group_reg_form->get_subsection('state');
247
-        if ($action === 'process_reg_step' || $action === 'update_reg_step') {
248
-            // ok then all we need to do is make sure the input's HTML name is consistent
249
-            // by forcing it to set it now, like it did while getting the form for display
250
-            if ($input instanceof EE_State_Select_Input) {
251
-                $input->html_name();
252
-            }
253
-            return $question_group_reg_form;
254
-        }
255
-        // we're only doing this for state select inputs
256
-        if ($input instanceof EE_State_Select_Input
257
-            && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy
258
-        ) {
259
-            // grab any set values from the request
260
-            $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name());
261
-            $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name());
262
-            $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
263
-            $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
264
-            $country_options = array();
265
-            $countries = EEM_Country::instance()->get_all_countries();
266
-            if (! empty($countries)) {
267
-                foreach ($countries as $country) {
268
-                    if ($country instanceof EE_Country) {
269
-                        $country_options[ $country->ID() ] = $country->name();
270
-                    }
271
-                }
272
-            }
273
-            $new_state_micro_form = new EE_Form_Section_Proper(
274
-                array(
275
-                    'name'            => 'new_state_micro_form',
276
-                    'html_id'         => 'new_state_micro_form',
277
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
278
-                    'subsections'     => array(
279
-                        // add hidden input to indicate that a new state is being added
280
-                        'add_new_state'               => new EE_Hidden_Input(
281
-                            array(
282
-                                'html_name' => str_replace(
283
-                                    'state',
284
-                                    'nsmf_add_new_state',
285
-                                    $input->html_name()
286
-                                ),
287
-                                'html_id'   => str_replace(
288
-                                    'state',
289
-                                    'nsmf_add_new_state',
290
-                                    $input->html_id()
291
-                                ),
292
-                                'default'   => 0,
293
-                            )
294
-                        ),
295
-                        // add link for displaying hidden container
296
-                        'click_here_link'             => new EE_Form_Section_HTML(
297
-                            apply_filters(
298
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
299
-                                EEH_HTML::link(
300
-                                    '',
301
-                                    esc_html__('click here to add a new state/province', 'event_espresso'),
302
-                                    '',
303
-                                    'display-' . $input->html_id(),
304
-                                    'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
305
-                                    '',
306
-                                    'data-target="' . $input->html_id() . '"'
307
-                                )
308
-                            )
309
-                        ),
310
-                        // add initial html for hidden container
311
-                        'add_new_state_micro_form'    => new EE_Form_Section_HTML(
312
-                            apply_filters(
313
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
314
-                                EEH_HTML::div(
315
-                                    '',
316
-                                    $input->html_id() . '-dv',
317
-                                    'ee-form-add-new-state-dv',
318
-                                    'display: none;'
319
-                                ) .
320
-                                EEH_HTML::h6(
321
-                                    esc_html__(
322
-                                        'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
323
-                                        'event_espresso'
324
-                                    )
325
-                                ) .
326
-                                EEH_HTML::ul() .
327
-                                EEH_HTML::li(
328
-                                    esc_html__(
329
-                                        'first select the Country that your State/Province belongs to',
330
-                                        'event_espresso'
331
-                                    )
332
-                                ) .
333
-                                EEH_HTML::li(
334
-                                    esc_html__('enter the name of your State/Province', 'event_espresso')
335
-                                ) .
336
-                                EEH_HTML::li(
337
-                                    esc_html__(
338
-                                        'enter a two to six letter abbreviation for the name of your State/Province',
339
-                                        'event_espresso'
340
-                                    )
341
-                                ) .
342
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
343
-                                EEH_HTML::ulx()
344
-                            )
345
-                        ),
346
-                        // NEW STATE COUNTRY
347
-                        'new_state_country'           => new EE_Country_Select_Input(
348
-                            $country_options,
349
-                            array(
350
-                                'html_name'       => $country_name,
351
-                                'html_id'         => str_replace(
352
-                                    'state',
353
-                                    'nsmf_new_state_country',
354
-                                    $input->html_id()
355
-                                ),
356
-                                'html_class'      => $input->html_class() . ' new-state-country',
357
-                                'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
358
-                                'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
359
-                                'required'        => false,
360
-                            )
361
-                        ),
362
-                        // NEW STATE NAME
363
-                        'new_state_name'              => new EE_Text_Input(
364
-                            array(
365
-                                'html_name'       => $state_name,
366
-                                'html_id'         => str_replace(
367
-                                    'state',
368
-                                    'nsmf_new_state_name',
369
-                                    $input->html_id()
370
-                                ),
371
-                                'html_class'      => $input->html_class() . ' new-state-state',
372
-                                'html_label_text' => esc_html__(
373
-                                    'New State/Province Name',
374
-                                    'event_espresso'
375
-                                ),
376
-                                'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
377
-                                'required'        => false,
378
-                            )
379
-                        ),
380
-                        'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
381
-                        // NEW STATE NAME
382
-                        'new_state_abbrv'             => new EE_Text_Input(
383
-                            array(
384
-                                'html_name'             => $abbrv_name,
385
-                                'html_id'               => str_replace(
386
-                                    'state',
387
-                                    'nsmf_new_state_abbrv',
388
-                                    $input->html_id()
389
-                                ),
390
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
391
-                                'html_label_text'       => esc_html__(
392
-                                    'New State/Province Abbreviation',
393
-                                    'event_espresso'
394
-                                ) . ' *',
395
-                                'other_html_attributes' => 'size="24"',
396
-                                'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
397
-                                'required'              => false,
398
-                            )
399
-                        ),
400
-                        // "submit" button
401
-                        'add_new_state_submit_button' => new EE_Form_Section_HTML(
402
-                            apply_filters(
403
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
-                                EEH_HTML::nbsp(3) .
405
-                                EEH_HTML::link(
406
-                                    '',
407
-                                    esc_html__('ADD', 'event_espresso'),
408
-                                    '',
409
-                                    'submit-' . $new_state_submit_id,
410
-                                    'ee-form-add-new-state-submit button button-secondary',
411
-                                    '',
412
-                                    'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"'
413
-                                )
414
-                            )
415
-                        ),
416
-                        // extra info
417
-                        'add_new_state_extra'         => new EE_Form_Section_HTML(
418
-                            apply_filters(
419
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
420
-                                EEH_HTML::br(2)
421
-                                .
422
-                                EEH_HTML::div('', '', 'small-text')
423
-                                .
424
-                                EEH_HTML::strong(
425
-                                    '* ' .
426
-                                    esc_html__(
427
-                                        'Don\'t know your State/Province Abbreviation?',
428
-                                        'event_espresso'
429
-                                    )
430
-                                )
431
-                                .
432
-                                EEH_HTML::br()
433
-                                .
434
-                                sprintf(
435
-                                    esc_html__(
436
-                                        'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
437
-                                        'event_espresso'
438
-                                    ),
439
-                                    EEH_HTML::link(
440
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
441
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
442
-                                        '',
443
-                                        '',
444
-                                        'ee-form-add-new-state-wiki-lnk',
445
-                                        '',
446
-                                        'target="_blank"'
447
-                                    )
448
-                                )
449
-                                .
450
-                                EEH_HTML::divx()
451
-                                .
452
-                                EEH_HTML::br()
453
-                                .
454
-                                EEH_HTML::link(
455
-                                    '',
456
-                                    esc_html__('cancel new State/Province', 'event_espresso'),
457
-                                    '',
458
-                                    'hide-' . $input->html_id(),
459
-                                    'ee-form-cancel-new-state-lnk smaller-text',
460
-                                    '',
461
-                                    'data-target="' . $input->html_id() . '"'
462
-                                )
463
-                                .
464
-                                EEH_HTML::divx()
465
-                                .
466
-                                EEH_HTML::br()
467
-                            )
468
-                        ),
469
-                    ),
470
-                )
471
-            );
472
-            $question_group_reg_form->add_subsections(
473
-                array('new_state_micro_form' => $new_state_micro_form),
474
-                'state',
475
-                false
476
-            );
477
-        }
478
-        return $question_group_reg_form;
479
-    }
480
-
481
-
482
-    /**
483
-     * set_new_state_input_width
484
-     *
485
-     * @return int|string
486
-     * @throws EE_Error
487
-     * @throws InvalidArgumentException
488
-     * @throws InvalidDataTypeException
489
-     * @throws InvalidInterfaceException
490
-     * @throws ReflectionException
491
-     */
492
-    public static function add_new_state()
493
-    {
494
-        $REQ = EE_Registry::instance()->load_core('Request_Handler');
495
-        if (absint($REQ->get('nsmf_add_new_state')) === 1) {
496
-            EE_Registry::instance()->load_model('State');
497
-            // grab country ISO code, new state name, and new state abbreviation
498
-            $state_country = $REQ->is_set('nsmf_new_state_country')
499
-                ? sanitize_text_field($REQ->get('nsmf_new_state_country'))
500
-                : false;
501
-            $state_name = $REQ->is_set('nsmf_new_state_name')
502
-                ? sanitize_text_field($REQ->get('nsmf_new_state_name'))
503
-                : false;
504
-            $state_abbr = $REQ->is_set('nsmf_new_state_abbrv')
505
-                ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
506
-                : false;
507
-            if ($state_country && $state_name && $state_abbr) {
508
-                $new_state = EED_Add_New_State::save_new_state_to_db(
509
-                    array(
510
-                        'CNT_ISO'    => strtoupper($state_country),
511
-                        'STA_abbrev' => strtoupper($state_abbr),
512
-                        'STA_name'   => ucwords($state_name),
513
-                        'STA_active' => false,
514
-                    )
515
-                );
516
-                if ($new_state instanceof EE_State) {
517
-                    // clean house
518
-                    EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
519
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
520
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
521
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
522
-                    // get any existing new states
523
-                    $new_states = EE_Registry::instance()->SSN->get_session_data(
524
-                        'nsmf_new_states'
525
-                    );
526
-                    $new_states[ $new_state->ID() ] = $new_state;
527
-                    EE_Registry::instance()->SSN->set_session_data(
528
-                        array('nsmf_new_states' => $new_states)
529
-                    );
530
-                    if (EE_Registry::instance()->REQ->ajax) {
531
-                        echo wp_json_encode(
532
-                            array(
533
-                                'success'      => true,
534
-                                'id'           => $new_state->ID(),
535
-                                'name'         => $new_state->name(),
536
-                                'abbrev'       => $new_state->abbrev(),
537
-                                'country_iso'  => $new_state->country_iso(),
538
-                                'country_name' => $new_state->country()->name(),
539
-                            )
540
-                        );
541
-                        exit();
542
-                    }
543
-                    return $new_state->ID();
544
-                }
545
-            } else {
546
-                $error = esc_html__(
547
-                    'A new State/Province could not be added because invalid or missing data was received.',
548
-                    'event_espresso'
549
-                );
550
-                if (EE_Registry::instance()->REQ->ajax) {
551
-                    echo wp_json_encode(array('error' => $error));
552
-                    exit();
553
-                }
554
-                EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
555
-            }
556
-        }
557
-        return false;
558
-    }
559
-
560
-
561
-    /**
562
-     * recursively drills down through request params to remove any that were added by this module
563
-     *
564
-     * @param array $request_params
565
-     * @return array
566
-     */
567
-    public static function filter_checkout_request_params($request_params)
568
-    {
569
-        foreach ($request_params as $form_section) {
570
-            if (is_array($form_section)) {
571
-                EED_Add_New_State::unset_new_state_request_params($form_section);
572
-                EED_Add_New_State::filter_checkout_request_params($form_section);
573
-            }
574
-        }
575
-        return $request_params;
576
-    }
577
-
578
-
579
-    /**
580
-     * @param array $request_params
581
-     * @return array
582
-     */
583
-    public static function unset_new_state_request_params($request_params)
584
-    {
585
-        unset(
586
-            $request_params['new_state_micro_form'],
587
-            $request_params['new_state_micro_add_new_state'],
588
-            $request_params['new_state_micro_new_state_country'],
589
-            $request_params['new_state_micro_new_state_name'],
590
-            $request_params['new_state_micro_new_state_abbrv']
591
-        );
592
-        return $request_params;
593
-    }
594
-
595
-
596
-    /**
597
-     * @param array $props_n_values
598
-     * @return bool
599
-     * @throws EE_Error
600
-     * @throws InvalidArgumentException
601
-     * @throws InvalidDataTypeException
602
-     * @throws InvalidInterfaceException
603
-     */
604
-    public static function save_new_state_to_db($props_n_values = array())
605
-    {
606
-        $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
607
-        if (! empty($existing_state)) {
608
-            return array_pop($existing_state);
609
-        }
610
-        $new_state = EE_State::new_instance($props_n_values);
611
-        if ($new_state instanceof EE_State) {
612
-            $country_settings_url = add_query_arg(
613
-                array(
614
-                    'page'    => 'espresso_general_settings',
615
-                    'action'  => 'country_settings',
616
-                    'country' => $new_state->country_iso(),
617
-                ),
618
-                admin_url('admin.php')
619
-            );
620
-            // if not non-ajax admin
621
-            new PersistentAdminNotice(
622
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
623
-                sprintf(
624
-                    esc_html__(
625
-                        'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
626
-                        'event_espresso'
627
-                    ),
628
-                    '<b>' . $new_state->name() . '</b>',
629
-                    '<b>' . $new_state->abbrev() . '</b>',
630
-                    '<b>' . $new_state->country()->name() . '</b>',
631
-                    '<a href="'
632
-                    . $country_settings_url
633
-                    . '">'
634
-                    . esc_html__(
635
-                        'Event Espresso - General Settings > Countries Tab',
636
-                        'event_espresso'
637
-                    )
638
-                    . '</a>',
639
-                    '<br />'
640
-                )
641
-            );
642
-            $new_state->save();
643
-            EEM_State::instance()->reset_cached_states();
644
-            return $new_state;
645
-        }
646
-        return false;
647
-    }
648
-
649
-
650
-    /**
651
-     * @param string $CNT_ISO
652
-     * @param string $STA_ID
653
-     * @param array  $cols_n_values
654
-     * @return void
655
-     * @throws DomainException
656
-     * @throws EE_Error
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidDataTypeException
659
-     * @throws InvalidInterfaceException
660
-     */
661
-    public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
662
-    {
663
-        if (! $CNT_ISO) {
664
-            EE_Error::add_error(
665
-                esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
666
-                __FILE__,
667
-                __FUNCTION__,
668
-                __LINE__
669
-            );
670
-        }
671
-        $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
672
-            : false;
673
-        if (! $STA_abbrev && ! empty($STA_ID)) {
674
-            $state = EEM_State::instance()->get_one_by_ID($STA_ID);
675
-            if ($state instanceof EE_State) {
676
-                $STA_abbrev = $state->abbrev();
677
-            }
678
-        }
679
-        if (! $STA_abbrev) {
680
-            EE_Error::add_error(
681
-                esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
682
-                __FILE__,
683
-                __FUNCTION__,
684
-                __LINE__
685
-            );
686
-        }
687
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
688
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
689
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
690
-        );
691
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
692
-    }
693
-
694
-
695
-    /**
696
-     * @param EE_State[]                            $state_options
697
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
698
-     * @param EE_Registration                       $registration
699
-     * @param EE_Question                           $question
700
-     * @param                                       $answer
701
-     * @return array
702
-     * @throws EE_Error
703
-     * @throws InvalidArgumentException
704
-     * @throws InvalidDataTypeException
705
-     * @throws InvalidInterfaceException
706
-     */
707
-    public static function inject_new_reg_state_into_options(
708
-        $state_options = array(),
709
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
710
-        EE_Registration $registration,
711
-        EE_Question $question,
712
-        $answer
713
-    ) {
714
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
715
-            && $question->type() === EEM_Question::QST_type_state
716
-        ) {
717
-            $STA_ID = $answer->value();
718
-            if (! empty($STA_ID)) {
719
-                $state = EEM_State::instance()->get_one_by_ID($STA_ID);
720
-                if ($state instanceof EE_State) {
721
-                    $country = $state->country();
722
-                    if ($country instanceof EE_Country) {
723
-                        if (! isset($state_options[ $country->name() ])) {
724
-                            $state_options[ $country->name() ] = array();
725
-                        }
726
-                        if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
727
-                            $state_options[ $country->name() ][ $STA_ID ] = $state->name();
728
-                        }
729
-                    }
730
-                }
731
-            }
732
-        }
733
-        return $state_options;
734
-    }
735
-
736
-
737
-    /**
738
-     * @param EE_Country[]                          $country_options
739
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
740
-     * @param EE_Registration                       $registration
741
-     * @param EE_Question                           $question
742
-     * @param                                       $answer
743
-     * @return array
744
-     * @throws EE_Error
745
-     * @throws InvalidArgumentException
746
-     * @throws InvalidDataTypeException
747
-     * @throws InvalidInterfaceException
748
-     */
749
-    public static function inject_new_reg_country_into_options(
750
-        $country_options = array(),
751
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
752
-        EE_Registration $registration,
753
-        EE_Question $question,
754
-        $answer
755
-    ) {
756
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
757
-            && $question->type()
758
-               === EEM_Question::QST_type_country
759
-        ) {
760
-            $CNT_ISO = $answer->value();
761
-            if (! empty($CNT_ISO)) {
762
-                $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
763
-                if ($country instanceof EE_Country) {
764
-                    if (! isset($country_options[ $CNT_ISO ])) {
765
-                        $country_options[ $CNT_ISO ] = $country->name();
766
-                    }
767
-                }
768
-            }
769
-        }
770
-        return $country_options;
771
-    }
772
-
773
-
774
-    /**
775
-     * @param EE_State[] $state_options
776
-     * @return array
777
-     * @throws EE_Error
778
-     * @throws InvalidArgumentException
779
-     * @throws InvalidDataTypeException
780
-     * @throws InvalidInterfaceException
781
-     */
782
-    public static function state_options($state_options = array())
783
-    {
784
-        $new_states = EED_Add_New_State::_get_new_states();
785
-        foreach ($new_states as $new_state) {
786
-            if ($new_state instanceof EE_State
787
-                && $new_state->country() instanceof EE_Country
788
-            ) {
789
-                $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
790
-            }
791
-        }
792
-        return $state_options;
793
-    }
794
-
795
-
796
-    /**
797
-     * @return array
798
-     * @throws InvalidArgumentException
799
-     * @throws InvalidDataTypeException
800
-     * @throws InvalidInterfaceException
801
-     */
802
-    protected static function _get_new_states()
803
-    {
804
-        $new_states = array();
805
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
806
-            $new_states = EE_Registry::instance()->SSN->get_session_data(
807
-                'nsmf_new_states'
808
-            );
809
-        }
810
-        return is_array($new_states) ? $new_states : array();
811
-    }
812
-
813
-
814
-    /**
815
-     * @param EE_Country[] $country_options
816
-     * @return array
817
-     * @throws EE_Error
818
-     * @throws InvalidArgumentException
819
-     * @throws InvalidDataTypeException
820
-     * @throws InvalidInterfaceException
821
-     */
822
-    public static function country_options($country_options = array())
823
-    {
824
-        $new_states = EED_Add_New_State::_get_new_states();
825
-        foreach ($new_states as $new_state) {
826
-            if ($new_state instanceof EE_State
827
-                && $new_state->country() instanceof EE_Country
828
-            ) {
829
-                $country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
830
-            }
831
-        }
832
-        return $country_options;
833
-    }
20
+	/**
21
+	 * @return EED_Module|EED_Add_New_State
22
+	 */
23
+	public static function instance()
24
+	{
25
+		return parent::get_instance(__CLASS__);
26
+	}
27
+
28
+
29
+	/**
30
+	 * set_hooks - for hooking into EE Core, other modules, etc
31
+	 *
32
+	 * @return void
33
+	 */
34
+	public static function set_hooks()
35
+	{
36
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
37
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
38
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
39
+		add_filter(
40
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
41
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
42
+			1,
43
+			1
44
+		);
45
+		add_filter(
46
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
47
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
48
+			1,
49
+			1
50
+		);
51
+		add_filter(
52
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
53
+			array('EED_Add_New_State', 'unset_new_state_request_params'),
54
+			10,
55
+			1
56
+		);
57
+		add_filter(
58
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
59
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
60
+			10,
61
+			5
62
+		);
63
+		add_filter(
64
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
65
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
66
+			10,
67
+			5
68
+		);
69
+		add_filter(
70
+			'FHEE__EE_State_Select_Input____construct__state_options',
71
+			array('EED_Add_New_State', 'state_options'),
72
+			10,
73
+			1
74
+		);
75
+		add_filter(
76
+			'FHEE__EE_Country_Select_Input____construct__country_options',
77
+			array('EED_Add_New_State', 'country_options'),
78
+			10,
79
+			1
80
+		);
81
+	}
82
+
83
+
84
+	/**
85
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
86
+	 *
87
+	 * @return void
88
+	 */
89
+	public static function set_hooks_admin()
90
+	{
91
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
92
+		add_filter(
93
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
94
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
95
+			1,
96
+			1
97
+		);
98
+		add_filter(
99
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
100
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
101
+			1,
102
+			1
103
+		);
104
+		add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
105
+		add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
106
+		add_filter(
107
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
108
+			array('EED_Add_New_State', 'unset_new_state_request_params'),
109
+			10,
110
+			1
111
+		);
112
+		add_action(
113
+			'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
114
+			array('EED_Add_New_State', 'update_country_settings'),
115
+			10,
116
+			3
117
+		);
118
+		add_action(
119
+			'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
120
+			array('EED_Add_New_State', 'update_country_settings'),
121
+			10,
122
+			3
123
+		);
124
+		add_filter(
125
+			'FHEE__EE_State_Select_Input____construct__state_options',
126
+			array('EED_Add_New_State', 'state_options'),
127
+			10,
128
+			1
129
+		);
130
+		add_filter(
131
+			'FHEE__EE_Country_Select_Input____construct__country_options',
132
+			array('EED_Add_New_State', 'country_options'),
133
+			10,
134
+			1
135
+		);
136
+		add_filter(
137
+			'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
138
+			array('EED_Add_New_State', 'filter_checkout_request_params'),
139
+			10,
140
+			1
141
+		);
142
+		add_filter(
143
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
144
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
145
+			10,
146
+			5
147
+		);
148
+		add_filter(
149
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
150
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
151
+			10,
152
+			5
153
+		);
154
+	}
155
+
156
+
157
+	/**
158
+	 * @return void
159
+	 */
160
+	public static function set_definitions()
161
+	{
162
+		define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
163
+		define(
164
+			'ANS_TEMPLATES_PATH',
165
+			str_replace(
166
+				'\\',
167
+				'/',
168
+				plugin_dir_path(__FILE__)
169
+			) . 'templates/'
170
+		);
171
+	}
172
+
173
+
174
+	/**
175
+	 * @param WP $WP
176
+	 * @return void
177
+	 */
178
+	public function run($WP)
179
+	{
180
+	}
181
+
182
+
183
+	/**
184
+	 * @return void
185
+	 */
186
+	public static function translate_js_strings()
187
+	{
188
+		EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
189
+			'In order to proceed, you need to select the Country that your State/Province belongs to.',
190
+			'event_espresso'
191
+		);
192
+		EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
193
+			'In order to proceed, you need to enter the name of your State/Province.',
194
+			'event_espresso'
195
+		);
196
+		EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
197
+			'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
198
+			'event_espresso'
199
+		);
200
+		EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
201
+			'The new state was successfully saved to the database.',
202
+			'event_espresso'
203
+		);
204
+		EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
205
+			'An unknown error has occurred on the server while saving the new state to the database.',
206
+			'event_espresso'
207
+		);
208
+	}
209
+
210
+
211
+	/**
212
+	 * @return void
213
+	 */
214
+	public static function wp_enqueue_scripts()
215
+	{
216
+		if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
217
+			wp_register_script(
218
+				'add_new_state',
219
+				ANS_ASSETS_URL . 'add_new_state.js',
220
+				array('espresso_core', 'single_page_checkout'),
221
+				EVENT_ESPRESSO_VERSION,
222
+				true
223
+			);
224
+			wp_enqueue_script('add_new_state');
225
+		}
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * display_add_new_state_micro_form
232
+	 *
233
+	 * @param EE_Form_Section_Proper $question_group_reg_form
234
+	 * @return string
235
+	 * @throws EE_Error
236
+	 * @throws InvalidArgumentException
237
+	 * @throws InvalidDataTypeException
238
+	 * @throws InvalidInterfaceException
239
+	 */
240
+	public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
241
+	{
242
+		// only add the 'new_state_micro_form' when displaying reg forms,
243
+		// not during processing since we process the 'new_state_micro_form' in it's own AJAX request
244
+		$action = EE_Registry::instance()->REQ->get('action', '');
245
+		// is the "state" question in this form section?
246
+		$input = $question_group_reg_form->get_subsection('state');
247
+		if ($action === 'process_reg_step' || $action === 'update_reg_step') {
248
+			// ok then all we need to do is make sure the input's HTML name is consistent
249
+			// by forcing it to set it now, like it did while getting the form for display
250
+			if ($input instanceof EE_State_Select_Input) {
251
+				$input->html_name();
252
+			}
253
+			return $question_group_reg_form;
254
+		}
255
+		// we're only doing this for state select inputs
256
+		if ($input instanceof EE_State_Select_Input
257
+			&& ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy
258
+		) {
259
+			// grab any set values from the request
260
+			$country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name());
261
+			$state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name());
262
+			$abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
263
+			$new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
264
+			$country_options = array();
265
+			$countries = EEM_Country::instance()->get_all_countries();
266
+			if (! empty($countries)) {
267
+				foreach ($countries as $country) {
268
+					if ($country instanceof EE_Country) {
269
+						$country_options[ $country->ID() ] = $country->name();
270
+					}
271
+				}
272
+			}
273
+			$new_state_micro_form = new EE_Form_Section_Proper(
274
+				array(
275
+					'name'            => 'new_state_micro_form',
276
+					'html_id'         => 'new_state_micro_form',
277
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
278
+					'subsections'     => array(
279
+						// add hidden input to indicate that a new state is being added
280
+						'add_new_state'               => new EE_Hidden_Input(
281
+							array(
282
+								'html_name' => str_replace(
283
+									'state',
284
+									'nsmf_add_new_state',
285
+									$input->html_name()
286
+								),
287
+								'html_id'   => str_replace(
288
+									'state',
289
+									'nsmf_add_new_state',
290
+									$input->html_id()
291
+								),
292
+								'default'   => 0,
293
+							)
294
+						),
295
+						// add link for displaying hidden container
296
+						'click_here_link'             => new EE_Form_Section_HTML(
297
+							apply_filters(
298
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
299
+								EEH_HTML::link(
300
+									'',
301
+									esc_html__('click here to add a new state/province', 'event_espresso'),
302
+									'',
303
+									'display-' . $input->html_id(),
304
+									'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
305
+									'',
306
+									'data-target="' . $input->html_id() . '"'
307
+								)
308
+							)
309
+						),
310
+						// add initial html for hidden container
311
+						'add_new_state_micro_form'    => new EE_Form_Section_HTML(
312
+							apply_filters(
313
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
314
+								EEH_HTML::div(
315
+									'',
316
+									$input->html_id() . '-dv',
317
+									'ee-form-add-new-state-dv',
318
+									'display: none;'
319
+								) .
320
+								EEH_HTML::h6(
321
+									esc_html__(
322
+										'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
323
+										'event_espresso'
324
+									)
325
+								) .
326
+								EEH_HTML::ul() .
327
+								EEH_HTML::li(
328
+									esc_html__(
329
+										'first select the Country that your State/Province belongs to',
330
+										'event_espresso'
331
+									)
332
+								) .
333
+								EEH_HTML::li(
334
+									esc_html__('enter the name of your State/Province', 'event_espresso')
335
+								) .
336
+								EEH_HTML::li(
337
+									esc_html__(
338
+										'enter a two to six letter abbreviation for the name of your State/Province',
339
+										'event_espresso'
340
+									)
341
+								) .
342
+								EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
343
+								EEH_HTML::ulx()
344
+							)
345
+						),
346
+						// NEW STATE COUNTRY
347
+						'new_state_country'           => new EE_Country_Select_Input(
348
+							$country_options,
349
+							array(
350
+								'html_name'       => $country_name,
351
+								'html_id'         => str_replace(
352
+									'state',
353
+									'nsmf_new_state_country',
354
+									$input->html_id()
355
+								),
356
+								'html_class'      => $input->html_class() . ' new-state-country',
357
+								'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
358
+								'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
359
+								'required'        => false,
360
+							)
361
+						),
362
+						// NEW STATE NAME
363
+						'new_state_name'              => new EE_Text_Input(
364
+							array(
365
+								'html_name'       => $state_name,
366
+								'html_id'         => str_replace(
367
+									'state',
368
+									'nsmf_new_state_name',
369
+									$input->html_id()
370
+								),
371
+								'html_class'      => $input->html_class() . ' new-state-state',
372
+								'html_label_text' => esc_html__(
373
+									'New State/Province Name',
374
+									'event_espresso'
375
+								),
376
+								'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
377
+								'required'        => false,
378
+							)
379
+						),
380
+						'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
381
+						// NEW STATE NAME
382
+						'new_state_abbrv'             => new EE_Text_Input(
383
+							array(
384
+								'html_name'             => $abbrv_name,
385
+								'html_id'               => str_replace(
386
+									'state',
387
+									'nsmf_new_state_abbrv',
388
+									$input->html_id()
389
+								),
390
+								'html_class'            => $input->html_class() . ' new-state-abbrv',
391
+								'html_label_text'       => esc_html__(
392
+									'New State/Province Abbreviation',
393
+									'event_espresso'
394
+								) . ' *',
395
+								'other_html_attributes' => 'size="24"',
396
+								'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
397
+								'required'              => false,
398
+							)
399
+						),
400
+						// "submit" button
401
+						'add_new_state_submit_button' => new EE_Form_Section_HTML(
402
+							apply_filters(
403
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
+								EEH_HTML::nbsp(3) .
405
+								EEH_HTML::link(
406
+									'',
407
+									esc_html__('ADD', 'event_espresso'),
408
+									'',
409
+									'submit-' . $new_state_submit_id,
410
+									'ee-form-add-new-state-submit button button-secondary',
411
+									'',
412
+									'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"'
413
+								)
414
+							)
415
+						),
416
+						// extra info
417
+						'add_new_state_extra'         => new EE_Form_Section_HTML(
418
+							apply_filters(
419
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
420
+								EEH_HTML::br(2)
421
+								.
422
+								EEH_HTML::div('', '', 'small-text')
423
+								.
424
+								EEH_HTML::strong(
425
+									'* ' .
426
+									esc_html__(
427
+										'Don\'t know your State/Province Abbreviation?',
428
+										'event_espresso'
429
+									)
430
+								)
431
+								.
432
+								EEH_HTML::br()
433
+								.
434
+								sprintf(
435
+									esc_html__(
436
+										'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
437
+										'event_espresso'
438
+									),
439
+									EEH_HTML::link(
440
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
441
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
442
+										'',
443
+										'',
444
+										'ee-form-add-new-state-wiki-lnk',
445
+										'',
446
+										'target="_blank"'
447
+									)
448
+								)
449
+								.
450
+								EEH_HTML::divx()
451
+								.
452
+								EEH_HTML::br()
453
+								.
454
+								EEH_HTML::link(
455
+									'',
456
+									esc_html__('cancel new State/Province', 'event_espresso'),
457
+									'',
458
+									'hide-' . $input->html_id(),
459
+									'ee-form-cancel-new-state-lnk smaller-text',
460
+									'',
461
+									'data-target="' . $input->html_id() . '"'
462
+								)
463
+								.
464
+								EEH_HTML::divx()
465
+								.
466
+								EEH_HTML::br()
467
+							)
468
+						),
469
+					),
470
+				)
471
+			);
472
+			$question_group_reg_form->add_subsections(
473
+				array('new_state_micro_form' => $new_state_micro_form),
474
+				'state',
475
+				false
476
+			);
477
+		}
478
+		return $question_group_reg_form;
479
+	}
480
+
481
+
482
+	/**
483
+	 * set_new_state_input_width
484
+	 *
485
+	 * @return int|string
486
+	 * @throws EE_Error
487
+	 * @throws InvalidArgumentException
488
+	 * @throws InvalidDataTypeException
489
+	 * @throws InvalidInterfaceException
490
+	 * @throws ReflectionException
491
+	 */
492
+	public static function add_new_state()
493
+	{
494
+		$REQ = EE_Registry::instance()->load_core('Request_Handler');
495
+		if (absint($REQ->get('nsmf_add_new_state')) === 1) {
496
+			EE_Registry::instance()->load_model('State');
497
+			// grab country ISO code, new state name, and new state abbreviation
498
+			$state_country = $REQ->is_set('nsmf_new_state_country')
499
+				? sanitize_text_field($REQ->get('nsmf_new_state_country'))
500
+				: false;
501
+			$state_name = $REQ->is_set('nsmf_new_state_name')
502
+				? sanitize_text_field($REQ->get('nsmf_new_state_name'))
503
+				: false;
504
+			$state_abbr = $REQ->is_set('nsmf_new_state_abbrv')
505
+				? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
506
+				: false;
507
+			if ($state_country && $state_name && $state_abbr) {
508
+				$new_state = EED_Add_New_State::save_new_state_to_db(
509
+					array(
510
+						'CNT_ISO'    => strtoupper($state_country),
511
+						'STA_abbrev' => strtoupper($state_abbr),
512
+						'STA_name'   => ucwords($state_name),
513
+						'STA_active' => false,
514
+					)
515
+				);
516
+				if ($new_state instanceof EE_State) {
517
+					// clean house
518
+					EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
519
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
520
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
521
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
522
+					// get any existing new states
523
+					$new_states = EE_Registry::instance()->SSN->get_session_data(
524
+						'nsmf_new_states'
525
+					);
526
+					$new_states[ $new_state->ID() ] = $new_state;
527
+					EE_Registry::instance()->SSN->set_session_data(
528
+						array('nsmf_new_states' => $new_states)
529
+					);
530
+					if (EE_Registry::instance()->REQ->ajax) {
531
+						echo wp_json_encode(
532
+							array(
533
+								'success'      => true,
534
+								'id'           => $new_state->ID(),
535
+								'name'         => $new_state->name(),
536
+								'abbrev'       => $new_state->abbrev(),
537
+								'country_iso'  => $new_state->country_iso(),
538
+								'country_name' => $new_state->country()->name(),
539
+							)
540
+						);
541
+						exit();
542
+					}
543
+					return $new_state->ID();
544
+				}
545
+			} else {
546
+				$error = esc_html__(
547
+					'A new State/Province could not be added because invalid or missing data was received.',
548
+					'event_espresso'
549
+				);
550
+				if (EE_Registry::instance()->REQ->ajax) {
551
+					echo wp_json_encode(array('error' => $error));
552
+					exit();
553
+				}
554
+				EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
555
+			}
556
+		}
557
+		return false;
558
+	}
559
+
560
+
561
+	/**
562
+	 * recursively drills down through request params to remove any that were added by this module
563
+	 *
564
+	 * @param array $request_params
565
+	 * @return array
566
+	 */
567
+	public static function filter_checkout_request_params($request_params)
568
+	{
569
+		foreach ($request_params as $form_section) {
570
+			if (is_array($form_section)) {
571
+				EED_Add_New_State::unset_new_state_request_params($form_section);
572
+				EED_Add_New_State::filter_checkout_request_params($form_section);
573
+			}
574
+		}
575
+		return $request_params;
576
+	}
577
+
578
+
579
+	/**
580
+	 * @param array $request_params
581
+	 * @return array
582
+	 */
583
+	public static function unset_new_state_request_params($request_params)
584
+	{
585
+		unset(
586
+			$request_params['new_state_micro_form'],
587
+			$request_params['new_state_micro_add_new_state'],
588
+			$request_params['new_state_micro_new_state_country'],
589
+			$request_params['new_state_micro_new_state_name'],
590
+			$request_params['new_state_micro_new_state_abbrv']
591
+		);
592
+		return $request_params;
593
+	}
594
+
595
+
596
+	/**
597
+	 * @param array $props_n_values
598
+	 * @return bool
599
+	 * @throws EE_Error
600
+	 * @throws InvalidArgumentException
601
+	 * @throws InvalidDataTypeException
602
+	 * @throws InvalidInterfaceException
603
+	 */
604
+	public static function save_new_state_to_db($props_n_values = array())
605
+	{
606
+		$existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
607
+		if (! empty($existing_state)) {
608
+			return array_pop($existing_state);
609
+		}
610
+		$new_state = EE_State::new_instance($props_n_values);
611
+		if ($new_state instanceof EE_State) {
612
+			$country_settings_url = add_query_arg(
613
+				array(
614
+					'page'    => 'espresso_general_settings',
615
+					'action'  => 'country_settings',
616
+					'country' => $new_state->country_iso(),
617
+				),
618
+				admin_url('admin.php')
619
+			);
620
+			// if not non-ajax admin
621
+			new PersistentAdminNotice(
622
+				'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
623
+				sprintf(
624
+					esc_html__(
625
+						'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
626
+						'event_espresso'
627
+					),
628
+					'<b>' . $new_state->name() . '</b>',
629
+					'<b>' . $new_state->abbrev() . '</b>',
630
+					'<b>' . $new_state->country()->name() . '</b>',
631
+					'<a href="'
632
+					. $country_settings_url
633
+					. '">'
634
+					. esc_html__(
635
+						'Event Espresso - General Settings > Countries Tab',
636
+						'event_espresso'
637
+					)
638
+					. '</a>',
639
+					'<br />'
640
+				)
641
+			);
642
+			$new_state->save();
643
+			EEM_State::instance()->reset_cached_states();
644
+			return $new_state;
645
+		}
646
+		return false;
647
+	}
648
+
649
+
650
+	/**
651
+	 * @param string $CNT_ISO
652
+	 * @param string $STA_ID
653
+	 * @param array  $cols_n_values
654
+	 * @return void
655
+	 * @throws DomainException
656
+	 * @throws EE_Error
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidDataTypeException
659
+	 * @throws InvalidInterfaceException
660
+	 */
661
+	public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
662
+	{
663
+		if (! $CNT_ISO) {
664
+			EE_Error::add_error(
665
+				esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
666
+				__FILE__,
667
+				__FUNCTION__,
668
+				__LINE__
669
+			);
670
+		}
671
+		$STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
672
+			: false;
673
+		if (! $STA_abbrev && ! empty($STA_ID)) {
674
+			$state = EEM_State::instance()->get_one_by_ID($STA_ID);
675
+			if ($state instanceof EE_State) {
676
+				$STA_abbrev = $state->abbrev();
677
+			}
678
+		}
679
+		if (! $STA_abbrev) {
680
+			EE_Error::add_error(
681
+				esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
682
+				__FILE__,
683
+				__FUNCTION__,
684
+				__LINE__
685
+			);
686
+		}
687
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
688
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
689
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
690
+		);
691
+		$persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
692
+	}
693
+
694
+
695
+	/**
696
+	 * @param EE_State[]                            $state_options
697
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
698
+	 * @param EE_Registration                       $registration
699
+	 * @param EE_Question                           $question
700
+	 * @param                                       $answer
701
+	 * @return array
702
+	 * @throws EE_Error
703
+	 * @throws InvalidArgumentException
704
+	 * @throws InvalidDataTypeException
705
+	 * @throws InvalidInterfaceException
706
+	 */
707
+	public static function inject_new_reg_state_into_options(
708
+		$state_options = array(),
709
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
710
+		EE_Registration $registration,
711
+		EE_Question $question,
712
+		$answer
713
+	) {
714
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
715
+			&& $question->type() === EEM_Question::QST_type_state
716
+		) {
717
+			$STA_ID = $answer->value();
718
+			if (! empty($STA_ID)) {
719
+				$state = EEM_State::instance()->get_one_by_ID($STA_ID);
720
+				if ($state instanceof EE_State) {
721
+					$country = $state->country();
722
+					if ($country instanceof EE_Country) {
723
+						if (! isset($state_options[ $country->name() ])) {
724
+							$state_options[ $country->name() ] = array();
725
+						}
726
+						if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
727
+							$state_options[ $country->name() ][ $STA_ID ] = $state->name();
728
+						}
729
+					}
730
+				}
731
+			}
732
+		}
733
+		return $state_options;
734
+	}
735
+
736
+
737
+	/**
738
+	 * @param EE_Country[]                          $country_options
739
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
740
+	 * @param EE_Registration                       $registration
741
+	 * @param EE_Question                           $question
742
+	 * @param                                       $answer
743
+	 * @return array
744
+	 * @throws EE_Error
745
+	 * @throws InvalidArgumentException
746
+	 * @throws InvalidDataTypeException
747
+	 * @throws InvalidInterfaceException
748
+	 */
749
+	public static function inject_new_reg_country_into_options(
750
+		$country_options = array(),
751
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
752
+		EE_Registration $registration,
753
+		EE_Question $question,
754
+		$answer
755
+	) {
756
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
757
+			&& $question->type()
758
+			   === EEM_Question::QST_type_country
759
+		) {
760
+			$CNT_ISO = $answer->value();
761
+			if (! empty($CNT_ISO)) {
762
+				$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
763
+				if ($country instanceof EE_Country) {
764
+					if (! isset($country_options[ $CNT_ISO ])) {
765
+						$country_options[ $CNT_ISO ] = $country->name();
766
+					}
767
+				}
768
+			}
769
+		}
770
+		return $country_options;
771
+	}
772
+
773
+
774
+	/**
775
+	 * @param EE_State[] $state_options
776
+	 * @return array
777
+	 * @throws EE_Error
778
+	 * @throws InvalidArgumentException
779
+	 * @throws InvalidDataTypeException
780
+	 * @throws InvalidInterfaceException
781
+	 */
782
+	public static function state_options($state_options = array())
783
+	{
784
+		$new_states = EED_Add_New_State::_get_new_states();
785
+		foreach ($new_states as $new_state) {
786
+			if ($new_state instanceof EE_State
787
+				&& $new_state->country() instanceof EE_Country
788
+			) {
789
+				$state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
790
+			}
791
+		}
792
+		return $state_options;
793
+	}
794
+
795
+
796
+	/**
797
+	 * @return array
798
+	 * @throws InvalidArgumentException
799
+	 * @throws InvalidDataTypeException
800
+	 * @throws InvalidInterfaceException
801
+	 */
802
+	protected static function _get_new_states()
803
+	{
804
+		$new_states = array();
805
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
806
+			$new_states = EE_Registry::instance()->SSN->get_session_data(
807
+				'nsmf_new_states'
808
+			);
809
+		}
810
+		return is_array($new_states) ? $new_states : array();
811
+	}
812
+
813
+
814
+	/**
815
+	 * @param EE_Country[] $country_options
816
+	 * @return array
817
+	 * @throws EE_Error
818
+	 * @throws InvalidArgumentException
819
+	 * @throws InvalidDataTypeException
820
+	 * @throws InvalidInterfaceException
821
+	 */
822
+	public static function country_options($country_options = array())
823
+	{
824
+		$new_states = EED_Add_New_State::_get_new_states();
825
+		foreach ($new_states as $new_state) {
826
+			if ($new_state instanceof EE_State
827
+				&& $new_state->country() instanceof EE_Country
828
+			) {
829
+				$country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
830
+			}
831
+		}
832
+		return $country_options;
833
+	}
834 834
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public static function set_definitions()
161 161
     {
162
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
162
+        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
163 163
         define(
164 164
             'ANS_TEMPLATES_PATH',
165 165
             str_replace(
166 166
                 '\\',
167 167
                 '/',
168 168
                 plugin_dir_path(__FILE__)
169
-            ) . 'templates/'
169
+            ).'templates/'
170 170
         );
171 171
     }
172 172
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
217 217
             wp_register_script(
218 218
                 'add_new_state',
219
-                ANS_ASSETS_URL . 'add_new_state.js',
219
+                ANS_ASSETS_URL.'add_new_state.js',
220 220
                 array('espresso_core', 'single_page_checkout'),
221 221
                 EVENT_ESPRESSO_VERSION,
222 222
                 true
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
             $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
264 264
             $country_options = array();
265 265
             $countries = EEM_Country::instance()->get_all_countries();
266
-            if (! empty($countries)) {
266
+            if ( ! empty($countries)) {
267 267
                 foreach ($countries as $country) {
268 268
                     if ($country instanceof EE_Country) {
269
-                        $country_options[ $country->ID() ] = $country->name();
269
+                        $country_options[$country->ID()] = $country->name();
270 270
                     }
271 271
                 }
272 272
             }
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
                                     '',
301 301
                                     esc_html__('click here to add a new state/province', 'event_espresso'),
302 302
                                     '',
303
-                                    'display-' . $input->html_id(),
303
+                                    'display-'.$input->html_id(),
304 304
                                     'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
305 305
                                     '',
306
-                                    'data-target="' . $input->html_id() . '"'
306
+                                    'data-target="'.$input->html_id().'"'
307 307
                                 )
308 308
                             )
309 309
                         ),
@@ -313,33 +313,33 @@  discard block
 block discarded – undo
313 313
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
314 314
                                 EEH_HTML::div(
315 315
                                     '',
316
-                                    $input->html_id() . '-dv',
316
+                                    $input->html_id().'-dv',
317 317
                                     'ee-form-add-new-state-dv',
318 318
                                     'display: none;'
319
-                                ) .
319
+                                ).
320 320
                                 EEH_HTML::h6(
321 321
                                     esc_html__(
322 322
                                         'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
323 323
                                         'event_espresso'
324 324
                                     )
325
-                                ) .
326
-                                EEH_HTML::ul() .
325
+                                ).
326
+                                EEH_HTML::ul().
327 327
                                 EEH_HTML::li(
328 328
                                     esc_html__(
329 329
                                         'first select the Country that your State/Province belongs to',
330 330
                                         'event_espresso'
331 331
                                     )
332
-                                ) .
332
+                                ).
333 333
                                 EEH_HTML::li(
334 334
                                     esc_html__('enter the name of your State/Province', 'event_espresso')
335
-                                ) .
335
+                                ).
336 336
                                 EEH_HTML::li(
337 337
                                     esc_html__(
338 338
                                         'enter a two to six letter abbreviation for the name of your State/Province',
339 339
                                         'event_espresso'
340 340
                                     )
341
-                                ) .
342
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
341
+                                ).
342
+                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')).
343 343
                                 EEH_HTML::ulx()
344 344
                             )
345 345
                         ),
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
                                     'nsmf_new_state_country',
354 354
                                     $input->html_id()
355 355
                                 ),
356
-                                'html_class'      => $input->html_class() . ' new-state-country',
356
+                                'html_class'      => $input->html_class().' new-state-country',
357 357
                                 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
358 358
                                 'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
359 359
                                 'required'        => false,
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
                                     'nsmf_new_state_name',
369 369
                                     $input->html_id()
370 370
                                 ),
371
-                                'html_class'      => $input->html_class() . ' new-state-state',
371
+                                'html_class'      => $input->html_class().' new-state-state',
372 372
                                 'html_label_text' => esc_html__(
373 373
                                     'New State/Province Name',
374 374
                                     'event_espresso'
@@ -387,11 +387,11 @@  discard block
 block discarded – undo
387 387
                                     'nsmf_new_state_abbrv',
388 388
                                     $input->html_id()
389 389
                                 ),
390
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
390
+                                'html_class'            => $input->html_class().' new-state-abbrv',
391 391
                                 'html_label_text'       => esc_html__(
392 392
                                     'New State/Province Abbreviation',
393 393
                                     'event_espresso'
394
-                                ) . ' *',
394
+                                ).' *',
395 395
                                 'other_html_attributes' => 'size="24"',
396 396
                                 'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
397 397
                                 'required'              => false,
@@ -401,15 +401,15 @@  discard block
 block discarded – undo
401 401
                         'add_new_state_submit_button' => new EE_Form_Section_HTML(
402 402
                             apply_filters(
403 403
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
-                                EEH_HTML::nbsp(3) .
404
+                                EEH_HTML::nbsp(3).
405 405
                                 EEH_HTML::link(
406 406
                                     '',
407 407
                                     esc_html__('ADD', 'event_espresso'),
408 408
                                     '',
409
-                                    'submit-' . $new_state_submit_id,
409
+                                    'submit-'.$new_state_submit_id,
410 410
                                     'ee-form-add-new-state-submit button button-secondary',
411 411
                                     '',
412
-                                    'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"'
412
+                                    'data-target="'.$new_state_submit_id.'" data-value-field-name="'.$input->valueFieldName().'"'
413 413
                                 )
414 414
                             )
415 415
                         ),
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
                                 EEH_HTML::div('', '', 'small-text')
423 423
                                 .
424 424
                                 EEH_HTML::strong(
425
-                                    '* ' .
425
+                                    '* '.
426 426
                                     esc_html__(
427 427
                                         'Don\'t know your State/Province Abbreviation?',
428 428
                                         'event_espresso'
@@ -455,10 +455,10 @@  discard block
 block discarded – undo
455 455
                                     '',
456 456
                                     esc_html__('cancel new State/Province', 'event_espresso'),
457 457
                                     '',
458
-                                    'hide-' . $input->html_id(),
458
+                                    'hide-'.$input->html_id(),
459 459
                                     'ee-form-cancel-new-state-lnk smaller-text',
460 460
                                     '',
461
-                                    'data-target="' . $input->html_id() . '"'
461
+                                    'data-target="'.$input->html_id().'"'
462 462
                                 )
463 463
                                 .
464 464
                                 EEH_HTML::divx()
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
                     $new_states = EE_Registry::instance()->SSN->get_session_data(
524 524
                         'nsmf_new_states'
525 525
                     );
526
-                    $new_states[ $new_state->ID() ] = $new_state;
526
+                    $new_states[$new_state->ID()] = $new_state;
527 527
                     EE_Registry::instance()->SSN->set_session_data(
528 528
                         array('nsmf_new_states' => $new_states)
529 529
                     );
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
     public static function save_new_state_to_db($props_n_values = array())
605 605
     {
606 606
         $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
607
-        if (! empty($existing_state)) {
607
+        if ( ! empty($existing_state)) {
608 608
             return array_pop($existing_state);
609 609
         }
610 610
         $new_state = EE_State::new_instance($props_n_values);
@@ -619,15 +619,15 @@  discard block
 block discarded – undo
619 619
             );
620 620
             // if not non-ajax admin
621 621
             new PersistentAdminNotice(
622
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
622
+                'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(),
623 623
                 sprintf(
624 624
                     esc_html__(
625 625
                         'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
626 626
                         'event_espresso'
627 627
                     ),
628
-                    '<b>' . $new_state->name() . '</b>',
629
-                    '<b>' . $new_state->abbrev() . '</b>',
630
-                    '<b>' . $new_state->country()->name() . '</b>',
628
+                    '<b>'.$new_state->name().'</b>',
629
+                    '<b>'.$new_state->abbrev().'</b>',
630
+                    '<b>'.$new_state->country()->name().'</b>',
631 631
                     '<a href="'
632 632
                     . $country_settings_url
633 633
                     . '">'
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
      */
661 661
     public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
662 662
     {
663
-        if (! $CNT_ISO) {
663
+        if ( ! $CNT_ISO) {
664 664
             EE_Error::add_error(
665 665
                 esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
666 666
                 __FILE__,
@@ -670,13 +670,13 @@  discard block
 block discarded – undo
670 670
         }
671 671
         $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
672 672
             : false;
673
-        if (! $STA_abbrev && ! empty($STA_ID)) {
673
+        if ( ! $STA_abbrev && ! empty($STA_ID)) {
674 674
             $state = EEM_State::instance()->get_one_by_ID($STA_ID);
675 675
             if ($state instanceof EE_State) {
676 676
                 $STA_abbrev = $state->abbrev();
677 677
             }
678 678
         }
679
-        if (! $STA_abbrev) {
679
+        if ( ! $STA_abbrev) {
680 680
             EE_Error::add_error(
681 681
                 esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
682 682
                 __FILE__,
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
         $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
689 689
             'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
690 690
         );
691
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
691
+        $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true);
692 692
     }
693 693
 
694 694
 
@@ -715,16 +715,16 @@  discard block
 block discarded – undo
715 715
             && $question->type() === EEM_Question::QST_type_state
716 716
         ) {
717 717
             $STA_ID = $answer->value();
718
-            if (! empty($STA_ID)) {
718
+            if ( ! empty($STA_ID)) {
719 719
                 $state = EEM_State::instance()->get_one_by_ID($STA_ID);
720 720
                 if ($state instanceof EE_State) {
721 721
                     $country = $state->country();
722 722
                     if ($country instanceof EE_Country) {
723
-                        if (! isset($state_options[ $country->name() ])) {
724
-                            $state_options[ $country->name() ] = array();
723
+                        if ( ! isset($state_options[$country->name()])) {
724
+                            $state_options[$country->name()] = array();
725 725
                         }
726
-                        if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
727
-                            $state_options[ $country->name() ][ $STA_ID ] = $state->name();
726
+                        if ( ! isset($state_options[$country->name()][$STA_ID])) {
727
+                            $state_options[$country->name()][$STA_ID] = $state->name();
728 728
                         }
729 729
                     }
730 730
                 }
@@ -758,11 +758,11 @@  discard block
 block discarded – undo
758 758
                === EEM_Question::QST_type_country
759 759
         ) {
760 760
             $CNT_ISO = $answer->value();
761
-            if (! empty($CNT_ISO)) {
761
+            if ( ! empty($CNT_ISO)) {
762 762
                 $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
763 763
                 if ($country instanceof EE_Country) {
764
-                    if (! isset($country_options[ $CNT_ISO ])) {
765
-                        $country_options[ $CNT_ISO ] = $country->name();
764
+                    if ( ! isset($country_options[$CNT_ISO])) {
765
+                        $country_options[$CNT_ISO] = $country->name();
766 766
                     }
767 767
                 }
768 768
             }
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
             if ($new_state instanceof EE_State
787 787
                 && $new_state->country() instanceof EE_Country
788 788
             ) {
789
-                $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
789
+                $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
790 790
             }
791 791
         }
792 792
         return $state_options;
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
             if ($new_state instanceof EE_State
827 827
                 && $new_state->country() instanceof EE_Country
828 828
             ) {
829
-                $country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
829
+                $country_options[$new_state->country()->ID()] = $new_state->country()->name();
830 830
             }
831 831
         }
832 832
         return $country_options;
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Base.form.php 2 patches
Indentation   +476 added lines, -476 removed lines patch added patch discarded remove patch
@@ -15,486 +15,486 @@
 block discarded – undo
15 15
 abstract class EE_Form_Section_Base
16 16
 {
17 17
 
18
-    /**
19
-     * the URL the form is submitted to
20
-     *
21
-     * @var string
22
-     */
23
-    protected $_action;
24
-
25
-    /**
26
-     * POST (default) or GET
27
-     *
28
-     * @var string
29
-     */
30
-    protected $_method;
31
-
32
-    /**
33
-     * html_id and html_name are derived from this by default
34
-     *
35
-     * @var string
36
-     */
37
-    protected $_name;
38
-
39
-    /**
40
-     * $_html_id
41
-     * @var string
42
-     */
43
-    protected $_html_id;
44
-
45
-    /**
46
-     * $_html_class
47
-     * @var string
48
-     */
49
-    protected $_html_class;
50
-
51
-    /**
52
-     * $_html_style
53
-     * @var string
54
-     */
55
-    protected $_html_style;
56
-
57
-    /**
58
-     * $_other_html_attributes
59
-     * @var string
60
-     */
61
-    protected $_other_html_attributes;
62
-
63
-    /**
64
-     * The form section of which this form section is a part
65
-     *
66
-     * @var EE_Form_Section_Proper
67
-     */
68
-    protected $_parent_section;
69
-
70
-    /**
71
-     * flag indicating that _construct_finalize has been called.
72
-     * If it has not been called and we try to use functions which require it, we call it
73
-     * with no parameters. But normally, _construct_finalize should be called by the instantiating class
74
-     *
75
-     * @var boolean
76
-     */
77
-    protected $_construction_finalized;
78
-
79
-    /**
80
-     * Strategy for parsing the form HTML upon display
81
-     *
82
-     * @var FormHtmlFilter
83
-     */
84
-    protected $_form_html_filter;
85
-
86
-
87
-    /**
88
-     * @param array $options_array {
89
-     * @type        $name          string the name for this form section, if you want to explicitly define it
90
-     *                             }
91
-     * @throws InvalidDataTypeException
92
-     */
93
-    public function __construct($options_array = array())
94
-    {
95
-        // used by display strategies
96
-        // assign incoming values to properties
97
-        foreach ($options_array as $key => $value) {
98
-            $key = '_' . $key;
99
-            if (property_exists($this, $key) && empty($this->{$key})) {
100
-                $this->{$key} = $value;
101
-                if ($key === '_subsections' && ! is_array($value)) {
102
-                    throw new InvalidDataTypeException($key, $value, 'array');
103
-                }
104
-            }
105
-        }
106
-        // set parser which allows the form section's rendered HTML to be filtered
107
-        if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
108
-            $this->_form_html_filter = $options_array['form_html_filter'];
109
-        }
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * @param $parent_form_section
116
-     * @param $name
117
-     * @throws \EE_Error
118
-     */
119
-    protected function _construct_finalize($parent_form_section, $name)
120
-    {
121
-        $this->_construction_finalized = true;
122
-        $this->_parent_section = $parent_form_section;
123
-        if ($name !== null) {
124
-            $this->_name = $name;
125
-        }
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * make sure construction finalized was called, otherwise children might not be ready
132
-     *
133
-     * @return void
134
-     * @throws \EE_Error
135
-     */
136
-    public function ensure_construct_finalized_called()
137
-    {
138
-        if (! $this->_construction_finalized) {
139
-            $this->_construct_finalize($this->_parent_section, $this->_name);
140
-        }
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @return string
147
-     */
148
-    public function action()
149
-    {
150
-        return $this->_action;
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * @param string $action
157
-     */
158
-    public function set_action($action)
159
-    {
160
-        $this->_action = $action;
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     * @return string
167
-     */
168
-    public function method()
169
-    {
170
-        return ! empty($this->_method) ? $this->_method : 'POST';
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     * @param string $method
177
-     */
178
-    public function set_method($method)
179
-    {
180
-        switch ($method) {
181
-            case 'get':
182
-            case 'GET':
183
-                $this->_method = 'GET';
184
-                break;
185
-            default:
186
-                $this->_method = 'POST';
187
-        }
188
-    }
189
-
190
-
191
-
192
-    /**
193
-     * Sets the html_id to its default value, if none was specified in the constructor.
194
-     * Calculation involves using the name and the parent's html id
195
-     * return void
196
-     *
197
-     * @throws \EE_Error
198
-     */
199
-    protected function _set_default_html_id_if_empty()
200
-    {
201
-        if (! $this->_html_id) {
202
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
203
-                $this->_html_id = $this->_parent_section->html_id()
204
-                                  . '-'
205
-                                  . $this->_prep_name_for_html_id($this->name());
206
-            } else {
207
-                $this->_html_id = $this->_prep_name_for_html_id($this->name());
208
-            }
209
-        }
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * _prep_name_for_html_id
216
-     *
217
-     * @param $name
218
-     * @return string
219
-     */
220
-    private function _prep_name_for_html_id($name)
221
-    {
222
-        return sanitize_key(str_replace(array('&nbsp;', ' ', '_'), '-', $name));
223
-    }
18
+	/**
19
+	 * the URL the form is submitted to
20
+	 *
21
+	 * @var string
22
+	 */
23
+	protected $_action;
24
+
25
+	/**
26
+	 * POST (default) or GET
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected $_method;
31
+
32
+	/**
33
+	 * html_id and html_name are derived from this by default
34
+	 *
35
+	 * @var string
36
+	 */
37
+	protected $_name;
38
+
39
+	/**
40
+	 * $_html_id
41
+	 * @var string
42
+	 */
43
+	protected $_html_id;
44
+
45
+	/**
46
+	 * $_html_class
47
+	 * @var string
48
+	 */
49
+	protected $_html_class;
50
+
51
+	/**
52
+	 * $_html_style
53
+	 * @var string
54
+	 */
55
+	protected $_html_style;
56
+
57
+	/**
58
+	 * $_other_html_attributes
59
+	 * @var string
60
+	 */
61
+	protected $_other_html_attributes;
62
+
63
+	/**
64
+	 * The form section of which this form section is a part
65
+	 *
66
+	 * @var EE_Form_Section_Proper
67
+	 */
68
+	protected $_parent_section;
69
+
70
+	/**
71
+	 * flag indicating that _construct_finalize has been called.
72
+	 * If it has not been called and we try to use functions which require it, we call it
73
+	 * with no parameters. But normally, _construct_finalize should be called by the instantiating class
74
+	 *
75
+	 * @var boolean
76
+	 */
77
+	protected $_construction_finalized;
78
+
79
+	/**
80
+	 * Strategy for parsing the form HTML upon display
81
+	 *
82
+	 * @var FormHtmlFilter
83
+	 */
84
+	protected $_form_html_filter;
85
+
86
+
87
+	/**
88
+	 * @param array $options_array {
89
+	 * @type        $name          string the name for this form section, if you want to explicitly define it
90
+	 *                             }
91
+	 * @throws InvalidDataTypeException
92
+	 */
93
+	public function __construct($options_array = array())
94
+	{
95
+		// used by display strategies
96
+		// assign incoming values to properties
97
+		foreach ($options_array as $key => $value) {
98
+			$key = '_' . $key;
99
+			if (property_exists($this, $key) && empty($this->{$key})) {
100
+				$this->{$key} = $value;
101
+				if ($key === '_subsections' && ! is_array($value)) {
102
+					throw new InvalidDataTypeException($key, $value, 'array');
103
+				}
104
+			}
105
+		}
106
+		// set parser which allows the form section's rendered HTML to be filtered
107
+		if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
108
+			$this->_form_html_filter = $options_array['form_html_filter'];
109
+		}
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * @param $parent_form_section
116
+	 * @param $name
117
+	 * @throws \EE_Error
118
+	 */
119
+	protected function _construct_finalize($parent_form_section, $name)
120
+	{
121
+		$this->_construction_finalized = true;
122
+		$this->_parent_section = $parent_form_section;
123
+		if ($name !== null) {
124
+			$this->_name = $name;
125
+		}
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * make sure construction finalized was called, otherwise children might not be ready
132
+	 *
133
+	 * @return void
134
+	 * @throws \EE_Error
135
+	 */
136
+	public function ensure_construct_finalized_called()
137
+	{
138
+		if (! $this->_construction_finalized) {
139
+			$this->_construct_finalize($this->_parent_section, $this->_name);
140
+		}
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @return string
147
+	 */
148
+	public function action()
149
+	{
150
+		return $this->_action;
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * @param string $action
157
+	 */
158
+	public function set_action($action)
159
+	{
160
+		$this->_action = $action;
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 * @return string
167
+	 */
168
+	public function method()
169
+	{
170
+		return ! empty($this->_method) ? $this->_method : 'POST';
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 * @param string $method
177
+	 */
178
+	public function set_method($method)
179
+	{
180
+		switch ($method) {
181
+			case 'get':
182
+			case 'GET':
183
+				$this->_method = 'GET';
184
+				break;
185
+			default:
186
+				$this->_method = 'POST';
187
+		}
188
+	}
189
+
190
+
191
+
192
+	/**
193
+	 * Sets the html_id to its default value, if none was specified in the constructor.
194
+	 * Calculation involves using the name and the parent's html id
195
+	 * return void
196
+	 *
197
+	 * @throws \EE_Error
198
+	 */
199
+	protected function _set_default_html_id_if_empty()
200
+	{
201
+		if (! $this->_html_id) {
202
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
203
+				$this->_html_id = $this->_parent_section->html_id()
204
+								  . '-'
205
+								  . $this->_prep_name_for_html_id($this->name());
206
+			} else {
207
+				$this->_html_id = $this->_prep_name_for_html_id($this->name());
208
+			}
209
+		}
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * _prep_name_for_html_id
216
+	 *
217
+	 * @param $name
218
+	 * @return string
219
+	 */
220
+	private function _prep_name_for_html_id($name)
221
+	{
222
+		return sanitize_key(str_replace(array('&nbsp;', ' ', '_'), '-', $name));
223
+	}
224 224
 
225 225
 
226 226
 
227
-    /**
228
-     * Returns the HTML, JS, and CSS necessary to display this form section on a page.
229
-     * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
230
-     * and call get_html when you want to output the html. Calling get_html_and_js after
231
-     * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
232
-     * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
233
-     * and so might stop working anytime.
234
-     *
235
-     * @return string
236
-     */
237
-    public function get_html_and_js()
238
-    {
239
-        return $this->get_html();
240
-    }
227
+	/**
228
+	 * Returns the HTML, JS, and CSS necessary to display this form section on a page.
229
+	 * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
230
+	 * and call get_html when you want to output the html. Calling get_html_and_js after
231
+	 * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
232
+	 * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
233
+	 * and so might stop working anytime.
234
+	 *
235
+	 * @return string
236
+	 */
237
+	public function get_html_and_js()
238
+	{
239
+		return $this->get_html();
240
+	}
241 241
 
242 242
 
243
-
244
-    /**
245
-     * Gets the HTML for displaying this form section
246
-     *
247
-     * @return string
248
-     */
249
-    abstract public function get_html();
250
-
251
-
252
-    /**
253
-     * @param bool $add_pound_sign
254
-     * @return string
255
-     * @throws EE_Error
256
-     */
257
-    public function html_id($add_pound_sign = false)
258
-    {
259
-        $this->_set_default_html_id_if_empty();
260
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @return string
267
-     */
268
-    public function html_class()
269
-    {
270
-        return $this->_html_class;
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * @return string
277
-     */
278
-    public function html_style()
279
-    {
280
-        return $this->_html_style;
281
-    }
282
-
283
-
284
-
285
-    /**
286
-     * @param mixed $html_class
287
-     */
288
-    public function set_html_class($html_class)
289
-    {
290
-        $this->_html_class = $html_class;
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * @param mixed $html_id
297
-     */
298
-    public function set_html_id($html_id)
299
-    {
300
-        $this->_html_id = $html_id;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * @param mixed $html_style
307
-     */
308
-    public function set_html_style($html_style)
309
-    {
310
-        $this->_html_style = $html_style;
311
-    }
312
-
313
-
314
-
315
-    /**
316
-     * @param string $other_html_attributes
317
-     */
318
-    public function set_other_html_attributes($other_html_attributes)
319
-    {
320
-        $this->_other_html_attributes = $other_html_attributes;
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * @return string
327
-     */
328
-    public function other_html_attributes()
329
-    {
330
-        return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : '';
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * Gets the name of the form section. This is not the same as the HTML name.
337
-     *
338
-     * @throws EE_Error
339
-     * @return string
340
-     */
341
-    public function name()
342
-    {
343
-        if (! $this->_construction_finalized) {
344
-            throw new EE_Error(sprintf(__(
345
-                'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
-                'event_espresso'
347
-            ), get_class($this)));
348
-        }
349
-        return $this->_name;
350
-    }
351
-
352
-
353
-
354
-    /**
355
-     * Gets the parent section
356
-     *
357
-     * @return EE_Form_Section_Proper
358
-     */
359
-    public function parent_section()
360
-    {
361
-        return $this->_parent_section;
362
-    }
363
-
364
-
365
-    /**
366
-     * returns HTML for generating the opening form HTML tag (<form>)
367
-     *
368
-     * @param string $action           the URL the form is submitted to
369
-     * @param string $method           POST (default) or GET
370
-     * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
-     * @return string
372
-     * @throws EE_Error
373
-     */
374
-    public function form_open($action = '', $method = '', $other_attributes = '')
375
-    {
376
-        if (! empty($action)) {
377
-            $this->set_action($action);
378
-        }
379
-        if (! empty($method)) {
380
-            $this->set_method($method);
381
-        }
382
-        $html = EEH_HTML::nl(1, 'form') . '<form';
383
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
384
-        $html .= ' action="' . $this->action() . '"';
385
-        $html .= ' method="' . $this->method() . '"';
386
-        $html .= ' name="' . $this->name() . '"';
387
-        $html .= $other_attributes . '>';
388
-        return $html;
389
-    }
390
-
391
-
392
-
393
-    /**
394
-     * ensures that html id for form either ends in "-form" or "-frm"
395
-     * so that id doesn't conflict/collide with other elements
396
-     *
397
-     * @param string $html_id
398
-     * @return string
399
-     */
400
-    protected function get_html_id_for_form($html_id)
401
-    {
402
-        $strlen = strlen($html_id);
403
-        $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
404
-            ? $html_id
405
-            : $html_id . '-frm';
406
-        return $html_id;
407
-    }
408
-
409
-
410
-    /**
411
-     * returns HTML for generating the closing form HTML tag (</form>)
412
-     *
413
-     * @return string
414
-     * @throws EE_Error
415
-     */
416
-    public function form_close()
417
-    {
418
-        return EEH_HTML::nl(-1, 'form')
419
-               . '</form>'
420
-               . EEH_HTML::nl()
421
-               . '<!-- end of ee-'
422
-               . $this->html_id()
423
-               . '-form -->'
424
-               . EEH_HTML::nl();
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
431
-     * wp_enqueue_style; the scripts could have optionally been registered earlier)
432
-     * Default does nothing, but child classes can override
433
-     *
434
-     * @return void
435
-     */
436
-    public function enqueue_js()
437
-    {
438
-        // defaults to enqueue NO js or css
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * Adds any extra data needed by js. Eventually we'll call wp_localize_script
445
-     * with it, and it will be on each form section's 'other_data' property.
446
-     * By default nothing is added, but child classes can extend this method to add something.
447
-     * Eg, if you have an input that will cause a modal dialog to appear,
448
-     * here you could add an entry like 'modal_dialog_inputs' to this array
449
-     * to map between the input's html ID and the modal dialogue's ID, so that
450
-     * your JS code will know where to find the modal dialog when the input is pressed.
451
-     * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
452
-     *
453
-     * @param array $form_other_js_data
454
-     * @return array
455
-     */
456
-    public function get_other_js_data($form_other_js_data = array())
457
-    {
458
-        return $form_other_js_data;
459
-    }
460
-
461
-
462
-
463
-    /**
464
-     * This isn't just the name of an input, it's a path pointing to an input. The
465
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
466
-     * dot-dot-slash (../) means to ascend into the parent section.
467
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
468
-     * which will be returned.
469
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
470
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
471
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
472
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
473
-     * Etc
474
-     *
475
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
476
-     * @return EE_Form_Section_Base
477
-     */
478
-    public function find_section_from_path($form_section_path)
479
-    {
480
-        if (strpos($form_section_path, '/') === 0) {
481
-            $form_section_path = substr($form_section_path, strlen('/'));
482
-        }
483
-        if (empty($form_section_path)) {
484
-            return $this;
485
-        }
486
-        if (strpos($form_section_path, '../') === 0) {
487
-            $parent = $this->parent_section();
488
-            $form_section_path = substr($form_section_path, strlen('../'));
489
-            if ($parent instanceof EE_Form_Section_Base) {
490
-                return $parent->find_section_from_path($form_section_path);
491
-            }
492
-            if (empty($form_section_path)) {
493
-                return $this;
494
-            }
495
-        }
496
-        // couldn't find it using simple parent following
497
-        return null;
498
-    }
243
+
244
+	/**
245
+	 * Gets the HTML for displaying this form section
246
+	 *
247
+	 * @return string
248
+	 */
249
+	abstract public function get_html();
250
+
251
+
252
+	/**
253
+	 * @param bool $add_pound_sign
254
+	 * @return string
255
+	 * @throws EE_Error
256
+	 */
257
+	public function html_id($add_pound_sign = false)
258
+	{
259
+		$this->_set_default_html_id_if_empty();
260
+		return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @return string
267
+	 */
268
+	public function html_class()
269
+	{
270
+		return $this->_html_class;
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * @return string
277
+	 */
278
+	public function html_style()
279
+	{
280
+		return $this->_html_style;
281
+	}
282
+
283
+
284
+
285
+	/**
286
+	 * @param mixed $html_class
287
+	 */
288
+	public function set_html_class($html_class)
289
+	{
290
+		$this->_html_class = $html_class;
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * @param mixed $html_id
297
+	 */
298
+	public function set_html_id($html_id)
299
+	{
300
+		$this->_html_id = $html_id;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * @param mixed $html_style
307
+	 */
308
+	public function set_html_style($html_style)
309
+	{
310
+		$this->_html_style = $html_style;
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * @param string $other_html_attributes
317
+	 */
318
+	public function set_other_html_attributes($other_html_attributes)
319
+	{
320
+		$this->_other_html_attributes = $other_html_attributes;
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * @return string
327
+	 */
328
+	public function other_html_attributes()
329
+	{
330
+		return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : '';
331
+	}
332
+
333
+
334
+
335
+	/**
336
+	 * Gets the name of the form section. This is not the same as the HTML name.
337
+	 *
338
+	 * @throws EE_Error
339
+	 * @return string
340
+	 */
341
+	public function name()
342
+	{
343
+		if (! $this->_construction_finalized) {
344
+			throw new EE_Error(sprintf(__(
345
+				'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
+				'event_espresso'
347
+			), get_class($this)));
348
+		}
349
+		return $this->_name;
350
+	}
351
+
352
+
353
+
354
+	/**
355
+	 * Gets the parent section
356
+	 *
357
+	 * @return EE_Form_Section_Proper
358
+	 */
359
+	public function parent_section()
360
+	{
361
+		return $this->_parent_section;
362
+	}
363
+
364
+
365
+	/**
366
+	 * returns HTML for generating the opening form HTML tag (<form>)
367
+	 *
368
+	 * @param string $action           the URL the form is submitted to
369
+	 * @param string $method           POST (default) or GET
370
+	 * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
+	 * @return string
372
+	 * @throws EE_Error
373
+	 */
374
+	public function form_open($action = '', $method = '', $other_attributes = '')
375
+	{
376
+		if (! empty($action)) {
377
+			$this->set_action($action);
378
+		}
379
+		if (! empty($method)) {
380
+			$this->set_method($method);
381
+		}
382
+		$html = EEH_HTML::nl(1, 'form') . '<form';
383
+		$html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
384
+		$html .= ' action="' . $this->action() . '"';
385
+		$html .= ' method="' . $this->method() . '"';
386
+		$html .= ' name="' . $this->name() . '"';
387
+		$html .= $other_attributes . '>';
388
+		return $html;
389
+	}
390
+
391
+
392
+
393
+	/**
394
+	 * ensures that html id for form either ends in "-form" or "-frm"
395
+	 * so that id doesn't conflict/collide with other elements
396
+	 *
397
+	 * @param string $html_id
398
+	 * @return string
399
+	 */
400
+	protected function get_html_id_for_form($html_id)
401
+	{
402
+		$strlen = strlen($html_id);
403
+		$html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
404
+			? $html_id
405
+			: $html_id . '-frm';
406
+		return $html_id;
407
+	}
408
+
409
+
410
+	/**
411
+	 * returns HTML for generating the closing form HTML tag (</form>)
412
+	 *
413
+	 * @return string
414
+	 * @throws EE_Error
415
+	 */
416
+	public function form_close()
417
+	{
418
+		return EEH_HTML::nl(-1, 'form')
419
+			   . '</form>'
420
+			   . EEH_HTML::nl()
421
+			   . '<!-- end of ee-'
422
+			   . $this->html_id()
423
+			   . '-form -->'
424
+			   . EEH_HTML::nl();
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
431
+	 * wp_enqueue_style; the scripts could have optionally been registered earlier)
432
+	 * Default does nothing, but child classes can override
433
+	 *
434
+	 * @return void
435
+	 */
436
+	public function enqueue_js()
437
+	{
438
+		// defaults to enqueue NO js or css
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * Adds any extra data needed by js. Eventually we'll call wp_localize_script
445
+	 * with it, and it will be on each form section's 'other_data' property.
446
+	 * By default nothing is added, but child classes can extend this method to add something.
447
+	 * Eg, if you have an input that will cause a modal dialog to appear,
448
+	 * here you could add an entry like 'modal_dialog_inputs' to this array
449
+	 * to map between the input's html ID and the modal dialogue's ID, so that
450
+	 * your JS code will know where to find the modal dialog when the input is pressed.
451
+	 * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
452
+	 *
453
+	 * @param array $form_other_js_data
454
+	 * @return array
455
+	 */
456
+	public function get_other_js_data($form_other_js_data = array())
457
+	{
458
+		return $form_other_js_data;
459
+	}
460
+
461
+
462
+
463
+	/**
464
+	 * This isn't just the name of an input, it's a path pointing to an input. The
465
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
466
+	 * dot-dot-slash (../) means to ascend into the parent section.
467
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
468
+	 * which will be returned.
469
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
470
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
471
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
472
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
473
+	 * Etc
474
+	 *
475
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
476
+	 * @return EE_Form_Section_Base
477
+	 */
478
+	public function find_section_from_path($form_section_path)
479
+	{
480
+		if (strpos($form_section_path, '/') === 0) {
481
+			$form_section_path = substr($form_section_path, strlen('/'));
482
+		}
483
+		if (empty($form_section_path)) {
484
+			return $this;
485
+		}
486
+		if (strpos($form_section_path, '../') === 0) {
487
+			$parent = $this->parent_section();
488
+			$form_section_path = substr($form_section_path, strlen('../'));
489
+			if ($parent instanceof EE_Form_Section_Base) {
490
+				return $parent->find_section_from_path($form_section_path);
491
+			}
492
+			if (empty($form_section_path)) {
493
+				return $this;
494
+			}
495
+		}
496
+		// couldn't find it using simple parent following
497
+		return null;
498
+	}
499 499
 }
500 500
 // End of file EE_Form_Section_Base.form.php
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         // used by display strategies
96 96
         // assign incoming values to properties
97 97
         foreach ($options_array as $key => $value) {
98
-            $key = '_' . $key;
98
+            $key = '_'.$key;
99 99
             if (property_exists($this, $key) && empty($this->{$key})) {
100 100
                 $this->{$key} = $value;
101 101
                 if ($key === '_subsections' && ! is_array($value)) {
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function ensure_construct_finalized_called()
137 137
     {
138
-        if (! $this->_construction_finalized) {
138
+        if ( ! $this->_construction_finalized) {
139 139
             $this->_construct_finalize($this->_parent_section, $this->_name);
140 140
         }
141 141
     }
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
      */
199 199
     protected function _set_default_html_id_if_empty()
200 200
     {
201
-        if (! $this->_html_id) {
201
+        if ( ! $this->_html_id) {
202 202
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
203 203
                 $this->_html_id = $this->_parent_section->html_id()
204 204
                                   . '-'
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
     public function html_id($add_pound_sign = false)
258 258
     {
259 259
         $this->_set_default_html_id_if_empty();
260
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
260
+        return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id;
261 261
     }
262 262
 
263 263
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
      */
328 328
     public function other_html_attributes()
329 329
     {
330
-        return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : '';
330
+        return ! empty($this->_other_html_attributes) ? ' '.$this->_other_html_attributes : '';
331 331
     }
332 332
 
333 333
 
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
      */
341 341
     public function name()
342 342
     {
343
-        if (! $this->_construction_finalized) {
343
+        if ( ! $this->_construction_finalized) {
344 344
             throw new EE_Error(sprintf(__(
345 345
                 'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346 346
                 'event_espresso'
@@ -373,18 +373,18 @@  discard block
 block discarded – undo
373 373
      */
374 374
     public function form_open($action = '', $method = '', $other_attributes = '')
375 375
     {
376
-        if (! empty($action)) {
376
+        if ( ! empty($action)) {
377 377
             $this->set_action($action);
378 378
         }
379
-        if (! empty($method)) {
379
+        if ( ! empty($method)) {
380 380
             $this->set_method($method);
381 381
         }
382
-        $html = EEH_HTML::nl(1, 'form') . '<form';
383
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
384
-        $html .= ' action="' . $this->action() . '"';
385
-        $html .= ' method="' . $this->method() . '"';
386
-        $html .= ' name="' . $this->name() . '"';
387
-        $html .= $other_attributes . '>';
382
+        $html = EEH_HTML::nl(1, 'form').'<form';
383
+        $html .= $this->html_id() !== '' ? ' id="'.$this->get_html_id_for_form($this->html_id()).'"' : '';
384
+        $html .= ' action="'.$this->action().'"';
385
+        $html .= ' method="'.$this->method().'"';
386
+        $html .= ' name="'.$this->name().'"';
387
+        $html .= $other_attributes.'>';
388 388
         return $html;
389 389
     }
390 390
 
@@ -400,9 +400,9 @@  discard block
 block discarded – undo
400 400
     protected function get_html_id_for_form($html_id)
401 401
     {
402 402
         $strlen = strlen($html_id);
403
-        $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
403
+        $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4
404 404
             ? $html_id
405
-            : $html_id . '-frm';
405
+            : $html_id.'-frm';
406 406
         return $html_id;
407 407
     }
408 408
 
Please login to merge, or discard this patch.
attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.php 1 patch
Indentation   +1425 added lines, -1425 removed lines patch added patch discarded remove patch
@@ -18,1433 +18,1433 @@
 block discarded – undo
18 18
 class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step
19 19
 {
20 20
 
21
-    /**
22
-     * @type bool $_print_copy_info
23
-     */
24
-    private $_print_copy_info = false;
25
-
26
-    /**
27
-     * @type array $_attendee_data
28
-     */
29
-    private $_attendee_data = array();
30
-
31
-    /**
32
-     * @type array $_required_questions
33
-     */
34
-    private $_required_questions = array();
35
-
36
-    /**
37
-     * @type array $_registration_answers
38
-     */
39
-    private $_registration_answers = array();
40
-
41
-
42
-    /**
43
-     *    class constructor
44
-     *
45
-     * @access    public
46
-     * @param    EE_Checkout $checkout
47
-     */
48
-    public function __construct(EE_Checkout $checkout)
49
-    {
50
-        $this->_slug = 'attendee_information';
51
-        $this->_name = esc_html__('Attendee Information', 'event_espresso');
52
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php';
53
-        $this->checkout = $checkout;
54
-        $this->_reset_success_message();
55
-        $this->set_instructions(
56
-            esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
57
-        );
58
-    }
59
-
60
-
61
-    public function translate_js_strings()
62
-    {
63
-        EE_Registry::$i18n_js_strings['required_field'] = esc_html__(
64
-            ' is a required question.',
65
-            'event_espresso'
66
-        );
67
-        EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__(
68
-            ' is a required question. Please enter a value for at least one of the options.',
69
-            'event_espresso'
70
-        );
71
-        EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
72
-            'Please answer all required questions correctly before proceeding.',
73
-            'event_espresso'
74
-        );
75
-        EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf(
76
-            esc_html_x(
77
-                'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
78
-                'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
79
-                'event_espresso'
80
-            ),
81
-            '<br/>'
82
-        );
83
-        EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__(
84
-            'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
85
-            'event_espresso'
86
-        );
87
-        EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__(
88
-            'You must enter a valid email address.',
89
-            'event_espresso'
90
-        );
91
-        EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
92
-            'You must enter a valid email address and answer all other required questions before you can proceed.',
93
-            'event_espresso'
94
-        );
95
-    }
96
-
97
-
98
-    public function enqueue_styles_and_scripts()
99
-    {
100
-    }
101
-
102
-
103
-    /**
104
-     * @return boolean
105
-     */
106
-    public function initialize_reg_step()
107
-    {
108
-        return true;
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EE_Form_Section_Proper
114
-     * @throws DomainException
115
-     * @throws EE_Error
116
-     * @throws InvalidArgumentException
117
-     * @throws ReflectionException
118
-     * @throws EntityNotFoundException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidInterfaceException
121
-     */
122
-    public function generate_reg_form()
123
-    {
124
-        /**
125
-         * @var $reg_config EE_Registration_Config
126
-         */
127
-        $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
21
+	/**
22
+	 * @type bool $_print_copy_info
23
+	 */
24
+	private $_print_copy_info = false;
25
+
26
+	/**
27
+	 * @type array $_attendee_data
28
+	 */
29
+	private $_attendee_data = array();
30
+
31
+	/**
32
+	 * @type array $_required_questions
33
+	 */
34
+	private $_required_questions = array();
35
+
36
+	/**
37
+	 * @type array $_registration_answers
38
+	 */
39
+	private $_registration_answers = array();
40
+
41
+
42
+	/**
43
+	 *    class constructor
44
+	 *
45
+	 * @access    public
46
+	 * @param    EE_Checkout $checkout
47
+	 */
48
+	public function __construct(EE_Checkout $checkout)
49
+	{
50
+		$this->_slug = 'attendee_information';
51
+		$this->_name = esc_html__('Attendee Information', 'event_espresso');
52
+		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php';
53
+		$this->checkout = $checkout;
54
+		$this->_reset_success_message();
55
+		$this->set_instructions(
56
+			esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
57
+		);
58
+	}
59
+
60
+
61
+	public function translate_js_strings()
62
+	{
63
+		EE_Registry::$i18n_js_strings['required_field'] = esc_html__(
64
+			' is a required question.',
65
+			'event_espresso'
66
+		);
67
+		EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__(
68
+			' is a required question. Please enter a value for at least one of the options.',
69
+			'event_espresso'
70
+		);
71
+		EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
72
+			'Please answer all required questions correctly before proceeding.',
73
+			'event_espresso'
74
+		);
75
+		EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf(
76
+			esc_html_x(
77
+				'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
78
+				'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
79
+				'event_espresso'
80
+			),
81
+			'<br/>'
82
+		);
83
+		EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__(
84
+			'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
85
+			'event_espresso'
86
+		);
87
+		EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__(
88
+			'You must enter a valid email address.',
89
+			'event_espresso'
90
+		);
91
+		EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
92
+			'You must enter a valid email address and answer all other required questions before you can proceed.',
93
+			'event_espresso'
94
+		);
95
+	}
96
+
97
+
98
+	public function enqueue_styles_and_scripts()
99
+	{
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return boolean
105
+	 */
106
+	public function initialize_reg_step()
107
+	{
108
+		return true;
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EE_Form_Section_Proper
114
+	 * @throws DomainException
115
+	 * @throws EE_Error
116
+	 * @throws InvalidArgumentException
117
+	 * @throws ReflectionException
118
+	 * @throws EntityNotFoundException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidInterfaceException
121
+	 */
122
+	public function generate_reg_form()
123
+	{
124
+		/**
125
+		 * @var $reg_config EE_Registration_Config
126
+		 */
127
+		$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
128 128
  
129
-        $this->_print_copy_info = $reg_config->copyAttendeeInfo();
130
-
131
-        $primary_registrant = null;
132
-        // autoload Line_Item_Display classes
133
-        EEH_Autoloader::register_line_item_display_autoloaders();
134
-        $Line_Item_Display = new EE_Line_Item_Display();
135
-        // calculate taxes
136
-        $Line_Item_Display->display_line_item(
137
-            $this->checkout->cart->get_grand_total(),
138
-            array('set_tax_rate' => true)
139
-        );
140
-        /** @var $subsections EE_Form_Section_Proper[] */
141
-        $extra_inputs_section = $this->reg_step_hidden_inputs();
142
-        $subsections = array(
143
-            'default_hidden_inputs' => $extra_inputs_section,
144
-        );
145
-
146
-        // if this isn't a revisit, and they have the privacy consent box enalbed, add it
147
-        if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) {
148
-            $extra_inputs_section->add_subsections(
149
-                array(
150
-                    'consent_box' => new EE_Form_Section_Proper(
151
-                        array(
152
-                            'layout_strategy' =>
153
-                                new EE_Template_Layout(
154
-                                    array(
155
-                                        'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php',
156
-                                    )
157
-                                ),
158
-                            'subsections'     => array(
159
-                                'consent' => new EE_Checkbox_Multi_Input(
160
-                                    array(
161
-                                        'consent' => $reg_config->getConsentCheckboxLabelText(),
162
-                                    ),
163
-                                    array(
164
-                                        'required'                          => true,
165
-                                        'required_validation_error_message' => esc_html__(
166
-                                            'You must consent to these terms in order to register.',
167
-                                            'event_espresso'
168
-                                        ),
169
-                                        'html_label_text'                   => '',
170
-                                    )
171
-                                ),
172
-                            ),
173
-                        )
174
-                    ),
175
-                ),
176
-                null,
177
-                false
178
-            );
179
-        }
180
-        $template_args = array(
181
-            'revisit'       => $this->checkout->revisit,
182
-            'registrations' => array(),
183
-            'ticket_count'  => array(),
184
-        );
185
-        // grab the saved registrations from the transaction
186
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
187
-        if ($registrations) {
188
-            foreach ($registrations as $registration) {
189
-                // can this registration be processed during this visit ?
190
-                if ($registration instanceof EE_Registration
191
-                    && $this->checkout->visit_allows_processing_of_this_registration($registration)
192
-                ) {
193
-                    $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration);
194
-                    $template_args['registrations'][ $registration->reg_url_link() ] = $registration;
195
-                    $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset(
196
-                        $template_args['ticket_count'][ $registration->ticket()->ID() ]
197
-                    )
198
-                        ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1
199
-                        : 1;
200
-                    $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
201
-                        $this->checkout->cart->get_grand_total(),
202
-                        'Ticket',
203
-                        array($registration->ticket()->ID())
204
-                    );
205
-                    $ticket_line_item = is_array($ticket_line_item)
206
-                        ? reset($ticket_line_item)
207
-                        : $ticket_line_item;
208
-                    $template_args['ticket_line_item'][ $registration->ticket()->ID() ] =
209
-                        $Line_Item_Display->display_line_item($ticket_line_item);
210
-                    if ($registration->is_primary_registrant()) {
211
-                        $primary_registrant = $registration->reg_url_link();
212
-                    }
213
-                }
214
-            }
215
-
216
-            if ($primary_registrant && count($registrations) > 1) {
217
-                $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
218
-                    ? $this->_copy_attendee_info_form()
219
-                    : $this->_auto_copy_attendee_info();
220
-                // generate hidden input
221
-                if (isset($subsections[ $primary_registrant ])
222
-                    && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
223
-                ) {
224
-                    $subsections[ $primary_registrant ]->add_subsections(
225
-                        $copy_options,
226
-                        'primary_registrant',
227
-                        false
228
-                    );
229
-                }
230
-            }
231
-        }
232
-        return new EE_Form_Section_Proper(
233
-            array(
234
-                'name'            => $this->reg_form_name(),
235
-                'html_id'         => $this->reg_form_name(),
236
-                'subsections'     => $subsections,
237
-                'layout_strategy' => new EE_Template_Layout(
238
-                    array(
239
-                        'layout_template_file' => $this->_template, // layout_template
240
-                        'template_args'        => $template_args,
241
-                    )
242
-                ),
243
-            )
244
-        );
245
-    }
246
-
247
-
248
-    /**
249
-     * @param EE_Registration $registration
250
-     * @return EE_Form_Section_Base
251
-     * @throws EE_Error
252
-     * @throws InvalidArgumentException
253
-     * @throws EntityNotFoundException
254
-     * @throws InvalidDataTypeException
255
-     * @throws InvalidInterfaceException
256
-     * @throws ReflectionException
257
-     */
258
-    private function _registrations_reg_form(EE_Registration $registration)
259
-    {
260
-        static $attendee_nmbr = 1;
261
-        $form_args = array();
262
-        // verify that registration has valid event
263
-        if ($registration->event() instanceof EE_Event) {
264
-            $field_name = 'Event_Question_Group.'
265
-                . EEM_Event_Question_Group::instance()->fieldNameForContext(
266
-                    $registration->is_primary_registrant()
267
-                );
268
-            $question_groups = $registration->event()->question_groups(
269
-                apply_filters(
270
-                    // @codingStandardsIgnoreStart
271
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
272
-                    // @codingStandardsIgnoreEnd
273
-                    [
274
-                        [
275
-                            'Event.EVT_ID'                     => $registration->event()->ID(),
276
-                            $field_name => true,
277
-                        ],
278
-                        'order_by' => ['QSG_order' => 'ASC'],
279
-                    ],
280
-                    $registration,
281
-                    $this
282
-                )
283
-            );
284
-            if ($question_groups) {
285
-                // array of params to pass to parent constructor
286
-                $form_args = array(
287
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
288
-                    'html_class'      => 'ee-reg-form-attendee-dv',
289
-                    'html_style'      => $this->checkout->admin_request
290
-                        ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
291
-                        : '',
292
-                    'subsections'     => array(),
293
-                    'layout_strategy' => new EE_Fieldset_Section_Layout(
294
-                        array(
295
-                            'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
296
-                            'legend_text'  => sprintf(
297
-                                esc_html_x(
298
-                                    'Attendee %d',
299
-                                    'Attendee 123',
300
-                                    'event_espresso'
301
-                                ),
302
-                                $attendee_nmbr
303
-                            ),
304
-                        )
305
-                    ),
306
-                );
307
-                foreach ($question_groups as $question_group) {
308
-                    if ($question_group instanceof EE_Question_Group) {
309
-                        $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form(
310
-                            $registration,
311
-                            $question_group
312
-                        );
313
-                    }
314
-                }
315
-                // add hidden input
316
-                $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
317
-                    $registration
318
-                );
319
-
320
-                /**
321
-                 * @var $reg_config EE_Registration_Config
322
-                 */
323
-                $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
324
-
325
-                // If we have question groups for additional attendees, then display the copy options
326
-                $this->_print_copy_info = apply_filters(
327
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo',
328
-                    $attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false,
329
-                    $attendee_nmbr
330
-                );
331
-
332
-                if ($registration->is_primary_registrant()) {
333
-                    // generate hidden input
334
-                    $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
335
-                        $registration
336
-                    );
337
-                }
338
-            }
339
-        }
340
-        $attendee_nmbr++;
341
-        return ! empty($form_args)
342
-            ? new EE_Form_Section_Proper($form_args)
343
-            : new EE_Form_Section_HTML();
344
-    }
345
-
346
-
347
-    /**
348
-     * @param EE_Registration $registration
349
-     * @param bool            $additional_attendee_reg_info
350
-     * @return EE_Form_Input_Base
351
-     * @throws EE_Error
352
-     */
353
-    private function _additional_attendee_reg_info_input(
354
-        EE_Registration $registration,
355
-        $additional_attendee_reg_info = true
356
-    ) {
357
-        // generate hidden input
358
-        return new EE_Hidden_Input(
359
-            array(
360
-                'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
361
-                'default' => $additional_attendee_reg_info,
362
-            )
363
-        );
364
-    }
365
-
366
-
367
-    /**
368
-     * @param EE_Registration   $registration
369
-     * @param EE_Question_Group $question_group
370
-     * @return EE_Form_Section_Proper
371
-     * @throws EE_Error
372
-     * @throws InvalidArgumentException
373
-     * @throws InvalidDataTypeException
374
-     * @throws InvalidInterfaceException
375
-     * @throws ReflectionException
376
-     */
377
-    private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group)
378
-    {
379
-        // array of params to pass to parent constructor
380
-        $form_args = array(
381
-            'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
382
-            'html_class'      => $this->checkout->admin_request
383
-                ? 'form-table ee-reg-form-qstn-grp-dv'
384
-                : 'ee-reg-form-qstn-grp-dv',
385
-            'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-'
386
-                                 . $registration->ID() . '-lbl',
387
-            'subsections'     => array(
388
-                'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
389
-            ),
390
-            'layout_strategy' => $this->checkout->admin_request
391
-                ? new EE_Admin_Two_Column_Layout()
392
-                : new EE_Div_Per_Section_Layout(),
393
-        );
394
-        // where params
395
-        $query_params = array('QST_deleted' => 0);
396
-        // don't load admin only questions on the frontend
397
-        if (! $this->checkout->admin_request) {
398
-            $query_params['QST_admin_only'] = array('!=', true);
399
-        }
400
-        $questions = $question_group->get_many_related(
401
-            'Question',
402
-            apply_filters(
403
-                'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
404
-                array(
405
-                    $query_params,
406
-                    'order_by' => array(
407
-                        'Question_Group_Question.QGQ_order' => 'ASC',
408
-                    ),
409
-                ),
410
-                $question_group,
411
-                $registration,
412
-                $this
413
-            )
414
-        );
415
-        // filter for additional content before questions
416
-        $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
417
-            apply_filters(
418
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
419
-                '',
420
-                $registration,
421
-                $question_group,
422
-                $this
423
-            )
424
-        );
425
-        // loop thru questions
426
-        foreach ($questions as $question) {
427
-            if ($question instanceof EE_Question) {
428
-                $identifier = $question->is_system_question()
429
-                    ? $question->system_ID()
430
-                    : $question->ID();
431
-                $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question);
432
-            }
433
-        }
434
-        $form_args['subsections'] = apply_filters(
435
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
436
-            $form_args['subsections'],
437
-            $registration,
438
-            $question_group,
439
-            $this
440
-        );
441
-        // filter for additional content after questions
442
-        $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
443
-            apply_filters(
444
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
445
-                '',
446
-                $registration,
447
-                $question_group,
448
-                $this
449
-            )
450
-        );
451
-        // d($form_args);
452
-        $question_group_reg_form = new EE_Form_Section_Proper($form_args);
453
-        return apply_filters(
454
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
455
-            $question_group_reg_form,
456
-            $registration,
457
-            $question_group,
458
-            $this
459
-        );
460
-    }
461
-
462
-
463
-    /**
464
-     * @param EE_Question_Group $question_group
465
-     * @return    EE_Form_Section_HTML
466
-     */
467
-    private function _question_group_header(EE_Question_Group $question_group)
468
-    {
469
-        $html = '';
470
-        // group_name
471
-        if ($question_group->show_group_name() && $question_group->name() !== '') {
472
-            if ($this->checkout->admin_request) {
473
-                $html .= EEH_HTML::br();
474
-                $html .= EEH_HTML::h3(
475
-                    $question_group->name(),
476
-                    '',
477
-                    'ee-reg-form-qstn-grp-title title',
478
-                    'font-size: 1.3em; padding-left:0;'
479
-                );
480
-            } else {
481
-                $html .= EEH_HTML::h4(
482
-                    $question_group->name(),
483
-                    '',
484
-                    'ee-reg-form-qstn-grp-title section-title'
485
-                );
486
-            }
487
-        }
488
-        // group_desc
489
-        if ($question_group->show_group_desc() && $question_group->desc() !== '') {
490
-            $html .= EEH_HTML::p(
491
-                $question_group->desc(),
492
-                '',
493
-                $this->checkout->admin_request
494
-                    ? 'ee-reg-form-qstn-grp-desc-pg'
495
-                    : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
496
-            );
497
-        }
498
-        return new EE_Form_Section_HTML($html);
499
-    }
500
-
501
-
502
-    /**
503
-     * @return    EE_Form_Section_Proper
504
-     * @throws EE_Error
505
-     * @throws InvalidArgumentException
506
-     * @throws ReflectionException
507
-     * @throws InvalidDataTypeException
508
-     * @throws InvalidInterfaceException
509
-     */
510
-    private function _copy_attendee_info_form()
511
-    {
512
-        // array of params to pass to parent constructor
513
-        return new EE_Form_Section_Proper(
514
-            array(
515
-                'subsections'     => $this->_copy_attendee_info_inputs(),
516
-                'layout_strategy' => new EE_Template_Layout(
517
-                    array(
518
-                        'layout_template_file'     => SPCO_REG_STEPS_PATH
519
-                                                      . $this->_slug
520
-                                                      . '/copy_attendee_info.template.php',
521
-                        'begin_template_file'      => null,
522
-                        'input_template_file'      => null,
523
-                        'subsection_template_file' => null,
524
-                        'end_template_file'        => null,
525
-                    )
526
-                ),
527
-            )
528
-        );
529
-    }
530
-
531
-
532
-    /**
533
-     * @return EE_Form_Section_HTML
534
-     * @throws DomainException
535
-     * @throws InvalidArgumentException
536
-     * @throws InvalidDataTypeException
537
-     * @throws InvalidInterfaceException
538
-     */
539
-    private function _auto_copy_attendee_info()
540
-    {
541
-        return new EE_Form_Section_HTML(
542
-            EEH_Template::locate_template(
543
-                SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php',
544
-                apply_filters(
545
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
546
-                    array()
547
-                ),
548
-                true,
549
-                true
550
-            )
551
-        );
552
-    }
553
-
554
-
555
-    /**
556
-     * @return array
557
-     * @throws EE_Error
558
-     * @throws InvalidArgumentException
559
-     * @throws ReflectionException
560
-     * @throws InvalidDataTypeException
561
-     * @throws InvalidInterfaceException
562
-     */
563
-    private function _copy_attendee_info_inputs()
564
-    {
565
-        $copy_attendee_info_inputs = array();
566
-        $prev_ticket = null;
567
-        // grab the saved registrations from the transaction
568
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
569
-        foreach ($registrations as $registration) {
570
-            // for all  attendees other than the primary attendee
571
-            if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
572
-                // if this is a new ticket OR if this is the very first additional attendee after the primary attendee
573
-                if ($registration->ticket()->ID() !== $prev_ticket) {
574
-                    $item_name = $registration->ticket()->name();
575
-                    $item_name .= $registration->ticket()->description() !== ''
576
-                        ? ' - ' . $registration->ticket()->description()
577
-                        : '';
578
-                    $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID(
579
-                    ) . ']' ] =
580
-                        new EE_Form_Section_HTML(
581
-                            '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
582
-                        );
583
-                    $prev_ticket = $registration->ticket()->ID();
584
-                }
585
-
586
-                $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] =
587
-                    new EE_Checkbox_Multi_Input(
588
-                        array(
589
-                            $registration->ID() => sprintf(
590
-                                esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'),
591
-                                $registration->count()
592
-                            ),
593
-                        ),
594
-                        array(
595
-                            'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
596
-                            'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
597
-                            'display_html_label_text' => false,
598
-                        )
599
-                    );
600
-            }
601
-        }
602
-        return $copy_attendee_info_inputs;
603
-    }
604
-
605
-
606
-    /**
607
-     * @param EE_Registration $registration
608
-     * @return    EE_Form_Input_Base
609
-     * @throws EE_Error
610
-     */
611
-    private function _additional_primary_registrant_inputs(EE_Registration $registration)
612
-    {
613
-        // generate hidden input
614
-        return new EE_Hidden_Input(
615
-            array(
616
-                'html_id' => 'primary_registrant',
617
-                'default' => $registration->reg_url_link(),
618
-            )
619
-        );
620
-    }
621
-
622
-
623
-    /**
624
-     * @param EE_Registration $registration
625
-     * @param EE_Question     $question
626
-     * @return EE_Form_Input_Base
627
-     * @throws EE_Error
628
-     * @throws InvalidArgumentException
629
-     * @throws InvalidDataTypeException
630
-     * @throws InvalidInterfaceException
631
-     * @throws ReflectionException
632
-     */
633
-    public function reg_form_question(EE_Registration $registration, EE_Question $question)
634
-    {
635
-
636
-        // if this question was for an attendee detail, then check for that answer
637
-        $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
638
-            $registration,
639
-            $question->system_ID()
640
-        );
641
-        $answer = $answer_value === null
642
-            ? EEM_Answer::instance()->get_one(
643
-                array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
644
-            )
645
-            : null;
646
-        // if NOT returning to edit an existing registration
647
-        // OR if this question is for an attendee property
648
-        // OR we still don't have an EE_Answer object
649
-        if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
650
-            // create an EE_Answer object for storing everything in
651
-            $answer = EE_Answer::new_instance(
652
-                array(
653
-                    'QST_ID' => $question->ID(),
654
-                    'REG_ID' => $registration->ID(),
655
-                )
656
-            );
657
-        }
658
-        // verify instance
659
-        if ($answer instanceof EE_Answer) {
660
-            if (! empty($answer_value)) {
661
-                $answer->set('ANS_value', $answer_value);
662
-            }
663
-            $answer->cache('Question', $question);
664
-            // remember system ID had a bug where sometimes it could be null
665
-            $answer_cache_id = $question->is_system_question()
666
-                ? $question->system_ID() . '-' . $registration->reg_url_link()
667
-                : $question->ID() . '-' . $registration->reg_url_link();
668
-            $registration->cache('Answer', $answer, $answer_cache_id);
669
-        }
670
-        return $this->_generate_question_input($registration, $question, $answer);
671
-    }
672
-
673
-
674
-    /**
675
-     * @param EE_Registration $registration
676
-     * @param EE_Question     $question
677
-     * @param                 $answer
678
-     * @return EE_Form_Input_Base
679
-     * @throws EE_Error
680
-     * @throws InvalidArgumentException
681
-     * @throws ReflectionException
682
-     * @throws InvalidDataTypeException
683
-     * @throws InvalidInterfaceException
684
-     */
685
-    private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer)
686
-    {
687
-        $identifier = $question->is_system_question()
688
-            ? $question->system_ID()
689
-            : $question->ID();
690
-        $this->_required_questions[ $identifier ] = $question->required() ? true : false;
691
-        add_filter(
692
-            'FHEE__EE_Question__generate_form_input__country_options',
693
-            array($this, 'use_cached_countries_for_form_input'),
694
-            10,
695
-            4
696
-        );
697
-        add_filter(
698
-            'FHEE__EE_Question__generate_form_input__state_options',
699
-            array($this, 'use_cached_states_for_form_input'),
700
-            10,
701
-            4
702
-        );
703
-        $input_constructor_args = array(
704
-            'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
705
-            'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
706
-            'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
707
-            'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
708
-            'html_label_class' => 'ee-reg-qstn',
709
-        );
710
-        $input_constructor_args['html_label_id'] .= '-lbl';
711
-        if ($answer instanceof EE_Answer && $answer->ID()) {
712
-            $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']';
713
-            $input_constructor_args['html_id'] .= '-' . $answer->ID();
714
-            $input_constructor_args['html_label_id'] .= '-' . $answer->ID();
715
-        }
716
-        $form_input = $question->generate_form_input(
717
-            $registration,
718
-            $answer,
719
-            $input_constructor_args
720
-        );
721
-        remove_filter(
722
-            'FHEE__EE_Question__generate_form_input__country_options',
723
-            array($this, 'use_cached_countries_for_form_input')
724
-        );
725
-        remove_filter(
726
-            'FHEE__EE_Question__generate_form_input__state_options',
727
-            array($this, 'use_cached_states_for_form_input')
728
-        );
729
-        return $form_input;
730
-    }
731
-
732
-
733
-    /**
734
-     * Gets the list of countries for the form input
735
-     *
736
-     * @param array|null      $countries_list
737
-     * @param EE_Question     $question
738
-     * @param EE_Registration $registration
739
-     * @param EE_Answer       $answer
740
-     * @return array 2d keys are country IDs, values are their names
741
-     * @throws EE_Error
742
-     * @throws InvalidArgumentException
743
-     * @throws InvalidDataTypeException
744
-     * @throws InvalidInterfaceException
745
-     * @throws ReflectionException
746
-     */
747
-    public function use_cached_countries_for_form_input(
748
-        $countries_list,
749
-        EE_Question $question = null,
750
-        EE_Registration $registration = null,
751
-        EE_Answer $answer = null
752
-    ) {
753
-        $country_options = array('' => '');
754
-        // get possibly cached list of countries
755
-        $countries = $this->checkout->action === 'process_reg_step'
756
-            ? EEM_Country::instance()->get_all_countries()
757
-            : EEM_Country::instance()->get_all_active_countries();
758
-        if (! empty($countries)) {
759
-            foreach ($countries as $country) {
760
-                if ($country instanceof EE_Country) {
761
-                    $country_options[ $country->ID() ] = $country->name();
762
-                }
763
-            }
764
-        }
765
-        if ($question instanceof EE_Question && $registration instanceof EE_Registration) {
766
-            $answer = EEM_Answer::instance()->get_one(
767
-                array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
768
-            );
769
-        } else {
770
-            $answer = EE_Answer::new_instance();
771
-        }
772
-        $country_options = apply_filters(
773
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
774
-            $country_options,
775
-            $this,
776
-            $registration,
777
-            $question,
778
-            $answer
779
-        );
780
-        return $country_options;
781
-    }
782
-
783
-
784
-    /**
785
-     * Gets the list of states for the form input
786
-     *
787
-     * @param array|null      $states_list
788
-     * @param EE_Question     $question
789
-     * @param EE_Registration $registration
790
-     * @param EE_Answer       $answer
791
-     * @return array 2d keys are state IDs, values are their names
792
-     * @throws EE_Error
793
-     * @throws InvalidArgumentException
794
-     * @throws InvalidDataTypeException
795
-     * @throws InvalidInterfaceException
796
-     * @throws ReflectionException
797
-     */
798
-    public function use_cached_states_for_form_input(
799
-        $states_list,
800
-        EE_Question $question = null,
801
-        EE_Registration $registration = null,
802
-        EE_Answer $answer = null
803
-    ) {
804
-        $state_options = array('' => array('' => ''));
805
-        $states = $this->checkout->action === 'process_reg_step'
806
-            ? EEM_State::instance()->get_all_states()
807
-            : EEM_State::instance()->get_all_active_states();
808
-        if (! empty($states)) {
809
-            foreach ($states as $state) {
810
-                if ($state instanceof EE_State) {
811
-                    $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name();
812
-                }
813
-            }
814
-        }
815
-        $state_options = apply_filters(
816
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
817
-            $state_options,
818
-            $this,
819
-            $registration,
820
-            $question,
821
-            $answer
822
-        );
823
-        return $state_options;
824
-    }
825
-
826
-
827
-    /********************************************************************************************************/
828
-    /****************************************  PROCESS REG STEP  ****************************************/
829
-    /********************************************************************************************************/
830
-
831
-
832
-    /**
833
-     * @return bool
834
-     * @throws EE_Error
835
-     * @throws InvalidArgumentException
836
-     * @throws ReflectionException
837
-     * @throws RuntimeException
838
-     * @throws InvalidDataTypeException
839
-     * @throws InvalidInterfaceException
840
-     */
841
-    public function process_reg_step()
842
-    {
843
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
844
-        // grab validated data from form
845
-        $valid_data = $this->checkout->current_step->valid_data();
846
-        // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
847
-        // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
848
-        // if we don't have any $valid_data then something went TERRIBLY WRONG !!!
849
-        if (empty($valid_data)) {
850
-            EE_Error::add_error(
851
-                esc_html__('No valid question responses were received.', 'event_espresso'),
852
-                __FILE__,
853
-                __FUNCTION__,
854
-                __LINE__
855
-            );
856
-            return false;
857
-        }
858
-        if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
859
-            EE_Error::add_error(
860
-                esc_html__(
861
-                    'A valid transaction could not be initiated for processing your registrations.',
862
-                    'event_espresso'
863
-                ),
864
-                __FILE__,
865
-                __FUNCTION__,
866
-                __LINE__
867
-            );
868
-            return false;
869
-        }
870
-        // get cached registrations
871
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
872
-        // verify we got the goods
873
-        if (empty($registrations)) {
874
-            // combine the old translated string with a new one, in order to not break translations
875
-            $error_message = esc_html__(
876
-                'Your form data could not be applied to any valid registrations.',
877
-                'event_espresso'
878
-            )
879
-            . sprintf(
880
-                esc_html_x(
881
-                    '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.',
882
-                    '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.',
883
-                    'event_espresso'
884
-                ),
885
-                '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
886
-                '</a>',
887
-                '<br />'
888
-            );
889
-            EE_Error::add_error(
890
-                $error_message,
891
-                __FILE__,
892
-                __FUNCTION__,
893
-                __LINE__
894
-            );
895
-            return false;
896
-        }
897
-        // extract attendee info from form data and save to model objects
898
-        $registrations_processed = $this->_process_registrations($registrations, $valid_data);
899
-        // if first pass thru SPCO,
900
-        // then let's check processed registrations against the total number of tickets in the cart
901
-        if ($registrations_processed === false) {
902
-            // but return immediately if the previous step exited early due to errors
903
-            return false;
904
-        }
905
-        if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
906
-            // generate a correctly translated string for all possible singular/plural combinations
907
-            if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
908
-                $error_msg = sprintf(
909
-                    esc_html_x(
910
-                        'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
911
-                        'There was 1 ticket in the Event Queue, but 2 registrations were processed',
912
-                        'event_espresso'
913
-                    ),
914
-                    $this->checkout->total_ticket_count,
915
-                    $registrations_processed
916
-                );
917
-            } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
918
-                $error_msg = sprintf(
919
-                    esc_html_x(
920
-                        'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
921
-                        'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed',
922
-                        'event_espresso'
923
-                    ),
924
-                    $this->checkout->total_ticket_count,
925
-                    $registrations_processed
926
-                );
927
-            } else {
928
-                $error_msg = sprintf(
929
-                    esc_html__(
930
-                        'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed',
931
-                        'event_espresso'
932
-                    ),
933
-                    $this->checkout->total_ticket_count,
934
-                    $registrations_processed
935
-                );
936
-            }
937
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
938
-            return false;
939
-        }
940
-        // mark this reg step as completed
941
-        $this->set_completed();
942
-        $this->_set_success_message(
943
-            esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
944
-        );
945
-        // do action in case a plugin wants to do something with the data submitted in step 1.
946
-        // passes EE_Single_Page_Checkout, and it's posted data
947
-        do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
948
-        return true;
949
-    }
950
-
951
-
952
-    /**
953
-     *    _process_registrations
954
-     *
955
-     * @param EE_Registration[] $registrations
956
-     * @param array[][]         $valid_data
957
-     * @return bool|int
958
-     * @throws EntityNotFoundException
959
-     * @throws EE_Error
960
-     * @throws InvalidArgumentException
961
-     * @throws ReflectionException
962
-     * @throws RuntimeException
963
-     * @throws InvalidDataTypeException
964
-     * @throws InvalidInterfaceException
965
-     */
966
-    private function _process_registrations($registrations = array(), $valid_data = array())
967
-    {
968
-        // load resources and set some defaults
969
-        EE_Registry::instance()->load_model('Attendee');
970
-        // holder for primary registrant attendee object
971
-        $this->checkout->primary_attendee_obj = null;
972
-        // array for tracking reg form data for the primary registrant
973
-        $primary_registrant = array(
974
-            'line_item_id' => null,
975
-        );
976
-        $copy_primary = false;
977
-        // reg form sections that do not contain inputs
978
-        $non_input_form_sections = array(
979
-            'primary_registrant',
980
-            'additional_attendee_reg_info',
981
-            'spco_copy_attendee_chk',
982
-        );
983
-        // attendee counter
984
-        $att_nmbr = 0;
985
-        // grab the saved registrations from the transaction
986
-        foreach ($registrations as $registration) {
987
-            // verify EE_Registration object
988
-            if (! $registration instanceof EE_Registration) {
989
-                EE_Error::add_error(
990
-                    esc_html__(
991
-                        'An invalid Registration object was discovered when attempting to process your registration information.',
992
-                        'event_espresso'
993
-                    ),
994
-                    __FILE__,
995
-                    __FUNCTION__,
996
-                    __LINE__
997
-                );
998
-                return false;
999
-            }
1000
-            /** @var string $reg_url_link */
1001
-            $reg_url_link = $registration->reg_url_link();
1002
-            // reg_url_link exists ?
1003
-            if (! empty($reg_url_link)) {
1004
-                // should this registration be processed during this visit ?
1005
-                if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
1006
-                    // if NOT revisiting, then let's save the registration now,
1007
-                    // so that we have a REG_ID to use when generating other objects
1008
-                    if (! $this->checkout->revisit) {
1009
-                        $registration->save();
1010
-                    }
1011
-                    /**
1012
-                     * This allows plugins to trigger a fail on processing of a
1013
-                     * registration for any conditions they may have for it to pass.
1014
-                     *
1015
-                     * @var bool   if true is returned by the plugin then the
1016
-                     *            registration processing is halted.
1017
-                     */
1018
-                    if (apply_filters(
1019
-                        'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
1020
-                        false,
1021
-                        $att_nmbr,
1022
-                        $registration,
1023
-                        $registrations,
1024
-                        $valid_data,
1025
-                        $this
1026
-                    )) {
1027
-                        return false;
1028
-                    }
1029
-
1030
-                    // Houston, we have a registration!
1031
-                    $att_nmbr++;
1032
-                    $this->_attendee_data[ $reg_url_link ] = array();
1033
-                    // grab any existing related answer objects
1034
-                    $this->_registration_answers = $registration->answers();
1035
-                    // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
1036
-                    if (isset($valid_data[ $reg_url_link ])) {
1037
-                        // do we need to copy basic info from primary attendee ?
1038
-                        $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info'])
1039
-                                        && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
1040
-                        // filter form input data for this registration
1041
-                        $valid_data[ $reg_url_link ] = (array) apply_filters(
1042
-                            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
1043
-                            $valid_data[ $reg_url_link ]
1044
-                        );
1045
-                        if (isset($valid_data['primary_attendee'])) {
1046
-                            $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
1047
-                                ? $valid_data['primary_attendee']
1048
-                                : false;
1049
-                            unset($valid_data['primary_attendee']);
1050
-                        }
1051
-                        // now loop through our array of valid post data && process attendee reg forms
1052
-                        foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) {
1053
-                            if (! in_array($form_section, $non_input_form_sections, true)) {
1054
-                                foreach ($form_inputs as $form_input => $input_value) {
1055
-                                    // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
1056
-                                    // check for critical inputs
1057
-                                    if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
1058
-                                        $form_input,
1059
-                                        $input_value
1060
-                                    )
1061
-                                    ) {
1062
-                                        return false;
1063
-                                    }
1064
-                                    // store a bit of data about the primary attendee
1065
-                                    if ($att_nmbr === 1
1066
-                                        && ! empty($input_value)
1067
-                                        && $reg_url_link === $primary_registrant['line_item_id']
1068
-                                    ) {
1069
-                                        $primary_registrant[ $form_input ] = $input_value;
1070
-                                    } elseif ($copy_primary
1071
-                                              && $input_value === null
1072
-                                              && isset($primary_registrant[ $form_input ])
1073
-                                    ) {
1074
-                                        $input_value = $primary_registrant[ $form_input ];
1075
-                                    }
1076
-                                    // now attempt to save the input data
1077
-                                    if (! $this->_save_registration_form_input(
1078
-                                        $registration,
1079
-                                        $form_input,
1080
-                                        $input_value
1081
-                                    )
1082
-                                    ) {
1083
-                                        EE_Error::add_error(
1084
-                                            sprintf(
1085
-                                                esc_html_x(
1086
-                                                    'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
1087
-                                                    'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"',
1088
-                                                    'event_espresso'
1089
-                                                ),
1090
-                                                $form_input,
1091
-                                                $input_value
1092
-                                            ),
1093
-                                            __FILE__,
1094
-                                            __FUNCTION__,
1095
-                                            __LINE__
1096
-                                        );
1097
-                                        return false;
1098
-                                    }
1099
-                                }
1100
-                            }
1101
-                        }  // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs )
1102
-                    }
1103
-                    // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ );
1104
-                    // this registration does not require additional attendee information ?
1105
-                    if ($copy_primary
1106
-                        && $att_nmbr > 1
1107
-                        && $this->checkout->primary_attendee_obj instanceof EE_Attendee
1108
-                    ) {
1109
-                        // just copy the primary registrant
1110
-                        $attendee = $this->checkout->primary_attendee_obj;
1111
-                    } else {
1112
-                        // ensure critical details are set for additional attendees
1113
-                        $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1
1114
-                            ? $this->_copy_critical_attendee_details_from_primary_registrant(
1115
-                                $this->_attendee_data[ $reg_url_link ]
1116
-                            )
1117
-                            : $this->_attendee_data[ $reg_url_link ];
1118
-                        // execute create attendee command (which may return an existing attendee)
1119
-                        $attendee = EE_Registry::instance()->BUS->execute(
1120
-                            new CreateAttendeeCommand(
1121
-                                $this->_attendee_data[ $reg_url_link ],
1122
-                                $registration
1123
-                            )
1124
-                        );
1125
-                        // who's #1 ?
1126
-                        if ($att_nmbr === 1) {
1127
-                            $this->checkout->primary_attendee_obj = $attendee;
1128
-                        }
1129
-                    }
1130
-                    // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
1131
-                    // add relation to registration, set attendee ID, and cache attendee
1132
-                    $this->_associate_attendee_with_registration($registration, $attendee);
1133
-                    // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1134
-                    if (! $registration->attendee() instanceof EE_Attendee) {
1135
-                        EE_Error::add_error(
1136
-                            sprintf(
1137
-                                esc_html_x(
1138
-                                    'Registration %s has an invalid or missing Attendee object.',
1139
-                                    'Registration 123-456-789 has an invalid or missing Attendee object.',
1140
-                                    'event_espresso'
1141
-                                ),
1142
-                                $reg_url_link
1143
-                            ),
1144
-                            __FILE__,
1145
-                            __FUNCTION__,
1146
-                            __LINE__
1147
-                        );
1148
-                        return false;
1149
-                    }
1150
-                    /** @type EE_Registration_Processor $registration_processor */
1151
-                    $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1152
-                    // at this point, we should have enough details about the registrant to consider the registration
1153
-                    // NOT incomplete
1154
-                    $registration_processor->toggle_incomplete_registration_status_to_default(
1155
-                        $registration,
1156
-                        false,
1157
-                        new Context(
1158
-                            'spco_reg_step_attendee_information_process_registrations',
1159
-                            esc_html__(
1160
-                                'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
1161
-                                'event_espresso'
1162
-                            )
1163
-                        )
1164
-                    );
1165
-                    // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
1166
-                    // abandoned
1167
-                    $this->checkout->transaction->toggle_failed_transaction_status();
1168
-                    // if we've gotten this far, then let's save what we have
1169
-                    $registration->save();
1170
-                    // add relation between TXN and registration
1171
-                    $this->_associate_registration_with_transaction($registration);
1172
-                }
1173
-            } else {
1174
-                EE_Error::add_error(
1175
-                    esc_html__(
1176
-                        'An invalid or missing line item ID was encountered while attempting to process the registration form.',
1177
-                        'event_espresso'
1178
-                    ),
1179
-                    __FILE__,
1180
-                    __FUNCTION__,
1181
-                    __LINE__
1182
-                );
1183
-                // remove malformed data
1184
-                unset($valid_data[ $reg_url_link ]);
1185
-                return false;
1186
-            }
1187
-        } // end of foreach ( $this->checkout->transaction->registrations()  as $registration )
1188
-        return $att_nmbr;
1189
-    }
1190
-
1191
-
1192
-    /**
1193
-     *    _save_registration_form_input
1194
-     *
1195
-     * @param EE_Registration $registration
1196
-     * @param string          $form_input
1197
-     * @param string          $input_value
1198
-     * @return bool
1199
-     * @throws EE_Error
1200
-     * @throws InvalidArgumentException
1201
-     * @throws InvalidDataTypeException
1202
-     * @throws InvalidInterfaceException
1203
-     * @throws ReflectionException
1204
-     */
1205
-    private function _save_registration_form_input(
1206
-        EE_Registration $registration,
1207
-        $form_input = '',
1208
-        $input_value = ''
1209
-    ) {
1210
-        // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
1211
-        // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ );
1212
-        // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1213
-        // allow for plugins to hook in and do their own processing of the form input.
1214
-        // For plugins to bypass normal processing here, they just need to return a boolean value.
1215
-        if (apply_filters(
1216
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1217
-            false,
1218
-            $registration,
1219
-            $form_input,
1220
-            $input_value,
1221
-            $this
1222
-        )) {
1223
-            return true;
1224
-        }
1225
-        /*
129
+		$this->_print_copy_info = $reg_config->copyAttendeeInfo();
130
+
131
+		$primary_registrant = null;
132
+		// autoload Line_Item_Display classes
133
+		EEH_Autoloader::register_line_item_display_autoloaders();
134
+		$Line_Item_Display = new EE_Line_Item_Display();
135
+		// calculate taxes
136
+		$Line_Item_Display->display_line_item(
137
+			$this->checkout->cart->get_grand_total(),
138
+			array('set_tax_rate' => true)
139
+		);
140
+		/** @var $subsections EE_Form_Section_Proper[] */
141
+		$extra_inputs_section = $this->reg_step_hidden_inputs();
142
+		$subsections = array(
143
+			'default_hidden_inputs' => $extra_inputs_section,
144
+		);
145
+
146
+		// if this isn't a revisit, and they have the privacy consent box enalbed, add it
147
+		if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) {
148
+			$extra_inputs_section->add_subsections(
149
+				array(
150
+					'consent_box' => new EE_Form_Section_Proper(
151
+						array(
152
+							'layout_strategy' =>
153
+								new EE_Template_Layout(
154
+									array(
155
+										'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php',
156
+									)
157
+								),
158
+							'subsections'     => array(
159
+								'consent' => new EE_Checkbox_Multi_Input(
160
+									array(
161
+										'consent' => $reg_config->getConsentCheckboxLabelText(),
162
+									),
163
+									array(
164
+										'required'                          => true,
165
+										'required_validation_error_message' => esc_html__(
166
+											'You must consent to these terms in order to register.',
167
+											'event_espresso'
168
+										),
169
+										'html_label_text'                   => '',
170
+									)
171
+								),
172
+							),
173
+						)
174
+					),
175
+				),
176
+				null,
177
+				false
178
+			);
179
+		}
180
+		$template_args = array(
181
+			'revisit'       => $this->checkout->revisit,
182
+			'registrations' => array(),
183
+			'ticket_count'  => array(),
184
+		);
185
+		// grab the saved registrations from the transaction
186
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
187
+		if ($registrations) {
188
+			foreach ($registrations as $registration) {
189
+				// can this registration be processed during this visit ?
190
+				if ($registration instanceof EE_Registration
191
+					&& $this->checkout->visit_allows_processing_of_this_registration($registration)
192
+				) {
193
+					$subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration);
194
+					$template_args['registrations'][ $registration->reg_url_link() ] = $registration;
195
+					$template_args['ticket_count'][ $registration->ticket()->ID() ] = isset(
196
+						$template_args['ticket_count'][ $registration->ticket()->ID() ]
197
+					)
198
+						? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1
199
+						: 1;
200
+					$ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
201
+						$this->checkout->cart->get_grand_total(),
202
+						'Ticket',
203
+						array($registration->ticket()->ID())
204
+					);
205
+					$ticket_line_item = is_array($ticket_line_item)
206
+						? reset($ticket_line_item)
207
+						: $ticket_line_item;
208
+					$template_args['ticket_line_item'][ $registration->ticket()->ID() ] =
209
+						$Line_Item_Display->display_line_item($ticket_line_item);
210
+					if ($registration->is_primary_registrant()) {
211
+						$primary_registrant = $registration->reg_url_link();
212
+					}
213
+				}
214
+			}
215
+
216
+			if ($primary_registrant && count($registrations) > 1) {
217
+				$copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
218
+					? $this->_copy_attendee_info_form()
219
+					: $this->_auto_copy_attendee_info();
220
+				// generate hidden input
221
+				if (isset($subsections[ $primary_registrant ])
222
+					&& $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
223
+				) {
224
+					$subsections[ $primary_registrant ]->add_subsections(
225
+						$copy_options,
226
+						'primary_registrant',
227
+						false
228
+					);
229
+				}
230
+			}
231
+		}
232
+		return new EE_Form_Section_Proper(
233
+			array(
234
+				'name'            => $this->reg_form_name(),
235
+				'html_id'         => $this->reg_form_name(),
236
+				'subsections'     => $subsections,
237
+				'layout_strategy' => new EE_Template_Layout(
238
+					array(
239
+						'layout_template_file' => $this->_template, // layout_template
240
+						'template_args'        => $template_args,
241
+					)
242
+				),
243
+			)
244
+		);
245
+	}
246
+
247
+
248
+	/**
249
+	 * @param EE_Registration $registration
250
+	 * @return EE_Form_Section_Base
251
+	 * @throws EE_Error
252
+	 * @throws InvalidArgumentException
253
+	 * @throws EntityNotFoundException
254
+	 * @throws InvalidDataTypeException
255
+	 * @throws InvalidInterfaceException
256
+	 * @throws ReflectionException
257
+	 */
258
+	private function _registrations_reg_form(EE_Registration $registration)
259
+	{
260
+		static $attendee_nmbr = 1;
261
+		$form_args = array();
262
+		// verify that registration has valid event
263
+		if ($registration->event() instanceof EE_Event) {
264
+			$field_name = 'Event_Question_Group.'
265
+				. EEM_Event_Question_Group::instance()->fieldNameForContext(
266
+					$registration->is_primary_registrant()
267
+				);
268
+			$question_groups = $registration->event()->question_groups(
269
+				apply_filters(
270
+					// @codingStandardsIgnoreStart
271
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
272
+					// @codingStandardsIgnoreEnd
273
+					[
274
+						[
275
+							'Event.EVT_ID'                     => $registration->event()->ID(),
276
+							$field_name => true,
277
+						],
278
+						'order_by' => ['QSG_order' => 'ASC'],
279
+					],
280
+					$registration,
281
+					$this
282
+				)
283
+			);
284
+			if ($question_groups) {
285
+				// array of params to pass to parent constructor
286
+				$form_args = array(
287
+					'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
288
+					'html_class'      => 'ee-reg-form-attendee-dv',
289
+					'html_style'      => $this->checkout->admin_request
290
+						? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
291
+						: '',
292
+					'subsections'     => array(),
293
+					'layout_strategy' => new EE_Fieldset_Section_Layout(
294
+						array(
295
+							'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
296
+							'legend_text'  => sprintf(
297
+								esc_html_x(
298
+									'Attendee %d',
299
+									'Attendee 123',
300
+									'event_espresso'
301
+								),
302
+								$attendee_nmbr
303
+							),
304
+						)
305
+					),
306
+				);
307
+				foreach ($question_groups as $question_group) {
308
+					if ($question_group instanceof EE_Question_Group) {
309
+						$form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form(
310
+							$registration,
311
+							$question_group
312
+						);
313
+					}
314
+				}
315
+				// add hidden input
316
+				$form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
317
+					$registration
318
+				);
319
+
320
+				/**
321
+				 * @var $reg_config EE_Registration_Config
322
+				 */
323
+				$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
324
+
325
+				// If we have question groups for additional attendees, then display the copy options
326
+				$this->_print_copy_info = apply_filters(
327
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo',
328
+					$attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false,
329
+					$attendee_nmbr
330
+				);
331
+
332
+				if ($registration->is_primary_registrant()) {
333
+					// generate hidden input
334
+					$form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
335
+						$registration
336
+					);
337
+				}
338
+			}
339
+		}
340
+		$attendee_nmbr++;
341
+		return ! empty($form_args)
342
+			? new EE_Form_Section_Proper($form_args)
343
+			: new EE_Form_Section_HTML();
344
+	}
345
+
346
+
347
+	/**
348
+	 * @param EE_Registration $registration
349
+	 * @param bool            $additional_attendee_reg_info
350
+	 * @return EE_Form_Input_Base
351
+	 * @throws EE_Error
352
+	 */
353
+	private function _additional_attendee_reg_info_input(
354
+		EE_Registration $registration,
355
+		$additional_attendee_reg_info = true
356
+	) {
357
+		// generate hidden input
358
+		return new EE_Hidden_Input(
359
+			array(
360
+				'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
361
+				'default' => $additional_attendee_reg_info,
362
+			)
363
+		);
364
+	}
365
+
366
+
367
+	/**
368
+	 * @param EE_Registration   $registration
369
+	 * @param EE_Question_Group $question_group
370
+	 * @return EE_Form_Section_Proper
371
+	 * @throws EE_Error
372
+	 * @throws InvalidArgumentException
373
+	 * @throws InvalidDataTypeException
374
+	 * @throws InvalidInterfaceException
375
+	 * @throws ReflectionException
376
+	 */
377
+	private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group)
378
+	{
379
+		// array of params to pass to parent constructor
380
+		$form_args = array(
381
+			'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
382
+			'html_class'      => $this->checkout->admin_request
383
+				? 'form-table ee-reg-form-qstn-grp-dv'
384
+				: 'ee-reg-form-qstn-grp-dv',
385
+			'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-'
386
+								 . $registration->ID() . '-lbl',
387
+			'subsections'     => array(
388
+				'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
389
+			),
390
+			'layout_strategy' => $this->checkout->admin_request
391
+				? new EE_Admin_Two_Column_Layout()
392
+				: new EE_Div_Per_Section_Layout(),
393
+		);
394
+		// where params
395
+		$query_params = array('QST_deleted' => 0);
396
+		// don't load admin only questions on the frontend
397
+		if (! $this->checkout->admin_request) {
398
+			$query_params['QST_admin_only'] = array('!=', true);
399
+		}
400
+		$questions = $question_group->get_many_related(
401
+			'Question',
402
+			apply_filters(
403
+				'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
404
+				array(
405
+					$query_params,
406
+					'order_by' => array(
407
+						'Question_Group_Question.QGQ_order' => 'ASC',
408
+					),
409
+				),
410
+				$question_group,
411
+				$registration,
412
+				$this
413
+			)
414
+		);
415
+		// filter for additional content before questions
416
+		$form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
417
+			apply_filters(
418
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
419
+				'',
420
+				$registration,
421
+				$question_group,
422
+				$this
423
+			)
424
+		);
425
+		// loop thru questions
426
+		foreach ($questions as $question) {
427
+			if ($question instanceof EE_Question) {
428
+				$identifier = $question->is_system_question()
429
+					? $question->system_ID()
430
+					: $question->ID();
431
+				$form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question);
432
+			}
433
+		}
434
+		$form_args['subsections'] = apply_filters(
435
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
436
+			$form_args['subsections'],
437
+			$registration,
438
+			$question_group,
439
+			$this
440
+		);
441
+		// filter for additional content after questions
442
+		$form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
443
+			apply_filters(
444
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
445
+				'',
446
+				$registration,
447
+				$question_group,
448
+				$this
449
+			)
450
+		);
451
+		// d($form_args);
452
+		$question_group_reg_form = new EE_Form_Section_Proper($form_args);
453
+		return apply_filters(
454
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
455
+			$question_group_reg_form,
456
+			$registration,
457
+			$question_group,
458
+			$this
459
+		);
460
+	}
461
+
462
+
463
+	/**
464
+	 * @param EE_Question_Group $question_group
465
+	 * @return    EE_Form_Section_HTML
466
+	 */
467
+	private function _question_group_header(EE_Question_Group $question_group)
468
+	{
469
+		$html = '';
470
+		// group_name
471
+		if ($question_group->show_group_name() && $question_group->name() !== '') {
472
+			if ($this->checkout->admin_request) {
473
+				$html .= EEH_HTML::br();
474
+				$html .= EEH_HTML::h3(
475
+					$question_group->name(),
476
+					'',
477
+					'ee-reg-form-qstn-grp-title title',
478
+					'font-size: 1.3em; padding-left:0;'
479
+				);
480
+			} else {
481
+				$html .= EEH_HTML::h4(
482
+					$question_group->name(),
483
+					'',
484
+					'ee-reg-form-qstn-grp-title section-title'
485
+				);
486
+			}
487
+		}
488
+		// group_desc
489
+		if ($question_group->show_group_desc() && $question_group->desc() !== '') {
490
+			$html .= EEH_HTML::p(
491
+				$question_group->desc(),
492
+				'',
493
+				$this->checkout->admin_request
494
+					? 'ee-reg-form-qstn-grp-desc-pg'
495
+					: 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
496
+			);
497
+		}
498
+		return new EE_Form_Section_HTML($html);
499
+	}
500
+
501
+
502
+	/**
503
+	 * @return    EE_Form_Section_Proper
504
+	 * @throws EE_Error
505
+	 * @throws InvalidArgumentException
506
+	 * @throws ReflectionException
507
+	 * @throws InvalidDataTypeException
508
+	 * @throws InvalidInterfaceException
509
+	 */
510
+	private function _copy_attendee_info_form()
511
+	{
512
+		// array of params to pass to parent constructor
513
+		return new EE_Form_Section_Proper(
514
+			array(
515
+				'subsections'     => $this->_copy_attendee_info_inputs(),
516
+				'layout_strategy' => new EE_Template_Layout(
517
+					array(
518
+						'layout_template_file'     => SPCO_REG_STEPS_PATH
519
+													  . $this->_slug
520
+													  . '/copy_attendee_info.template.php',
521
+						'begin_template_file'      => null,
522
+						'input_template_file'      => null,
523
+						'subsection_template_file' => null,
524
+						'end_template_file'        => null,
525
+					)
526
+				),
527
+			)
528
+		);
529
+	}
530
+
531
+
532
+	/**
533
+	 * @return EE_Form_Section_HTML
534
+	 * @throws DomainException
535
+	 * @throws InvalidArgumentException
536
+	 * @throws InvalidDataTypeException
537
+	 * @throws InvalidInterfaceException
538
+	 */
539
+	private function _auto_copy_attendee_info()
540
+	{
541
+		return new EE_Form_Section_HTML(
542
+			EEH_Template::locate_template(
543
+				SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php',
544
+				apply_filters(
545
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
546
+					array()
547
+				),
548
+				true,
549
+				true
550
+			)
551
+		);
552
+	}
553
+
554
+
555
+	/**
556
+	 * @return array
557
+	 * @throws EE_Error
558
+	 * @throws InvalidArgumentException
559
+	 * @throws ReflectionException
560
+	 * @throws InvalidDataTypeException
561
+	 * @throws InvalidInterfaceException
562
+	 */
563
+	private function _copy_attendee_info_inputs()
564
+	{
565
+		$copy_attendee_info_inputs = array();
566
+		$prev_ticket = null;
567
+		// grab the saved registrations from the transaction
568
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
569
+		foreach ($registrations as $registration) {
570
+			// for all  attendees other than the primary attendee
571
+			if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
572
+				// if this is a new ticket OR if this is the very first additional attendee after the primary attendee
573
+				if ($registration->ticket()->ID() !== $prev_ticket) {
574
+					$item_name = $registration->ticket()->name();
575
+					$item_name .= $registration->ticket()->description() !== ''
576
+						? ' - ' . $registration->ticket()->description()
577
+						: '';
578
+					$copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID(
579
+					) . ']' ] =
580
+						new EE_Form_Section_HTML(
581
+							'<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
582
+						);
583
+					$prev_ticket = $registration->ticket()->ID();
584
+				}
585
+
586
+				$copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] =
587
+					new EE_Checkbox_Multi_Input(
588
+						array(
589
+							$registration->ID() => sprintf(
590
+								esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'),
591
+								$registration->count()
592
+							),
593
+						),
594
+						array(
595
+							'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
596
+							'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
597
+							'display_html_label_text' => false,
598
+						)
599
+					);
600
+			}
601
+		}
602
+		return $copy_attendee_info_inputs;
603
+	}
604
+
605
+
606
+	/**
607
+	 * @param EE_Registration $registration
608
+	 * @return    EE_Form_Input_Base
609
+	 * @throws EE_Error
610
+	 */
611
+	private function _additional_primary_registrant_inputs(EE_Registration $registration)
612
+	{
613
+		// generate hidden input
614
+		return new EE_Hidden_Input(
615
+			array(
616
+				'html_id' => 'primary_registrant',
617
+				'default' => $registration->reg_url_link(),
618
+			)
619
+		);
620
+	}
621
+
622
+
623
+	/**
624
+	 * @param EE_Registration $registration
625
+	 * @param EE_Question     $question
626
+	 * @return EE_Form_Input_Base
627
+	 * @throws EE_Error
628
+	 * @throws InvalidArgumentException
629
+	 * @throws InvalidDataTypeException
630
+	 * @throws InvalidInterfaceException
631
+	 * @throws ReflectionException
632
+	 */
633
+	public function reg_form_question(EE_Registration $registration, EE_Question $question)
634
+	{
635
+
636
+		// if this question was for an attendee detail, then check for that answer
637
+		$answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
638
+			$registration,
639
+			$question->system_ID()
640
+		);
641
+		$answer = $answer_value === null
642
+			? EEM_Answer::instance()->get_one(
643
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
644
+			)
645
+			: null;
646
+		// if NOT returning to edit an existing registration
647
+		// OR if this question is for an attendee property
648
+		// OR we still don't have an EE_Answer object
649
+		if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
650
+			// create an EE_Answer object for storing everything in
651
+			$answer = EE_Answer::new_instance(
652
+				array(
653
+					'QST_ID' => $question->ID(),
654
+					'REG_ID' => $registration->ID(),
655
+				)
656
+			);
657
+		}
658
+		// verify instance
659
+		if ($answer instanceof EE_Answer) {
660
+			if (! empty($answer_value)) {
661
+				$answer->set('ANS_value', $answer_value);
662
+			}
663
+			$answer->cache('Question', $question);
664
+			// remember system ID had a bug where sometimes it could be null
665
+			$answer_cache_id = $question->is_system_question()
666
+				? $question->system_ID() . '-' . $registration->reg_url_link()
667
+				: $question->ID() . '-' . $registration->reg_url_link();
668
+			$registration->cache('Answer', $answer, $answer_cache_id);
669
+		}
670
+		return $this->_generate_question_input($registration, $question, $answer);
671
+	}
672
+
673
+
674
+	/**
675
+	 * @param EE_Registration $registration
676
+	 * @param EE_Question     $question
677
+	 * @param                 $answer
678
+	 * @return EE_Form_Input_Base
679
+	 * @throws EE_Error
680
+	 * @throws InvalidArgumentException
681
+	 * @throws ReflectionException
682
+	 * @throws InvalidDataTypeException
683
+	 * @throws InvalidInterfaceException
684
+	 */
685
+	private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer)
686
+	{
687
+		$identifier = $question->is_system_question()
688
+			? $question->system_ID()
689
+			: $question->ID();
690
+		$this->_required_questions[ $identifier ] = $question->required() ? true : false;
691
+		add_filter(
692
+			'FHEE__EE_Question__generate_form_input__country_options',
693
+			array($this, 'use_cached_countries_for_form_input'),
694
+			10,
695
+			4
696
+		);
697
+		add_filter(
698
+			'FHEE__EE_Question__generate_form_input__state_options',
699
+			array($this, 'use_cached_states_for_form_input'),
700
+			10,
701
+			4
702
+		);
703
+		$input_constructor_args = array(
704
+			'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
705
+			'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
706
+			'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
707
+			'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
708
+			'html_label_class' => 'ee-reg-qstn',
709
+		);
710
+		$input_constructor_args['html_label_id'] .= '-lbl';
711
+		if ($answer instanceof EE_Answer && $answer->ID()) {
712
+			$input_constructor_args['html_name'] .= '[' . $answer->ID() . ']';
713
+			$input_constructor_args['html_id'] .= '-' . $answer->ID();
714
+			$input_constructor_args['html_label_id'] .= '-' . $answer->ID();
715
+		}
716
+		$form_input = $question->generate_form_input(
717
+			$registration,
718
+			$answer,
719
+			$input_constructor_args
720
+		);
721
+		remove_filter(
722
+			'FHEE__EE_Question__generate_form_input__country_options',
723
+			array($this, 'use_cached_countries_for_form_input')
724
+		);
725
+		remove_filter(
726
+			'FHEE__EE_Question__generate_form_input__state_options',
727
+			array($this, 'use_cached_states_for_form_input')
728
+		);
729
+		return $form_input;
730
+	}
731
+
732
+
733
+	/**
734
+	 * Gets the list of countries for the form input
735
+	 *
736
+	 * @param array|null      $countries_list
737
+	 * @param EE_Question     $question
738
+	 * @param EE_Registration $registration
739
+	 * @param EE_Answer       $answer
740
+	 * @return array 2d keys are country IDs, values are their names
741
+	 * @throws EE_Error
742
+	 * @throws InvalidArgumentException
743
+	 * @throws InvalidDataTypeException
744
+	 * @throws InvalidInterfaceException
745
+	 * @throws ReflectionException
746
+	 */
747
+	public function use_cached_countries_for_form_input(
748
+		$countries_list,
749
+		EE_Question $question = null,
750
+		EE_Registration $registration = null,
751
+		EE_Answer $answer = null
752
+	) {
753
+		$country_options = array('' => '');
754
+		// get possibly cached list of countries
755
+		$countries = $this->checkout->action === 'process_reg_step'
756
+			? EEM_Country::instance()->get_all_countries()
757
+			: EEM_Country::instance()->get_all_active_countries();
758
+		if (! empty($countries)) {
759
+			foreach ($countries as $country) {
760
+				if ($country instanceof EE_Country) {
761
+					$country_options[ $country->ID() ] = $country->name();
762
+				}
763
+			}
764
+		}
765
+		if ($question instanceof EE_Question && $registration instanceof EE_Registration) {
766
+			$answer = EEM_Answer::instance()->get_one(
767
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
768
+			);
769
+		} else {
770
+			$answer = EE_Answer::new_instance();
771
+		}
772
+		$country_options = apply_filters(
773
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
774
+			$country_options,
775
+			$this,
776
+			$registration,
777
+			$question,
778
+			$answer
779
+		);
780
+		return $country_options;
781
+	}
782
+
783
+
784
+	/**
785
+	 * Gets the list of states for the form input
786
+	 *
787
+	 * @param array|null      $states_list
788
+	 * @param EE_Question     $question
789
+	 * @param EE_Registration $registration
790
+	 * @param EE_Answer       $answer
791
+	 * @return array 2d keys are state IDs, values are their names
792
+	 * @throws EE_Error
793
+	 * @throws InvalidArgumentException
794
+	 * @throws InvalidDataTypeException
795
+	 * @throws InvalidInterfaceException
796
+	 * @throws ReflectionException
797
+	 */
798
+	public function use_cached_states_for_form_input(
799
+		$states_list,
800
+		EE_Question $question = null,
801
+		EE_Registration $registration = null,
802
+		EE_Answer $answer = null
803
+	) {
804
+		$state_options = array('' => array('' => ''));
805
+		$states = $this->checkout->action === 'process_reg_step'
806
+			? EEM_State::instance()->get_all_states()
807
+			: EEM_State::instance()->get_all_active_states();
808
+		if (! empty($states)) {
809
+			foreach ($states as $state) {
810
+				if ($state instanceof EE_State) {
811
+					$state_options[ $state->country()->name() ][ $state->ID() ] = $state->name();
812
+				}
813
+			}
814
+		}
815
+		$state_options = apply_filters(
816
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
817
+			$state_options,
818
+			$this,
819
+			$registration,
820
+			$question,
821
+			$answer
822
+		);
823
+		return $state_options;
824
+	}
825
+
826
+
827
+	/********************************************************************************************************/
828
+	/****************************************  PROCESS REG STEP  ****************************************/
829
+	/********************************************************************************************************/
830
+
831
+
832
+	/**
833
+	 * @return bool
834
+	 * @throws EE_Error
835
+	 * @throws InvalidArgumentException
836
+	 * @throws ReflectionException
837
+	 * @throws RuntimeException
838
+	 * @throws InvalidDataTypeException
839
+	 * @throws InvalidInterfaceException
840
+	 */
841
+	public function process_reg_step()
842
+	{
843
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
844
+		// grab validated data from form
845
+		$valid_data = $this->checkout->current_step->valid_data();
846
+		// EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
847
+		// EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
848
+		// if we don't have any $valid_data then something went TERRIBLY WRONG !!!
849
+		if (empty($valid_data)) {
850
+			EE_Error::add_error(
851
+				esc_html__('No valid question responses were received.', 'event_espresso'),
852
+				__FILE__,
853
+				__FUNCTION__,
854
+				__LINE__
855
+			);
856
+			return false;
857
+		}
858
+		if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
859
+			EE_Error::add_error(
860
+				esc_html__(
861
+					'A valid transaction could not be initiated for processing your registrations.',
862
+					'event_espresso'
863
+				),
864
+				__FILE__,
865
+				__FUNCTION__,
866
+				__LINE__
867
+			);
868
+			return false;
869
+		}
870
+		// get cached registrations
871
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
872
+		// verify we got the goods
873
+		if (empty($registrations)) {
874
+			// combine the old translated string with a new one, in order to not break translations
875
+			$error_message = esc_html__(
876
+				'Your form data could not be applied to any valid registrations.',
877
+				'event_espresso'
878
+			)
879
+			. sprintf(
880
+				esc_html_x(
881
+					'%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.',
882
+					'(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.',
883
+					'event_espresso'
884
+				),
885
+				'<a href="' . get_post_type_archive_link('espresso_events') . '" >',
886
+				'</a>',
887
+				'<br />'
888
+			);
889
+			EE_Error::add_error(
890
+				$error_message,
891
+				__FILE__,
892
+				__FUNCTION__,
893
+				__LINE__
894
+			);
895
+			return false;
896
+		}
897
+		// extract attendee info from form data and save to model objects
898
+		$registrations_processed = $this->_process_registrations($registrations, $valid_data);
899
+		// if first pass thru SPCO,
900
+		// then let's check processed registrations against the total number of tickets in the cart
901
+		if ($registrations_processed === false) {
902
+			// but return immediately if the previous step exited early due to errors
903
+			return false;
904
+		}
905
+		if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
906
+			// generate a correctly translated string for all possible singular/plural combinations
907
+			if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
908
+				$error_msg = sprintf(
909
+					esc_html_x(
910
+						'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
911
+						'There was 1 ticket in the Event Queue, but 2 registrations were processed',
912
+						'event_espresso'
913
+					),
914
+					$this->checkout->total_ticket_count,
915
+					$registrations_processed
916
+				);
917
+			} elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
918
+				$error_msg = sprintf(
919
+					esc_html_x(
920
+						'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
921
+						'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed',
922
+						'event_espresso'
923
+					),
924
+					$this->checkout->total_ticket_count,
925
+					$registrations_processed
926
+				);
927
+			} else {
928
+				$error_msg = sprintf(
929
+					esc_html__(
930
+						'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed',
931
+						'event_espresso'
932
+					),
933
+					$this->checkout->total_ticket_count,
934
+					$registrations_processed
935
+				);
936
+			}
937
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
938
+			return false;
939
+		}
940
+		// mark this reg step as completed
941
+		$this->set_completed();
942
+		$this->_set_success_message(
943
+			esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
944
+		);
945
+		// do action in case a plugin wants to do something with the data submitted in step 1.
946
+		// passes EE_Single_Page_Checkout, and it's posted data
947
+		do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
948
+		return true;
949
+	}
950
+
951
+
952
+	/**
953
+	 *    _process_registrations
954
+	 *
955
+	 * @param EE_Registration[] $registrations
956
+	 * @param array[][]         $valid_data
957
+	 * @return bool|int
958
+	 * @throws EntityNotFoundException
959
+	 * @throws EE_Error
960
+	 * @throws InvalidArgumentException
961
+	 * @throws ReflectionException
962
+	 * @throws RuntimeException
963
+	 * @throws InvalidDataTypeException
964
+	 * @throws InvalidInterfaceException
965
+	 */
966
+	private function _process_registrations($registrations = array(), $valid_data = array())
967
+	{
968
+		// load resources and set some defaults
969
+		EE_Registry::instance()->load_model('Attendee');
970
+		// holder for primary registrant attendee object
971
+		$this->checkout->primary_attendee_obj = null;
972
+		// array for tracking reg form data for the primary registrant
973
+		$primary_registrant = array(
974
+			'line_item_id' => null,
975
+		);
976
+		$copy_primary = false;
977
+		// reg form sections that do not contain inputs
978
+		$non_input_form_sections = array(
979
+			'primary_registrant',
980
+			'additional_attendee_reg_info',
981
+			'spco_copy_attendee_chk',
982
+		);
983
+		// attendee counter
984
+		$att_nmbr = 0;
985
+		// grab the saved registrations from the transaction
986
+		foreach ($registrations as $registration) {
987
+			// verify EE_Registration object
988
+			if (! $registration instanceof EE_Registration) {
989
+				EE_Error::add_error(
990
+					esc_html__(
991
+						'An invalid Registration object was discovered when attempting to process your registration information.',
992
+						'event_espresso'
993
+					),
994
+					__FILE__,
995
+					__FUNCTION__,
996
+					__LINE__
997
+				);
998
+				return false;
999
+			}
1000
+			/** @var string $reg_url_link */
1001
+			$reg_url_link = $registration->reg_url_link();
1002
+			// reg_url_link exists ?
1003
+			if (! empty($reg_url_link)) {
1004
+				// should this registration be processed during this visit ?
1005
+				if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
1006
+					// if NOT revisiting, then let's save the registration now,
1007
+					// so that we have a REG_ID to use when generating other objects
1008
+					if (! $this->checkout->revisit) {
1009
+						$registration->save();
1010
+					}
1011
+					/**
1012
+					 * This allows plugins to trigger a fail on processing of a
1013
+					 * registration for any conditions they may have for it to pass.
1014
+					 *
1015
+					 * @var bool   if true is returned by the plugin then the
1016
+					 *            registration processing is halted.
1017
+					 */
1018
+					if (apply_filters(
1019
+						'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
1020
+						false,
1021
+						$att_nmbr,
1022
+						$registration,
1023
+						$registrations,
1024
+						$valid_data,
1025
+						$this
1026
+					)) {
1027
+						return false;
1028
+					}
1029
+
1030
+					// Houston, we have a registration!
1031
+					$att_nmbr++;
1032
+					$this->_attendee_data[ $reg_url_link ] = array();
1033
+					// grab any existing related answer objects
1034
+					$this->_registration_answers = $registration->answers();
1035
+					// unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
1036
+					if (isset($valid_data[ $reg_url_link ])) {
1037
+						// do we need to copy basic info from primary attendee ?
1038
+						$copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info'])
1039
+										&& absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
1040
+						// filter form input data for this registration
1041
+						$valid_data[ $reg_url_link ] = (array) apply_filters(
1042
+							'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
1043
+							$valid_data[ $reg_url_link ]
1044
+						);
1045
+						if (isset($valid_data['primary_attendee'])) {
1046
+							$primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
1047
+								? $valid_data['primary_attendee']
1048
+								: false;
1049
+							unset($valid_data['primary_attendee']);
1050
+						}
1051
+						// now loop through our array of valid post data && process attendee reg forms
1052
+						foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) {
1053
+							if (! in_array($form_section, $non_input_form_sections, true)) {
1054
+								foreach ($form_inputs as $form_input => $input_value) {
1055
+									// \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
1056
+									// check for critical inputs
1057
+									if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
1058
+										$form_input,
1059
+										$input_value
1060
+									)
1061
+									) {
1062
+										return false;
1063
+									}
1064
+									// store a bit of data about the primary attendee
1065
+									if ($att_nmbr === 1
1066
+										&& ! empty($input_value)
1067
+										&& $reg_url_link === $primary_registrant['line_item_id']
1068
+									) {
1069
+										$primary_registrant[ $form_input ] = $input_value;
1070
+									} elseif ($copy_primary
1071
+											  && $input_value === null
1072
+											  && isset($primary_registrant[ $form_input ])
1073
+									) {
1074
+										$input_value = $primary_registrant[ $form_input ];
1075
+									}
1076
+									// now attempt to save the input data
1077
+									if (! $this->_save_registration_form_input(
1078
+										$registration,
1079
+										$form_input,
1080
+										$input_value
1081
+									)
1082
+									) {
1083
+										EE_Error::add_error(
1084
+											sprintf(
1085
+												esc_html_x(
1086
+													'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
1087
+													'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"',
1088
+													'event_espresso'
1089
+												),
1090
+												$form_input,
1091
+												$input_value
1092
+											),
1093
+											__FILE__,
1094
+											__FUNCTION__,
1095
+											__LINE__
1096
+										);
1097
+										return false;
1098
+									}
1099
+								}
1100
+							}
1101
+						}  // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs )
1102
+					}
1103
+					// EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ );
1104
+					// this registration does not require additional attendee information ?
1105
+					if ($copy_primary
1106
+						&& $att_nmbr > 1
1107
+						&& $this->checkout->primary_attendee_obj instanceof EE_Attendee
1108
+					) {
1109
+						// just copy the primary registrant
1110
+						$attendee = $this->checkout->primary_attendee_obj;
1111
+					} else {
1112
+						// ensure critical details are set for additional attendees
1113
+						$this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1
1114
+							? $this->_copy_critical_attendee_details_from_primary_registrant(
1115
+								$this->_attendee_data[ $reg_url_link ]
1116
+							)
1117
+							: $this->_attendee_data[ $reg_url_link ];
1118
+						// execute create attendee command (which may return an existing attendee)
1119
+						$attendee = EE_Registry::instance()->BUS->execute(
1120
+							new CreateAttendeeCommand(
1121
+								$this->_attendee_data[ $reg_url_link ],
1122
+								$registration
1123
+							)
1124
+						);
1125
+						// who's #1 ?
1126
+						if ($att_nmbr === 1) {
1127
+							$this->checkout->primary_attendee_obj = $attendee;
1128
+						}
1129
+					}
1130
+					// EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
1131
+					// add relation to registration, set attendee ID, and cache attendee
1132
+					$this->_associate_attendee_with_registration($registration, $attendee);
1133
+					// \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1134
+					if (! $registration->attendee() instanceof EE_Attendee) {
1135
+						EE_Error::add_error(
1136
+							sprintf(
1137
+								esc_html_x(
1138
+									'Registration %s has an invalid or missing Attendee object.',
1139
+									'Registration 123-456-789 has an invalid or missing Attendee object.',
1140
+									'event_espresso'
1141
+								),
1142
+								$reg_url_link
1143
+							),
1144
+							__FILE__,
1145
+							__FUNCTION__,
1146
+							__LINE__
1147
+						);
1148
+						return false;
1149
+					}
1150
+					/** @type EE_Registration_Processor $registration_processor */
1151
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1152
+					// at this point, we should have enough details about the registrant to consider the registration
1153
+					// NOT incomplete
1154
+					$registration_processor->toggle_incomplete_registration_status_to_default(
1155
+						$registration,
1156
+						false,
1157
+						new Context(
1158
+							'spco_reg_step_attendee_information_process_registrations',
1159
+							esc_html__(
1160
+								'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
1161
+								'event_espresso'
1162
+							)
1163
+						)
1164
+					);
1165
+					// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
1166
+					// abandoned
1167
+					$this->checkout->transaction->toggle_failed_transaction_status();
1168
+					// if we've gotten this far, then let's save what we have
1169
+					$registration->save();
1170
+					// add relation between TXN and registration
1171
+					$this->_associate_registration_with_transaction($registration);
1172
+				}
1173
+			} else {
1174
+				EE_Error::add_error(
1175
+					esc_html__(
1176
+						'An invalid or missing line item ID was encountered while attempting to process the registration form.',
1177
+						'event_espresso'
1178
+					),
1179
+					__FILE__,
1180
+					__FUNCTION__,
1181
+					__LINE__
1182
+				);
1183
+				// remove malformed data
1184
+				unset($valid_data[ $reg_url_link ]);
1185
+				return false;
1186
+			}
1187
+		} // end of foreach ( $this->checkout->transaction->registrations()  as $registration )
1188
+		return $att_nmbr;
1189
+	}
1190
+
1191
+
1192
+	/**
1193
+	 *    _save_registration_form_input
1194
+	 *
1195
+	 * @param EE_Registration $registration
1196
+	 * @param string          $form_input
1197
+	 * @param string          $input_value
1198
+	 * @return bool
1199
+	 * @throws EE_Error
1200
+	 * @throws InvalidArgumentException
1201
+	 * @throws InvalidDataTypeException
1202
+	 * @throws InvalidInterfaceException
1203
+	 * @throws ReflectionException
1204
+	 */
1205
+	private function _save_registration_form_input(
1206
+		EE_Registration $registration,
1207
+		$form_input = '',
1208
+		$input_value = ''
1209
+	) {
1210
+		// \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
1211
+		// \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ );
1212
+		// \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1213
+		// allow for plugins to hook in and do their own processing of the form input.
1214
+		// For plugins to bypass normal processing here, they just need to return a boolean value.
1215
+		if (apply_filters(
1216
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1217
+			false,
1218
+			$registration,
1219
+			$form_input,
1220
+			$input_value,
1221
+			$this
1222
+		)) {
1223
+			return true;
1224
+		}
1225
+		/*
1226 1226
          * $answer_cache_id is the key used to find the EE_Answer we want
1227 1227
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
1228 1228
          */
1229
-        $answer_cache_id = $this->checkout->reg_url_link
1230
-            ? $form_input . '-' . $registration->reg_url_link()
1231
-            : $form_input;
1232
-        $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ])
1233
-                         && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer;
1234
-        // rename form_inputs if they are EE_Attendee properties
1235
-        switch ((string) $form_input) {
1236
-            case 'state':
1237
-            case 'STA_ID':
1238
-                $attendee_property = true;
1239
-                $form_input = 'STA_ID';
1240
-                break;
1241
-
1242
-            case 'country':
1243
-            case 'CNT_ISO':
1244
-                $attendee_property = true;
1245
-                $form_input = 'CNT_ISO';
1246
-                break;
1247
-
1248
-            default:
1249
-                $ATT_input = 'ATT_' . $form_input;
1250
-                // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1251
-                $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1252
-                $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input;
1253
-        }
1254
-        // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1255
-        // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1256
-        // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1257
-        // if this form input has a corresponding attendee property
1258
-        if ($attendee_property) {
1259
-            $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value;
1260
-            if ($answer_is_obj) {
1261
-                // and delete the corresponding answer since we won't be storing this data in that object
1262
-                $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer');
1263
-                $this->_registration_answers[ $answer_cache_id ]->delete_permanently();
1264
-            }
1265
-            return true;
1266
-        }
1267
-        if ($answer_is_obj) {
1268
-            // save this data to the answer object
1269
-            $this->_registration_answers[ $answer_cache_id ]->set_value($input_value);
1270
-            $result = $this->_registration_answers[ $answer_cache_id ]->save();
1271
-            return $result !== false;
1272
-        }
1273
-        foreach ($this->_registration_answers as $answer) {
1274
-            if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1275
-                $answer->set_value($input_value);
1276
-                $result = $answer->save();
1277
-                return $result !== false;
1278
-            }
1279
-        }
1280
-        return false;
1281
-    }
1282
-
1283
-
1284
-    /**
1285
-     *    _verify_critical_attendee_details_are_set
1286
-     *
1287
-     * @param string $form_input
1288
-     * @param string $input_value
1289
-     * @return boolean
1290
-     */
1291
-    private function _verify_critical_attendee_details_are_set_and_validate_email(
1292
-        $form_input = '',
1293
-        $input_value = ''
1294
-    ) {
1295
-        if (empty($input_value)) {
1296
-            // if the form input isn't marked as being required, then just return
1297
-            if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) {
1298
-                return true;
1299
-            }
1300
-            switch ($form_input) {
1301
-                case 'fname':
1302
-                    EE_Error::add_error(
1303
-                        esc_html__('First Name is a required value.', 'event_espresso'),
1304
-                        __FILE__,
1305
-                        __FUNCTION__,
1306
-                        __LINE__
1307
-                    );
1308
-                    return false;
1309
-                    break;
1310
-                case 'lname':
1311
-                    EE_Error::add_error(
1312
-                        esc_html__('Last Name is a required value.', 'event_espresso'),
1313
-                        __FILE__,
1314
-                        __FUNCTION__,
1315
-                        __LINE__
1316
-                    );
1317
-                    return false;
1318
-                    break;
1319
-                case 'email':
1320
-                    EE_Error::add_error(
1321
-                        esc_html__('Please enter a valid email address.', 'event_espresso'),
1322
-                        __FILE__,
1323
-                        __FUNCTION__,
1324
-                        __LINE__
1325
-                    );
1326
-                    return false;
1327
-                    break;
1328
-            }
1329
-        }
1330
-        return true;
1331
-    }
1332
-
1333
-
1334
-    /**
1335
-     *    _associate_attendee_with_registration
1336
-     *
1337
-     * @param EE_Registration $registration
1338
-     * @param EE_Attendee     $attendee
1339
-     * @return void
1340
-     * @throws EE_Error
1341
-     * @throws InvalidArgumentException
1342
-     * @throws ReflectionException
1343
-     * @throws RuntimeException
1344
-     * @throws InvalidDataTypeException
1345
-     * @throws InvalidInterfaceException
1346
-     */
1347
-    private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee)
1348
-    {
1349
-        // add relation to attendee
1350
-        $registration->_add_relation_to($attendee, 'Attendee');
1351
-        $registration->set_attendee_id($attendee->ID());
1352
-        $registration->update_cache_after_object_save('Attendee', $attendee);
1353
-    }
1354
-
1355
-
1356
-    /**
1357
-     *    _associate_registration_with_transaction
1358
-     *
1359
-     * @param EE_Registration $registration
1360
-     * @return void
1361
-     * @throws EE_Error
1362
-     * @throws InvalidArgumentException
1363
-     * @throws ReflectionException
1364
-     * @throws InvalidDataTypeException
1365
-     * @throws InvalidInterfaceException
1366
-     */
1367
-    private function _associate_registration_with_transaction(EE_Registration $registration)
1368
-    {
1369
-        // add relation to registration
1370
-        $this->checkout->transaction->_add_relation_to($registration, 'Registration');
1371
-        $this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1372
-    }
1373
-
1374
-
1375
-    /**
1376
-     *    _copy_critical_attendee_details_from_primary_registrant
1377
-     *    ensures that all attendees at least have data for first name, last name, and email address
1378
-     *
1379
-     * @param array $attendee_data
1380
-     * @return array
1381
-     * @throws EE_Error
1382
-     * @throws InvalidArgumentException
1383
-     * @throws ReflectionException
1384
-     * @throws InvalidDataTypeException
1385
-     * @throws InvalidInterfaceException
1386
-     */
1387
-    private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array())
1388
-    {
1389
-        // bare minimum critical details include first name, last name, email address
1390
-        $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1391
-        // add address info to critical details?
1392
-        if (apply_filters(
1393
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1394
-            false
1395
-        )) {
1396
-            $address_details = array(
1397
-                'ATT_address',
1398
-                'ATT_address2',
1399
-                'ATT_city',
1400
-                'STA_ID',
1401
-                'CNT_ISO',
1402
-                'ATT_zip',
1403
-                'ATT_phone',
1404
-            );
1405
-            $critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1406
-        }
1407
-        foreach ($critical_attendee_details as $critical_attendee_detail) {
1408
-            if (! isset($attendee_data[ $critical_attendee_detail ])
1409
-                || empty($attendee_data[ $critical_attendee_detail ])
1410
-            ) {
1411
-                $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get(
1412
-                    $critical_attendee_detail
1413
-                );
1414
-            }
1415
-        }
1416
-        return $attendee_data;
1417
-    }
1418
-
1419
-
1420
-    /**
1421
-     *    update_reg_step
1422
-     *    this is the final step after a user  revisits the site to edit their attendee information
1423
-     *    this gets called AFTER the process_reg_step() method above
1424
-     *
1425
-     * @return bool
1426
-     * @throws EE_Error
1427
-     * @throws InvalidArgumentException
1428
-     * @throws ReflectionException
1429
-     * @throws RuntimeException
1430
-     * @throws InvalidDataTypeException
1431
-     * @throws InvalidInterfaceException
1432
-     */
1433
-    public function update_reg_step()
1434
-    {
1435
-        // save everything
1436
-        if ($this->process_reg_step()) {
1437
-            $this->checkout->redirect = true;
1438
-            $this->checkout->redirect_url = add_query_arg(
1439
-                array(
1440
-                    'e_reg_url_link' => $this->checkout->reg_url_link,
1441
-                    'revisit'        => true,
1442
-                ),
1443
-                $this->checkout->thank_you_page_url
1444
-            );
1445
-            $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1446
-            return true;
1447
-        }
1448
-        return false;
1449
-    }
1229
+		$answer_cache_id = $this->checkout->reg_url_link
1230
+			? $form_input . '-' . $registration->reg_url_link()
1231
+			: $form_input;
1232
+		$answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ])
1233
+						 && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer;
1234
+		// rename form_inputs if they are EE_Attendee properties
1235
+		switch ((string) $form_input) {
1236
+			case 'state':
1237
+			case 'STA_ID':
1238
+				$attendee_property = true;
1239
+				$form_input = 'STA_ID';
1240
+				break;
1241
+
1242
+			case 'country':
1243
+			case 'CNT_ISO':
1244
+				$attendee_property = true;
1245
+				$form_input = 'CNT_ISO';
1246
+				break;
1247
+
1248
+			default:
1249
+				$ATT_input = 'ATT_' . $form_input;
1250
+				// EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1251
+				$attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1252
+				$form_input = $attendee_property ? 'ATT_' . $form_input : $form_input;
1253
+		}
1254
+		// EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1255
+		// EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1256
+		// EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1257
+		// if this form input has a corresponding attendee property
1258
+		if ($attendee_property) {
1259
+			$this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value;
1260
+			if ($answer_is_obj) {
1261
+				// and delete the corresponding answer since we won't be storing this data in that object
1262
+				$registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer');
1263
+				$this->_registration_answers[ $answer_cache_id ]->delete_permanently();
1264
+			}
1265
+			return true;
1266
+		}
1267
+		if ($answer_is_obj) {
1268
+			// save this data to the answer object
1269
+			$this->_registration_answers[ $answer_cache_id ]->set_value($input_value);
1270
+			$result = $this->_registration_answers[ $answer_cache_id ]->save();
1271
+			return $result !== false;
1272
+		}
1273
+		foreach ($this->_registration_answers as $answer) {
1274
+			if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1275
+				$answer->set_value($input_value);
1276
+				$result = $answer->save();
1277
+				return $result !== false;
1278
+			}
1279
+		}
1280
+		return false;
1281
+	}
1282
+
1283
+
1284
+	/**
1285
+	 *    _verify_critical_attendee_details_are_set
1286
+	 *
1287
+	 * @param string $form_input
1288
+	 * @param string $input_value
1289
+	 * @return boolean
1290
+	 */
1291
+	private function _verify_critical_attendee_details_are_set_and_validate_email(
1292
+		$form_input = '',
1293
+		$input_value = ''
1294
+	) {
1295
+		if (empty($input_value)) {
1296
+			// if the form input isn't marked as being required, then just return
1297
+			if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) {
1298
+				return true;
1299
+			}
1300
+			switch ($form_input) {
1301
+				case 'fname':
1302
+					EE_Error::add_error(
1303
+						esc_html__('First Name is a required value.', 'event_espresso'),
1304
+						__FILE__,
1305
+						__FUNCTION__,
1306
+						__LINE__
1307
+					);
1308
+					return false;
1309
+					break;
1310
+				case 'lname':
1311
+					EE_Error::add_error(
1312
+						esc_html__('Last Name is a required value.', 'event_espresso'),
1313
+						__FILE__,
1314
+						__FUNCTION__,
1315
+						__LINE__
1316
+					);
1317
+					return false;
1318
+					break;
1319
+				case 'email':
1320
+					EE_Error::add_error(
1321
+						esc_html__('Please enter a valid email address.', 'event_espresso'),
1322
+						__FILE__,
1323
+						__FUNCTION__,
1324
+						__LINE__
1325
+					);
1326
+					return false;
1327
+					break;
1328
+			}
1329
+		}
1330
+		return true;
1331
+	}
1332
+
1333
+
1334
+	/**
1335
+	 *    _associate_attendee_with_registration
1336
+	 *
1337
+	 * @param EE_Registration $registration
1338
+	 * @param EE_Attendee     $attendee
1339
+	 * @return void
1340
+	 * @throws EE_Error
1341
+	 * @throws InvalidArgumentException
1342
+	 * @throws ReflectionException
1343
+	 * @throws RuntimeException
1344
+	 * @throws InvalidDataTypeException
1345
+	 * @throws InvalidInterfaceException
1346
+	 */
1347
+	private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee)
1348
+	{
1349
+		// add relation to attendee
1350
+		$registration->_add_relation_to($attendee, 'Attendee');
1351
+		$registration->set_attendee_id($attendee->ID());
1352
+		$registration->update_cache_after_object_save('Attendee', $attendee);
1353
+	}
1354
+
1355
+
1356
+	/**
1357
+	 *    _associate_registration_with_transaction
1358
+	 *
1359
+	 * @param EE_Registration $registration
1360
+	 * @return void
1361
+	 * @throws EE_Error
1362
+	 * @throws InvalidArgumentException
1363
+	 * @throws ReflectionException
1364
+	 * @throws InvalidDataTypeException
1365
+	 * @throws InvalidInterfaceException
1366
+	 */
1367
+	private function _associate_registration_with_transaction(EE_Registration $registration)
1368
+	{
1369
+		// add relation to registration
1370
+		$this->checkout->transaction->_add_relation_to($registration, 'Registration');
1371
+		$this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1372
+	}
1373
+
1374
+
1375
+	/**
1376
+	 *    _copy_critical_attendee_details_from_primary_registrant
1377
+	 *    ensures that all attendees at least have data for first name, last name, and email address
1378
+	 *
1379
+	 * @param array $attendee_data
1380
+	 * @return array
1381
+	 * @throws EE_Error
1382
+	 * @throws InvalidArgumentException
1383
+	 * @throws ReflectionException
1384
+	 * @throws InvalidDataTypeException
1385
+	 * @throws InvalidInterfaceException
1386
+	 */
1387
+	private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array())
1388
+	{
1389
+		// bare minimum critical details include first name, last name, email address
1390
+		$critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1391
+		// add address info to critical details?
1392
+		if (apply_filters(
1393
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1394
+			false
1395
+		)) {
1396
+			$address_details = array(
1397
+				'ATT_address',
1398
+				'ATT_address2',
1399
+				'ATT_city',
1400
+				'STA_ID',
1401
+				'CNT_ISO',
1402
+				'ATT_zip',
1403
+				'ATT_phone',
1404
+			);
1405
+			$critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1406
+		}
1407
+		foreach ($critical_attendee_details as $critical_attendee_detail) {
1408
+			if (! isset($attendee_data[ $critical_attendee_detail ])
1409
+				|| empty($attendee_data[ $critical_attendee_detail ])
1410
+			) {
1411
+				$attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get(
1412
+					$critical_attendee_detail
1413
+				);
1414
+			}
1415
+		}
1416
+		return $attendee_data;
1417
+	}
1418
+
1419
+
1420
+	/**
1421
+	 *    update_reg_step
1422
+	 *    this is the final step after a user  revisits the site to edit their attendee information
1423
+	 *    this gets called AFTER the process_reg_step() method above
1424
+	 *
1425
+	 * @return bool
1426
+	 * @throws EE_Error
1427
+	 * @throws InvalidArgumentException
1428
+	 * @throws ReflectionException
1429
+	 * @throws RuntimeException
1430
+	 * @throws InvalidDataTypeException
1431
+	 * @throws InvalidInterfaceException
1432
+	 */
1433
+	public function update_reg_step()
1434
+	{
1435
+		// save everything
1436
+		if ($this->process_reg_step()) {
1437
+			$this->checkout->redirect = true;
1438
+			$this->checkout->redirect_url = add_query_arg(
1439
+				array(
1440
+					'e_reg_url_link' => $this->checkout->reg_url_link,
1441
+					'revisit'        => true,
1442
+				),
1443
+				$this->checkout->thank_you_page_url
1444
+			);
1445
+			$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1446
+			return true;
1447
+		}
1448
+		return false;
1449
+	}
1450 1450
 }
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 patch
Indentation   +2136 added lines, -2136 removed lines patch added patch discarded remove patch
@@ -15,2196 +15,2196 @@
 block discarded – undo
15 15
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * This property is just used to hold the status of whether an event is currently being
20
-     * created (true) or edited (false)
21
-     *
22
-     * @access protected
23
-     * @var bool
24
-     */
25
-    protected $_is_creating_event;
18
+	/**
19
+	 * This property is just used to hold the status of whether an event is currently being
20
+	 * created (true) or edited (false)
21
+	 *
22
+	 * @access protected
23
+	 * @var bool
24
+	 */
25
+	protected $_is_creating_event;
26 26
 
27
-    /**
28
-     * Used to contain the format strings for date and time that will be used for php date and
29
-     * time.
30
-     * Is set in the _set_hooks_properties() method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_date_format_strings;
27
+	/**
28
+	 * Used to contain the format strings for date and time that will be used for php date and
29
+	 * time.
30
+	 * Is set in the _set_hooks_properties() method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_date_format_strings;
35 35
 
36
-    /**
37
-     * @var string $_date_time_format
38
-     */
39
-    protected $_date_time_format;
36
+	/**
37
+	 * @var string $_date_time_format
38
+	 */
39
+	protected $_date_time_format;
40 40
 
41 41
 
42
-    /**
43
-     * @throws InvalidArgumentException
44
-     * @throws InvalidInterfaceException
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    protected function _set_hooks_properties()
48
-    {
49
-        $this->_name = 'pricing';
50
-        // capability check
51
-        if (EE_Registry::instance()->CFG->admin->useAdvancedEditor() ||
52
-            ! EE_Registry::instance()->CAP->current_user_can(
53
-                'ee_read_default_prices',
54
-                'advanced_ticket_datetime_metabox'
55
-            )
56
-        ) {
57
-            return;
58
-        }
59
-        $this->_setup_metaboxes();
60
-        $this->_set_date_time_formats();
61
-        $this->_validate_format_strings();
62
-        $this->_set_scripts_styles();
63
-        // commented out temporarily until logic is implemented in callback
64
-        // add_action(
65
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
66
-        //     array($this, 'autosave_handling')
67
-        // );
68
-        add_filter(
69
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
70
-            array($this, 'caf_updates')
71
-        );
72
-    }
42
+	/**
43
+	 * @throws InvalidArgumentException
44
+	 * @throws InvalidInterfaceException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	protected function _set_hooks_properties()
48
+	{
49
+		$this->_name = 'pricing';
50
+		// capability check
51
+		if (EE_Registry::instance()->CFG->admin->useAdvancedEditor() ||
52
+			! EE_Registry::instance()->CAP->current_user_can(
53
+				'ee_read_default_prices',
54
+				'advanced_ticket_datetime_metabox'
55
+			)
56
+		) {
57
+			return;
58
+		}
59
+		$this->_setup_metaboxes();
60
+		$this->_set_date_time_formats();
61
+		$this->_validate_format_strings();
62
+		$this->_set_scripts_styles();
63
+		// commented out temporarily until logic is implemented in callback
64
+		// add_action(
65
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
66
+		//     array($this, 'autosave_handling')
67
+		// );
68
+		add_filter(
69
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
70
+			array($this, 'caf_updates')
71
+		);
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * @return void
77
-     */
78
-    protected function _setup_metaboxes()
79
-    {
80
-        // if we were going to add our own metaboxes we'd use the below.
81
-        $this->_metaboxes = array(
82
-            0 => array(
83
-                'page_route' => array('edit', 'create_new'),
84
-                'func'       => 'pricing_metabox',
85
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
86
-                'priority'   => 'high',
87
-                'context'    => 'normal',
88
-            ),
89
-        );
90
-        $this->_remove_metaboxes = array(
91
-            0 => array(
92
-                'page_route' => array('edit', 'create_new'),
93
-                'id'         => 'espresso_event_editor_tickets',
94
-                'context'    => 'normal',
95
-            ),
96
-        );
97
-    }
75
+	/**
76
+	 * @return void
77
+	 */
78
+	protected function _setup_metaboxes()
79
+	{
80
+		// if we were going to add our own metaboxes we'd use the below.
81
+		$this->_metaboxes = array(
82
+			0 => array(
83
+				'page_route' => array('edit', 'create_new'),
84
+				'func'       => 'pricing_metabox',
85
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
86
+				'priority'   => 'high',
87
+				'context'    => 'normal',
88
+			),
89
+		);
90
+		$this->_remove_metaboxes = array(
91
+			0 => array(
92
+				'page_route' => array('edit', 'create_new'),
93
+				'id'         => 'espresso_event_editor_tickets',
94
+				'context'    => 'normal',
95
+			),
96
+		);
97
+	}
98 98
 
99 99
 
100
-    /**
101
-     * @return void
102
-     */
103
-    protected function _set_date_time_formats()
104
-    {
105
-        /**
106
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
107
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
108
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
109
-         *
110
-         * @since 4.6.7
111
-         * @var array  Expected an array returned with 'date' and 'time' keys.
112
-         */
113
-        $this->_date_format_strings = apply_filters(
114
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
115
-            array(
116
-                'date' => 'Y-m-d',
117
-                'time' => 'h:i a',
118
-            )
119
-        );
120
-        // validate
121
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
122
-            ? $this->_date_format_strings['date']
123
-            : null;
124
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
125
-            ? $this->_date_format_strings['time']
126
-            : null;
127
-        $this->_date_time_format = $this->_date_format_strings['date']
128
-                                   . ' '
129
-                                   . $this->_date_format_strings['time'];
130
-    }
100
+	/**
101
+	 * @return void
102
+	 */
103
+	protected function _set_date_time_formats()
104
+	{
105
+		/**
106
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
107
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
108
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
109
+		 *
110
+		 * @since 4.6.7
111
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
112
+		 */
113
+		$this->_date_format_strings = apply_filters(
114
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
115
+			array(
116
+				'date' => 'Y-m-d',
117
+				'time' => 'h:i a',
118
+			)
119
+		);
120
+		// validate
121
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
122
+			? $this->_date_format_strings['date']
123
+			: null;
124
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
125
+			? $this->_date_format_strings['time']
126
+			: null;
127
+		$this->_date_time_format = $this->_date_format_strings['date']
128
+								   . ' '
129
+								   . $this->_date_format_strings['time'];
130
+	}
131 131
 
132 132
 
133
-    /**
134
-     * @return void
135
-     */
136
-    protected function _validate_format_strings()
137
-    {
138
-        // validate format strings
139
-        $format_validation = EEH_DTT_Helper::validate_format_string(
140
-            $this->_date_time_format
141
-        );
142
-        if (is_array($format_validation)) {
143
-            $msg = '<p>';
144
-            $msg .= sprintf(
145
-                esc_html__(
146
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
147
-                    'event_espresso'
148
-                ),
149
-                $this->_date_time_format
150
-            );
151
-            $msg .= '</p><ul>';
152
-            foreach ($format_validation as $error) {
153
-                $msg .= '<li>' . $error . '</li>';
154
-            }
155
-            $msg .= '</ul><p>';
156
-            $msg .= sprintf(
157
-                esc_html__(
158
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
159
-                    'event_espresso'
160
-                ),
161
-                '<span style="color:#D54E21;">',
162
-                '</span>'
163
-            );
164
-            $msg .= '</p>';
165
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
166
-            $this->_date_format_strings = array(
167
-                'date' => 'Y-m-d',
168
-                'time' => 'h:i a',
169
-            );
170
-        }
171
-    }
133
+	/**
134
+	 * @return void
135
+	 */
136
+	protected function _validate_format_strings()
137
+	{
138
+		// validate format strings
139
+		$format_validation = EEH_DTT_Helper::validate_format_string(
140
+			$this->_date_time_format
141
+		);
142
+		if (is_array($format_validation)) {
143
+			$msg = '<p>';
144
+			$msg .= sprintf(
145
+				esc_html__(
146
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
147
+					'event_espresso'
148
+				),
149
+				$this->_date_time_format
150
+			);
151
+			$msg .= '</p><ul>';
152
+			foreach ($format_validation as $error) {
153
+				$msg .= '<li>' . $error . '</li>';
154
+			}
155
+			$msg .= '</ul><p>';
156
+			$msg .= sprintf(
157
+				esc_html__(
158
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
159
+					'event_espresso'
160
+				),
161
+				'<span style="color:#D54E21;">',
162
+				'</span>'
163
+			);
164
+			$msg .= '</p>';
165
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
166
+			$this->_date_format_strings = array(
167
+				'date' => 'Y-m-d',
168
+				'time' => 'h:i a',
169
+			);
170
+		}
171
+	}
172 172
 
173 173
 
174
-    /**
175
-     * @return void
176
-     */
177
-    protected function _set_scripts_styles()
178
-    {
179
-        $this->_scripts_styles = array(
180
-            'registers'   => array(
181
-                'ee-tickets-datetimes-css' => array(
182
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
183
-                    'type' => 'css',
184
-                ),
185
-                'ee-dtt-ticket-metabox'    => array(
186
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
187
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
188
-                ),
189
-            ),
190
-            'deregisters' => array(
191
-                'event-editor-css'       => array('type' => 'css'),
192
-                'event-datetime-metabox' => array('type' => 'js'),
193
-            ),
194
-            'enqueues'    => array(
195
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
196
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
197
-            ),
198
-            'localize'    => array(
199
-                'ee-dtt-ticket-metabox' => array(
200
-                    'DTT_TRASH_BLOCK'       => array(
201
-                        'main_warning'            => esc_html__(
202
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
203
-                            'event_espresso'
204
-                        ),
205
-                        'after_warning'           => esc_html__(
206
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
207
-                            'event_espresso'
208
-                        ),
209
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
210
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
211
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
212
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
213
-                        'single_warning_from_tkt' => esc_html__(
214
-                            'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
215
-                            'event_espresso'
216
-                        ),
217
-                        'single_warning_from_dtt' => esc_html__(
218
-                            'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
219
-                            'event_espresso'
220
-                        ),
221
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
222
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
223
-                    ),
224
-                    'DTT_ERROR_MSG'         => array(
225
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
226
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
227
-                                            . '<button class="button-secondary ee-modal-cancel">'
228
-                                            . esc_html__('Dismiss', 'event_espresso')
229
-                                            . '</button></div>',
230
-                    ),
231
-                    'DTT_OVERSELL_WARNING'  => array(
232
-                        'datetime_ticket' => esc_html__(
233
-                            'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
234
-                            'event_espresso'
235
-                        ),
236
-                        'ticket_datetime' => esc_html__(
237
-                            'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
238
-                            'event_espresso'
239
-                        ),
240
-                    ),
241
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
242
-                        $this->_date_format_strings['date'],
243
-                        $this->_date_format_strings['time']
244
-                    ),
245
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
246
-                ),
247
-            ),
248
-        );
249
-    }
174
+	/**
175
+	 * @return void
176
+	 */
177
+	protected function _set_scripts_styles()
178
+	{
179
+		$this->_scripts_styles = array(
180
+			'registers'   => array(
181
+				'ee-tickets-datetimes-css' => array(
182
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
183
+					'type' => 'css',
184
+				),
185
+				'ee-dtt-ticket-metabox'    => array(
186
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
187
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
188
+				),
189
+			),
190
+			'deregisters' => array(
191
+				'event-editor-css'       => array('type' => 'css'),
192
+				'event-datetime-metabox' => array('type' => 'js'),
193
+			),
194
+			'enqueues'    => array(
195
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
196
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
197
+			),
198
+			'localize'    => array(
199
+				'ee-dtt-ticket-metabox' => array(
200
+					'DTT_TRASH_BLOCK'       => array(
201
+						'main_warning'            => esc_html__(
202
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
203
+							'event_espresso'
204
+						),
205
+						'after_warning'           => esc_html__(
206
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
207
+							'event_espresso'
208
+						),
209
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
210
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
211
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
212
+													 . esc_html__('Close', 'event_espresso') . '</button>',
213
+						'single_warning_from_tkt' => esc_html__(
214
+							'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
215
+							'event_espresso'
216
+						),
217
+						'single_warning_from_dtt' => esc_html__(
218
+							'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
219
+							'event_espresso'
220
+						),
221
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
222
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
223
+					),
224
+					'DTT_ERROR_MSG'         => array(
225
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
226
+						'dismiss_button' => '<div class="save-cancel-button-container">'
227
+											. '<button class="button-secondary ee-modal-cancel">'
228
+											. esc_html__('Dismiss', 'event_espresso')
229
+											. '</button></div>',
230
+					),
231
+					'DTT_OVERSELL_WARNING'  => array(
232
+						'datetime_ticket' => esc_html__(
233
+							'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
234
+							'event_espresso'
235
+						),
236
+						'ticket_datetime' => esc_html__(
237
+							'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
238
+							'event_espresso'
239
+						),
240
+					),
241
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
242
+						$this->_date_format_strings['date'],
243
+						$this->_date_format_strings['time']
244
+					),
245
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
246
+				),
247
+			),
248
+		);
249
+	}
250 250
 
251 251
 
252
-    /**
253
-     * @param array $update_callbacks
254
-     * @return array
255
-     */
256
-    public function caf_updates(array $update_callbacks)
257
-    {
258
-        foreach ($update_callbacks as $key => $callback) {
259
-            if ($callback[1] === '_default_tickets_update') {
260
-                unset($update_callbacks[ $key ]);
261
-            }
262
-        }
263
-        $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
264
-        return $update_callbacks;
265
-    }
252
+	/**
253
+	 * @param array $update_callbacks
254
+	 * @return array
255
+	 */
256
+	public function caf_updates(array $update_callbacks)
257
+	{
258
+		foreach ($update_callbacks as $key => $callback) {
259
+			if ($callback[1] === '_default_tickets_update') {
260
+				unset($update_callbacks[ $key ]);
261
+			}
262
+		}
263
+		$update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
264
+		return $update_callbacks;
265
+	}
266 266
 
267 267
 
268
-    /**
269
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
270
-     *
271
-     * @param  EE_Event $event The Event object we're attaching data to
272
-     * @param  array    $data  The request data from the form
273
-     * @throws ReflectionException
274
-     * @throws Exception
275
-     * @throws InvalidInterfaceException
276
-     * @throws InvalidDataTypeException
277
-     * @throws EE_Error
278
-     * @throws InvalidArgumentException
279
-     */
280
-    public function datetime_and_tickets_caf_update($event, $data)
281
-    {
282
-        // first we need to start with datetimes cause they are the "root" items attached to events.
283
-        $saved_datetimes = $this->_update_datetimes($event, $data);
284
-        // next tackle the tickets (and prices?)
285
-        $this->_update_tickets($event, $saved_datetimes, $data);
286
-    }
268
+	/**
269
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
270
+	 *
271
+	 * @param  EE_Event $event The Event object we're attaching data to
272
+	 * @param  array    $data  The request data from the form
273
+	 * @throws ReflectionException
274
+	 * @throws Exception
275
+	 * @throws InvalidInterfaceException
276
+	 * @throws InvalidDataTypeException
277
+	 * @throws EE_Error
278
+	 * @throws InvalidArgumentException
279
+	 */
280
+	public function datetime_and_tickets_caf_update($event, $data)
281
+	{
282
+		// first we need to start with datetimes cause they are the "root" items attached to events.
283
+		$saved_datetimes = $this->_update_datetimes($event, $data);
284
+		// next tackle the tickets (and prices?)
285
+		$this->_update_tickets($event, $saved_datetimes, $data);
286
+	}
287 287
 
288 288
 
289
-    /**
290
-     * update event_datetimes
291
-     *
292
-     * @param  EE_Event $event Event being updated
293
-     * @param  array    $data  the request data from the form
294
-     * @return EE_Datetime[]
295
-     * @throws Exception
296
-     * @throws ReflectionException
297
-     * @throws InvalidInterfaceException
298
-     * @throws InvalidDataTypeException
299
-     * @throws InvalidArgumentException
300
-     * @throws EE_Error
301
-     */
302
-    protected function _update_datetimes($event, $data)
303
-    {
304
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
305
-        $saved_dtt_ids = array();
306
-        $saved_dtt_objs = array();
307
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
308
-            throw new InvalidArgumentException(
309
-                esc_html__(
310
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
311
-                    'event_espresso'
312
-                )
313
-            );
314
-        }
315
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
316
-            // trim all values to ensure any excess whitespace is removed.
317
-            $datetime_data = array_map(
318
-                function ($datetime_data) {
319
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
320
-                },
321
-                $datetime_data
322
-            );
323
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
324
-                                            && ! empty($datetime_data['DTT_EVT_end'])
325
-                ? $datetime_data['DTT_EVT_end']
326
-                : $datetime_data['DTT_EVT_start'];
327
-            $datetime_values = array(
328
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
329
-                    ? $datetime_data['DTT_ID']
330
-                    : null,
331
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
332
-                    ? $datetime_data['DTT_name']
333
-                    : '',
334
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
335
-                    ? $datetime_data['DTT_description']
336
-                    : '',
337
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
338
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
339
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
340
-                    ? EE_INF
341
-                    : $datetime_data['DTT_reg_limit'],
342
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
343
-                    ? $row
344
-                    : $datetime_data['DTT_order'],
345
-            );
346
-            // if we have an id then let's get existing object first and then set the new values.
347
-            // Otherwise we instantiate a new object for save.
348
-            if (! empty($datetime_data['DTT_ID'])) {
349
-                $datetime = EE_Registry::instance()
350
-                                       ->load_model('Datetime', array($timezone))
351
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
352
-                // set date and time format according to what is set in this class.
353
-                $datetime->set_date_format($this->_date_format_strings['date']);
354
-                $datetime->set_time_format($this->_date_format_strings['time']);
355
-                foreach ($datetime_values as $field => $value) {
356
-                    $datetime->set($field, $value);
357
-                }
358
-                // make sure the $dtt_id here is saved just in case
359
-                // after the add_relation_to() the autosave replaces it.
360
-                // We need to do this so we dont' TRASH the parent DTT.
361
-                // (save the ID for both key and value to avoid duplications)
362
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
363
-            } else {
364
-                $datetime = EE_Registry::instance()->load_class(
365
-                    'Datetime',
366
-                    array(
367
-                        $datetime_values,
368
-                        $timezone,
369
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
370
-                    ),
371
-                    false,
372
-                    false
373
-                );
374
-                foreach ($datetime_values as $field => $value) {
375
-                    $datetime->set($field, $value);
376
-                }
377
-            }
378
-            $datetime->save();
379
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
380
-            // before going any further make sure our dates are setup correctly
381
-            // so that the end date is always equal or greater than the start date.
382
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
383
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
384
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
385
-                $datetime->save();
386
-            }
387
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
388
-            // because it is possible there was a new one created for the autosave.
389
-            // (save the ID for both key and value to avoid duplications)
390
-            $DTT_ID = $datetime->ID();
391
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
392
-            $saved_dtt_objs[ $row ] = $datetime;
393
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
394
-        }
395
-        $event->save();
396
-        // now we need to REMOVE any datetimes that got deleted.
397
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
398
-        // So its safe to permanently delete at this point.
399
-        $old_datetimes = explode(',', $data['datetime_IDs']);
400
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
401
-        if (is_array($old_datetimes)) {
402
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
403
-            foreach ($datetimes_to_delete as $id) {
404
-                $id = absint($id);
405
-                if (empty($id)) {
406
-                    continue;
407
-                }
408
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
409
-                // remove tkt relationships.
410
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
411
-                foreach ($related_tickets as $tkt) {
412
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
413
-                }
414
-                $event->_remove_relation_to($id, 'Datetime');
415
-                $dtt_to_remove->refresh_cache_of_related_objects();
416
-            }
417
-        }
418
-        return $saved_dtt_objs;
419
-    }
289
+	/**
290
+	 * update event_datetimes
291
+	 *
292
+	 * @param  EE_Event $event Event being updated
293
+	 * @param  array    $data  the request data from the form
294
+	 * @return EE_Datetime[]
295
+	 * @throws Exception
296
+	 * @throws ReflectionException
297
+	 * @throws InvalidInterfaceException
298
+	 * @throws InvalidDataTypeException
299
+	 * @throws InvalidArgumentException
300
+	 * @throws EE_Error
301
+	 */
302
+	protected function _update_datetimes($event, $data)
303
+	{
304
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
305
+		$saved_dtt_ids = array();
306
+		$saved_dtt_objs = array();
307
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
308
+			throw new InvalidArgumentException(
309
+				esc_html__(
310
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
311
+					'event_espresso'
312
+				)
313
+			);
314
+		}
315
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
316
+			// trim all values to ensure any excess whitespace is removed.
317
+			$datetime_data = array_map(
318
+				function ($datetime_data) {
319
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
320
+				},
321
+				$datetime_data
322
+			);
323
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
324
+											&& ! empty($datetime_data['DTT_EVT_end'])
325
+				? $datetime_data['DTT_EVT_end']
326
+				: $datetime_data['DTT_EVT_start'];
327
+			$datetime_values = array(
328
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
329
+					? $datetime_data['DTT_ID']
330
+					: null,
331
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
332
+					? $datetime_data['DTT_name']
333
+					: '',
334
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
335
+					? $datetime_data['DTT_description']
336
+					: '',
337
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
338
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
339
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
340
+					? EE_INF
341
+					: $datetime_data['DTT_reg_limit'],
342
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
343
+					? $row
344
+					: $datetime_data['DTT_order'],
345
+			);
346
+			// if we have an id then let's get existing object first and then set the new values.
347
+			// Otherwise we instantiate a new object for save.
348
+			if (! empty($datetime_data['DTT_ID'])) {
349
+				$datetime = EE_Registry::instance()
350
+									   ->load_model('Datetime', array($timezone))
351
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
352
+				// set date and time format according to what is set in this class.
353
+				$datetime->set_date_format($this->_date_format_strings['date']);
354
+				$datetime->set_time_format($this->_date_format_strings['time']);
355
+				foreach ($datetime_values as $field => $value) {
356
+					$datetime->set($field, $value);
357
+				}
358
+				// make sure the $dtt_id here is saved just in case
359
+				// after the add_relation_to() the autosave replaces it.
360
+				// We need to do this so we dont' TRASH the parent DTT.
361
+				// (save the ID for both key and value to avoid duplications)
362
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
363
+			} else {
364
+				$datetime = EE_Registry::instance()->load_class(
365
+					'Datetime',
366
+					array(
367
+						$datetime_values,
368
+						$timezone,
369
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
370
+					),
371
+					false,
372
+					false
373
+				);
374
+				foreach ($datetime_values as $field => $value) {
375
+					$datetime->set($field, $value);
376
+				}
377
+			}
378
+			$datetime->save();
379
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
380
+			// before going any further make sure our dates are setup correctly
381
+			// so that the end date is always equal or greater than the start date.
382
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
383
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
384
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
385
+				$datetime->save();
386
+			}
387
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
388
+			// because it is possible there was a new one created for the autosave.
389
+			// (save the ID for both key and value to avoid duplications)
390
+			$DTT_ID = $datetime->ID();
391
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
392
+			$saved_dtt_objs[ $row ] = $datetime;
393
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
394
+		}
395
+		$event->save();
396
+		// now we need to REMOVE any datetimes that got deleted.
397
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
398
+		// So its safe to permanently delete at this point.
399
+		$old_datetimes = explode(',', $data['datetime_IDs']);
400
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
401
+		if (is_array($old_datetimes)) {
402
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
403
+			foreach ($datetimes_to_delete as $id) {
404
+				$id = absint($id);
405
+				if (empty($id)) {
406
+					continue;
407
+				}
408
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
409
+				// remove tkt relationships.
410
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
411
+				foreach ($related_tickets as $tkt) {
412
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
413
+				}
414
+				$event->_remove_relation_to($id, 'Datetime');
415
+				$dtt_to_remove->refresh_cache_of_related_objects();
416
+			}
417
+		}
418
+		return $saved_dtt_objs;
419
+	}
420 420
 
421 421
 
422
-    /**
423
-     * update tickets
424
-     *
425
-     * @param  EE_Event      $event           Event object being updated
426
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
427
-     * @param  array         $data            incoming request data
428
-     * @return EE_Ticket[]
429
-     * @throws Exception
430
-     * @throws ReflectionException
431
-     * @throws InvalidInterfaceException
432
-     * @throws InvalidDataTypeException
433
-     * @throws InvalidArgumentException
434
-     * @throws EE_Error
435
-     */
436
-    protected function _update_tickets($event, $saved_datetimes, $data)
437
-    {
438
-        $new_tkt = null;
439
-        $new_default = null;
440
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
441
-        $data = stripslashes_deep($data);
442
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
443
-        $saved_tickets = $datetimes_on_existing = array();
444
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
445
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
446
-            throw new InvalidArgumentException(
447
-                esc_html__(
448
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
449
-                    'event_espresso'
450
-                )
451
-            );
452
-        }
453
-        foreach ($data['edit_tickets'] as $row => $tkt) {
454
-            $update_prices = $create_new_TKT = false;
455
-            // figure out what datetimes were added to the ticket
456
-            // and what datetimes were removed from the ticket in the session.
457
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
458
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
459
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
460
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
461
-            // trim inputs to ensure any excess whitespace is removed.
462
-            $tkt = array_map(
463
-                function ($ticket_data) {
464
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
465
-                },
466
-                $tkt
467
-            );
468
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
469
-            // because we're doing calculations prior to using the models.
470
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
471
-            $ticket_price = isset($tkt['TKT_price'])
472
-                ? round((float) $tkt['TKT_price'], 3)
473
-                : 0;
474
-            // note incoming base price needs converted from localized value.
475
-            $base_price = isset($tkt['TKT_base_price'])
476
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
477
-                : 0;
478
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
479
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
480
-                ? $base_price
481
-                : $ticket_price;
482
-            $base_price_id = isset($tkt['TKT_base_price_ID'])
483
-                ? $tkt['TKT_base_price_ID']
484
-                : 0;
485
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
486
-                ? $data['edit_prices'][ $row ]
487
-                : array();
488
-            $now = null;
489
-            if (empty($tkt['TKT_start_date'])) {
490
-                // lets' use now in the set timezone.
491
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
492
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
493
-            }
494
-            if (empty($tkt['TKT_end_date'])) {
495
-                /**
496
-                 * set the TKT_end_date to the first datetime attached to the ticket.
497
-                 */
498
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
499
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
500
-            }
501
-            $TKT_values = array(
502
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
503
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
504
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
505
-                'TKT_description' => ! empty($tkt['TKT_description'])
506
-                                     && $tkt['TKT_description'] !== esc_html__(
507
-                                         'You can modify this description',
508
-                                         'event_espresso'
509
-                                     )
510
-                    ? $tkt['TKT_description']
511
-                    : '',
512
-                'TKT_start_date'  => $tkt['TKT_start_date'],
513
-                'TKT_end_date'    => $tkt['TKT_end_date'],
514
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
515
-                    ? EE_INF
516
-                    : $tkt['TKT_qty'],
517
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
518
-                    ? EE_INF
519
-                    : $tkt['TKT_uses'],
520
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
521
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
522
-                'TKT_row'         => $row,
523
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
524
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
525
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
526
-                'TKT_price'       => $ticket_price,
527
-            );
528
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
529
-            // which means in turn that the prices will become new prices as well.
530
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
531
-                $TKT_values['TKT_ID'] = 0;
532
-                $TKT_values['TKT_is_default'] = 0;
533
-                $update_prices = true;
534
-            }
535
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
536
-            // we actually do our saves ahead of doing any add_relations to
537
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
538
-            // but DID have it's items modified.
539
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
540
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
541
-            if (absint($TKT_values['TKT_ID'])) {
542
-                $ticket = EE_Registry::instance()
543
-                                     ->load_model('Ticket', array($timezone))
544
-                                     ->get_one_by_ID($tkt['TKT_ID']);
545
-                if ($ticket instanceof EE_Ticket) {
546
-                    $ticket = $this->_update_ticket_datetimes(
547
-                        $ticket,
548
-                        $saved_datetimes,
549
-                        $datetimes_added,
550
-                        $datetimes_removed
551
-                    );
552
-                    // are there any registrations using this ticket ?
553
-                    $tickets_sold = $ticket->count_related(
554
-                        'Registration',
555
-                        array(
556
-                            array(
557
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
558
-                            ),
559
-                        )
560
-                    );
561
-                    // set ticket formats
562
-                    $ticket->set_date_format($this->_date_format_strings['date']);
563
-                    $ticket->set_time_format($this->_date_format_strings['time']);
564
-                    // let's just check the total price for the existing ticket
565
-                    // and determine if it matches the new total price.
566
-                    // if they are different then we create a new ticket (if tickets sold)
567
-                    // if they aren't different then we go ahead and modify existing ticket.
568
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
569
-                    // set new values
570
-                    foreach ($TKT_values as $field => $value) {
571
-                        if ($field === 'TKT_qty') {
572
-                            $ticket->set_qty($value);
573
-                        } else {
574
-                            $ticket->set($field, $value);
575
-                        }
576
-                    }
577
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
578
-                    // Otherwise we have to create a new ticket.
579
-                    if ($create_new_TKT) {
580
-                        $new_tkt = $this->_duplicate_ticket(
581
-                            $ticket,
582
-                            $price_rows,
583
-                            $ticket_price,
584
-                            $base_price,
585
-                            $base_price_id
586
-                        );
587
-                    }
588
-                }
589
-            } else {
590
-                // no TKT_id so a new TKT
591
-                $ticket = EE_Ticket::new_instance(
592
-                    $TKT_values,
593
-                    $timezone,
594
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
595
-                );
596
-                if ($ticket instanceof EE_Ticket) {
597
-                    // make sure ticket has an ID of setting relations won't work
598
-                    $ticket->save();
599
-                    $ticket = $this->_update_ticket_datetimes(
600
-                        $ticket,
601
-                        $saved_datetimes,
602
-                        $datetimes_added,
603
-                        $datetimes_removed
604
-                    );
605
-                    $update_prices = true;
606
-                }
607
-            }
608
-            // make sure any current values have been saved.
609
-            // $ticket->save();
610
-            // before going any further make sure our dates are setup correctly
611
-            // so that the end date is always equal or greater than the start date.
612
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
613
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
614
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
615
-            }
616
-            // let's make sure the base price is handled
617
-            $ticket = ! $create_new_TKT
618
-                ? $this->_add_prices_to_ticket(
619
-                    array(),
620
-                    $ticket,
621
-                    $update_prices,
622
-                    $base_price,
623
-                    $base_price_id
624
-                )
625
-                : $ticket;
626
-            // add/update price_modifiers
627
-            $ticket = ! $create_new_TKT
628
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
629
-                : $ticket;
630
-            // need to make sue that the TKT_price is accurate after saving the prices.
631
-            $ticket->ensure_TKT_Price_correct();
632
-            // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
633
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
634
-                $update_prices = true;
635
-                $new_default = clone $ticket;
636
-                $new_default->set('TKT_ID', 0);
637
-                $new_default->set('TKT_is_default', 1);
638
-                $new_default->set('TKT_row', 1);
639
-                $new_default->set('TKT_price', $ticket_price);
640
-                // remove any dtt relations cause we DON'T want dtt relations attached
641
-                // (note this is just removing the cached relations in the object)
642
-                $new_default->_remove_relations('Datetime');
643
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
644
-                $new_default = $this->_add_prices_to_ticket(
645
-                    $price_rows,
646
-                    $new_default,
647
-                    $update_prices
648
-                );
649
-                // don't forget the base price!
650
-                $new_default = $this->_add_prices_to_ticket(
651
-                    array(),
652
-                    $new_default,
653
-                    $update_prices,
654
-                    $base_price,
655
-                    $base_price_id
656
-                );
657
-                $new_default->save();
658
-                do_action(
659
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
660
-                    $new_default,
661
-                    $row,
662
-                    $ticket,
663
-                    $data
664
-                );
665
-            }
666
-            // DO ALL dtt relationships for both current tickets and any archived tickets
667
-            // for the given dtt that are related to the current ticket.
668
-            // TODO... not sure exactly how we're going to do this considering we don't know
669
-            // what current ticket the archived tickets are related to
670
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
671
-            // let's assign any tickets that have been setup to the saved_tickets tracker
672
-            // save existing TKT
673
-            $ticket->save();
674
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
675
-                // save new TKT
676
-                $new_tkt->save();
677
-                // add new ticket to array
678
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
679
-                do_action(
680
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
681
-                    $new_tkt,
682
-                    $row,
683
-                    $tkt,
684
-                    $data
685
-                );
686
-            } else {
687
-                // add tkt to saved tkts
688
-                $saved_tickets[ $ticket->ID() ] = $ticket;
689
-                do_action(
690
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
691
-                    $ticket,
692
-                    $row,
693
-                    $tkt,
694
-                    $data
695
-                );
696
-            }
697
-        }
698
-        // now we need to handle tickets actually "deleted permanently".
699
-        // There are cases where we'd want this to happen
700
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
701
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
702
-        // No sense in keeping all the related data in the db!
703
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
704
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
705
-        foreach ($tickets_removed as $id) {
706
-            $id = absint($id);
707
-            // get the ticket for this id
708
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
709
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
710
-            if ($tkt_to_remove->get('TKT_is_default')) {
711
-                continue;
712
-            }
713
-            // if this tkt has any registrations attached so then we just ARCHIVE
714
-            // because we don't actually permanently delete these tickets.
715
-            if ($tkt_to_remove->count_related('Registration') > 0) {
716
-                $tkt_to_remove->delete();
717
-                continue;
718
-            }
719
-            // need to get all the related datetimes on this ticket and remove from every single one of them
720
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
721
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
722
-            foreach ($datetimes as $datetime) {
723
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
724
-            }
725
-            // need to do the same for prices (except these prices can also be deleted because again,
726
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
727
-            $tkt_to_remove->delete_related_permanently('Price');
728
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
729
-            // finally let's delete this ticket
730
-            // (which should not be blocked at this point b/c we've removed all our relationships)
731
-            $tkt_to_remove->delete_permanently();
732
-        }
733
-        return $saved_tickets;
734
-    }
422
+	/**
423
+	 * update tickets
424
+	 *
425
+	 * @param  EE_Event      $event           Event object being updated
426
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
427
+	 * @param  array         $data            incoming request data
428
+	 * @return EE_Ticket[]
429
+	 * @throws Exception
430
+	 * @throws ReflectionException
431
+	 * @throws InvalidInterfaceException
432
+	 * @throws InvalidDataTypeException
433
+	 * @throws InvalidArgumentException
434
+	 * @throws EE_Error
435
+	 */
436
+	protected function _update_tickets($event, $saved_datetimes, $data)
437
+	{
438
+		$new_tkt = null;
439
+		$new_default = null;
440
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
441
+		$data = stripslashes_deep($data);
442
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
443
+		$saved_tickets = $datetimes_on_existing = array();
444
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
445
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
446
+			throw new InvalidArgumentException(
447
+				esc_html__(
448
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
449
+					'event_espresso'
450
+				)
451
+			);
452
+		}
453
+		foreach ($data['edit_tickets'] as $row => $tkt) {
454
+			$update_prices = $create_new_TKT = false;
455
+			// figure out what datetimes were added to the ticket
456
+			// and what datetimes were removed from the ticket in the session.
457
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
458
+			$tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
459
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
460
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
461
+			// trim inputs to ensure any excess whitespace is removed.
462
+			$tkt = array_map(
463
+				function ($ticket_data) {
464
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
465
+				},
466
+				$tkt
467
+			);
468
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
469
+			// because we're doing calculations prior to using the models.
470
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
471
+			$ticket_price = isset($tkt['TKT_price'])
472
+				? round((float) $tkt['TKT_price'], 3)
473
+				: 0;
474
+			// note incoming base price needs converted from localized value.
475
+			$base_price = isset($tkt['TKT_base_price'])
476
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
477
+				: 0;
478
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
479
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
480
+				? $base_price
481
+				: $ticket_price;
482
+			$base_price_id = isset($tkt['TKT_base_price_ID'])
483
+				? $tkt['TKT_base_price_ID']
484
+				: 0;
485
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
486
+				? $data['edit_prices'][ $row ]
487
+				: array();
488
+			$now = null;
489
+			if (empty($tkt['TKT_start_date'])) {
490
+				// lets' use now in the set timezone.
491
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
492
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
493
+			}
494
+			if (empty($tkt['TKT_end_date'])) {
495
+				/**
496
+				 * set the TKT_end_date to the first datetime attached to the ticket.
497
+				 */
498
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
499
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
500
+			}
501
+			$TKT_values = array(
502
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
503
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
504
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
505
+				'TKT_description' => ! empty($tkt['TKT_description'])
506
+									 && $tkt['TKT_description'] !== esc_html__(
507
+										 'You can modify this description',
508
+										 'event_espresso'
509
+									 )
510
+					? $tkt['TKT_description']
511
+					: '',
512
+				'TKT_start_date'  => $tkt['TKT_start_date'],
513
+				'TKT_end_date'    => $tkt['TKT_end_date'],
514
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
515
+					? EE_INF
516
+					: $tkt['TKT_qty'],
517
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
518
+					? EE_INF
519
+					: $tkt['TKT_uses'],
520
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
521
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
522
+				'TKT_row'         => $row,
523
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
524
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
525
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
526
+				'TKT_price'       => $ticket_price,
527
+			);
528
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
529
+			// which means in turn that the prices will become new prices as well.
530
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
531
+				$TKT_values['TKT_ID'] = 0;
532
+				$TKT_values['TKT_is_default'] = 0;
533
+				$update_prices = true;
534
+			}
535
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
536
+			// we actually do our saves ahead of doing any add_relations to
537
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
538
+			// but DID have it's items modified.
539
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
540
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
541
+			if (absint($TKT_values['TKT_ID'])) {
542
+				$ticket = EE_Registry::instance()
543
+									 ->load_model('Ticket', array($timezone))
544
+									 ->get_one_by_ID($tkt['TKT_ID']);
545
+				if ($ticket instanceof EE_Ticket) {
546
+					$ticket = $this->_update_ticket_datetimes(
547
+						$ticket,
548
+						$saved_datetimes,
549
+						$datetimes_added,
550
+						$datetimes_removed
551
+					);
552
+					// are there any registrations using this ticket ?
553
+					$tickets_sold = $ticket->count_related(
554
+						'Registration',
555
+						array(
556
+							array(
557
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
558
+							),
559
+						)
560
+					);
561
+					// set ticket formats
562
+					$ticket->set_date_format($this->_date_format_strings['date']);
563
+					$ticket->set_time_format($this->_date_format_strings['time']);
564
+					// let's just check the total price for the existing ticket
565
+					// and determine if it matches the new total price.
566
+					// if they are different then we create a new ticket (if tickets sold)
567
+					// if they aren't different then we go ahead and modify existing ticket.
568
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
569
+					// set new values
570
+					foreach ($TKT_values as $field => $value) {
571
+						if ($field === 'TKT_qty') {
572
+							$ticket->set_qty($value);
573
+						} else {
574
+							$ticket->set($field, $value);
575
+						}
576
+					}
577
+					// if $create_new_TKT is false then we can safely update the existing ticket.
578
+					// Otherwise we have to create a new ticket.
579
+					if ($create_new_TKT) {
580
+						$new_tkt = $this->_duplicate_ticket(
581
+							$ticket,
582
+							$price_rows,
583
+							$ticket_price,
584
+							$base_price,
585
+							$base_price_id
586
+						);
587
+					}
588
+				}
589
+			} else {
590
+				// no TKT_id so a new TKT
591
+				$ticket = EE_Ticket::new_instance(
592
+					$TKT_values,
593
+					$timezone,
594
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
595
+				);
596
+				if ($ticket instanceof EE_Ticket) {
597
+					// make sure ticket has an ID of setting relations won't work
598
+					$ticket->save();
599
+					$ticket = $this->_update_ticket_datetimes(
600
+						$ticket,
601
+						$saved_datetimes,
602
+						$datetimes_added,
603
+						$datetimes_removed
604
+					);
605
+					$update_prices = true;
606
+				}
607
+			}
608
+			// make sure any current values have been saved.
609
+			// $ticket->save();
610
+			// before going any further make sure our dates are setup correctly
611
+			// so that the end date is always equal or greater than the start date.
612
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
613
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
614
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
615
+			}
616
+			// let's make sure the base price is handled
617
+			$ticket = ! $create_new_TKT
618
+				? $this->_add_prices_to_ticket(
619
+					array(),
620
+					$ticket,
621
+					$update_prices,
622
+					$base_price,
623
+					$base_price_id
624
+				)
625
+				: $ticket;
626
+			// add/update price_modifiers
627
+			$ticket = ! $create_new_TKT
628
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
629
+				: $ticket;
630
+			// need to make sue that the TKT_price is accurate after saving the prices.
631
+			$ticket->ensure_TKT_Price_correct();
632
+			// handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
633
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
634
+				$update_prices = true;
635
+				$new_default = clone $ticket;
636
+				$new_default->set('TKT_ID', 0);
637
+				$new_default->set('TKT_is_default', 1);
638
+				$new_default->set('TKT_row', 1);
639
+				$new_default->set('TKT_price', $ticket_price);
640
+				// remove any dtt relations cause we DON'T want dtt relations attached
641
+				// (note this is just removing the cached relations in the object)
642
+				$new_default->_remove_relations('Datetime');
643
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
644
+				$new_default = $this->_add_prices_to_ticket(
645
+					$price_rows,
646
+					$new_default,
647
+					$update_prices
648
+				);
649
+				// don't forget the base price!
650
+				$new_default = $this->_add_prices_to_ticket(
651
+					array(),
652
+					$new_default,
653
+					$update_prices,
654
+					$base_price,
655
+					$base_price_id
656
+				);
657
+				$new_default->save();
658
+				do_action(
659
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
660
+					$new_default,
661
+					$row,
662
+					$ticket,
663
+					$data
664
+				);
665
+			}
666
+			// DO ALL dtt relationships for both current tickets and any archived tickets
667
+			// for the given dtt that are related to the current ticket.
668
+			// TODO... not sure exactly how we're going to do this considering we don't know
669
+			// what current ticket the archived tickets are related to
670
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
671
+			// let's assign any tickets that have been setup to the saved_tickets tracker
672
+			// save existing TKT
673
+			$ticket->save();
674
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
675
+				// save new TKT
676
+				$new_tkt->save();
677
+				// add new ticket to array
678
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
679
+				do_action(
680
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
681
+					$new_tkt,
682
+					$row,
683
+					$tkt,
684
+					$data
685
+				);
686
+			} else {
687
+				// add tkt to saved tkts
688
+				$saved_tickets[ $ticket->ID() ] = $ticket;
689
+				do_action(
690
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
691
+					$ticket,
692
+					$row,
693
+					$tkt,
694
+					$data
695
+				);
696
+			}
697
+		}
698
+		// now we need to handle tickets actually "deleted permanently".
699
+		// There are cases where we'd want this to happen
700
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
701
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
702
+		// No sense in keeping all the related data in the db!
703
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
704
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
705
+		foreach ($tickets_removed as $id) {
706
+			$id = absint($id);
707
+			// get the ticket for this id
708
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
709
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
710
+			if ($tkt_to_remove->get('TKT_is_default')) {
711
+				continue;
712
+			}
713
+			// if this tkt has any registrations attached so then we just ARCHIVE
714
+			// because we don't actually permanently delete these tickets.
715
+			if ($tkt_to_remove->count_related('Registration') > 0) {
716
+				$tkt_to_remove->delete();
717
+				continue;
718
+			}
719
+			// need to get all the related datetimes on this ticket and remove from every single one of them
720
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
721
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
722
+			foreach ($datetimes as $datetime) {
723
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
724
+			}
725
+			// need to do the same for prices (except these prices can also be deleted because again,
726
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
727
+			$tkt_to_remove->delete_related_permanently('Price');
728
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
729
+			// finally let's delete this ticket
730
+			// (which should not be blocked at this point b/c we've removed all our relationships)
731
+			$tkt_to_remove->delete_permanently();
732
+		}
733
+		return $saved_tickets;
734
+	}
735 735
 
736 736
 
737
-    /**
738
-     * @access  protected
739
-     * @param EE_Ticket      $ticket
740
-     * @param \EE_Datetime[] $saved_datetimes
741
-     * @param \EE_Datetime[] $added_datetimes
742
-     * @param \EE_Datetime[] $removed_datetimes
743
-     * @return EE_Ticket
744
-     * @throws EE_Error
745
-     */
746
-    protected function _update_ticket_datetimes(
747
-        EE_Ticket $ticket,
748
-        $saved_datetimes = array(),
749
-        $added_datetimes = array(),
750
-        $removed_datetimes = array()
751
-    ) {
752
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
753
-        // and removing the ticket from datetimes it got removed from.
754
-        // first let's add datetimes
755
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
756
-            foreach ($added_datetimes as $row_id) {
757
-                $row_id = (int) $row_id;
758
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
759
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
760
-                    // Is this an existing ticket (has an ID) and does it have any sold?
761
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
762
-                    if ($ticket->ID() && $ticket->sold() > 0) {
763
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
764
-                    }
765
-                }
766
-            }
767
-        }
768
-        // then remove datetimes
769
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
770
-            foreach ($removed_datetimes as $row_id) {
771
-                $row_id = (int) $row_id;
772
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
773
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
774
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
775
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
776
-                    // Is this an existing ticket (has an ID) and does it have any sold?
777
-                    // If so, then we need to remove it's sold from the DTT_sold.
778
-                    if ($ticket->ID() && $ticket->sold() > 0) {
779
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
780
-                    }
781
-                }
782
-            }
783
-        }
784
-        // cap ticket qty by datetime reg limits
785
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
786
-        return $ticket;
787
-    }
737
+	/**
738
+	 * @access  protected
739
+	 * @param EE_Ticket      $ticket
740
+	 * @param \EE_Datetime[] $saved_datetimes
741
+	 * @param \EE_Datetime[] $added_datetimes
742
+	 * @param \EE_Datetime[] $removed_datetimes
743
+	 * @return EE_Ticket
744
+	 * @throws EE_Error
745
+	 */
746
+	protected function _update_ticket_datetimes(
747
+		EE_Ticket $ticket,
748
+		$saved_datetimes = array(),
749
+		$added_datetimes = array(),
750
+		$removed_datetimes = array()
751
+	) {
752
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
753
+		// and removing the ticket from datetimes it got removed from.
754
+		// first let's add datetimes
755
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
756
+			foreach ($added_datetimes as $row_id) {
757
+				$row_id = (int) $row_id;
758
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
759
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
760
+					// Is this an existing ticket (has an ID) and does it have any sold?
761
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
762
+					if ($ticket->ID() && $ticket->sold() > 0) {
763
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
764
+					}
765
+				}
766
+			}
767
+		}
768
+		// then remove datetimes
769
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
770
+			foreach ($removed_datetimes as $row_id) {
771
+				$row_id = (int) $row_id;
772
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
773
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
774
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
775
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
776
+					// Is this an existing ticket (has an ID) and does it have any sold?
777
+					// If so, then we need to remove it's sold from the DTT_sold.
778
+					if ($ticket->ID() && $ticket->sold() > 0) {
779
+						$saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
780
+					}
781
+				}
782
+			}
783
+		}
784
+		// cap ticket qty by datetime reg limits
785
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
786
+		return $ticket;
787
+	}
788 788
 
789 789
 
790
-    /**
791
-     * @access  protected
792
-     * @param EE_Ticket $ticket
793
-     * @param array     $price_rows
794
-     * @param int       $ticket_price
795
-     * @param int       $base_price
796
-     * @param int       $base_price_id
797
-     * @return EE_Ticket
798
-     * @throws ReflectionException
799
-     * @throws InvalidArgumentException
800
-     * @throws InvalidInterfaceException
801
-     * @throws InvalidDataTypeException
802
-     * @throws EE_Error
803
-     */
804
-    protected function _duplicate_ticket(
805
-        EE_Ticket $ticket,
806
-        $price_rows = array(),
807
-        $ticket_price = 0,
808
-        $base_price = 0,
809
-        $base_price_id = 0
810
-    ) {
811
-        // create new ticket that's a copy of the existing
812
-        // except a new id of course (and not archived)
813
-        // AND has the new TKT_price associated with it.
814
-        $new_ticket = clone $ticket;
815
-        $new_ticket->set('TKT_ID', 0);
816
-        $new_ticket->set_deleted(0);
817
-        $new_ticket->set_price($ticket_price);
818
-        $new_ticket->set_sold(0);
819
-        // let's get a new ID for this ticket
820
-        $new_ticket->save();
821
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
822
-        $datetimes_on_existing = $ticket->datetimes();
823
-        $new_ticket = $this->_update_ticket_datetimes(
824
-            $new_ticket,
825
-            $datetimes_on_existing,
826
-            array_keys($datetimes_on_existing)
827
-        );
828
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
829
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
830
-        // available.
831
-        if ($ticket->sold() > 0) {
832
-            $new_qty = $ticket->qty() - $ticket->sold();
833
-            $new_ticket->set_qty($new_qty);
834
-        }
835
-        // now we update the prices just for this ticket
836
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
837
-        // and we update the base price
838
-        $new_ticket = $this->_add_prices_to_ticket(
839
-            array(),
840
-            $new_ticket,
841
-            true,
842
-            $base_price,
843
-            $base_price_id
844
-        );
845
-        return $new_ticket;
846
-    }
790
+	/**
791
+	 * @access  protected
792
+	 * @param EE_Ticket $ticket
793
+	 * @param array     $price_rows
794
+	 * @param int       $ticket_price
795
+	 * @param int       $base_price
796
+	 * @param int       $base_price_id
797
+	 * @return EE_Ticket
798
+	 * @throws ReflectionException
799
+	 * @throws InvalidArgumentException
800
+	 * @throws InvalidInterfaceException
801
+	 * @throws InvalidDataTypeException
802
+	 * @throws EE_Error
803
+	 */
804
+	protected function _duplicate_ticket(
805
+		EE_Ticket $ticket,
806
+		$price_rows = array(),
807
+		$ticket_price = 0,
808
+		$base_price = 0,
809
+		$base_price_id = 0
810
+	) {
811
+		// create new ticket that's a copy of the existing
812
+		// except a new id of course (and not archived)
813
+		// AND has the new TKT_price associated with it.
814
+		$new_ticket = clone $ticket;
815
+		$new_ticket->set('TKT_ID', 0);
816
+		$new_ticket->set_deleted(0);
817
+		$new_ticket->set_price($ticket_price);
818
+		$new_ticket->set_sold(0);
819
+		// let's get a new ID for this ticket
820
+		$new_ticket->save();
821
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
822
+		$datetimes_on_existing = $ticket->datetimes();
823
+		$new_ticket = $this->_update_ticket_datetimes(
824
+			$new_ticket,
825
+			$datetimes_on_existing,
826
+			array_keys($datetimes_on_existing)
827
+		);
828
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
829
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
830
+		// available.
831
+		if ($ticket->sold() > 0) {
832
+			$new_qty = $ticket->qty() - $ticket->sold();
833
+			$new_ticket->set_qty($new_qty);
834
+		}
835
+		// now we update the prices just for this ticket
836
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
837
+		// and we update the base price
838
+		$new_ticket = $this->_add_prices_to_ticket(
839
+			array(),
840
+			$new_ticket,
841
+			true,
842
+			$base_price,
843
+			$base_price_id
844
+		);
845
+		return $new_ticket;
846
+	}
847 847
 
848 848
 
849
-    /**
850
-     * This attaches a list of given prices to a ticket.
851
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
852
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
853
-     * price info and prices are automatically "archived" via the ticket.
854
-     *
855
-     * @access  private
856
-     * @param array     $prices        Array of prices from the form.
857
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
858
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
859
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
860
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
861
-     * @return EE_Ticket
862
-     * @throws ReflectionException
863
-     * @throws InvalidArgumentException
864
-     * @throws InvalidInterfaceException
865
-     * @throws InvalidDataTypeException
866
-     * @throws EE_Error
867
-     */
868
-    protected function _add_prices_to_ticket(
869
-        $prices = array(),
870
-        EE_Ticket $ticket,
871
-        $new_prices = false,
872
-        $base_price = false,
873
-        $base_price_id = false
874
-    ) {
875
-        // let's just get any current prices that may exist on the given ticket
876
-        // so we can remove any prices that got trashed in this session.
877
-        $current_prices_on_ticket = $base_price !== false
878
-            ? $ticket->base_price(true)
879
-            : $ticket->price_modifiers();
880
-        $updated_prices = array();
881
-        // if $base_price ! FALSE then updating a base price.
882
-        if ($base_price !== false) {
883
-            $prices[1] = array(
884
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
885
-                'PRT_ID'     => 1,
886
-                'PRC_amount' => $base_price,
887
-                'PRC_name'   => $ticket->get('TKT_name'),
888
-                'PRC_desc'   => $ticket->get('TKT_description'),
889
-            );
890
-        }
891
-        // possibly need to save tkt
892
-        if (! $ticket->ID()) {
893
-            $ticket->save();
894
-        }
895
-        foreach ($prices as $row => $prc) {
896
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
897
-            if (empty($prt_id)) {
898
-                continue;
899
-            } //prices MUST have a price type id.
900
-            $PRC_values = array(
901
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
902
-                'PRT_ID'         => $prt_id,
903
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
904
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
905
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
906
-                'PRC_is_default' => false,
907
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
908
-                'PRC_order'      => $row,
909
-            );
910
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
911
-                $PRC_values['PRC_ID'] = 0;
912
-                $price = EE_Registry::instance()->load_class(
913
-                    'Price',
914
-                    array($PRC_values),
915
-                    false,
916
-                    false
917
-                );
918
-            } else {
919
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
920
-                // update this price with new values
921
-                foreach ($PRC_values as $field => $value) {
922
-                    $price->set($field, $value);
923
-                }
924
-            }
925
-            $price->save();
926
-            $updated_prices[ $price->ID() ] = $price;
927
-            $ticket->_add_relation_to($price, 'Price');
928
-        }
929
-        // now let's remove any prices that got removed from the ticket
930
-        if (! empty($current_prices_on_ticket)) {
931
-            $current = array_keys($current_prices_on_ticket);
932
-            $updated = array_keys($updated_prices);
933
-            $prices_to_remove = array_diff($current, $updated);
934
-            if (! empty($prices_to_remove)) {
935
-                foreach ($prices_to_remove as $prc_id) {
936
-                    $p = $current_prices_on_ticket[ $prc_id ];
937
-                    $ticket->_remove_relation_to($p, 'Price');
938
-                    // delete permanently the price
939
-                    $p->delete_permanently();
940
-                }
941
-            }
942
-        }
943
-        return $ticket;
944
-    }
849
+	/**
850
+	 * This attaches a list of given prices to a ticket.
851
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
852
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
853
+	 * price info and prices are automatically "archived" via the ticket.
854
+	 *
855
+	 * @access  private
856
+	 * @param array     $prices        Array of prices from the form.
857
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
858
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
859
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
860
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
861
+	 * @return EE_Ticket
862
+	 * @throws ReflectionException
863
+	 * @throws InvalidArgumentException
864
+	 * @throws InvalidInterfaceException
865
+	 * @throws InvalidDataTypeException
866
+	 * @throws EE_Error
867
+	 */
868
+	protected function _add_prices_to_ticket(
869
+		$prices = array(),
870
+		EE_Ticket $ticket,
871
+		$new_prices = false,
872
+		$base_price = false,
873
+		$base_price_id = false
874
+	) {
875
+		// let's just get any current prices that may exist on the given ticket
876
+		// so we can remove any prices that got trashed in this session.
877
+		$current_prices_on_ticket = $base_price !== false
878
+			? $ticket->base_price(true)
879
+			: $ticket->price_modifiers();
880
+		$updated_prices = array();
881
+		// if $base_price ! FALSE then updating a base price.
882
+		if ($base_price !== false) {
883
+			$prices[1] = array(
884
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
885
+				'PRT_ID'     => 1,
886
+				'PRC_amount' => $base_price,
887
+				'PRC_name'   => $ticket->get('TKT_name'),
888
+				'PRC_desc'   => $ticket->get('TKT_description'),
889
+			);
890
+		}
891
+		// possibly need to save tkt
892
+		if (! $ticket->ID()) {
893
+			$ticket->save();
894
+		}
895
+		foreach ($prices as $row => $prc) {
896
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
897
+			if (empty($prt_id)) {
898
+				continue;
899
+			} //prices MUST have a price type id.
900
+			$PRC_values = array(
901
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
902
+				'PRT_ID'         => $prt_id,
903
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
904
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
905
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
906
+				'PRC_is_default' => false,
907
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
908
+				'PRC_order'      => $row,
909
+			);
910
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
911
+				$PRC_values['PRC_ID'] = 0;
912
+				$price = EE_Registry::instance()->load_class(
913
+					'Price',
914
+					array($PRC_values),
915
+					false,
916
+					false
917
+				);
918
+			} else {
919
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
920
+				// update this price with new values
921
+				foreach ($PRC_values as $field => $value) {
922
+					$price->set($field, $value);
923
+				}
924
+			}
925
+			$price->save();
926
+			$updated_prices[ $price->ID() ] = $price;
927
+			$ticket->_add_relation_to($price, 'Price');
928
+		}
929
+		// now let's remove any prices that got removed from the ticket
930
+		if (! empty($current_prices_on_ticket)) {
931
+			$current = array_keys($current_prices_on_ticket);
932
+			$updated = array_keys($updated_prices);
933
+			$prices_to_remove = array_diff($current, $updated);
934
+			if (! empty($prices_to_remove)) {
935
+				foreach ($prices_to_remove as $prc_id) {
936
+					$p = $current_prices_on_ticket[ $prc_id ];
937
+					$ticket->_remove_relation_to($p, 'Price');
938
+					// delete permanently the price
939
+					$p->delete_permanently();
940
+				}
941
+			}
942
+		}
943
+		return $ticket;
944
+	}
945 945
 
946 946
 
947
-    /**
948
-     * @param Events_Admin_Page $event_admin_obj
949
-     * @return Events_Admin_Page
950
-     */
951
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
952
-    {
953
-        return $event_admin_obj;
954
-        // doing nothing for the moment.
955
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
956
-        // (use the set_template_args() method)
957
-        /**
958
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
959
-         * 1. TKT_is_default_selector (visible)
960
-         * 2. TKT_is_default (hidden)
961
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
962
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
963
-         * this ticket to be saved as a default.
964
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
965
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
966
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
967
-         * the TKT HAS been saved as a default..
968
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
969
-         * On Autosave:
970
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
971
-         * then set the TKT_is_default to false.
972
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
973
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
974
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
975
-         */
976
-    }
947
+	/**
948
+	 * @param Events_Admin_Page $event_admin_obj
949
+	 * @return Events_Admin_Page
950
+	 */
951
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
952
+	{
953
+		return $event_admin_obj;
954
+		// doing nothing for the moment.
955
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
956
+		// (use the set_template_args() method)
957
+		/**
958
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
959
+		 * 1. TKT_is_default_selector (visible)
960
+		 * 2. TKT_is_default (hidden)
961
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
962
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
963
+		 * this ticket to be saved as a default.
964
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
965
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
966
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
967
+		 * the TKT HAS been saved as a default..
968
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
969
+		 * On Autosave:
970
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
971
+		 * then set the TKT_is_default to false.
972
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
973
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
974
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
975
+		 */
976
+	}
977 977
 
978 978
 
979
-    /**
980
-     * @throws ReflectionException
981
-     * @throws InvalidArgumentException
982
-     * @throws InvalidInterfaceException
983
-     * @throws InvalidDataTypeException
984
-     * @throws DomainException
985
-     * @throws EE_Error
986
-     */
987
-    public function pricing_metabox()
988
-    {
989
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
990
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
991
-        // set is_creating_event property.
992
-        $EVT_ID = $event->ID();
993
-        $this->_is_creating_event = empty($this->_req_data['post']);
994
-        // default main template args
995
-        $main_template_args = array(
996
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
997
-                'event_editor_event_datetimes_help_tab',
998
-                $this->_adminpage_obj->page_slug,
999
-                $this->_adminpage_obj->get_req_action(),
1000
-                false,
1001
-                false
1002
-            ),
1003
-            // todo need to add a filter to the template for the help text
1004
-            // in the Events_Admin_Page core file so we can add further help
1005
-            'existing_datetime_ids'    => '',
1006
-            'total_dtt_rows'           => 1,
1007
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1008
-                'add_new_dtt_info',
1009
-                $this->_adminpage_obj->page_slug,
1010
-                $this->_adminpage_obj->get_req_action(),
1011
-                false,
1012
-                false
1013
-            ),
1014
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1015
-            'datetime_rows'            => '',
1016
-            'show_tickets_container'   => '',
1017
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1018
-            'ticket_rows'              => '',
1019
-            'existing_ticket_ids'      => '',
1020
-            'total_ticket_rows'        => 1,
1021
-            'ticket_js_structure'      => '',
1022
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1023
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1024
-        );
1025
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1026
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1027
-        /**
1028
-         * 1. Start with retrieving Datetimes
1029
-         * 2. For each datetime get related tickets
1030
-         * 3. For each ticket get related prices
1031
-         */
1032
-        /** @var EEM_Datetime $datetime_model */
1033
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1034
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1035
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1036
-        /**
1037
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1038
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1039
-         */
1040
-        $datetime_row = 1;
1041
-        foreach ($datetimes as $datetime) {
1042
-            $DTT_ID = $datetime->get('DTT_ID');
1043
-            $datetime->set('DTT_order', $datetime_row);
1044
-            $existing_datetime_ids[] = $DTT_ID;
1045
-            // tickets attached
1046
-            $related_tickets = $datetime->ID() > 0
1047
-                ? $datetime->get_many_related(
1048
-                    'Ticket',
1049
-                    array(
1050
-                        array(
1051
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1052
-                        ),
1053
-                        'default_where_conditions' => 'none',
1054
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1055
-                    )
1056
-                )
1057
-                : array();
1058
-            // if there are no related tickets this is likely a new event OR autodraft
1059
-            // event so we need to generate the default tickets because datetimes
1060
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1061
-            // datetime on the event.
1062
-            if (empty($related_tickets) && count($datetimes) < 2) {
1063
-                /** @var EEM_Ticket $ticket_model */
1064
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1065
-                $related_tickets = $ticket_model->get_all_default_tickets();
1066
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1067
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1068
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1069
-                $main_default_ticket = reset($related_tickets);
1070
-                if ($main_default_ticket instanceof EE_Ticket) {
1071
-                    foreach ($default_prices as $default_price) {
1072
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1073
-                            continue;
1074
-                        }
1075
-                        $main_default_ticket->cache('Price', $default_price);
1076
-                    }
1077
-                }
1078
-            }
1079
-            // we can't actually setup rows in this loop yet cause we don't know all
1080
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1081
-            // So we're going to temporarily cache some of that information.
1082
-            // loop through and setup the ticket rows and make sure the order is set.
1083
-            foreach ($related_tickets as $ticket) {
1084
-                $TKT_ID = $ticket->get('TKT_ID');
1085
-                $ticket_row = $ticket->get('TKT_row');
1086
-                // we only want unique tickets in our final display!!
1087
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1088
-                    $existing_ticket_ids[] = $TKT_ID;
1089
-                    $all_tickets[] = $ticket;
1090
-                }
1091
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1092
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1093
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1094
-                if (! isset($ticket_datetimes[ $TKT_ID ])
1095
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1096
-                ) {
1097
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1098
-                }
1099
-            }
1100
-            $datetime_row++;
1101
-        }
1102
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1103
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1104
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1105
-        // sort $all_tickets by order
1106
-        usort(
1107
-            $all_tickets,
1108
-            function (EE_Ticket $a, EE_Ticket $b) {
1109
-                $a_order = (int) $a->get('TKT_order');
1110
-                $b_order = (int) $b->get('TKT_order');
1111
-                if ($a_order === $b_order) {
1112
-                    return 0;
1113
-                }
1114
-                return ($a_order < $b_order) ? -1 : 1;
1115
-            }
1116
-        );
1117
-        // k NOW we have all the data we need for setting up the dtt rows
1118
-        // and ticket rows so we start our dtt loop again.
1119
-        $datetime_row = 1;
1120
-        foreach ($datetimes as $datetime) {
1121
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1122
-                $datetime_row,
1123
-                $datetime,
1124
-                $datetime_tickets,
1125
-                $all_tickets,
1126
-                false,
1127
-                $datetimes
1128
-            );
1129
-            $datetime_row++;
1130
-        }
1131
-        // then loop through all tickets for the ticket rows.
1132
-        $ticket_row = 1;
1133
-        foreach ($all_tickets as $ticket) {
1134
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1135
-                $ticket_row,
1136
-                $ticket,
1137
-                $ticket_datetimes,
1138
-                $datetimes,
1139
-                false,
1140
-                $all_tickets
1141
-            );
1142
-            $ticket_row++;
1143
-        }
1144
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1145
-        EEH_Template::display_template(
1146
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1147
-            $main_template_args
1148
-        );
1149
-    }
979
+	/**
980
+	 * @throws ReflectionException
981
+	 * @throws InvalidArgumentException
982
+	 * @throws InvalidInterfaceException
983
+	 * @throws InvalidDataTypeException
984
+	 * @throws DomainException
985
+	 * @throws EE_Error
986
+	 */
987
+	public function pricing_metabox()
988
+	{
989
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
990
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
991
+		// set is_creating_event property.
992
+		$EVT_ID = $event->ID();
993
+		$this->_is_creating_event = empty($this->_req_data['post']);
994
+		// default main template args
995
+		$main_template_args = array(
996
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
997
+				'event_editor_event_datetimes_help_tab',
998
+				$this->_adminpage_obj->page_slug,
999
+				$this->_adminpage_obj->get_req_action(),
1000
+				false,
1001
+				false
1002
+			),
1003
+			// todo need to add a filter to the template for the help text
1004
+			// in the Events_Admin_Page core file so we can add further help
1005
+			'existing_datetime_ids'    => '',
1006
+			'total_dtt_rows'           => 1,
1007
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1008
+				'add_new_dtt_info',
1009
+				$this->_adminpage_obj->page_slug,
1010
+				$this->_adminpage_obj->get_req_action(),
1011
+				false,
1012
+				false
1013
+			),
1014
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1015
+			'datetime_rows'            => '',
1016
+			'show_tickets_container'   => '',
1017
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1018
+			'ticket_rows'              => '',
1019
+			'existing_ticket_ids'      => '',
1020
+			'total_ticket_rows'        => 1,
1021
+			'ticket_js_structure'      => '',
1022
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1023
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1024
+		);
1025
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1026
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1027
+		/**
1028
+		 * 1. Start with retrieving Datetimes
1029
+		 * 2. For each datetime get related tickets
1030
+		 * 3. For each ticket get related prices
1031
+		 */
1032
+		/** @var EEM_Datetime $datetime_model */
1033
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1034
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1035
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1036
+		/**
1037
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1038
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1039
+		 */
1040
+		$datetime_row = 1;
1041
+		foreach ($datetimes as $datetime) {
1042
+			$DTT_ID = $datetime->get('DTT_ID');
1043
+			$datetime->set('DTT_order', $datetime_row);
1044
+			$existing_datetime_ids[] = $DTT_ID;
1045
+			// tickets attached
1046
+			$related_tickets = $datetime->ID() > 0
1047
+				? $datetime->get_many_related(
1048
+					'Ticket',
1049
+					array(
1050
+						array(
1051
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1052
+						),
1053
+						'default_where_conditions' => 'none',
1054
+						'order_by'                 => array('TKT_order' => 'ASC'),
1055
+					)
1056
+				)
1057
+				: array();
1058
+			// if there are no related tickets this is likely a new event OR autodraft
1059
+			// event so we need to generate the default tickets because datetimes
1060
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1061
+			// datetime on the event.
1062
+			if (empty($related_tickets) && count($datetimes) < 2) {
1063
+				/** @var EEM_Ticket $ticket_model */
1064
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1065
+				$related_tickets = $ticket_model->get_all_default_tickets();
1066
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1067
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1068
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1069
+				$main_default_ticket = reset($related_tickets);
1070
+				if ($main_default_ticket instanceof EE_Ticket) {
1071
+					foreach ($default_prices as $default_price) {
1072
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1073
+							continue;
1074
+						}
1075
+						$main_default_ticket->cache('Price', $default_price);
1076
+					}
1077
+				}
1078
+			}
1079
+			// we can't actually setup rows in this loop yet cause we don't know all
1080
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1081
+			// So we're going to temporarily cache some of that information.
1082
+			// loop through and setup the ticket rows and make sure the order is set.
1083
+			foreach ($related_tickets as $ticket) {
1084
+				$TKT_ID = $ticket->get('TKT_ID');
1085
+				$ticket_row = $ticket->get('TKT_row');
1086
+				// we only want unique tickets in our final display!!
1087
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1088
+					$existing_ticket_ids[] = $TKT_ID;
1089
+					$all_tickets[] = $ticket;
1090
+				}
1091
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1092
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1093
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1094
+				if (! isset($ticket_datetimes[ $TKT_ID ])
1095
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1096
+				) {
1097
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1098
+				}
1099
+			}
1100
+			$datetime_row++;
1101
+		}
1102
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1103
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1104
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1105
+		// sort $all_tickets by order
1106
+		usort(
1107
+			$all_tickets,
1108
+			function (EE_Ticket $a, EE_Ticket $b) {
1109
+				$a_order = (int) $a->get('TKT_order');
1110
+				$b_order = (int) $b->get('TKT_order');
1111
+				if ($a_order === $b_order) {
1112
+					return 0;
1113
+				}
1114
+				return ($a_order < $b_order) ? -1 : 1;
1115
+			}
1116
+		);
1117
+		// k NOW we have all the data we need for setting up the dtt rows
1118
+		// and ticket rows so we start our dtt loop again.
1119
+		$datetime_row = 1;
1120
+		foreach ($datetimes as $datetime) {
1121
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1122
+				$datetime_row,
1123
+				$datetime,
1124
+				$datetime_tickets,
1125
+				$all_tickets,
1126
+				false,
1127
+				$datetimes
1128
+			);
1129
+			$datetime_row++;
1130
+		}
1131
+		// then loop through all tickets for the ticket rows.
1132
+		$ticket_row = 1;
1133
+		foreach ($all_tickets as $ticket) {
1134
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1135
+				$ticket_row,
1136
+				$ticket,
1137
+				$ticket_datetimes,
1138
+				$datetimes,
1139
+				false,
1140
+				$all_tickets
1141
+			);
1142
+			$ticket_row++;
1143
+		}
1144
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1145
+		EEH_Template::display_template(
1146
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1147
+			$main_template_args
1148
+		);
1149
+	}
1150 1150
 
1151 1151
 
1152
-    /**
1153
-     * @param int         $datetime_row
1154
-     * @param EE_Datetime $datetime
1155
-     * @param array       $datetime_tickets
1156
-     * @param array       $all_tickets
1157
-     * @param bool        $default
1158
-     * @param array       $all_datetimes
1159
-     * @return mixed
1160
-     * @throws DomainException
1161
-     * @throws EE_Error
1162
-     */
1163
-    protected function _get_datetime_row(
1164
-        $datetime_row,
1165
-        EE_Datetime $datetime,
1166
-        $datetime_tickets = array(),
1167
-        $all_tickets = array(),
1168
-        $default = false,
1169
-        $all_datetimes = array()
1170
-    ) {
1171
-        $dtt_display_template_args = array(
1172
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1173
-                $datetime_row,
1174
-                $datetime,
1175
-                $default,
1176
-                $all_datetimes
1177
-            ),
1178
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1179
-                $datetime_row,
1180
-                $datetime,
1181
-                $datetime_tickets,
1182
-                $all_tickets,
1183
-                $default
1184
-            ),
1185
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1186
-        );
1187
-        return EEH_Template::display_template(
1188
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1189
-            $dtt_display_template_args,
1190
-            true
1191
-        );
1192
-    }
1152
+	/**
1153
+	 * @param int         $datetime_row
1154
+	 * @param EE_Datetime $datetime
1155
+	 * @param array       $datetime_tickets
1156
+	 * @param array       $all_tickets
1157
+	 * @param bool        $default
1158
+	 * @param array       $all_datetimes
1159
+	 * @return mixed
1160
+	 * @throws DomainException
1161
+	 * @throws EE_Error
1162
+	 */
1163
+	protected function _get_datetime_row(
1164
+		$datetime_row,
1165
+		EE_Datetime $datetime,
1166
+		$datetime_tickets = array(),
1167
+		$all_tickets = array(),
1168
+		$default = false,
1169
+		$all_datetimes = array()
1170
+	) {
1171
+		$dtt_display_template_args = array(
1172
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1173
+				$datetime_row,
1174
+				$datetime,
1175
+				$default,
1176
+				$all_datetimes
1177
+			),
1178
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1179
+				$datetime_row,
1180
+				$datetime,
1181
+				$datetime_tickets,
1182
+				$all_tickets,
1183
+				$default
1184
+			),
1185
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1186
+		);
1187
+		return EEH_Template::display_template(
1188
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1189
+			$dtt_display_template_args,
1190
+			true
1191
+		);
1192
+	}
1193 1193
 
1194 1194
 
1195
-    /**
1196
-     * This method is used to generate a dtt fields  edit row.
1197
-     * The same row is used to generate a row with valid DTT objects
1198
-     * and the default row that is used as the skeleton by the js.
1199
-     *
1200
-     * @param int           $datetime_row  The row number for the row being generated.
1201
-     * @param EE_Datetime   $datetime
1202
-     * @param bool          $default       Whether a default row is being generated or not.
1203
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1204
-     * @return string
1205
-     * @throws DomainException
1206
-     * @throws EE_Error
1207
-     */
1208
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1209
-    {
1210
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1211
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1212
-        $template_args = array(
1213
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1214
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1215
-            'edit_dtt_expanded'    => '',
1216
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1217
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1218
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1219
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1220
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1221
-            'DTT_reg_limit'        => $default
1222
-                ? ''
1223
-                : $datetime->get_pretty(
1224
-                    'DTT_reg_limit',
1225
-                    'input'
1226
-                ),
1227
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1228
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1229
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1230
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1231
-                ? ''
1232
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1233
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1234
-                ? 'ee-lock-icon'
1235
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1236
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1237
-                ? ''
1238
-                : EE_Admin_Page::add_query_args_and_nonce(
1239
-                    array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1240
-                    REG_ADMIN_URL
1241
-                ),
1242
-        );
1243
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1244
-            ? ' style="display:none"'
1245
-            : '';
1246
-        // allow filtering of template args at this point.
1247
-        $template_args = apply_filters(
1248
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1249
-            $template_args,
1250
-            $datetime_row,
1251
-            $datetime,
1252
-            $default,
1253
-            $all_datetimes,
1254
-            $this->_is_creating_event
1255
-        );
1256
-        return EEH_Template::display_template(
1257
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1258
-            $template_args,
1259
-            true
1260
-        );
1261
-    }
1195
+	/**
1196
+	 * This method is used to generate a dtt fields  edit row.
1197
+	 * The same row is used to generate a row with valid DTT objects
1198
+	 * and the default row that is used as the skeleton by the js.
1199
+	 *
1200
+	 * @param int           $datetime_row  The row number for the row being generated.
1201
+	 * @param EE_Datetime   $datetime
1202
+	 * @param bool          $default       Whether a default row is being generated or not.
1203
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1204
+	 * @return string
1205
+	 * @throws DomainException
1206
+	 * @throws EE_Error
1207
+	 */
1208
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1209
+	{
1210
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1211
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1212
+		$template_args = array(
1213
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1214
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1215
+			'edit_dtt_expanded'    => '',
1216
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1217
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1218
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1219
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1220
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1221
+			'DTT_reg_limit'        => $default
1222
+				? ''
1223
+				: $datetime->get_pretty(
1224
+					'DTT_reg_limit',
1225
+					'input'
1226
+				),
1227
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1228
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1229
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1230
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1231
+				? ''
1232
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1233
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1234
+				? 'ee-lock-icon'
1235
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1236
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1237
+				? ''
1238
+				: EE_Admin_Page::add_query_args_and_nonce(
1239
+					array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1240
+					REG_ADMIN_URL
1241
+				),
1242
+		);
1243
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1244
+			? ' style="display:none"'
1245
+			: '';
1246
+		// allow filtering of template args at this point.
1247
+		$template_args = apply_filters(
1248
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1249
+			$template_args,
1250
+			$datetime_row,
1251
+			$datetime,
1252
+			$default,
1253
+			$all_datetimes,
1254
+			$this->_is_creating_event
1255
+		);
1256
+		return EEH_Template::display_template(
1257
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1258
+			$template_args,
1259
+			true
1260
+		);
1261
+	}
1262 1262
 
1263 1263
 
1264
-    /**
1265
-     * @param int         $datetime_row
1266
-     * @param EE_Datetime $datetime
1267
-     * @param array       $datetime_tickets
1268
-     * @param array       $all_tickets
1269
-     * @param bool        $default
1270
-     * @return mixed
1271
-     * @throws DomainException
1272
-     * @throws EE_Error
1273
-     */
1274
-    protected function _get_dtt_attached_tickets_row(
1275
-        $datetime_row,
1276
-        $datetime,
1277
-        $datetime_tickets = array(),
1278
-        $all_tickets = array(),
1279
-        $default
1280
-    ) {
1281
-        $template_args = array(
1282
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1283
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1284
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1285
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1286
-            'show_tickets_row'                  => ' style="display:none;"',
1287
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1288
-                'add_new_ticket_via_datetime',
1289
-                $this->_adminpage_obj->page_slug,
1290
-                $this->_adminpage_obj->get_req_action(),
1291
-                false,
1292
-                false
1293
-            ),
1294
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1295
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1296
-        );
1297
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1298
-        if (! $default) {
1299
-            $ticket_row = 1;
1300
-            foreach ($all_tickets as $ticket) {
1301
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1302
-                    $datetime_row,
1303
-                    $ticket_row,
1304
-                    $datetime,
1305
-                    $ticket,
1306
-                    $datetime_tickets,
1307
-                    $default
1308
-                );
1309
-                $ticket_row++;
1310
-            }
1311
-        }
1312
-        // filter template args at this point
1313
-        $template_args = apply_filters(
1314
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1315
-            $template_args,
1316
-            $datetime_row,
1317
-            $datetime,
1318
-            $datetime_tickets,
1319
-            $all_tickets,
1320
-            $default,
1321
-            $this->_is_creating_event
1322
-        );
1323
-        return EEH_Template::display_template(
1324
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1325
-            $template_args,
1326
-            true
1327
-        );
1328
-    }
1264
+	/**
1265
+	 * @param int         $datetime_row
1266
+	 * @param EE_Datetime $datetime
1267
+	 * @param array       $datetime_tickets
1268
+	 * @param array       $all_tickets
1269
+	 * @param bool        $default
1270
+	 * @return mixed
1271
+	 * @throws DomainException
1272
+	 * @throws EE_Error
1273
+	 */
1274
+	protected function _get_dtt_attached_tickets_row(
1275
+		$datetime_row,
1276
+		$datetime,
1277
+		$datetime_tickets = array(),
1278
+		$all_tickets = array(),
1279
+		$default
1280
+	) {
1281
+		$template_args = array(
1282
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1283
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1284
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1285
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1286
+			'show_tickets_row'                  => ' style="display:none;"',
1287
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1288
+				'add_new_ticket_via_datetime',
1289
+				$this->_adminpage_obj->page_slug,
1290
+				$this->_adminpage_obj->get_req_action(),
1291
+				false,
1292
+				false
1293
+			),
1294
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1295
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1296
+		);
1297
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1298
+		if (! $default) {
1299
+			$ticket_row = 1;
1300
+			foreach ($all_tickets as $ticket) {
1301
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1302
+					$datetime_row,
1303
+					$ticket_row,
1304
+					$datetime,
1305
+					$ticket,
1306
+					$datetime_tickets,
1307
+					$default
1308
+				);
1309
+				$ticket_row++;
1310
+			}
1311
+		}
1312
+		// filter template args at this point
1313
+		$template_args = apply_filters(
1314
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1315
+			$template_args,
1316
+			$datetime_row,
1317
+			$datetime,
1318
+			$datetime_tickets,
1319
+			$all_tickets,
1320
+			$default,
1321
+			$this->_is_creating_event
1322
+		);
1323
+		return EEH_Template::display_template(
1324
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1325
+			$template_args,
1326
+			true
1327
+		);
1328
+	}
1329 1329
 
1330 1330
 
1331
-    /**
1332
-     * @param int         $datetime_row
1333
-     * @param int         $ticket_row
1334
-     * @param EE_Datetime $datetime
1335
-     * @param EE_Ticket   $ticket
1336
-     * @param array       $datetime_tickets
1337
-     * @param bool        $default
1338
-     * @return mixed
1339
-     * @throws DomainException
1340
-     * @throws EE_Error
1341
-     */
1342
-    protected function _get_datetime_tickets_list_item(
1343
-        $datetime_row,
1344
-        $ticket_row,
1345
-        $datetime,
1346
-        $ticket,
1347
-        $datetime_tickets = array(),
1348
-        $default
1349
-    ) {
1350
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1351
-            ? $datetime_tickets[ $datetime->ID() ]
1352
-            : array();
1353
-        $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1354
-        $no_ticket = $default && empty($ticket);
1355
-        $template_args = array(
1356
-            'dtt_row'                 => $default
1357
-                ? 'DTTNUM'
1358
-                : $datetime_row,
1359
-            'tkt_row'                 => $no_ticket
1360
-                ? 'TICKETNUM'
1361
-                : $ticket_row,
1362
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1363
-                ? ' checked="checked"'
1364
-                : '',
1365
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1366
-                ? ' ticket-selected'
1367
-                : '',
1368
-            'TKT_name'                => $no_ticket
1369
-                ? 'TKTNAME'
1370
-                : $ticket->get('TKT_name'),
1371
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1372
-                ? ' tkt-status-' . EE_Ticket::onsale
1373
-                : ' tkt-status-' . $ticket->ticket_status(),
1374
-        );
1375
-        // filter template args
1376
-        $template_args = apply_filters(
1377
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1378
-            $template_args,
1379
-            $datetime_row,
1380
-            $ticket_row,
1381
-            $datetime,
1382
-            $ticket,
1383
-            $datetime_tickets,
1384
-            $default,
1385
-            $this->_is_creating_event
1386
-        );
1387
-        return EEH_Template::display_template(
1388
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1389
-            $template_args,
1390
-            true
1391
-        );
1392
-    }
1331
+	/**
1332
+	 * @param int         $datetime_row
1333
+	 * @param int         $ticket_row
1334
+	 * @param EE_Datetime $datetime
1335
+	 * @param EE_Ticket   $ticket
1336
+	 * @param array       $datetime_tickets
1337
+	 * @param bool        $default
1338
+	 * @return mixed
1339
+	 * @throws DomainException
1340
+	 * @throws EE_Error
1341
+	 */
1342
+	protected function _get_datetime_tickets_list_item(
1343
+		$datetime_row,
1344
+		$ticket_row,
1345
+		$datetime,
1346
+		$ticket,
1347
+		$datetime_tickets = array(),
1348
+		$default
1349
+	) {
1350
+		$dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1351
+			? $datetime_tickets[ $datetime->ID() ]
1352
+			: array();
1353
+		$display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1354
+		$no_ticket = $default && empty($ticket);
1355
+		$template_args = array(
1356
+			'dtt_row'                 => $default
1357
+				? 'DTTNUM'
1358
+				: $datetime_row,
1359
+			'tkt_row'                 => $no_ticket
1360
+				? 'TICKETNUM'
1361
+				: $ticket_row,
1362
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1363
+				? ' checked="checked"'
1364
+				: '',
1365
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1366
+				? ' ticket-selected'
1367
+				: '',
1368
+			'TKT_name'                => $no_ticket
1369
+				? 'TKTNAME'
1370
+				: $ticket->get('TKT_name'),
1371
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1372
+				? ' tkt-status-' . EE_Ticket::onsale
1373
+				: ' tkt-status-' . $ticket->ticket_status(),
1374
+		);
1375
+		// filter template args
1376
+		$template_args = apply_filters(
1377
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1378
+			$template_args,
1379
+			$datetime_row,
1380
+			$ticket_row,
1381
+			$datetime,
1382
+			$ticket,
1383
+			$datetime_tickets,
1384
+			$default,
1385
+			$this->_is_creating_event
1386
+		);
1387
+		return EEH_Template::display_template(
1388
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1389
+			$template_args,
1390
+			true
1391
+		);
1392
+	}
1393 1393
 
1394 1394
 
1395
-    /**
1396
-     * This generates the ticket row for tickets.
1397
-     * This same method is used to generate both the actual rows and the js skeleton row
1398
-     * (when default === true)
1399
-     *
1400
-     * @param int           $ticket_row       Represents the row number being generated.
1401
-     * @param               $ticket
1402
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1403
-     *                                        or empty for default
1404
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1405
-     * @param bool          $default          Whether default row being generated or not.
1406
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1407
-     *                                        (or empty in the case of defaults)
1408
-     * @return mixed
1409
-     * @throws InvalidArgumentException
1410
-     * @throws InvalidInterfaceException
1411
-     * @throws InvalidDataTypeException
1412
-     * @throws DomainException
1413
-     * @throws EE_Error
1414
-     * @throws ReflectionException
1415
-     */
1416
-    protected function _get_ticket_row(
1417
-        $ticket_row,
1418
-        $ticket,
1419
-        $ticket_datetimes,
1420
-        $all_datetimes,
1421
-        $default = false,
1422
-        $all_tickets = array()
1423
-    ) {
1424
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1425
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1426
-        $prices = ! empty($ticket) && ! $default
1427
-            ? $ticket->get_many_related(
1428
-                'Price',
1429
-                array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1430
-            )
1431
-            : array();
1432
-        // if there is only one price (which would be the base price)
1433
-        // or NO prices and this ticket is a default ticket,
1434
-        // let's just make sure there are no cached default prices on the object.
1435
-        // This is done by not including any query_params.
1436
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1437
-            $prices = $ticket->prices();
1438
-        }
1439
-        // check if we're dealing with a default ticket in which case
1440
-        // we don't want any starting_ticket_datetime_row values set
1441
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1442
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1443
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1444
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1445
-            ? $ticket_datetimes[ $ticket->ID() ]
1446
-            : array();
1447
-        $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1448
-        $base_price = $default ? null : $ticket->base_price();
1449
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1450
-        // breaking out complicated condition for ticket_status
1451
-        if ($default) {
1452
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1453
-        } else {
1454
-            $ticket_status_class = $ticket->is_default()
1455
-                ? ' tkt-status-' . EE_Ticket::onsale
1456
-                : ' tkt-status-' . $ticket->ticket_status();
1457
-        }
1458
-        // breaking out complicated condition for TKT_taxable
1459
-        if ($default) {
1460
-            $TKT_taxable = '';
1461
-        } else {
1462
-            $TKT_taxable = $ticket->taxable()
1463
-                ? ' checked="checked"'
1464
-                : '';
1465
-        }
1466
-        if ($default) {
1467
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1468
-        } elseif ($ticket->is_default()) {
1469
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1470
-        } else {
1471
-            $TKT_status = $ticket->ticket_status(true);
1472
-        }
1473
-        if ($default) {
1474
-            $TKT_min = '';
1475
-        } else {
1476
-            $TKT_min = $ticket->min();
1477
-            if ($TKT_min === -1 || $TKT_min === 0) {
1478
-                $TKT_min = '';
1479
-            }
1480
-        }
1481
-        $template_args = array(
1482
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1483
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1484
-            // on initial page load this will always be the correct order.
1485
-            'tkt_status_class'              => $ticket_status_class,
1486
-            'display_edit_tkt_row'          => ' style="display:none;"',
1487
-            'edit_tkt_expanded'             => '',
1488
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1489
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1490
-            'TKT_start_date'                => $default
1491
-                ? ''
1492
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1493
-            'TKT_end_date'                  => $default
1494
-                ? ''
1495
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1496
-            'TKT_status'                    => $TKT_status,
1497
-            'TKT_price'                     => $default
1498
-                ? ''
1499
-                : EEH_Template::format_currency(
1500
-                    $ticket->get_ticket_total_with_taxes(),
1501
-                    false,
1502
-                    false
1503
-                ),
1504
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1505
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1506
-            'TKT_qty'                       => $default
1507
-                ? ''
1508
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1509
-            'TKT_qty_for_input'             => $default
1510
-                ? ''
1511
-                : $ticket->get_pretty('TKT_qty', 'input'),
1512
-            'TKT_uses'                      => $default
1513
-                ? ''
1514
-                : $ticket->get_pretty('TKT_uses', 'input'),
1515
-            'TKT_min'                       => $TKT_min,
1516
-            'TKT_max'                       => $default
1517
-                ? ''
1518
-                : $ticket->get_pretty('TKT_max', 'input'),
1519
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1520
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1521
-            'TKT_registrations'             => $default
1522
-                ? 0
1523
-                : $ticket->count_registrations(
1524
-                    array(
1525
-                        array(
1526
-                            'STS_ID' => array(
1527
-                                '!=',
1528
-                                EEM_Registration::status_id_incomplete,
1529
-                            ),
1530
-                        ),
1531
-                    )
1532
-                ),
1533
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1534
-            'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1535
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1536
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1537
-            'TKT_is_default_selector'       => '',
1538
-            'ticket_price_rows'             => '',
1539
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1540
-                ? ''
1541
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1542
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1543
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1544
-                ? ''
1545
-                : ' style="display:none;"',
1546
-            'show_price_mod_button'         => count($prices) > 1
1547
-                                               || ($default && $count_price_mods > 0)
1548
-                                               || (! $default && $ticket->deleted())
1549
-                ? ' style="display:none;"'
1550
-                : '',
1551
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1552
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1553
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1554
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1555
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1556
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1557
-            'TKT_taxable'                   => $TKT_taxable,
1558
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1559
-                ? ''
1560
-                : ' style="display:none"',
1561
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1562
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1563
-                $ticket_subtotal,
1564
-                false,
1565
-                false
1566
-            ),
1567
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1568
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1569
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1570
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1571
-                ? ' ticket-archived'
1572
-                : '',
1573
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1574
-                                               && $ticket->deleted()
1575
-                                               && ! $ticket->is_permanently_deleteable()
1576
-                ? 'ee-lock-icon '
1577
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1578
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1579
-                ? ''
1580
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1581
-        );
1582
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1583
-            ? ' style="display:none"'
1584
-            : '';
1585
-        // handle rows that should NOT be empty
1586
-        if (empty($template_args['TKT_start_date'])) {
1587
-            // if empty then the start date will be now.
1588
-            $template_args['TKT_start_date'] = date(
1589
-                $this->_date_time_format,
1590
-                current_time('timestamp')
1591
-            );
1592
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1593
-        }
1594
-        if (empty($template_args['TKT_end_date'])) {
1595
-            // get the earliest datetime (if present);
1596
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1597
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1598
-                    'Datetime',
1599
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1600
-                )
1601
-                : null;
1602
-            if (! empty($earliest_dtt)) {
1603
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1604
-                    'DTT_EVT_start',
1605
-                    $this->_date_time_format
1606
-                );
1607
-            } else {
1608
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1609
-                $template_args['TKT_end_date'] = date(
1610
-                    $this->_date_time_format,
1611
-                    mktime(
1612
-                        24,
1613
-                        0,
1614
-                        0,
1615
-                        date('m'),
1616
-                        date('d') + 29,
1617
-                        date('Y')
1618
-                    )
1619
-                );
1620
-            }
1621
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1622
-        }
1623
-        // generate ticket_datetime items
1624
-        if (! $default) {
1625
-            $datetime_row = 1;
1626
-            foreach ($all_datetimes as $datetime) {
1627
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1628
-                    $datetime_row,
1629
-                    $ticket_row,
1630
-                    $datetime,
1631
-                    $ticket,
1632
-                    $ticket_datetimes,
1633
-                    $default
1634
-                );
1635
-                $datetime_row++;
1636
-            }
1637
-        }
1638
-        $price_row = 1;
1639
-        foreach ($prices as $price) {
1640
-            if (! $price instanceof EE_Price) {
1641
-                continue;
1642
-            }
1643
-            if ($price->is_base_price()) {
1644
-                $price_row++;
1645
-                continue;
1646
-            }
1647
-            $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1648
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1649
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1650
-                $ticket_row,
1651
-                $price_row,
1652
-                $price,
1653
-                $default,
1654
-                $ticket,
1655
-                $show_trash,
1656
-                $show_create
1657
-            );
1658
-            $price_row++;
1659
-        }
1660
-        // filter $template_args
1661
-        $template_args = apply_filters(
1662
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1663
-            $template_args,
1664
-            $ticket_row,
1665
-            $ticket,
1666
-            $ticket_datetimes,
1667
-            $all_datetimes,
1668
-            $default,
1669
-            $all_tickets,
1670
-            $this->_is_creating_event
1671
-        );
1672
-        return EEH_Template::display_template(
1673
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1674
-            $template_args,
1675
-            true
1676
-        );
1677
-    }
1395
+	/**
1396
+	 * This generates the ticket row for tickets.
1397
+	 * This same method is used to generate both the actual rows and the js skeleton row
1398
+	 * (when default === true)
1399
+	 *
1400
+	 * @param int           $ticket_row       Represents the row number being generated.
1401
+	 * @param               $ticket
1402
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1403
+	 *                                        or empty for default
1404
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1405
+	 * @param bool          $default          Whether default row being generated or not.
1406
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1407
+	 *                                        (or empty in the case of defaults)
1408
+	 * @return mixed
1409
+	 * @throws InvalidArgumentException
1410
+	 * @throws InvalidInterfaceException
1411
+	 * @throws InvalidDataTypeException
1412
+	 * @throws DomainException
1413
+	 * @throws EE_Error
1414
+	 * @throws ReflectionException
1415
+	 */
1416
+	protected function _get_ticket_row(
1417
+		$ticket_row,
1418
+		$ticket,
1419
+		$ticket_datetimes,
1420
+		$all_datetimes,
1421
+		$default = false,
1422
+		$all_tickets = array()
1423
+	) {
1424
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1425
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1426
+		$prices = ! empty($ticket) && ! $default
1427
+			? $ticket->get_many_related(
1428
+				'Price',
1429
+				array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1430
+			)
1431
+			: array();
1432
+		// if there is only one price (which would be the base price)
1433
+		// or NO prices and this ticket is a default ticket,
1434
+		// let's just make sure there are no cached default prices on the object.
1435
+		// This is done by not including any query_params.
1436
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1437
+			$prices = $ticket->prices();
1438
+		}
1439
+		// check if we're dealing with a default ticket in which case
1440
+		// we don't want any starting_ticket_datetime_row values set
1441
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1442
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1443
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1444
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1445
+			? $ticket_datetimes[ $ticket->ID() ]
1446
+			: array();
1447
+		$ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1448
+		$base_price = $default ? null : $ticket->base_price();
1449
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1450
+		// breaking out complicated condition for ticket_status
1451
+		if ($default) {
1452
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1453
+		} else {
1454
+			$ticket_status_class = $ticket->is_default()
1455
+				? ' tkt-status-' . EE_Ticket::onsale
1456
+				: ' tkt-status-' . $ticket->ticket_status();
1457
+		}
1458
+		// breaking out complicated condition for TKT_taxable
1459
+		if ($default) {
1460
+			$TKT_taxable = '';
1461
+		} else {
1462
+			$TKT_taxable = $ticket->taxable()
1463
+				? ' checked="checked"'
1464
+				: '';
1465
+		}
1466
+		if ($default) {
1467
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1468
+		} elseif ($ticket->is_default()) {
1469
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1470
+		} else {
1471
+			$TKT_status = $ticket->ticket_status(true);
1472
+		}
1473
+		if ($default) {
1474
+			$TKT_min = '';
1475
+		} else {
1476
+			$TKT_min = $ticket->min();
1477
+			if ($TKT_min === -1 || $TKT_min === 0) {
1478
+				$TKT_min = '';
1479
+			}
1480
+		}
1481
+		$template_args = array(
1482
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1483
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1484
+			// on initial page load this will always be the correct order.
1485
+			'tkt_status_class'              => $ticket_status_class,
1486
+			'display_edit_tkt_row'          => ' style="display:none;"',
1487
+			'edit_tkt_expanded'             => '',
1488
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1489
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1490
+			'TKT_start_date'                => $default
1491
+				? ''
1492
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1493
+			'TKT_end_date'                  => $default
1494
+				? ''
1495
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1496
+			'TKT_status'                    => $TKT_status,
1497
+			'TKT_price'                     => $default
1498
+				? ''
1499
+				: EEH_Template::format_currency(
1500
+					$ticket->get_ticket_total_with_taxes(),
1501
+					false,
1502
+					false
1503
+				),
1504
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1505
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1506
+			'TKT_qty'                       => $default
1507
+				? ''
1508
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1509
+			'TKT_qty_for_input'             => $default
1510
+				? ''
1511
+				: $ticket->get_pretty('TKT_qty', 'input'),
1512
+			'TKT_uses'                      => $default
1513
+				? ''
1514
+				: $ticket->get_pretty('TKT_uses', 'input'),
1515
+			'TKT_min'                       => $TKT_min,
1516
+			'TKT_max'                       => $default
1517
+				? ''
1518
+				: $ticket->get_pretty('TKT_max', 'input'),
1519
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1520
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1521
+			'TKT_registrations'             => $default
1522
+				? 0
1523
+				: $ticket->count_registrations(
1524
+					array(
1525
+						array(
1526
+							'STS_ID' => array(
1527
+								'!=',
1528
+								EEM_Registration::status_id_incomplete,
1529
+							),
1530
+						),
1531
+					)
1532
+				),
1533
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1534
+			'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1535
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1536
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1537
+			'TKT_is_default_selector'       => '',
1538
+			'ticket_price_rows'             => '',
1539
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1540
+				? ''
1541
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1542
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1543
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1544
+				? ''
1545
+				: ' style="display:none;"',
1546
+			'show_price_mod_button'         => count($prices) > 1
1547
+											   || ($default && $count_price_mods > 0)
1548
+											   || (! $default && $ticket->deleted())
1549
+				? ' style="display:none;"'
1550
+				: '',
1551
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1552
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1553
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1554
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1555
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1556
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1557
+			'TKT_taxable'                   => $TKT_taxable,
1558
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1559
+				? ''
1560
+				: ' style="display:none"',
1561
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1562
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1563
+				$ticket_subtotal,
1564
+				false,
1565
+				false
1566
+			),
1567
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1568
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1569
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1570
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1571
+				? ' ticket-archived'
1572
+				: '',
1573
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1574
+											   && $ticket->deleted()
1575
+											   && ! $ticket->is_permanently_deleteable()
1576
+				? 'ee-lock-icon '
1577
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1578
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1579
+				? ''
1580
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1581
+		);
1582
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1583
+			? ' style="display:none"'
1584
+			: '';
1585
+		// handle rows that should NOT be empty
1586
+		if (empty($template_args['TKT_start_date'])) {
1587
+			// if empty then the start date will be now.
1588
+			$template_args['TKT_start_date'] = date(
1589
+				$this->_date_time_format,
1590
+				current_time('timestamp')
1591
+			);
1592
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1593
+		}
1594
+		if (empty($template_args['TKT_end_date'])) {
1595
+			// get the earliest datetime (if present);
1596
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1597
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1598
+					'Datetime',
1599
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1600
+				)
1601
+				: null;
1602
+			if (! empty($earliest_dtt)) {
1603
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1604
+					'DTT_EVT_start',
1605
+					$this->_date_time_format
1606
+				);
1607
+			} else {
1608
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1609
+				$template_args['TKT_end_date'] = date(
1610
+					$this->_date_time_format,
1611
+					mktime(
1612
+						24,
1613
+						0,
1614
+						0,
1615
+						date('m'),
1616
+						date('d') + 29,
1617
+						date('Y')
1618
+					)
1619
+				);
1620
+			}
1621
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1622
+		}
1623
+		// generate ticket_datetime items
1624
+		if (! $default) {
1625
+			$datetime_row = 1;
1626
+			foreach ($all_datetimes as $datetime) {
1627
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1628
+					$datetime_row,
1629
+					$ticket_row,
1630
+					$datetime,
1631
+					$ticket,
1632
+					$ticket_datetimes,
1633
+					$default
1634
+				);
1635
+				$datetime_row++;
1636
+			}
1637
+		}
1638
+		$price_row = 1;
1639
+		foreach ($prices as $price) {
1640
+			if (! $price instanceof EE_Price) {
1641
+				continue;
1642
+			}
1643
+			if ($price->is_base_price()) {
1644
+				$price_row++;
1645
+				continue;
1646
+			}
1647
+			$show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1648
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1649
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1650
+				$ticket_row,
1651
+				$price_row,
1652
+				$price,
1653
+				$default,
1654
+				$ticket,
1655
+				$show_trash,
1656
+				$show_create
1657
+			);
1658
+			$price_row++;
1659
+		}
1660
+		// filter $template_args
1661
+		$template_args = apply_filters(
1662
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1663
+			$template_args,
1664
+			$ticket_row,
1665
+			$ticket,
1666
+			$ticket_datetimes,
1667
+			$all_datetimes,
1668
+			$default,
1669
+			$all_tickets,
1670
+			$this->_is_creating_event
1671
+		);
1672
+		return EEH_Template::display_template(
1673
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1674
+			$template_args,
1675
+			true
1676
+		);
1677
+	}
1678 1678
 
1679 1679
 
1680
-    /**
1681
-     * @param int            $ticket_row
1682
-     * @param EE_Ticket|null $ticket
1683
-     * @return string
1684
-     * @throws DomainException
1685
-     * @throws EE_Error
1686
-     */
1687
-    protected function _get_tax_rows($ticket_row, $ticket)
1688
-    {
1689
-        $tax_rows = '';
1690
-        /** @var EE_Price[] $taxes */
1691
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1692
-        foreach ($taxes as $tax) {
1693
-            $tax_added = $this->_get_tax_added($tax, $ticket);
1694
-            $template_args = array(
1695
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1696
-                    ? ''
1697
-                    : ' style="display:none;"',
1698
-                'tax_id'            => $tax->ID(),
1699
-                'tkt_row'           => $ticket_row,
1700
-                'tax_label'         => $tax->get('PRC_name'),
1701
-                'tax_added'         => $tax_added,
1702
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1703
-                'tax_amount'        => $tax->get('PRC_amount'),
1704
-            );
1705
-            $template_args = apply_filters(
1706
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1707
-                $template_args,
1708
-                $ticket_row,
1709
-                $ticket,
1710
-                $this->_is_creating_event
1711
-            );
1712
-            $tax_rows .= EEH_Template::display_template(
1713
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1714
-                $template_args,
1715
-                true
1716
-            );
1717
-        }
1718
-        return $tax_rows;
1719
-    }
1680
+	/**
1681
+	 * @param int            $ticket_row
1682
+	 * @param EE_Ticket|null $ticket
1683
+	 * @return string
1684
+	 * @throws DomainException
1685
+	 * @throws EE_Error
1686
+	 */
1687
+	protected function _get_tax_rows($ticket_row, $ticket)
1688
+	{
1689
+		$tax_rows = '';
1690
+		/** @var EE_Price[] $taxes */
1691
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1692
+		foreach ($taxes as $tax) {
1693
+			$tax_added = $this->_get_tax_added($tax, $ticket);
1694
+			$template_args = array(
1695
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1696
+					? ''
1697
+					: ' style="display:none;"',
1698
+				'tax_id'            => $tax->ID(),
1699
+				'tkt_row'           => $ticket_row,
1700
+				'tax_label'         => $tax->get('PRC_name'),
1701
+				'tax_added'         => $tax_added,
1702
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1703
+				'tax_amount'        => $tax->get('PRC_amount'),
1704
+			);
1705
+			$template_args = apply_filters(
1706
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1707
+				$template_args,
1708
+				$ticket_row,
1709
+				$ticket,
1710
+				$this->_is_creating_event
1711
+			);
1712
+			$tax_rows .= EEH_Template::display_template(
1713
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1714
+				$template_args,
1715
+				true
1716
+			);
1717
+		}
1718
+		return $tax_rows;
1719
+	}
1720 1720
 
1721 1721
 
1722
-    /**
1723
-     * @param EE_Price       $tax
1724
-     * @param EE_Ticket|null $ticket
1725
-     * @return float|int
1726
-     * @throws EE_Error
1727
-     */
1728
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1729
-    {
1730
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1731
-        return $subtotal * $tax->get('PRC_amount') / 100;
1732
-    }
1722
+	/**
1723
+	 * @param EE_Price       $tax
1724
+	 * @param EE_Ticket|null $ticket
1725
+	 * @return float|int
1726
+	 * @throws EE_Error
1727
+	 */
1728
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1729
+	{
1730
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1731
+		return $subtotal * $tax->get('PRC_amount') / 100;
1732
+	}
1733 1733
 
1734 1734
 
1735
-    /**
1736
-     * @param int            $ticket_row
1737
-     * @param int            $price_row
1738
-     * @param EE_Price|null  $price
1739
-     * @param bool           $default
1740
-     * @param EE_Ticket|null $ticket
1741
-     * @param bool           $show_trash
1742
-     * @param bool           $show_create
1743
-     * @return mixed
1744
-     * @throws InvalidArgumentException
1745
-     * @throws InvalidInterfaceException
1746
-     * @throws InvalidDataTypeException
1747
-     * @throws DomainException
1748
-     * @throws EE_Error
1749
-     * @throws ReflectionException
1750
-     */
1751
-    protected function _get_ticket_price_row(
1752
-        $ticket_row,
1753
-        $price_row,
1754
-        $price,
1755
-        $default,
1756
-        $ticket,
1757
-        $show_trash = true,
1758
-        $show_create = true
1759
-    ) {
1760
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1761
-        $template_args = array(
1762
-            'tkt_row'               => $default && empty($ticket)
1763
-                ? 'TICKETNUM'
1764
-                : $ticket_row,
1765
-            'PRC_order'             => $default && empty($price)
1766
-                ? 'PRICENUM'
1767
-                : $price_row,
1768
-            'edit_prices_name'      => $default && empty($price)
1769
-                ? 'PRICENAMEATTR'
1770
-                : 'edit_prices',
1771
-            'price_type_selector'   => $default && empty($price)
1772
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1773
-                : $this->_get_price_type_selector(
1774
-                    $ticket_row,
1775
-                    $price_row,
1776
-                    $price,
1777
-                    $default,
1778
-                    $send_disabled
1779
-                ),
1780
-            'PRC_ID'                => $default && empty($price)
1781
-                ? 0
1782
-                : $price->ID(),
1783
-            'PRC_is_default'        => $default && empty($price)
1784
-                ? 0
1785
-                : $price->get('PRC_is_default'),
1786
-            'PRC_name'              => $default && empty($price)
1787
-                ? ''
1788
-                : $price->get('PRC_name'),
1789
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1790
-            'show_plus_or_minus'    => $default && empty($price)
1791
-                ? ''
1792
-                : ' style="display:none;"',
1793
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1794
-                ? ' style="display:none;"'
1795
-                : '',
1796
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1797
-                ? ' style="display:none;"'
1798
-                : '',
1799
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1800
-                ? ' style="display:none"'
1801
-                : '',
1802
-            'PRC_amount'            => $default && empty($price)
1803
-                ? 0
1804
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1805
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1806
-                ? ' style="display:none;"'
1807
-                : '',
1808
-            'show_trash_icon'       => $show_trash
1809
-                ? ''
1810
-                : ' style="display:none;"',
1811
-            'show_create_button'    => $show_create
1812
-                ? ''
1813
-                : ' style="display:none;"',
1814
-            'PRC_desc'              => $default && empty($price)
1815
-                ? ''
1816
-                : $price->get('PRC_desc'),
1817
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1818
-        );
1819
-        $template_args = apply_filters(
1820
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1821
-            $template_args,
1822
-            $ticket_row,
1823
-            $price_row,
1824
-            $price,
1825
-            $default,
1826
-            $ticket,
1827
-            $show_trash,
1828
-            $show_create,
1829
-            $this->_is_creating_event
1830
-        );
1831
-        return EEH_Template::display_template(
1832
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1833
-            $template_args,
1834
-            true
1835
-        );
1836
-    }
1735
+	/**
1736
+	 * @param int            $ticket_row
1737
+	 * @param int            $price_row
1738
+	 * @param EE_Price|null  $price
1739
+	 * @param bool           $default
1740
+	 * @param EE_Ticket|null $ticket
1741
+	 * @param bool           $show_trash
1742
+	 * @param bool           $show_create
1743
+	 * @return mixed
1744
+	 * @throws InvalidArgumentException
1745
+	 * @throws InvalidInterfaceException
1746
+	 * @throws InvalidDataTypeException
1747
+	 * @throws DomainException
1748
+	 * @throws EE_Error
1749
+	 * @throws ReflectionException
1750
+	 */
1751
+	protected function _get_ticket_price_row(
1752
+		$ticket_row,
1753
+		$price_row,
1754
+		$price,
1755
+		$default,
1756
+		$ticket,
1757
+		$show_trash = true,
1758
+		$show_create = true
1759
+	) {
1760
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1761
+		$template_args = array(
1762
+			'tkt_row'               => $default && empty($ticket)
1763
+				? 'TICKETNUM'
1764
+				: $ticket_row,
1765
+			'PRC_order'             => $default && empty($price)
1766
+				? 'PRICENUM'
1767
+				: $price_row,
1768
+			'edit_prices_name'      => $default && empty($price)
1769
+				? 'PRICENAMEATTR'
1770
+				: 'edit_prices',
1771
+			'price_type_selector'   => $default && empty($price)
1772
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1773
+				: $this->_get_price_type_selector(
1774
+					$ticket_row,
1775
+					$price_row,
1776
+					$price,
1777
+					$default,
1778
+					$send_disabled
1779
+				),
1780
+			'PRC_ID'                => $default && empty($price)
1781
+				? 0
1782
+				: $price->ID(),
1783
+			'PRC_is_default'        => $default && empty($price)
1784
+				? 0
1785
+				: $price->get('PRC_is_default'),
1786
+			'PRC_name'              => $default && empty($price)
1787
+				? ''
1788
+				: $price->get('PRC_name'),
1789
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1790
+			'show_plus_or_minus'    => $default && empty($price)
1791
+				? ''
1792
+				: ' style="display:none;"',
1793
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1794
+				? ' style="display:none;"'
1795
+				: '',
1796
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1797
+				? ' style="display:none;"'
1798
+				: '',
1799
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1800
+				? ' style="display:none"'
1801
+				: '',
1802
+			'PRC_amount'            => $default && empty($price)
1803
+				? 0
1804
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1805
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1806
+				? ' style="display:none;"'
1807
+				: '',
1808
+			'show_trash_icon'       => $show_trash
1809
+				? ''
1810
+				: ' style="display:none;"',
1811
+			'show_create_button'    => $show_create
1812
+				? ''
1813
+				: ' style="display:none;"',
1814
+			'PRC_desc'              => $default && empty($price)
1815
+				? ''
1816
+				: $price->get('PRC_desc'),
1817
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1818
+		);
1819
+		$template_args = apply_filters(
1820
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1821
+			$template_args,
1822
+			$ticket_row,
1823
+			$price_row,
1824
+			$price,
1825
+			$default,
1826
+			$ticket,
1827
+			$show_trash,
1828
+			$show_create,
1829
+			$this->_is_creating_event
1830
+		);
1831
+		return EEH_Template::display_template(
1832
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1833
+			$template_args,
1834
+			true
1835
+		);
1836
+	}
1837 1837
 
1838 1838
 
1839
-    /**
1840
-     * @param int      $ticket_row
1841
-     * @param int      $price_row
1842
-     * @param EE_Price $price
1843
-     * @param bool     $default
1844
-     * @param bool     $disabled
1845
-     * @return mixed
1846
-     * @throws ReflectionException
1847
-     * @throws InvalidArgumentException
1848
-     * @throws InvalidInterfaceException
1849
-     * @throws InvalidDataTypeException
1850
-     * @throws DomainException
1851
-     * @throws EE_Error
1852
-     */
1853
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1854
-    {
1855
-        if ($price->is_base_price()) {
1856
-            return $this->_get_base_price_template(
1857
-                $ticket_row,
1858
-                $price_row,
1859
-                $price,
1860
-                $default
1861
-            );
1862
-        }
1863
-        return $this->_get_price_modifier_template(
1864
-            $ticket_row,
1865
-            $price_row,
1866
-            $price,
1867
-            $default,
1868
-            $disabled
1869
-        );
1870
-    }
1839
+	/**
1840
+	 * @param int      $ticket_row
1841
+	 * @param int      $price_row
1842
+	 * @param EE_Price $price
1843
+	 * @param bool     $default
1844
+	 * @param bool     $disabled
1845
+	 * @return mixed
1846
+	 * @throws ReflectionException
1847
+	 * @throws InvalidArgumentException
1848
+	 * @throws InvalidInterfaceException
1849
+	 * @throws InvalidDataTypeException
1850
+	 * @throws DomainException
1851
+	 * @throws EE_Error
1852
+	 */
1853
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1854
+	{
1855
+		if ($price->is_base_price()) {
1856
+			return $this->_get_base_price_template(
1857
+				$ticket_row,
1858
+				$price_row,
1859
+				$price,
1860
+				$default
1861
+			);
1862
+		}
1863
+		return $this->_get_price_modifier_template(
1864
+			$ticket_row,
1865
+			$price_row,
1866
+			$price,
1867
+			$default,
1868
+			$disabled
1869
+		);
1870
+	}
1871 1871
 
1872 1872
 
1873
-    /**
1874
-     * @param int      $ticket_row
1875
-     * @param int      $price_row
1876
-     * @param EE_Price $price
1877
-     * @param bool     $default
1878
-     * @return mixed
1879
-     * @throws DomainException
1880
-     * @throws EE_Error
1881
-     */
1882
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1883
-    {
1884
-        $template_args = array(
1885
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1886
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1887
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1888
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1889
-            'price_selected_operator'   => '+',
1890
-            'price_selected_is_percent' => 0,
1891
-        );
1892
-        $template_args = apply_filters(
1893
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1894
-            $template_args,
1895
-            $ticket_row,
1896
-            $price_row,
1897
-            $price,
1898
-            $default,
1899
-            $this->_is_creating_event
1900
-        );
1901
-        return EEH_Template::display_template(
1902
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1903
-            $template_args,
1904
-            true
1905
-        );
1906
-    }
1873
+	/**
1874
+	 * @param int      $ticket_row
1875
+	 * @param int      $price_row
1876
+	 * @param EE_Price $price
1877
+	 * @param bool     $default
1878
+	 * @return mixed
1879
+	 * @throws DomainException
1880
+	 * @throws EE_Error
1881
+	 */
1882
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1883
+	{
1884
+		$template_args = array(
1885
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1886
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1887
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1888
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1889
+			'price_selected_operator'   => '+',
1890
+			'price_selected_is_percent' => 0,
1891
+		);
1892
+		$template_args = apply_filters(
1893
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1894
+			$template_args,
1895
+			$ticket_row,
1896
+			$price_row,
1897
+			$price,
1898
+			$default,
1899
+			$this->_is_creating_event
1900
+		);
1901
+		return EEH_Template::display_template(
1902
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1903
+			$template_args,
1904
+			true
1905
+		);
1906
+	}
1907 1907
 
1908 1908
 
1909
-    /**
1910
-     * @param int      $ticket_row
1911
-     * @param int      $price_row
1912
-     * @param EE_Price $price
1913
-     * @param bool     $default
1914
-     * @param bool     $disabled
1915
-     * @return mixed
1916
-     * @throws ReflectionException
1917
-     * @throws InvalidArgumentException
1918
-     * @throws InvalidInterfaceException
1919
-     * @throws InvalidDataTypeException
1920
-     * @throws DomainException
1921
-     * @throws EE_Error
1922
-     */
1923
-    protected function _get_price_modifier_template(
1924
-        $ticket_row,
1925
-        $price_row,
1926
-        $price,
1927
-        $default,
1928
-        $disabled = false
1929
-    ) {
1930
-        $select_name = $default && ! $price instanceof EE_Price
1931
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1932
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1933
-        /** @var EEM_Price_Type $price_type_model */
1934
-        $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1935
-        $price_types = $price_type_model->get_all(array(
1936
-            array(
1937
-                'OR' => array(
1938
-                    'PBT_ID'  => '2',
1939
-                    'PBT_ID*' => '3',
1940
-                ),
1941
-            ),
1942
-        ));
1943
-        $all_price_types = $default && ! $price instanceof EE_Price
1944
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1945
-            : array();
1946
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1947
-        $price_option_spans = '';
1948
-        // setup price types for selector
1949
-        foreach ($price_types as $price_type) {
1950
-            if (! $price_type instanceof EE_Price_Type) {
1951
-                continue;
1952
-            }
1953
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1954
-            // while we're in the loop let's setup the option spans used by js
1955
-            $span_args = array(
1956
-                'PRT_ID'         => $price_type->ID(),
1957
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1958
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1959
-            );
1960
-            $price_option_spans .= EEH_Template::display_template(
1961
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1962
-                $span_args,
1963
-                true
1964
-            );
1965
-        }
1966
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1967
-            : $select_name;
1968
-        $select_input = new EE_Select_Input(
1969
-            $all_price_types,
1970
-            array(
1971
-                'default'               => $selected_price_type_id,
1972
-                'html_name'             => $select_name,
1973
-                'html_class'            => 'edit-price-PRT_ID',
1974
-                'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1975
-            )
1976
-        );
1977
-        $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1978
-        $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1979
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1980
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1981
-        $template_args = array(
1982
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1983
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1984
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1985
-            'main_name'                 => $select_name,
1986
-            'selected_price_type_id'    => $selected_price_type_id,
1987
-            'price_option_spans'        => $price_option_spans,
1988
-            'price_selected_operator'   => $price_selected_operator,
1989
-            'price_selected_is_percent' => $price_selected_is_percent,
1990
-            'disabled'                  => $disabled,
1991
-        );
1992
-        $template_args = apply_filters(
1993
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1994
-            $template_args,
1995
-            $ticket_row,
1996
-            $price_row,
1997
-            $price,
1998
-            $default,
1999
-            $disabled,
2000
-            $this->_is_creating_event
2001
-        );
2002
-        return EEH_Template::display_template(
2003
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2004
-            $template_args,
2005
-            true
2006
-        );
2007
-    }
1909
+	/**
1910
+	 * @param int      $ticket_row
1911
+	 * @param int      $price_row
1912
+	 * @param EE_Price $price
1913
+	 * @param bool     $default
1914
+	 * @param bool     $disabled
1915
+	 * @return mixed
1916
+	 * @throws ReflectionException
1917
+	 * @throws InvalidArgumentException
1918
+	 * @throws InvalidInterfaceException
1919
+	 * @throws InvalidDataTypeException
1920
+	 * @throws DomainException
1921
+	 * @throws EE_Error
1922
+	 */
1923
+	protected function _get_price_modifier_template(
1924
+		$ticket_row,
1925
+		$price_row,
1926
+		$price,
1927
+		$default,
1928
+		$disabled = false
1929
+	) {
1930
+		$select_name = $default && ! $price instanceof EE_Price
1931
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1932
+			: 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1933
+		/** @var EEM_Price_Type $price_type_model */
1934
+		$price_type_model = EE_Registry::instance()->load_model('Price_Type');
1935
+		$price_types = $price_type_model->get_all(array(
1936
+			array(
1937
+				'OR' => array(
1938
+					'PBT_ID'  => '2',
1939
+					'PBT_ID*' => '3',
1940
+				),
1941
+			),
1942
+		));
1943
+		$all_price_types = $default && ! $price instanceof EE_Price
1944
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1945
+			: array();
1946
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1947
+		$price_option_spans = '';
1948
+		// setup price types for selector
1949
+		foreach ($price_types as $price_type) {
1950
+			if (! $price_type instanceof EE_Price_Type) {
1951
+				continue;
1952
+			}
1953
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1954
+			// while we're in the loop let's setup the option spans used by js
1955
+			$span_args = array(
1956
+				'PRT_ID'         => $price_type->ID(),
1957
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1958
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1959
+			);
1960
+			$price_option_spans .= EEH_Template::display_template(
1961
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1962
+				$span_args,
1963
+				true
1964
+			);
1965
+		}
1966
+		$select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1967
+			: $select_name;
1968
+		$select_input = new EE_Select_Input(
1969
+			$all_price_types,
1970
+			array(
1971
+				'default'               => $selected_price_type_id,
1972
+				'html_name'             => $select_name,
1973
+				'html_class'            => 'edit-price-PRT_ID',
1974
+				'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1975
+			)
1976
+		);
1977
+		$price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1978
+		$price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1979
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1980
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1981
+		$template_args = array(
1982
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1983
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1984
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1985
+			'main_name'                 => $select_name,
1986
+			'selected_price_type_id'    => $selected_price_type_id,
1987
+			'price_option_spans'        => $price_option_spans,
1988
+			'price_selected_operator'   => $price_selected_operator,
1989
+			'price_selected_is_percent' => $price_selected_is_percent,
1990
+			'disabled'                  => $disabled,
1991
+		);
1992
+		$template_args = apply_filters(
1993
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1994
+			$template_args,
1995
+			$ticket_row,
1996
+			$price_row,
1997
+			$price,
1998
+			$default,
1999
+			$disabled,
2000
+			$this->_is_creating_event
2001
+		);
2002
+		return EEH_Template::display_template(
2003
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2004
+			$template_args,
2005
+			true
2006
+		);
2007
+	}
2008 2008
 
2009 2009
 
2010
-    /**
2011
-     * @param int              $datetime_row
2012
-     * @param int              $ticket_row
2013
-     * @param EE_Datetime|null $datetime
2014
-     * @param EE_Ticket|null   $ticket
2015
-     * @param array            $ticket_datetimes
2016
-     * @param bool             $default
2017
-     * @return mixed
2018
-     * @throws DomainException
2019
-     * @throws EE_Error
2020
-     */
2021
-    protected function _get_ticket_datetime_list_item(
2022
-        $datetime_row,
2023
-        $ticket_row,
2024
-        $datetime,
2025
-        $ticket,
2026
-        $ticket_datetimes = array(),
2027
-        $default
2028
-    ) {
2029
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2030
-            ? $ticket_datetimes[ $ticket->ID() ]
2031
-            : array();
2032
-        $template_args = array(
2033
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2034
-                ? 'DTTNUM'
2035
-                : $datetime_row,
2036
-            'tkt_row'                  => $default
2037
-                ? 'TICKETNUM'
2038
-                : $ticket_row,
2039
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2040
-                ? ' ticket-selected'
2041
-                : '',
2042
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2043
-                ? ' checked="checked"'
2044
-                : '',
2045
-            'DTT_name'                 => $default && empty($datetime)
2046
-                ? 'DTTNAME'
2047
-                : $datetime->get_dtt_display_name(true),
2048
-            'tkt_status_class'         => '',
2049
-        );
2050
-        $template_args = apply_filters(
2051
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2052
-            $template_args,
2053
-            $datetime_row,
2054
-            $ticket_row,
2055
-            $datetime,
2056
-            $ticket,
2057
-            $ticket_datetimes,
2058
-            $default,
2059
-            $this->_is_creating_event
2060
-        );
2061
-        return EEH_Template::display_template(
2062
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2063
-            $template_args,
2064
-            true
2065
-        );
2066
-    }
2010
+	/**
2011
+	 * @param int              $datetime_row
2012
+	 * @param int              $ticket_row
2013
+	 * @param EE_Datetime|null $datetime
2014
+	 * @param EE_Ticket|null   $ticket
2015
+	 * @param array            $ticket_datetimes
2016
+	 * @param bool             $default
2017
+	 * @return mixed
2018
+	 * @throws DomainException
2019
+	 * @throws EE_Error
2020
+	 */
2021
+	protected function _get_ticket_datetime_list_item(
2022
+		$datetime_row,
2023
+		$ticket_row,
2024
+		$datetime,
2025
+		$ticket,
2026
+		$ticket_datetimes = array(),
2027
+		$default
2028
+	) {
2029
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2030
+			? $ticket_datetimes[ $ticket->ID() ]
2031
+			: array();
2032
+		$template_args = array(
2033
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2034
+				? 'DTTNUM'
2035
+				: $datetime_row,
2036
+			'tkt_row'                  => $default
2037
+				? 'TICKETNUM'
2038
+				: $ticket_row,
2039
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2040
+				? ' ticket-selected'
2041
+				: '',
2042
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2043
+				? ' checked="checked"'
2044
+				: '',
2045
+			'DTT_name'                 => $default && empty($datetime)
2046
+				? 'DTTNAME'
2047
+				: $datetime->get_dtt_display_name(true),
2048
+			'tkt_status_class'         => '',
2049
+		);
2050
+		$template_args = apply_filters(
2051
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2052
+			$template_args,
2053
+			$datetime_row,
2054
+			$ticket_row,
2055
+			$datetime,
2056
+			$ticket,
2057
+			$ticket_datetimes,
2058
+			$default,
2059
+			$this->_is_creating_event
2060
+		);
2061
+		return EEH_Template::display_template(
2062
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2063
+			$template_args,
2064
+			true
2065
+		);
2066
+	}
2067 2067
 
2068 2068
 
2069
-    /**
2070
-     * @param array $all_datetimes
2071
-     * @param array $all_tickets
2072
-     * @return mixed
2073
-     * @throws ReflectionException
2074
-     * @throws InvalidArgumentException
2075
-     * @throws InvalidInterfaceException
2076
-     * @throws InvalidDataTypeException
2077
-     * @throws DomainException
2078
-     * @throws EE_Error
2079
-     */
2080
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2081
-    {
2082
-        $template_args = array(
2083
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2084
-                'DTTNUM',
2085
-                null,
2086
-                true,
2087
-                $all_datetimes
2088
-            ),
2089
-            'default_ticket_row'                       => $this->_get_ticket_row(
2090
-                'TICKETNUM',
2091
-                null,
2092
-                array(),
2093
-                array(),
2094
-                true
2095
-            ),
2096
-            'default_price_row'                        => $this->_get_ticket_price_row(
2097
-                'TICKETNUM',
2098
-                'PRICENUM',
2099
-                null,
2100
-                true,
2101
-                null
2102
-            ),
2103
-            'default_price_rows'                       => '',
2104
-            'default_base_price_amount'                => 0,
2105
-            'default_base_price_name'                  => '',
2106
-            'default_base_price_description'           => '',
2107
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2108
-                'TICKETNUM',
2109
-                'PRICENUM',
2110
-                null,
2111
-                true
2112
-            ),
2113
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2114
-                'DTTNUM',
2115
-                null,
2116
-                array(),
2117
-                array(),
2118
-                true
2119
-            ),
2120
-            'existing_available_datetime_tickets_list' => '',
2121
-            'existing_available_ticket_datetimes_list' => '',
2122
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2123
-                'DTTNUM',
2124
-                'TICKETNUM',
2125
-                null,
2126
-                null,
2127
-                array(),
2128
-                true
2129
-            ),
2130
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2131
-                'DTTNUM',
2132
-                'TICKETNUM',
2133
-                null,
2134
-                null,
2135
-                array(),
2136
-                true
2137
-            ),
2138
-        );
2139
-        $ticket_row = 1;
2140
-        foreach ($all_tickets as $ticket) {
2141
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2142
-                'DTTNUM',
2143
-                $ticket_row,
2144
-                null,
2145
-                $ticket,
2146
-                array(),
2147
-                true
2148
-            );
2149
-            $ticket_row++;
2150
-        }
2151
-        $datetime_row = 1;
2152
-        foreach ($all_datetimes as $datetime) {
2153
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2154
-                $datetime_row,
2155
-                'TICKETNUM',
2156
-                $datetime,
2157
-                null,
2158
-                array(),
2159
-                true
2160
-            );
2161
-            $datetime_row++;
2162
-        }
2163
-        /** @var EEM_Price $price_model */
2164
-        $price_model = EE_Registry::instance()->load_model('Price');
2165
-        $default_prices = $price_model->get_all_default_prices();
2166
-        $price_row = 1;
2167
-        foreach ($default_prices as $price) {
2168
-            if (! $price instanceof EE_Price) {
2169
-                continue;
2170
-            }
2171
-            if ($price->is_base_price()) {
2172
-                $template_args['default_base_price_amount'] = $price->get_pretty(
2173
-                    'PRC_amount',
2174
-                    'localized_float'
2175
-                );
2176
-                $template_args['default_base_price_name'] = $price->get('PRC_name');
2177
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2178
-                $price_row++;
2179
-                continue;
2180
-            }
2181
-            $show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2182
-                             || count($default_prices) === 1);
2183
-            $show_create = ! (count($default_prices) > 1
2184
-                              && count($default_prices)
2185
-                                 !== $price_row);
2186
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2187
-                'TICKETNUM',
2188
-                $price_row,
2189
-                $price,
2190
-                true,
2191
-                null,
2192
-                $show_trash,
2193
-                $show_create
2194
-            );
2195
-            $price_row++;
2196
-        }
2197
-        $template_args = apply_filters(
2198
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2199
-            $template_args,
2200
-            $all_datetimes,
2201
-            $all_tickets,
2202
-            $this->_is_creating_event
2203
-        );
2204
-        return EEH_Template::display_template(
2205
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2206
-            $template_args,
2207
-            true
2208
-        );
2209
-    }
2069
+	/**
2070
+	 * @param array $all_datetimes
2071
+	 * @param array $all_tickets
2072
+	 * @return mixed
2073
+	 * @throws ReflectionException
2074
+	 * @throws InvalidArgumentException
2075
+	 * @throws InvalidInterfaceException
2076
+	 * @throws InvalidDataTypeException
2077
+	 * @throws DomainException
2078
+	 * @throws EE_Error
2079
+	 */
2080
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2081
+	{
2082
+		$template_args = array(
2083
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2084
+				'DTTNUM',
2085
+				null,
2086
+				true,
2087
+				$all_datetimes
2088
+			),
2089
+			'default_ticket_row'                       => $this->_get_ticket_row(
2090
+				'TICKETNUM',
2091
+				null,
2092
+				array(),
2093
+				array(),
2094
+				true
2095
+			),
2096
+			'default_price_row'                        => $this->_get_ticket_price_row(
2097
+				'TICKETNUM',
2098
+				'PRICENUM',
2099
+				null,
2100
+				true,
2101
+				null
2102
+			),
2103
+			'default_price_rows'                       => '',
2104
+			'default_base_price_amount'                => 0,
2105
+			'default_base_price_name'                  => '',
2106
+			'default_base_price_description'           => '',
2107
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2108
+				'TICKETNUM',
2109
+				'PRICENUM',
2110
+				null,
2111
+				true
2112
+			),
2113
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2114
+				'DTTNUM',
2115
+				null,
2116
+				array(),
2117
+				array(),
2118
+				true
2119
+			),
2120
+			'existing_available_datetime_tickets_list' => '',
2121
+			'existing_available_ticket_datetimes_list' => '',
2122
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2123
+				'DTTNUM',
2124
+				'TICKETNUM',
2125
+				null,
2126
+				null,
2127
+				array(),
2128
+				true
2129
+			),
2130
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2131
+				'DTTNUM',
2132
+				'TICKETNUM',
2133
+				null,
2134
+				null,
2135
+				array(),
2136
+				true
2137
+			),
2138
+		);
2139
+		$ticket_row = 1;
2140
+		foreach ($all_tickets as $ticket) {
2141
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2142
+				'DTTNUM',
2143
+				$ticket_row,
2144
+				null,
2145
+				$ticket,
2146
+				array(),
2147
+				true
2148
+			);
2149
+			$ticket_row++;
2150
+		}
2151
+		$datetime_row = 1;
2152
+		foreach ($all_datetimes as $datetime) {
2153
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2154
+				$datetime_row,
2155
+				'TICKETNUM',
2156
+				$datetime,
2157
+				null,
2158
+				array(),
2159
+				true
2160
+			);
2161
+			$datetime_row++;
2162
+		}
2163
+		/** @var EEM_Price $price_model */
2164
+		$price_model = EE_Registry::instance()->load_model('Price');
2165
+		$default_prices = $price_model->get_all_default_prices();
2166
+		$price_row = 1;
2167
+		foreach ($default_prices as $price) {
2168
+			if (! $price instanceof EE_Price) {
2169
+				continue;
2170
+			}
2171
+			if ($price->is_base_price()) {
2172
+				$template_args['default_base_price_amount'] = $price->get_pretty(
2173
+					'PRC_amount',
2174
+					'localized_float'
2175
+				);
2176
+				$template_args['default_base_price_name'] = $price->get('PRC_name');
2177
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2178
+				$price_row++;
2179
+				continue;
2180
+			}
2181
+			$show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2182
+							 || count($default_prices) === 1);
2183
+			$show_create = ! (count($default_prices) > 1
2184
+							  && count($default_prices)
2185
+								 !== $price_row);
2186
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2187
+				'TICKETNUM',
2188
+				$price_row,
2189
+				$price,
2190
+				true,
2191
+				null,
2192
+				$show_trash,
2193
+				$show_create
2194
+			);
2195
+			$price_row++;
2196
+		}
2197
+		$template_args = apply_filters(
2198
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2199
+			$template_args,
2200
+			$all_datetimes,
2201
+			$all_tickets,
2202
+			$this->_is_creating_event
2203
+		);
2204
+		return EEH_Template::display_template(
2205
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2206
+			$template_args,
2207
+			true
2208
+		);
2209
+	}
2210 2210
 }
Please login to merge, or discard this patch.
core/domain/Domain.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -15,66 +15,66 @@
 block discarded – undo
15 15
  */
16 16
 class Domain extends DomainBase implements CaffeinatedInterface
17 17
 {
18
-    /**
19
-     * URL path component used to denote an API request
20
-     */
21
-    const API_NAMESPACE = 'ee/v';
18
+	/**
19
+	 * URL path component used to denote an API request
20
+	 */
21
+	const API_NAMESPACE = 'ee/v';
22 22
 
23
-    /**
24
-     * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
25
-     * Page ui.
26
-     */
27
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
28
-        = 'manual_registration_status_change_from_registration_admin';
23
+	/**
24
+	 * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
25
+	 * Page ui.
26
+	 */
27
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
28
+		= 'manual_registration_status_change_from_registration_admin';
29 29
 
30
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
31
-        = 'manual_registration_status_change_from_registration_admin_and_notify';
30
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
31
+		= 'manual_registration_status_change_from_registration_admin_and_notify';
32 32
 
33 33
 
34
-    /**
35
-     * Whether or not EE core is the full premium version.
36
-     * @since 4.9.59.p
37
-     * @var bool
38
-     */
39
-    private $caffeinated;
34
+	/**
35
+	 * Whether or not EE core is the full premium version.
36
+	 * @since 4.9.59.p
37
+	 * @var bool
38
+	 */
39
+	private $caffeinated;
40 40
 
41 41
 
42
-    public function __construct(FilePath $plugin_file, Version $version)
43
-    {
44
-        parent::__construct($plugin_file, $version);
45
-        $this->setCaffeinated();
46
-    }
42
+	public function __construct(FilePath $plugin_file, Version $version)
43
+	{
44
+		parent::__construct($plugin_file, $version);
45
+		$this->setCaffeinated();
46
+	}
47 47
 
48
-    /**
49
-     * Whether or not EE core is the full premium version.
50
-     * @since 4.9.59.p
51
-     * @return bool
52
-     */
53
-    public function isCaffeinated()
54
-    {
55
-        return $this->caffeinated;
56
-    }
48
+	/**
49
+	 * Whether or not EE core is the full premium version.
50
+	 * @since 4.9.59.p
51
+	 * @return bool
52
+	 */
53
+	public function isCaffeinated()
54
+	{
55
+		return $this->caffeinated;
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * Setter for $is_caffeinated property.
61
-     * @since 4.9.59.p
62
-     */
63
-    private function setCaffeinated()
64
-    {
65
-        $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
66
-            && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
67
-    }
59
+	/**
60
+	 * Setter for $is_caffeinated property.
61
+	 * @since 4.9.59.p
62
+	 */
63
+	private function setCaffeinated()
64
+	{
65
+		$this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
66
+			&& is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * This should be used everywhere the Event Espresso brand name is referenced in public facing interfaces
72
-     * to allow for filtering the brand.
73
-     *
74
-     * @return string
75
-     */
76
-    public static function brandName()
77
-    {
78
-        return (string) apply_filters('FHEE__EventEspresso_core_domain_Domain__brandName', 'Event Espresso');
79
-    }
70
+	/**
71
+	 * This should be used everywhere the Event Espresso brand name is referenced in public facing interfaces
72
+	 * to allow for filtering the brand.
73
+	 *
74
+	 * @return string
75
+	 */
76
+	public static function brandName()
77
+	{
78
+		return (string) apply_filters('FHEE__EventEspresso_core_domain_Domain__brandName', 'Event Espresso');
79
+	}
80 80
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.2.rc.083');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.2.rc.083');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.