Completed
Branch BUG/escape-localized-variables (bce518)
by
unknown
10:32 queued 01:38
created
admin/registrations/list_table/page_header/AttendeeFilterHeader.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,13 +59,13 @@
 block discarded – undo
59 59
                         'event_espresso'
60 60
                     ),
61 61
                     '<h3 style="line-height:1.5em;">',
62
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
62
+                    '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
63 63
                         array(
64 64
                             'action' => 'edit_attendee',
65 65
                             'post'   => $ATT_ID,
66 66
                         ),
67 67
                         REG_ADMIN_URL
68
-                    ) . '">' . $attendee->full_name() . '</a>',
68
+                    ).'">'.$attendee->full_name().'</a>',
69 69
                     '</h3>'
70 70
                 );
71 71
             }
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -20,56 +20,56 @@
 block discarded – undo
20 20
 class AttendeeFilterHeader extends AdminPageHeaderDecorator
21 21
 {
22 22
 
23
-    /**
24
-     * @var EEM_Attendee $attendee_model
25
-     */
26
-    private $attendee_model;
23
+	/**
24
+	 * @var EEM_Attendee $attendee_model
25
+	 */
26
+	private $attendee_model;
27 27
 
28 28
 
29
-    /**
30
-     * AttendeeFilterHeader constructor.
31
-     *
32
-     * @param RequestInterface $request
33
-     * @param EEM_Attendee     $attendee_model
34
-     */
35
-    public function __construct(RequestInterface $request, EEM_Attendee $attendee_model)
36
-    {
37
-        parent::__construct($request);
38
-        $this->attendee_model = $attendee_model;
39
-    }
29
+	/**
30
+	 * AttendeeFilterHeader constructor.
31
+	 *
32
+	 * @param RequestInterface $request
33
+	 * @param EEM_Attendee     $attendee_model
34
+	 */
35
+	public function __construct(RequestInterface $request, EEM_Attendee $attendee_model)
36
+	{
37
+		parent::__construct($request);
38
+		$this->attendee_model = $attendee_model;
39
+	}
40 40
 
41 41
 
42
-    /**
43
-     * @param string $text
44
-     * @return string
45
-     * @throws EE_Error
46
-     * @since $VID:$
47
-     */
48
-    public function getHeaderText($text = '')
49
-    {
50
-        $ATT_ID = $this->request->getRequestParam('ATT_ID');
51
-        $ATT_ID = $this->request->getRequestParam('attendee_id', $ATT_ID);
52
-        $ATT_ID = absint($ATT_ID);
53
-        if ($ATT_ID) {
54
-            $attendee = $this->attendee_model->get_one_by_ID($ATT_ID);
55
-            if ($attendee instanceof EE_Attendee) {
56
-                $text .= sprintf(
57
-                    esc_html__(
58
-                        '%1$s Viewing registrations for %2$s%3$s',
59
-                        'event_espresso'
60
-                    ),
61
-                    '<h3 style="line-height:1.5em;">',
62
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
63
-                        array(
64
-                            'action' => 'edit_attendee',
65
-                            'post'   => $ATT_ID,
66
-                        ),
67
-                        REG_ADMIN_URL
68
-                    ) . '">' . $attendee->full_name() . '</a>',
69
-                    '</h3>'
70
-                );
71
-            }
72
-        }
73
-        return $text;
74
-    }
42
+	/**
43
+	 * @param string $text
44
+	 * @return string
45
+	 * @throws EE_Error
46
+	 * @since $VID:$
47
+	 */
48
+	public function getHeaderText($text = '')
49
+	{
50
+		$ATT_ID = $this->request->getRequestParam('ATT_ID');
51
+		$ATT_ID = $this->request->getRequestParam('attendee_id', $ATT_ID);
52
+		$ATT_ID = absint($ATT_ID);
53
+		if ($ATT_ID) {
54
+			$attendee = $this->attendee_model->get_one_by_ID($ATT_ID);
55
+			if ($attendee instanceof EE_Attendee) {
56
+				$text .= sprintf(
57
+					esc_html__(
58
+						'%1$s Viewing registrations for %2$s%3$s',
59
+						'event_espresso'
60
+					),
61
+					'<h3 style="line-height:1.5em;">',
62
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
63
+						array(
64
+							'action' => 'edit_attendee',
65
+							'post'   => $ATT_ID,
66
+						),
67
+						REG_ADMIN_URL
68
+					) . '">' . $attendee->full_name() . '</a>',
69
+					'</h3>'
70
+				);
71
+			}
72
+		}
73
+		return $text;
74
+	}
75 75
 }
Please login to merge, or discard this patch.
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.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 patch
Indentation   +2134 added lines, -2134 removed lines patch added patch discarded remove patch
@@ -15,2194 +15,2194 @@
 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()->CAP->current_user_can(
52
-            'ee_read_default_prices',
53
-            'advanced_ticket_datetime_metabox'
54
-        )) {
55
-            return;
56
-        }
57
-        $this->_setup_metaboxes();
58
-        $this->_set_date_time_formats();
59
-        $this->_validate_format_strings();
60
-        $this->_set_scripts_styles();
61
-        // commented out temporarily until logic is implemented in callback
62
-        // add_action(
63
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
64
-        //     array($this, 'autosave_handling')
65
-        // );
66
-        add_filter(
67
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
68
-            array($this, 'caf_updates')
69
-        );
70
-    }
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()->CAP->current_user_can(
52
+			'ee_read_default_prices',
53
+			'advanced_ticket_datetime_metabox'
54
+		)) {
55
+			return;
56
+		}
57
+		$this->_setup_metaboxes();
58
+		$this->_set_date_time_formats();
59
+		$this->_validate_format_strings();
60
+		$this->_set_scripts_styles();
61
+		// commented out temporarily until logic is implemented in callback
62
+		// add_action(
63
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
64
+		//     array($this, 'autosave_handling')
65
+		// );
66
+		add_filter(
67
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
68
+			array($this, 'caf_updates')
69
+		);
70
+	}
71 71
 
72 72
 
73
-    /**
74
-     * @return void
75
-     */
76
-    protected function _setup_metaboxes()
77
-    {
78
-        // if we were going to add our own metaboxes we'd use the below.
79
-        $this->_metaboxes = array(
80
-            0 => array(
81
-                'page_route' => array('edit', 'create_new'),
82
-                'func'       => 'pricing_metabox',
83
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
84
-                'priority'   => 'high',
85
-                'context'    => 'normal',
86
-            ),
87
-        );
88
-        $this->_remove_metaboxes = array(
89
-            0 => array(
90
-                'page_route' => array('edit', 'create_new'),
91
-                'id'         => 'espresso_event_editor_tickets',
92
-                'context'    => 'normal',
93
-            ),
94
-        );
95
-    }
73
+	/**
74
+	 * @return void
75
+	 */
76
+	protected function _setup_metaboxes()
77
+	{
78
+		// if we were going to add our own metaboxes we'd use the below.
79
+		$this->_metaboxes = array(
80
+			0 => array(
81
+				'page_route' => array('edit', 'create_new'),
82
+				'func'       => 'pricing_metabox',
83
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
84
+				'priority'   => 'high',
85
+				'context'    => 'normal',
86
+			),
87
+		);
88
+		$this->_remove_metaboxes = array(
89
+			0 => array(
90
+				'page_route' => array('edit', 'create_new'),
91
+				'id'         => 'espresso_event_editor_tickets',
92
+				'context'    => 'normal',
93
+			),
94
+		);
95
+	}
96 96
 
97 97
 
98
-    /**
99
-     * @return void
100
-     */
101
-    protected function _set_date_time_formats()
102
-    {
103
-        /**
104
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
105
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
106
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
107
-         *
108
-         * @since 4.6.7
109
-         * @var array  Expected an array returned with 'date' and 'time' keys.
110
-         */
111
-        $this->_date_format_strings = apply_filters(
112
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
113
-            array(
114
-                'date' => 'Y-m-d',
115
-                'time' => 'h:i a',
116
-            )
117
-        );
118
-        // validate
119
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
120
-            ? $this->_date_format_strings['date']
121
-            : null;
122
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
123
-            ? $this->_date_format_strings['time']
124
-            : null;
125
-        $this->_date_time_format = $this->_date_format_strings['date']
126
-                                   . ' '
127
-                                   . $this->_date_format_strings['time'];
128
-    }
98
+	/**
99
+	 * @return void
100
+	 */
101
+	protected function _set_date_time_formats()
102
+	{
103
+		/**
104
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
105
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
106
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
107
+		 *
108
+		 * @since 4.6.7
109
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
110
+		 */
111
+		$this->_date_format_strings = apply_filters(
112
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
113
+			array(
114
+				'date' => 'Y-m-d',
115
+				'time' => 'h:i a',
116
+			)
117
+		);
118
+		// validate
119
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
120
+			? $this->_date_format_strings['date']
121
+			: null;
122
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
123
+			? $this->_date_format_strings['time']
124
+			: null;
125
+		$this->_date_time_format = $this->_date_format_strings['date']
126
+								   . ' '
127
+								   . $this->_date_format_strings['time'];
128
+	}
129 129
 
130 130
 
131
-    /**
132
-     * @return void
133
-     */
134
-    protected function _validate_format_strings()
135
-    {
136
-        // validate format strings
137
-        $format_validation = EEH_DTT_Helper::validate_format_string(
138
-            $this->_date_time_format
139
-        );
140
-        if (is_array($format_validation)) {
141
-            $msg = '<p>';
142
-            $msg .= sprintf(
143
-                esc_html__(
144
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
145
-                    'event_espresso'
146
-                ),
147
-                $this->_date_time_format
148
-            );
149
-            $msg .= '</p><ul>';
150
-            foreach ($format_validation as $error) {
151
-                $msg .= '<li>' . $error . '</li>';
152
-            }
153
-            $msg .= '</ul><p>';
154
-            $msg .= sprintf(
155
-                esc_html__(
156
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
157
-                    'event_espresso'
158
-                ),
159
-                '<span style="color:#D54E21;">',
160
-                '</span>'
161
-            );
162
-            $msg .= '</p>';
163
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
164
-            $this->_date_format_strings = array(
165
-                'date' => 'Y-m-d',
166
-                'time' => 'h:i a',
167
-            );
168
-        }
169
-    }
131
+	/**
132
+	 * @return void
133
+	 */
134
+	protected function _validate_format_strings()
135
+	{
136
+		// validate format strings
137
+		$format_validation = EEH_DTT_Helper::validate_format_string(
138
+			$this->_date_time_format
139
+		);
140
+		if (is_array($format_validation)) {
141
+			$msg = '<p>';
142
+			$msg .= sprintf(
143
+				esc_html__(
144
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
145
+					'event_espresso'
146
+				),
147
+				$this->_date_time_format
148
+			);
149
+			$msg .= '</p><ul>';
150
+			foreach ($format_validation as $error) {
151
+				$msg .= '<li>' . $error . '</li>';
152
+			}
153
+			$msg .= '</ul><p>';
154
+			$msg .= sprintf(
155
+				esc_html__(
156
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
157
+					'event_espresso'
158
+				),
159
+				'<span style="color:#D54E21;">',
160
+				'</span>'
161
+			);
162
+			$msg .= '</p>';
163
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
164
+			$this->_date_format_strings = array(
165
+				'date' => 'Y-m-d',
166
+				'time' => 'h:i a',
167
+			);
168
+		}
169
+	}
170 170
 
171 171
 
172
-    /**
173
-     * @return void
174
-     */
175
-    protected function _set_scripts_styles()
176
-    {
177
-        $this->_scripts_styles = array(
178
-            'registers'   => array(
179
-                'ee-tickets-datetimes-css' => array(
180
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
181
-                    'type' => 'css',
182
-                ),
183
-                'ee-dtt-ticket-metabox'    => array(
184
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
185
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
186
-                ),
187
-            ),
188
-            'deregisters' => array(
189
-                'event-editor-css'       => array('type' => 'css'),
190
-                'event-datetime-metabox' => array('type' => 'js'),
191
-            ),
192
-            'enqueues'    => array(
193
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
194
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
195
-            ),
196
-            'localize'    => array(
197
-                'ee-dtt-ticket-metabox' => array(
198
-                    'DTT_TRASH_BLOCK'       => array(
199
-                        'main_warning'            => esc_html__(
200
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
201
-                            'event_espresso'
202
-                        ),
203
-                        'after_warning'           => esc_html__(
204
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
205
-                            'event_espresso'
206
-                        ),
207
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
208
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
209
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
210
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
211
-                        'single_warning_from_tkt' => esc_html__(
212
-                            '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.',
213
-                            'event_espresso'
214
-                        ),
215
-                        'single_warning_from_dtt' => esc_html__(
216
-                            '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.',
217
-                            'event_espresso'
218
-                        ),
219
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
220
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
221
-                    ),
222
-                    'DTT_ERROR_MSG'         => array(
223
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
224
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
225
-                                            . '<button class="button-secondary ee-modal-cancel">'
226
-                                            . esc_html__('Dismiss', 'event_espresso')
227
-                                            . '</button></div>',
228
-                    ),
229
-                    'DTT_OVERSELL_WARNING'  => array(
230
-                        'datetime_ticket' => esc_html__(
231
-                            '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.',
232
-                            'event_espresso'
233
-                        ),
234
-                        'ticket_datetime' => esc_html__(
235
-                            '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.',
236
-                            'event_espresso'
237
-                        ),
238
-                    ),
239
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
240
-                        $this->_date_format_strings['date'],
241
-                        $this->_date_format_strings['time']
242
-                    ),
243
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
244
-                ),
245
-            ),
246
-        );
247
-    }
172
+	/**
173
+	 * @return void
174
+	 */
175
+	protected function _set_scripts_styles()
176
+	{
177
+		$this->_scripts_styles = array(
178
+			'registers'   => array(
179
+				'ee-tickets-datetimes-css' => array(
180
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
181
+					'type' => 'css',
182
+				),
183
+				'ee-dtt-ticket-metabox'    => array(
184
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
185
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
186
+				),
187
+			),
188
+			'deregisters' => array(
189
+				'event-editor-css'       => array('type' => 'css'),
190
+				'event-datetime-metabox' => array('type' => 'js'),
191
+			),
192
+			'enqueues'    => array(
193
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
194
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
195
+			),
196
+			'localize'    => array(
197
+				'ee-dtt-ticket-metabox' => array(
198
+					'DTT_TRASH_BLOCK'       => array(
199
+						'main_warning'            => esc_html__(
200
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
201
+							'event_espresso'
202
+						),
203
+						'after_warning'           => esc_html__(
204
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
205
+							'event_espresso'
206
+						),
207
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
208
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
209
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
210
+													 . esc_html__('Close', 'event_espresso') . '</button>',
211
+						'single_warning_from_tkt' => esc_html__(
212
+							'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.',
213
+							'event_espresso'
214
+						),
215
+						'single_warning_from_dtt' => esc_html__(
216
+							'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.',
217
+							'event_espresso'
218
+						),
219
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
220
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
221
+					),
222
+					'DTT_ERROR_MSG'         => array(
223
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
224
+						'dismiss_button' => '<div class="save-cancel-button-container">'
225
+											. '<button class="button-secondary ee-modal-cancel">'
226
+											. esc_html__('Dismiss', 'event_espresso')
227
+											. '</button></div>',
228
+					),
229
+					'DTT_OVERSELL_WARNING'  => array(
230
+						'datetime_ticket' => esc_html__(
231
+							'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.',
232
+							'event_espresso'
233
+						),
234
+						'ticket_datetime' => esc_html__(
235
+							'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.',
236
+							'event_espresso'
237
+						),
238
+					),
239
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
240
+						$this->_date_format_strings['date'],
241
+						$this->_date_format_strings['time']
242
+					),
243
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
244
+				),
245
+			),
246
+		);
247
+	}
248 248
 
249 249
 
250
-    /**
251
-     * @param array $update_callbacks
252
-     * @return array
253
-     */
254
-    public function caf_updates(array $update_callbacks)
255
-    {
256
-        foreach ($update_callbacks as $key => $callback) {
257
-            if ($callback[1] === '_default_tickets_update') {
258
-                unset($update_callbacks[ $key ]);
259
-            }
260
-        }
261
-        $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
262
-        return $update_callbacks;
263
-    }
250
+	/**
251
+	 * @param array $update_callbacks
252
+	 * @return array
253
+	 */
254
+	public function caf_updates(array $update_callbacks)
255
+	{
256
+		foreach ($update_callbacks as $key => $callback) {
257
+			if ($callback[1] === '_default_tickets_update') {
258
+				unset($update_callbacks[ $key ]);
259
+			}
260
+		}
261
+		$update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
262
+		return $update_callbacks;
263
+	}
264 264
 
265 265
 
266
-    /**
267
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
268
-     *
269
-     * @param  EE_Event $event The Event object we're attaching data to
270
-     * @param  array    $data  The request data from the form
271
-     * @throws ReflectionException
272
-     * @throws Exception
273
-     * @throws InvalidInterfaceException
274
-     * @throws InvalidDataTypeException
275
-     * @throws EE_Error
276
-     * @throws InvalidArgumentException
277
-     */
278
-    public function datetime_and_tickets_caf_update($event, $data)
279
-    {
280
-        // first we need to start with datetimes cause they are the "root" items attached to events.
281
-        $saved_datetimes = $this->_update_datetimes($event, $data);
282
-        // next tackle the tickets (and prices?)
283
-        $this->_update_tickets($event, $saved_datetimes, $data);
284
-    }
266
+	/**
267
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
268
+	 *
269
+	 * @param  EE_Event $event The Event object we're attaching data to
270
+	 * @param  array    $data  The request data from the form
271
+	 * @throws ReflectionException
272
+	 * @throws Exception
273
+	 * @throws InvalidInterfaceException
274
+	 * @throws InvalidDataTypeException
275
+	 * @throws EE_Error
276
+	 * @throws InvalidArgumentException
277
+	 */
278
+	public function datetime_and_tickets_caf_update($event, $data)
279
+	{
280
+		// first we need to start with datetimes cause they are the "root" items attached to events.
281
+		$saved_datetimes = $this->_update_datetimes($event, $data);
282
+		// next tackle the tickets (and prices?)
283
+		$this->_update_tickets($event, $saved_datetimes, $data);
284
+	}
285 285
 
286 286
 
287
-    /**
288
-     * update event_datetimes
289
-     *
290
-     * @param  EE_Event $event Event being updated
291
-     * @param  array    $data  the request data from the form
292
-     * @return EE_Datetime[]
293
-     * @throws Exception
294
-     * @throws ReflectionException
295
-     * @throws InvalidInterfaceException
296
-     * @throws InvalidDataTypeException
297
-     * @throws InvalidArgumentException
298
-     * @throws EE_Error
299
-     */
300
-    protected function _update_datetimes($event, $data)
301
-    {
302
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
303
-        $saved_dtt_ids = array();
304
-        $saved_dtt_objs = array();
305
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
306
-            throw new InvalidArgumentException(
307
-                esc_html__(
308
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
309
-                    'event_espresso'
310
-                )
311
-            );
312
-        }
313
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
314
-            // trim all values to ensure any excess whitespace is removed.
315
-            $datetime_data = array_map(
316
-                function ($datetime_data) {
317
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
318
-                },
319
-                $datetime_data
320
-            );
321
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
322
-                                            && ! empty($datetime_data['DTT_EVT_end'])
323
-                ? $datetime_data['DTT_EVT_end']
324
-                : $datetime_data['DTT_EVT_start'];
325
-            $datetime_values = array(
326
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
327
-                    ? $datetime_data['DTT_ID']
328
-                    : null,
329
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
330
-                    ? $datetime_data['DTT_name']
331
-                    : '',
332
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
333
-                    ? $datetime_data['DTT_description']
334
-                    : '',
335
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
336
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
337
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
338
-                    ? EE_INF
339
-                    : $datetime_data['DTT_reg_limit'],
340
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
341
-                    ? $row
342
-                    : $datetime_data['DTT_order'],
343
-            );
344
-            // if we have an id then let's get existing object first and then set the new values.
345
-            // Otherwise we instantiate a new object for save.
346
-            if (! empty($datetime_data['DTT_ID'])) {
347
-                $datetime = EE_Registry::instance()
348
-                                       ->load_model('Datetime', array($timezone))
349
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
350
-                // set date and time format according to what is set in this class.
351
-                $datetime->set_date_format($this->_date_format_strings['date']);
352
-                $datetime->set_time_format($this->_date_format_strings['time']);
353
-                foreach ($datetime_values as $field => $value) {
354
-                    $datetime->set($field, $value);
355
-                }
356
-                // make sure the $dtt_id here is saved just in case
357
-                // after the add_relation_to() the autosave replaces it.
358
-                // We need to do this so we dont' TRASH the parent DTT.
359
-                // (save the ID for both key and value to avoid duplications)
360
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
361
-            } else {
362
-                $datetime = EE_Registry::instance()->load_class(
363
-                    'Datetime',
364
-                    array(
365
-                        $datetime_values,
366
-                        $timezone,
367
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
368
-                    ),
369
-                    false,
370
-                    false
371
-                );
372
-                foreach ($datetime_values as $field => $value) {
373
-                    $datetime->set($field, $value);
374
-                }
375
-            }
376
-            $datetime->save();
377
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
378
-            // before going any further make sure our dates are setup correctly
379
-            // so that the end date is always equal or greater than the start date.
380
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
381
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
382
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
383
-                $datetime->save();
384
-            }
385
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
386
-            // because it is possible there was a new one created for the autosave.
387
-            // (save the ID for both key and value to avoid duplications)
388
-            $DTT_ID = $datetime->ID();
389
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
390
-            $saved_dtt_objs[ $row ] = $datetime;
391
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
392
-        }
393
-        $event->save();
394
-        // now we need to REMOVE any datetimes that got deleted.
395
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
396
-        // So its safe to permanently delete at this point.
397
-        $old_datetimes = explode(',', $data['datetime_IDs']);
398
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
399
-        if (is_array($old_datetimes)) {
400
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
401
-            foreach ($datetimes_to_delete as $id) {
402
-                $id = absint($id);
403
-                if (empty($id)) {
404
-                    continue;
405
-                }
406
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
407
-                // remove tkt relationships.
408
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
409
-                foreach ($related_tickets as $tkt) {
410
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
411
-                }
412
-                $event->_remove_relation_to($id, 'Datetime');
413
-                $dtt_to_remove->refresh_cache_of_related_objects();
414
-            }
415
-        }
416
-        return $saved_dtt_objs;
417
-    }
287
+	/**
288
+	 * update event_datetimes
289
+	 *
290
+	 * @param  EE_Event $event Event being updated
291
+	 * @param  array    $data  the request data from the form
292
+	 * @return EE_Datetime[]
293
+	 * @throws Exception
294
+	 * @throws ReflectionException
295
+	 * @throws InvalidInterfaceException
296
+	 * @throws InvalidDataTypeException
297
+	 * @throws InvalidArgumentException
298
+	 * @throws EE_Error
299
+	 */
300
+	protected function _update_datetimes($event, $data)
301
+	{
302
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
303
+		$saved_dtt_ids = array();
304
+		$saved_dtt_objs = array();
305
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
306
+			throw new InvalidArgumentException(
307
+				esc_html__(
308
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
309
+					'event_espresso'
310
+				)
311
+			);
312
+		}
313
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
314
+			// trim all values to ensure any excess whitespace is removed.
315
+			$datetime_data = array_map(
316
+				function ($datetime_data) {
317
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
318
+				},
319
+				$datetime_data
320
+			);
321
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
322
+											&& ! empty($datetime_data['DTT_EVT_end'])
323
+				? $datetime_data['DTT_EVT_end']
324
+				: $datetime_data['DTT_EVT_start'];
325
+			$datetime_values = array(
326
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
327
+					? $datetime_data['DTT_ID']
328
+					: null,
329
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
330
+					? $datetime_data['DTT_name']
331
+					: '',
332
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
333
+					? $datetime_data['DTT_description']
334
+					: '',
335
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
336
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
337
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
338
+					? EE_INF
339
+					: $datetime_data['DTT_reg_limit'],
340
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
341
+					? $row
342
+					: $datetime_data['DTT_order'],
343
+			);
344
+			// if we have an id then let's get existing object first and then set the new values.
345
+			// Otherwise we instantiate a new object for save.
346
+			if (! empty($datetime_data['DTT_ID'])) {
347
+				$datetime = EE_Registry::instance()
348
+									   ->load_model('Datetime', array($timezone))
349
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
350
+				// set date and time format according to what is set in this class.
351
+				$datetime->set_date_format($this->_date_format_strings['date']);
352
+				$datetime->set_time_format($this->_date_format_strings['time']);
353
+				foreach ($datetime_values as $field => $value) {
354
+					$datetime->set($field, $value);
355
+				}
356
+				// make sure the $dtt_id here is saved just in case
357
+				// after the add_relation_to() the autosave replaces it.
358
+				// We need to do this so we dont' TRASH the parent DTT.
359
+				// (save the ID for both key and value to avoid duplications)
360
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
361
+			} else {
362
+				$datetime = EE_Registry::instance()->load_class(
363
+					'Datetime',
364
+					array(
365
+						$datetime_values,
366
+						$timezone,
367
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
368
+					),
369
+					false,
370
+					false
371
+				);
372
+				foreach ($datetime_values as $field => $value) {
373
+					$datetime->set($field, $value);
374
+				}
375
+			}
376
+			$datetime->save();
377
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
378
+			// before going any further make sure our dates are setup correctly
379
+			// so that the end date is always equal or greater than the start date.
380
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
381
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
382
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
383
+				$datetime->save();
384
+			}
385
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
386
+			// because it is possible there was a new one created for the autosave.
387
+			// (save the ID for both key and value to avoid duplications)
388
+			$DTT_ID = $datetime->ID();
389
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
390
+			$saved_dtt_objs[ $row ] = $datetime;
391
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
392
+		}
393
+		$event->save();
394
+		// now we need to REMOVE any datetimes that got deleted.
395
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
396
+		// So its safe to permanently delete at this point.
397
+		$old_datetimes = explode(',', $data['datetime_IDs']);
398
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
399
+		if (is_array($old_datetimes)) {
400
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
401
+			foreach ($datetimes_to_delete as $id) {
402
+				$id = absint($id);
403
+				if (empty($id)) {
404
+					continue;
405
+				}
406
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
407
+				// remove tkt relationships.
408
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
409
+				foreach ($related_tickets as $tkt) {
410
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
411
+				}
412
+				$event->_remove_relation_to($id, 'Datetime');
413
+				$dtt_to_remove->refresh_cache_of_related_objects();
414
+			}
415
+		}
416
+		return $saved_dtt_objs;
417
+	}
418 418
 
