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