419 419
 
420
-    /**
421
-     * update tickets
422
-     *
423
-     * @param  EE_Event      $event           Event object being updated
424
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
425
-     * @param  array         $data            incoming request data
426
-     * @return EE_Ticket[]
427
-     * @throws Exception
428
-     * @throws ReflectionException
429
-     * @throws InvalidInterfaceException
430
-     * @throws InvalidDataTypeException
431
-     * @throws InvalidArgumentException
432
-     * @throws EE_Error
433
-     */
434
-    protected function _update_tickets($event, $saved_datetimes, $data)
435
-    {
436
-        $new_tkt = null;
437
-        $new_default = null;
438
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
439
-        $data = stripslashes_deep($data);
440
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
441
-        $saved_tickets = $datetimes_on_existing = array();
442
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
443
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
444
-            throw new InvalidArgumentException(
445
-                esc_html__(
446
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
447
-                    'event_espresso'
448
-                )
449
-            );
450
-        }
451
-        foreach ($data['edit_tickets'] as $row => $tkt) {
452
-            $update_prices = $create_new_TKT = false;
453
-            // figure out what datetimes were added to the ticket
454
-            // and what datetimes were removed from the ticket in the session.
455
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
456
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
457
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
458
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
459
-            // trim inputs to ensure any excess whitespace is removed.
460
-            $tkt = array_map(
461
-                function ($ticket_data) {
462
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
463
-                },
464
-                $tkt
465
-            );
466
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
467
-            // because we're doing calculations prior to using the models.
468
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
469
-            $ticket_price = isset($tkt['TKT_price'])
470
-                ? round((float) $tkt['TKT_price'], 3)
471
-                : 0;
472
-            // note incoming base price needs converted from localized value.
473
-            $base_price = isset($tkt['TKT_base_price'])
474
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
475
-                : 0;
476
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
477
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
478
-                ? $base_price
479
-                : $ticket_price;
480
-            $base_price_id = isset($tkt['TKT_base_price_ID'])
481
-                ? $tkt['TKT_base_price_ID']
482
-                : 0;
483
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
484
-                ? $data['edit_prices'][ $row ]
485
-                : array();
486
-            $now = null;
487
-            if (empty($tkt['TKT_start_date'])) {
488
-                // lets' use now in the set timezone.
489
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
490
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
491
-            }
492
-            if (empty($tkt['TKT_end_date'])) {
493
-                /**
494
-                 * set the TKT_end_date to the first datetime attached to the ticket.
495
-                 */
496
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
497
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
498
-            }
499
-            $TKT_values = array(
500
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
501
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
502
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
503
-                'TKT_description' => ! empty($tkt['TKT_description'])
504
-                                     && $tkt['TKT_description'] !== esc_html__(
505
-                                         'You can modify this description',
506
-                                         'event_espresso'
507
-                                     )
508
-                    ? $tkt['TKT_description']
509
-                    : '',
510
-                'TKT_start_date'  => $tkt['TKT_start_date'],
511
-                'TKT_end_date'    => $tkt['TKT_end_date'],
512
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
513
-                    ? EE_INF
514
-                    : $tkt['TKT_qty'],
515
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
516
-                    ? EE_INF
517
-                    : $tkt['TKT_uses'],
518
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
519
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
520
-                'TKT_row'         => $row,
521
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
522
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
523
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
524
-                'TKT_price'       => $ticket_price,
525
-            );
526
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
527
-            // which means in turn that the prices will become new prices as well.
528
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
529
-                $TKT_values['TKT_ID'] = 0;
530
-                $TKT_values['TKT_is_default'] = 0;
531
-                $update_prices = true;
532
-            }
533
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
534
-            // we actually do our saves ahead of doing any add_relations to
535
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
536
-            // but DID have it's items modified.
537
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
538
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
539
-            if (absint($TKT_values['TKT_ID'])) {
540
-                $ticket = EE_Registry::instance()
541
-                                     ->load_model('Ticket', array($timezone))
542
-                                     ->get_one_by_ID($tkt['TKT_ID']);
543
-                if ($ticket instanceof EE_Ticket) {
544
-                    $ticket = $this->_update_ticket_datetimes(
545
-                        $ticket,
546
-                        $saved_datetimes,
547
-                        $datetimes_added,
548
-                        $datetimes_removed
549
-                    );
550
-                    // are there any registrations using this ticket ?
551
-                    $tickets_sold = $ticket->count_related(
552
-                        'Registration',
553
-                        array(
554
-                            array(
555
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
556
-                            ),
557
-                        )
558
-                    );
559
-                    // set ticket formats
560
-                    $ticket->set_date_format($this->_date_format_strings['date']);
561
-                    $ticket->set_time_format($this->_date_format_strings['time']);
562
-                    // let's just check the total price for the existing ticket
563
-                    // and determine if it matches the new total price.
564
-                    // if they are different then we create a new ticket (if tickets sold)
565
-                    // if they aren't different then we go ahead and modify existing ticket.
566
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
567
-                    // set new values
568
-                    foreach ($TKT_values as $field => $value) {
569
-                        if ($field === 'TKT_qty') {
570
-                            $ticket->set_qty($value);
571
-                        } else {
572
-                            $ticket->set($field, $value);
573
-                        }
574
-                    }
575
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
576
-                    // Otherwise we have to create a new ticket.
577
-                    if ($create_new_TKT) {
578
-                        $new_tkt = $this->_duplicate_ticket(
579
-                            $ticket,
580
-                            $price_rows,
581
-                            $ticket_price,
582
-                            $base_price,
583
-                            $base_price_id
584
-                        );
585
-                    }
586
-                }
587
-            } else {
588
-                // no TKT_id so a new TKT
589
-                $ticket = EE_Ticket::new_instance(
590
-                    $TKT_values,
591
-                    $timezone,
592
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
593
-                );
594
-                if ($ticket instanceof EE_Ticket) {
595
-                    // make sure ticket has an ID of setting relations won't work
596
-                    $ticket->save();
597
-                    $ticket = $this->_update_ticket_datetimes(
598
-                        $ticket,
599
-                        $saved_datetimes,
600
-                        $datetimes_added,
601
-                        $datetimes_removed
602
-                    );
603
-                    $update_prices = true;
604
-                }
605
-            }
606
-            // make sure any current values have been saved.
607
-            // $ticket->save();
608
-            // before going any further make sure our dates are setup correctly
609
-            // so that the end date is always equal or greater than the start date.
610
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
611
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
612
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
613
-            }
614
-            // let's make sure the base price is handled
615
-            $ticket = ! $create_new_TKT
616
-                ? $this->_add_prices_to_ticket(
617
-                    array(),
618
-                    $ticket,
619
-                    $update_prices,
620
-                    $base_price,
621
-                    $base_price_id
622
-                )
623
-                : $ticket;
624
-            // add/update price_modifiers
625
-            $ticket = ! $create_new_TKT
626
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
627
-                : $ticket;
628
-            // need to make sue that the TKT_price is accurate after saving the prices.
629
-            $ticket->ensure_TKT_Price_correct();
630
-            // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
631
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
632
-                $update_prices = true;
633
-                $new_default = clone $ticket;
634
-                $new_default->set('TKT_ID', 0);
635
-                $new_default->set('TKT_is_default', 1);
636
-                $new_default->set('TKT_row', 1);
637
-                $new_default->set('TKT_price', $ticket_price);
638
-                // remove any dtt relations cause we DON'T want dtt relations attached
639
-                // (note this is just removing the cached relations in the object)
640
-                $new_default->_remove_relations('Datetime');
641
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
642
-                $new_default = $this->_add_prices_to_ticket(
643
-                    $price_rows,
644
-                    $new_default,
645
-                    $update_prices
646
-                );
647
-                // don't forget the base price!
648
-                $new_default = $this->_add_prices_to_ticket(
649
-                    array(),
650
-                    $new_default,
651
-                    $update_prices,
652
-                    $base_price,
653
-                    $base_price_id
654
-                );
655
-                $new_default->save();
656
-                do_action(
657
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
658
-                    $new_default,
659
-                    $row,
660
-                    $ticket,
661
-                    $data
662
-                );
663
-            }
664
-            // DO ALL dtt relationships for both current tickets and any archived tickets
665
-            // for the given dtt that are related to the current ticket.
666
-            // TODO... not sure exactly how we're going to do this considering we don't know
667
-            // what current ticket the archived tickets are related to
668
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
669
-            // let's assign any tickets that have been setup to the saved_tickets tracker
670
-            // save existing TKT
671
-            $ticket->save();
672
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
673
-                // save new TKT
674
-                $new_tkt->save();
675
-                // add new ticket to array
676
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
677
-                do_action(
678
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
679
-                    $new_tkt,
680
-                    $row,
681
-                    $tkt,
682
-                    $data
683
-                );
684
-            } else {
685
-                // add tkt to saved tkts
686
-                $saved_tickets[ $ticket->ID() ] = $ticket;
687
-                do_action(
688
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
689
-                    $ticket,
690
-                    $row,
691
-                    $tkt,
692
-                    $data
693
-                );
694
-            }
695
-        }
696
-        // now we need to handle tickets actually "deleted permanently".
697
-        // There are cases where we'd want this to happen
698
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
699
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
700
-        // No sense in keeping all the related data in the db!
701
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
702
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
703
-        foreach ($tickets_removed as $id) {
704
-            $id = absint($id);
705
-            // get the ticket for this id
706
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
707
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
708
-            if ($tkt_to_remove->get('TKT_is_default')) {
709
-                continue;
710
-            }
711
-            // if this tkt has any registrations attached so then we just ARCHIVE
712
-            // because we don't actually permanently delete these tickets.
713
-            if ($tkt_to_remove->count_related('Registration') > 0) {
714
-                $tkt_to_remove->delete();
715
-                continue;
716
-            }
717
-            // need to get all the related datetimes on this ticket and remove from every single one of them
718
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
719
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
720
-            foreach ($datetimes as $datetime) {
721
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
722
-            }
723
-            // need to do the same for prices (except these prices can also be deleted because again,
724
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
725
-            $tkt_to_remove->delete_related_permanently('Price');
726
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
727
-            // finally let's delete this ticket
728
-            // (which should not be blocked at this point b/c we've removed all our relationships)
729
-            $tkt_to_remove->delete_permanently();
730
-        }
731
-        return $saved_tickets;
732
-    }
420
+	/**
421
+	 * update tickets
422
+	 *
423
+	 * @param  EE_Event      $event           Event object being updated
424
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
425
+	 * @param  array         $data            incoming request data
426
+	 * @return EE_Ticket[]
427
+	 * @throws Exception
428
+	 * @throws ReflectionException
429
+	 * @throws InvalidInterfaceException
430
+	 * @throws InvalidDataTypeException
431
+	 * @throws InvalidArgumentException
432
+	 * @throws EE_Error
433
+	 */
434
+	protected function _update_tickets($event, $saved_datetimes, $data)
435
+	{
436
+		$new_tkt = null;
437
+		$new_default = null;
438
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
439
+		$data = stripslashes_deep($data);
440
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
441
+		$saved_tickets = $datetimes_on_existing = array();
442
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
443
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
444
+			throw new InvalidArgumentException(
445
+				esc_html__(
446
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
447
+					'event_espresso'
448
+				)
449
+			);
450
+		}
451
+		foreach ($data['edit_tickets'] as $row => $tkt) {
452
+			$update_prices = $create_new_TKT = false;
453
+			// figure out what datetimes were added to the ticket
454
+			// and what datetimes were removed from the ticket in the session.
455
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
456
+			$tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
457
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
458
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
459
+			// trim inputs to ensure any excess whitespace is removed.
460
+			$tkt = array_map(
461
+				function ($ticket_data) {
462
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
463
+				},
464
+				$tkt
465
+			);
466
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
467
+			// because we're doing calculations prior to using the models.
468
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
469
+			$ticket_price = isset($tkt['TKT_price'])
470
+				? round((float) $tkt['TKT_price'], 3)
471
+				: 0;
472
+			// note incoming base price needs converted from localized value.
473
+			$base_price = isset($tkt['TKT_base_price'])
474
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
475
+				: 0;
476
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
477
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
478
+				? $base_price
479
+				: $ticket_price;
480
+			$base_price_id = isset($tkt['TKT_base_price_ID'])
481
+				? $tkt['TKT_base_price_ID']
482
+				: 0;
483
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
484
+				? $data['edit_prices'][ $row ]
485
+				: array();
486
+			$now = null;
487
+			if (empty($tkt['TKT_start_date'])) {
488
+				// lets' use now in the set timezone.
489
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
490
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
491
+			}
492
+			if (empty($tkt['TKT_end_date'])) {
493
+				/**
494
+				 * set the TKT_end_date to the first datetime attached to the ticket.
495
+				 */
496
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
497
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
498
+			}
499
+			$TKT_values = array(
500
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
501
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
502
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
503
+				'TKT_description' => ! empty($tkt['TKT_description'])
504
+									 && $tkt['TKT_description'] !== esc_html__(
505
+										 'You can modify this description',
506
+										 'event_espresso'
507
+									 )
508
+					? $tkt['TKT_description']
509
+					: '',
510
+				'TKT_start_date'  => $tkt['TKT_start_date'],
511
+				'TKT_end_date'    => $tkt['TKT_end_date'],
512
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
513
+					? EE_INF
514
+					: $tkt['TKT_qty'],
515
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
516
+					? EE_INF
517
+					: $tkt['TKT_uses'],
518
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
519
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
520
+				'TKT_row'         => $row,
521
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
522
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
523
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
524
+				'TKT_price'       => $ticket_price,
525
+			);
526
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
527
+			// which means in turn that the prices will become new prices as well.
528
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
529
+				$TKT_values['TKT_ID'] = 0;
530
+				$TKT_values['TKT_is_default'] = 0;
531
+				$update_prices = true;
532
+			}
533
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
534
+			// we actually do our saves ahead of doing any add_relations to
535
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
536
+			// but DID have it's items modified.
537
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
538
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
539
+			if (absint($TKT_values['TKT_ID'])) {
540
+				$ticket = EE_Registry::instance()
541
+									 ->load_model('Ticket', array($timezone))
542
+									 ->get_one_by_ID($tkt['TKT_ID']);
543
+				if ($ticket instanceof EE_Ticket) {
544
+					$ticket = $this->_update_ticket_datetimes(
545
+						$ticket,
546
+						$saved_datetimes,
547
+						$datetimes_added,
548
+						$datetimes_removed
549
+					);
550
+					// are there any registrations using this ticket ?
551
+					$tickets_sold = $ticket->count_related(
552
+						'Registration',
553
+						array(
554
+							array(
555
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
556
+							),
557
+						)
558
+					);
559
+					// set ticket formats
560
+					$ticket->set_date_format($this->_date_format_strings['date']);
561
+					$ticket->set_time_format($this->_date_format_strings['time']);
562
+					// let's just check the total price for the existing ticket
563
+					// and determine if it matches the new total price.
564
+					// if they are different then we create a new ticket (if tickets sold)
565
+					// if they aren't different then we go ahead and modify existing ticket.
566
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
567
+					// set new values
568
+					foreach ($TKT_values as $field => $value) {
569
+						if ($field === 'TKT_qty') {
570
+							$ticket->set_qty($value);
571
+						} else {
572
+							$ticket->set($field, $value);
573
+						}
574
+					}
575
+					// if $create_new_TKT is false then we can safely update the existing ticket.
576
+					// Otherwise we have to create a new ticket.
577
+					if ($create_new_TKT) {
578
+						$new_tkt = $this->_duplicate_ticket(
579
+							$ticket,
580
+							$price_rows,
581
+							$ticket_price,
582
+							$base_price,
583
+							$base_price_id
584
+						);
585
+					}
586
+				}
587
+			} else {
588
+				// no TKT_id so a new TKT
589
+				$ticket = EE_Ticket::new_instance(
590
+					$TKT_values,
591
+					$timezone,
592
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
593
+				);
594
+				if ($ticket instanceof EE_Ticket) {
595
+					// make sure ticket has an ID of setting relations won't work
596
+					$ticket->save();
597
+					$ticket = $this->_update_ticket_datetimes(
598
+						$ticket,
599
+						$saved_datetimes,
600
+						$datetimes_added,
601
+						$datetimes_removed
602
+					);
603
+					$update_prices = true;
604
+				}
605
+			}
606
+			// make sure any current values have been saved.
607
+			// $ticket->save();
608
+			// before going any further make sure our dates are setup correctly
609
+			// so that the end date is always equal or greater than the start date.
610
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
611
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
612
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
613
+			}
614
+			// let's make sure the base price is handled
615
+			$ticket = ! $create_new_TKT
616
+				? $this->_add_prices_to_ticket(
617
+					array(),
618
+					$ticket,
619
+					$update_prices,
620
+					$base_price,
621
+					$base_price_id
622
+				)
623
+				: $ticket;
624
+			// add/update price_modifiers
625
+			$ticket = ! $create_new_TKT
626
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
627
+				: $ticket;
628
+			// need to make sue that the TKT_price is accurate after saving the prices.
629
+			$ticket->ensure_TKT_Price_correct();
630
+			// handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
631
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
632
+				$update_prices = true;
633
+				$new_default = clone $ticket;
634
+				$new_default->set('TKT_ID', 0);
635
+				$new_default->set('TKT_is_default', 1);
636
+				$new_default->set('TKT_row', 1);
637
+				$new_default->set('TKT_price', $ticket_price);
638
+				// remove any dtt relations cause we DON'T want dtt relations attached
639
+				// (note this is just removing the cached relations in the object)
640
+				$new_default->_remove_relations('Datetime');
641
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
642
+				$new_default = $this->_add_prices_to_ticket(
643
+					$price_rows,
644
+					$new_default,
645
+					$update_prices
646
+				);
647
+				// don't forget the base price!
648
+				$new_default = $this->_add_prices_to_ticket(
649
+					array(),
650
+					$new_default,
651
+					$update_prices,
652
+					$base_price,
653
+					$base_price_id
654
+				);
655
+				$new_default->save();
656
+				do_action(
657
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
658
+					$new_default,
659
+					$row,
660
+					$ticket,
661
+					$data
662
+				);
663
+			}
664
+			// DO ALL dtt relationships for both current tickets and any archived tickets
665
+			// for the given dtt that are related to the current ticket.
666
+			// TODO... not sure exactly how we're going to do this considering we don't know
667
+			// what current ticket the archived tickets are related to
668
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
669
+			// let's assign any tickets that have been setup to the saved_tickets tracker
670
+			// save existing TKT
671
+			$ticket->save();
672
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
673
+				// save new TKT
674
+				$new_tkt->save();
675
+				// add new ticket to array
676
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
677
+				do_action(
678
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
679
+					$new_tkt,
680
+					$row,
681
+					$tkt,
682
+					$data
683
+				);
684
+			} else {
685
+				// add tkt to saved tkts
686
+				$saved_tickets[ $ticket->ID() ] = $ticket;
687
+				do_action(
688
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
689
+					$ticket,
690
+					$row,
691
+					$tkt,
692
+					$data
693
+				);
694
+			}
695
+		}
696
+		// now we need to handle tickets actually "deleted permanently".
697
+		// There are cases where we'd want this to happen
698
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
699
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
700
+		// No sense in keeping all the related data in the db!
701
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
702
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
703
+		foreach ($tickets_removed as $id) {
704
+			$id = absint($id);
705
+			// get the ticket for this id
706
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
707
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
708
+			if ($tkt_to_remove->get('TKT_is_default')) {
709
+				continue;
710
+			}
711
+			// if this tkt has any registrations attached so then we just ARCHIVE
712
+			// because we don't actually permanently delete these tickets.
713
+			if ($tkt_to_remove->count_related('Registration') > 0) {
714
+				$tkt_to_remove->delete();
715
+				continue;
716
+			}
717
+			// need to get all the related datetimes on this ticket and remove from every single one of them
718
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
719
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
720
+			foreach ($datetimes as $datetime) {
721
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
722
+			}
723
+			// need to do the same for prices (except these prices can also be deleted because again,
724
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
725
+			$tkt_to_remove->delete_related_permanently('Price');
726
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
727
+			// finally let's delete this ticket
728
+			// (which should not be blocked at this point b/c we've removed all our relationships)
729
+			$tkt_to_remove->delete_permanently();
730
+		}
731
+		return $saved_tickets;
732
+	}
733 733
 
734 734
 
735
-    /**
736
-     * @access  protected
737
-     * @param EE_Ticket      $ticket
738
-     * @param \EE_Datetime[] $saved_datetimes
739
-     * @param \EE_Datetime[] $added_datetimes
740
-     * @param \EE_Datetime[] $removed_datetimes
741
-     * @return EE_Ticket
742
-     * @throws EE_Error
743
-     */
744
-    protected function _update_ticket_datetimes(
745
-        EE_Ticket $ticket,
746
-        $saved_datetimes = array(),
747
-        $added_datetimes = array(),
748
-        $removed_datetimes = array()
749
-    ) {
750
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
751
-        // and removing the ticket from datetimes it got removed from.
752
-        // first let's add datetimes
753
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
754
-            foreach ($added_datetimes as $row_id) {
755
-                $row_id = (int) $row_id;
756
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
757
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
758
-                    // Is this an existing ticket (has an ID) and does it have any sold?
759
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
760
-                    if ($ticket->ID() && $ticket->sold() > 0) {
761
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
762
-                    }
763
-                }
764
-            }
765
-        }
766
-        // then remove datetimes
767
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
768
-            foreach ($removed_datetimes as $row_id) {
769
-                $row_id = (int) $row_id;
770
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
771
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
772
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
773
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
774
-                    // Is this an existing ticket (has an ID) and does it have any sold?
775
-                    // If so, then we need to remove it's sold from the DTT_sold.
776
-                    if ($ticket->ID() && $ticket->sold() > 0) {
777
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
778
-                    }
779
-                }
780
-            }
781
-        }
782
-        // cap ticket qty by datetime reg limits
783
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
784
-        return $ticket;
785
-    }
735
+	/**
736
+	 * @access  protected
737
+	 * @param EE_Ticket      $ticket
738
+	 * @param \EE_Datetime[] $saved_datetimes
739
+	 * @param \EE_Datetime[] $added_datetimes
740
+	 * @param \EE_Datetime[] $removed_datetimes
741
+	 * @return EE_Ticket
742
+	 * @throws EE_Error
743
+	 */
744
+	protected function _update_ticket_datetimes(
745
+		EE_Ticket $ticket,
746
+		$saved_datetimes = array(),
747
+		$added_datetimes = array(),
748
+		$removed_datetimes = array()
749
+	) {
750
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
751
+		// and removing the ticket from datetimes it got removed from.
752
+		// first let's add datetimes
753
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
754
+			foreach ($added_datetimes as $row_id) {
755
+				$row_id = (int) $row_id;
756
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
757
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
758
+					// Is this an existing ticket (has an ID) and does it have any sold?
759
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
760
+					if ($ticket->ID() && $ticket->sold() > 0) {
761
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
762
+					}
763
+				}
764
+			}
765
+		}
766
+		// then remove datetimes
767
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
768
+			foreach ($removed_datetimes as $row_id) {
769
+				$row_id = (int) $row_id;
770
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
771
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
772
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
773
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
774
+					// Is this an existing ticket (has an ID) and does it have any sold?
775
+					// If so, then we need to remove it's sold from the DTT_sold.
776
+					if ($ticket->ID() && $ticket->sold() > 0) {
777
+						$saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
778
+					}
779
+				}
780
+			}
781
+		}
782
+		// cap ticket qty by datetime reg limits
783
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
784
+		return $ticket;
785
+	}
786 786
 
787 787
 
788
-    /**
789
-     * @access  protected
790
-     * @param EE_Ticket $ticket
791
-     * @param array     $price_rows
792
-     * @param int       $ticket_price
793
-     * @param int       $base_price
794
-     * @param int       $base_price_id
795
-     * @return EE_Ticket
796
-     * @throws ReflectionException
797
-     * @throws InvalidArgumentException
798
-     * @throws InvalidInterfaceException
799
-     * @throws InvalidDataTypeException
800
-     * @throws EE_Error
801
-     */
802
-    protected function _duplicate_ticket(
803
-        EE_Ticket $ticket,
804
-        $price_rows = array(),
805
-        $ticket_price = 0,
806
-        $base_price = 0,
807
-        $base_price_id = 0
808
-    ) {
809
-        // create new ticket that's a copy of the existing
810
-        // except a new id of course (and not archived)
811
-        // AND has the new TKT_price associated with it.
812
-        $new_ticket = clone $ticket;
813
-        $new_ticket->set('TKT_ID', 0);
814
-        $new_ticket->set_deleted(0);
815
-        $new_ticket->set_price($ticket_price);
816
-        $new_ticket->set_sold(0);
817
-        // let's get a new ID for this ticket
818
-        $new_ticket->save();
819
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
820
-        $datetimes_on_existing = $ticket->datetimes();
821
-        $new_ticket = $this->_update_ticket_datetimes(
822
-            $new_ticket,
823
-            $datetimes_on_existing,
824
-            array_keys($datetimes_on_existing)
825
-        );
826
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
827
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
828
-        // available.
829
-        if ($ticket->sold() > 0) {
830
-            $new_qty = $ticket->qty() - $ticket->sold();
831
-            $new_ticket->set_qty($new_qty);
832
-        }
833
-        // now we update the prices just for this ticket
834
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
835
-        // and we update the base price
836
-        $new_ticket = $this->_add_prices_to_ticket(
837
-            array(),
838
-            $new_ticket,
839
-            true,
840
-            $base_price,
841
-            $base_price_id
842
-        );
843
-        return $new_ticket;
844
-    }
788
+	/**
789
+	 * @access  protected
790
+	 * @param EE_Ticket $ticket
791
+	 * @param array     $price_rows
792
+	 * @param int       $ticket_price
793
+	 * @param int       $base_price
794
+	 * @param int       $base_price_id
795
+	 * @return EE_Ticket
796
+	 * @throws ReflectionException
797
+	 * @throws InvalidArgumentException
798
+	 * @throws InvalidInterfaceException
799
+	 * @throws InvalidDataTypeException
800
+	 * @throws EE_Error
801
+	 */
802
+	protected function _duplicate_ticket(
803
+		EE_Ticket $ticket,
804
+		$price_rows = array(),
805
+		$ticket_price = 0,
806
+		$base_price = 0,
807
+		$base_price_id = 0
808
+	) {
809
+		// create new ticket that's a copy of the existing
810
+		// except a new id of course (and not archived)
811
+		// AND has the new TKT_price associated with it.
812
+		$new_ticket = clone $ticket;
813
+		$new_ticket->set('TKT_ID', 0);
814
+		$new_ticket->set_deleted(0);
815
+		$new_ticket->set_price($ticket_price);
816
+		$new_ticket->set_sold(0);
817
+		// let's get a new ID for this ticket
818
+		$new_ticket->save();
819
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
820
+		$datetimes_on_existing = $ticket->datetimes();
821
+		$new_ticket = $this->_update_ticket_datetimes(
822
+			$new_ticket,
823
+			$datetimes_on_existing,
824
+			array_keys($datetimes_on_existing)
825
+		);
826
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
827
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
828
+		// available.
829
+		if ($ticket->sold() > 0) {
830
+			$new_qty = $ticket->qty() - $ticket->sold();
831
+			$new_ticket->set_qty($new_qty);
832
+		}
833
+		// now we update the prices just for this ticket
834
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
835
+		// and we update the base price
836
+		$new_ticket = $this->_add_prices_to_ticket(
837
+			array(),
838
+			$new_ticket,
839
+			true,
840
+			$base_price,
841
+			$base_price_id
842
+		);
843
+		return $new_ticket;
844
+	}
845 845
 
846 846
 
847
-    /**
848
-     * This attaches a list of given prices to a ticket.
849
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
850
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
851
-     * price info and prices are automatically "archived" via the ticket.
852
-     *
853
-     * @access  private
854
-     * @param array     $prices        Array of prices from the form.
855
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
856
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
857
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
858
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
859
-     * @return EE_Ticket
860
-     * @throws ReflectionException
861
-     * @throws InvalidArgumentException
862
-     * @throws InvalidInterfaceException
863
-     * @throws InvalidDataTypeException
864
-     * @throws EE_Error
865
-     */
866
-    protected function _add_prices_to_ticket(
867
-        $prices = array(),
868
-        EE_Ticket $ticket,
869
-        $new_prices = false,
870
-        $base_price = false,
871
-        $base_price_id = false
872
-    ) {
873
-        // let's just get any current prices that may exist on the given ticket
874
-        // so we can remove any prices that got trashed in this session.
875
-        $current_prices_on_ticket = $base_price !== false
876
-            ? $ticket->base_price(true)
877
-            : $ticket->price_modifiers();
878
-        $updated_prices = array();
879
-        // if $base_price ! FALSE then updating a base price.
880
-        if ($base_price !== false) {
881
-            $prices[1] = array(
882
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
883
-                'PRT_ID'     => 1,
884
-                'PRC_amount' => $base_price,
885
-                'PRC_name'   => $ticket->get('TKT_name'),
886
-                'PRC_desc'   => $ticket->get('TKT_description'),
887
-            );
888
-        }
889
-        // possibly need to save tkt
890
-        if (! $ticket->ID()) {
891
-            $ticket->save();
892
-        }
893
-        foreach ($prices as $row => $prc) {
894
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
895
-            if (empty($prt_id)) {
896
-                continue;
897
-            } //prices MUST have a price type id.
898
-            $PRC_values = array(
899
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
900
-                'PRT_ID'         => $prt_id,
901
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
902
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
903
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
904
-                'PRC_is_default' => false,
905
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
906
-                'PRC_order'      => $row,
907
-            );
908
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
909
-                $PRC_values['PRC_ID'] = 0;
910
-                $price = EE_Registry::instance()->load_class(
911
-                    'Price',
912
-                    array($PRC_values),
913
-                    false,
914
-                    false
915
-                );
916
-            } else {
917
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
918
-                // update this price with new values
919
-                foreach ($PRC_values as $field => $value) {
920
-                    $price->set($field, $value);
921
-                }
922
-            }
923
-            $price->save();
924
-            $updated_prices[ $price->ID() ] = $price;
925
-            $ticket->_add_relation_to($price, 'Price');
926
-        }
927
-        // now let's remove any prices that got removed from the ticket
928
-        if (! empty($current_prices_on_ticket)) {
929
-            $current = array_keys($current_prices_on_ticket);
930
-            $updated = array_keys($updated_prices);
931
-            $prices_to_remove = array_diff($current, $updated);
932
-            if (! empty($prices_to_remove)) {
933
-                foreach ($prices_to_remove as $prc_id) {
934
-                    $p = $current_prices_on_ticket[ $prc_id ];
935
-                    $ticket->_remove_relation_to($p, 'Price');
936
-                    // delete permanently the price
937
-                    $p->delete_permanently();
938
-                }
939
-            }
940
-        }
941
-        return $ticket;
942
-    }
847
+	/**
848
+	 * This attaches a list of given prices to a ticket.
849
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
850
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
851
+	 * price info and prices are automatically "archived" via the ticket.
852
+	 *
853
+	 * @access  private
854
+	 * @param array     $prices        Array of prices from the form.
855
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
856
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
857
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
858
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
859
+	 * @return EE_Ticket
860
+	 * @throws ReflectionException
861
+	 * @throws InvalidArgumentException
862
+	 * @throws InvalidInterfaceException
863
+	 * @throws InvalidDataTypeException
864
+	 * @throws EE_Error
865
+	 */
866
+	protected function _add_prices_to_ticket(
867
+		$prices = array(),
868
+		EE_Ticket $ticket,
869
+		$new_prices = false,
870
+		$base_price = false,
871
+		$base_price_id = false
872
+	) {
873
+		// let's just get any current prices that may exist on the given ticket
874
+		// so we can remove any prices that got trashed in this session.
875
+		$current_prices_on_ticket = $base_price !== false
876
+			? $ticket->base_price(true)
877
+			: $ticket->price_modifiers();
878
+		$updated_prices = array();
879
+		// if $base_price ! FALSE then updating a base price.
880
+		if ($base_price !== false) {
881
+			$prices[1] = array(
882
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
883
+				'PRT_ID'     => 1,
884
+				'PRC_amount' => $base_price,
885
+				'PRC_name'   => $ticket->get('TKT_name'),
886
+				'PRC_desc'   => $ticket->get('TKT_description'),
887
+			);
888
+		}
889
+		// possibly need to save tkt
890
+		if (! $ticket->ID()) {
891
+			$ticket->save();
892
+		}
893
+		foreach ($prices as $row => $prc) {
894
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
895
+			if (empty($prt_id)) {
896
+				continue;
897
+			} //prices MUST have a price type id.
898
+			$PRC_values = array(
899
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
900
+				'PRT_ID'         => $prt_id,
901
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
902
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
903
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
904
+				'PRC_is_default' => false,
905
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
906
+				'PRC_order'      => $row,
907
+			);
908
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
909
+				$PRC_values['PRC_ID'] = 0;
910
+				$price = EE_Registry::instance()->load_class(
911
+					'Price',
912
+					array($PRC_values),
913
+					false,
914
+					false
915
+				);
916
+			} else {
917
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
918
+				// update this price with new values
919
+				foreach ($PRC_values as $field => $value) {
920
+					$price->set($field, $value);
921
+				}
922
+			}
923
+			$price->save();
924
+			$updated_prices[ $price->ID() ] = $price;
925
+			$ticket->_add_relation_to($price, 'Price');
926
+		}
927
+		// now let's remove any prices that got removed from the ticket
928
+		if (! empty($current_prices_on_ticket)) {
929
+			$current = array_keys($current_prices_on_ticket);
930
+			$updated = array_keys($updated_prices);
931
+			$prices_to_remove = array_diff($current, $updated);
932
+			if (! empty($prices_to_remove)) {
933
+				foreach ($prices_to_remove as $prc_id) {
934
+					$p = $current_prices_on_ticket[ $prc_id ];
935
+					$ticket->_remove_relation_to($p, 'Price');
936
+					// delete permanently the price
937
+					$p->delete_permanently();
938
+				}
939
+			}
940
+		}
941
+		return $ticket;
942
+	}
943 943
 
944 944
 
945
-    /**
946
-     * @param Events_Admin_Page $event_admin_obj
947
-     * @return Events_Admin_Page
948
-     */
949
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
950
-    {
951
-        return $event_admin_obj;
952
-        // doing nothing for the moment.
953
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
954
-        // (use the set_template_args() method)
955
-        /**
956
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
957
-         * 1. TKT_is_default_selector (visible)
958
-         * 2. TKT_is_default (hidden)
959
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
960
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
961
-         * this ticket to be saved as a default.
962
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
963
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
964
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
965
-         * the TKT HAS been saved as a default..
966
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
967
-         * On Autosave:
968
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
969
-         * then set the TKT_is_default to false.
970
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
971
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
972
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
973
-         */
974
-    }
945
+	/**
946
+	 * @param Events_Admin_Page $event_admin_obj
947
+	 * @return Events_Admin_Page
948
+	 */
949
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
950
+	{
951
+		return $event_admin_obj;
952
+		// doing nothing for the moment.
953
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
954
+		// (use the set_template_args() method)
955
+		/**
956
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
957
+		 * 1. TKT_is_default_selector (visible)
958
+		 * 2. TKT_is_default (hidden)
959
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
960
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
961
+		 * this ticket to be saved as a default.
962
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
963
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
964
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
965
+		 * the TKT HAS been saved as a default..
966
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
967
+		 * On Autosave:
968
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
969
+		 * then set the TKT_is_default to false.
970
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
971
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
972
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
973
+		 */
974
+	}
975 975
 
976 976
 
977
-    /**
978
-     * @throws ReflectionException
979
-     * @throws InvalidArgumentException
980
-     * @throws InvalidInterfaceException
981
-     * @throws InvalidDataTypeException
982
-     * @throws DomainException
983
-     * @throws EE_Error
984
-     */
985
-    public function pricing_metabox()
986
-    {
987
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
988
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
989
-        // set is_creating_event property.
990
-        $EVT_ID = $event->ID();
991
-        $this->_is_creating_event = empty($this->_req_data['post']);
992
-        // default main template args
993
-        $main_template_args = array(
994
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
995
-                'event_editor_event_datetimes_help_tab',
996
-                $this->_adminpage_obj->page_slug,
997
-                $this->_adminpage_obj->get_req_action(),
998
-                false,
999
-                false
1000
-            ),
1001
-            // todo need to add a filter to the template for the help text
1002
-            // in the Events_Admin_Page core file so we can add further help
1003
-            'existing_datetime_ids'    => '',
1004
-            'total_dtt_rows'           => 1,
1005
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1006
-                'add_new_dtt_info',
1007
-                $this->_adminpage_obj->page_slug,
1008
-                $this->_adminpage_obj->get_req_action(),
1009
-                false,
1010
-                false
1011
-            ),
1012
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1013
-            'datetime_rows'            => '',
1014
-            'show_tickets_container'   => '',
1015
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1016
-            'ticket_rows'              => '',
1017
-            'existing_ticket_ids'      => '',
1018
-            'total_ticket_rows'        => 1,
1019
-            'ticket_js_structure'      => '',
1020
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1021
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1022
-        );
1023
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1024
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1025
-        /**
1026
-         * 1. Start with retrieving Datetimes
1027
-         * 2. For each datetime get related tickets
1028
-         * 3. For each ticket get related prices
1029
-         */
1030
-        /** @var EEM_Datetime $datetime_model */
1031
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1032
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1033
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1034
-        /**
1035
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1036
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1037
-         */
1038
-        $datetime_row = 1;
1039
-        foreach ($datetimes as $datetime) {
1040
-            $DTT_ID = $datetime->get('DTT_ID');
1041
-            $datetime->set('DTT_order', $datetime_row);
1042
-            $existing_datetime_ids[] = $DTT_ID;
1043
-            // tickets attached
1044
-            $related_tickets = $datetime->ID() > 0
1045
-                ? $datetime->get_many_related(
1046
-                    'Ticket',
1047
-                    array(
1048
-                        array(
1049
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1050
-                        ),
1051
-                        'default_where_conditions' => 'none',
1052
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1053
-                    )
1054
-                )
1055
-                : array();
1056
-            // if there are no related tickets this is likely a new event OR autodraft
1057
-            // event so we need to generate the default tickets because datetimes
1058
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1059
-            // datetime on the event.
1060
-            if (empty($related_tickets) && count($datetimes) < 2) {
1061
-                /** @var EEM_Ticket $ticket_model */
1062
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1063
-                $related_tickets = $ticket_model->get_all_default_tickets();
1064
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1065
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1066
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1067
-                $main_default_ticket = reset($related_tickets);
1068
-                if ($main_default_ticket instanceof EE_Ticket) {
1069
-                    foreach ($default_prices as $default_price) {
1070
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1071
-                            continue;
1072
-                        }
1073
-                        $main_default_ticket->cache('Price', $default_price);
1074
-                    }
1075
-                }
1076
-            }
1077
-            // we can't actually setup rows in this loop yet cause we don't know all
1078
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1079
-            // So we're going to temporarily cache some of that information.
1080
-            // loop through and setup the ticket rows and make sure the order is set.
1081
-            foreach ($related_tickets as $ticket) {
1082
-                $TKT_ID = $ticket->get('TKT_ID');
1083
-                $ticket_row = $ticket->get('TKT_row');
1084
-                // we only want unique tickets in our final display!!
1085
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1086
-                    $existing_ticket_ids[] = $TKT_ID;
1087
-                    $all_tickets[] = $ticket;
1088
-                }
1089
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1090
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1091
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1092
-                if (! isset($ticket_datetimes[ $TKT_ID ])
1093
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1094
-                ) {
1095
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1096
-                }
1097
-            }
1098
-            $datetime_row++;
1099
-        }
1100
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1101
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1102
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1103
-        // sort $all_tickets by order
1104
-        usort(
1105
-            $all_tickets,
1106
-            function (EE_Ticket $a, EE_Ticket $b) {
1107
-                $a_order = (int) $a->get('TKT_order');
1108
-                $b_order = (int) $b->get('TKT_order');
1109
-                if ($a_order === $b_order) {
1110
-                    return 0;
1111
-                }
1112
-                return ($a_order < $b_order) ? -1 : 1;
1113
-            }
1114
-        );
1115
-        // k NOW we have all the data we need for setting up the dtt rows
1116
-        // and ticket rows so we start our dtt loop again.
1117
-        $datetime_row = 1;
1118
-        foreach ($datetimes as $datetime) {
1119
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1120
-                $datetime_row,
1121
-                $datetime,
1122
-                $datetime_tickets,
1123
-                $all_tickets,
1124
-                false,
1125
-                $datetimes
1126
-            );
1127
-            $datetime_row++;
1128
-        }
1129
-        // then loop through all tickets for the ticket rows.
1130
-        $ticket_row = 1;
1131
-        foreach ($all_tickets as $ticket) {
1132
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1133
-                $ticket_row,
1134
-                $ticket,
1135
-                $ticket_datetimes,
1136
-                $datetimes,
1137
-                false,
1138
-                $all_tickets
1139
-            );
1140
-            $ticket_row++;
1141
-        }
1142
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1143
-        EEH_Template::display_template(
1144
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1145
-            $main_template_args
1146
-        );
1147
-    }
977
+	/**
978
+	 * @throws ReflectionException
979
+	 * @throws InvalidArgumentException
980
+	 * @throws InvalidInterfaceException
981
+	 * @throws InvalidDataTypeException
982
+	 * @throws DomainException
983
+	 * @throws EE_Error
984
+	 */
985
+	public function pricing_metabox()
986
+	{
987
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
988
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
989
+		// set is_creating_event property.
990
+		$EVT_ID = $event->ID();
991
+		$this->_is_creating_event = empty($this->_req_data['post']);
992
+		// default main template args
993
+		$main_template_args = array(
994
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
995
+				'event_editor_event_datetimes_help_tab',
996
+				$this->_adminpage_obj->page_slug,
997
+				$this->_adminpage_obj->get_req_action(),
998
+				false,
999
+				false
1000
+			),
1001
+			// todo need to add a filter to the template for the help text
1002
+			// in the Events_Admin_Page core file so we can add further help
1003
+			'existing_datetime_ids'    => '',
1004
+			'total_dtt_rows'           => 1,
1005
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1006
+				'add_new_dtt_info',
1007
+				$this->_adminpage_obj->page_slug,
1008
+				$this->_adminpage_obj->get_req_action(),
1009
+				false,
1010
+				false
1011
+			),
1012
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1013
+			'datetime_rows'            => '',
1014
+			'show_tickets_container'   => '',
1015
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1016
+			'ticket_rows'              => '',
1017
+			'existing_ticket_ids'      => '',
1018
+			'total_ticket_rows'        => 1,
1019
+			'ticket_js_structure'      => '',
1020
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1021
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1022
+		);
1023
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1024
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1025
+		/**
1026
+		 * 1. Start with retrieving Datetimes
1027
+		 * 2. For each datetime get related tickets
1028
+		 * 3. For each ticket get related prices
1029
+		 */
1030
+		/** @var EEM_Datetime $datetime_model */
1031
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1032
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1033
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1034
+		/**
1035
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1036
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1037
+		 */
1038
+		$datetime_row = 1;
1039
+		foreach ($datetimes as $datetime) {
1040
+			$DTT_ID = $datetime->get('DTT_ID');
1041
+			$datetime->set('DTT_order', $datetime_row);
1042
+			$existing_datetime_ids[] = $DTT_ID;
1043
+			// tickets attached
1044
+			$related_tickets = $datetime->ID() > 0
1045
+				? $datetime->get_many_related(
1046
+					'Ticket',
1047
+					array(
1048
+						array(
1049
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1050
+						),
1051
+						'default_where_conditions' => 'none',
1052
+						'order_by'                 => array('TKT_order' => 'ASC'),
1053
+					)
1054
+				)
1055
+				: array();
1056
+			// if there are no related tickets this is likely a new event OR autodraft
1057
+			// event so we need to generate the default tickets because datetimes
1058
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1059
+			// datetime on the event.
1060
+			if (empty($related_tickets) && count($datetimes) < 2) {
1061
+				/** @var EEM_Ticket $ticket_model */
1062
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1063
+				$related_tickets = $ticket_model->get_all_default_tickets();
1064
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1065
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1066
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1067
+				$main_default_ticket = reset($related_tickets);
1068
+				if ($main_default_ticket instanceof EE_Ticket) {
1069
+					foreach ($default_prices as $default_price) {
1070
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1071
+							continue;
1072
+						}
1073
+						$main_default_ticket->cache('Price', $default_price);
1074
+					}
1075
+				}
1076
+			}
1077
+			// we can't actually setup rows in this loop yet cause we don't know all
1078
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1079
+			// So we're going to temporarily cache some of that information.
1080
+			// loop through and setup the ticket rows and make sure the order is set.
1081
+			foreach ($related_tickets as $ticket) {
1082
+				$TKT_ID = $ticket->get('TKT_ID');
1083
+				$ticket_row = $ticket->get('TKT_row');
1084
+				// we only want unique tickets in our final display!!
1085
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1086
+					$existing_ticket_ids[] = $TKT_ID;
1087
+					$all_tickets[] = $ticket;
1088
+				}
1089
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1090
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1091
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1092
+				if (! isset($ticket_datetimes[ $TKT_ID ])
1093
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1094
+				) {
1095
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1096
+				}
1097
+			}
1098
+			$datetime_row++;
1099
+		}
1100
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1101
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1102
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1103
+		// sort $all_tickets by order
1104
+		usort(
1105
+			$all_tickets,
1106
+			function (EE_Ticket $a, EE_Ticket $b) {
1107
+				$a_order = (int) $a->get('TKT_order');
1108
+				$b_order = (int) $b->get('TKT_order');
1109
+				if ($a_order === $b_order) {
1110
+					return 0;
1111
+				}
1112
+				return ($a_order < $b_order) ? -1 : 1;
1113
+			}
1114
+		);
1115
+		// k NOW we have all the data we need for setting up the dtt rows
1116
+		// and ticket rows so we start our dtt loop again.
1117
+		$datetime_row = 1;
1118
+		foreach ($datetimes as $datetime) {
1119
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1120
+				$datetime_row,
1121
+				$datetime,
1122
+				$datetime_tickets,
1123
+				$all_tickets,
1124
+				false,
1125
+				$datetimes
1126
+			);
1127
+			$datetime_row++;
1128
+		}
1129
+		// then loop through all tickets for the ticket rows.
1130
+		$ticket_row = 1;
1131
+		foreach ($all_tickets as $ticket) {
1132
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1133
+				$ticket_row,
1134
+				$ticket,
1135
+				$ticket_datetimes,
1136
+				$datetimes,
1137
+				false,
1138
+				$all_tickets
1139
+			);
1140
+			$ticket_row++;
1141
+		}
1142
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1143
+		EEH_Template::display_template(
1144
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1145
+			$main_template_args
1146
+		);
1147
+	}
1148 1148
 
1149 1149
 
1150
-    /**
1151
-     * @param int         $datetime_row
1152
-     * @param EE_Datetime $datetime
1153
-     * @param array       $datetime_tickets
1154
-     * @param array       $all_tickets
1155
-     * @param bool        $default
1156
-     * @param array       $all_datetimes
1157
-     * @return mixed
1158
-     * @throws DomainException
1159
-     * @throws EE_Error
1160
-     */
1161
-    protected function _get_datetime_row(
1162
-        $datetime_row,
1163
-        EE_Datetime $datetime,
1164
-        $datetime_tickets = array(),
1165
-        $all_tickets = array(),
1166
-        $default = false,
1167
-        $all_datetimes = array()
1168
-    ) {
1169
-        $dtt_display_template_args = array(
1170
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1171
-                $datetime_row,
1172
-                $datetime,
1173
-                $default,
1174
-                $all_datetimes
1175
-            ),
1176
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1177
-                $datetime_row,
1178
-                $datetime,
1179
-                $datetime_tickets,
1180
-                $all_tickets,
1181
-                $default
1182
-            ),
1183
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1184
-        );
1185
-        return EEH_Template::display_template(
1186
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1187
-            $dtt_display_template_args,
1188
-            true
1189
-        );
1190
-    }
1150
+	/**
1151
+	 * @param int         $datetime_row
1152
+	 * @param EE_Datetime $datetime
1153
+	 * @param array       $datetime_tickets
1154
+	 * @param array       $all_tickets
1155
+	 * @param bool        $default
1156
+	 * @param array       $all_datetimes
1157
+	 * @return mixed
1158
+	 * @throws DomainException
1159
+	 * @throws EE_Error
1160
+	 */
1161
+	protected function _get_datetime_row(
1162
+		$datetime_row,
1163
+		EE_Datetime $datetime,
1164
+		$datetime_tickets = array(),
1165
+		$all_tickets = array(),
1166
+		$default = false,
1167
+		$all_datetimes = array()
1168
+	) {
1169
+		$dtt_display_template_args = array(
1170
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1171
+				$datetime_row,
1172
+				$datetime,
1173
+				$default,
1174
+				$all_datetimes
1175
+			),
1176
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1177
+				$datetime_row,
1178
+				$datetime,
1179
+				$datetime_tickets,
1180
+				$all_tickets,
1181
+				$default
1182
+			),
1183
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1184
+		);
1185
+		return EEH_Template::display_template(
1186
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1187
+			$dtt_display_template_args,
1188
+			true
1189
+		);
1190
+	}
1191 1191
 
1192 1192
 
1193
-    /**
1194
-     * This method is used to generate a dtt fields  edit row.
1195
-     * The same row is used to generate a row with valid DTT objects
1196
-     * and the default row that is used as the skeleton by the js.
1197
-     *
1198
-     * @param int           $datetime_row  The row number for the row being generated.
1199
-     * @param EE_Datetime   $datetime
1200
-     * @param bool          $default       Whether a default row is being generated or not.
1201
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1202
-     * @return string
1203
-     * @throws DomainException
1204
-     * @throws EE_Error
1205
-     */
1206
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1207
-    {
1208
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1209
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1210
-        $template_args = array(
1211
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1212
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1213
-            'edit_dtt_expanded'    => '',
1214
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1215
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1216
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1217
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1218
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1219
-            'DTT_reg_limit'        => $default
1220
-                ? ''
1221
-                : $datetime->get_pretty(
1222
-                    'DTT_reg_limit',
1223
-                    'input'
1224
-                ),
1225
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1226
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1227
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1228
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1229
-                ? ''
1230
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1231
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1232
-                ? 'ee-lock-icon'
1233
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1234
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1235
-                ? ''
1236
-                : EE_Admin_Page::add_query_args_and_nonce(
1237
-                    array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1238
-                    REG_ADMIN_URL
1239
-                ),
1240
-        );
1241
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1242
-            ? ' style="display:none"'
1243
-            : '';
1244
-        // allow filtering of template args at this point.
1245
-        $template_args = apply_filters(
1246
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1247
-            $template_args,
1248
-            $datetime_row,
1249
-            $datetime,
1250
-            $default,
1251
-            $all_datetimes,
1252
-            $this->_is_creating_event
1253
-        );
1254
-        return EEH_Template::display_template(
1255
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1256
-            $template_args,
1257
-            true
1258
-        );
1259
-    }
1193
+	/**
1194
+	 * This method is used to generate a dtt fields  edit row.
1195
+	 * The same row is used to generate a row with valid DTT objects
1196
+	 * and the default row that is used as the skeleton by the js.
1197
+	 *
1198
+	 * @param int           $datetime_row  The row number for the row being generated.
1199
+	 * @param EE_Datetime   $datetime
1200
+	 * @param bool          $default       Whether a default row is being generated or not.
1201
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1202
+	 * @return string
1203
+	 * @throws DomainException
1204
+	 * @throws EE_Error
1205
+	 */
1206
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1207
+	{
1208
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1209
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1210
+		$template_args = array(
1211
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1212
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1213
+			'edit_dtt_expanded'    => '',
1214
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1215
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1216
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1217
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1218
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1219
+			'DTT_reg_limit'        => $default
1220
+				? ''
1221
+				: $datetime->get_pretty(
1222
+					'DTT_reg_limit',
1223
+					'input'
1224
+				),
1225
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1226
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1227
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1228
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1229
+				? ''
1230
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1231
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1232
+				? 'ee-lock-icon'
1233
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1234
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1235
+				? ''
1236
+				: EE_Admin_Page::add_query_args_and_nonce(
1237
+					array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1238
+					REG_ADMIN_URL
1239
+				),
1240
+		);
1241
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1242
+			? ' style="display:none"'
1243
+			: '';
1244
+		// allow filtering of template args at this point.
1245
+		$template_args = apply_filters(
1246
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1247
+			$template_args,
1248
+			$datetime_row,
1249
+			$datetime,
1250
+			$default,
1251
+			$all_datetimes,
1252
+			$this->_is_creating_event
1253
+		);
1254
+		return EEH_Template::display_template(
1255
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1256
+			$template_args,
1257
+			true
1258
+		);
1259
+	}
1260 1260
 
1261 1261
 
1262
-    /**
1263
-     * @param int         $datetime_row
1264
-     * @param EE_Datetime $datetime
1265
-     * @param array       $datetime_tickets
1266
-     * @param array       $all_tickets
1267
-     * @param bool        $default
1268
-     * @return mixed
1269
-     * @throws DomainException
1270
-     * @throws EE_Error
1271
-     */
1272
-    protected function _get_dtt_attached_tickets_row(
1273
-        $datetime_row,
1274
-        $datetime,
1275
-        $datetime_tickets = array(),
1276
-        $all_tickets = array(),
1277
-        $default
1278
-    ) {
1279
-        $template_args = array(
1280
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1281
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1282
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1283
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1284
-            'show_tickets_row'                  => ' style="display:none;"',
1285
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1286
-                'add_new_ticket_via_datetime',
1287
-                $this->_adminpage_obj->page_slug,
1288
-                $this->_adminpage_obj->get_req_action(),
1289
-                false,
1290
-                false
1291
-            ),
1292
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1293
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1294
-        );
1295
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1296
-        if (! $default) {
1297
-            $ticket_row = 1;
1298
-            foreach ($all_tickets as $ticket) {
1299
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1300
-                    $datetime_row,
1301
-                    $ticket_row,
1302
-                    $datetime,
1303
-                    $ticket,
1304
-                    $datetime_tickets,
1305
-                    $default
1306
-                );
1307
-                $ticket_row++;
1308
-            }
1309
-        }
1310
-        // filter template args at this point
1311
-        $template_args = apply_filters(
1312
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1313
-            $template_args,
1314
-            $datetime_row,
1315
-            $datetime,
1316
-            $datetime_tickets,
1317
-            $all_tickets,
1318
-            $default,
1319
-            $this->_is_creating_event
1320
-        );
1321
-        return EEH_Template::display_template(
1322
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1323
-            $template_args,
1324
-            true
1325
-        );
1326
-    }
1262
+	/**
1263
+	 * @param int         $datetime_row
1264
+	 * @param EE_Datetime $datetime
1265
+	 * @param array       $datetime_tickets
1266
+	 * @param array       $all_tickets
1267
+	 * @param bool        $default
1268
+	 * @return mixed
1269
+	 * @throws DomainException
1270
+	 * @throws EE_Error
1271
+	 */
1272
+	protected function _get_dtt_attached_tickets_row(
1273
+		$datetime_row,
1274
+		$datetime,
1275
+		$datetime_tickets = array(),
1276
+		$all_tickets = array(),
1277
+		$default
1278
+	) {
1279
+		$template_args = array(
1280
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1281
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1282
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1283
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1284
+			'show_tickets_row'                  => ' style="display:none;"',
1285
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1286
+				'add_new_ticket_via_datetime',
1287
+				$this->_adminpage_obj->page_slug,
1288
+				$this->_adminpage_obj->get_req_action(),
1289
+				false,
1290
+				false
1291
+			),
1292
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1293
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1294
+		);
1295
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1296
+		if (! $default) {
1297
+			$ticket_row = 1;
1298
+			foreach ($all_tickets as $ticket) {
1299
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1300
+					$datetime_row,
1301
+					$ticket_row,
1302
+					$datetime,
1303
+					$ticket,
1304
+					$datetime_tickets,
1305
+					$default
1306
+				);
1307
+				$ticket_row++;
1308
+			}
1309
+		}
1310
+		// filter template args at this point
1311
+		$template_args = apply_filters(
1312
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1313
+			$template_args,
1314
+			$datetime_row,
1315
+			$datetime,
1316
+			$datetime_tickets,
1317
+			$all_tickets,
1318
+			$default,
1319
+			$this->_is_creating_event
1320
+		);
1321
+		return EEH_Template::display_template(
1322
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1323
+			$template_args,
1324
+			true
1325
+		);
1326
+	}
1327 1327
 
1328 1328
 
1329
-    /**
1330
-     * @param int         $datetime_row
1331
-     * @param int         $ticket_row
1332
-     * @param EE_Datetime $datetime
1333
-     * @param EE_Ticket   $ticket
1334
-     * @param array       $datetime_tickets
1335
-     * @param bool        $default
1336
-     * @return mixed
1337
-     * @throws DomainException
1338
-     * @throws EE_Error
1339
-     */
1340
-    protected function _get_datetime_tickets_list_item(
1341
-        $datetime_row,
1342
-        $ticket_row,
1343
-        $datetime,
1344
-        $ticket,
1345
-        $datetime_tickets = array(),
1346
-        $default
1347
-    ) {
1348
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1349
-            ? $datetime_tickets[ $datetime->ID() ]
1350
-            : array();
1351
-        $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1352
-        $no_ticket = $default && empty($ticket);
1353
-        $template_args = array(
1354
-            'dtt_row'                 => $default
1355
-                ? 'DTTNUM'
1356
-                : $datetime_row,
1357
-            'tkt_row'                 => $no_ticket
1358
-                ? 'TICKETNUM'
1359
-                : $ticket_row,
1360
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1361
-                ? ' checked="checked"'
1362
-                : '',
1363
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1364
-                ? ' ticket-selected'
1365
-                : '',
1366
-            'TKT_name'                => $no_ticket
1367
-                ? 'TKTNAME'
1368
-                : $ticket->get('TKT_name'),
1369
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1370
-                ? ' tkt-status-' . EE_Ticket::onsale
1371
-                : ' tkt-status-' . $ticket->ticket_status(),
1372
-        );
1373
-        // filter template args
1374
-        $template_args = apply_filters(
1375
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1376
-            $template_args,
1377
-            $datetime_row,
1378
-            $ticket_row,
1379
-            $datetime,
1380
-            $ticket,
1381
-            $datetime_tickets,
1382
-            $default,
1383
-            $this->_is_creating_event
1384
-        );
1385
-        return EEH_Template::display_template(
1386
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1387
-            $template_args,
1388
-            true
1389
-        );
1390
-    }
1329
+	/**
1330
+	 * @param int         $datetime_row
1331
+	 * @param int         $ticket_row
1332
+	 * @param EE_Datetime $datetime
1333
+	 * @param EE_Ticket   $ticket
1334
+	 * @param array       $datetime_tickets
1335
+	 * @param bool        $default
1336
+	 * @return mixed
1337
+	 * @throws DomainException
1338
+	 * @throws EE_Error
1339
+	 */
1340
+	protected function _get_datetime_tickets_list_item(
1341
+		$datetime_row,
1342
+		$ticket_row,
1343
+		$datetime,
1344
+		$ticket,
1345
+		$datetime_tickets = array(),
1346
+		$default
1347
+	) {
1348
+		$dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1349
+			? $datetime_tickets[ $datetime->ID() ]
1350
+			: array();
1351
+		$display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1352
+		$no_ticket = $default && empty($ticket);
1353
+		$template_args = array(
1354
+			'dtt_row'                 => $default
1355
+				? 'DTTNUM'
1356
+				: $datetime_row,
1357
+			'tkt_row'                 => $no_ticket
1358
+				? 'TICKETNUM'
1359
+				: $ticket_row,
1360
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1361
+				? ' checked="checked"'
1362
+				: '',
1363
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1364
+				? ' ticket-selected'
1365
+				: '',
1366
+			'TKT_name'                => $no_ticket
1367
+				? 'TKTNAME'
1368
+				: $ticket->get('TKT_name'),
1369
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1370
+				? ' tkt-status-' . EE_Ticket::onsale
1371
+				: ' tkt-status-' . $ticket->ticket_status(),
1372
+		);
1373
+		// filter template args
1374
+		$template_args = apply_filters(
1375
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1376
+			$template_args,
1377
+			$datetime_row,
1378
+			$ticket_row,
1379
+			$datetime,
1380
+			$ticket,
1381
+			$datetime_tickets,
1382
+			$default,
1383
+			$this->_is_creating_event
1384
+		);
1385
+		return EEH_Template::display_template(
1386
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1387
+			$template_args,
1388
+			true
1389
+		);
1390
+	}
1391 1391
 
1392 1392
 
1393
-    /**
1394
-     * This generates the ticket row for tickets.
1395
-     * This same method is used to generate both the actual rows and the js skeleton row
1396
-     * (when default === true)
1397
-     *
1398
-     * @param int           $ticket_row       Represents the row number being generated.
1399
-     * @param               $ticket
1400
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1401
-     *                                        or empty for default
1402
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1403
-     * @param bool          $default          Whether default row being generated or not.
1404
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1405
-     *                                        (or empty in the case of defaults)
1406
-     * @return mixed
1407
-     * @throws InvalidArgumentException
1408
-     * @throws InvalidInterfaceException
1409
-     * @throws InvalidDataTypeException
1410
-     * @throws DomainException
1411
-     * @throws EE_Error
1412
-     * @throws ReflectionException
1413
-     */
1414
-    protected function _get_ticket_row(
1415
-        $ticket_row,
1416
-        $ticket,
1417
-        $ticket_datetimes,
1418
-        $all_datetimes,
1419
-        $default = false,
1420
-        $all_tickets = array()
1421
-    ) {
1422
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1423
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1424
-        $prices = ! empty($ticket) && ! $default
1425
-            ? $ticket->get_many_related(
1426
-                'Price',
1427
-                array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1428
-            )
1429
-            : array();
1430
-        // if there is only one price (which would be the base price)
1431
-        // or NO prices and this ticket is a default ticket,
1432
-        // let's just make sure there are no cached default prices on the object.
1433
-        // This is done by not including any query_params.
1434
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1435
-            $prices = $ticket->prices();
1436
-        }
1437
-        // check if we're dealing with a default ticket in which case
1438
-        // we don't want any starting_ticket_datetime_row values set
1439
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1440
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1441
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1442
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1443
-            ? $ticket_datetimes[ $ticket->ID() ]
1444
-            : array();
1445
-        $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1446
-        $base_price = $default ? null : $ticket->base_price();
1447
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1448
-        // breaking out complicated condition for ticket_status
1449
-        if ($default) {
1450
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1451
-        } else {
1452
-            $ticket_status_class = $ticket->is_default()
1453
-                ? ' tkt-status-' . EE_Ticket::onsale
1454
-                : ' tkt-status-' . $ticket->ticket_status();
1455
-        }
1456
-        // breaking out complicated condition for TKT_taxable
1457
-        if ($default) {
1458
-            $TKT_taxable = '';
1459
-        } else {
1460
-            $TKT_taxable = $ticket->taxable()
1461
-                ? ' checked="checked"'
1462
-                : '';
1463
-        }
1464
-        if ($default) {
1465
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1466
-        } elseif ($ticket->is_default()) {
1467
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1468
-        } else {
1469
-            $TKT_status = $ticket->ticket_status(true);
1470
-        }
1471
-        if ($default) {
1472
-            $TKT_min = '';
1473
-        } else {
1474
-            $TKT_min = $ticket->min();
1475
-            if ($TKT_min === -1 || $TKT_min === 0) {
1476
-                $TKT_min = '';
1477
-            }
1478
-        }
1479
-        $template_args = array(
1480
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1481
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1482
-            // on initial page load this will always be the correct order.
1483
-            'tkt_status_class'              => $ticket_status_class,
1484
-            'display_edit_tkt_row'          => ' style="display:none;"',
1485
-            'edit_tkt_expanded'             => '',
1486
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1487
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1488
-            'TKT_start_date'                => $default
1489
-                ? ''
1490
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1491
-            'TKT_end_date'                  => $default
1492
-                ? ''
1493
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1494
-            'TKT_status'                    => $TKT_status,
1495
-            'TKT_price'                     => $default
1496
-                ? ''
1497
-                : EEH_Template::format_currency(
1498
-                    $ticket->get_ticket_total_with_taxes(),
1499
-                    false,
1500
-                    false
1501
-                ),
1502
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1503
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1504
-            'TKT_qty'                       => $default
1505
-                ? ''
1506
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1507
-            'TKT_qty_for_input'             => $default
1508
-                ? ''
1509
-                : $ticket->get_pretty('TKT_qty', 'input'),
1510
-            'TKT_uses'                      => $default
1511
-                ? ''
1512
-                : $ticket->get_pretty('TKT_uses', 'input'),
1513
-            'TKT_min'                       => $TKT_min,
1514
-            'TKT_max'                       => $default
1515
-                ? ''
1516
-                : $ticket->get_pretty('TKT_max', 'input'),
1517
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1518
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1519
-            'TKT_registrations'             => $default
1520
-                ? 0
1521
-                : $ticket->count_registrations(
1522
-                    array(
1523
-                        array(
1524
-                            'STS_ID' => array(
1525
-                                '!=',
1526
-                                EEM_Registration::status_id_incomplete,
1527
-                            ),
1528
-                        ),
1529
-                    )
1530
-                ),
1531
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1532
-            'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1533
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1534
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1535
-            'TKT_is_default_selector'       => '',
1536
-            'ticket_price_rows'             => '',
1537
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1538
-                ? ''
1539
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1540
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1541
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1542
-                ? ''
1543
-                : ' style="display:none;"',
1544
-            'show_price_mod_button'         => count($prices) > 1
1545
-                                               || ($default && $count_price_mods > 0)
1546
-                                               || (! $default && $ticket->deleted())
1547
-                ? ' style="display:none;"'
1548
-                : '',
1549
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1550
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1551
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1552
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1553
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1554
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1555
-            'TKT_taxable'                   => $TKT_taxable,
1556
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1557
-                ? ''
1558
-                : ' style="display:none"',
1559
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1560
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1561
-                $ticket_subtotal,
1562
-                false,
1563
-                false
1564
-            ),
1565
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1566
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1567
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1568
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1569
-                ? ' ticket-archived'
1570
-                : '',
1571
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1572
-                                               && $ticket->deleted()
1573
-                                               && ! $ticket->is_permanently_deleteable()
1574
-                ? 'ee-lock-icon '
1575
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1576
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1577
-                ? ''
1578
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1579
-        );
1580
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1581
-            ? ' style="display:none"'
1582
-            : '';
1583
-        // handle rows that should NOT be empty
1584
-        if (empty($template_args['TKT_start_date'])) {
1585
-            // if empty then the start date will be now.
1586
-            $template_args['TKT_start_date'] = date(
1587
-                $this->_date_time_format,
1588
-                current_time('timestamp')
1589
-            );
1590
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1591
-        }
1592
-        if (empty($template_args['TKT_end_date'])) {
1593
-            // get the earliest datetime (if present);
1594
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1595
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1596
-                    'Datetime',
1597
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1598
-                )
1599
-                : null;
1600
-            if (! empty($earliest_dtt)) {
1601
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1602
-                    'DTT_EVT_start',
1603
-                    $this->_date_time_format
1604
-                );
1605
-            } else {
1606
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1607
-                $template_args['TKT_end_date'] = date(
1608
-                    $this->_date_time_format,
1609
-                    mktime(
1610
-                        24,
1611
-                        0,
1612
-                        0,
1613
-                        date('m'),
1614
-                        date('d') + 29,
1615
-                        date('Y')
1616
-                    )
1617
-                );
1618
-            }
1619
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1620
-        }
1621
-        // generate ticket_datetime items
1622
-        if (! $default) {
1623
-            $datetime_row = 1;
1624
-            foreach ($all_datetimes as $datetime) {
1625
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1626
-                    $datetime_row,
1627
-                    $ticket_row,
1628
-                    $datetime,
1629
-                    $ticket,
1630
-                    $ticket_datetimes,
1631
-                    $default
1632
-                );
1633
-                $datetime_row++;
1634
-            }
1635
-        }
1636
-        $price_row = 1;
1637
-        foreach ($prices as $price) {
1638
-            if (! $price instanceof EE_Price) {
1639
-                continue;
1640
-            }
1641
-            if ($price->is_base_price()) {
1642
-                $price_row++;
1643
-                continue;
1644
-            }
1645
-            $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1646
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1647
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1648
-                $ticket_row,
1649
-                $price_row,
1650
-                $price,
1651
-                $default,
1652
-                $ticket,
1653
-                $show_trash,
1654
-                $show_create
1655
-            );
1656
-            $price_row++;
1657
-        }
1658
-        // filter $template_args
1659
-        $template_args = apply_filters(
1660
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1661
-            $template_args,
1662
-            $ticket_row,
1663
-            $ticket,
1664
-            $ticket_datetimes,
1665
-            $all_datetimes,
1666
-            $default,
1667
-            $all_tickets,
1668
-            $this->_is_creating_event
1669
-        );
1670
-        return EEH_Template::display_template(
1671
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1672
-            $template_args,
1673
-            true
1674
-        );
1675
-    }
1393
+	/**
1394
+	 * This generates the ticket row for tickets.
1395
+	 * This same method is used to generate both the actual rows and the js skeleton row
1396
+	 * (when default === true)
1397
+	 *
1398
+	 * @param int           $ticket_row       Represents the row number being generated.
1399
+	 * @param               $ticket
1400
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1401
+	 *                                        or empty for default
1402
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1403
+	 * @param bool          $default          Whether default row being generated or not.
1404
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1405
+	 *                                        (or empty in the case of defaults)
1406
+	 * @return mixed
1407
+	 * @throws InvalidArgumentException
1408
+	 * @throws InvalidInterfaceException
1409
+	 * @throws InvalidDataTypeException
1410
+	 * @throws DomainException
1411
+	 * @throws EE_Error
1412
+	 * @throws ReflectionException
1413
+	 */
1414
+	protected function _get_ticket_row(
1415
+		$ticket_row,
1416
+		$ticket,
1417
+		$ticket_datetimes,
1418
+		$all_datetimes,
1419
+		$default = false,
1420
+		$all_tickets = array()
1421
+	) {
1422
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1423
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1424
+		$prices = ! empty($ticket) && ! $default
1425
+			? $ticket->get_many_related(
1426
+				'Price',
1427
+				array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1428
+			)
1429
+			: array();
1430
+		// if there is only one price (which would be the base price)
1431
+		// or NO prices and this ticket is a default ticket,
1432
+		// let's just make sure there are no cached default prices on the object.
1433
+		// This is done by not including any query_params.
1434
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1435
+			$prices = $ticket->prices();
1436
+		}
1437
+		// check if we're dealing with a default ticket in which case
1438
+		// we don't want any starting_ticket_datetime_row values set
1439
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1440
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1441
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1442
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1443
+			? $ticket_datetimes[ $ticket->ID() ]
1444
+			: array();
1445
+		$ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1446
+		$base_price = $default ? null : $ticket->base_price();
1447
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1448
+		// breaking out complicated condition for ticket_status
1449
+		if ($default) {
1450
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1451
+		} else {
1452
+			$ticket_status_class = $ticket->is_default()
1453
+				? ' tkt-status-' . EE_Ticket::onsale
1454
+				: ' tkt-status-' . $ticket->ticket_status();
1455
+		}
1456
+		// breaking out complicated condition for TKT_taxable
1457
+		if ($default) {
1458
+			$TKT_taxable = '';
1459
+		} else {
1460
+			$TKT_taxable = $ticket->taxable()
1461
+				? ' checked="checked"'
1462
+				: '';
1463
+		}
1464
+		if ($default) {
1465
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1466
+		} elseif ($ticket->is_default()) {
1467
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1468
+		} else {
1469
+			$TKT_status = $ticket->ticket_status(true);
1470
+		}
1471
+		if ($default) {
1472
+			$TKT_min = '';
1473
+		} else {
1474
+			$TKT_min = $ticket->min();
1475
+			if ($TKT_min === -1 || $TKT_min === 0) {
1476
+				$TKT_min = '';
1477
+			}
1478
+		}
1479
+		$template_args = array(
1480
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1481
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1482
+			// on initial page load this will always be the correct order.
1483
+			'tkt_status_class'              => $ticket_status_class,
1484
+			'display_edit_tkt_row'          => ' style="display:none;"',
1485
+			'edit_tkt_expanded'             => '',
1486
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1487
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1488
+			'TKT_start_date'                => $default
1489
+				? ''
1490
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1491
+			'TKT_end_date'                  => $default
1492
+				? ''
1493
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1494
+			'TKT_status'                    => $TKT_status,
1495
+			'TKT_price'                     => $default
1496
+				? ''
1497
+				: EEH_Template::format_currency(
1498
+					$ticket->get_ticket_total_with_taxes(),
1499
+					false,
1500
+					false
1501
+				),
1502
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1503
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1504
+			'TKT_qty'                       => $default
1505
+				? ''
1506
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1507
+			'TKT_qty_for_input'             => $default
1508
+				? ''
1509
+				: $ticket->get_pretty('TKT_qty', 'input'),
1510
+			'TKT_uses'                      => $default
1511
+				? ''
1512
+				: $ticket->get_pretty('TKT_uses', 'input'),
1513
+			'TKT_min'                       => $TKT_min,
1514
+			'TKT_max'                       => $default
1515
+				? ''
1516
+				: $ticket->get_pretty('TKT_max', 'input'),
1517
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1518
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1519
+			'TKT_registrations'             => $default
1520
+				? 0
1521
+				: $ticket->count_registrations(
1522
+					array(
1523
+						array(
1524
+							'STS_ID' => array(
1525
+								'!=',
1526
+								EEM_Registration::status_id_incomplete,
1527
+							),
1528
+						),
1529
+					)
1530
+				),
1531
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1532
+			'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1533
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1534
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1535
+			'TKT_is_default_selector'       => '',
1536
+			'ticket_price_rows'             => '',
1537
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1538
+				? ''
1539
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1540
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1541
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1542
+				? ''
1543
+				: ' style="display:none;"',
1544
+			'show_price_mod_button'         => count($prices) > 1
1545
+											   || ($default && $count_price_mods > 0)
1546
+											   || (! $default && $ticket->deleted())
1547
+				? ' style="display:none;"'
1548
+				: '',
1549
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1550
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1551
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1552
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1553
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1554
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1555
+			'TKT_taxable'                   => $TKT_taxable,
1556
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1557
+				? ''
1558
+				: ' style="display:none"',
1559
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1560
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1561
+				$ticket_subtotal,
1562
+				false,
1563
+				false
1564
+			),
1565
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1566
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1567
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1568
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1569
+				? ' ticket-archived'
1570
+				: '',
1571
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1572
+											   && $ticket->deleted()
1573
+											   && ! $ticket->is_permanently_deleteable()
1574
+				? 'ee-lock-icon '
1575
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1576
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1577
+				? ''
1578
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1579
+		);
1580
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1581
+			? ' style="display:none"'
1582
+			: '';
1583
+		// handle rows that should NOT be empty
1584
+		if (empty($template_args['TKT_start_date'])) {
1585
+			// if empty then the start date will be now.
1586
+			$template_args['TKT_start_date'] = date(
1587
+				$this->_date_time_format,
1588
+				current_time('timestamp')
1589
+			);
1590
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1591
+		}
1592
+		if (empty($template_args['TKT_end_date'])) {
1593
+			// get the earliest datetime (if present);
1594
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1595
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1596
+					'Datetime',
1597
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1598
+				)
1599
+				: null;
1600
+			if (! empty($earliest_dtt)) {
1601
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1602
+					'DTT_EVT_start',
1603
+					$this->_date_time_format
1604
+				);
1605
+			} else {
1606
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1607
+				$template_args['TKT_end_date'] = date(
1608
+					$this->_date_time_format,
1609
+					mktime(
1610
+						24,
1611
+						0,
1612
+						0,
1613
+						date('m'),
1614
+						date('d') + 29,
1615
+						date('Y')
1616
+					)
1617
+				);
1618
+			}
1619
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1620
+		}
1621
+		// generate ticket_datetime items
1622
+		if (! $default) {
1623
+			$datetime_row = 1;
1624
+			foreach ($all_datetimes as $datetime) {
1625
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1626
+					$datetime_row,
1627
+					$ticket_row,
1628
+					$datetime,
1629
+					$ticket,
1630
+					$ticket_datetimes,
1631
+					$default
1632
+				);
1633
+				$datetime_row++;
1634
+			}
1635
+		}
1636
+		$price_row = 1;
1637
+		foreach ($prices as $price) {
1638
+			if (! $price instanceof EE_Price) {
1639
+				continue;
1640
+			}
1641
+			if ($price->is_base_price()) {
1642
+				$price_row++;
1643
+				continue;
1644
+			}
1645
+			$show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1646
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1647
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1648
+				$ticket_row,
1649
+				$price_row,
1650
+				$price,
1651
+				$default,
1652
+				$ticket,
1653
+				$show_trash,
1654
+				$show_create
1655
+			);
1656
+			$price_row++;
1657
+		}
1658
+		// filter $template_args
1659
+		$template_args = apply_filters(
1660
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1661
+			$template_args,
1662
+			$ticket_row,
1663
+			$ticket,
1664
+			$ticket_datetimes,
1665
+			$all_datetimes,
1666
+			$default,
1667
+			$all_tickets,
1668
+			$this->_is_creating_event
1669
+		);
1670
+		return EEH_Template::display_template(
1671
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1672
+			$template_args,
1673
+			true
1674
+		);
1675
+	}
1676 1676
 
1677 1677
 
1678
-    /**
1679
-     * @param int            $ticket_row
1680
-     * @param EE_Ticket|null $ticket
1681
-     * @return string
1682
-     * @throws DomainException
1683
-     * @throws EE_Error
1684
-     */
1685
-    protected function _get_tax_rows($ticket_row, $ticket)
1686
-    {
1687
-        $tax_rows = '';
1688
-        /** @var EE_Price[] $taxes */
1689
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1690
-        foreach ($taxes as $tax) {
1691
-            $tax_added = $this->_get_tax_added($tax, $ticket);
1692
-            $template_args = array(
1693
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1694
-                    ? ''
1695
-                    : ' style="display:none;"',
1696
-                'tax_id'            => $tax->ID(),
1697
-                'tkt_row'           => $ticket_row,
1698
-                'tax_label'         => $tax->get('PRC_name'),
1699
-                'tax_added'         => $tax_added,
1700
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1701
-                'tax_amount'        => $tax->get('PRC_amount'),
1702
-            );
1703
-            $template_args = apply_filters(
1704
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1705
-                $template_args,
1706
-                $ticket_row,
1707
-                $ticket,
1708
-                $this->_is_creating_event
1709
-            );
1710
-            $tax_rows .= EEH_Template::display_template(
1711
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1712
-                $template_args,
1713
-                true
1714
-            );
1715
-        }
1716
-        return $tax_rows;
1717
-    }
1678
+	/**
1679
+	 * @param int            $ticket_row
1680
+	 * @param EE_Ticket|null $ticket
1681
+	 * @return string
1682
+	 * @throws DomainException
1683
+	 * @throws EE_Error
1684
+	 */
1685
+	protected function _get_tax_rows($ticket_row, $ticket)
1686
+	{
1687
+		$tax_rows = '';
1688
+		/** @var EE_Price[] $taxes */
1689
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1690
+		foreach ($taxes as $tax) {
1691
+			$tax_added = $this->_get_tax_added($tax, $ticket);
1692
+			$template_args = array(
1693
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1694
+					? ''
1695
+					: ' style="display:none;"',
1696
+				'tax_id'            => $tax->ID(),
1697
+				'tkt_row'           => $ticket_row,
1698
+				'tax_label'         => $tax->get('PRC_name'),
1699
+				'tax_added'         => $tax_added,
1700
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1701
+				'tax_amount'        => $tax->get('PRC_amount'),
1702
+			);
1703
+			$template_args = apply_filters(
1704
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1705
+				$template_args,
1706
+				$ticket_row,
1707
+				$ticket,
1708
+				$this->_is_creating_event
1709
+			);
1710
+			$tax_rows .= EEH_Template::display_template(
1711
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1712
+				$template_args,
1713
+				true
1714
+			);
1715
+		}
1716
+		return $tax_rows;
1717
+	}
1718 1718
 
1719 1719
 
1720
-    /**
1721
-     * @param EE_Price       $tax
1722
-     * @param EE_Ticket|null $ticket
1723
-     * @return float|int
1724
-     * @throws EE_Error
1725
-     */
1726
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1727
-    {
1728
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1729
-        return $subtotal * $tax->get('PRC_amount') / 100;
1730
-    }
1720
+	/**
1721
+	 * @param EE_Price       $tax
1722
+	 * @param EE_Ticket|null $ticket
1723
+	 * @return float|int
1724
+	 * @throws EE_Error
1725
+	 */
1726
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1727
+	{
1728
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1729
+		return $subtotal * $tax->get('PRC_amount') / 100;
1730
+	}
1731 1731
 
1732 1732
 
1733
-    /**
1734
-     * @param int            $ticket_row
1735
-     * @param int            $price_row
1736
-     * @param EE_Price|null  $price
1737
-     * @param bool           $default
1738
-     * @param EE_Ticket|null $ticket
1739
-     * @param bool           $show_trash
1740
-     * @param bool           $show_create
1741
-     * @return mixed
1742
-     * @throws InvalidArgumentException
1743
-     * @throws InvalidInterfaceException
1744
-     * @throws InvalidDataTypeException
1745
-     * @throws DomainException
1746
-     * @throws EE_Error
1747
-     * @throws ReflectionException
1748
-     */
1749
-    protected function _get_ticket_price_row(
1750
-        $ticket_row,
1751
-        $price_row,
1752
-        $price,
1753
-        $default,
1754
-        $ticket,
1755
-        $show_trash = true,
1756
-        $show_create = true
1757
-    ) {
1758
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1759
-        $template_args = array(
1760
-            'tkt_row'               => $default && empty($ticket)
1761
-                ? 'TICKETNUM'
1762
-                : $ticket_row,
1763
-            'PRC_order'             => $default && empty($price)
1764
-                ? 'PRICENUM'
1765
-                : $price_row,
1766
-            'edit_prices_name'      => $default && empty($price)
1767
-                ? 'PRICENAMEATTR'
1768
-                : 'edit_prices',
1769
-            'price_type_selector'   => $default && empty($price)
1770
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1771
-                : $this->_get_price_type_selector(
1772
-                    $ticket_row,
1773
-                    $price_row,
1774
-                    $price,
1775
-                    $default,
1776
-                    $send_disabled
1777
-                ),
1778
-            'PRC_ID'                => $default && empty($price)
1779
-                ? 0
1780
-                : $price->ID(),
1781
-            'PRC_is_default'        => $default && empty($price)
1782
-                ? 0
1783
-                : $price->get('PRC_is_default'),
1784
-            'PRC_name'              => $default && empty($price)
1785
-                ? ''
1786
-                : $price->get('PRC_name'),
1787
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1788
-            'show_plus_or_minus'    => $default && empty($price)
1789
-                ? ''
1790
-                : ' style="display:none;"',
1791
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1792
-                ? ' style="display:none;"'
1793
-                : '',
1794
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1795
-                ? ' style="display:none;"'
1796
-                : '',
1797
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1798
-                ? ' style="display:none"'
1799
-                : '',
1800
-            'PRC_amount'            => $default && empty($price)
1801
-                ? 0
1802
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1803
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1804
-                ? ' style="display:none;"'
1805
-                : '',
1806
-            'show_trash_icon'       => $show_trash
1807
-                ? ''
1808
-                : ' style="display:none;"',
1809
-            'show_create_button'    => $show_create
1810
-                ? ''
1811
-                : ' style="display:none;"',
1812
-            'PRC_desc'              => $default && empty($price)
1813
-                ? ''
1814
-                : $price->get('PRC_desc'),
1815
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1816
-        );
1817
-        $template_args = apply_filters(
1818
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1819
-            $template_args,
1820
-            $ticket_row,
1821
-            $price_row,
1822
-            $price,
1823
-            $default,
1824
-            $ticket,
1825
-            $show_trash,
1826
-            $show_create,
1827
-            $this->_is_creating_event
1828
-        );
1829
-        return EEH_Template::display_template(
1830
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1831
-            $template_args,
1832
-            true
1833
-        );
1834
-    }
1733
+	/**
1734
+	 * @param int            $ticket_row
1735
+	 * @param int            $price_row
1736
+	 * @param EE_Price|null  $price
1737
+	 * @param bool           $default
1738
+	 * @param EE_Ticket|null $ticket
1739
+	 * @param bool           $show_trash
1740
+	 * @param bool           $show_create
1741
+	 * @return mixed
1742
+	 * @throws InvalidArgumentException
1743
+	 * @throws InvalidInterfaceException
1744
+	 * @throws InvalidDataTypeException
1745
+	 * @throws DomainException
1746
+	 * @throws EE_Error
1747
+	 * @throws ReflectionException
1748
+	 */
1749
+	protected function _get_ticket_price_row(
1750
+		$ticket_row,
1751
+		$price_row,
1752
+		$price,
1753
+		$default,
1754
+		$ticket,
1755
+		$show_trash = true,
1756
+		$show_create = true
1757
+	) {
1758
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1759
+		$template_args = array(
1760
+			'tkt_row'               => $default && empty($ticket)
1761
+				? 'TICKETNUM'
1762
+				: $ticket_row,
1763
+			'PRC_order'             => $default && empty($price)
1764
+				? 'PRICENUM'
1765
+				: $price_row,
1766
+			'edit_prices_name'      => $default && empty($price)
1767
+				? 'PRICENAMEATTR'
1768
+				: 'edit_prices',
1769
+			'price_type_selector'   => $default && empty($price)
1770
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1771
+				: $this->_get_price_type_selector(
1772
+					$ticket_row,
1773
+					$price_row,
1774
+					$price,
1775
+					$default,
1776
+					$send_disabled
1777
+				),
1778
+			'PRC_ID'                => $default && empty($price)
1779
+				? 0
1780
+				: $price->ID(),
1781
+			'PRC_is_default'        => $default && empty($price)
1782
+				? 0
1783
+				: $price->get('PRC_is_default'),
1784
+			'PRC_name'              => $default && empty($price)
1785
+				? ''
1786
+				: $price->get('PRC_name'),
1787
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1788
+			'show_plus_or_minus'    => $default && empty($price)
1789
+				? ''
1790
+				: ' style="display:none;"',
1791
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1792
+				? ' style="display:none;"'
1793
+				: '',
1794
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1795
+				? ' style="display:none;"'
1796
+				: '',
1797
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1798
+				? ' style="display:none"'
1799
+				: '',
1800
+			'PRC_amount'            => $default && empty($price)
1801
+				? 0
1802
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1803
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1804
+				? ' style="display:none;"'
1805
+				: '',
1806
+			'show_trash_icon'       => $show_trash
1807
+				? ''
1808
+				: ' style="display:none;"',
1809
+			'show_create_button'    => $show_create
1810
+				? ''
1811
+				: ' style="display:none;"',
1812
+			'PRC_desc'              => $default && empty($price)
1813
+				? ''
1814
+				: $price->get('PRC_desc'),
1815
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1816
+		);
1817
+		$template_args = apply_filters(
1818
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1819
+			$template_args,
1820
+			$ticket_row,
1821
+			$price_row,
1822
+			$price,
1823
+			$default,
1824
+			$ticket,
1825
+			$show_trash,
1826
+			$show_create,
1827
+			$this->_is_creating_event
1828
+		);
1829
+		return EEH_Template::display_template(
1830
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1831
+			$template_args,
1832
+			true
1833
+		);
1834
+	}
1835 1835
 
1836 1836
 
1837
-    /**
1838
-     * @param int      $ticket_row
1839
-     * @param int      $price_row
1840
-     * @param EE_Price $price
1841
-     * @param bool     $default
1842
-     * @param bool     $disabled
1843
-     * @return mixed
1844
-     * @throws ReflectionException
1845
-     * @throws InvalidArgumentException
1846
-     * @throws InvalidInterfaceException
1847
-     * @throws InvalidDataTypeException
1848
-     * @throws DomainException
1849
-     * @throws EE_Error
1850
-     */
1851
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1852
-    {
1853
-        if ($price->is_base_price()) {
1854
-            return $this->_get_base_price_template(
1855
-                $ticket_row,
1856
-                $price_row,
1857
-                $price,
1858
-                $default
1859
-            );
1860
-        }
1861
-        return $this->_get_price_modifier_template(
1862
-            $ticket_row,
1863
-            $price_row,
1864
-            $price,
1865
-            $default,
1866
-            $disabled
1867
-        );
1868
-    }
1837
+	/**
1838
+	 * @param int      $ticket_row
1839
+	 * @param int      $price_row
1840
+	 * @param EE_Price $price
1841
+	 * @param bool     $default
1842
+	 * @param bool     $disabled
1843
+	 * @return mixed
1844
+	 * @throws ReflectionException
1845
+	 * @throws InvalidArgumentException
1846
+	 * @throws InvalidInterfaceException
1847
+	 * @throws InvalidDataTypeException
1848
+	 * @throws DomainException
1849
+	 * @throws EE_Error
1850
+	 */
1851
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1852
+	{
1853
+		if ($price->is_base_price()) {
1854
+			return $this->_get_base_price_template(
1855
+				$ticket_row,
1856
+				$price_row,
1857
+				$price,
1858
+				$default
1859
+			);
1860
+		}
1861
+		return $this->_get_price_modifier_template(
1862
+			$ticket_row,
1863
+			$price_row,
1864
+			$price,
1865
+			$default,
1866
+			$disabled
1867
+		);
1868
+	}
1869 1869
 
1870 1870
 
1871
-    /**
1872
-     * @param int      $ticket_row
1873
-     * @param int      $price_row
1874
-     * @param EE_Price $price
1875
-     * @param bool     $default
1876
-     * @return mixed
1877
-     * @throws DomainException
1878
-     * @throws EE_Error
1879
-     */
1880
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1881
-    {
1882
-        $template_args = array(
1883
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1884
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1885
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1886
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1887
-            'price_selected_operator'   => '+',
1888
-            'price_selected_is_percent' => 0,
1889
-        );
1890
-        $template_args = apply_filters(
1891
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1892
-            $template_args,
1893
-            $ticket_row,
1894
-            $price_row,
1895
-            $price,
1896
-            $default,
1897
-            $this->_is_creating_event
1898
-        );
1899
-        return EEH_Template::display_template(
1900
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1901
-            $template_args,
1902
-            true
1903
-        );
1904
-    }
1871
+	/**
1872
+	 * @param int      $ticket_row
1873
+	 * @param int      $price_row
1874
+	 * @param EE_Price $price
1875
+	 * @param bool     $default
1876
+	 * @return mixed
1877
+	 * @throws DomainException
1878
+	 * @throws EE_Error
1879
+	 */
1880
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1881
+	{
1882
+		$template_args = array(
1883
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1884
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1885
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1886
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1887
+			'price_selected_operator'   => '+',
1888
+			'price_selected_is_percent' => 0,
1889
+		);
1890
+		$template_args = apply_filters(
1891
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1892
+			$template_args,
1893
+			$ticket_row,
1894
+			$price_row,
1895
+			$price,
1896
+			$default,
1897
+			$this->_is_creating_event
1898
+		);
1899
+		return EEH_Template::display_template(
1900
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1901
+			$template_args,
1902
+			true
1903
+		);
1904
+	}
1905 1905
 
1906 1906
 
1907
-    /**
1908
-     * @param int      $ticket_row
1909
-     * @param int      $price_row
1910
-     * @param EE_Price $price
1911
-     * @param bool     $default
1912
-     * @param bool     $disabled
1913
-     * @return mixed
1914
-     * @throws ReflectionException
1915
-     * @throws InvalidArgumentException
1916
-     * @throws InvalidInterfaceException
1917
-     * @throws InvalidDataTypeException
1918
-     * @throws DomainException
1919
-     * @throws EE_Error
1920
-     */
1921
-    protected function _get_price_modifier_template(
1922
-        $ticket_row,
1923
-        $price_row,
1924
-        $price,
1925
-        $default,
1926
-        $disabled = false
1927
-    ) {
1928
-        $select_name = $default && ! $price instanceof EE_Price
1929
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1930
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1931
-        /** @var EEM_Price_Type $price_type_model */
1932
-        $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1933
-        $price_types = $price_type_model->get_all(array(
1934
-            array(
1935
-                'OR' => array(
1936
-                    'PBT_ID'  => '2',
1937
-                    'PBT_ID*' => '3',
1938
-                ),
1939
-            ),
1940
-        ));
1941
-        $all_price_types = $default && ! $price instanceof EE_Price
1942
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1943
-            : array();
1944
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1945
-        $price_option_spans = '';
1946
-        // setup price types for selector
1947
-        foreach ($price_types as $price_type) {
1948
-            if (! $price_type instanceof EE_Price_Type) {
1949
-                continue;
1950
-            }
1951
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1952
-            // while we're in the loop let's setup the option spans used by js
1953
-            $span_args = array(
1954
-                'PRT_ID'         => $price_type->ID(),
1955
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1956
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1957
-            );
1958
-            $price_option_spans .= EEH_Template::display_template(
1959
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1960
-                $span_args,
1961
-                true
1962
-            );
1963
-        }
1964
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1965
-            : $select_name;
1966
-        $select_input = new EE_Select_Input(
1967
-            $all_price_types,
1968
-            array(
1969
-                'default'               => $selected_price_type_id,
1970
-                'html_name'             => $select_name,
1971
-                'html_class'            => 'edit-price-PRT_ID',
1972
-                'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1973
-            )
1974
-        );
1975
-        $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1976
-        $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1977
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1978
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1979
-        $template_args = array(
1980
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1981
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1982
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1983
-            'main_name'                 => $select_name,
1984
-            'selected_price_type_id'    => $selected_price_type_id,
1985
-            'price_option_spans'        => $price_option_spans,
1986
-            'price_selected_operator'   => $price_selected_operator,
1987
-            'price_selected_is_percent' => $price_selected_is_percent,
1988
-            'disabled'                  => $disabled,
1989
-        );
1990
-        $template_args = apply_filters(
1991
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1992
-            $template_args,
1993
-            $ticket_row,
1994
-            $price_row,
1995
-            $price,
1996
-            $default,
1997
-            $disabled,
1998
-            $this->_is_creating_event
1999
-        );
2000
-        return EEH_Template::display_template(
2001
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2002
-            $template_args,
2003
-            true
2004
-        );
2005
-    }
1907
+	/**
1908
+	 * @param int      $ticket_row
1909
+	 * @param int      $price_row
1910
+	 * @param EE_Price $price
1911
+	 * @param bool     $default
1912
+	 * @param bool     $disabled
1913
+	 * @return mixed
1914
+	 * @throws ReflectionException
1915
+	 * @throws InvalidArgumentException
1916
+	 * @throws InvalidInterfaceException
1917
+	 * @throws InvalidDataTypeException
1918
+	 * @throws DomainException
1919
+	 * @throws EE_Error
1920
+	 */
1921
+	protected function _get_price_modifier_template(
1922
+		$ticket_row,
1923
+		$price_row,
1924
+		$price,
1925
+		$default,
1926
+		$disabled = false
1927
+	) {
1928
+		$select_name = $default && ! $price instanceof EE_Price
1929
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1930
+			: 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1931
+		/** @var EEM_Price_Type $price_type_model */
1932
+		$price_type_model = EE_Registry::instance()->load_model('Price_Type');
1933
+		$price_types = $price_type_model->get_all(array(
1934
+			array(
1935
+				'OR' => array(
1936
+					'PBT_ID'  => '2',
1937
+					'PBT_ID*' => '3',
1938
+				),
1939
+			),
1940
+		));
1941
+		$all_price_types = $default && ! $price instanceof EE_Price
1942
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1943
+			: array();
1944
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1945
+		$price_option_spans = '';
1946
+		// setup price types for selector
1947
+		foreach ($price_types as $price_type) {
1948
+			if (! $price_type instanceof EE_Price_Type) {
1949
+				continue;
1950
+			}
1951
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1952
+			// while we're in the loop let's setup the option spans used by js
1953
+			$span_args = array(
1954
+				'PRT_ID'         => $price_type->ID(),
1955
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1956
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1957
+			);
1958
+			$price_option_spans .= EEH_Template::display_template(
1959
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1960
+				$span_args,
1961
+				true
1962
+			);
1963
+		}
1964
+		$select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1965
+			: $select_name;
1966
+		$select_input = new EE_Select_Input(
1967
+			$all_price_types,
1968
+			array(
1969
+				'default'               => $selected_price_type_id,
1970
+				'html_name'             => $select_name,
1971
+				'html_class'            => 'edit-price-PRT_ID',
1972
+				'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1973
+			)
1974
+		);
1975
+		$price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1976
+		$price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1977
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1978
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1979
+		$template_args = array(
1980
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1981
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1982
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1983
+			'main_name'                 => $select_name,
1984
+			'selected_price_type_id'    => $selected_price_type_id,
1985
+			'price_option_spans'        => $price_option_spans,
1986
+			'price_selected_operator'   => $price_selected_operator,
1987
+			'price_selected_is_percent' => $price_selected_is_percent,
1988
+			'disabled'                  => $disabled,
1989
+		);
1990
+		$template_args = apply_filters(
1991
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1992
+			$template_args,
1993
+			$ticket_row,
1994
+			$price_row,
1995
+			$price,
1996
+			$default,
1997
+			$disabled,
1998
+			$this->_is_creating_event
1999
+		);
2000
+		return EEH_Template::display_template(
2001
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2002
+			$template_args,
2003
+			true
2004
+		);
2005
+	}
2006 2006
 
2007 2007
 
2008
-    /**
2009
-     * @param int              $datetime_row
2010
-     * @param int              $ticket_row
2011
-     * @param EE_Datetime|null $datetime
2012
-     * @param EE_Ticket|null   $ticket
2013
-     * @param array            $ticket_datetimes
2014
-     * @param bool             $default
2015
-     * @return mixed
2016
-     * @throws DomainException
2017
-     * @throws EE_Error
2018
-     */
2019
-    protected function _get_ticket_datetime_list_item(
2020
-        $datetime_row,
2021
-        $ticket_row,
2022
-        $datetime,
2023
-        $ticket,
2024
-        $ticket_datetimes = array(),
2025
-        $default
2026
-    ) {
2027
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2028
-            ? $ticket_datetimes[ $ticket->ID() ]
2029
-            : array();
2030
-        $template_args = array(
2031
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2032
-                ? 'DTTNUM'
2033
-                : $datetime_row,
2034
-            'tkt_row'                  => $default
2035
-                ? 'TICKETNUM'
2036
-                : $ticket_row,
2037
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2038
-                ? ' ticket-selected'
2039
-                : '',
2040
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2041
-                ? ' checked="checked"'
2042
-                : '',
2043
-            'DTT_name'                 => $default && empty($datetime)
2044
-                ? 'DTTNAME'
2045
-                : $datetime->get_dtt_display_name(true),
2046
-            'tkt_status_class'         => '',
2047
-        );
2048
-        $template_args = apply_filters(
2049
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2050
-            $template_args,
2051
-            $datetime_row,
2052
-            $ticket_row,
2053
-            $datetime,
2054
-            $ticket,
2055
-            $ticket_datetimes,
2056
-            $default,
2057
-            $this->_is_creating_event
2058
-        );
2059
-        return EEH_Template::display_template(
2060
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2061
-            $template_args,
2062
-            true
2063
-        );
2064
-    }
2008
+	/**
2009
+	 * @param int              $datetime_row
2010
+	 * @param int              $ticket_row
2011
+	 * @param EE_Datetime|null $datetime
2012
+	 * @param EE_Ticket|null   $ticket
2013
+	 * @param array            $ticket_datetimes
2014
+	 * @param bool             $default
2015
+	 * @return mixed
2016
+	 * @throws DomainException
2017
+	 * @throws EE_Error
2018
+	 */
2019
+	protected function _get_ticket_datetime_list_item(
2020
+		$datetime_row,
2021
+		$ticket_row,
2022
+		$datetime,
2023
+		$ticket,
2024
+		$ticket_datetimes = array(),
2025
+		$default
2026
+	) {
2027
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2028
+			? $ticket_datetimes[ $ticket->ID() ]
2029
+			: array();
2030
+		$template_args = array(
2031
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2032
+				? 'DTTNUM'
2033
+				: $datetime_row,
2034
+			'tkt_row'                  => $default
2035
+				? 'TICKETNUM'
2036
+				: $ticket_row,
2037
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2038
+				? ' ticket-selected'
2039
+				: '',
2040
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2041
+				? ' checked="checked"'
2042
+				: '',
2043
+			'DTT_name'                 => $default && empty($datetime)
2044
+				? 'DTTNAME'
2045
+				: $datetime->get_dtt_display_name(true),
2046
+			'tkt_status_class'         => '',
2047
+		);
2048
+		$template_args = apply_filters(
2049
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2050
+			$template_args,
2051
+			$datetime_row,
2052
+			$ticket_row,
2053
+			$datetime,
2054
+			$ticket,
2055
+			$ticket_datetimes,
2056
+			$default,
2057
+			$this->_is_creating_event
2058
+		);
2059
+		return EEH_Template::display_template(
2060
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2061
+			$template_args,
2062
+			true
2063
+		);
2064
+	}
2065 2065
 
2066 2066
 
2067
-    /**
2068
-     * @param array $all_datetimes
2069
-     * @param array $all_tickets
2070
-     * @return mixed
2071
-     * @throws ReflectionException
2072
-     * @throws InvalidArgumentException
2073
-     * @throws InvalidInterfaceException
2074
-     * @throws InvalidDataTypeException
2075
-     * @throws DomainException
2076
-     * @throws EE_Error
2077
-     */
2078
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2079
-    {
2080
-        $template_args = array(
2081
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2082
-                'DTTNUM',
2083
-                null,
2084
-                true,
2085
-                $all_datetimes
2086
-            ),
2087
-            'default_ticket_row'                       => $this->_get_ticket_row(
2088
-                'TICKETNUM',
2089
-                null,
2090
-                array(),
2091
-                array(),
2092
-                true
2093
-            ),
2094
-            'default_price_row'                        => $this->_get_ticket_price_row(
2095
-                'TICKETNUM',
2096
-                'PRICENUM',
2097
-                null,
2098
-                true,
2099
-                null
2100
-            ),
2101
-            'default_price_rows'                       => '',
2102
-            'default_base_price_amount'                => 0,
2103
-            'default_base_price_name'                  => '',
2104
-            'default_base_price_description'           => '',
2105
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2106
-                'TICKETNUM',
2107
-                'PRICENUM',
2108
-                null,
2109
-                true
2110
-            ),
2111
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2112
-                'DTTNUM',
2113
-                null,
2114
-                array(),
2115
-                array(),
2116
-                true
2117
-            ),
2118
-            'existing_available_datetime_tickets_list' => '',
2119
-            'existing_available_ticket_datetimes_list' => '',
2120
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2121
-                'DTTNUM',
2122
-                'TICKETNUM',
2123
-                null,
2124
-                null,
2125
-                array(),
2126
-                true
2127
-            ),
2128
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2129
-                'DTTNUM',
2130
-                'TICKETNUM',
2131
-                null,
2132
-                null,
2133
-                array(),
2134
-                true
2135
-            ),
2136
-        );
2137
-        $ticket_row = 1;
2138
-        foreach ($all_tickets as $ticket) {
2139
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2140
-                'DTTNUM',
2141
-                $ticket_row,
2142
-                null,
2143
-                $ticket,
2144
-                array(),
2145
-                true
2146
-            );
2147
-            $ticket_row++;
2148
-        }
2149
-        $datetime_row = 1;
2150
-        foreach ($all_datetimes as $datetime) {
2151
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2152
-                $datetime_row,
2153
-                'TICKETNUM',
2154
-                $datetime,
2155
-                null,
2156
-                array(),
2157
-                true
2158
-            );
2159
-            $datetime_row++;
2160
-        }
2161
-        /** @var EEM_Price $price_model */
2162
-        $price_model = EE_Registry::instance()->load_model('Price');
2163
-        $default_prices = $price_model->get_all_default_prices();
2164
-        $price_row = 1;
2165
-        foreach ($default_prices as $price) {
2166
-            if (! $price instanceof EE_Price) {
2167
-                continue;
2168
-            }
2169
-            if ($price->is_base_price()) {
2170
-                $template_args['default_base_price_amount'] = $price->get_pretty(
2171
-                    'PRC_amount',
2172
-                    'localized_float'
2173
-                );
2174
-                $template_args['default_base_price_name'] = $price->get('PRC_name');
2175
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2176
-                $price_row++;
2177
-                continue;
2178
-            }
2179
-            $show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2180
-                             || count($default_prices) === 1);
2181
-            $show_create = ! (count($default_prices) > 1
2182
-                              && count($default_prices)
2183
-                                 !== $price_row);
2184
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2185
-                'TICKETNUM',
2186
-                $price_row,
2187
-                $price,
2188
-                true,
2189
-                null,
2190
-                $show_trash,
2191
-                $show_create
2192
-            );
2193
-            $price_row++;
2194
-        }
2195
-        $template_args = apply_filters(
2196
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2197
-            $template_args,
2198
-            $all_datetimes,
2199
-            $all_tickets,
2200
-            $this->_is_creating_event
2201
-        );
2202
-        return EEH_Template::display_template(
2203
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2204
-            $template_args,
2205
-            true
2206
-        );
2207
-    }
2067
+	/**
2068
+	 * @param array $all_datetimes
2069
+	 * @param array $all_tickets
2070
+	 * @return mixed
2071
+	 * @throws ReflectionException
2072
+	 * @throws InvalidArgumentException
2073
+	 * @throws InvalidInterfaceException
2074
+	 * @throws InvalidDataTypeException
2075
+	 * @throws DomainException
2076
+	 * @throws EE_Error
2077
+	 */
2078
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2079
+	{
2080
+		$template_args = array(
2081
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2082
+				'DTTNUM',
2083
+				null,
2084
+				true,
2085
+				$all_datetimes
2086
+			),
2087
+			'default_ticket_row'                       => $this->_get_ticket_row(
2088
+				'TICKETNUM',
2089
+				null,
2090
+				array(),
2091
+				array(),
2092
+				true
2093
+			),
2094
+			'default_price_row'                        => $this->_get_ticket_price_row(
2095
+				'TICKETNUM',
2096
+				'PRICENUM',
2097
+				null,
2098
+				true,
2099
+				null
2100
+			),
2101
+			'default_price_rows'                       => '',
2102
+			'default_base_price_amount'                => 0,
2103
+			'default_base_price_name'                  => '',
2104
+			'default_base_price_description'           => '',
2105
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2106
+				'TICKETNUM',
2107
+				'PRICENUM',
2108
+				null,
2109
+				true
2110
+			),
2111
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2112
+				'DTTNUM',
2113
+				null,
2114
+				array(),
2115
+				array(),
2116
+				true
2117
+			),
2118
+			'existing_available_datetime_tickets_list' => '',
2119
+			'existing_available_ticket_datetimes_list' => '',
2120
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2121
+				'DTTNUM',
2122
+				'TICKETNUM',
2123
+				null,
2124
+				null,
2125
+				array(),
2126
+				true
2127
+			),
2128
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2129
+				'DTTNUM',
2130
+				'TICKETNUM',
2131
+				null,
2132
+				null,
2133
+				array(),
2134
+				true
2135
+			),
2136
+		);
2137
+		$ticket_row = 1;
2138
+		foreach ($all_tickets as $ticket) {
2139
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2140
+				'DTTNUM',
2141
+				$ticket_row,
2142
+				null,
2143
+				$ticket,
2144
+				array(),
2145
+				true
2146
+			);
2147
+			$ticket_row++;
2148
+		}
2149
+		$datetime_row = 1;
2150
+		foreach ($all_datetimes as $datetime) {
2151
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2152
+				$datetime_row,
2153
+				'TICKETNUM',
2154
+				$datetime,
2155
+				null,
2156
+				array(),
2157
+				true
2158
+			);
2159
+			$datetime_row++;
2160
+		}
2161
+		/** @var EEM_Price $price_model */
2162
+		$price_model = EE_Registry::instance()->load_model('Price');
2163
+		$default_prices = $price_model->get_all_default_prices();
2164
+		$price_row = 1;
2165
+		foreach ($default_prices as $price) {
2166
+			if (! $price instanceof EE_Price) {
2167
+				continue;
2168
+			}
2169
+			if ($price->is_base_price()) {
2170
+				$template_args['default_base_price_amount'] = $price->get_pretty(
2171
+					'PRC_amount',
2172
+					'localized_float'
2173
+				);
2174
+				$template_args['default_base_price_name'] = $price->get('PRC_name');
2175
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2176
+				$price_row++;
2177
+				continue;
2178
+			}
2179
+			$show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2180
+							 || count($default_prices) === 1);
2181
+			$show_create = ! (count($default_prices) > 1
2182
+							  && count($default_prices)
2183
+								 !== $price_row);
2184
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2185
+				'TICKETNUM',
2186
+				$price_row,
2187
+				$price,
2188
+				true,
2189
+				null,
2190
+				$show_trash,
2191
+				$show_create
2192
+			);
2193
+			$price_row++;
2194
+		}
2195
+		$template_args = apply_filters(
2196
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2197
+			$template_args,
2198
+			$all_datetimes,
2199
+			$all_tickets,
2200
+			$this->_is_creating_event
2201
+		);
2202
+		return EEH_Template::display_template(
2203
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2204
+			$template_args,
2205
+			true
2206
+		);
2207
+	}
2208 2208
 }
Please login to merge, or discard this patch.
core/services/request/RequestInterface.php 1 patch
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -16,155 +16,155 @@
 block discarded – undo
16 16
 interface RequestInterface extends RequestTypeContextCheckerInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @param RequestTypeContextCheckerInterface $type
21
-     */
22
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
23
-
24
-    /**
25
-     * @return array
26
-     */
27
-    public function getParams();
28
-
29
-
30
-    /**
31
-     * @return array
32
-     */
33
-    public function postParams();
34
-
35
-
36
-    /**
37
-     * @return array
38
-     */
39
-    public function cookieParams();
40
-
41
-
42
-    /**
43
-     * @return array
44
-     */
45
-    public function serverParams();
46
-
47
-
48
-    /**
49
-     * @return array
50
-     */
51
-    public function filesParams();
52
-
19
+	/**
20
+	 * @param RequestTypeContextCheckerInterface $type
21
+	 */
22
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
23
+
24
+	/**
25
+	 * @return array
26
+	 */
27
+	public function getParams();
28
+
29
+
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function postParams();
34
+
35
+
36
+	/**
37
+	 * @return array
38
+	 */
39
+	public function cookieParams();
40
+
41
+
42
+	/**
43
+	 * @return array
44
+	 */
45
+	public function serverParams();
46
+
47
+
48
+	/**
49
+	 * @return array
50
+	 */
51
+	public function filesParams();
52
+
53 53
 
54
-    /**
55
-     * returns contents of $_REQUEST
56
-     *
57
-     * @return array
58
-     */
59
-    public function requestParams();
54
+	/**
55
+	 * returns contents of $_REQUEST
56
+	 *
57
+	 * @return array
58
+	 */
59
+	public function requestParams();
60 60
 
61 61
 
62
-    /**
63
-     * @param string $key
64
-     * @param string $value
65
-     * @param bool   $override_ee
66
-     * @return    void
67
-     */
68
-    public function setRequestParam($key, $value, $override_ee = false);
62
+	/**
63
+	 * @param string $key
64
+	 * @param string $value
65
+	 * @param bool   $override_ee
66
+	 * @return    void
67
+	 */
68
+	public function setRequestParam($key, $value, $override_ee = false);
69 69
 
70 70
 
71
-    /**
72
-     * returns the value for a request param if the given key exists
73
-     *
74
-     * @param string $key
75
-     * @param null   $default
76
-     * @return mixed
77
-     */
78
-    public function getRequestParam($key, $default = null);
71
+	/**
72
+	 * returns the value for a request param if the given key exists
73
+	 *
74
+	 * @param string $key
75
+	 * @param null   $default
76
+	 * @return mixed
77
+	 */
78
+	public function getRequestParam($key, $default = null);
79 79
 
80 80
 
81
-    /**
82
-     * check if param exists
83
-     *
84
-     * @param string $key
85
-     * @return bool
86
-     */
87
-    public function requestParamIsSet($key);
81
+	/**
82
+	 * check if param exists
83
+	 *
84
+	 * @param string $key
85
+	 * @return bool
86
+	 */
87
+	public function requestParamIsSet($key);
88 88
 
89 89
 
90
-    /**
91
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
92
-     * and return the value for the first match found
93
-     * wildcards can be either of the following:
94
-     *      ? to represent a single character of any type
95
-     *      * to represent one or more characters of any type
96
-     *
97
-     * @param string     $pattern
98
-     * @param null|mixed $default
99
-     * @return false|int
100
-     */
101
-    public function getMatch($pattern, $default = null);
90
+	/**
91
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
92
+	 * and return the value for the first match found
93
+	 * wildcards can be either of the following:
94
+	 *      ? to represent a single character of any type
95
+	 *      * to represent one or more characters of any type
96
+	 *
97
+	 * @param string     $pattern
98
+	 * @param null|mixed $default
99
+	 * @return false|int
100
+	 */
101
+	public function getMatch($pattern, $default = null);
102 102
 
103 103
 
104
-    /**
105
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
106
-     * wildcards can be either of the following:
107
-     *      ? to represent a single character of any type
108
-     *      * to represent one or more characters of any type
109
-     * returns true if a match is found or false if not
110
-     *
111
-     * @param string $pattern
112
-     * @return false|int
113
-     */
114
-    public function matches($pattern);
104
+	/**
105
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
106
+	 * wildcards can be either of the following:
107
+	 *      ? to represent a single character of any type
108
+	 *      * to represent one or more characters of any type
109
+	 * returns true if a match is found or false if not
110
+	 *
111
+	 * @param string $pattern
112
+	 * @return false|int
113
+	 */
114
+	public function matches($pattern);
115 115
 
116 116
 
117
-    /**
118
-     * remove param
119
-     *
120
-     * @param string $key
121
-     * @param bool   $unset_from_global_too
122
-     */
123
-    public function unSetRequestParam($key, $unset_from_global_too = false);
117
+	/**
118
+	 * remove param
119
+	 *
120
+	 * @param string $key
121
+	 * @param bool   $unset_from_global_too
122
+	 */
123
+	public function unSetRequestParam($key, $unset_from_global_too = false);
124 124
 
125 125
 
126
-    /**
127
-     * remove params
128
-     *
129
-     * @param array $keys
130
-     * @param bool   $unset_from_global_too
131
-     */
132
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false);
126
+	/**
127
+	 * remove params
128
+	 *
129
+	 * @param array $keys
130
+	 * @param bool   $unset_from_global_too
131
+	 */
132
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false);
133 133
 
134 134
 
135
-    /**
136
-     * @return string
137
-     */
138
-    public function ipAddress();
135
+	/**
136
+	 * @return string
137
+	 */
138
+	public function ipAddress();
139 139
 
140 140
 
141
-    /**
142
-     * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not.
143
-     * @return string
144
-     */
145
-    public function requestUri($relativeToWpRoot = false);
146
-
147
-
148
-    /**
149
-     * @return string
150
-     */
151
-    public function userAgent();
152
-
153
-
154
-    /**
155
-     * @param string $user_agent
156
-     */
157
-    public function setUserAgent($user_agent = '');
158
-
159
-
160
-    /**
161
-     * @return bool
162
-     */
163
-    public function isBot();
164
-
165
-
166
-    /**
167
-     * @param bool $is_bot
168
-     */
169
-    public function setIsBot($is_bot);
141
+	/**
142
+	 * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not.
143
+	 * @return string
144
+	 */
145
+	public function requestUri($relativeToWpRoot = false);
146
+
147
+
148
+	/**
149
+	 * @return string
150
+	 */
151
+	public function userAgent();
152
+
153
+
154
+	/**
155
+	 * @param string $user_agent
156
+	 */
157
+	public function setUserAgent($user_agent = '');
158
+
159
+
160
+	/**
161
+	 * @return bool
162
+	 */
163
+	public function isBot();
164
+
165
+
166
+	/**
167
+	 * @param bool $is_bot
168
+	 */
169
+	public function setIsBot($is_bot);
170 170
 }
Please login to merge, or discard this patch.
core/services/request/Request.php 2 patches
Indentation   +652 added lines, -652 removed lines patch added patch discarded remove patch
@@ -17,656 +17,656 @@
 block discarded – undo
17 17
 class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface
18 18
 {
19 19
 
20
-    /**
21
-     * $_GET parameters
22
-     *
23
-     * @var array $get
24
-     */
25
-    private $get;
26
-
27
-    /**
28
-     * $_POST parameters
29
-     *
30
-     * @var array $post
31
-     */
32
-    private $post;
33
-
34
-    /**
35
-     * $_COOKIE parameters
36
-     *
37
-     * @var array $cookie
38
-     */
39
-    private $cookie;
40
-
41
-    /**
42
-     * $_SERVER parameters
43
-     *
44
-     * @var array $server
45
-     */
46
-    private $server;
47
-
48
-    /**
49
-     * $_FILES parameters
50
-     *
51
-     * @var array $files
52
-     */
53
-    private $files;
54
-
55
-    /**
56
-     * $_REQUEST parameters
57
-     *
58
-     * @var array $request
59
-     */
60
-    private $request;
61
-
62
-    /**
63
-     * @var RequestTypeContextCheckerInterface
64
-     */
65
-    private $request_type;
66
-
67
-    /**
68
-     * IP address for request
69
-     *
70
-     * @var string $ip_address
71
-     */
72
-    private $ip_address;
73
-
74
-    /**
75
-     * @var string $user_agent
76
-     */
77
-    private $user_agent;
78
-
79
-    /**
80
-     * true if current user appears to be some kind of bot
81
-     *
82
-     * @var bool $is_bot
83
-     */
84
-    private $is_bot;
85
-
86
-
87
-    /**
88
-     * @param array $get
89
-     * @param array $post
90
-     * @param array $cookie
91
-     * @param array $server
92
-     * @param array $files
93
-     */
94
-    public function __construct(array $get, array $post, array $cookie, array $server, array $files = array())
95
-    {
96
-        // grab request vars
97
-        $this->get = $get;
98
-        $this->post = $post;
99
-        $this->cookie = $cookie;
100
-        $this->server = $server;
101
-        $this->files = $files;
102
-        $this->request = array_merge($this->get, $this->post);
103
-        $this->ip_address = $this->visitorIp();
104
-    }
105
-
106
-
107
-    /**
108
-     * @param RequestTypeContextCheckerInterface $type
109
-     */
110
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
111
-    {
112
-        $this->request_type = $type;
113
-    }
114
-
115
-
116
-    /**
117
-     * @return array
118
-     */
119
-    public function getParams()
120
-    {
121
-        return $this->get;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return array
127
-     */
128
-    public function postParams()
129
-    {
130
-        return $this->post;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return array
136
-     */
137
-    public function cookieParams()
138
-    {
139
-        return $this->cookie;
140
-    }
141
-
142
-
143
-    /**
144
-     * @return array
145
-     */
146
-    public function serverParams()
147
-    {
148
-        return $this->server;
149
-    }
150
-
151
-
152
-    /**
153
-     * @return array
154
-     */
155
-    public function filesParams()
156
-    {
157
-        return $this->files;
158
-    }
159
-
160
-
161
-    /**
162
-     * returns contents of $_REQUEST
163
-     *
164
-     * @return array
165
-     */
166
-    public function requestParams()
167
-    {
168
-        return $this->request;
169
-    }
170
-
171
-
172
-    /**
173
-     * @param      $key
174
-     * @param      $value
175
-     * @param bool $override_ee
176
-     * @return    void
177
-     */
178
-    public function setRequestParam($key, $value, $override_ee = false)
179
-    {
180
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
181
-        if ($key !== 'ee'
182
-            || ($key === 'ee' && empty($this->request['ee']))
183
-            || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
184
-        ) {
185
-            $this->request[ $key ] = $value;
186
-        }
187
-    }
188
-
189
-
190
-    /**
191
-     * returns   the value for a request param if the given key exists
192
-     *
193
-     * @param       $key
194
-     * @param null  $default
195
-     * @return mixed
196
-     */
197
-    public function getRequestParam($key, $default = null)
198
-    {
199
-        return $this->requestParameterDrillDown($key, $default, 'get');
200
-    }
201
-
202
-
203
-    /**
204
-     * check if param exists
205
-     *
206
-     * @param       $key
207
-     * @return bool
208
-     */
209
-    public function requestParamIsSet($key)
210
-    {
211
-        return $this->requestParameterDrillDown($key);
212
-    }
213
-
214
-
215
-    /**
216
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
217
-     * and return the value for the first match found
218
-     * wildcards can be either of the following:
219
-     *      ? to represent a single character of any type
220
-     *      * to represent one or more characters of any type
221
-     *
222
-     * @param string     $pattern
223
-     * @param null|mixed $default
224
-     * @return mixed
225
-     */
226
-    public function getMatch($pattern, $default = null)
227
-    {
228
-        return $this->requestParameterDrillDown($pattern, $default, 'match');
229
-    }
230
-
231
-
232
-    /**
233
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
234
-     * wildcards can be either of the following:
235
-     *      ? to represent a single character of any type
236
-     *      * to represent one or more characters of any type
237
-     * returns true if a match is found or false if not
238
-     *
239
-     * @param string $pattern
240
-     * @return bool
241
-     */
242
-    public function matches($pattern)
243
-    {
244
-        return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
245
-    }
246
-
247
-
248
-    /**
249
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
250
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
251
-     *                                      and used to search through the current request's parameter keys
252
-     * @param array  $request_params        The array of request parameters to search through
253
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
254
-     *                                      Default is null
255
-     * @param string $return                [optional] Controls what kind of value is returned.
256
-     *                                      Options are:
257
-     *                                      'bool' will return true or false if match is found or not
258
-     *                                      'key' will return the first key found that matches the supplied pattern
259
-     *                                      'value' will return the value for the first request parameter
260
-     *                                      whose key matches the supplied pattern
261
-     *                                      Default is 'value'
262
-     * @return boolean|string
263
-     */
264
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
265
-    {
266
-        $return = in_array($return, array('bool', 'key', 'value'), true)
267
-            ? $return
268
-            : 'is_set';
269
-        // replace wildcard chars with regex chars
270
-        $pattern = str_replace(
271
-            array("\*", "\?"),
272
-            array('.*', '.'),
273
-            preg_quote($pattern, '/')
274
-        );
275
-        foreach ($request_params as $key => $request_param) {
276
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
277
-                // return value for request param
278
-                if ($return === 'value') {
279
-                    return $request_params[ $key ];
280
-                }
281
-                // or actual key or true just to indicate it was found
282
-                return $return === 'key' ? $key : true;
283
-            }
284
-        }
285
-        // match not found so return default value or false
286
-        return $return === 'value' ? $default : false;
287
-    }
288
-
289
-
290
-    /**
291
-     * the supplied key can be a simple string to represent a "top-level" request parameter
292
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
293
-     * by using square brackets to surround keys for deeper array elements.
294
-     * For example :
295
-     * if the supplied $key was: "first[second][third]"
296
-     * then this will attempt to drill down into the request parameter array to find a value.
297
-     * Given the following request parameters:
298
-     *  array(
299
-     *      'first' => array(
300
-     *          'second' => array(
301
-     *              'third' => 'has a value'
302
-     *          )
303
-     *      )
304
-     *  )
305
-     * would return true if default parameters were set
306
-     *
307
-     * @param string $callback
308
-     * @param        $key
309
-     * @param null   $default
310
-     * @param array  $request_params
311
-     * @return bool|mixed|null
312
-     */
313
-    private function requestParameterDrillDown(
314
-        $key,
315
-        $default = null,
316
-        $callback = 'is_set',
317
-        array $request_params = array()
318
-    ) {
319
-        $callback = in_array($callback, array('is_set', 'get', 'match'), true)
320
-            ? $callback
321
-            : 'is_set';
322
-        $request_params = ! empty($request_params)
323
-            ? $request_params
324
-            : $this->request;
325
-        // does incoming key represent an array like 'first[second][third]'  ?
326
-        if (strpos($key, '[') !== false) {
327
-            // turn it into an actual array
328
-            $key = str_replace(']', '', $key);
329
-            $keys = explode('[', $key);
330
-            $key = array_shift($keys);
331
-            if ($callback === 'match') {
332
-                $real_key = $this->match($key, $request_params, $default, 'key');
333
-                $key = $real_key ? $real_key : $key;
334
-            }
335
-            // check if top level key exists
336
-            if (isset($request_params[ $key ])) {
337
-                // build a new key to pass along like: 'second[third]'
338
-                // or just 'second' depending on depth of keys
339
-                $key_string = array_shift($keys);
340
-                if (! empty($keys)) {
341
-                    $key_string .= '[' . implode('][', $keys) . ']';
342
-                }
343
-                return $this->requestParameterDrillDown(
344
-                    $key_string,
345
-                    $default,
346
-                    $callback,
347
-                    $request_params[ $key ]
348
-                );
349
-            }
350
-        }
351
-        if ($callback === 'is_set') {
352
-            return isset($request_params[ $key ]);
353
-        }
354
-        if ($callback === 'match') {
355
-            return $this->match($key, $request_params, $default);
356
-        }
357
-        return isset($request_params[ $key ])
358
-            ? $request_params[ $key ]
359
-            : $default;
360
-    }
361
-
362
-
363
-    /**
364
-     * remove param
365
-     *
366
-     * @param      $key
367
-     * @param bool $unset_from_global_too
368
-     */
369
-    public function unSetRequestParam($key, $unset_from_global_too = false)
370
-    {
371
-        // because unset may not actually remove var
372
-        $this->request[ $key ] = null;
373
-        unset($this->request[ $key ]);
374
-        if ($unset_from_global_too) {
375
-            unset($_REQUEST[ $key ]);
376
-        }
377
-    }
378
-
379
-
380
-    /**
381
-     * remove params
382
-     *
383
-     * @param array $keys
384
-     * @param bool  $unset_from_global_too
385
-     */
386
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
387
-    {
388
-        foreach ($keys as $key) {
389
-            $this->unSetRequestParam($key, $unset_from_global_too);
390
-        }
391
-    }
392
-
393
-
394
-    /**
395
-     * @return string
396
-     */
397
-    public function ipAddress()
398
-    {
399
-        return $this->ip_address;
400
-    }
401
-
402
-
403
-    /**
404
-     * attempt to get IP address of current visitor from server
405
-     * plz see: http://stackoverflow.com/a/2031935/1475279
406
-     *
407
-     * @access public
408
-     * @return string
409
-     */
410
-    private function visitorIp()
411
-    {
412
-        $visitor_ip = '0.0.0.0';
413
-        $server_keys = array(
414
-            'HTTP_CLIENT_IP',
415
-            'HTTP_X_FORWARDED_FOR',
416
-            'HTTP_X_FORWARDED',
417
-            'HTTP_X_CLUSTER_CLIENT_IP',
418
-            'HTTP_FORWARDED_FOR',
419
-            'HTTP_FORWARDED',
420
-            'REMOTE_ADDR',
421
-        );
422
-        foreach ($server_keys as $key) {
423
-            if (isset($this->server[ $key ])) {
424
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
425
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
426
-                        $visitor_ip = $ip;
427
-                    }
428
-                }
429
-            }
430
-        }
431
-        return $visitor_ip;
432
-    }
433
-
434
-
435
-    /**
436
-     * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
437
-     * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
438
-     *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
439
-     *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
440
-     * @return string
441
-     */
442
-    public function requestUri($relativeToWpRoot = false)
443
-    {
444
-        $request_uri = filter_input(
445
-            INPUT_SERVER,
446
-            'REQUEST_URI',
447
-            FILTER_SANITIZE_URL,
448
-            FILTER_NULL_ON_FAILURE
449
-        );
450
-        if (empty($request_uri)) {
451
-            // fallback sanitization if the above fails
452
-            $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
453
-        }
454
-        if ($relativeToWpRoot) {
455
-            $home_path = untrailingslashit(
456
-                parse_url(
457
-                    home_url(),
458
-                    PHP_URL_PATH
459
-                )
460
-            );
461
-            $request_uri = str_replace(
462
-                $home_path,
463
-                '',
464
-                $request_uri
465
-            );
466
-        }
467
-        return $request_uri;
468
-    }
469
-
470
-    /**
471
-     * @return string
472
-     */
473
-    public function userAgent()
474
-    {
475
-        return $this->user_agent;
476
-    }
477
-
478
-
479
-    /**
480
-     * @param string $user_agent
481
-     */
482
-    public function setUserAgent($user_agent = '')
483
-    {
484
-        if ($user_agent === '' || ! is_string($user_agent)) {
485
-            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
486
-        }
487
-        $this->user_agent = $user_agent;
488
-    }
489
-
490
-
491
-    /**
492
-     * @return bool
493
-     */
494
-    public function isBot()
495
-    {
496
-        return $this->is_bot;
497
-    }
498
-
499
-
500
-    /**
501
-     * @param bool $is_bot
502
-     */
503
-    public function setIsBot($is_bot)
504
-    {
505
-        $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
506
-    }
507
-
508
-
509
-    /**
510
-     * @return bool
511
-     */
512
-    public function isActivation()
513
-    {
514
-        return $this->request_type->isActivation();
515
-    }
516
-
517
-
518
-    /**
519
-     * @param $is_activation
520
-     * @return bool
521
-     */
522
-    public function setIsActivation($is_activation)
523
-    {
524
-        return $this->request_type->setIsActivation($is_activation);
525
-    }
526
-
527
-
528
-    /**
529
-     * @return bool
530
-     */
531
-    public function isAdmin()
532
-    {
533
-        return $this->request_type->isAdmin();
534
-    }
535
-
536
-
537
-    /**
538
-     * @return bool
539
-     */
540
-    public function isAdminAjax()
541
-    {
542
-        return $this->request_type->isAdminAjax();
543
-    }
544
-
545
-
546
-    /**
547
-     * @return bool
548
-     */
549
-    public function isAjax()
550
-    {
551
-        return $this->request_type->isAjax();
552
-    }
553
-
554
-
555
-    /**
556
-     * @return bool
557
-     */
558
-    public function isEeAjax()
559
-    {
560
-        return $this->request_type->isEeAjax();
561
-    }
562
-
563
-
564
-    /**
565
-     * @return bool
566
-     */
567
-    public function isOtherAjax()
568
-    {
569
-        return $this->request_type->isOtherAjax();
570
-    }
571
-
572
-
573
-    /**
574
-     * @return bool
575
-     */
576
-    public function isApi()
577
-    {
578
-        return $this->request_type->isApi();
579
-    }
580
-
581
-
582
-    /**
583
-     * @return bool
584
-     */
585
-    public function isCli()
586
-    {
587
-        return $this->request_type->isCli();
588
-    }
589
-
590
-
591
-    /**
592
-     * @return bool
593
-     */
594
-    public function isCron()
595
-    {
596
-        return $this->request_type->isCron();
597
-    }
598
-
599
-
600
-    /**
601
-     * @return bool
602
-     */
603
-    public function isFeed()
604
-    {
605
-        return $this->request_type->isFeed();
606
-    }
607
-
608
-
609
-    /**
610
-     * @return bool
611
-     */
612
-    public function isFrontend()
613
-    {
614
-        return $this->request_type->isFrontend();
615
-    }
616
-
617
-
618
-    /**
619
-     * @return bool
620
-     */
621
-    public function isFrontAjax()
622
-    {
623
-        return $this->request_type->isFrontAjax();
624
-    }
625
-
626
-
627
-    /**
628
-     * @return bool
629
-     */
630
-    public function isIframe()
631
-    {
632
-        return $this->request_type->isIframe();
633
-    }
634
-
635
-
636
-    /**
637
-     * @return bool
638
-     */
639
-    public function isWordPressApi()
640
-    {
641
-        return $this->request_type->isWordPressApi();
642
-    }
643
-
644
-
645
-
646
-    /**
647
-     * @return bool
648
-     */
649
-    public function isWordPressHeartbeat()
650
-    {
651
-        return $this->request_type->isWordPressHeartbeat();
652
-    }
653
-
654
-
655
-
656
-    /**
657
-     * @return bool
658
-     */
659
-    public function isWordPressScrape()
660
-    {
661
-        return $this->request_type->isWordPressScrape();
662
-    }
663
-
664
-
665
-    /**
666
-     * @return string
667
-     */
668
-    public function slug()
669
-    {
670
-        return $this->request_type->slug();
671
-    }
20
+	/**
21
+	 * $_GET parameters
22
+	 *
23
+	 * @var array $get
24
+	 */
25
+	private $get;
26
+
27
+	/**
28
+	 * $_POST parameters
29
+	 *
30
+	 * @var array $post
31
+	 */
32
+	private $post;
33
+
34
+	/**
35
+	 * $_COOKIE parameters
36
+	 *
37
+	 * @var array $cookie
38
+	 */
39
+	private $cookie;
40
+
41
+	/**
42
+	 * $_SERVER parameters
43
+	 *
44
+	 * @var array $server
45
+	 */
46
+	private $server;
47
+
48
+	/**
49
+	 * $_FILES parameters
50
+	 *
51
+	 * @var array $files
52
+	 */
53
+	private $files;
54
+
55
+	/**
56
+	 * $_REQUEST parameters
57
+	 *
58
+	 * @var array $request
59
+	 */
60
+	private $request;
61
+
62
+	/**
63
+	 * @var RequestTypeContextCheckerInterface
64
+	 */
65
+	private $request_type;
66
+
67
+	/**
68
+	 * IP address for request
69
+	 *
70
+	 * @var string $ip_address
71
+	 */
72
+	private $ip_address;
73
+
74
+	/**
75
+	 * @var string $user_agent
76
+	 */
77
+	private $user_agent;
78
+
79
+	/**
80
+	 * true if current user appears to be some kind of bot
81
+	 *
82
+	 * @var bool $is_bot
83
+	 */
84
+	private $is_bot;
85
+
86
+
87
+	/**
88
+	 * @param array $get
89
+	 * @param array $post
90
+	 * @param array $cookie
91
+	 * @param array $server
92
+	 * @param array $files
93
+	 */
94
+	public function __construct(array $get, array $post, array $cookie, array $server, array $files = array())
95
+	{
96
+		// grab request vars
97
+		$this->get = $get;
98
+		$this->post = $post;
99
+		$this->cookie = $cookie;
100
+		$this->server = $server;
101
+		$this->files = $files;
102
+		$this->request = array_merge($this->get, $this->post);
103
+		$this->ip_address = $this->visitorIp();
104
+	}
105
+
106
+
107
+	/**
108
+	 * @param RequestTypeContextCheckerInterface $type
109
+	 */
110
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
111
+	{
112
+		$this->request_type = $type;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return array
118
+	 */
119
+	public function getParams()
120
+	{
121
+		return $this->get;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return array
127
+	 */
128
+	public function postParams()
129
+	{
130
+		return $this->post;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return array
136
+	 */
137
+	public function cookieParams()
138
+	{
139
+		return $this->cookie;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @return array
145
+	 */
146
+	public function serverParams()
147
+	{
148
+		return $this->server;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @return array
154
+	 */
155
+	public function filesParams()
156
+	{
157
+		return $this->files;
158
+	}
159
+
160
+
161
+	/**
162
+	 * returns contents of $_REQUEST
163
+	 *
164
+	 * @return array
165
+	 */
166
+	public function requestParams()
167
+	{
168
+		return $this->request;
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param      $key
174
+	 * @param      $value
175
+	 * @param bool $override_ee
176
+	 * @return    void
177
+	 */
178
+	public function setRequestParam($key, $value, $override_ee = false)
179
+	{
180
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
181
+		if ($key !== 'ee'
182
+			|| ($key === 'ee' && empty($this->request['ee']))
183
+			|| ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
184
+		) {
185
+			$this->request[ $key ] = $value;
186
+		}
187
+	}
188
+
189
+
190
+	/**
191
+	 * returns   the value for a request param if the given key exists
192
+	 *
193
+	 * @param       $key
194
+	 * @param null  $default
195
+	 * @return mixed
196
+	 */
197
+	public function getRequestParam($key, $default = null)
198
+	{
199
+		return $this->requestParameterDrillDown($key, $default, 'get');
200
+	}
201
+
202
+
203
+	/**
204
+	 * check if param exists
205
+	 *
206
+	 * @param       $key
207
+	 * @return bool
208
+	 */
209
+	public function requestParamIsSet($key)
210
+	{
211
+		return $this->requestParameterDrillDown($key);
212
+	}
213
+
214
+
215
+	/**
216
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
217
+	 * and return the value for the first match found
218
+	 * wildcards can be either of the following:
219
+	 *      ? to represent a single character of any type
220
+	 *      * to represent one or more characters of any type
221
+	 *
222
+	 * @param string     $pattern
223
+	 * @param null|mixed $default
224
+	 * @return mixed
225
+	 */
226
+	public function getMatch($pattern, $default = null)
227
+	{
228
+		return $this->requestParameterDrillDown($pattern, $default, 'match');
229
+	}
230
+
231
+
232
+	/**
233
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
234
+	 * wildcards can be either of the following:
235
+	 *      ? to represent a single character of any type
236
+	 *      * to represent one or more characters of any type
237
+	 * returns true if a match is found or false if not
238
+	 *
239
+	 * @param string $pattern
240
+	 * @return bool
241
+	 */
242
+	public function matches($pattern)
243
+	{
244
+		return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
245
+	}
246
+
247
+
248
+	/**
249
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
250
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
251
+	 *                                      and used to search through the current request's parameter keys
252
+	 * @param array  $request_params        The array of request parameters to search through
253
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
254
+	 *                                      Default is null
255
+	 * @param string $return                [optional] Controls what kind of value is returned.
256
+	 *                                      Options are:
257
+	 *                                      'bool' will return true or false if match is found or not
258
+	 *                                      'key' will return the first key found that matches the supplied pattern
259
+	 *                                      'value' will return the value for the first request parameter
260
+	 *                                      whose key matches the supplied pattern
261
+	 *                                      Default is 'value'
262
+	 * @return boolean|string
263
+	 */
264
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
265
+	{
266
+		$return = in_array($return, array('bool', 'key', 'value'), true)
267
+			? $return
268
+			: 'is_set';
269
+		// replace wildcard chars with regex chars
270
+		$pattern = str_replace(
271
+			array("\*", "\?"),
272
+			array('.*', '.'),
273
+			preg_quote($pattern, '/')
274
+		);
275
+		foreach ($request_params as $key => $request_param) {
276
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
277
+				// return value for request param
278
+				if ($return === 'value') {
279
+					return $request_params[ $key ];
280
+				}
281
+				// or actual key or true just to indicate it was found
282
+				return $return === 'key' ? $key : true;
283
+			}
284
+		}
285
+		// match not found so return default value or false
286
+		return $return === 'value' ? $default : false;
287
+	}
288
+
289
+
290
+	/**
291
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
292
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
293
+	 * by using square brackets to surround keys for deeper array elements.
294
+	 * For example :
295
+	 * if the supplied $key was: "first[second][third]"
296
+	 * then this will attempt to drill down into the request parameter array to find a value.
297
+	 * Given the following request parameters:
298
+	 *  array(
299
+	 *      'first' => array(
300
+	 *          'second' => array(
301
+	 *              'third' => 'has a value'
302
+	 *          )
303
+	 *      )
304
+	 *  )
305
+	 * would return true if default parameters were set
306
+	 *
307
+	 * @param string $callback
308
+	 * @param        $key
309
+	 * @param null   $default
310
+	 * @param array  $request_params
311
+	 * @return bool|mixed|null
312
+	 */
313
+	private function requestParameterDrillDown(
314
+		$key,
315
+		$default = null,
316
+		$callback = 'is_set',
317
+		array $request_params = array()
318
+	) {
319
+		$callback = in_array($callback, array('is_set', 'get', 'match'), true)
320
+			? $callback
321
+			: 'is_set';
322
+		$request_params = ! empty($request_params)
323
+			? $request_params
324
+			: $this->request;
325
+		// does incoming key represent an array like 'first[second][third]'  ?
326
+		if (strpos($key, '[') !== false) {
327
+			// turn it into an actual array
328
+			$key = str_replace(']', '', $key);
329
+			$keys = explode('[', $key);
330
+			$key = array_shift($keys);
331
+			if ($callback === 'match') {
332
+				$real_key = $this->match($key, $request_params, $default, 'key');
333
+				$key = $real_key ? $real_key : $key;
334
+			}
335
+			// check if top level key exists
336
+			if (isset($request_params[ $key ])) {
337
+				// build a new key to pass along like: 'second[third]'
338
+				// or just 'second' depending on depth of keys
339
+				$key_string = array_shift($keys);
340
+				if (! empty($keys)) {
341
+					$key_string .= '[' . implode('][', $keys) . ']';
342
+				}
343
+				return $this->requestParameterDrillDown(
344
+					$key_string,
345
+					$default,
346
+					$callback,
347
+					$request_params[ $key ]
348
+				);
349
+			}
350
+		}
351
+		if ($callback === 'is_set') {
352
+			return isset($request_params[ $key ]);
353
+		}
354
+		if ($callback === 'match') {
355
+			return $this->match($key, $request_params, $default);
356
+		}
357
+		return isset($request_params[ $key ])
358
+			? $request_params[ $key ]
359
+			: $default;
360
+	}
361
+
362
+
363
+	/**
364
+	 * remove param
365
+	 *
366
+	 * @param      $key
367
+	 * @param bool $unset_from_global_too
368
+	 */
369
+	public function unSetRequestParam($key, $unset_from_global_too = false)
370
+	{
371
+		// because unset may not actually remove var
372
+		$this->request[ $key ] = null;
373
+		unset($this->request[ $key ]);
374
+		if ($unset_from_global_too) {
375
+			unset($_REQUEST[ $key ]);
376
+		}
377
+	}
378
+
379
+
380
+	/**
381
+	 * remove params
382
+	 *
383
+	 * @param array $keys
384
+	 * @param bool  $unset_from_global_too
385
+	 */
386
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
387
+	{
388
+		foreach ($keys as $key) {
389
+			$this->unSetRequestParam($key, $unset_from_global_too);
390
+		}
391
+	}
392
+
393
+
394
+	/**
395
+	 * @return string
396
+	 */
397
+	public function ipAddress()
398
+	{
399
+		return $this->ip_address;
400
+	}
401
+
402
+
403
+	/**
404
+	 * attempt to get IP address of current visitor from server
405
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
406
+	 *
407
+	 * @access public
408
+	 * @return string
409
+	 */
410
+	private function visitorIp()
411
+	{
412
+		$visitor_ip = '0.0.0.0';
413
+		$server_keys = array(
414
+			'HTTP_CLIENT_IP',
415
+			'HTTP_X_FORWARDED_FOR',
416
+			'HTTP_X_FORWARDED',
417
+			'HTTP_X_CLUSTER_CLIENT_IP',
418
+			'HTTP_FORWARDED_FOR',
419
+			'HTTP_FORWARDED',
420
+			'REMOTE_ADDR',
421
+		);
422
+		foreach ($server_keys as $key) {
423
+			if (isset($this->server[ $key ])) {
424
+				foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
425
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
426
+						$visitor_ip = $ip;
427
+					}
428
+				}
429
+			}
430
+		}
431
+		return $visitor_ip;
432
+	}
433
+
434
+
435
+	/**
436
+	 * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
437
+	 * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
438
+	 *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
439
+	 *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
440
+	 * @return string
441
+	 */
442
+	public function requestUri($relativeToWpRoot = false)
443
+	{
444
+		$request_uri = filter_input(
445
+			INPUT_SERVER,
446
+			'REQUEST_URI',
447
+			FILTER_SANITIZE_URL,
448
+			FILTER_NULL_ON_FAILURE
449
+		);
450
+		if (empty($request_uri)) {
451
+			// fallback sanitization if the above fails
452
+			$request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
453
+		}
454
+		if ($relativeToWpRoot) {
455
+			$home_path = untrailingslashit(
456
+				parse_url(
457
+					home_url(),
458
+					PHP_URL_PATH
459
+				)
460
+			);
461
+			$request_uri = str_replace(
462
+				$home_path,
463
+				'',
464
+				$request_uri
465
+			);
466
+		}
467
+		return $request_uri;
468
+	}
469
+
470
+	/**
471
+	 * @return string
472
+	 */
473
+	public function userAgent()
474
+	{
475
+		return $this->user_agent;
476
+	}
477
+
478
+
479
+	/**
480
+	 * @param string $user_agent
481
+	 */
482
+	public function setUserAgent($user_agent = '')
483
+	{
484
+		if ($user_agent === '' || ! is_string($user_agent)) {
485
+			$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
486
+		}
487
+		$this->user_agent = $user_agent;
488
+	}
489
+
490
+
491
+	/**
492
+	 * @return bool
493
+	 */
494
+	public function isBot()
495
+	{
496
+		return $this->is_bot;
497
+	}
498
+
499
+
500
+	/**
501
+	 * @param bool $is_bot
502
+	 */
503
+	public function setIsBot($is_bot)
504
+	{
505
+		$this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
506
+	}
507
+
508
+
509
+	/**
510
+	 * @return bool
511
+	 */
512
+	public function isActivation()
513
+	{
514
+		return $this->request_type->isActivation();
515
+	}
516
+
517
+
518
+	/**
519
+	 * @param $is_activation
520
+	 * @return bool
521
+	 */
522
+	public function setIsActivation($is_activation)
523
+	{
524
+		return $this->request_type->setIsActivation($is_activation);
525
+	}
526
+
527
+
528
+	/**
529
+	 * @return bool
530
+	 */
531
+	public function isAdmin()
532
+	{
533
+		return $this->request_type->isAdmin();
534
+	}
535
+
536
+
537
+	/**
538
+	 * @return bool
539
+	 */
540
+	public function isAdminAjax()
541
+	{
542
+		return $this->request_type->isAdminAjax();
543
+	}
544
+
545
+
546
+	/**
547
+	 * @return bool
548
+	 */
549
+	public function isAjax()
550
+	{
551
+		return $this->request_type->isAjax();
552
+	}
553
+
554
+
555
+	/**
556
+	 * @return bool
557
+	 */
558
+	public function isEeAjax()
559
+	{
560
+		return $this->request_type->isEeAjax();
561
+	}
562
+
563
+
564
+	/**
565
+	 * @return bool
566
+	 */
567
+	public function isOtherAjax()
568
+	{
569
+		return $this->request_type->isOtherAjax();
570
+	}
571
+
572
+
573
+	/**
574
+	 * @return bool
575
+	 */
576
+	public function isApi()
577
+	{
578
+		return $this->request_type->isApi();
579
+	}
580
+
581
+
582
+	/**
583
+	 * @return bool
584
+	 */
585
+	public function isCli()
586
+	{
587
+		return $this->request_type->isCli();
588
+	}
589
+
590
+
591
+	/**
592
+	 * @return bool
593
+	 */
594
+	public function isCron()
595
+	{
596
+		return $this->request_type->isCron();
597
+	}
598
+
599
+
600
+	/**
601
+	 * @return bool
602
+	 */
603
+	public function isFeed()
604
+	{
605
+		return $this->request_type->isFeed();
606
+	}
607
+
608
+
609
+	/**
610
+	 * @return bool
611
+	 */
612
+	public function isFrontend()
613
+	{
614
+		return $this->request_type->isFrontend();
615
+	}
616
+
617
+
618
+	/**
619
+	 * @return bool
620
+	 */
621
+	public function isFrontAjax()
622
+	{
623
+		return $this->request_type->isFrontAjax();
624
+	}
625
+
626
+
627
+	/**
628
+	 * @return bool
629
+	 */
630
+	public function isIframe()
631
+	{
632
+		return $this->request_type->isIframe();
633
+	}
634
+
635
+
636
+	/**
637
+	 * @return bool
638
+	 */
639
+	public function isWordPressApi()
640
+	{
641
+		return $this->request_type->isWordPressApi();
642
+	}
643
+
644
+
645
+
646
+	/**
647
+	 * @return bool
648
+	 */
649
+	public function isWordPressHeartbeat()
650
+	{
651
+		return $this->request_type->isWordPressHeartbeat();
652
+	}
653
+
654
+
655
+
656
+	/**
657
+	 * @return bool
658
+	 */
659
+	public function isWordPressScrape()
660
+	{
661
+		return $this->request_type->isWordPressScrape();
662
+	}
663
+
664
+
665
+	/**
666
+	 * @return string
667
+	 */
668
+	public function slug()
669
+	{
670
+		return $this->request_type->slug();
671
+	}
672 672
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
             || ($key === 'ee' && empty($this->request['ee']))
183 183
             || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
184 184
         ) {
185
-            $this->request[ $key ] = $value;
185
+            $this->request[$key] = $value;
186 186
         }
187 187
     }
188 188
 
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
             preg_quote($pattern, '/')
274 274
         );
275 275
         foreach ($request_params as $key => $request_param) {
276
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
276
+            if (preg_match('/^'.$pattern.'$/is', $key)) {
277 277
                 // return value for request param
278 278
                 if ($return === 'value') {
279
-                    return $request_params[ $key ];
279
+                    return $request_params[$key];
280 280
                 }
281 281
                 // or actual key or true just to indicate it was found
282 282
                 return $return === 'key' ? $key : true;
@@ -333,29 +333,29 @@  discard block
 block discarded – undo
333 333
                 $key = $real_key ? $real_key : $key;
334 334
             }
335 335
             // check if top level key exists
336
-            if (isset($request_params[ $key ])) {
336
+            if (isset($request_params[$key])) {
337 337
                 // build a new key to pass along like: 'second[third]'
338 338
                 // or just 'second' depending on depth of keys
339 339
                 $key_string = array_shift($keys);
340
-                if (! empty($keys)) {
341
-                    $key_string .= '[' . implode('][', $keys) . ']';
340
+                if ( ! empty($keys)) {
341
+                    $key_string .= '['.implode('][', $keys).']';
342 342
                 }
343 343
                 return $this->requestParameterDrillDown(
344 344
                     $key_string,
345 345
                     $default,
346 346
                     $callback,
347
-                    $request_params[ $key ]
347
+                    $request_params[$key]
348 348
                 );
349 349
             }
350 350
         }
351 351
         if ($callback === 'is_set') {
352
-            return isset($request_params[ $key ]);
352
+            return isset($request_params[$key]);
353 353
         }
354 354
         if ($callback === 'match') {
355 355
             return $this->match($key, $request_params, $default);
356 356
         }
357
-        return isset($request_params[ $key ])
358
-            ? $request_params[ $key ]
357
+        return isset($request_params[$key])
358
+            ? $request_params[$key]
359 359
             : $default;
360 360
     }
361 361
 
@@ -369,10 +369,10 @@  discard block
 block discarded – undo
369 369
     public function unSetRequestParam($key, $unset_from_global_too = false)
370 370
     {
371 371
         // because unset may not actually remove var
372
-        $this->request[ $key ] = null;
373
-        unset($this->request[ $key ]);
372
+        $this->request[$key] = null;
373
+        unset($this->request[$key]);
374 374
         if ($unset_from_global_too) {
375
-            unset($_REQUEST[ $key ]);
375
+            unset($_REQUEST[$key]);
376 376
         }
377 377
     }
378 378
 
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
             'REMOTE_ADDR',
421 421
         );
422 422
         foreach ($server_keys as $key) {
423
-            if (isset($this->server[ $key ])) {
424
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
423
+            if (isset($this->server[$key])) {
424
+                foreach (array_map('trim', explode(',', $this->server[$key])) as $ip) {
425 425
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
426 426
                         $visitor_ip = $ip;
427 427
                     }
Please login to merge, or discard this patch.
core/services/admin/AdminPageHeaderDecoratorInterface.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@
 block discarded – undo
13 13
 interface AdminPageHeaderDecoratorInterface
14 14
 {
15 15
 
16
-    /**
17
-     * @param string $text
18
-     * @return string
19
-     * @since $VID:$
20
-     */
21
-    public function getHeaderText($text = '');
16
+	/**
17
+	 * @param string $text
18
+	 * @return string
19
+	 * @since $VID:$
20
+	 */
21
+	public function getHeaderText($text = '');
22 22
 }
Please login to merge, or discard this patch.