Completed
Branch fix/escaping-2 (511e5c)
by
unknown
14:14 queued 12:22
created
core/admin/EE_Admin_Page_CPT.core.php 1 patch
Indentation   +1486 added lines, -1486 removed lines patch added patch discarded remove patch
@@ -28,492 +28,492 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * This gets set in _setup_cpt
33
-     * It will contain the object for the custom post type.
34
-     *
35
-     * @var EE_CPT_Base
36
-     */
37
-    protected $_cpt_object;
38
-
39
-
40
-    /**
41
-     * a boolean flag to set whether the current route is a cpt route or not.
42
-     *
43
-     * @var bool
44
-     */
45
-    protected $_cpt_route = false;
46
-
47
-
48
-    /**
49
-     * This property allows cpt classes to define multiple routes as cpt routes.
50
-     * //in this array we define what the custom post type for this route is.
51
-     * array(
52
-     * 'route_name' => 'custom_post_type_slug'
53
-     * )
54
-     *
55
-     * @var array
56
-     */
57
-    protected $_cpt_routes = [];
58
-
59
-
60
-    /**
61
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
62
-     * in this format:
63
-     * array(
64
-     * 'post_type_slug' => 'edit_route'
65
-     * )
66
-     *
67
-     * @var array
68
-     */
69
-    protected $_cpt_edit_routes = [];
70
-
71
-
72
-    /**
73
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
-     * _cpt_model_names property should be in the following format: array(
76
-     * 'route_defined_by_action_param' => 'Model_Name')
77
-     *
78
-     * @var array $_cpt_model_names
79
-     */
80
-    protected $_cpt_model_names = [];
81
-
82
-
83
-    /**
84
-     * @var EE_CPT_Base
85
-     */
86
-    protected $_cpt_model_obj = false;
87
-
88
-    /**
89
-     * @var LoaderInterface $loader ;
90
-     */
91
-    protected $loader;
92
-
93
-    /**
94
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
95
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
96
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
97
-     * Registration of containers should be done before load_page_dependencies() is run.
98
-     *
99
-     * @var array()
100
-     */
101
-    protected $_autosave_containers = [];
102
-
103
-    protected $_autosave_fields     = [];
104
-
105
-    /**
106
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
107
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
108
-     *
109
-     * @var array
110
-     */
111
-    protected $_pagenow_map;
112
-
113
-
114
-    /**
115
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
116
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
117
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
118
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
119
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
120
-     *
121
-     * @abstract
122
-     * @param string      $post_id The ID of the cpt that was saved (so you can link relationally)
123
-     * @param WP_Post     $post    The post object of the cpt that was saved.
124
-     * @return void
125
-     */
126
-    abstract protected function _insert_update_cpt_item($post_id, $post);
127
-
128
-
129
-    /**
130
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
131
-     *
132
-     * @abstract
133
-     * @param string $post_id The ID of the cpt that was trashed
134
-     * @return void
135
-     */
136
-    abstract public function trash_cpt_item($post_id);
137
-
138
-
139
-    /**
140
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
141
-     *
142
-     * @param string $post_id theID of the cpt that was untrashed
143
-     * @return void
144
-     */
145
-    abstract public function restore_cpt_item($post_id);
146
-
147
-
148
-    /**
149
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
150
-     * from the db
151
-     *
152
-     * @param string $post_id the ID of the cpt that was deleted
153
-     * @return void
154
-     */
155
-    abstract public function delete_cpt_item($post_id);
156
-
157
-
158
-    /**
159
-     * @return LoaderInterface
160
-     * @throws InvalidArgumentException
161
-     * @throws InvalidDataTypeException
162
-     * @throws InvalidInterfaceException
163
-     */
164
-    protected function getLoader()
165
-    {
166
-        if (! $this->loader instanceof LoaderInterface) {
167
-            $this->loader = LoaderFactory::getLoader();
168
-        }
169
-        return $this->loader;
170
-    }
171
-
172
-
173
-    /**
174
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
175
-     *
176
-     * @return void
177
-     */
178
-    protected function _before_page_setup()
179
-    {
180
-        $this->raw_req_action = $this->request->getRequestParam('action');
181
-        $this->raw_req_page = $this->request->getRequestParam('page');
182
-        $this->_cpt_routes = array_merge(
183
-            [
184
-                'create_new' => $this->page_slug,
185
-                'edit'       => $this->page_slug,
186
-                'trash'      => $this->page_slug,
187
-            ],
188
-            $this->_cpt_routes
189
-        );
190
-        $cpt_route_action  = isset($this->_cpt_routes[ $this->raw_req_action ])
191
-            ? $this->_cpt_routes[ $this->raw_req_action ]
192
-            : null;
193
-        // let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page
194
-        $page              = $this->raw_req_page ?: $this->page_slug;
195
-        $page              = $cpt_route_action ?: $page;
196
-        $this->_cpt_object = get_post_type_object($page);
197
-        // tweak pagenow for page loading.
198
-        if (! $this->_pagenow_map) {
199
-            $this->_pagenow_map = [
200
-                'create_new' => 'post-new.php',
201
-                'edit'       => 'post.php',
202
-                'trash'      => 'post.php',
203
-            ];
204
-        }
205
-        add_action('current_screen', [$this, 'modify_pagenow']);
206
-        // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
207
-        // get current page from autosave
208
-        $current_page        = $this->request->getRequestParam('ee_autosave_data[ee-cpt-hidden-inputs][current_page]');
209
-        $this->_current_page = $this->request->getRequestParam('current_page', $current_page);
210
-    }
211
-
212
-
213
-    /**
214
-     * Simply ensure that we simulate the correct post route for cpt screens
215
-     *
216
-     * @param WP_Screen $current_screen
217
-     * @return void
218
-     */
219
-    public function modify_pagenow($current_screen)
220
-    {
221
-        // possibly reset pagenow.
222
-        if (
223
-            $this->page_slug === $this->raw_req_page
224
-            && isset($this->_pagenow_map[ $this->raw_req_action ])
225
-        ) {
226
-            global $pagenow, $hook_suffix;
227
-            $pagenow     = $this->_pagenow_map[ $this->raw_req_action ];
228
-            $hook_suffix = $pagenow;
229
-        }
230
-    }
231
-
232
-
233
-    /**
234
-     * This method is used to register additional autosave containers to the _autosave_containers property.
235
-     *
236
-     * @param array $ids  an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
237
-     *                    you would send along the id of a metabox container.
238
-     * @return void
239
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
240
-     *                    automatically register the id for the post metabox as a container.
241
-     */
242
-    protected function _register_autosave_containers($ids)
243
-    {
244
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
245
-    }
246
-
247
-
248
-    /**
249
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
250
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
251
-     */
252
-    protected function _set_autosave_containers()
253
-    {
254
-        global $wp_meta_boxes;
255
-        $containers = [];
256
-        if (empty($wp_meta_boxes)) {
257
-            return;
258
-        }
259
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : [];
260
-        foreach ($current_metaboxes as $box_context) {
261
-            foreach ($box_context as $box_details) {
262
-                foreach ($box_details as $box) {
263
-                    if (
264
-                        is_array($box) && is_array($box['callback'])
265
-                        && (
266
-                            $box['callback'][0] instanceof EE_Admin_Page
267
-                            || $box['callback'][0] instanceof EE_Admin_Hooks
268
-                        )
269
-                    ) {
270
-                        $containers[] = $box['id'];
271
-                    }
272
-                }
273
-            }
274
-        }
275
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
276
-        // add hidden inputs container
277
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
278
-    }
279
-
280
-
281
-    protected function _load_autosave_scripts_styles()
282
-    {
283
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
31
+	/**
32
+	 * This gets set in _setup_cpt
33
+	 * It will contain the object for the custom post type.
34
+	 *
35
+	 * @var EE_CPT_Base
36
+	 */
37
+	protected $_cpt_object;
38
+
39
+
40
+	/**
41
+	 * a boolean flag to set whether the current route is a cpt route or not.
42
+	 *
43
+	 * @var bool
44
+	 */
45
+	protected $_cpt_route = false;
46
+
47
+
48
+	/**
49
+	 * This property allows cpt classes to define multiple routes as cpt routes.
50
+	 * //in this array we define what the custom post type for this route is.
51
+	 * array(
52
+	 * 'route_name' => 'custom_post_type_slug'
53
+	 * )
54
+	 *
55
+	 * @var array
56
+	 */
57
+	protected $_cpt_routes = [];
58
+
59
+
60
+	/**
61
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
62
+	 * in this format:
63
+	 * array(
64
+	 * 'post_type_slug' => 'edit_route'
65
+	 * )
66
+	 *
67
+	 * @var array
68
+	 */
69
+	protected $_cpt_edit_routes = [];
70
+
71
+
72
+	/**
73
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
+	 * _cpt_model_names property should be in the following format: array(
76
+	 * 'route_defined_by_action_param' => 'Model_Name')
77
+	 *
78
+	 * @var array $_cpt_model_names
79
+	 */
80
+	protected $_cpt_model_names = [];
81
+
82
+
83
+	/**
84
+	 * @var EE_CPT_Base
85
+	 */
86
+	protected $_cpt_model_obj = false;
87
+
88
+	/**
89
+	 * @var LoaderInterface $loader ;
90
+	 */
91
+	protected $loader;
92
+
93
+	/**
94
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
95
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
96
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
97
+	 * Registration of containers should be done before load_page_dependencies() is run.
98
+	 *
99
+	 * @var array()
100
+	 */
101
+	protected $_autosave_containers = [];
102
+
103
+	protected $_autosave_fields     = [];
104
+
105
+	/**
106
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
107
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
108
+	 *
109
+	 * @var array
110
+	 */
111
+	protected $_pagenow_map;
112
+
113
+
114
+	/**
115
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
116
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
117
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
118
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
119
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
120
+	 *
121
+	 * @abstract
122
+	 * @param string      $post_id The ID of the cpt that was saved (so you can link relationally)
123
+	 * @param WP_Post     $post    The post object of the cpt that was saved.
124
+	 * @return void
125
+	 */
126
+	abstract protected function _insert_update_cpt_item($post_id, $post);
127
+
128
+
129
+	/**
130
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
131
+	 *
132
+	 * @abstract
133
+	 * @param string $post_id The ID of the cpt that was trashed
134
+	 * @return void
135
+	 */
136
+	abstract public function trash_cpt_item($post_id);
137
+
138
+
139
+	/**
140
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
141
+	 *
142
+	 * @param string $post_id theID of the cpt that was untrashed
143
+	 * @return void
144
+	 */
145
+	abstract public function restore_cpt_item($post_id);
146
+
147
+
148
+	/**
149
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
150
+	 * from the db
151
+	 *
152
+	 * @param string $post_id the ID of the cpt that was deleted
153
+	 * @return void
154
+	 */
155
+	abstract public function delete_cpt_item($post_id);
156
+
157
+
158
+	/**
159
+	 * @return LoaderInterface
160
+	 * @throws InvalidArgumentException
161
+	 * @throws InvalidDataTypeException
162
+	 * @throws InvalidInterfaceException
163
+	 */
164
+	protected function getLoader()
165
+	{
166
+		if (! $this->loader instanceof LoaderInterface) {
167
+			$this->loader = LoaderFactory::getLoader();
168
+		}
169
+		return $this->loader;
170
+	}
171
+
172
+
173
+	/**
174
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
175
+	 *
176
+	 * @return void
177
+	 */
178
+	protected function _before_page_setup()
179
+	{
180
+		$this->raw_req_action = $this->request->getRequestParam('action');
181
+		$this->raw_req_page = $this->request->getRequestParam('page');
182
+		$this->_cpt_routes = array_merge(
183
+			[
184
+				'create_new' => $this->page_slug,
185
+				'edit'       => $this->page_slug,
186
+				'trash'      => $this->page_slug,
187
+			],
188
+			$this->_cpt_routes
189
+		);
190
+		$cpt_route_action  = isset($this->_cpt_routes[ $this->raw_req_action ])
191
+			? $this->_cpt_routes[ $this->raw_req_action ]
192
+			: null;
193
+		// let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page
194
+		$page              = $this->raw_req_page ?: $this->page_slug;
195
+		$page              = $cpt_route_action ?: $page;
196
+		$this->_cpt_object = get_post_type_object($page);
197
+		// tweak pagenow for page loading.
198
+		if (! $this->_pagenow_map) {
199
+			$this->_pagenow_map = [
200
+				'create_new' => 'post-new.php',
201
+				'edit'       => 'post.php',
202
+				'trash'      => 'post.php',
203
+			];
204
+		}
205
+		add_action('current_screen', [$this, 'modify_pagenow']);
206
+		// TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
207
+		// get current page from autosave
208
+		$current_page        = $this->request->getRequestParam('ee_autosave_data[ee-cpt-hidden-inputs][current_page]');
209
+		$this->_current_page = $this->request->getRequestParam('current_page', $current_page);
210
+	}
211
+
212
+
213
+	/**
214
+	 * Simply ensure that we simulate the correct post route for cpt screens
215
+	 *
216
+	 * @param WP_Screen $current_screen
217
+	 * @return void
218
+	 */
219
+	public function modify_pagenow($current_screen)
220
+	{
221
+		// possibly reset pagenow.
222
+		if (
223
+			$this->page_slug === $this->raw_req_page
224
+			&& isset($this->_pagenow_map[ $this->raw_req_action ])
225
+		) {
226
+			global $pagenow, $hook_suffix;
227
+			$pagenow     = $this->_pagenow_map[ $this->raw_req_action ];
228
+			$hook_suffix = $pagenow;
229
+		}
230
+	}
231
+
232
+
233
+	/**
234
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
235
+	 *
236
+	 * @param array $ids  an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
237
+	 *                    you would send along the id of a metabox container.
238
+	 * @return void
239
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
240
+	 *                    automatically register the id for the post metabox as a container.
241
+	 */
242
+	protected function _register_autosave_containers($ids)
243
+	{
244
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
245
+	}
246
+
247
+
248
+	/**
249
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
250
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
251
+	 */
252
+	protected function _set_autosave_containers()
253
+	{
254
+		global $wp_meta_boxes;
255
+		$containers = [];
256
+		if (empty($wp_meta_boxes)) {
257
+			return;
258
+		}
259
+		$current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : [];
260
+		foreach ($current_metaboxes as $box_context) {
261
+			foreach ($box_context as $box_details) {
262
+				foreach ($box_details as $box) {
263
+					if (
264
+						is_array($box) && is_array($box['callback'])
265
+						&& (
266
+							$box['callback'][0] instanceof EE_Admin_Page
267
+							|| $box['callback'][0] instanceof EE_Admin_Hooks
268
+						)
269
+					) {
270
+						$containers[] = $box['id'];
271
+					}
272
+				}
273
+			}
274
+		}
275
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
276
+		// add hidden inputs container
277
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
278
+	}
279
+
280
+
281
+	protected function _load_autosave_scripts_styles()
282
+	{
283
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
284 284
         wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2
285 285
 
286
-        // filter _autosave_containers
287
-        $containers = apply_filters(
288
-            'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
289
-            $this->_autosave_containers,
290
-            $this
291
-        );
292
-        $containers = apply_filters(
293
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
294
-            $containers,
295
-            $this
296
-        );
297
-
298
-        wp_localize_script(
299
-            'event_editor_js',
300
-            'EE_AUTOSAVE_IDS',
301
-            $containers
302
-        ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
303
-
304
-        $unsaved_data_msg = [
305
-            'eventmsg'     => sprintf(
306
-                wp_strip_all_tags(
307
-                    __(
308
-                        "The changes you made to this %s will be lost if you navigate away from this page.",
309
-                        'event_espresso'
310
-                    )
311
-                ),
312
-                $this->_cpt_object->labels->singular_name
313
-            ),
314
-            'inputChanged' => 0,
315
-        ];
316
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
317
-    }
318
-
319
-
320
-    public function load_page_dependencies()
321
-    {
322
-        try {
323
-            $this->_load_page_dependencies();
324
-        } catch (EE_Error $e) {
325
-            $e->get_error();
326
-        }
327
-    }
328
-
329
-
330
-    /**
331
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
332
-     *
333
-     * @return void
334
-     */
335
-    protected function _load_page_dependencies()
336
-    {
337
-        // we only add stuff if this is a cpt_route!
338
-        if (! $this->_cpt_route) {
339
-            parent::_load_page_dependencies();
340
-            return;
341
-        }
342
-        // now let's do some automatic filters into the wp_system
343
-        // and we'll check to make sure the CHILD class
344
-        // automatically has the required methods in place.
345
-        // the following filters are for setting all the redirects
346
-        // on DEFAULT WP custom post type actions
347
-        // let's add a hidden input to the post-edit form
348
-        // so we know when we have to trigger our custom redirects!
349
-        // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
350
-        add_action('edit_form_after_title', [$this, 'cpt_post_form_hidden_input']);
351
-        // inject our Admin page nav tabs...
352
-        // let's make sure the nav tabs are set if they aren't already
353
-        // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
354
-        add_action('post_edit_form_tag', [$this, 'inject_nav_tabs']);
355
-        // modify the post_updated messages array
356
-        add_action('post_updated_messages', [$this, 'post_update_messages'], 10);
357
-        // add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
358
-        // cpts use the same format for shortlinks as posts!
359
-        add_filter('pre_get_shortlink', [$this, 'add_shortlink_button_to_editor'], 10, 4);
360
-        // This basically allows us to change the title of the "publish" metabox area
361
-        // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
362
-        if (! empty($this->_labels['publishbox'])) {
363
-            $box_label = is_array($this->_labels['publishbox'])
364
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
365
-                ? $this->_labels['publishbox'][ $this->_req_action ]
366
-                : $this->_labels['publishbox'];
367
-            add_meta_box(
368
-                'submitdiv',
369
-                $box_label,
370
-                'post_submit_meta_box',
371
-                $this->_cpt_routes[ $this->_req_action ],
372
-                'side',
373
-                'core'
374
-            );
375
-        }
376
-        // let's add page_templates metabox if this cpt added support for it.
377
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
378
-            add_meta_box(
379
-                'page_templates',
380
-                esc_html__('Page Template', 'event_espresso'),
381
-                [$this, 'page_template_meta_box'],
382
-                $this->_cpt_routes[ $this->_req_action ],
383
-                'side',
384
-                'default'
385
-            );
386
-        }
387
-        // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
388
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
389
-            add_filter('get_sample_permalink_html', [$this, 'extra_permalink_field_buttons'], 10, 4);
390
-        }
391
-        // add preview button
392
-        add_filter('get_sample_permalink_html', [$this, 'preview_button_html'], 5, 4);
393
-        // insert our own post_stati dropdown
394
-        add_action('post_submitbox_misc_actions', [$this, 'custom_post_stati_dropdown'], 10);
395
-        // This allows adding additional information to the publish post submitbox on the wp post edit form
396
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
397
-            add_action('post_submitbox_misc_actions', [$this, 'extra_misc_actions_publish_box'], 10);
398
-        }
399
-        // This allows for adding additional stuff after the title field on the wp post edit form.
400
-        // This is also before the wp_editor for post description field.
401
-        if (method_exists($this, 'edit_form_after_title')) {
402
-            add_action('edit_form_after_title', [$this, 'edit_form_after_title'], 10);
403
-        }
404
-        /**
405
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
406
-         */
407
-        add_filter('clean_url', [$this, 'switch_core_wp_urls_with_ours'], 10, 3);
408
-        parent::_load_page_dependencies();
409
-        // notice we are ALSO going to load the pagenow hook set for this route
410
-        // (see _before_page_setup for the reset of the pagenow global ).
411
-        // This is for any plugins that are doing things properly
412
-        // and hooking into the load page hook for core wp cpt routes.
413
-        global $pagenow;
414
-        add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20);
415
-        do_action('load-' . $pagenow);
416
-        add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30);
417
-        // we route REALLY early.
418
-        try {
419
-            $this->_route_admin_request();
420
-        } catch (EE_Error $e) {
421
-            $e->get_error();
422
-        }
423
-    }
424
-
425
-
426
-    /**
427
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
428
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
429
-     * route instead.
430
-     *
431
-     * @param string $good_protocol_url The escaped url.
432
-     * @param string $original_url      The original url.
433
-     * @param string $_context          The context sent to the esc_url method.
434
-     * @return string possibly a new url for our route.
435
-     */
436
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
437
-    {
438
-        $routes_to_match = [
439
-            0 => [
440
-                'edit.php?post_type=espresso_attendees',
441
-                'admin.php?page=espresso_registrations&action=contact_list',
442
-            ],
443
-            1 => [
444
-                'edit.php?post_type=' . $this->_cpt_object->name,
445
-                'admin.php?page=' . $this->_cpt_object->name,
446
-            ],
447
-        ];
448
-        foreach ($routes_to_match as $route_matches) {
449
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
450
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
451
-            }
452
-        }
453
-        return $good_protocol_url;
454
-    }
455
-
456
-
457
-    /**
458
-     * Determine whether the current cpt supports page templates or not.
459
-     *
460
-     * @param string $cpt_name The cpt slug we're checking on.
461
-     * @return bool True supported, false not.
462
-     * @throws InvalidArgumentException
463
-     * @throws InvalidDataTypeException
464
-     * @throws InvalidInterfaceException
465
-     * @since %VER%
466
-     */
467
-    private function _supports_page_templates($cpt_name)
468
-    {
469
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
470
-        $custom_post_types = $this->getLoader()->getShared(
471
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
472
-        );
473
-        $cpt_args          = $custom_post_types->getDefinitions();
474
-        $cpt_args          = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : [];
475
-        $cpt_has_support   = ! empty($cpt_args['page_templates']);
476
-
477
-        // if the installed version of WP is > 4.7 we do some additional checks.
478
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
479
-            $post_templates = wp_get_theme()->get_post_templates();
480
-            // if there are $post_templates for this cpt, then we return false for this method because
481
-            // that means we aren't going to load our page template manager and leave that up to the native
482
-            // cpt template manager.
483
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
484
-        }
485
-
486
-        return $cpt_has_support;
487
-    }
488
-
489
-
490
-    /**
491
-     * Callback for the page_templates metabox selector.
492
-     *
493
-     * @return void
494
-     * @since %VER%
495
-     */
496
-    public function page_template_meta_box()
497
-    {
498
-        global $post;
499
-        $template = '';
500
-
501
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
502
-            $page_template_count = count(get_page_templates());
503
-        } else {
504
-            $page_template_count = count(get_page_templates($post));
505
-        };
506
-
507
-        if ($page_template_count) {
508
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
509
-            $template      = ! empty($page_template) ? $page_template : '';
510
-        }
511
-        ?>
286
+		// filter _autosave_containers
287
+		$containers = apply_filters(
288
+			'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
289
+			$this->_autosave_containers,
290
+			$this
291
+		);
292
+		$containers = apply_filters(
293
+			'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
294
+			$containers,
295
+			$this
296
+		);
297
+
298
+		wp_localize_script(
299
+			'event_editor_js',
300
+			'EE_AUTOSAVE_IDS',
301
+			$containers
302
+		); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
303
+
304
+		$unsaved_data_msg = [
305
+			'eventmsg'     => sprintf(
306
+				wp_strip_all_tags(
307
+					__(
308
+						"The changes you made to this %s will be lost if you navigate away from this page.",
309
+						'event_espresso'
310
+					)
311
+				),
312
+				$this->_cpt_object->labels->singular_name
313
+			),
314
+			'inputChanged' => 0,
315
+		];
316
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
317
+	}
318
+
319
+
320
+	public function load_page_dependencies()
321
+	{
322
+		try {
323
+			$this->_load_page_dependencies();
324
+		} catch (EE_Error $e) {
325
+			$e->get_error();
326
+		}
327
+	}
328
+
329
+
330
+	/**
331
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
332
+	 *
333
+	 * @return void
334
+	 */
335
+	protected function _load_page_dependencies()
336
+	{
337
+		// we only add stuff if this is a cpt_route!
338
+		if (! $this->_cpt_route) {
339
+			parent::_load_page_dependencies();
340
+			return;
341
+		}
342
+		// now let's do some automatic filters into the wp_system
343
+		// and we'll check to make sure the CHILD class
344
+		// automatically has the required methods in place.
345
+		// the following filters are for setting all the redirects
346
+		// on DEFAULT WP custom post type actions
347
+		// let's add a hidden input to the post-edit form
348
+		// so we know when we have to trigger our custom redirects!
349
+		// Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
350
+		add_action('edit_form_after_title', [$this, 'cpt_post_form_hidden_input']);
351
+		// inject our Admin page nav tabs...
352
+		// let's make sure the nav tabs are set if they aren't already
353
+		// if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
354
+		add_action('post_edit_form_tag', [$this, 'inject_nav_tabs']);
355
+		// modify the post_updated messages array
356
+		add_action('post_updated_messages', [$this, 'post_update_messages'], 10);
357
+		// add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
358
+		// cpts use the same format for shortlinks as posts!
359
+		add_filter('pre_get_shortlink', [$this, 'add_shortlink_button_to_editor'], 10, 4);
360
+		// This basically allows us to change the title of the "publish" metabox area
361
+		// on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
362
+		if (! empty($this->_labels['publishbox'])) {
363
+			$box_label = is_array($this->_labels['publishbox'])
364
+						 && isset($this->_labels['publishbox'][ $this->_req_action ])
365
+				? $this->_labels['publishbox'][ $this->_req_action ]
366
+				: $this->_labels['publishbox'];
367
+			add_meta_box(
368
+				'submitdiv',
369
+				$box_label,
370
+				'post_submit_meta_box',
371
+				$this->_cpt_routes[ $this->_req_action ],
372
+				'side',
373
+				'core'
374
+			);
375
+		}
376
+		// let's add page_templates metabox if this cpt added support for it.
377
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
378
+			add_meta_box(
379
+				'page_templates',
380
+				esc_html__('Page Template', 'event_espresso'),
381
+				[$this, 'page_template_meta_box'],
382
+				$this->_cpt_routes[ $this->_req_action ],
383
+				'side',
384
+				'default'
385
+			);
386
+		}
387
+		// this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
388
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
389
+			add_filter('get_sample_permalink_html', [$this, 'extra_permalink_field_buttons'], 10, 4);
390
+		}
391
+		// add preview button
392
+		add_filter('get_sample_permalink_html', [$this, 'preview_button_html'], 5, 4);
393
+		// insert our own post_stati dropdown
394
+		add_action('post_submitbox_misc_actions', [$this, 'custom_post_stati_dropdown'], 10);
395
+		// This allows adding additional information to the publish post submitbox on the wp post edit form
396
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
397
+			add_action('post_submitbox_misc_actions', [$this, 'extra_misc_actions_publish_box'], 10);
398
+		}
399
+		// This allows for adding additional stuff after the title field on the wp post edit form.
400
+		// This is also before the wp_editor for post description field.
401
+		if (method_exists($this, 'edit_form_after_title')) {
402
+			add_action('edit_form_after_title', [$this, 'edit_form_after_title'], 10);
403
+		}
404
+		/**
405
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
406
+		 */
407
+		add_filter('clean_url', [$this, 'switch_core_wp_urls_with_ours'], 10, 3);
408
+		parent::_load_page_dependencies();
409
+		// notice we are ALSO going to load the pagenow hook set for this route
410
+		// (see _before_page_setup for the reset of the pagenow global ).
411
+		// This is for any plugins that are doing things properly
412
+		// and hooking into the load page hook for core wp cpt routes.
413
+		global $pagenow;
414
+		add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20);
415
+		do_action('load-' . $pagenow);
416
+		add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30);
417
+		// we route REALLY early.
418
+		try {
419
+			$this->_route_admin_request();
420
+		} catch (EE_Error $e) {
421
+			$e->get_error();
422
+		}
423
+	}
424
+
425
+
426
+	/**
427
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
428
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
429
+	 * route instead.
430
+	 *
431
+	 * @param string $good_protocol_url The escaped url.
432
+	 * @param string $original_url      The original url.
433
+	 * @param string $_context          The context sent to the esc_url method.
434
+	 * @return string possibly a new url for our route.
435
+	 */
436
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
437
+	{
438
+		$routes_to_match = [
439
+			0 => [
440
+				'edit.php?post_type=espresso_attendees',
441
+				'admin.php?page=espresso_registrations&action=contact_list',
442
+			],
443
+			1 => [
444
+				'edit.php?post_type=' . $this->_cpt_object->name,
445
+				'admin.php?page=' . $this->_cpt_object->name,
446
+			],
447
+		];
448
+		foreach ($routes_to_match as $route_matches) {
449
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
450
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
451
+			}
452
+		}
453
+		return $good_protocol_url;
454
+	}
455
+
456
+
457
+	/**
458
+	 * Determine whether the current cpt supports page templates or not.
459
+	 *
460
+	 * @param string $cpt_name The cpt slug we're checking on.
461
+	 * @return bool True supported, false not.
462
+	 * @throws InvalidArgumentException
463
+	 * @throws InvalidDataTypeException
464
+	 * @throws InvalidInterfaceException
465
+	 * @since %VER%
466
+	 */
467
+	private function _supports_page_templates($cpt_name)
468
+	{
469
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
470
+		$custom_post_types = $this->getLoader()->getShared(
471
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
472
+		);
473
+		$cpt_args          = $custom_post_types->getDefinitions();
474
+		$cpt_args          = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : [];
475
+		$cpt_has_support   = ! empty($cpt_args['page_templates']);
476
+
477
+		// if the installed version of WP is > 4.7 we do some additional checks.
478
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
479
+			$post_templates = wp_get_theme()->get_post_templates();
480
+			// if there are $post_templates for this cpt, then we return false for this method because
481
+			// that means we aren't going to load our page template manager and leave that up to the native
482
+			// cpt template manager.
483
+			$cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
484
+		}
485
+
486
+		return $cpt_has_support;
487
+	}
488
+
489
+
490
+	/**
491
+	 * Callback for the page_templates metabox selector.
492
+	 *
493
+	 * @return void
494
+	 * @since %VER%
495
+	 */
496
+	public function page_template_meta_box()
497
+	{
498
+		global $post;
499
+		$template = '';
500
+
501
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
502
+			$page_template_count = count(get_page_templates());
503
+		} else {
504
+			$page_template_count = count(get_page_templates($post));
505
+		};
506
+
507
+		if ($page_template_count) {
508
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
509
+			$template      = ! empty($page_template) ? $page_template : '';
510
+		}
511
+		?>
512 512
         <p><strong><?php esc_html_e('Template', 'event_espresso') ?></strong></p>
513 513
         <label class="screen-reader-text" for="page_template"><?php esc_html_e(
514
-            'Page Template',
515
-            'event_espresso'
516
-        ) ?></label>
514
+			'Page Template',
515
+			'event_espresso'
516
+		) ?></label>
517 517
         <select
518 518
             name="page_template" id="page_template"
519 519
         >
@@ -521,473 +521,473 @@  discard block
 block discarded – undo
521 521
             <?php page_template_dropdown($template); ?>
522 522
         </select>
523 523
         <?php
524
-    }
525
-
526
-
527
-    /**
528
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
529
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
530
-     *
531
-     * @param string $return    the current html
532
-     * @param int    $id        the post id for the page
533
-     * @param string $new_title What the title is
534
-     * @param string $new_slug  what the slug is
535
-     * @return string            The new html string for the permalink area
536
-     */
537
-    public function preview_button_html($return, $id, $new_title, $new_slug)
538
-    {
539
-        $post = get_post($id);
540
-        if ('publish' !== get_post_status($post)) {
541
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
542
-                       . get_preview_post_link($id)
543
-                       . '" class="button button-small">'
544
-                       . esc_html__('Preview', 'event_espresso')
545
-                       . '</a></span>'
546
-                       . "\n";
547
-        }
548
-        return $return;
549
-    }
550
-
551
-
552
-    /**
553
-     * add our custom post stati dropdown on the wp post page for this cpt
554
-     *
555
-     * @return void
556
-     */
557
-    public function custom_post_stati_dropdown()
558
-    {
559
-
560
-        $statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
561
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
562
-            ? $statuses[ $this->_cpt_model_obj->status() ]
563
-            : '';
564
-        $template_args    = [
565
-            'cur_status'            => $this->_cpt_model_obj->status(),
566
-            'statuses'              => $statuses,
567
-            'cur_status_label'      => $cur_status_label,
568
-            'localized_status_save' => sprintf(esc_html__('Save %s', 'event_espresso'), $cur_status_label),
569
-        ];
570
-        // we'll add a trash post status (WP doesn't add one for some reason)
571
-        if ($this->_cpt_model_obj->status() === 'trash') {
572
-            $template_args['cur_status_label'] = esc_html__('Trashed', 'event_espresso');
573
-            $statuses['trash']                 = esc_html__('Trashed', 'event_espresso');
574
-            $template_args['statuses']         = $statuses;
575
-        }
576
-
577
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
578
-        EEH_Template::display_template($template, $template_args);
579
-    }
580
-
581
-
582
-    public function setup_autosave_hooks()
583
-    {
584
-        $this->_set_autosave_containers();
585
-        $this->_load_autosave_scripts_styles();
586
-    }
587
-
588
-
589
-    /**
590
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a post object (available
591
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
592
-     * for the nonce in here, but then this method looks for two things:
593
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
594
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
595
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
596
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
597
-     * template args.
598
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
599
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
600
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
601
-     *    $this->_template_args['data']['items'] = array(
602
-     *        'event-datetime-ids' => '1,2,3';
603
-     *    );
604
-     *    Keep in mind the following things:
605
-     *    - "where" index is for the input with the id as that string.
606
-     *    - "what" index is what will be used for the value of that input.
607
-     *
608
-     * @return void
609
-     * @throws EE_Error
610
-     */
611
-    public function do_extra_autosave_stuff()
612
-    {
613
-        // next let's check for the autosave nonce (we'll use _verify_nonce )
614
-        $nonce = $this->request->getRequestParam('autosavenonce');
615
-        $this->_verify_nonce($nonce, 'autosave');
616
-        // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
617
-        if (! defined('DOING_AUTOSAVE')) {
618
-            define('DOING_AUTOSAVE', true);
619
-        }
620
-        // if we made it here then the nonce checked out.  Let's run our methods and actions
621
-        $autosave = "_ee_autosave_{$this->_current_view}";
622
-        if (method_exists($this, $autosave)) {
623
-            $this->$autosave();
624
-        } else {
625
-            $this->_template_args['success'] = true;
626
-        }
627
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
628
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
629
-        // now let's return json
630
-        $this->_return_json();
631
-    }
632
-
633
-
634
-    /**
635
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
636
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
637
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
638
-     *
639
-     * @return void
640
-     * @throws EE_Error
641
-     * @throws ReflectionException
642
-     */
643
-    protected function _extend_page_config_for_cpt()
644
-    {
645
-        // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
646
-        if ($this->raw_req_page !== $this->page_slug) {
647
-            return;
648
-        }
649
-        // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
650
-        if (! empty($this->_cpt_object)) {
651
-            $this->_page_routes = array_merge(
652
-                [
653
-                    'create_new' => '_create_new_cpt_item',
654
-                    'edit'       => '_edit_cpt_item',
655
-                ],
656
-                $this->_page_routes
657
-            );
658
-            $this->_page_config = array_merge(
659
-                [
660
-                    'create_new' => [
661
-                        'nav'           => [
662
-                            'label' => $this->_cpt_object->labels->add_new_item,
663
-                            'order' => 5,
664
-                        ],
665
-                        'require_nonce' => false,
666
-                    ],
667
-                    'edit'       => [
668
-                        'nav'           => [
669
-                            'label'      => $this->_cpt_object->labels->edit_item,
670
-                            'order'      => 5,
671
-                            'persistent' => false,
672
-                            'url'        => '',
673
-                        ],
674
-                        'require_nonce' => false,
675
-                    ],
676
-                ],
677
-                $this->_page_config
678
-            );
679
-        }
680
-        // load the next section only if this is a matching cpt route as set in the cpt routes array.
681
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
682
-            return;
683
-        }
684
-        $this->_cpt_route = true;
685
-        // $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]);
686
-        // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
687
-        if (empty($this->_cpt_object)) {
688
-            $msg = sprintf(
689
-                esc_html__(
690
-                    'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).',
691
-                    'event_espresso'
692
-                ),
693
-                $this->page_slug,
694
-                $this->_req_action,
695
-                get_class($this)
696
-            );
697
-            throw new EE_Error($msg);
698
-        }
699
-        $this->_set_model_object($this->request->getRequestParam('post'));
700
-    }
701
-
702
-
703
-    /**
704
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
705
-     *
706
-     * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
707
-     * @param bool   $ignore_route_check
708
-     * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
709
-     * @throws EE_Error
710
-     * @throws InvalidArgumentException
711
-     * @throws InvalidDataTypeException
712
-     * @throws InvalidInterfaceException
713
-     * @throws ReflectionException
714
-     */
715
-    protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
716
-    {
717
-        $model = null;
718
-        if (
719
-            empty($this->_cpt_model_names)
720
-            || (
721
-                ! $ignore_route_check
722
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
723
-            )
724
-            || (
725
-                $this->_cpt_model_obj instanceof EE_CPT_Base
726
-                && $this->_cpt_model_obj->ID() === $id
727
-            )
728
-        ) {
729
-            // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
730
-            return;
731
-        }
732
-        // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
733
-        if ($ignore_route_check) {
734
-            $post_type = get_post_type($id);
735
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
736
-            $custom_post_types = $this->getLoader()->getShared(
737
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
738
-            );
739
-            $model_names       = $custom_post_types->getCustomPostTypeModelNames($post_type);
740
-            if (isset($model_names[ $post_type ])) {
741
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
742
-            }
743
-        } else {
744
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
745
-        }
746
-        if ($model instanceof EEM_Base) {
747
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
748
-        }
749
-        do_action(
750
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
751
-            $this->_cpt_model_obj,
752
-            $req_type
753
-        );
754
-    }
755
-
756
-
757
-    /**
758
-     * admin_init_global
759
-     * This runs all the code that we want executed within the WP admin_init hook.
760
-     * This method executes for ALL EE Admin pages.
761
-     *
762
-     * @return void
763
-     */
764
-    public function admin_init_global()
765
-    {
766
-        $post = $this->request->getRequestParam('post');
767
-        // its possible this is a new save so let's catch that instead
768
-        $post           = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
769
-        $post_type      = $post instanceof WP_Post ? $post->post_type : false;
770
-        $current_route  = isset($this->_req_data['current_route'])
771
-            ? $this->_req_data['current_route']
772
-            : 'shouldneverwork';
773
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
774
-            ? $this->_cpt_routes[ $current_route ]
775
-            : '';
776
-        add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 3);
777
-        add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 3);
778
-        if ($post_type === $route_to_check) {
779
-            add_filter('redirect_post_location', [$this, 'cpt_post_location_redirect'], 10, 2);
780
-        }
781
-        // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
782
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
783
-        if (! empty($revision)) {
784
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
785
-            // doing a restore?
786
-            if (! empty($action) && $action === 'restore') {
787
-                // get post for revision
788
-                $rev_post   = get_post($revision);
789
-                $rev_parent = get_post($rev_post->post_parent);
790
-                // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
791
-                if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
792
-                    add_filter('wp_redirect', [$this, 'revision_redirect'], 10, 2);
793
-                    // restores of revisions
794
-                    add_action('wp_restore_post_revision', [$this, 'restore_revision'], 10, 2);
795
-                }
796
-            }
797
-        }
798
-        // NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
799
-        if ($post_type && $post_type === $route_to_check) {
800
-            // $post_id, $post
801
-            add_action('save_post', [$this, 'insert_update'], 10, 3);
802
-            // $post_id
803
-            add_action('trashed_post', [$this, 'before_trash_cpt_item'], 10);
804
-            add_action('trashed_post', [$this, 'dont_permanently_delete_ee_cpts'], 10);
805
-            add_action('untrashed_post', [$this, 'before_restore_cpt_item'], 10);
806
-            add_action('after_delete_post', [$this, 'before_delete_cpt_item'], 10);
807
-        }
808
-    }
809
-
810
-
811
-    /**
812
-     * Callback for the WordPress trashed_post hook.
813
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
814
-     *
815
-     * @param int $post_id
816
-     * @throws \EE_Error
817
-     * @throws ReflectionException
818
-     */
819
-    public function before_trash_cpt_item($post_id)
820
-    {
821
-        $this->_set_model_object($post_id, true, 'trash');
822
-        // if our cpt object isn't existent then get out immediately.
823
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
824
-            return;
825
-        }
826
-        $this->trash_cpt_item($post_id);
827
-    }
828
-
829
-
830
-    /**
831
-     * Callback for the WordPress untrashed_post hook.
832
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
833
-     *
834
-     * @param $post_id
835
-     * @throws \EE_Error
836
-     * @throws ReflectionException
837
-     */
838
-    public function before_restore_cpt_item($post_id)
839
-    {
840
-        $this->_set_model_object($post_id, true, 'restore');
841
-        // if our cpt object isn't existent then get out immediately.
842
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
843
-            return;
844
-        }
845
-        $this->restore_cpt_item($post_id);
846
-    }
847
-
848
-
849
-    /**
850
-     * Callback for the WordPress after_delete_post hook.
851
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
852
-     *
853
-     * @param $post_id
854
-     * @throws \EE_Error
855
-     * @throws ReflectionException
856
-     */
857
-    public function before_delete_cpt_item($post_id)
858
-    {
859
-        $this->_set_model_object($post_id, true, 'delete');
860
-        // if our cpt object isn't existent then get out immediately.
861
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
862
-            return;
863
-        }
864
-        $this->delete_cpt_item($post_id);
865
-    }
866
-
867
-
868
-    /**
869
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
870
-     * accordingly.
871
-     *
872
-     * @return void
873
-     * @throws EE_Error
874
-     * @throws ReflectionException
875
-     */
876
-    public function verify_cpt_object()
877
-    {
878
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
879
-        // verify event object
880
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
881
-            throw new EE_Error(
882
-                sprintf(
883
-                    esc_html__(
884
-                        'Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
885
-                        'event_espresso'
886
-                    ),
887
-                    $label
888
-                )
889
-            );
890
-        }
891
-        // if auto-draft then throw an error
892
-        if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
893
-            EE_Error::overwrite_errors();
894
-            EE_Error::add_error(
895
-                sprintf(
896
-                    esc_html__(
897
-                        'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.',
898
-                        'event_espresso'
899
-                    ),
900
-                    $label
901
-                ),
902
-                __FILE__,
903
-                __FUNCTION__,
904
-                __LINE__
905
-            );
906
-        }
907
-    }
908
-
909
-
910
-    /**
911
-     * admin_footer_scripts_global
912
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
913
-     * will apply on ALL EE_Admin pages.
914
-     *
915
-     * @return void
916
-     */
917
-    public function admin_footer_scripts_global()
918
-    {
919
-        $this->_add_admin_page_ajax_loading_img();
920
-        $this->_add_admin_page_overlay();
921
-    }
922
-
923
-
924
-    /**
925
-     * add in any global scripts for cpt routes
926
-     *
927
-     * @return void
928
-     */
929
-    public function load_global_scripts_styles()
930
-    {
931
-        parent::load_global_scripts_styles();
932
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
933
-            // setup custom post status object for localize script but only if we've got a cpt object
934
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
935
-            if (! empty($statuses)) {
936
-                // get ALL statuses!
937
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
938
-                // setup object
939
-                $ee_cpt_statuses = [];
940
-                foreach ($statuses as $status => $label) {
941
-                    $ee_cpt_statuses[ $status ] = [
942
-                        'label'      => $label,
943
-                        'save_label' => sprintf(
944
-                            wp_strip_all_tags(__('Save as %s', 'event_espresso')),
945
-                            $label
946
-                        ),
947
-                    ];
948
-                }
949
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
950
-            }
951
-        }
952
-    }
953
-
954
-
955
-    /**
956
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
957
-     * insert/updates
958
-     *
959
-     * @param int     $post_id ID of post being updated
960
-     * @param WP_Post $post    Post object from WP
961
-     * @param bool    $update  Whether this is an update or a new save.
962
-     * @return void
963
-     * @throws \EE_Error
964
-     * @throws ReflectionException
965
-     */
966
-    public function insert_update($post_id, $post, $update)
967
-    {
968
-        // make sure that if this is a revision OR trash action that we don't do any updates!
969
-        if (
970
-            isset($this->_req_data['action'])
971
-            && (
972
-                $this->_req_data['action'] === 'restore'
973
-                || $this->_req_data['action'] === 'trash'
974
-            )
975
-        ) {
976
-            return;
977
-        }
978
-        $this->_set_model_object($post_id, true, 'insert_update');
979
-        // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
980
-        if (
981
-            $update
982
-            && (
983
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
984
-                || $this->_cpt_model_obj->ID() !== $post_id
985
-            )
986
-        ) {
987
-            return;
988
-        }
989
-        // check for autosave and update our req_data property accordingly.
990
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
524
+	}
525
+
526
+
527
+	/**
528
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
529
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
530
+	 *
531
+	 * @param string $return    the current html
532
+	 * @param int    $id        the post id for the page
533
+	 * @param string $new_title What the title is
534
+	 * @param string $new_slug  what the slug is
535
+	 * @return string            The new html string for the permalink area
536
+	 */
537
+	public function preview_button_html($return, $id, $new_title, $new_slug)
538
+	{
539
+		$post = get_post($id);
540
+		if ('publish' !== get_post_status($post)) {
541
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
542
+					   . get_preview_post_link($id)
543
+					   . '" class="button button-small">'
544
+					   . esc_html__('Preview', 'event_espresso')
545
+					   . '</a></span>'
546
+					   . "\n";
547
+		}
548
+		return $return;
549
+	}
550
+
551
+
552
+	/**
553
+	 * add our custom post stati dropdown on the wp post page for this cpt
554
+	 *
555
+	 * @return void
556
+	 */
557
+	public function custom_post_stati_dropdown()
558
+	{
559
+
560
+		$statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
561
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
562
+			? $statuses[ $this->_cpt_model_obj->status() ]
563
+			: '';
564
+		$template_args    = [
565
+			'cur_status'            => $this->_cpt_model_obj->status(),
566
+			'statuses'              => $statuses,
567
+			'cur_status_label'      => $cur_status_label,
568
+			'localized_status_save' => sprintf(esc_html__('Save %s', 'event_espresso'), $cur_status_label),
569
+		];
570
+		// we'll add a trash post status (WP doesn't add one for some reason)
571
+		if ($this->_cpt_model_obj->status() === 'trash') {
572
+			$template_args['cur_status_label'] = esc_html__('Trashed', 'event_espresso');
573
+			$statuses['trash']                 = esc_html__('Trashed', 'event_espresso');
574
+			$template_args['statuses']         = $statuses;
575
+		}
576
+
577
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
578
+		EEH_Template::display_template($template, $template_args);
579
+	}
580
+
581
+
582
+	public function setup_autosave_hooks()
583
+	{
584
+		$this->_set_autosave_containers();
585
+		$this->_load_autosave_scripts_styles();
586
+	}
587
+
588
+
589
+	/**
590
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a post object (available
591
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
592
+	 * for the nonce in here, but then this method looks for two things:
593
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
594
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
595
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
596
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
597
+	 * template args.
598
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
599
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
600
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
601
+	 *    $this->_template_args['data']['items'] = array(
602
+	 *        'event-datetime-ids' => '1,2,3';
603
+	 *    );
604
+	 *    Keep in mind the following things:
605
+	 *    - "where" index is for the input with the id as that string.
606
+	 *    - "what" index is what will be used for the value of that input.
607
+	 *
608
+	 * @return void
609
+	 * @throws EE_Error
610
+	 */
611
+	public function do_extra_autosave_stuff()
612
+	{
613
+		// next let's check for the autosave nonce (we'll use _verify_nonce )
614
+		$nonce = $this->request->getRequestParam('autosavenonce');
615
+		$this->_verify_nonce($nonce, 'autosave');
616
+		// make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
617
+		if (! defined('DOING_AUTOSAVE')) {
618
+			define('DOING_AUTOSAVE', true);
619
+		}
620
+		// if we made it here then the nonce checked out.  Let's run our methods and actions
621
+		$autosave = "_ee_autosave_{$this->_current_view}";
622
+		if (method_exists($this, $autosave)) {
623
+			$this->$autosave();
624
+		} else {
625
+			$this->_template_args['success'] = true;
626
+		}
627
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
628
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
629
+		// now let's return json
630
+		$this->_return_json();
631
+	}
632
+
633
+
634
+	/**
635
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
636
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
637
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
638
+	 *
639
+	 * @return void
640
+	 * @throws EE_Error
641
+	 * @throws ReflectionException
642
+	 */
643
+	protected function _extend_page_config_for_cpt()
644
+	{
645
+		// before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
646
+		if ($this->raw_req_page !== $this->page_slug) {
647
+			return;
648
+		}
649
+		// set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
650
+		if (! empty($this->_cpt_object)) {
651
+			$this->_page_routes = array_merge(
652
+				[
653
+					'create_new' => '_create_new_cpt_item',
654
+					'edit'       => '_edit_cpt_item',
655
+				],
656
+				$this->_page_routes
657
+			);
658
+			$this->_page_config = array_merge(
659
+				[
660
+					'create_new' => [
661
+						'nav'           => [
662
+							'label' => $this->_cpt_object->labels->add_new_item,
663
+							'order' => 5,
664
+						],
665
+						'require_nonce' => false,
666
+					],
667
+					'edit'       => [
668
+						'nav'           => [
669
+							'label'      => $this->_cpt_object->labels->edit_item,
670
+							'order'      => 5,
671
+							'persistent' => false,
672
+							'url'        => '',
673
+						],
674
+						'require_nonce' => false,
675
+					],
676
+				],
677
+				$this->_page_config
678
+			);
679
+		}
680
+		// load the next section only if this is a matching cpt route as set in the cpt routes array.
681
+		if (! isset($this->_cpt_routes[ $this->_req_action ])) {
682
+			return;
683
+		}
684
+		$this->_cpt_route = true;
685
+		// $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]);
686
+		// add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
687
+		if (empty($this->_cpt_object)) {
688
+			$msg = sprintf(
689
+				esc_html__(
690
+					'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).',
691
+					'event_espresso'
692
+				),
693
+				$this->page_slug,
694
+				$this->_req_action,
695
+				get_class($this)
696
+			);
697
+			throw new EE_Error($msg);
698
+		}
699
+		$this->_set_model_object($this->request->getRequestParam('post'));
700
+	}
701
+
702
+
703
+	/**
704
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
705
+	 *
706
+	 * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
707
+	 * @param bool   $ignore_route_check
708
+	 * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
709
+	 * @throws EE_Error
710
+	 * @throws InvalidArgumentException
711
+	 * @throws InvalidDataTypeException
712
+	 * @throws InvalidInterfaceException
713
+	 * @throws ReflectionException
714
+	 */
715
+	protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
716
+	{
717
+		$model = null;
718
+		if (
719
+			empty($this->_cpt_model_names)
720
+			|| (
721
+				! $ignore_route_check
722
+				&& ! isset($this->_cpt_routes[ $this->_req_action ])
723
+			)
724
+			|| (
725
+				$this->_cpt_model_obj instanceof EE_CPT_Base
726
+				&& $this->_cpt_model_obj->ID() === $id
727
+			)
728
+		) {
729
+			// get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
730
+			return;
731
+		}
732
+		// if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
733
+		if ($ignore_route_check) {
734
+			$post_type = get_post_type($id);
735
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
736
+			$custom_post_types = $this->getLoader()->getShared(
737
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
738
+			);
739
+			$model_names       = $custom_post_types->getCustomPostTypeModelNames($post_type);
740
+			if (isset($model_names[ $post_type ])) {
741
+				$model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
742
+			}
743
+		} else {
744
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
745
+		}
746
+		if ($model instanceof EEM_Base) {
747
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
748
+		}
749
+		do_action(
750
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
751
+			$this->_cpt_model_obj,
752
+			$req_type
753
+		);
754
+	}
755
+
756
+
757
+	/**
758
+	 * admin_init_global
759
+	 * This runs all the code that we want executed within the WP admin_init hook.
760
+	 * This method executes for ALL EE Admin pages.
761
+	 *
762
+	 * @return void
763
+	 */
764
+	public function admin_init_global()
765
+	{
766
+		$post = $this->request->getRequestParam('post');
767
+		// its possible this is a new save so let's catch that instead
768
+		$post           = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
769
+		$post_type      = $post instanceof WP_Post ? $post->post_type : false;
770
+		$current_route  = isset($this->_req_data['current_route'])
771
+			? $this->_req_data['current_route']
772
+			: 'shouldneverwork';
773
+		$route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
774
+			? $this->_cpt_routes[ $current_route ]
775
+			: '';
776
+		add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 3);
777
+		add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 3);
778
+		if ($post_type === $route_to_check) {
779
+			add_filter('redirect_post_location', [$this, 'cpt_post_location_redirect'], 10, 2);
780
+		}
781
+		// now let's filter redirect if we're on a revision page and the revision is for an event CPT.
782
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
783
+		if (! empty($revision)) {
784
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
785
+			// doing a restore?
786
+			if (! empty($action) && $action === 'restore') {
787
+				// get post for revision
788
+				$rev_post   = get_post($revision);
789
+				$rev_parent = get_post($rev_post->post_parent);
790
+				// only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
791
+				if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
792
+					add_filter('wp_redirect', [$this, 'revision_redirect'], 10, 2);
793
+					// restores of revisions
794
+					add_action('wp_restore_post_revision', [$this, 'restore_revision'], 10, 2);
795
+				}
796
+			}
797
+		}
798
+		// NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
799
+		if ($post_type && $post_type === $route_to_check) {
800
+			// $post_id, $post
801
+			add_action('save_post', [$this, 'insert_update'], 10, 3);
802
+			// $post_id
803
+			add_action('trashed_post', [$this, 'before_trash_cpt_item'], 10);
804
+			add_action('trashed_post', [$this, 'dont_permanently_delete_ee_cpts'], 10);
805
+			add_action('untrashed_post', [$this, 'before_restore_cpt_item'], 10);
806
+			add_action('after_delete_post', [$this, 'before_delete_cpt_item'], 10);
807
+		}
808
+	}
809
+
810
+
811
+	/**
812
+	 * Callback for the WordPress trashed_post hook.
813
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
814
+	 *
815
+	 * @param int $post_id
816
+	 * @throws \EE_Error
817
+	 * @throws ReflectionException
818
+	 */
819
+	public function before_trash_cpt_item($post_id)
820
+	{
821
+		$this->_set_model_object($post_id, true, 'trash');
822
+		// if our cpt object isn't existent then get out immediately.
823
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
824
+			return;
825
+		}
826
+		$this->trash_cpt_item($post_id);
827
+	}
828
+
829
+
830
+	/**
831
+	 * Callback for the WordPress untrashed_post hook.
832
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
833
+	 *
834
+	 * @param $post_id
835
+	 * @throws \EE_Error
836
+	 * @throws ReflectionException
837
+	 */
838
+	public function before_restore_cpt_item($post_id)
839
+	{
840
+		$this->_set_model_object($post_id, true, 'restore');
841
+		// if our cpt object isn't existent then get out immediately.
842
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
843
+			return;
844
+		}
845
+		$this->restore_cpt_item($post_id);
846
+	}
847
+
848
+
849
+	/**
850
+	 * Callback for the WordPress after_delete_post hook.
851
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
852
+	 *
853
+	 * @param $post_id
854
+	 * @throws \EE_Error
855
+	 * @throws ReflectionException
856
+	 */
857
+	public function before_delete_cpt_item($post_id)
858
+	{
859
+		$this->_set_model_object($post_id, true, 'delete');
860
+		// if our cpt object isn't existent then get out immediately.
861
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
862
+			return;
863
+		}
864
+		$this->delete_cpt_item($post_id);
865
+	}
866
+
867
+
868
+	/**
869
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
870
+	 * accordingly.
871
+	 *
872
+	 * @return void
873
+	 * @throws EE_Error
874
+	 * @throws ReflectionException
875
+	 */
876
+	public function verify_cpt_object()
877
+	{
878
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
879
+		// verify event object
880
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
881
+			throw new EE_Error(
882
+				sprintf(
883
+					esc_html__(
884
+						'Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
885
+						'event_espresso'
886
+					),
887
+					$label
888
+				)
889
+			);
890
+		}
891
+		// if auto-draft then throw an error
892
+		if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
893
+			EE_Error::overwrite_errors();
894
+			EE_Error::add_error(
895
+				sprintf(
896
+					esc_html__(
897
+						'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.',
898
+						'event_espresso'
899
+					),
900
+					$label
901
+				),
902
+				__FILE__,
903
+				__FUNCTION__,
904
+				__LINE__
905
+			);
906
+		}
907
+	}
908
+
909
+
910
+	/**
911
+	 * admin_footer_scripts_global
912
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
913
+	 * will apply on ALL EE_Admin pages.
914
+	 *
915
+	 * @return void
916
+	 */
917
+	public function admin_footer_scripts_global()
918
+	{
919
+		$this->_add_admin_page_ajax_loading_img();
920
+		$this->_add_admin_page_overlay();
921
+	}
922
+
923
+
924
+	/**
925
+	 * add in any global scripts for cpt routes
926
+	 *
927
+	 * @return void
928
+	 */
929
+	public function load_global_scripts_styles()
930
+	{
931
+		parent::load_global_scripts_styles();
932
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
933
+			// setup custom post status object for localize script but only if we've got a cpt object
934
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
935
+			if (! empty($statuses)) {
936
+				// get ALL statuses!
937
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
938
+				// setup object
939
+				$ee_cpt_statuses = [];
940
+				foreach ($statuses as $status => $label) {
941
+					$ee_cpt_statuses[ $status ] = [
942
+						'label'      => $label,
943
+						'save_label' => sprintf(
944
+							wp_strip_all_tags(__('Save as %s', 'event_espresso')),
945
+							$label
946
+						),
947
+					];
948
+				}
949
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
950
+			}
951
+		}
952
+	}
953
+
954
+
955
+	/**
956
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
957
+	 * insert/updates
958
+	 *
959
+	 * @param int     $post_id ID of post being updated
960
+	 * @param WP_Post $post    Post object from WP
961
+	 * @param bool    $update  Whether this is an update or a new save.
962
+	 * @return void
963
+	 * @throws \EE_Error
964
+	 * @throws ReflectionException
965
+	 */
966
+	public function insert_update($post_id, $post, $update)
967
+	{
968
+		// make sure that if this is a revision OR trash action that we don't do any updates!
969
+		if (
970
+			isset($this->_req_data['action'])
971
+			&& (
972
+				$this->_req_data['action'] === 'restore'
973
+				|| $this->_req_data['action'] === 'trash'
974
+			)
975
+		) {
976
+			return;
977
+		}
978
+		$this->_set_model_object($post_id, true, 'insert_update');
979
+		// if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
980
+		if (
981
+			$update
982
+			&& (
983
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
984
+				|| $this->_cpt_model_obj->ID() !== $post_id
985
+			)
986
+		) {
987
+			return;
988
+		}
989
+		// check for autosave and update our req_data property accordingly.
990
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
991 991
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
992 992
 
993 993
                 foreach ( (array) $values as $key => $value ) {
@@ -997,554 +997,554 @@  discard block
 block discarded – undo
997 997
 
998 998
         }/**/ // TODO reactivate after autosave is implemented in 4.2
999 999
 
1000
-        // take care of updating any selected page_template IF this cpt supports it.
1001
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
1002
-            // wp version aware.
1003
-            if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
1004
-                $page_templates = wp_get_theme()->get_page_templates();
1005
-            } else {
1006
-                $post->page_template = $this->_req_data['page_template'];
1007
-                $page_templates      = wp_get_theme()->get_page_templates($post);
1008
-            }
1009
-            if (
1010
-                'default' != $this->_req_data['page_template']
1011
-                && ! isset($page_templates[ $this->_req_data['page_template'] ])
1012
-            ) {
1013
-                EE_Error::add_error(
1014
-                    esc_html__('Invalid Page Template.', 'event_espresso'),
1015
-                    __FILE__,
1016
-                    __FUNCTION__,
1017
-                    __LINE__
1018
-                );
1019
-            } else {
1020
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
1021
-            }
1022
-        }
1023
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
1024
-            return;
1025
-        } //TODO we'll remove this after reimplementing autosave in 4.2
1026
-        $this->_insert_update_cpt_item($post_id, $post);
1027
-    }
1028
-
1029
-
1030
-    /**
1031
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1032
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1033
-     * so we don't have to check for our CPT.
1034
-     *
1035
-     * @param int $post_id ID of the post
1036
-     * @return void
1037
-     */
1038
-    public function dont_permanently_delete_ee_cpts($post_id)
1039
-    {
1040
-        // only do this if we're actually processing one of our CPTs
1041
-        // if our cpt object isn't existent then get out immediately.
1042
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1043
-            return;
1044
-        }
1045
-        delete_post_meta($post_id, '_wp_trash_meta_status');
1046
-        delete_post_meta($post_id, '_wp_trash_meta_time');
1047
-        // our cpts may have comments so let's take care of that too
1048
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1049
-    }
1050
-
1051
-
1052
-    /**
1053
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1054
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1055
-     * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1056
-     *
1057
-     * @param int $post_id     ID of cpt item
1058
-     * @param int $revision_id ID of revision being restored
1059
-     * @return void
1060
-     */
1061
-    public function restore_revision($post_id, $revision_id)
1062
-    {
1063
-        $this->_restore_cpt_item($post_id, $revision_id);
1064
-        // global action
1065
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1066
-        // class specific action so you can limit hooking into a specific page.
1067
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1068
-    }
1069
-
1070
-
1071
-    /**
1072
-     * @param int $post_id     ID of cpt item
1073
-     * @param int $revision_id ID of revision for item
1074
-     * @return void
1075
-     * @see restore_revision() for details
1076
-     */
1077
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
1078
-
1079
-
1080
-    /**
1081
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
1082
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1083
-     * To fix we have to reset the current_screen using the page_slug
1084
-     * (which is identical - or should be - to our registered_post_type id.)
1085
-     * Also, since the core WP file loads the admin_header.php for WP
1086
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1087
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1088
-     *
1089
-     * @return void
1090
-     * @throws EE_Error
1091
-     * @throws EE_Error
1092
-     */
1093
-    public function modify_current_screen()
1094
-    {
1095
-        // ONLY do this if the current page_route IS a cpt route
1096
-        if (! $this->_cpt_route) {
1097
-            return;
1098
-        }
1099
-        // routing things REALLY early b/c this is a cpt admin page
1100
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1101
-        $this->_current_screen       = get_current_screen();
1102
-        $this->_current_screen->base = 'event-espresso';
1103
-        $this->_add_help_tabs(); // we make sure we add any help tabs back in!
1104
-        /*try {
1000
+		// take care of updating any selected page_template IF this cpt supports it.
1001
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
1002
+			// wp version aware.
1003
+			if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
1004
+				$page_templates = wp_get_theme()->get_page_templates();
1005
+			} else {
1006
+				$post->page_template = $this->_req_data['page_template'];
1007
+				$page_templates      = wp_get_theme()->get_page_templates($post);
1008
+			}
1009
+			if (
1010
+				'default' != $this->_req_data['page_template']
1011
+				&& ! isset($page_templates[ $this->_req_data['page_template'] ])
1012
+			) {
1013
+				EE_Error::add_error(
1014
+					esc_html__('Invalid Page Template.', 'event_espresso'),
1015
+					__FILE__,
1016
+					__FUNCTION__,
1017
+					__LINE__
1018
+				);
1019
+			} else {
1020
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
1021
+			}
1022
+		}
1023
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
1024
+			return;
1025
+		} //TODO we'll remove this after reimplementing autosave in 4.2
1026
+		$this->_insert_update_cpt_item($post_id, $post);
1027
+	}
1028
+
1029
+
1030
+	/**
1031
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1032
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1033
+	 * so we don't have to check for our CPT.
1034
+	 *
1035
+	 * @param int $post_id ID of the post
1036
+	 * @return void
1037
+	 */
1038
+	public function dont_permanently_delete_ee_cpts($post_id)
1039
+	{
1040
+		// only do this if we're actually processing one of our CPTs
1041
+		// if our cpt object isn't existent then get out immediately.
1042
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1043
+			return;
1044
+		}
1045
+		delete_post_meta($post_id, '_wp_trash_meta_status');
1046
+		delete_post_meta($post_id, '_wp_trash_meta_time');
1047
+		// our cpts may have comments so let's take care of that too
1048
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1049
+	}
1050
+
1051
+
1052
+	/**
1053
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1054
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1055
+	 * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1056
+	 *
1057
+	 * @param int $post_id     ID of cpt item
1058
+	 * @param int $revision_id ID of revision being restored
1059
+	 * @return void
1060
+	 */
1061
+	public function restore_revision($post_id, $revision_id)
1062
+	{
1063
+		$this->_restore_cpt_item($post_id, $revision_id);
1064
+		// global action
1065
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1066
+		// class specific action so you can limit hooking into a specific page.
1067
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1068
+	}
1069
+
1070
+
1071
+	/**
1072
+	 * @param int $post_id     ID of cpt item
1073
+	 * @param int $revision_id ID of revision for item
1074
+	 * @return void
1075
+	 * @see restore_revision() for details
1076
+	 */
1077
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
1078
+
1079
+
1080
+	/**
1081
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
1082
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1083
+	 * To fix we have to reset the current_screen using the page_slug
1084
+	 * (which is identical - or should be - to our registered_post_type id.)
1085
+	 * Also, since the core WP file loads the admin_header.php for WP
1086
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1087
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1088
+	 *
1089
+	 * @return void
1090
+	 * @throws EE_Error
1091
+	 * @throws EE_Error
1092
+	 */
1093
+	public function modify_current_screen()
1094
+	{
1095
+		// ONLY do this if the current page_route IS a cpt route
1096
+		if (! $this->_cpt_route) {
1097
+			return;
1098
+		}
1099
+		// routing things REALLY early b/c this is a cpt admin page
1100
+		set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1101
+		$this->_current_screen       = get_current_screen();
1102
+		$this->_current_screen->base = 'event-espresso';
1103
+		$this->_add_help_tabs(); // we make sure we add any help tabs back in!
1104
+		/*try {
1105 1105
             $this->_route_admin_request();
1106 1106
         } catch ( EE_Error $e ) {
1107 1107
             $e->get_error();
1108 1108
         }/**/
1109
-    }
1110
-
1111
-
1112
-    /**
1113
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1114
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1115
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1116
-     * default to be.
1117
-     *
1118
-     * @param string $title The new title (or existing if there is no editor_title defined)
1119
-     * @return string
1120
-     */
1121
-    public function add_custom_editor_default_title($title)
1122
-    {
1123
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1124
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1125
-            : $title;
1126
-    }
1127
-
1128
-
1129
-    /**
1130
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1131
-     *
1132
-     * @param string $shortlink   The already generated shortlink
1133
-     * @param int    $id          Post ID for this item
1134
-     * @param string $context     The context for the link
1135
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1136
-     * @return string
1137
-     */
1138
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1139
-    {
1140
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1141
-            $post = get_post($id);
1142
-            if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1143
-                $shortlink = home_url('?p=' . $post->ID);
1144
-            }
1145
-        }
1146
-        return $shortlink;
1147
-    }
1148
-
1149
-
1150
-    /**
1151
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1152
-     * already run in modify_current_screen())
1153
-     *
1154
-     * @return void
1155
-     */
1156
-    public function route_admin_request()
1157
-    {
1158
-        if ($this->_cpt_route) {
1159
-            return;
1160
-        }
1161
-        try {
1162
-            $this->_route_admin_request();
1163
-        } catch (EE_Error $e) {
1164
-            $e->get_error();
1165
-        }
1166
-    }
1167
-
1168
-
1169
-    /**
1170
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1171
-     *
1172
-     * @return void
1173
-     */
1174
-    public function cpt_post_form_hidden_input()
1175
-    {
1176
-        // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1177
-        echo '
1109
+	}
1110
+
1111
+
1112
+	/**
1113
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1114
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1115
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1116
+	 * default to be.
1117
+	 *
1118
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1119
+	 * @return string
1120
+	 */
1121
+	public function add_custom_editor_default_title($title)
1122
+	{
1123
+		return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1124
+			? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1125
+			: $title;
1126
+	}
1127
+
1128
+
1129
+	/**
1130
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1131
+	 *
1132
+	 * @param string $shortlink   The already generated shortlink
1133
+	 * @param int    $id          Post ID for this item
1134
+	 * @param string $context     The context for the link
1135
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1136
+	 * @return string
1137
+	 */
1138
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1139
+	{
1140
+		if (! empty($id) && get_option('permalink_structure') !== '') {
1141
+			$post = get_post($id);
1142
+			if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1143
+				$shortlink = home_url('?p=' . $post->ID);
1144
+			}
1145
+		}
1146
+		return $shortlink;
1147
+	}
1148
+
1149
+
1150
+	/**
1151
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1152
+	 * already run in modify_current_screen())
1153
+	 *
1154
+	 * @return void
1155
+	 */
1156
+	public function route_admin_request()
1157
+	{
1158
+		if ($this->_cpt_route) {
1159
+			return;
1160
+		}
1161
+		try {
1162
+			$this->_route_admin_request();
1163
+		} catch (EE_Error $e) {
1164
+			$e->get_error();
1165
+		}
1166
+	}
1167
+
1168
+
1169
+	/**
1170
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1171
+	 *
1172
+	 * @return void
1173
+	 */
1174
+	public function cpt_post_form_hidden_input()
1175
+	{
1176
+		// we're also going to add the route value and the current page so we can direct autosave parsing correctly
1177
+		echo '
1178 1178
         <input type="hidden" name="ee_cpt_item_redirect_url" value="' . esc_url_raw($this->_admin_base_url) . '"/>
1179 1179
         <div id="ee-cpt-hidden-inputs">
1180 1180
             <input type="hidden" id="current_route" name="current_route" value="' . esc_attr($this->_current_view) . '"/>
1181 1181
             <input type="hidden" id="current_page" name="current_page" value="' . esc_attr($this->page_slug) . '"/>
1182 1182
         </div>';
1183
-    }
1184
-
1185
-
1186
-    /**
1187
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1188
-     *
1189
-     * @param string $location Original location url
1190
-     * @param int    $status   Status for http header
1191
-     * @return string           new (or original) url to redirect to.
1192
-     * @throws EE_Error
1193
-     * @throws EE_Error
1194
-     */
1195
-    public function revision_redirect($location, $status)
1196
-    {
1197
-        // get revision
1198
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1199
-        // can't do anything without revision so let's get out if not present
1200
-        if (empty($rev_id)) {
1201
-            return $location;
1202
-        }
1203
-        // get rev_post_data
1204
-        $rev        = get_post($rev_id);
1205
-        $admin_url  = $this->_admin_base_url;
1206
-        $query_args = [
1207
-            'action'   => 'edit',
1208
-            'post'     => $rev->post_parent,
1209
-            'revision' => $rev_id,
1210
-            'message'  => 5,
1211
-        ];
1212
-        $this->_process_notices($query_args, true);
1213
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1219
-     *
1220
-     * @param string $link    the original generated link
1221
-     * @param int    $id      post id
1222
-     * @param string $context optional, defaults to display.  How to write the '&'
1223
-     * @return string          the link
1224
-     */
1225
-    public function modify_edit_post_link($link, $id, $context)
1226
-    {
1227
-        $post = get_post($id);
1228
-        if (
1229
-            ! isset($this->_req_data['action'])
1230
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1231
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1232
-        ) {
1233
-            return $link;
1234
-        }
1235
-        $query_args = [
1236
-            'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1237
-                ? $this->_cpt_edit_routes[ $post->post_type ]
1238
-                : 'edit',
1239
-            'post'   => $id,
1240
-        ];
1241
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1242
-    }
1243
-
1244
-
1245
-    /**
1246
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1247
-     * our routes.
1248
-     *
1249
-     * @param string $delete_link  original delete link
1250
-     * @param int    $post_id      id of cpt object
1251
-     * @param bool   $force_delete whether this is forcing a hard delete instead of trash
1252
-     * @return string new delete link
1253
-     * @throws EE_Error
1254
-     * @throws ReflectionException
1255
-     */
1256
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1257
-    {
1258
-        $post = get_post($post_id);
1259
-
1260
-        if (
1261
-            empty($this->_req_data['action'])
1262
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1263
-            || ! $post instanceof WP_Post
1264
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1265
-        ) {
1266
-            return $delete_link;
1267
-        }
1268
-        $this->_set_model_object($post->ID, true);
1269
-
1270
-        // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1271
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1272
-
1273
-        return EE_Admin_Page::add_query_args_and_nonce(
1274
-            [
1275
-                'page'   => $this->_req_data['page'],
1276
-                'action' => $action,
1277
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1278
-                         => $post->ID,
1279
-            ],
1280
-            admin_url()
1281
-        );
1282
-    }
1283
-
1284
-
1285
-    /**
1286
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1287
-     * so that we can hijack the default redirect locations for wp custom post types
1288
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1289
-     *
1290
-     * @param string $location This is the incoming currently set redirect location
1291
-     * @param string $post_id  This is the 'ID' value of the wp_posts table
1292
-     * @return string           the new location to redirect to
1293
-     * @throws EE_Error
1294
-     * @throws EE_Error
1295
-     */
1296
-    public function cpt_post_location_redirect($location, $post_id)
1297
-    {
1298
-        // we DO have a match so let's setup the url
1299
-        // we have to get the post to determine our route
1300
-        $post       = get_post($post_id);
1301
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1302
-        // shared query_args
1303
-        $query_args = ['action' => $edit_route, 'post' => $post_id];
1304
-        $admin_url  = $this->_admin_base_url;
1305
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1306
-            $status = get_post_status($post_id);
1307
-            if (isset($this->_req_data['publish'])) {
1308
-                switch ($status) {
1309
-                    case 'pending':
1310
-                        $message = 8;
1311
-                        break;
1312
-                    case 'future':
1313
-                        $message = 9;
1314
-                        break;
1315
-                    default:
1316
-                        $message = 6;
1317
-                }
1318
-            } else {
1319
-                $message = 'draft' === $status ? 10 : 1;
1320
-            }
1321
-        } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1322
-            $message = 2;
1323
-        } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1324
-            $message = 3;
1325
-        } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1326
-            $message = 7;
1327
-        } else {
1328
-            $message = 4;
1329
-        }
1330
-        // change the message if the post type is not viewable on the frontend
1331
-        $this->_cpt_object = get_post_type_object($post->post_type);
1332
-        $message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1333
-        $query_args        = array_merge(['message' => $message], $query_args);
1334
-        $this->_process_notices($query_args, true);
1335
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1336
-    }
1337
-
1338
-
1339
-    /**
1340
-     * This method is called to inject nav tabs on core WP cpt pages
1341
-     *
1342
-     * @return void
1343
-     * @throws EE_Error
1344
-     * @throws EE_Error
1345
-     */
1346
-    public function inject_nav_tabs()
1347
-    {
1348
-        // can we hijack and insert the nav_tabs?
1349
-        $nav_tabs = $this->_get_main_nav_tabs();
1350
-        // first close off existing form tag
1351
-        $html = '>';
1352
-        $html .= $nav_tabs;
1353
-        // now let's handle the remaining tag ( missing ">" is CORRECT )
1354
-        $html .= '<span></span';
1355
-        echo $html;  // already escaped
1356
-    }
1357
-
1358
-
1359
-    /**
1360
-     * This just sets up the post update messages when an update form is loaded
1361
-     *
1362
-     * @param array $messages the original messages array
1363
-     * @return array           the new messages array
1364
-     */
1365
-    public function post_update_messages($messages)
1366
-    {
1367
-        global $post;
1368
-        $id       = $this->request->getRequestParam('post');
1369
-        $id       = empty($id) && is_object($post) ? $post->ID : null;
1370
-        $revision = $this->request->getRequestParam('revision', 0, 'int');
1371
-
1372
-        $messages[ $post->post_type ] = [
1373
-            0  => '', // Unused. Messages start at index 1.
1374
-            1  => sprintf(
1375
-                esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1376
-                $this->_cpt_object->labels->singular_name,
1377
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1378
-                '</a>'
1379
-            ),
1380
-            2  => esc_html__('Custom field updated', 'event_espresso'),
1381
-            3  => esc_html__('Custom field deleted.', 'event_espresso'),
1382
-            4  => sprintf(esc_html__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1383
-            5  => $revision
1384
-                ? sprintf(
1385
-                    esc_html__('%s restored to revision from %s', 'event_espresso'),
1386
-                    $this->_cpt_object->labels->singular_name,
1387
-                    wp_post_revision_title($revision, false)
1388
-                )
1389
-                : false,
1390
-            6  => sprintf(
1391
-                esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1392
-                $this->_cpt_object->labels->singular_name,
1393
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1394
-                '</a>'
1395
-            ),
1396
-            7  => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1397
-            8  => sprintf(
1398
-                esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1399
-                $this->_cpt_object->labels->singular_name,
1400
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1401
-                '</a>'
1402
-            ),
1403
-            9  => sprintf(
1404
-                esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1405
-                $this->_cpt_object->labels->singular_name,
1406
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1407
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1408
-                '</a>'
1409
-            ),
1410
-            10 => sprintf(
1411
-                esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1412
-                $this->_cpt_object->labels->singular_name,
1413
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1414
-                '</a>'
1415
-            ),
1416
-        ];
1417
-        return $messages;
1418
-    }
1419
-
1420
-
1421
-    /**
1422
-     * default method for the 'create_new' route for cpt admin pages.
1423
-     * For reference what to include in here, see wp-admin/post-new.php
1424
-     *
1425
-     * @return void
1426
-     */
1427
-    protected function _create_new_cpt_item()
1428
-    {
1429
-        // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1430
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1431
-        $post_type        = $this->_cpt_routes[ $this->_req_action ];
1432
-        $post_type_object = $this->_cpt_object;
1433
-        $title            = $post_type_object->labels->add_new_item;
1434
-        $post             = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1435
-        add_action('admin_print_styles', [$this, 'add_new_admin_page_global']);
1436
-        // modify the default editor title field with default title.
1437
-        add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10);
1438
-        $this->loadEditorTemplate(true);
1439
-    }
1440
-
1441
-
1442
-    /**
1443
-     * Enqueues auto-save and loads the editor template
1444
-     *
1445
-     * @param bool $creating
1446
-     */
1447
-    private function loadEditorTemplate($creating = true)
1448
-    {
1449
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1450
-        // these vars are used by the template
1451
-        $editing = true;
1452
-        $post_ID = $post->ID;
1453
-        if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1454
-            // only enqueue autosave when creating event (necessary to get permalink/url generated)
1455
-            // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1456
-            if ($creating) {
1457
-                wp_enqueue_script('autosave');
1458
-            } else {
1459
-                if (
1460
-                    isset($this->_cpt_routes[ $this->_req_data['action'] ])
1461
-                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1462
-                ) {
1463
-                    $create_new_action = apply_filters(
1464
-                        'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1465
-                        'create_new',
1466
-                        $this
1467
-                    );
1468
-                    $post_new_file     = EE_Admin_Page::add_query_args_and_nonce(
1469
-                        [
1470
-                            'action' => $create_new_action,
1471
-                            'page'   => $this->page_slug,
1472
-                        ],
1473
-                        'admin.php'
1474
-                    );
1475
-                }
1476
-            }
1477
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1478
-        }
1479
-    }
1480
-
1481
-
1482
-    public function add_new_admin_page_global()
1483
-    {
1484
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1485
-        ?>
1183
+	}
1184
+
1185
+
1186
+	/**
1187
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1188
+	 *
1189
+	 * @param string $location Original location url
1190
+	 * @param int    $status   Status for http header
1191
+	 * @return string           new (or original) url to redirect to.
1192
+	 * @throws EE_Error
1193
+	 * @throws EE_Error
1194
+	 */
1195
+	public function revision_redirect($location, $status)
1196
+	{
1197
+		// get revision
1198
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1199
+		// can't do anything without revision so let's get out if not present
1200
+		if (empty($rev_id)) {
1201
+			return $location;
1202
+		}
1203
+		// get rev_post_data
1204
+		$rev        = get_post($rev_id);
1205
+		$admin_url  = $this->_admin_base_url;
1206
+		$query_args = [
1207
+			'action'   => 'edit',
1208
+			'post'     => $rev->post_parent,
1209
+			'revision' => $rev_id,
1210
+			'message'  => 5,
1211
+		];
1212
+		$this->_process_notices($query_args, true);
1213
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1219
+	 *
1220
+	 * @param string $link    the original generated link
1221
+	 * @param int    $id      post id
1222
+	 * @param string $context optional, defaults to display.  How to write the '&'
1223
+	 * @return string          the link
1224
+	 */
1225
+	public function modify_edit_post_link($link, $id, $context)
1226
+	{
1227
+		$post = get_post($id);
1228
+		if (
1229
+			! isset($this->_req_data['action'])
1230
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1231
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1232
+		) {
1233
+			return $link;
1234
+		}
1235
+		$query_args = [
1236
+			'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1237
+				? $this->_cpt_edit_routes[ $post->post_type ]
1238
+				: 'edit',
1239
+			'post'   => $id,
1240
+		];
1241
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1242
+	}
1243
+
1244
+
1245
+	/**
1246
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1247
+	 * our routes.
1248
+	 *
1249
+	 * @param string $delete_link  original delete link
1250
+	 * @param int    $post_id      id of cpt object
1251
+	 * @param bool   $force_delete whether this is forcing a hard delete instead of trash
1252
+	 * @return string new delete link
1253
+	 * @throws EE_Error
1254
+	 * @throws ReflectionException
1255
+	 */
1256
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1257
+	{
1258
+		$post = get_post($post_id);
1259
+
1260
+		if (
1261
+			empty($this->_req_data['action'])
1262
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1263
+			|| ! $post instanceof WP_Post
1264
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1265
+		) {
1266
+			return $delete_link;
1267
+		}
1268
+		$this->_set_model_object($post->ID, true);
1269
+
1270
+		// returns something like `trash_event` or `trash_attendee` or `trash_venue`
1271
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1272
+
1273
+		return EE_Admin_Page::add_query_args_and_nonce(
1274
+			[
1275
+				'page'   => $this->_req_data['page'],
1276
+				'action' => $action,
1277
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1278
+						 => $post->ID,
1279
+			],
1280
+			admin_url()
1281
+		);
1282
+	}
1283
+
1284
+
1285
+	/**
1286
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1287
+	 * so that we can hijack the default redirect locations for wp custom post types
1288
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1289
+	 *
1290
+	 * @param string $location This is the incoming currently set redirect location
1291
+	 * @param string $post_id  This is the 'ID' value of the wp_posts table
1292
+	 * @return string           the new location to redirect to
1293
+	 * @throws EE_Error
1294
+	 * @throws EE_Error
1295
+	 */
1296
+	public function cpt_post_location_redirect($location, $post_id)
1297
+	{
1298
+		// we DO have a match so let's setup the url
1299
+		// we have to get the post to determine our route
1300
+		$post       = get_post($post_id);
1301
+		$edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1302
+		// shared query_args
1303
+		$query_args = ['action' => $edit_route, 'post' => $post_id];
1304
+		$admin_url  = $this->_admin_base_url;
1305
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1306
+			$status = get_post_status($post_id);
1307
+			if (isset($this->_req_data['publish'])) {
1308
+				switch ($status) {
1309
+					case 'pending':
1310
+						$message = 8;
1311
+						break;
1312
+					case 'future':
1313
+						$message = 9;
1314
+						break;
1315
+					default:
1316
+						$message = 6;
1317
+				}
1318
+			} else {
1319
+				$message = 'draft' === $status ? 10 : 1;
1320
+			}
1321
+		} elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1322
+			$message = 2;
1323
+		} elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1324
+			$message = 3;
1325
+		} elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1326
+			$message = 7;
1327
+		} else {
1328
+			$message = 4;
1329
+		}
1330
+		// change the message if the post type is not viewable on the frontend
1331
+		$this->_cpt_object = get_post_type_object($post->post_type);
1332
+		$message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1333
+		$query_args        = array_merge(['message' => $message], $query_args);
1334
+		$this->_process_notices($query_args, true);
1335
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1336
+	}
1337
+
1338
+
1339
+	/**
1340
+	 * This method is called to inject nav tabs on core WP cpt pages
1341
+	 *
1342
+	 * @return void
1343
+	 * @throws EE_Error
1344
+	 * @throws EE_Error
1345
+	 */
1346
+	public function inject_nav_tabs()
1347
+	{
1348
+		// can we hijack and insert the nav_tabs?
1349
+		$nav_tabs = $this->_get_main_nav_tabs();
1350
+		// first close off existing form tag
1351
+		$html = '>';
1352
+		$html .= $nav_tabs;
1353
+		// now let's handle the remaining tag ( missing ">" is CORRECT )
1354
+		$html .= '<span></span';
1355
+		echo $html;  // already escaped
1356
+	}
1357
+
1358
+
1359
+	/**
1360
+	 * This just sets up the post update messages when an update form is loaded
1361
+	 *
1362
+	 * @param array $messages the original messages array
1363
+	 * @return array           the new messages array
1364
+	 */
1365
+	public function post_update_messages($messages)
1366
+	{
1367
+		global $post;
1368
+		$id       = $this->request->getRequestParam('post');
1369
+		$id       = empty($id) && is_object($post) ? $post->ID : null;
1370
+		$revision = $this->request->getRequestParam('revision', 0, 'int');
1371
+
1372
+		$messages[ $post->post_type ] = [
1373
+			0  => '', // Unused. Messages start at index 1.
1374
+			1  => sprintf(
1375
+				esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1376
+				$this->_cpt_object->labels->singular_name,
1377
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1378
+				'</a>'
1379
+			),
1380
+			2  => esc_html__('Custom field updated', 'event_espresso'),
1381
+			3  => esc_html__('Custom field deleted.', 'event_espresso'),
1382
+			4  => sprintf(esc_html__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1383
+			5  => $revision
1384
+				? sprintf(
1385
+					esc_html__('%s restored to revision from %s', 'event_espresso'),
1386
+					$this->_cpt_object->labels->singular_name,
1387
+					wp_post_revision_title($revision, false)
1388
+				)
1389
+				: false,
1390
+			6  => sprintf(
1391
+				esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1392
+				$this->_cpt_object->labels->singular_name,
1393
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1394
+				'</a>'
1395
+			),
1396
+			7  => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1397
+			8  => sprintf(
1398
+				esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1399
+				$this->_cpt_object->labels->singular_name,
1400
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1401
+				'</a>'
1402
+			),
1403
+			9  => sprintf(
1404
+				esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1405
+				$this->_cpt_object->labels->singular_name,
1406
+				'<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1407
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1408
+				'</a>'
1409
+			),
1410
+			10 => sprintf(
1411
+				esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1412
+				$this->_cpt_object->labels->singular_name,
1413
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1414
+				'</a>'
1415
+			),
1416
+		];
1417
+		return $messages;
1418
+	}
1419
+
1420
+
1421
+	/**
1422
+	 * default method for the 'create_new' route for cpt admin pages.
1423
+	 * For reference what to include in here, see wp-admin/post-new.php
1424
+	 *
1425
+	 * @return void
1426
+	 */
1427
+	protected function _create_new_cpt_item()
1428
+	{
1429
+		// gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1430
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1431
+		$post_type        = $this->_cpt_routes[ $this->_req_action ];
1432
+		$post_type_object = $this->_cpt_object;
1433
+		$title            = $post_type_object->labels->add_new_item;
1434
+		$post             = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1435
+		add_action('admin_print_styles', [$this, 'add_new_admin_page_global']);
1436
+		// modify the default editor title field with default title.
1437
+		add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10);
1438
+		$this->loadEditorTemplate(true);
1439
+	}
1440
+
1441
+
1442
+	/**
1443
+	 * Enqueues auto-save and loads the editor template
1444
+	 *
1445
+	 * @param bool $creating
1446
+	 */
1447
+	private function loadEditorTemplate($creating = true)
1448
+	{
1449
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1450
+		// these vars are used by the template
1451
+		$editing = true;
1452
+		$post_ID = $post->ID;
1453
+		if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1454
+			// only enqueue autosave when creating event (necessary to get permalink/url generated)
1455
+			// otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1456
+			if ($creating) {
1457
+				wp_enqueue_script('autosave');
1458
+			} else {
1459
+				if (
1460
+					isset($this->_cpt_routes[ $this->_req_data['action'] ])
1461
+					&& ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1462
+				) {
1463
+					$create_new_action = apply_filters(
1464
+						'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1465
+						'create_new',
1466
+						$this
1467
+					);
1468
+					$post_new_file     = EE_Admin_Page::add_query_args_and_nonce(
1469
+						[
1470
+							'action' => $create_new_action,
1471
+							'page'   => $this->page_slug,
1472
+						],
1473
+						'admin.php'
1474
+					);
1475
+				}
1476
+			}
1477
+			include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1478
+		}
1479
+	}
1480
+
1481
+
1482
+	public function add_new_admin_page_global()
1483
+	{
1484
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1485
+		?>
1486 1486
         <script type="text/javascript">
1487 1487
             adminpage = '<?php echo $admin_page; ?>';
1488 1488
         </script>
1489 1489
         <?php
1490
-    }
1491
-
1492
-
1493
-    /**
1494
-     * default method for the 'edit' route for cpt admin pages
1495
-     * For reference on what to put in here, refer to wp-admin/post.php
1496
-     *
1497
-     * @return string   template for edit cpt form
1498
-     */
1499
-    protected function _edit_cpt_item()
1500
-    {
1501
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1502
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1503
-        $post    = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1504
-        if (empty($post)) {
1505
-            wp_die(esc_html__(
1506
-                'You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?',
1507
-                'event_espresso'
1508
-            ));
1509
-        }
1510
-
1511
-        $post_lock = $this->request->getRequestParam('get-post-lock');
1512
-        if ($post_lock) {
1513
-            wp_set_post_lock($post_id);
1514
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1515
-            exit();
1516
-        }
1517
-
1518
-        // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1519
-        $post_type        = $this->_cpt_routes[ $this->_req_action ];
1520
-        $post_type_object = $this->_cpt_object;
1521
-
1522
-        if (! wp_check_post_lock($post->ID)) {
1523
-            wp_set_post_lock($post->ID);
1524
-        }
1525
-        add_action('admin_footer', '_admin_notice_post_locked');
1526
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1527
-            wp_enqueue_script('admin-comments');
1528
-            enqueue_comment_hotkeys_js();
1529
-        }
1530
-        add_action('admin_print_styles', [$this, 'add_new_admin_page_global']);
1531
-        // modify the default editor title field with default title.
1532
-        add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10);
1533
-        $this->loadEditorTemplate(false);
1534
-    }
1535
-
1536
-
1537
-
1538
-    /**
1539
-     * some getters
1540
-     */
1541
-    /**
1542
-     * This returns the protected _cpt_model_obj property
1543
-     *
1544
-     * @return EE_CPT_Base
1545
-     */
1546
-    public function get_cpt_model_obj()
1547
-    {
1548
-        return $this->_cpt_model_obj;
1549
-    }
1490
+	}
1491
+
1492
+
1493
+	/**
1494
+	 * default method for the 'edit' route for cpt admin pages
1495
+	 * For reference on what to put in here, refer to wp-admin/post.php
1496
+	 *
1497
+	 * @return string   template for edit cpt form
1498
+	 */
1499
+	protected function _edit_cpt_item()
1500
+	{
1501
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1502
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1503
+		$post    = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1504
+		if (empty($post)) {
1505
+			wp_die(esc_html__(
1506
+				'You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?',
1507
+				'event_espresso'
1508
+			));
1509
+		}
1510
+
1511
+		$post_lock = $this->request->getRequestParam('get-post-lock');
1512
+		if ($post_lock) {
1513
+			wp_set_post_lock($post_id);
1514
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1515
+			exit();
1516
+		}
1517
+
1518
+		// template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1519
+		$post_type        = $this->_cpt_routes[ $this->_req_action ];
1520
+		$post_type_object = $this->_cpt_object;
1521
+
1522
+		if (! wp_check_post_lock($post->ID)) {
1523
+			wp_set_post_lock($post->ID);
1524
+		}
1525
+		add_action('admin_footer', '_admin_notice_post_locked');
1526
+		if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1527
+			wp_enqueue_script('admin-comments');
1528
+			enqueue_comment_hotkeys_js();
1529
+		}
1530
+		add_action('admin_print_styles', [$this, 'add_new_admin_page_global']);
1531
+		// modify the default editor title field with default title.
1532
+		add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10);
1533
+		$this->loadEditorTemplate(false);
1534
+	}
1535
+
1536
+
1537
+
1538
+	/**
1539
+	 * some getters
1540
+	 */
1541
+	/**
1542
+	 * This returns the protected _cpt_model_obj property
1543
+	 *
1544
+	 * @return EE_CPT_Base
1545
+	 */
1546
+	public function get_cpt_model_obj()
1547
+	{
1548
+		return $this->_cpt_model_obj;
1549
+	}
1550 1550
 }
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 2 patches
Indentation   +2144 added lines, -2144 removed lines patch added patch discarded remove patch
@@ -15,2204 +15,2204 @@
 block discarded – undo
15 15
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * This property is just used to hold the status of whether an event is currently being
20
-     * created (true) or edited (false)
21
-     *
22
-     * @access protected
23
-     * @var bool
24
-     */
25
-    protected $_is_creating_event;
18
+	/**
19
+	 * This property is just used to hold the status of whether an event is currently being
20
+	 * created (true) or edited (false)
21
+	 *
22
+	 * @access protected
23
+	 * @var bool
24
+	 */
25
+	protected $_is_creating_event;
26 26
 
27
-    /**
28
-     * Used to contain the format strings for date and time that will be used for php date and
29
-     * time.
30
-     * Is set in the _set_hooks_properties() method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_date_format_strings;
27
+	/**
28
+	 * Used to contain the format strings for date and time that will be used for php date and
29
+	 * time.
30
+	 * Is set in the _set_hooks_properties() method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_date_format_strings;
35 35
 
36
-    /**
37
-     * @var string $_date_time_format
38
-     */
39
-    protected $_date_time_format;
36
+	/**
37
+	 * @var string $_date_time_format
38
+	 */
39
+	protected $_date_time_format;
40 40
 
41 41
 
42
-    /**
43
-     * @throws InvalidArgumentException
44
-     * @throws InvalidInterfaceException
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    protected function _set_hooks_properties()
48
-    {
49
-        $this->_name = 'pricing';
50
-        // capability check
51
-        if (
52
-            ! EE_Registry::instance()->CAP->current_user_can(
53
-                'ee_read_default_prices',
54
-                'advanced_ticket_datetime_metabox'
55
-            )
56
-        ) {
57
-            return;
58
-        }
59
-        $this->_setup_metaboxes();
60
-        $this->_set_date_time_formats();
61
-        $this->_validate_format_strings();
62
-        $this->_set_scripts_styles();
63
-        // commented out temporarily until logic is implemented in callback
64
-        // add_action(
65
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
66
-        //     array($this, 'autosave_handling')
67
-        // );
68
-        add_filter(
69
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
70
-            array($this, 'caf_updates')
71
-        );
72
-    }
42
+	/**
43
+	 * @throws InvalidArgumentException
44
+	 * @throws InvalidInterfaceException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	protected function _set_hooks_properties()
48
+	{
49
+		$this->_name = 'pricing';
50
+		// capability check
51
+		if (
52
+			! EE_Registry::instance()->CAP->current_user_can(
53
+				'ee_read_default_prices',
54
+				'advanced_ticket_datetime_metabox'
55
+			)
56
+		) {
57
+			return;
58
+		}
59
+		$this->_setup_metaboxes();
60
+		$this->_set_date_time_formats();
61
+		$this->_validate_format_strings();
62
+		$this->_set_scripts_styles();
63
+		// commented out temporarily until logic is implemented in callback
64
+		// add_action(
65
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
66
+		//     array($this, 'autosave_handling')
67
+		// );
68
+		add_filter(
69
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
70
+			array($this, 'caf_updates')
71
+		);
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * @return void
77
-     */
78
-    protected function _setup_metaboxes()
79
-    {
80
-        // if we were going to add our own metaboxes we'd use the below.
81
-        $this->_metaboxes = array(
82
-            0 => array(
83
-                'page_route' => array('edit', 'create_new'),
84
-                'func'       => 'pricing_metabox',
85
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
86
-                'priority'   => 'high',
87
-                'context'    => 'normal',
88
-            ),
89
-        );
90
-        $this->_remove_metaboxes = array(
91
-            0 => array(
92
-                'page_route' => array('edit', 'create_new'),
93
-                'id'         => 'espresso_event_editor_tickets',
94
-                'context'    => 'normal',
95
-            ),
96
-        );
97
-    }
75
+	/**
76
+	 * @return void
77
+	 */
78
+	protected function _setup_metaboxes()
79
+	{
80
+		// if we were going to add our own metaboxes we'd use the below.
81
+		$this->_metaboxes = array(
82
+			0 => array(
83
+				'page_route' => array('edit', 'create_new'),
84
+				'func'       => 'pricing_metabox',
85
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
86
+				'priority'   => 'high',
87
+				'context'    => 'normal',
88
+			),
89
+		);
90
+		$this->_remove_metaboxes = array(
91
+			0 => array(
92
+				'page_route' => array('edit', 'create_new'),
93
+				'id'         => 'espresso_event_editor_tickets',
94
+				'context'    => 'normal',
95
+			),
96
+		);
97
+	}
98 98
 
99 99
 
100
-    /**
101
-     * @return void
102
-     */
103
-    protected function _set_date_time_formats()
104
-    {
105
-        /**
106
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
107
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
108
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
109
-         *
110
-         * @since 4.6.7
111
-         * @var array  Expected an array returned with 'date' and 'time' keys.
112
-         */
113
-        $this->_date_format_strings = apply_filters(
114
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
115
-            array(
116
-                'date' => 'Y-m-d',
117
-                'time' => 'h:i a',
118
-            )
119
-        );
120
-        // validate
121
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
122
-            ? $this->_date_format_strings['date']
123
-            : null;
124
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
125
-            ? $this->_date_format_strings['time']
126
-            : null;
127
-        $this->_date_time_format = $this->_date_format_strings['date']
128
-                                   . ' '
129
-                                   . $this->_date_format_strings['time'];
130
-    }
100
+	/**
101
+	 * @return void
102
+	 */
103
+	protected function _set_date_time_formats()
104
+	{
105
+		/**
106
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
107
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
108
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
109
+		 *
110
+		 * @since 4.6.7
111
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
112
+		 */
113
+		$this->_date_format_strings = apply_filters(
114
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
115
+			array(
116
+				'date' => 'Y-m-d',
117
+				'time' => 'h:i a',
118
+			)
119
+		);
120
+		// validate
121
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
122
+			? $this->_date_format_strings['date']
123
+			: null;
124
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
125
+			? $this->_date_format_strings['time']
126
+			: null;
127
+		$this->_date_time_format = $this->_date_format_strings['date']
128
+								   . ' '
129
+								   . $this->_date_format_strings['time'];
130
+	}
131 131
 
132 132
 
133
-    /**
134
-     * @return void
135
-     */
136
-    protected function _validate_format_strings()
137
-    {
138
-        // validate format strings
139
-        $format_validation = EEH_DTT_Helper::validate_format_string(
140
-            $this->_date_time_format
141
-        );
142
-        if (is_array($format_validation)) {
143
-            $msg = '<p>';
144
-            $msg .= sprintf(
145
-                esc_html__(
146
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
147
-                    'event_espresso'
148
-                ),
149
-                $this->_date_time_format
150
-            );
151
-            $msg .= '</p><ul>';
152
-            foreach ($format_validation as $error) {
153
-                $msg .= '<li>' . $error . '</li>';
154
-            }
155
-            $msg .= '</ul><p>';
156
-            $msg .= sprintf(
157
-                esc_html__(
158
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
159
-                    'event_espresso'
160
-                ),
161
-                '<span style="color:#D54E21;">',
162
-                '</span>'
163
-            );
164
-            $msg .= '</p>';
165
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
166
-            $this->_date_format_strings = array(
167
-                'date' => 'Y-m-d',
168
-                'time' => 'h:i a',
169
-            );
170
-        }
171
-    }
133
+	/**
134
+	 * @return void
135
+	 */
136
+	protected function _validate_format_strings()
137
+	{
138
+		// validate format strings
139
+		$format_validation = EEH_DTT_Helper::validate_format_string(
140
+			$this->_date_time_format
141
+		);
142
+		if (is_array($format_validation)) {
143
+			$msg = '<p>';
144
+			$msg .= sprintf(
145
+				esc_html__(
146
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
147
+					'event_espresso'
148
+				),
149
+				$this->_date_time_format
150
+			);
151
+			$msg .= '</p><ul>';
152
+			foreach ($format_validation as $error) {
153
+				$msg .= '<li>' . $error . '</li>';
154
+			}
155
+			$msg .= '</ul><p>';
156
+			$msg .= sprintf(
157
+				esc_html__(
158
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
159
+					'event_espresso'
160
+				),
161
+				'<span style="color:#D54E21;">',
162
+				'</span>'
163
+			);
164
+			$msg .= '</p>';
165
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
166
+			$this->_date_format_strings = array(
167
+				'date' => 'Y-m-d',
168
+				'time' => 'h:i a',
169
+			);
170
+		}
171
+	}
172 172
 
173 173
 
174
-    /**
175
-     * @return void
176
-     */
177
-    protected function _set_scripts_styles()
178
-    {
179
-        $this->_scripts_styles = array(
180
-            'registers'   => array(
181
-                'ee-tickets-datetimes-css' => array(
182
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
183
-                    'type' => 'css',
184
-                ),
185
-                'ee-dtt-ticket-metabox'    => array(
186
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
187
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
188
-                ),
189
-            ),
190
-            'deregisters' => array(
191
-                'event-editor-css'       => array('type' => 'css'),
192
-                'event-datetime-metabox' => array('type' => 'js'),
193
-            ),
194
-            'enqueues'    => array(
195
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
196
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
197
-            ),
198
-            'localize'    => array(
199
-                'ee-dtt-ticket-metabox' => array(
200
-                    'DTT_TRASH_BLOCK'       => array(
201
-                        'main_warning'            => esc_html__(
202
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
203
-                            'event_espresso'
204
-                        ),
205
-                        'after_warning'           => esc_html__(
206
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
207
-                            'event_espresso'
208
-                        ),
209
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
210
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
211
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
212
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
213
-                        'single_warning_from_tkt' => esc_html__(
214
-                            'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
215
-                            'event_espresso'
216
-                        ),
217
-                        'single_warning_from_dtt' => esc_html__(
218
-                            'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
219
-                            'event_espresso'
220
-                        ),
221
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
222
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
223
-                    ),
224
-                    'DTT_ERROR_MSG'         => array(
225
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
226
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
227
-                                            . '<button class="button-secondary ee-modal-cancel">'
228
-                                            . esc_html__('Dismiss', 'event_espresso')
229
-                                            . '</button></div>',
230
-                    ),
231
-                    'DTT_OVERSELL_WARNING'  => array(
232
-                        'datetime_ticket' => esc_html__(
233
-                            'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
234
-                            'event_espresso'
235
-                        ),
236
-                        'ticket_datetime' => esc_html__(
237
-                            'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
238
-                            'event_espresso'
239
-                        ),
240
-                    ),
241
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
242
-                        $this->_date_format_strings['date'],
243
-                        $this->_date_format_strings['time']
244
-                    ),
245
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
246
-                ),
247
-            ),
248
-        );
249
-    }
174
+	/**
175
+	 * @return void
176
+	 */
177
+	protected function _set_scripts_styles()
178
+	{
179
+		$this->_scripts_styles = array(
180
+			'registers'   => array(
181
+				'ee-tickets-datetimes-css' => array(
182
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
183
+					'type' => 'css',
184
+				),
185
+				'ee-dtt-ticket-metabox'    => array(
186
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
187
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
188
+				),
189
+			),
190
+			'deregisters' => array(
191
+				'event-editor-css'       => array('type' => 'css'),
192
+				'event-datetime-metabox' => array('type' => 'js'),
193
+			),
194
+			'enqueues'    => array(
195
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
196
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
197
+			),
198
+			'localize'    => array(
199
+				'ee-dtt-ticket-metabox' => array(
200
+					'DTT_TRASH_BLOCK'       => array(
201
+						'main_warning'            => esc_html__(
202
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
203
+							'event_espresso'
204
+						),
205
+						'after_warning'           => esc_html__(
206
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
207
+							'event_espresso'
208
+						),
209
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
210
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
211
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
212
+													 . esc_html__('Close', 'event_espresso') . '</button>',
213
+						'single_warning_from_tkt' => esc_html__(
214
+							'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
215
+							'event_espresso'
216
+						),
217
+						'single_warning_from_dtt' => esc_html__(
218
+							'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
219
+							'event_espresso'
220
+						),
221
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
222
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
223
+					),
224
+					'DTT_ERROR_MSG'         => array(
225
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
226
+						'dismiss_button' => '<div class="save-cancel-button-container">'
227
+											. '<button class="button-secondary ee-modal-cancel">'
228
+											. esc_html__('Dismiss', 'event_espresso')
229
+											. '</button></div>',
230
+					),
231
+					'DTT_OVERSELL_WARNING'  => array(
232
+						'datetime_ticket' => esc_html__(
233
+							'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
234
+							'event_espresso'
235
+						),
236
+						'ticket_datetime' => esc_html__(
237
+							'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
238
+							'event_espresso'
239
+						),
240
+					),
241
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
242
+						$this->_date_format_strings['date'],
243
+						$this->_date_format_strings['time']
244
+					),
245
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
246
+				),
247
+			),
248
+		);
249
+	}
250 250
 
251 251
 
252
-    /**
253
-     * @param array $update_callbacks
254
-     * @return array
255
-     */
256
-    public function caf_updates(array $update_callbacks)
257
-    {
258
-        foreach ($update_callbacks as $key => $callback) {
259
-            if ($callback[1] === '_default_tickets_update') {
260
-                unset($update_callbacks[ $key ]);
261
-            }
262
-        }
263
-        $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
264
-        return $update_callbacks;
265
-    }
252
+	/**
253
+	 * @param array $update_callbacks
254
+	 * @return array
255
+	 */
256
+	public function caf_updates(array $update_callbacks)
257
+	{
258
+		foreach ($update_callbacks as $key => $callback) {
259
+			if ($callback[1] === '_default_tickets_update') {
260
+				unset($update_callbacks[ $key ]);
261
+			}
262
+		}
263
+		$update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
264
+		return $update_callbacks;
265
+	}
266 266
 
267 267
 
268
-    /**
269
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
270
-     *
271
-     * @param  EE_Event $event The Event object we're attaching data to
272
-     * @param  array    $data  The request data from the form
273
-     * @throws ReflectionException
274
-     * @throws Exception
275
-     * @throws InvalidInterfaceException
276
-     * @throws InvalidDataTypeException
277
-     * @throws EE_Error
278
-     * @throws InvalidArgumentException
279
-     */
280
-    public function datetime_and_tickets_caf_update($event, $data)
281
-    {
282
-        // first we need to start with datetimes cause they are the "root" items attached to events.
283
-        $saved_datetimes = $this->_update_datetimes($event, $data);
284
-        // next tackle the tickets (and prices?)
285
-        $this->_update_tickets($event, $saved_datetimes, $data);
286
-    }
268
+	/**
269
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
270
+	 *
271
+	 * @param  EE_Event $event The Event object we're attaching data to
272
+	 * @param  array    $data  The request data from the form
273
+	 * @throws ReflectionException
274
+	 * @throws Exception
275
+	 * @throws InvalidInterfaceException
276
+	 * @throws InvalidDataTypeException
277
+	 * @throws EE_Error
278
+	 * @throws InvalidArgumentException
279
+	 */
280
+	public function datetime_and_tickets_caf_update($event, $data)
281
+	{
282
+		// first we need to start with datetimes cause they are the "root" items attached to events.
283
+		$saved_datetimes = $this->_update_datetimes($event, $data);
284
+		// next tackle the tickets (and prices?)
285
+		$this->_update_tickets($event, $saved_datetimes, $data);
286
+	}
287 287
 
288 288
 
289
-    /**
290
-     * update event_datetimes
291
-     *
292
-     * @param  EE_Event $event Event being updated
293
-     * @param  array    $data  the request data from the form
294
-     * @return EE_Datetime[]
295
-     * @throws Exception
296
-     * @throws ReflectionException
297
-     * @throws InvalidInterfaceException
298
-     * @throws InvalidDataTypeException
299
-     * @throws InvalidArgumentException
300
-     * @throws EE_Error
301
-     */
302
-    protected function _update_datetimes($event, $data)
303
-    {
304
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
305
-        $saved_dtt_ids = array();
306
-        $saved_dtt_objs = array();
307
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
308
-            throw new InvalidArgumentException(
309
-                esc_html__(
310
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
311
-                    'event_espresso'
312
-                )
313
-            );
314
-        }
315
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
316
-            // trim all values to ensure any excess whitespace is removed.
317
-            $datetime_data = array_map(
318
-                function ($datetime_data) {
319
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
320
-                },
321
-                $datetime_data
322
-            );
323
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
324
-                                            && ! empty($datetime_data['DTT_EVT_end'])
325
-                ? $datetime_data['DTT_EVT_end']
326
-                : $datetime_data['DTT_EVT_start'];
327
-            $datetime_values = array(
328
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
329
-                    ? $datetime_data['DTT_ID']
330
-                    : null,
331
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
332
-                    ? $datetime_data['DTT_name']
333
-                    : '',
334
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
335
-                    ? $datetime_data['DTT_description']
336
-                    : '',
337
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
338
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
339
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
340
-                    ? EE_INF
341
-                    : $datetime_data['DTT_reg_limit'],
342
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
343
-                    ? $row
344
-                    : $datetime_data['DTT_order'],
345
-            );
346
-            // if we have an id then let's get existing object first and then set the new values.
347
-            // Otherwise we instantiate a new object for save.
348
-            if (! empty($datetime_data['DTT_ID'])) {
349
-                $datetime = EE_Registry::instance()
350
-                                       ->load_model('Datetime', array($timezone))
351
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
352
-                // set date and time format according to what is set in this class.
353
-                $datetime->set_date_format($this->_date_format_strings['date']);
354
-                $datetime->set_time_format($this->_date_format_strings['time']);
355
-                foreach ($datetime_values as $field => $value) {
356
-                    $datetime->set($field, $value);
357
-                }
358
-                // make sure the $dtt_id here is saved just in case
359
-                // after the add_relation_to() the autosave replaces it.
360
-                // We need to do this so we dont' TRASH the parent DTT.
361
-                // (save the ID for both key and value to avoid duplications)
362
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
363
-            } else {
364
-                $datetime = EE_Registry::instance()->load_class(
365
-                    'Datetime',
366
-                    array(
367
-                        $datetime_values,
368
-                        $timezone,
369
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
370
-                    ),
371
-                    false,
372
-                    false
373
-                );
374
-                foreach ($datetime_values as $field => $value) {
375
-                    $datetime->set($field, $value);
376
-                }
377
-            }
378
-            $datetime->save();
379
-            do_action(
380
-                'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save',
381
-                $datetime,
382
-                $row,
383
-                $datetime_data,
384
-                $data
385
-            );
386
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
387
-            // before going any further make sure our dates are setup correctly
388
-            // so that the end date is always equal or greater than the start date.
389
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
390
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
391
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
392
-                $datetime->save();
393
-            }
394
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
395
-            // because it is possible there was a new one created for the autosave.
396
-            // (save the ID for both key and value to avoid duplications)
397
-            $DTT_ID = $datetime->ID();
398
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
399
-            $saved_dtt_objs[ $row ] = $datetime;
400
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
401
-        }
402
-        $event->save();
403
-        // now we need to REMOVE any datetimes that got deleted.
404
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
405
-        // So its safe to permanently delete at this point.
406
-        $old_datetimes = explode(',', $data['datetime_IDs']);
407
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
408
-        if (is_array($old_datetimes)) {
409
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
410
-            foreach ($datetimes_to_delete as $id) {
411
-                $id = absint($id);
412
-                if (empty($id)) {
413
-                    continue;
414
-                }
415
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
416
-                // remove tkt relationships.
417
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
418
-                foreach ($related_tickets as $tkt) {
419
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
420
-                }
421
-                $event->_remove_relation_to($id, 'Datetime');
422
-                $dtt_to_remove->refresh_cache_of_related_objects();
423
-            }
424
-        }
425
-        return $saved_dtt_objs;
426
-    }
289
+	/**
290
+	 * update event_datetimes
291
+	 *
292
+	 * @param  EE_Event $event Event being updated
293
+	 * @param  array    $data  the request data from the form
294
+	 * @return EE_Datetime[]
295
+	 * @throws Exception
296
+	 * @throws ReflectionException
297
+	 * @throws InvalidInterfaceException
298
+	 * @throws InvalidDataTypeException
299
+	 * @throws InvalidArgumentException
300
+	 * @throws EE_Error
301
+	 */
302
+	protected function _update_datetimes($event, $data)
303
+	{
304
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
305
+		$saved_dtt_ids = array();
306
+		$saved_dtt_objs = array();
307
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
308
+			throw new InvalidArgumentException(
309
+				esc_html__(
310
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
311
+					'event_espresso'
312
+				)
313
+			);
314
+		}
315
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
316
+			// trim all values to ensure any excess whitespace is removed.
317
+			$datetime_data = array_map(
318
+				function ($datetime_data) {
319
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
320
+				},
321
+				$datetime_data
322
+			);
323
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
324
+											&& ! empty($datetime_data['DTT_EVT_end'])
325
+				? $datetime_data['DTT_EVT_end']
326
+				: $datetime_data['DTT_EVT_start'];
327
+			$datetime_values = array(
328
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
329
+					? $datetime_data['DTT_ID']
330
+					: null,
331
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
332
+					? $datetime_data['DTT_name']
333
+					: '',
334
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
335
+					? $datetime_data['DTT_description']
336
+					: '',
337
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
338
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
339
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
340
+					? EE_INF
341
+					: $datetime_data['DTT_reg_limit'],
342
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
343
+					? $row
344
+					: $datetime_data['DTT_order'],
345
+			);
346
+			// if we have an id then let's get existing object first and then set the new values.
347
+			// Otherwise we instantiate a new object for save.
348
+			if (! empty($datetime_data['DTT_ID'])) {
349
+				$datetime = EE_Registry::instance()
350
+									   ->load_model('Datetime', array($timezone))
351
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
352
+				// set date and time format according to what is set in this class.
353
+				$datetime->set_date_format($this->_date_format_strings['date']);
354
+				$datetime->set_time_format($this->_date_format_strings['time']);
355
+				foreach ($datetime_values as $field => $value) {
356
+					$datetime->set($field, $value);
357
+				}
358
+				// make sure the $dtt_id here is saved just in case
359
+				// after the add_relation_to() the autosave replaces it.
360
+				// We need to do this so we dont' TRASH the parent DTT.
361
+				// (save the ID for both key and value to avoid duplications)
362
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
363
+			} else {
364
+				$datetime = EE_Registry::instance()->load_class(
365
+					'Datetime',
366
+					array(
367
+						$datetime_values,
368
+						$timezone,
369
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
370
+					),
371
+					false,
372
+					false
373
+				);
374
+				foreach ($datetime_values as $field => $value) {
375
+					$datetime->set($field, $value);
376
+				}
377
+			}
378
+			$datetime->save();
379
+			do_action(
380
+				'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save',
381
+				$datetime,
382
+				$row,
383
+				$datetime_data,
384
+				$data
385
+			);
386
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
387
+			// before going any further make sure our dates are setup correctly
388
+			// so that the end date is always equal or greater than the start date.
389
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
390
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
391
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
392
+				$datetime->save();
393
+			}
394
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
395
+			// because it is possible there was a new one created for the autosave.
396
+			// (save the ID for both key and value to avoid duplications)
397
+			$DTT_ID = $datetime->ID();
398
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
399
+			$saved_dtt_objs[ $row ] = $datetime;
400
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
401
+		}
402
+		$event->save();
403
+		// now we need to REMOVE any datetimes that got deleted.
404
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
405
+		// So its safe to permanently delete at this point.
406
+		$old_datetimes = explode(',', $data['datetime_IDs']);
407
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
408
+		if (is_array($old_datetimes)) {
409
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
410
+			foreach ($datetimes_to_delete as $id) {
411
+				$id = absint($id);
412
+				if (empty($id)) {
413
+					continue;
414
+				}
415
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
416
+				// remove tkt relationships.
417
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
418
+				foreach ($related_tickets as $tkt) {
419
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
420
+				}
421
+				$event->_remove_relation_to($id, 'Datetime');
422
+				$dtt_to_remove->refresh_cache_of_related_objects();
423
+			}
424
+		}
425
+		return $saved_dtt_objs;
426
+	}
427 427
 
428 428
 
429
-    /**
430
-     * update tickets
431
-     *
432
-     * @param  EE_Event      $event           Event object being updated
433
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
434
-     * @param  array         $data            incoming request data
435
-     * @return EE_Ticket[]
436
-     * @throws Exception
437
-     * @throws ReflectionException
438
-     * @throws InvalidInterfaceException
439
-     * @throws InvalidDataTypeException
440
-     * @throws InvalidArgumentException
441
-     * @throws EE_Error
442
-     */
443
-    protected function _update_tickets($event, $saved_datetimes, $data)
444
-    {
445
-        $new_tkt = null;
446
-        $new_default = null;
447
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
448
-        $data = stripslashes_deep($data);
449
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
450
-        $saved_tickets = $datetimes_on_existing = array();
451
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
452
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
453
-            throw new InvalidArgumentException(
454
-                esc_html__(
455
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
456
-                    'event_espresso'
457
-                )
458
-            );
459
-        }
460
-        foreach ($data['edit_tickets'] as $row => $tkt) {
461
-            $update_prices = $create_new_TKT = false;
462
-            // figure out what datetimes were added to the ticket
463
-            // and what datetimes were removed from the ticket in the session.
464
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
465
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
466
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
467
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
468
-            // trim inputs to ensure any excess whitespace is removed.
469
-            $tkt = array_map(
470
-                function ($ticket_data) {
471
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
472
-                },
473
-                $tkt
474
-            );
475
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
476
-            // because we're doing calculations prior to using the models.
477
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
478
-            $ticket_price = isset($tkt['TKT_price'])
479
-                ? round((float) $tkt['TKT_price'], 3)
480
-                : 0;
481
-            // note incoming base price needs converted from localized value.
482
-            $base_price = isset($tkt['TKT_base_price'])
483
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
484
-                : 0;
485
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
486
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
487
-                ? $base_price
488
-                : $ticket_price;
489
-            $base_price_id = isset($tkt['TKT_base_price_ID'])
490
-                ? $tkt['TKT_base_price_ID']
491
-                : 0;
492
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
493
-                ? $data['edit_prices'][ $row ]
494
-                : array();
495
-            $now = null;
496
-            if (empty($tkt['TKT_start_date'])) {
497
-                // lets' use now in the set timezone.
498
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
499
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
500
-            }
501
-            if (empty($tkt['TKT_end_date'])) {
502
-                /**
503
-                 * set the TKT_end_date to the first datetime attached to the ticket.
504
-                 */
505
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
506
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
507
-            }
508
-            $TKT_values = array(
509
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
510
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
511
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
512
-                'TKT_description' => ! empty($tkt['TKT_description'])
513
-                                     && $tkt['TKT_description'] !== esc_html__(
514
-                                         'You can modify this description',
515
-                                         'event_espresso'
516
-                                     )
517
-                    ? $tkt['TKT_description']
518
-                    : '',
519
-                'TKT_start_date'  => $tkt['TKT_start_date'],
520
-                'TKT_end_date'    => $tkt['TKT_end_date'],
521
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
522
-                    ? EE_INF
523
-                    : $tkt['TKT_qty'],
524
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
525
-                    ? EE_INF
526
-                    : $tkt['TKT_uses'],
527
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
528
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
529
-                'TKT_row'         => $row,
530
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
531
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
532
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
533
-                'TKT_price'       => $ticket_price,
534
-            );
535
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
536
-            // which means in turn that the prices will become new prices as well.
537
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
538
-                $TKT_values['TKT_ID'] = 0;
539
-                $TKT_values['TKT_is_default'] = 0;
540
-                $update_prices = true;
541
-            }
542
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
543
-            // we actually do our saves ahead of doing any add_relations to
544
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
545
-            // but DID have it's items modified.
546
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
547
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
548
-            if (absint($TKT_values['TKT_ID'])) {
549
-                $ticket = EE_Registry::instance()
550
-                                     ->load_model('Ticket', array($timezone))
551
-                                     ->get_one_by_ID($tkt['TKT_ID']);
552
-                if ($ticket instanceof EE_Ticket) {
553
-                    $ticket = $this->_update_ticket_datetimes(
554
-                        $ticket,
555
-                        $saved_datetimes,
556
-                        $datetimes_added,
557
-                        $datetimes_removed
558
-                    );
559
-                    // are there any registrations using this ticket ?
560
-                    $tickets_sold = $ticket->count_related(
561
-                        'Registration',
562
-                        array(
563
-                            array(
564
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
565
-                            ),
566
-                        )
567
-                    );
568
-                    // set ticket formats
569
-                    $ticket->set_date_format($this->_date_format_strings['date']);
570
-                    $ticket->set_time_format($this->_date_format_strings['time']);
571
-                    // let's just check the total price for the existing ticket
572
-                    // and determine if it matches the new total price.
573
-                    // if they are different then we create a new ticket (if tickets sold)
574
-                    // if they aren't different then we go ahead and modify existing ticket.
575
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
576
-                    // set new values
577
-                    foreach ($TKT_values as $field => $value) {
578
-                        if ($field === 'TKT_qty') {
579
-                            $ticket->set_qty($value);
580
-                        } else {
581
-                            $ticket->set($field, $value);
582
-                        }
583
-                    }
584
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
585
-                    // Otherwise we have to create a new ticket.
586
-                    if ($create_new_TKT) {
587
-                        $new_tkt = $this->_duplicate_ticket(
588
-                            $ticket,
589
-                            $price_rows,
590
-                            $ticket_price,
591
-                            $base_price,
592
-                            $base_price_id
593
-                        );
594
-                    }
595
-                }
596
-            } else {
597
-                // no TKT_id so a new TKT
598
-                $ticket = EE_Ticket::new_instance(
599
-                    $TKT_values,
600
-                    $timezone,
601
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
602
-                );
603
-                if ($ticket instanceof EE_Ticket) {
604
-                    // make sure ticket has an ID of setting relations won't work
605
-                    $ticket->save();
606
-                    $ticket = $this->_update_ticket_datetimes(
607
-                        $ticket,
608
-                        $saved_datetimes,
609
-                        $datetimes_added,
610
-                        $datetimes_removed
611
-                    );
612
-                    $update_prices = true;
613
-                }
614
-            }
615
-            // make sure any current values have been saved.
616
-            // $ticket->save();
617
-            // before going any further make sure our dates are setup correctly
618
-            // so that the end date is always equal or greater than the start date.
619
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
620
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
621
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
622
-            }
623
-            // let's make sure the base price is handled
624
-            $ticket = ! $create_new_TKT
625
-                ? $this->_add_prices_to_ticket(
626
-                    array(),
627
-                    $ticket,
628
-                    $update_prices,
629
-                    $base_price,
630
-                    $base_price_id
631
-                )
632
-                : $ticket;
633
-            // add/update price_modifiers
634
-            $ticket = ! $create_new_TKT
635
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
636
-                : $ticket;
637
-            // need to make sue that the TKT_price is accurate after saving the prices.
638
-            $ticket->ensure_TKT_Price_correct();
639
-            // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
640
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
641
-                $update_prices = true;
642
-                $new_default = clone $ticket;
643
-                $new_default->set('TKT_ID', 0);
644
-                $new_default->set('TKT_is_default', 1);
645
-                $new_default->set('TKT_row', 1);
646
-                $new_default->set('TKT_price', $ticket_price);
647
-                // remove any dtt relations cause we DON'T want dtt relations attached
648
-                // (note this is just removing the cached relations in the object)
649
-                $new_default->_remove_relations('Datetime');
650
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
651
-                $new_default = $this->_add_prices_to_ticket(
652
-                    $price_rows,
653
-                    $new_default,
654
-                    $update_prices
655
-                );
656
-                // don't forget the base price!
657
-                $new_default = $this->_add_prices_to_ticket(
658
-                    array(),
659
-                    $new_default,
660
-                    $update_prices,
661
-                    $base_price,
662
-                    $base_price_id
663
-                );
664
-                $new_default->save();
665
-                do_action(
666
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
667
-                    $new_default,
668
-                    $row,
669
-                    $ticket,
670
-                    $data
671
-                );
672
-            }
673
-            // DO ALL dtt relationships for both current tickets and any archived tickets
674
-            // for the given dtt that are related to the current ticket.
675
-            // TODO... not sure exactly how we're going to do this considering we don't know
676
-            // what current ticket the archived tickets are related to
677
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
678
-            // let's assign any tickets that have been setup to the saved_tickets tracker
679
-            // save existing TKT
680
-            $ticket->save();
681
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
682
-                // save new TKT
683
-                $new_tkt->save();
684
-                // add new ticket to array
685
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
686
-                do_action(
687
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
688
-                    $new_tkt,
689
-                    $row,
690
-                    $tkt,
691
-                    $data
692
-                );
693
-            } else {
694
-                // add tkt to saved tkts
695
-                $saved_tickets[ $ticket->ID() ] = $ticket;
696
-                do_action(
697
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
698
-                    $ticket,
699
-                    $row,
700
-                    $tkt,
701
-                    $data
702
-                );
703
-            }
704
-        }
705
-        // now we need to handle tickets actually "deleted permanently".
706
-        // There are cases where we'd want this to happen
707
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
708
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
709
-        // No sense in keeping all the related data in the db!
710
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
711
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
712
-        foreach ($tickets_removed as $id) {
713
-            $id = absint($id);
714
-            // get the ticket for this id
715
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
716
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
717
-            if ($tkt_to_remove->get('TKT_is_default')) {
718
-                continue;
719
-            }
720
-            // if this tkt has any registrations attached so then we just ARCHIVE
721
-            // because we don't actually permanently delete these tickets.
722
-            if ($tkt_to_remove->count_related('Registration') > 0) {
723
-                $tkt_to_remove->delete();
724
-                continue;
725
-            }
726
-            // need to get all the related datetimes on this ticket and remove from every single one of them
727
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
728
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
729
-            foreach ($datetimes as $datetime) {
730
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
731
-            }
732
-            // need to do the same for prices (except these prices can also be deleted because again,
733
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
734
-            $tkt_to_remove->delete_related_permanently('Price');
735
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
736
-            // finally let's delete this ticket
737
-            // (which should not be blocked at this point b/c we've removed all our relationships)
738
-            $tkt_to_remove->delete_permanently();
739
-        }
740
-        return $saved_tickets;
741
-    }
429
+	/**
430
+	 * update tickets
431
+	 *
432
+	 * @param  EE_Event      $event           Event object being updated
433
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
434
+	 * @param  array         $data            incoming request data
435
+	 * @return EE_Ticket[]
436
+	 * @throws Exception
437
+	 * @throws ReflectionException
438
+	 * @throws InvalidInterfaceException
439
+	 * @throws InvalidDataTypeException
440
+	 * @throws InvalidArgumentException
441
+	 * @throws EE_Error
442
+	 */
443
+	protected function _update_tickets($event, $saved_datetimes, $data)
444
+	{
445
+		$new_tkt = null;
446
+		$new_default = null;
447
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
448
+		$data = stripslashes_deep($data);
449
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
450
+		$saved_tickets = $datetimes_on_existing = array();
451
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
452
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
453
+			throw new InvalidArgumentException(
454
+				esc_html__(
455
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
456
+					'event_espresso'
457
+				)
458
+			);
459
+		}
460
+		foreach ($data['edit_tickets'] as $row => $tkt) {
461
+			$update_prices = $create_new_TKT = false;
462
+			// figure out what datetimes were added to the ticket
463
+			// and what datetimes were removed from the ticket in the session.
464
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
465
+			$tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
466
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
467
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
468
+			// trim inputs to ensure any excess whitespace is removed.
469
+			$tkt = array_map(
470
+				function ($ticket_data) {
471
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
472
+				},
473
+				$tkt
474
+			);
475
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
476
+			// because we're doing calculations prior to using the models.
477
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
478
+			$ticket_price = isset($tkt['TKT_price'])
479
+				? round((float) $tkt['TKT_price'], 3)
480
+				: 0;
481
+			// note incoming base price needs converted from localized value.
482
+			$base_price = isset($tkt['TKT_base_price'])
483
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
484
+				: 0;
485
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
486
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
487
+				? $base_price
488
+				: $ticket_price;
489
+			$base_price_id = isset($tkt['TKT_base_price_ID'])
490
+				? $tkt['TKT_base_price_ID']
491
+				: 0;
492
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
493
+				? $data['edit_prices'][ $row ]
494
+				: array();
495
+			$now = null;
496
+			if (empty($tkt['TKT_start_date'])) {
497
+				// lets' use now in the set timezone.
498
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
499
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
500
+			}
501
+			if (empty($tkt['TKT_end_date'])) {
502
+				/**
503
+				 * set the TKT_end_date to the first datetime attached to the ticket.
504
+				 */
505
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
506
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
507
+			}
508
+			$TKT_values = array(
509
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
510
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
511
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
512
+				'TKT_description' => ! empty($tkt['TKT_description'])
513
+									 && $tkt['TKT_description'] !== esc_html__(
514
+										 'You can modify this description',
515
+										 'event_espresso'
516
+									 )
517
+					? $tkt['TKT_description']
518
+					: '',
519
+				'TKT_start_date'  => $tkt['TKT_start_date'],
520
+				'TKT_end_date'    => $tkt['TKT_end_date'],
521
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
522
+					? EE_INF
523
+					: $tkt['TKT_qty'],
524
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
525
+					? EE_INF
526
+					: $tkt['TKT_uses'],
527
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
528
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
529
+				'TKT_row'         => $row,
530
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
531
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
532
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
533
+				'TKT_price'       => $ticket_price,
534
+			);
535
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
536
+			// which means in turn that the prices will become new prices as well.
537
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
538
+				$TKT_values['TKT_ID'] = 0;
539
+				$TKT_values['TKT_is_default'] = 0;
540
+				$update_prices = true;
541
+			}
542
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
543
+			// we actually do our saves ahead of doing any add_relations to
544
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
545
+			// but DID have it's items modified.
546
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
547
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
548
+			if (absint($TKT_values['TKT_ID'])) {
549
+				$ticket = EE_Registry::instance()
550
+									 ->load_model('Ticket', array($timezone))
551
+									 ->get_one_by_ID($tkt['TKT_ID']);
552
+				if ($ticket instanceof EE_Ticket) {
553
+					$ticket = $this->_update_ticket_datetimes(
554
+						$ticket,
555
+						$saved_datetimes,
556
+						$datetimes_added,
557
+						$datetimes_removed
558
+					);
559
+					// are there any registrations using this ticket ?
560
+					$tickets_sold = $ticket->count_related(
561
+						'Registration',
562
+						array(
563
+							array(
564
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
565
+							),
566
+						)
567
+					);
568
+					// set ticket formats
569
+					$ticket->set_date_format($this->_date_format_strings['date']);
570
+					$ticket->set_time_format($this->_date_format_strings['time']);
571
+					// let's just check the total price for the existing ticket
572
+					// and determine if it matches the new total price.
573
+					// if they are different then we create a new ticket (if tickets sold)
574
+					// if they aren't different then we go ahead and modify existing ticket.
575
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
576
+					// set new values
577
+					foreach ($TKT_values as $field => $value) {
578
+						if ($field === 'TKT_qty') {
579
+							$ticket->set_qty($value);
580
+						} else {
581
+							$ticket->set($field, $value);
582
+						}
583
+					}
584
+					// if $create_new_TKT is false then we can safely update the existing ticket.
585
+					// Otherwise we have to create a new ticket.
586
+					if ($create_new_TKT) {
587
+						$new_tkt = $this->_duplicate_ticket(
588
+							$ticket,
589
+							$price_rows,
590
+							$ticket_price,
591
+							$base_price,
592
+							$base_price_id
593
+						);
594
+					}
595
+				}
596
+			} else {
597
+				// no TKT_id so a new TKT
598
+				$ticket = EE_Ticket::new_instance(
599
+					$TKT_values,
600
+					$timezone,
601
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
602
+				);
603
+				if ($ticket instanceof EE_Ticket) {
604
+					// make sure ticket has an ID of setting relations won't work
605
+					$ticket->save();
606
+					$ticket = $this->_update_ticket_datetimes(
607
+						$ticket,
608
+						$saved_datetimes,
609
+						$datetimes_added,
610
+						$datetimes_removed
611
+					);
612
+					$update_prices = true;
613
+				}
614
+			}
615
+			// make sure any current values have been saved.
616
+			// $ticket->save();
617
+			// before going any further make sure our dates are setup correctly
618
+			// so that the end date is always equal or greater than the start date.
619
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
620
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
621
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
622
+			}
623
+			// let's make sure the base price is handled
624
+			$ticket = ! $create_new_TKT
625
+				? $this->_add_prices_to_ticket(
626
+					array(),
627
+					$ticket,
628
+					$update_prices,
629
+					$base_price,
630
+					$base_price_id
631
+				)
632
+				: $ticket;
633
+			// add/update price_modifiers
634
+			$ticket = ! $create_new_TKT
635
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
636
+				: $ticket;
637
+			// need to make sue that the TKT_price is accurate after saving the prices.
638
+			$ticket->ensure_TKT_Price_correct();
639
+			// handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
640
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
641
+				$update_prices = true;
642
+				$new_default = clone $ticket;
643
+				$new_default->set('TKT_ID', 0);
644
+				$new_default->set('TKT_is_default', 1);
645
+				$new_default->set('TKT_row', 1);
646
+				$new_default->set('TKT_price', $ticket_price);
647
+				// remove any dtt relations cause we DON'T want dtt relations attached
648
+				// (note this is just removing the cached relations in the object)
649
+				$new_default->_remove_relations('Datetime');
650
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
651
+				$new_default = $this->_add_prices_to_ticket(
652
+					$price_rows,
653
+					$new_default,
654
+					$update_prices
655
+				);
656
+				// don't forget the base price!
657
+				$new_default = $this->_add_prices_to_ticket(
658
+					array(),
659
+					$new_default,
660
+					$update_prices,
661
+					$base_price,
662
+					$base_price_id
663
+				);
664
+				$new_default->save();
665
+				do_action(
666
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
667
+					$new_default,
668
+					$row,
669
+					$ticket,
670
+					$data
671
+				);
672
+			}
673
+			// DO ALL dtt relationships for both current tickets and any archived tickets
674
+			// for the given dtt that are related to the current ticket.
675
+			// TODO... not sure exactly how we're going to do this considering we don't know
676
+			// what current ticket the archived tickets are related to
677
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
678
+			// let's assign any tickets that have been setup to the saved_tickets tracker
679
+			// save existing TKT
680
+			$ticket->save();
681
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
682
+				// save new TKT
683
+				$new_tkt->save();
684
+				// add new ticket to array
685
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
686
+				do_action(
687
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
688
+					$new_tkt,
689
+					$row,
690
+					$tkt,
691
+					$data
692
+				);
693
+			} else {
694
+				// add tkt to saved tkts
695
+				$saved_tickets[ $ticket->ID() ] = $ticket;
696
+				do_action(
697
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
698
+					$ticket,
699
+					$row,
700
+					$tkt,
701
+					$data
702
+				);
703
+			}
704
+		}
705
+		// now we need to handle tickets actually "deleted permanently".
706
+		// There are cases where we'd want this to happen
707
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
708
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
709
+		// No sense in keeping all the related data in the db!
710
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
711
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
712
+		foreach ($tickets_removed as $id) {
713
+			$id = absint($id);
714
+			// get the ticket for this id
715
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
716
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
717
+			if ($tkt_to_remove->get('TKT_is_default')) {
718
+				continue;
719
+			}
720
+			// if this tkt has any registrations attached so then we just ARCHIVE
721
+			// because we don't actually permanently delete these tickets.
722
+			if ($tkt_to_remove->count_related('Registration') > 0) {
723
+				$tkt_to_remove->delete();
724
+				continue;
725
+			}
726
+			// need to get all the related datetimes on this ticket and remove from every single one of them
727
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
728
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
729
+			foreach ($datetimes as $datetime) {
730
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
731
+			}
732
+			// need to do the same for prices (except these prices can also be deleted because again,
733
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
734
+			$tkt_to_remove->delete_related_permanently('Price');
735
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
736
+			// finally let's delete this ticket
737
+			// (which should not be blocked at this point b/c we've removed all our relationships)
738
+			$tkt_to_remove->delete_permanently();
739
+		}
740
+		return $saved_tickets;
741
+	}
742 742
 
743 743
 
744
-    /**
745
-     * @access  protected
746
-     * @param EE_Ticket      $ticket
747
-     * @param \EE_Datetime[] $saved_datetimes
748
-     * @param \EE_Datetime[] $added_datetimes
749
-     * @param \EE_Datetime[] $removed_datetimes
750
-     * @return EE_Ticket
751
-     * @throws EE_Error
752
-     */
753
-    protected function _update_ticket_datetimes(
754
-        EE_Ticket $ticket,
755
-        $saved_datetimes = array(),
756
-        $added_datetimes = array(),
757
-        $removed_datetimes = array()
758
-    ) {
759
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
760
-        // and removing the ticket from datetimes it got removed from.
761
-        // first let's add datetimes
762
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
763
-            foreach ($added_datetimes as $row_id) {
764
-                $row_id = (int) $row_id;
765
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
766
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
767
-                    // Is this an existing ticket (has an ID) and does it have any sold?
768
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
769
-                    if ($ticket->ID() && $ticket->sold() > 0) {
770
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
771
-                    }
772
-                }
773
-            }
774
-        }
775
-        // then remove datetimes
776
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
777
-            foreach ($removed_datetimes as $row_id) {
778
-                $row_id = (int) $row_id;
779
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
780
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
781
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
782
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
783
-                    // Is this an existing ticket (has an ID) and does it have any sold?
784
-                    // If so, then we need to remove it's sold from the DTT_sold.
785
-                    if ($ticket->ID() && $ticket->sold() > 0) {
786
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
787
-                    }
788
-                }
789
-            }
790
-        }
791
-        // cap ticket qty by datetime reg limits
792
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
793
-        return $ticket;
794
-    }
744
+	/**
745
+	 * @access  protected
746
+	 * @param EE_Ticket      $ticket
747
+	 * @param \EE_Datetime[] $saved_datetimes
748
+	 * @param \EE_Datetime[] $added_datetimes
749
+	 * @param \EE_Datetime[] $removed_datetimes
750
+	 * @return EE_Ticket
751
+	 * @throws EE_Error
752
+	 */
753
+	protected function _update_ticket_datetimes(
754
+		EE_Ticket $ticket,
755
+		$saved_datetimes = array(),
756
+		$added_datetimes = array(),
757
+		$removed_datetimes = array()
758
+	) {
759
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
760
+		// and removing the ticket from datetimes it got removed from.
761
+		// first let's add datetimes
762
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
763
+			foreach ($added_datetimes as $row_id) {
764
+				$row_id = (int) $row_id;
765
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
766
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
767
+					// Is this an existing ticket (has an ID) and does it have any sold?
768
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
769
+					if ($ticket->ID() && $ticket->sold() > 0) {
770
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
771
+					}
772
+				}
773
+			}
774
+		}
775
+		// then remove datetimes
776
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
777
+			foreach ($removed_datetimes as $row_id) {
778
+				$row_id = (int) $row_id;
779
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
780
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
781
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
782
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
783
+					// Is this an existing ticket (has an ID) and does it have any sold?
784
+					// If so, then we need to remove it's sold from the DTT_sold.
785
+					if ($ticket->ID() && $ticket->sold() > 0) {
786
+						$saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
787
+					}
788
+				}
789
+			}
790
+		}
791
+		// cap ticket qty by datetime reg limits
792
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
793
+		return $ticket;
794
+	}
795 795
 
796 796
 
797
-    /**
798
-     * @access  protected
799
-     * @param EE_Ticket $ticket
800
-     * @param array     $price_rows
801
-     * @param int       $ticket_price
802
-     * @param int       $base_price
803
-     * @param int       $base_price_id
804
-     * @return EE_Ticket
805
-     * @throws ReflectionException
806
-     * @throws InvalidArgumentException
807
-     * @throws InvalidInterfaceException
808
-     * @throws InvalidDataTypeException
809
-     * @throws EE_Error
810
-     */
811
-    protected function _duplicate_ticket(
812
-        EE_Ticket $ticket,
813
-        $price_rows = array(),
814
-        $ticket_price = 0,
815
-        $base_price = 0,
816
-        $base_price_id = 0
817
-    ) {
818
-        // create new ticket that's a copy of the existing
819
-        // except a new id of course (and not archived)
820
-        // AND has the new TKT_price associated with it.
821
-        $new_ticket = clone $ticket;
822
-        $new_ticket->set('TKT_ID', 0);
823
-        $new_ticket->set_deleted(0);
824
-        $new_ticket->set_price($ticket_price);
825
-        $new_ticket->set_sold(0);
826
-        // let's get a new ID for this ticket
827
-        $new_ticket->save();
828
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
829
-        $datetimes_on_existing = $ticket->datetimes();
830
-        $new_ticket = $this->_update_ticket_datetimes(
831
-            $new_ticket,
832
-            $datetimes_on_existing,
833
-            array_keys($datetimes_on_existing)
834
-        );
835
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
836
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
837
-        // available.
838
-        if ($ticket->sold() > 0) {
839
-            $new_qty = $ticket->qty() - $ticket->sold();
840
-            $new_ticket->set_qty($new_qty);
841
-        }
842
-        // now we update the prices just for this ticket
843
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
844
-        // and we update the base price
845
-        $new_ticket = $this->_add_prices_to_ticket(
846
-            array(),
847
-            $new_ticket,
848
-            true,
849
-            $base_price,
850
-            $base_price_id
851
-        );
852
-        return $new_ticket;
853
-    }
797
+	/**
798
+	 * @access  protected
799
+	 * @param EE_Ticket $ticket
800
+	 * @param array     $price_rows
801
+	 * @param int       $ticket_price
802
+	 * @param int       $base_price
803
+	 * @param int       $base_price_id
804
+	 * @return EE_Ticket
805
+	 * @throws ReflectionException
806
+	 * @throws InvalidArgumentException
807
+	 * @throws InvalidInterfaceException
808
+	 * @throws InvalidDataTypeException
809
+	 * @throws EE_Error
810
+	 */
811
+	protected function _duplicate_ticket(
812
+		EE_Ticket $ticket,
813
+		$price_rows = array(),
814
+		$ticket_price = 0,
815
+		$base_price = 0,
816
+		$base_price_id = 0
817
+	) {
818
+		// create new ticket that's a copy of the existing
819
+		// except a new id of course (and not archived)
820
+		// AND has the new TKT_price associated with it.
821
+		$new_ticket = clone $ticket;
822
+		$new_ticket->set('TKT_ID', 0);
823
+		$new_ticket->set_deleted(0);
824
+		$new_ticket->set_price($ticket_price);
825
+		$new_ticket->set_sold(0);
826
+		// let's get a new ID for this ticket
827
+		$new_ticket->save();
828
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
829
+		$datetimes_on_existing = $ticket->datetimes();
830
+		$new_ticket = $this->_update_ticket_datetimes(
831
+			$new_ticket,
832
+			$datetimes_on_existing,
833
+			array_keys($datetimes_on_existing)
834
+		);
835
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
836
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
837
+		// available.
838
+		if ($ticket->sold() > 0) {
839
+			$new_qty = $ticket->qty() - $ticket->sold();
840
+			$new_ticket->set_qty($new_qty);
841
+		}
842
+		// now we update the prices just for this ticket
843
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
844
+		// and we update the base price
845
+		$new_ticket = $this->_add_prices_to_ticket(
846
+			array(),
847
+			$new_ticket,
848
+			true,
849
+			$base_price,
850
+			$base_price_id
851
+		);
852
+		return $new_ticket;
853
+	}
854 854
 
855 855
 
856
-    /**
857
-     * This attaches a list of given prices to a ticket.
858
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
859
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
860
-     * price info and prices are automatically "archived" via the ticket.
861
-     *
862
-     * @access  private
863
-     * @param array     $prices        Array of prices from the form.
864
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
865
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
866
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
867
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
868
-     * @return EE_Ticket
869
-     * @throws ReflectionException
870
-     * @throws InvalidArgumentException
871
-     * @throws InvalidInterfaceException
872
-     * @throws InvalidDataTypeException
873
-     * @throws EE_Error
874
-     */
875
-    protected function _add_prices_to_ticket(
876
-        $prices = array(),
877
-        EE_Ticket $ticket,
878
-        $new_prices = false,
879
-        $base_price = false,
880
-        $base_price_id = false
881
-    ) {
882
-        // let's just get any current prices that may exist on the given ticket
883
-        // so we can remove any prices that got trashed in this session.
884
-        $current_prices_on_ticket = $base_price !== false
885
-            ? $ticket->base_price(true)
886
-            : $ticket->price_modifiers();
887
-        $updated_prices = array();
888
-        // if $base_price ! FALSE then updating a base price.
889
-        if ($base_price !== false) {
890
-            $prices[1] = array(
891
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
892
-                'PRT_ID'     => 1,
893
-                'PRC_amount' => $base_price,
894
-                'PRC_name'   => $ticket->get('TKT_name'),
895
-                'PRC_desc'   => $ticket->get('TKT_description'),
896
-            );
897
-        }
898
-        // possibly need to save tkt
899
-        if (! $ticket->ID()) {
900
-            $ticket->save();
901
-        }
902
-        foreach ($prices as $row => $prc) {
903
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
904
-            if (empty($prt_id)) {
905
-                continue;
906
-            } //prices MUST have a price type id.
907
-            $PRC_values = array(
908
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
909
-                'PRT_ID'         => $prt_id,
910
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
911
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
912
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
913
-                'PRC_is_default' => false,
914
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
915
-                'PRC_order'      => $row,
916
-            );
917
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
918
-                $PRC_values['PRC_ID'] = 0;
919
-                $price = EE_Registry::instance()->load_class(
920
-                    'Price',
921
-                    array($PRC_values),
922
-                    false,
923
-                    false
924
-                );
925
-            } else {
926
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
927
-                // update this price with new values
928
-                foreach ($PRC_values as $field => $value) {
929
-                    $price->set($field, $value);
930
-                }
931
-            }
932
-            $price->save();
933
-            $updated_prices[ $price->ID() ] = $price;
934
-            $ticket->_add_relation_to($price, 'Price');
935
-        }
936
-        // now let's remove any prices that got removed from the ticket
937
-        if (! empty($current_prices_on_ticket)) {
938
-            $current = array_keys($current_prices_on_ticket);
939
-            $updated = array_keys($updated_prices);
940
-            $prices_to_remove = array_diff($current, $updated);
941
-            if (! empty($prices_to_remove)) {
942
-                foreach ($prices_to_remove as $prc_id) {
943
-                    $p = $current_prices_on_ticket[ $prc_id ];
944
-                    $ticket->_remove_relation_to($p, 'Price');
945
-                    // delete permanently the price
946
-                    $p->delete_permanently();
947
-                }
948
-            }
949
-        }
950
-        return $ticket;
951
-    }
856
+	/**
857
+	 * This attaches a list of given prices to a ticket.
858
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
859
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
860
+	 * price info and prices are automatically "archived" via the ticket.
861
+	 *
862
+	 * @access  private
863
+	 * @param array     $prices        Array of prices from the form.
864
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
865
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
866
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
867
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
868
+	 * @return EE_Ticket
869
+	 * @throws ReflectionException
870
+	 * @throws InvalidArgumentException
871
+	 * @throws InvalidInterfaceException
872
+	 * @throws InvalidDataTypeException
873
+	 * @throws EE_Error
874
+	 */
875
+	protected function _add_prices_to_ticket(
876
+		$prices = array(),
877
+		EE_Ticket $ticket,
878
+		$new_prices = false,
879
+		$base_price = false,
880
+		$base_price_id = false
881
+	) {
882
+		// let's just get any current prices that may exist on the given ticket
883
+		// so we can remove any prices that got trashed in this session.
884
+		$current_prices_on_ticket = $base_price !== false
885
+			? $ticket->base_price(true)
886
+			: $ticket->price_modifiers();
887
+		$updated_prices = array();
888
+		// if $base_price ! FALSE then updating a base price.
889
+		if ($base_price !== false) {
890
+			$prices[1] = array(
891
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
892
+				'PRT_ID'     => 1,
893
+				'PRC_amount' => $base_price,
894
+				'PRC_name'   => $ticket->get('TKT_name'),
895
+				'PRC_desc'   => $ticket->get('TKT_description'),
896
+			);
897
+		}
898
+		// possibly need to save tkt
899
+		if (! $ticket->ID()) {
900
+			$ticket->save();
901
+		}
902
+		foreach ($prices as $row => $prc) {
903
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
904
+			if (empty($prt_id)) {
905
+				continue;
906
+			} //prices MUST have a price type id.
907
+			$PRC_values = array(
908
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
909
+				'PRT_ID'         => $prt_id,
910
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
911
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
912
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
913
+				'PRC_is_default' => false,
914
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
915
+				'PRC_order'      => $row,
916
+			);
917
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
918
+				$PRC_values['PRC_ID'] = 0;
919
+				$price = EE_Registry::instance()->load_class(
920
+					'Price',
921
+					array($PRC_values),
922
+					false,
923
+					false
924
+				);
925
+			} else {
926
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
927
+				// update this price with new values
928
+				foreach ($PRC_values as $field => $value) {
929
+					$price->set($field, $value);
930
+				}
931
+			}
932
+			$price->save();
933
+			$updated_prices[ $price->ID() ] = $price;
934
+			$ticket->_add_relation_to($price, 'Price');
935
+		}
936
+		// now let's remove any prices that got removed from the ticket
937
+		if (! empty($current_prices_on_ticket)) {
938
+			$current = array_keys($current_prices_on_ticket);
939
+			$updated = array_keys($updated_prices);
940
+			$prices_to_remove = array_diff($current, $updated);
941
+			if (! empty($prices_to_remove)) {
942
+				foreach ($prices_to_remove as $prc_id) {
943
+					$p = $current_prices_on_ticket[ $prc_id ];
944
+					$ticket->_remove_relation_to($p, 'Price');
945
+					// delete permanently the price
946
+					$p->delete_permanently();
947
+				}
948
+			}
949
+		}
950
+		return $ticket;
951
+	}
952 952
 
953 953
 
954
-    /**
955
-     * @param Events_Admin_Page $event_admin_obj
956
-     * @return Events_Admin_Page
957
-     */
958
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
959
-    {
960
-        return $event_admin_obj;
961
-        // doing nothing for the moment.
962
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
963
-        // (use the set_template_args() method)
964
-        /**
965
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
966
-         * 1. TKT_is_default_selector (visible)
967
-         * 2. TKT_is_default (hidden)
968
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
969
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
970
-         * this ticket to be saved as a default.
971
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
972
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
973
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
974
-         * the TKT HAS been saved as a default..
975
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
976
-         * On Autosave:
977
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
978
-         * then set the TKT_is_default to false.
979
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
980
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
981
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
982
-         */
983
-    }
954
+	/**
955
+	 * @param Events_Admin_Page $event_admin_obj
956
+	 * @return Events_Admin_Page
957
+	 */
958
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
959
+	{
960
+		return $event_admin_obj;
961
+		// doing nothing for the moment.
962
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
963
+		// (use the set_template_args() method)
964
+		/**
965
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
966
+		 * 1. TKT_is_default_selector (visible)
967
+		 * 2. TKT_is_default (hidden)
968
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
969
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
970
+		 * this ticket to be saved as a default.
971
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
972
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
973
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
974
+		 * the TKT HAS been saved as a default..
975
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
976
+		 * On Autosave:
977
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
978
+		 * then set the TKT_is_default to false.
979
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
980
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
981
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
982
+		 */
983
+	}
984 984
 
985 985
 
986
-    /**
987
-     * @throws ReflectionException
988
-     * @throws InvalidArgumentException
989
-     * @throws InvalidInterfaceException
990
-     * @throws InvalidDataTypeException
991
-     * @throws DomainException
992
-     * @throws EE_Error
993
-     */
994
-    public function pricing_metabox()
995
-    {
996
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
997
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
998
-        // set is_creating_event property.
999
-        $EVT_ID = $event->ID();
1000
-        $this->_is_creating_event = empty($this->_req_data['post']);
1001
-        // default main template args
1002
-        $main_template_args = array(
1003
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1004
-                'event_editor_event_datetimes_help_tab',
1005
-                $this->_adminpage_obj->page_slug,
1006
-                $this->_adminpage_obj->get_req_action(),
1007
-                false,
1008
-                false
1009
-            ),
1010
-            // todo need to add a filter to the template for the help text
1011
-            // in the Events_Admin_Page core file so we can add further help
1012
-            'existing_datetime_ids'    => '',
1013
-            'total_dtt_rows'           => 1,
1014
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1015
-                'add_new_dtt_info',
1016
-                $this->_adminpage_obj->page_slug,
1017
-                $this->_adminpage_obj->get_req_action(),
1018
-                false,
1019
-                false
1020
-            ),
1021
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1022
-            'datetime_rows'            => '',
1023
-            'show_tickets_container'   => '',
1024
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1025
-            'ticket_rows'              => '',
1026
-            'existing_ticket_ids'      => '',
1027
-            'total_ticket_rows'        => 1,
1028
-            'ticket_js_structure'      => '',
1029
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1030
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1031
-        );
1032
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1033
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1034
-        /**
1035
-         * 1. Start with retrieving Datetimes
1036
-         * 2. For each datetime get related tickets
1037
-         * 3. For each ticket get related prices
1038
-         */
1039
-        /** @var EEM_Datetime $datetime_model */
1040
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1041
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1042
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1043
-        /**
1044
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1045
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1046
-         */
1047
-        $datetime_row = 1;
1048
-        foreach ($datetimes as $datetime) {
1049
-            $DTT_ID = $datetime->get('DTT_ID');
1050
-            $datetime->set('DTT_order', $datetime_row);
1051
-            $existing_datetime_ids[] = $DTT_ID;
1052
-            // tickets attached
1053
-            $related_tickets = $datetime->ID() > 0
1054
-                ? $datetime->get_many_related(
1055
-                    'Ticket',
1056
-                    array(
1057
-                        array(
1058
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1059
-                        ),
1060
-                        'default_where_conditions' => 'none',
1061
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1062
-                    )
1063
-                )
1064
-                : array();
1065
-            // if there are no related tickets this is likely a new event OR autodraft
1066
-            // event so we need to generate the default tickets because datetimes
1067
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1068
-            // datetime on the event.
1069
-            if (empty($related_tickets) && count($datetimes) < 2) {
1070
-                /** @var EEM_Ticket $ticket_model */
1071
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1072
-                $related_tickets = $ticket_model->get_all_default_tickets();
1073
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1074
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1075
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1076
-                $main_default_ticket = reset($related_tickets);
1077
-                if ($main_default_ticket instanceof EE_Ticket) {
1078
-                    foreach ($default_prices as $default_price) {
1079
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1080
-                            continue;
1081
-                        }
1082
-                        $main_default_ticket->cache('Price', $default_price);
1083
-                    }
1084
-                }
1085
-            }
1086
-            // we can't actually setup rows in this loop yet cause we don't know all
1087
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1088
-            // So we're going to temporarily cache some of that information.
1089
-            // loop through and setup the ticket rows and make sure the order is set.
1090
-            foreach ($related_tickets as $ticket) {
1091
-                $TKT_ID = $ticket->get('TKT_ID');
1092
-                $ticket_row = $ticket->get('TKT_row');
1093
-                // we only want unique tickets in our final display!!
1094
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1095
-                    $existing_ticket_ids[] = $TKT_ID;
1096
-                    $all_tickets[] = $ticket;
1097
-                }
1098
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1099
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1100
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1101
-                if (
1102
-                    ! isset($ticket_datetimes[ $TKT_ID ])
1103
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1104
-                ) {
1105
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1106
-                }
1107
-            }
1108
-            $datetime_row++;
1109
-        }
1110
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1111
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1112
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1113
-        // sort $all_tickets by order
1114
-        usort(
1115
-            $all_tickets,
1116
-            function (EE_Ticket $a, EE_Ticket $b) {
1117
-                $a_order = (int) $a->get('TKT_order');
1118
-                $b_order = (int) $b->get('TKT_order');
1119
-                if ($a_order === $b_order) {
1120
-                    return 0;
1121
-                }
1122
-                return ($a_order < $b_order) ? -1 : 1;
1123
-            }
1124
-        );
1125
-        // k NOW we have all the data we need for setting up the dtt rows
1126
-        // and ticket rows so we start our dtt loop again.
1127
-        $datetime_row = 1;
1128
-        foreach ($datetimes as $datetime) {
1129
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1130
-                $datetime_row,
1131
-                $datetime,
1132
-                $datetime_tickets,
1133
-                $all_tickets,
1134
-                false,
1135
-                $datetimes
1136
-            );
1137
-            $datetime_row++;
1138
-        }
1139
-        // then loop through all tickets for the ticket rows.
1140
-        $ticket_row = 1;
1141
-        foreach ($all_tickets as $ticket) {
1142
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1143
-                $ticket_row,
1144
-                $ticket,
1145
-                $ticket_datetimes,
1146
-                $datetimes,
1147
-                false,
1148
-                $all_tickets
1149
-            );
1150
-            $ticket_row++;
1151
-        }
1152
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1153
-        EEH_Template::display_template(
1154
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1155
-            $main_template_args
1156
-        );
1157
-    }
986
+	/**
987
+	 * @throws ReflectionException
988
+	 * @throws InvalidArgumentException
989
+	 * @throws InvalidInterfaceException
990
+	 * @throws InvalidDataTypeException
991
+	 * @throws DomainException
992
+	 * @throws EE_Error
993
+	 */
994
+	public function pricing_metabox()
995
+	{
996
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
997
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
998
+		// set is_creating_event property.
999
+		$EVT_ID = $event->ID();
1000
+		$this->_is_creating_event = empty($this->_req_data['post']);
1001
+		// default main template args
1002
+		$main_template_args = array(
1003
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1004
+				'event_editor_event_datetimes_help_tab',
1005
+				$this->_adminpage_obj->page_slug,
1006
+				$this->_adminpage_obj->get_req_action(),
1007
+				false,
1008
+				false
1009
+			),
1010
+			// todo need to add a filter to the template for the help text
1011
+			// in the Events_Admin_Page core file so we can add further help
1012
+			'existing_datetime_ids'    => '',
1013
+			'total_dtt_rows'           => 1,
1014
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1015
+				'add_new_dtt_info',
1016
+				$this->_adminpage_obj->page_slug,
1017
+				$this->_adminpage_obj->get_req_action(),
1018
+				false,
1019
+				false
1020
+			),
1021
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1022
+			'datetime_rows'            => '',
1023
+			'show_tickets_container'   => '',
1024
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1025
+			'ticket_rows'              => '',
1026
+			'existing_ticket_ids'      => '',
1027
+			'total_ticket_rows'        => 1,
1028
+			'ticket_js_structure'      => '',
1029
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1030
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1031
+		);
1032
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1033
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1034
+		/**
1035
+		 * 1. Start with retrieving Datetimes
1036
+		 * 2. For each datetime get related tickets
1037
+		 * 3. For each ticket get related prices
1038
+		 */
1039
+		/** @var EEM_Datetime $datetime_model */
1040
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1041
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1042
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1043
+		/**
1044
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1045
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1046
+		 */
1047
+		$datetime_row = 1;
1048
+		foreach ($datetimes as $datetime) {
1049
+			$DTT_ID = $datetime->get('DTT_ID');
1050
+			$datetime->set('DTT_order', $datetime_row);
1051
+			$existing_datetime_ids[] = $DTT_ID;
1052
+			// tickets attached
1053
+			$related_tickets = $datetime->ID() > 0
1054
+				? $datetime->get_many_related(
1055
+					'Ticket',
1056
+					array(
1057
+						array(
1058
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1059
+						),
1060
+						'default_where_conditions' => 'none',
1061
+						'order_by'                 => array('TKT_order' => 'ASC'),
1062
+					)
1063
+				)
1064
+				: array();
1065
+			// if there are no related tickets this is likely a new event OR autodraft
1066
+			// event so we need to generate the default tickets because datetimes
1067
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1068
+			// datetime on the event.
1069
+			if (empty($related_tickets) && count($datetimes) < 2) {
1070
+				/** @var EEM_Ticket $ticket_model */
1071
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1072
+				$related_tickets = $ticket_model->get_all_default_tickets();
1073
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1074
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1075
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1076
+				$main_default_ticket = reset($related_tickets);
1077
+				if ($main_default_ticket instanceof EE_Ticket) {
1078
+					foreach ($default_prices as $default_price) {
1079
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1080
+							continue;
1081
+						}
1082
+						$main_default_ticket->cache('Price', $default_price);
1083
+					}
1084
+				}
1085
+			}
1086
+			// we can't actually setup rows in this loop yet cause we don't know all
1087
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1088
+			// So we're going to temporarily cache some of that information.
1089
+			// loop through and setup the ticket rows and make sure the order is set.
1090
+			foreach ($related_tickets as $ticket) {
1091
+				$TKT_ID = $ticket->get('TKT_ID');
1092
+				$ticket_row = $ticket->get('TKT_row');
1093
+				// we only want unique tickets in our final display!!
1094
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1095
+					$existing_ticket_ids[] = $TKT_ID;
1096
+					$all_tickets[] = $ticket;
1097
+				}
1098
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1099
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1100
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1101
+				if (
1102
+					! isset($ticket_datetimes[ $TKT_ID ])
1103
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1104
+				) {
1105
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1106
+				}
1107
+			}
1108
+			$datetime_row++;
1109
+		}
1110
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1111
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1112
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1113
+		// sort $all_tickets by order
1114
+		usort(
1115
+			$all_tickets,
1116
+			function (EE_Ticket $a, EE_Ticket $b) {
1117
+				$a_order = (int) $a->get('TKT_order');
1118
+				$b_order = (int) $b->get('TKT_order');
1119
+				if ($a_order === $b_order) {
1120
+					return 0;
1121
+				}
1122
+				return ($a_order < $b_order) ? -1 : 1;
1123
+			}
1124
+		);
1125
+		// k NOW we have all the data we need for setting up the dtt rows
1126
+		// and ticket rows so we start our dtt loop again.
1127
+		$datetime_row = 1;
1128
+		foreach ($datetimes as $datetime) {
1129
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1130
+				$datetime_row,
1131
+				$datetime,
1132
+				$datetime_tickets,
1133
+				$all_tickets,
1134
+				false,
1135
+				$datetimes
1136
+			);
1137
+			$datetime_row++;
1138
+		}
1139
+		// then loop through all tickets for the ticket rows.
1140
+		$ticket_row = 1;
1141
+		foreach ($all_tickets as $ticket) {
1142
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1143
+				$ticket_row,
1144
+				$ticket,
1145
+				$ticket_datetimes,
1146
+				$datetimes,
1147
+				false,
1148
+				$all_tickets
1149
+			);
1150
+			$ticket_row++;
1151
+		}
1152
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1153
+		EEH_Template::display_template(
1154
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1155
+			$main_template_args
1156
+		);
1157
+	}
1158 1158
 
1159 1159
 
1160
-    /**
1161
-     * @param int         $datetime_row
1162
-     * @param EE_Datetime $datetime
1163
-     * @param array       $datetime_tickets
1164
-     * @param array       $all_tickets
1165
-     * @param bool        $default
1166
-     * @param array       $all_datetimes
1167
-     * @return mixed
1168
-     * @throws DomainException
1169
-     * @throws EE_Error
1170
-     */
1171
-    protected function _get_datetime_row(
1172
-        $datetime_row,
1173
-        EE_Datetime $datetime,
1174
-        $datetime_tickets = array(),
1175
-        $all_tickets = array(),
1176
-        $default = false,
1177
-        $all_datetimes = array()
1178
-    ) {
1179
-        $dtt_display_template_args = array(
1180
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1181
-                $datetime_row,
1182
-                $datetime,
1183
-                $default,
1184
-                $all_datetimes
1185
-            ),
1186
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1187
-                $datetime_row,
1188
-                $datetime,
1189
-                $datetime_tickets,
1190
-                $all_tickets,
1191
-                $default
1192
-            ),
1193
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1194
-        );
1195
-        return EEH_Template::display_template(
1196
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1197
-            $dtt_display_template_args,
1198
-            true
1199
-        );
1200
-    }
1160
+	/**
1161
+	 * @param int         $datetime_row
1162
+	 * @param EE_Datetime $datetime
1163
+	 * @param array       $datetime_tickets
1164
+	 * @param array       $all_tickets
1165
+	 * @param bool        $default
1166
+	 * @param array       $all_datetimes
1167
+	 * @return mixed
1168
+	 * @throws DomainException
1169
+	 * @throws EE_Error
1170
+	 */
1171
+	protected function _get_datetime_row(
1172
+		$datetime_row,
1173
+		EE_Datetime $datetime,
1174
+		$datetime_tickets = array(),
1175
+		$all_tickets = array(),
1176
+		$default = false,
1177
+		$all_datetimes = array()
1178
+	) {
1179
+		$dtt_display_template_args = array(
1180
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1181
+				$datetime_row,
1182
+				$datetime,
1183
+				$default,
1184
+				$all_datetimes
1185
+			),
1186
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1187
+				$datetime_row,
1188
+				$datetime,
1189
+				$datetime_tickets,
1190
+				$all_tickets,
1191
+				$default
1192
+			),
1193
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1194
+		);
1195
+		return EEH_Template::display_template(
1196
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1197
+			$dtt_display_template_args,
1198
+			true
1199
+		);
1200
+	}
1201 1201
 
1202 1202
 
1203
-    /**
1204
-     * This method is used to generate a dtt fields  edit row.
1205
-     * The same row is used to generate a row with valid DTT objects
1206
-     * and the default row that is used as the skeleton by the js.
1207
-     *
1208
-     * @param int           $datetime_row  The row number for the row being generated.
1209
-     * @param EE_Datetime   $datetime
1210
-     * @param bool          $default       Whether a default row is being generated or not.
1211
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1212
-     * @return string
1213
-     * @throws DomainException
1214
-     * @throws EE_Error
1215
-     */
1216
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1217
-    {
1218
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1219
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1220
-        $template_args = array(
1221
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1222
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1223
-            'edit_dtt_expanded'    => '',
1224
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1225
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1226
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1227
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1228
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1229
-            'DTT_reg_limit'        => $default
1230
-                ? ''
1231
-                : $datetime->get_pretty(
1232
-                    'DTT_reg_limit',
1233
-                    'input'
1234
-                ),
1235
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1236
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1237
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1238
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1239
-                ? ''
1240
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1241
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1242
-                ? 'ee-lock-icon'
1243
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1244
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1245
-                ? ''
1246
-                : EE_Admin_Page::add_query_args_and_nonce(
1247
-                    array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1248
-                    REG_ADMIN_URL
1249
-                ),
1250
-        );
1251
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1252
-            ? ' style="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
-    }
1203
+	/**
1204
+	 * This method is used to generate a dtt fields  edit row.
1205
+	 * The same row is used to generate a row with valid DTT objects
1206
+	 * and the default row that is used as the skeleton by the js.
1207
+	 *
1208
+	 * @param int           $datetime_row  The row number for the row being generated.
1209
+	 * @param EE_Datetime   $datetime
1210
+	 * @param bool          $default       Whether a default row is being generated or not.
1211
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1212
+	 * @return string
1213
+	 * @throws DomainException
1214
+	 * @throws EE_Error
1215
+	 */
1216
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1217
+	{
1218
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1219
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1220
+		$template_args = array(
1221
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1222
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1223
+			'edit_dtt_expanded'    => '',
1224
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1225
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1226
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1227
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1228
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1229
+			'DTT_reg_limit'        => $default
1230
+				? ''
1231
+				: $datetime->get_pretty(
1232
+					'DTT_reg_limit',
1233
+					'input'
1234
+				),
1235
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1236
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1237
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1238
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1239
+				? ''
1240
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1241
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1242
+				? 'ee-lock-icon'
1243
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1244
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1245
+				? ''
1246
+				: EE_Admin_Page::add_query_args_and_nonce(
1247
+					array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1248
+					REG_ADMIN_URL
1249
+				),
1250
+		);
1251
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1252
+			? ' style="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
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'                  => ' style="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
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'                  => ' style="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
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="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
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="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="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'          => ' style="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_f('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
-                : ' style="display:none;"',
1554
-            'show_price_mod_button'         => count($prices) > 1
1555
-                                               || ($default && $count_price_mods > 0)
1556
-                                               || (! $default && $ticket->deleted())
1557
-                ? ' style="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
-                : ' style="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
-            ? ' style="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="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'          => ' style="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_f('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
+				: ' style="display:none;"',
1554
+			'show_price_mod_button'         => count($prices) > 1
1555
+											   || ($default && $count_price_mods > 0)
1556
+											   || (! $default && $ticket->deleted())
1557
+				? ' style="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
+				: ' style="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
+			? ' style="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
-                    : ' style="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
+					: ' style="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
-                : ' style="display:none;"',
1801
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1802
-                ? ' style="display:none;"'
1803
-                : '',
1804
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1805
-                ? ' style="display:none;"'
1806
-                : '',
1807
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1808
-                ? ' style="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
-                ? ' style="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
+				: ' style="display:none;"',
1801
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1802
+				? ' style="display:none;"'
1803
+				: '',
1804
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1805
+				? ' style="display:none;"'
1806
+				: '',
1807
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1808
+				? ' style="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
+				? ' style="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
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="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
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="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.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
             );
151 151
             $msg .= '</p><ul>';
152 152
             foreach ($format_validation as $error) {
153
-                $msg .= '<li>' . $error . '</li>';
153
+                $msg .= '<li>'.$error.'</li>';
154 154
             }
155 155
             $msg .= '</ul><p>';
156 156
             $msg .= sprintf(
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
         $this->_scripts_styles = array(
180 180
             'registers'   => array(
181 181
                 'ee-tickets-datetimes-css' => array(
182
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
182
+                    'url'  => PRICING_ASSETS_URL.'event-tickets-datetimes.css',
183 183
                     'type' => 'css',
184 184
                 ),
185 185
                 'ee-dtt-ticket-metabox'    => array(
186
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
186
+                    'url'     => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js',
187 187
                     'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
188 188
                 ),
189 189
             ),
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
                             'event_espresso'
208 208
                         ),
209 209
                         'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
210
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
210
+                                                     . esc_html__('Cancel', 'event_espresso').'</button>',
211 211
                         'close_button'            => '<button class="button-secondary ee-modal-cancel">'
212
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
212
+                                                     . esc_html__('Close', 'event_espresso').'</button>',
213 213
                         'single_warning_from_tkt' => esc_html__(
214 214
                             'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
215 215
                             'event_espresso'
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                             'event_espresso'
220 220
                         ),
221 221
                         'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
222
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
222
+                                                     . esc_html__('Dismiss', 'event_espresso').'</button>',
223 223
                     ),
224 224
                     'DTT_ERROR_MSG'         => array(
225 225
                         'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
     {
258 258
         foreach ($update_callbacks as $key => $callback) {
259 259
             if ($callback[1] === '_default_tickets_update') {
260
-                unset($update_callbacks[ $key ]);
260
+                unset($update_callbacks[$key]);
261 261
             }
262 262
         }
263 263
         $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
         foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
316 316
             // trim all values to ensure any excess whitespace is removed.
317 317
             $datetime_data = array_map(
318
-                function ($datetime_data) {
318
+                function($datetime_data) {
319 319
                     return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
320 320
                 },
321 321
                 $datetime_data
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
             );
346 346
             // if we have an id then let's get existing object first and then set the new values.
347 347
             // Otherwise we instantiate a new object for save.
348
-            if (! empty($datetime_data['DTT_ID'])) {
348
+            if ( ! empty($datetime_data['DTT_ID'])) {
349 349
                 $datetime = EE_Registry::instance()
350 350
                                        ->load_model('Datetime', array($timezone))
351 351
                                        ->get_one_by_ID($datetime_data['DTT_ID']);
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
                 // after the add_relation_to() the autosave replaces it.
360 360
                 // We need to do this so we dont' TRASH the parent DTT.
361 361
                 // (save the ID for both key and value to avoid duplications)
362
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
362
+                $saved_dtt_ids[$datetime->ID()] = $datetime->ID();
363 363
             } else {
364 364
                 $datetime = EE_Registry::instance()->load_class(
365 365
                     'Datetime',
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
             // because it is possible there was a new one created for the autosave.
396 396
             // (save the ID for both key and value to avoid duplications)
397 397
             $DTT_ID = $datetime->ID();
398
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
399
-            $saved_dtt_objs[ $row ] = $datetime;
398
+            $saved_dtt_ids[$DTT_ID] = $DTT_ID;
399
+            $saved_dtt_objs[$row] = $datetime;
400 400
             // @todo if ANY of these updates fail then we want the appropriate global error message.
401 401
         }
402 402
         $event->save();
@@ -461,13 +461,13 @@  discard block
 block discarded – undo
461 461
             $update_prices = $create_new_TKT = false;
462 462
             // figure out what datetimes were added to the ticket
463 463
             // and what datetimes were removed from the ticket in the session.
464
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
465
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
464
+            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
465
+            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]);
466 466
             $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
467 467
             $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
468 468
             // trim inputs to ensure any excess whitespace is removed.
469 469
             $tkt = array_map(
470
-                function ($ticket_data) {
470
+                function($ticket_data) {
471 471
                     return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
472 472
                 },
473 473
                 $tkt
@@ -489,8 +489,8 @@  discard block
 block discarded – undo
489 489
             $base_price_id = isset($tkt['TKT_base_price_ID'])
490 490
                 ? $tkt['TKT_base_price_ID']
491 491
                 : 0;
492
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
493
-                ? $data['edit_prices'][ $row ]
492
+            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row])
493
+                ? $data['edit_prices'][$row]
494 494
                 : array();
495 495
             $now = null;
496 496
             if (empty($tkt['TKT_start_date'])) {
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
                 /**
503 503
                  * set the TKT_end_date to the first datetime attached to the ticket.
504 504
                  */
505
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
505
+                $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)];
506 506
                 $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
507 507
             }
508 508
             $TKT_values = array(
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
             // need to make sue that the TKT_price is accurate after saving the prices.
638 638
             $ticket->ensure_TKT_Price_correct();
639 639
             // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
640
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
640
+            if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
641 641
                 $update_prices = true;
642 642
                 $new_default = clone $ticket;
643 643
                 $new_default->set('TKT_ID', 0);
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
                 // save new TKT
683 683
                 $new_tkt->save();
684 684
                 // add new ticket to array
685
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
685
+                $saved_tickets[$new_tkt->ID()] = $new_tkt;
686 686
                 do_action(
687 687
                     'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
688 688
                     $new_tkt,
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
                 );
693 693
             } else {
694 694
                 // add tkt to saved tkts
695
-                $saved_tickets[ $ticket->ID() ] = $ticket;
695
+                $saved_tickets[$ticket->ID()] = $ticket;
696 696
                 do_action(
697 697
                     'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
698 698
                     $ticket,
@@ -759,31 +759,31 @@  discard block
 block discarded – undo
759 759
         // to start we have to add the ticket to all the datetimes its supposed to be with,
760 760
         // and removing the ticket from datetimes it got removed from.
761 761
         // first let's add datetimes
762
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
762
+        if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
763 763
             foreach ($added_datetimes as $row_id) {
764 764
                 $row_id = (int) $row_id;
765
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
766
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
765
+                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
766
+                    $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
767 767
                     // Is this an existing ticket (has an ID) and does it have any sold?
768 768
                     // If so, then we need to add that to the DTT sold because this DTT is getting added.
769 769
                     if ($ticket->ID() && $ticket->sold() > 0) {
770
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
770
+                        $saved_datetimes[$row_id]->increaseSold($ticket->sold(), false);
771 771
                     }
772 772
                 }
773 773
             }
774 774
         }
775 775
         // then remove datetimes
776
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
776
+        if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
777 777
             foreach ($removed_datetimes as $row_id) {
778 778
                 $row_id = (int) $row_id;
779 779
                 // its entirely possible that a datetime got deleted (instead of just removed from relationship.
780 780
                 // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
781
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
782
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
781
+                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
782
+                    $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
783 783
                     // Is this an existing ticket (has an ID) and does it have any sold?
784 784
                     // If so, then we need to remove it's sold from the DTT_sold.
785 785
                     if ($ticket->ID() && $ticket->sold() > 0) {
786
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
786
+                        $saved_datetimes[$row_id]->decreaseSold($ticket->sold());
787 787
                     }
788 788
                 }
789 789
             }
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
             );
897 897
         }
898 898
         // possibly need to save tkt
899
-        if (! $ticket->ID()) {
899
+        if ( ! $ticket->ID()) {
900 900
             $ticket->save();
901 901
         }
902 902
         foreach ($prices as $row => $prc) {
@@ -930,17 +930,17 @@  discard block
 block discarded – undo
930 930
                 }
931 931
             }
932 932
             $price->save();
933
-            $updated_prices[ $price->ID() ] = $price;
933
+            $updated_prices[$price->ID()] = $price;
934 934
             $ticket->_add_relation_to($price, 'Price');
935 935
         }
936 936
         // now let's remove any prices that got removed from the ticket
937
-        if (! empty($current_prices_on_ticket)) {
937
+        if ( ! empty($current_prices_on_ticket)) {
938 938
             $current = array_keys($current_prices_on_ticket);
939 939
             $updated = array_keys($updated_prices);
940 940
             $prices_to_remove = array_diff($current, $updated);
941
-            if (! empty($prices_to_remove)) {
941
+            if ( ! empty($prices_to_remove)) {
942 942
                 foreach ($prices_to_remove as $prc_id) {
943
-                    $p = $current_prices_on_ticket[ $prc_id ];
943
+                    $p = $current_prices_on_ticket[$prc_id];
944 944
                     $ticket->_remove_relation_to($p, 'Price');
945 945
                     // delete permanently the price
946 946
                     $p->delete_permanently();
@@ -1091,18 +1091,18 @@  discard block
 block discarded – undo
1091 1091
                 $TKT_ID = $ticket->get('TKT_ID');
1092 1092
                 $ticket_row = $ticket->get('TKT_row');
1093 1093
                 // we only want unique tickets in our final display!!
1094
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1094
+                if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) {
1095 1095
                     $existing_ticket_ids[] = $TKT_ID;
1096 1096
                     $all_tickets[] = $ticket;
1097 1097
                 }
1098 1098
                 // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1099
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1099
+                $datetime_tickets[$DTT_ID][] = $ticket_row;
1100 1100
                 // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1101 1101
                 if (
1102
-                    ! isset($ticket_datetimes[ $TKT_ID ])
1103
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1102
+                    ! isset($ticket_datetimes[$TKT_ID])
1103
+                    || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true)
1104 1104
                 ) {
1105
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1105
+                    $ticket_datetimes[$TKT_ID][] = $datetime_row;
1106 1106
                 }
1107 1107
             }
1108 1108
             $datetime_row++;
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
         // sort $all_tickets by order
1114 1114
         usort(
1115 1115
             $all_tickets,
1116
-            function (EE_Ticket $a, EE_Ticket $b) {
1116
+            function(EE_Ticket $a, EE_Ticket $b) {
1117 1117
                 $a_order = (int) $a->get('TKT_order');
1118 1118
                 $b_order = (int) $b->get('TKT_order');
1119 1119
                 if ($a_order === $b_order) {
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
         }
1152 1152
         $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1153 1153
         EEH_Template::display_template(
1154
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1154
+            PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php',
1155 1155
             $main_template_args
1156 1156
         );
1157 1157
     }
@@ -1193,7 +1193,7 @@  discard block
 block discarded – undo
1193 1193
             'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1194 1194
         );
1195 1195
         return EEH_Template::display_template(
1196
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1196
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php',
1197 1197
             $dtt_display_template_args,
1198 1198
             true
1199 1199
         );
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
             $this->_is_creating_event
1263 1263
         );
1264 1264
         return EEH_Template::display_template(
1265
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1265
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php',
1266 1266
             $template_args,
1267 1267
             true
1268 1268
         );
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
             'DTT_ID'                            => $default ? '' : $datetime->ID(),
1304 1304
         );
1305 1305
         // need to setup the list items (but only if this isn't a default skeleton setup)
1306
-        if (! $default) {
1306
+        if ( ! $default) {
1307 1307
             $ticket_row = 1;
1308 1308
             foreach ($all_tickets as $ticket) {
1309 1309
                 $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
@@ -1329,7 +1329,7 @@  discard block
 block discarded – undo
1329 1329
             $this->_is_creating_event
1330 1330
         );
1331 1331
         return EEH_Template::display_template(
1332
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1332
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php',
1333 1333
             $template_args,
1334 1334
             true
1335 1335
         );
@@ -1355,8 +1355,8 @@  discard block
 block discarded – undo
1355 1355
         $datetime_tickets = array(),
1356 1356
         $default
1357 1357
     ) {
1358
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1359
-            ? $datetime_tickets[ $datetime->ID() ]
1358
+        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()])
1359
+            ? $datetime_tickets[$datetime->ID()]
1360 1360
             : array();
1361 1361
         $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1362 1362
         $no_ticket = $default && empty($ticket);
@@ -1377,8 +1377,8 @@  discard block
 block discarded – undo
1377 1377
                 ? 'TKTNAME'
1378 1378
                 : $ticket->get('TKT_name'),
1379 1379
             'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1380
-                ? ' tkt-status-' . EE_Ticket::onsale
1381
-                : ' tkt-status-' . $ticket->ticket_status(),
1380
+                ? ' tkt-status-'.EE_Ticket::onsale
1381
+                : ' tkt-status-'.$ticket->ticket_status(),
1382 1382
         );
1383 1383
         // filter template args
1384 1384
         $template_args = apply_filters(
@@ -1393,7 +1393,7 @@  discard block
 block discarded – undo
1393 1393
             $this->_is_creating_event
1394 1394
         );
1395 1395
         return EEH_Template::display_template(
1396
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1396
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php',
1397 1397
             $template_args,
1398 1398
             true
1399 1399
         );
@@ -1449,19 +1449,19 @@  discard block
 block discarded – undo
1449 1449
         // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1450 1450
         // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1451 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() ]
1452
+        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()])
1453
+            ? $ticket_datetimes[$ticket->ID()]
1454 1454
             : array();
1455 1455
         $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1456 1456
         $base_price = $default ? null : $ticket->base_price();
1457 1457
         $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1458 1458
         // breaking out complicated condition for ticket_status
1459 1459
         if ($default) {
1460
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1460
+            $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale;
1461 1461
         } else {
1462 1462
             $ticket_status_class = $ticket->is_default()
1463
-                ? ' tkt-status-' . EE_Ticket::onsale
1464
-                : ' tkt-status-' . $ticket->ticket_status();
1463
+                ? ' tkt-status-'.EE_Ticket::onsale
1464
+                : ' tkt-status-'.$ticket->ticket_status();
1465 1465
         }
1466 1466
         // breaking out complicated condition for TKT_taxable
1467 1467
         if ($default) {
@@ -1553,7 +1553,7 @@  discard block
 block discarded – undo
1553 1553
                 : ' style="display:none;"',
1554 1554
             'show_price_mod_button'         => count($prices) > 1
1555 1555
                                                || ($default && $count_price_mods > 0)
1556
-                                               || (! $default && $ticket->deleted())
1556
+                                               || ( ! $default && $ticket->deleted())
1557 1557
                 ? ' style="display:none;"'
1558 1558
                 : '',
1559 1559
             'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
@@ -1597,7 +1597,7 @@  discard block
 block discarded – undo
1597 1597
                 $this->_date_time_format,
1598 1598
                 current_time('timestamp')
1599 1599
             );
1600
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1600
+            $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale;
1601 1601
         }
1602 1602
         if (empty($template_args['TKT_end_date'])) {
1603 1603
             // get the earliest datetime (if present);
@@ -1607,7 +1607,7 @@  discard block
 block discarded – undo
1607 1607
                     array('order_by' => array('DTT_EVT_start' => 'ASC'))
1608 1608
                 )
1609 1609
                 : null;
1610
-            if (! empty($earliest_dtt)) {
1610
+            if ( ! empty($earliest_dtt)) {
1611 1611
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1612 1612
                     'DTT_EVT_start',
1613 1613
                     $this->_date_time_format
@@ -1626,10 +1626,10 @@  discard block
 block discarded – undo
1626 1626
                     )
1627 1627
                 );
1628 1628
             }
1629
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1629
+            $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale;
1630 1630
         }
1631 1631
         // generate ticket_datetime items
1632
-        if (! $default) {
1632
+        if ( ! $default) {
1633 1633
             $datetime_row = 1;
1634 1634
             foreach ($all_datetimes as $datetime) {
1635 1635
                 $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
@@ -1645,7 +1645,7 @@  discard block
 block discarded – undo
1645 1645
         }
1646 1646
         $price_row = 1;
1647 1647
         foreach ($prices as $price) {
1648
-            if (! $price instanceof EE_Price) {
1648
+            if ( ! $price instanceof EE_Price) {
1649 1649
                 continue;
1650 1650
             }
1651 1651
             if ($price->is_base_price()) {
@@ -1678,7 +1678,7 @@  discard block
 block discarded – undo
1678 1678
             $this->_is_creating_event
1679 1679
         );
1680 1680
         return EEH_Template::display_template(
1681
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1681
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php',
1682 1682
             $template_args,
1683 1683
             true
1684 1684
         );
@@ -1718,7 +1718,7 @@  discard block
 block discarded – undo
1718 1718
                 $this->_is_creating_event
1719 1719
             );
1720 1720
             $tax_rows .= EEH_Template::display_template(
1721
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1721
+                PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php',
1722 1722
                 $template_args,
1723 1723
                 true
1724 1724
             );
@@ -1837,7 +1837,7 @@  discard block
 block discarded – undo
1837 1837
             $this->_is_creating_event
1838 1838
         );
1839 1839
         return EEH_Template::display_template(
1840
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1840
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php',
1841 1841
             $template_args,
1842 1842
             true
1843 1843
         );
@@ -1907,7 +1907,7 @@  discard block
 block discarded – undo
1907 1907
             $this->_is_creating_event
1908 1908
         );
1909 1909
         return EEH_Template::display_template(
1910
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1910
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php',
1911 1911
             $template_args,
1912 1912
             true
1913 1913
         );
@@ -1937,7 +1937,7 @@  discard block
 block discarded – undo
1937 1937
     ) {
1938 1938
         $select_name = $default && ! $price instanceof EE_Price
1939 1939
             ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1940
-            : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]';
1940
+            : 'edit_prices['.esc_attr($ticket_row).']['.esc_attr($price_row).'][PRT_ID]';
1941 1941
         /** @var EEM_Price_Type $price_type_model */
1942 1942
         $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1943 1943
         $price_types = $price_type_model->get_all(array(
@@ -1955,10 +1955,10 @@  discard block
 block discarded – undo
1955 1955
         $price_option_spans = '';
1956 1956
         // setup price types for selector
1957 1957
         foreach ($price_types as $price_type) {
1958
-            if (! $price_type instanceof EE_Price_Type) {
1958
+            if ( ! $price_type instanceof EE_Price_Type) {
1959 1959
                 continue;
1960 1960
             }
1961
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1961
+            $all_price_types[$price_type->ID()] = $price_type->get('PRT_name');
1962 1962
             // while we're in the loop let's setup the option spans used by js
1963 1963
             $span_args = array(
1964 1964
                 'PRT_ID'         => $price_type->ID(),
@@ -1966,12 +1966,12 @@  discard block
 block discarded – undo
1966 1966
                 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1967 1967
             );
1968 1968
             $price_option_spans .= EEH_Template::display_template(
1969
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1969
+                PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php',
1970 1970
                 $span_args,
1971 1971
                 true
1972 1972
             );
1973 1973
         }
1974
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1974
+        $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]'
1975 1975
             : $select_name;
1976 1976
         $select_input = new EE_Select_Input(
1977 1977
             $all_price_types,
@@ -2008,7 +2008,7 @@  discard block
 block discarded – undo
2008 2008
             $this->_is_creating_event
2009 2009
         );
2010 2010
         return EEH_Template::display_template(
2011
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2011
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php',
2012 2012
             $template_args,
2013 2013
             true
2014 2014
         );
@@ -2034,8 +2034,8 @@  discard block
 block discarded – undo
2034 2034
         $ticket_datetimes = array(),
2035 2035
         $default
2036 2036
     ) {
2037
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2038
-            ? $ticket_datetimes[ $ticket->ID() ]
2037
+        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()])
2038
+            ? $ticket_datetimes[$ticket->ID()]
2039 2039
             : array();
2040 2040
         $template_args = array(
2041 2041
             'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
@@ -2067,7 +2067,7 @@  discard block
 block discarded – undo
2067 2067
             $this->_is_creating_event
2068 2068
         );
2069 2069
         return EEH_Template::display_template(
2070
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2070
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2071 2071
             $template_args,
2072 2072
             true
2073 2073
         );
@@ -2173,7 +2173,7 @@  discard block
 block discarded – undo
2173 2173
         $default_prices = $price_model->get_all_default_prices();
2174 2174
         $price_row = 1;
2175 2175
         foreach ($default_prices as $price) {
2176
-            if (! $price instanceof EE_Price) {
2176
+            if ( ! $price instanceof EE_Price) {
2177 2177
                 continue;
2178 2178
             }
2179 2179
             if ($price->is_base_price()) {
@@ -2210,7 +2210,7 @@  discard block
 block discarded – undo
2210 2210
             $this->_is_creating_event
2211 2211
         );
2212 2212
         return EEH_Template::display_template(
2213
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2213
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php',
2214 2214
             $template_args,
2215 2215
             true
2216 2216
         );
Please login to merge, or discard this patch.
admin_pages/venues/Venues_Admin_Page.core.php 1 patch
Indentation   +1556 added lines, -1556 removed lines patch added patch discarded remove patch
@@ -14,1566 +14,1566 @@
 block discarded – undo
14 14
 class Venues_Admin_Page extends EE_Admin_Page_CPT
15 15
 {
16 16
 
17
-    /**
18
-     * _venue
19
-     * This will hold the venue object for venue_details screen.
20
-     *
21
-     * @access protected
22
-     * @var object
23
-     */
24
-    protected $_venue;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var object
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This property will hold the venue model instance
37
-     *
38
-     * @var object
39
-     */
40
-    protected $_venue_model;
41
-
42
-
43
-    /**
44
-     * @throws EE_Error
45
-     */
46
-    protected function _init_page_props()
47
-    {
48
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
49
-        $this->page_slug        = EE_VENUES_PG_SLUG;
50
-        $this->_admin_base_url  = EE_VENUES_ADMIN_URL;
51
-        $this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
52
-        $this->page_label       = esc_html__('Event Venues', 'event_espresso');
53
-        $this->_cpt_model_names = [
54
-            'create_new' => 'EEM_Venue',
55
-            'edit'       => 'EEM_Venue',
56
-        ];
57
-        $this->_cpt_edit_routes = [
58
-            'espresso_venues' => 'edit',
59
-        ];
60
-        $this->_venue_model     = EEM_Venue::instance();
61
-    }
62
-
63
-
64
-    protected function _ajax_hooks()
65
-    {
66
-        // todo: all hooks for ee_venues ajax goes in here.
67
-    }
68
-
69
-
70
-    protected function _define_page_props()
71
-    {
72
-        $this->_admin_page_title = $this->page_label;
73
-        $this->_labels           = [
74
-            'buttons'      => [
75
-                'add'             => esc_html__('Add New Venue', 'event_espresso'),
76
-                'edit'            => esc_html__('Edit Venue', 'event_espresso'),
77
-                'delete'          => esc_html__('Delete Venue', 'event_espresso'),
78
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
79
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
80
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
81
-            ],
82
-            'editor_title' => [
83
-                'espresso_venues' => esc_html__('Enter Venue name here', 'event_espresso'),
84
-            ],
85
-            'publishbox'   => [
86
-                'create_new'          => esc_html__('Save New Venue', 'event_espresso'),
87
-                'edit'                => esc_html__('Update Venue', 'event_espresso'),
88
-                'add_category'        => esc_html__('Save New Category', 'event_espresso'),
89
-                'edit_category'       => esc_html__('Update Category', 'event_espresso'),
90
-                'google_map_settings' => esc_html__('Update Settings', 'event_espresso'),
91
-            ],
92
-        ];
93
-    }
94
-
95
-
96
-    protected function _set_page_routes()
97
-    {
98
-
99
-        // load formatter helper
100
-        // load field generator helper
101
-
102
-        // is there a vnu_id in the request?
103
-        $VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
104
-        $VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
105
-
106
-        $this->_page_routes = [
107
-            'default'                    => [
108
-                'func'       => '_overview_list_table',
109
-                'capability' => 'ee_read_venues',
110
-            ],
111
-            'create_new'                 => [
112
-                'func'       => '_create_new_cpt_item',
113
-                'capability' => 'ee_edit_venues',
114
-            ],
115
-            'edit'                       => [
116
-                'func'       => '_edit_cpt_item',
117
-                'capability' => 'ee_edit_venue',
118
-                'obj_id'     => $VNU_ID,
119
-            ],
120
-            'trash_venue'                => [
121
-                'func'       => '_trash_or_restore_venue',
122
-                'args'       => ['venue_status' => 'trash'],
123
-                'noheader'   => true,
124
-                'capability' => 'ee_delete_venue',
125
-                'obj_id'     => $VNU_ID,
126
-            ],
127
-            'trash_venues'               => [
128
-                'func'       => '_trash_or_restore_venues',
129
-                'args'       => ['venue_status' => 'trash'],
130
-                'noheader'   => true,
131
-                'capability' => 'ee_delete_venues',
132
-            ],
133
-            'restore_venue'              => [
134
-                'func'       => '_trash_or_restore_venue',
135
-                'args'       => ['venue_status' => 'draft'],
136
-                'noheader'   => true,
137
-                'capability' => 'ee_delete_venue',
138
-                'obj_id'     => $VNU_ID,
139
-            ],
140
-            'restore_venues'             => [
141
-                'func'       => '_trash_or_restore_venues',
142
-                'args'       => ['venue_status' => 'draft'],
143
-                'noheader'   => true,
144
-                'capability' => 'ee_delete_venues',
145
-            ],
146
-            'delete_venues'              => [
147
-                'func'       => '_delete_venues',
148
-                'noheader'   => true,
149
-                'capability' => 'ee_delete_venues',
150
-            ],
151
-            'delete_venue'               => [
152
-                'func'       => '_delete_venue',
153
-                'noheader'   => true,
154
-                'capability' => 'ee_delete_venue',
155
-                'obj_id'     => $VNU_ID,
156
-            ],
157
-            // settings related
158
-            'google_map_settings'        => [
159
-                'func'       => '_google_map_settings',
160
-                'capability' => 'manage_options',
161
-            ],
162
-            'update_google_map_settings' => [
163
-                'func'       => '_update_google_map_settings',
164
-                'capability' => 'manage_options',
165
-                'noheader'   => true,
166
-            ],
167
-            // venue category tab related
168
-            'add_category'               => [
169
-                'func'       => '_category_details',
170
-                'args'       => ['add'],
171
-                'capability' => 'ee_edit_venue_category',
172
-            ],
173
-            'edit_category'              => [
174
-                'func'       => '_category_details',
175
-                'args'       => ['edit'],
176
-                'capability' => 'ee_edit_venue_category',
177
-            ],
178
-            'delete_categories'          => [
179
-                'func'       => '_delete_categories',
180
-                'noheader'   => true,
181
-                'capability' => 'ee_delete_venue_category',
182
-            ],
183
-
184
-            'delete_category' => [
185
-                'func'       => '_delete_categories',
186
-                'noheader'   => true,
187
-                'capability' => 'ee_delete_venue_category',
188
-            ],
189
-
190
-            'insert_category' => [
191
-                'func'       => '_insert_or_update_category',
192
-                'args'       => ['new_category' => true],
193
-                'noheader'   => true,
194
-                'capability' => 'ee_edit_venue_category',
195
-            ],
196
-
197
-            'update_category'   => [
198
-                'func'       => '_insert_or_update_category',
199
-                'args'       => ['new_category' => false],
200
-                'noheader'   => true,
201
-                'capability' => 'ee_edit_venue_category',
202
-            ],
203
-            'export_categories' => [
204
-                'func'       => '_categories_export',
205
-                'noheader'   => true,
206
-                'capability' => 'export',
207
-            ],
208
-            'import_categories' => [
209
-                'func'       => '_import_categories',
210
-                'capability' => 'import',
211
-            ],
212
-            'category_list'     => [
213
-                'func'       => '_category_list_table',
214
-                'capability' => 'ee_manage_venue_categories',
215
-            ],
216
-        ];
217
-    }
218
-
219
-
220
-    protected function _set_page_config()
221
-    {
222
-        $VNU_ID     = $this->request->getRequestParam('post', 0, 'int');
223
-        $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
224
-
225
-        $this->_page_config = [
226
-            'default'             => [
227
-                'nav'           => [
228
-                    'label' => esc_html__('Overview', 'event_espresso'),
229
-                    'order' => 10,
230
-                ],
231
-                'list_table'    => 'Venues_Admin_List_Table',
232
-                'help_tabs'     => [
233
-                    'venues_overview_help_tab'                           => [
234
-                        'title'    => esc_html__('Venues Overview', 'event_espresso'),
235
-                        'filename' => 'venues_overview',
236
-                    ],
237
-                    'venues_overview_table_column_headings_help_tab'     => [
238
-                        'title'    => esc_html__('Venues Overview Table Column Headings', 'event_espresso'),
239
-                        'filename' => 'venues_overview_table_column_headings',
240
-                    ],
241
-                    'venues_overview_views_bulk_actions_search_help_tab' => [
242
-                        'title'    => esc_html__('Venues Overview Views & Bulk Actions & Search', 'event_espresso'),
243
-                        'filename' => 'venues_overview_views_bulk_actions_search',
244
-                    ],
245
-                ],
246
-                'metaboxes'     => ['_espresso_news_post_box', '_espresso_links_post_box'],
247
-                'require_nonce' => false,
248
-            ],
249
-            'create_new'          => [
250
-                'nav'           => [
251
-                    'label'      => esc_html__('Add Venue', 'event_espresso'),
252
-                    'order'      => 5,
253
-                    'persistent' => false,
254
-                ],
255
-                'help_tabs'     => [
256
-                    'venues_editor_help_tab'                                               => [
257
-                        'title'    => esc_html__('Venue Editor', 'event_espresso'),
258
-                        'filename' => 'venues_editor',
259
-                    ],
260
-                    'venues_editor_title_richtexteditor_help_tab'                          => [
261
-                        'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
262
-                        'filename' => 'venues_editor_title_richtexteditor',
263
-                    ],
264
-                    'venues_editor_tags_categories_help_tab'                               => [
265
-                        'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
266
-                        'filename' => 'venues_editor_tags_categories',
267
-                    ],
268
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
269
-                        'title'    => esc_html__(
270
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
271
-                            'event_espresso'
272
-                        ),
273
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
274
-                    ],
275
-                    'venues_editor_save_new_venue_help_tab'                                => [
276
-                        'title'    => esc_html__('Save New Venue', 'event_espresso'),
277
-                        'filename' => 'venues_editor_save_new_venue',
278
-                    ],
279
-                    'venues_editor_other_help_tab'                                         => [
280
-                        'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
281
-                        'filename' => 'venues_editor_other',
282
-                    ],
283
-                ],
284
-                'metaboxes'     => ['_venue_editor_metaboxes'],
285
-                'require_nonce' => false,
286
-            ],
287
-            'edit'                => [
288
-                'nav'           => [
289
-                    'label'      => esc_html__('Edit Venue', 'event_espresso'),
290
-                    'order'      => 5,
291
-                    'persistent' => false,
292
-                    'url'        => $VNU_ID
293
-                        ? add_query_arg(['post' => $VNU_ID], $this->_current_page_view_url)
294
-                        : $this->_admin_base_url,
295
-                ],
296
-                'help_tabs'     => [
297
-                    'venues_editor_help_tab'                                               => [
298
-                        'title'    => esc_html__('Venue Editor', 'event_espresso'),
299
-                        'filename' => 'venues_editor',
300
-                    ],
301
-                    'venues_editor_title_richtexteditor_help_tab'                          => [
302
-                        'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
303
-                        'filename' => 'venues_editor_title_richtexteditor',
304
-                    ],
305
-                    'venues_editor_tags_categories_help_tab'                               => [
306
-                        'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
307
-                        'filename' => 'venues_editor_tags_categories',
308
-                    ],
309
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
310
-                        'title'    => esc_html__(
311
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
312
-                            'event_espresso'
313
-                        ),
314
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
315
-                    ],
316
-                    'venues_editor_save_new_venue_help_tab'                                => [
317
-                        'title'    => esc_html__('Save New Venue', 'event_espresso'),
318
-                        'filename' => 'venues_editor_save_new_venue',
319
-                    ],
320
-                    'venues_editor_other_help_tab'                                         => [
321
-                        'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
322
-                        'filename' => 'venues_editor_other',
323
-                    ],
324
-                ],
325
-                'metaboxes'     => ['_venue_editor_metaboxes'],
326
-                'require_nonce' => false,
327
-            ],
328
-            'google_map_settings' => [
329
-                'nav'           => [
330
-                    'label' => esc_html__('Google Maps', 'event_espresso'),
331
-                    'order' => 40,
332
-                ],
333
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
334
-                'help_tabs'     => [
335
-                    'general_settings_google_maps_help_tab' => [
336
-                        'title'    => esc_html__('Google Maps', 'event_espresso'),
337
-                        'filename' => 'general_settings_google_maps',
338
-                    ],
339
-                ],
340
-                'require_nonce' => false,
341
-            ],
342
-            // venue category stuff
343
-            'add_category'        => [
344
-                'nav'           => [
345
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
346
-                    'order'      => 15,
347
-                    'persistent' => false,
348
-                ],
349
-                'metaboxes'     => ['_publish_post_box'],
350
-                'help_tabs'     => [
351
-                    'venues_add_category_help_tab' => [
352
-                        'title'    => esc_html__('Add New Venue Category', 'event_espresso'),
353
-                        'filename' => 'venues_add_category',
354
-                    ],
355
-                ],
356
-                'require_nonce' => false,
357
-            ],
358
-            'edit_category'       => [
359
-                'nav'           => [
360
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
361
-                    'order'      => 15,
362
-                    'persistent' => false,
363
-                    'url'        => $EVT_CAT_ID
364
-                        ? add_query_arg(['EVT_CAT_ID' => $EVT_CAT_ID], $this->_current_page_view_url)
365
-                        : $this->_admin_base_url,
366
-                ],
367
-                'metaboxes'     => ['_publish_post_box'],
368
-                'help_tabs'     => [
369
-                    'venues_edit_category_help_tab' => [
370
-                        'title'    => esc_html__('Edit Venue Category', 'event_espresso'),
371
-                        'filename' => 'venues_edit_category',
372
-                    ],
373
-                ],
374
-                'require_nonce' => false,
375
-            ],
376
-            'category_list'       => [
377
-                'nav'           => [
378
-                    'label' => esc_html__('Categories', 'event_espresso'),
379
-                    'order' => 20,
380
-                ],
381
-                'list_table'    => 'Venue_Categories_Admin_List_Table',
382
-                'help_tabs'     => [
383
-                    'venues_categories_help_tab'                       => [
384
-                        'title'    => esc_html__('Venue Categories', 'event_espresso'),
385
-                        'filename' => 'venues_categories',
386
-                    ],
387
-                    'venues_categories_table_column_headings_help_tab' => [
388
-                        'title'    => esc_html__('Venue Categories Table Column Headings', 'event_espresso'),
389
-                        'filename' => 'venues_categories_table_column_headings',
390
-                    ],
391
-                    'venues_categories_views_help_tab'                 => [
392
-                        'title'    => esc_html__('Venue Categories Views', 'event_espresso'),
393
-                        'filename' => 'venues_categories_views',
394
-                    ],
395
-                    'venues_categories_other_help_tab'                 => [
396
-                        'title'    => esc_html__('Venue Categories Other', 'event_espresso'),
397
-                        'filename' => 'venues_categories_other',
398
-                    ],
399
-                ],
400
-                'metaboxes'     => $this->_default_espresso_metaboxes,
401
-                'require_nonce' => false,
402
-            ],
403
-        ];
404
-    }
405
-
406
-
407
-    protected function _add_screen_options()
408
-    {
409
-        // todo
410
-    }
411
-
412
-
413
-    protected function _add_screen_options_default()
414
-    {
415
-        $this->_per_page_screen_option();
416
-    }
417
-
418
-
419
-    protected function _add_screen_options_category_list()
420
-    {
421
-        $page_title              = $this->_admin_page_title;
422
-        $this->_admin_page_title = esc_html__('Venue Categories', 'event_espresso');
423
-        $this->_per_page_screen_option();
424
-        $this->_admin_page_title = $page_title;
425
-    }
426
-
427
-
428
-    // none of the below group are currently used for Event Venues
429
-    protected function _add_feature_pointers()
430
-    {
431
-    }
432
-
433
-
434
-    public function admin_init()
435
-    {
436
-    }
437
-
438
-
439
-    public function admin_notices()
440
-    {
441
-    }
442
-
443
-
444
-    public function admin_footer_scripts()
445
-    {
446
-    }
447
-
448
-
449
-    public function load_scripts_styles_create_new()
450
-    {
451
-        $this->load_scripts_styles_edit();
452
-    }
453
-
454
-
455
-    public function load_scripts_styles()
456
-    {
457
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
458
-        wp_enqueue_style('ee-cat-admin');
459
-    }
460
-
461
-
462
-    public function load_scripts_styles_add_category()
463
-    {
464
-        $this->load_scripts_styles_edit_category();
465
-    }
466
-
467
-
468
-    public function load_scripts_styles_edit_category()
469
-    {
470
-    }
471
-
472
-
473
-    public function load_scripts_styles_edit()
474
-    {
475
-        // styles
476
-        wp_enqueue_style('espresso-ui-theme');
477
-        wp_register_style(
478
-            'espresso_venues',
479
-            EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
480
-            [],
481
-            EVENT_ESPRESSO_VERSION
482
-        );
483
-        wp_enqueue_style('espresso_venues');
484
-    }
485
-
486
-
487
-    protected function _set_list_table_views_default()
488
-    {
489
-        $this->_views = [
490
-            'all' => [
491
-                'slug'        => 'all',
492
-                'label'       => esc_html__('View All Venues', 'event_espresso'),
493
-                'count'       => 0,
494
-                'bulk_action' => [],
495
-            ],
496
-        ];
497
-
498
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
499
-            $this->_views['all']['bulk_action'] = [
500
-                'trash_venues' => esc_html__('Move to Trash', 'event_espresso'),
501
-            ];
502
-            $this->_views['trash']              = [
503
-                'slug'        => 'trash',
504
-                'label'       => esc_html__('Trash', 'event_espresso'),
505
-                'count'       => 0,
506
-                'bulk_action' => [
507
-                    'restore_venues' => esc_html__('Restore from Trash', 'event_espresso'),
508
-                    'delete_venues'  => esc_html__('Delete', 'event_espresso'),
509
-                ],
510
-            ];
511
-        }
512
-    }
513
-
514
-
515
-    protected function _set_list_table_views_category_list()
516
-    {
517
-        $this->_views = [
518
-            'all' => [
519
-                'slug'        => 'all',
520
-                'label'       => esc_html__('All', 'event_espresso'),
521
-                'count'       => 0,
522
-                'bulk_action' => [
523
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
524
-                ],
525
-            ],
526
-        ];
527
-    }
528
-
529
-
530
-    /**
531
-     * @throws EE_Error
532
-     */
533
-    protected function _overview_list_table()
534
-    {
535
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
536
-        $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
537
-            get_post_type_archive_link('espresso_venues'),
538
-            esc_html__("View Venue Archive Page", "event_espresso"),
539
-            'button'
540
-        );
541
-
542
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
543
-            'create_new',
544
-            'add',
545
-            [],
546
-            'add-new-h2'
547
-        );
548
-
549
-        $this->_search_btn_label  = esc_html__('Venues', 'event_espresso');
550
-        $this->display_admin_list_table_page_with_sidebar();
551
-    }
552
-
553
-
554
-    /**
555
-     * @throws EE_Error
556
-     * @throws ReflectionException
557
-     */
558
-    public function extra_misc_actions_publish_box()
559
-    {
560
-        $extra_rows = [
561
-            'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
562
-            'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
563
-            'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
564
-        ];
565
-        $template   = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
566
-        EEH_Template::display_template($template, $extra_rows);
567
-    }
568
-
569
-
570
-    /*************        Google Maps        *************
17
+	/**
18
+	 * _venue
19
+	 * This will hold the venue object for venue_details screen.
20
+	 *
21
+	 * @access protected
22
+	 * @var object
23
+	 */
24
+	protected $_venue;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var object
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This property will hold the venue model instance
37
+	 *
38
+	 * @var object
39
+	 */
40
+	protected $_venue_model;
41
+
42
+
43
+	/**
44
+	 * @throws EE_Error
45
+	 */
46
+	protected function _init_page_props()
47
+	{
48
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
49
+		$this->page_slug        = EE_VENUES_PG_SLUG;
50
+		$this->_admin_base_url  = EE_VENUES_ADMIN_URL;
51
+		$this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
52
+		$this->page_label       = esc_html__('Event Venues', 'event_espresso');
53
+		$this->_cpt_model_names = [
54
+			'create_new' => 'EEM_Venue',
55
+			'edit'       => 'EEM_Venue',
56
+		];
57
+		$this->_cpt_edit_routes = [
58
+			'espresso_venues' => 'edit',
59
+		];
60
+		$this->_venue_model     = EEM_Venue::instance();
61
+	}
62
+
63
+
64
+	protected function _ajax_hooks()
65
+	{
66
+		// todo: all hooks for ee_venues ajax goes in here.
67
+	}
68
+
69
+
70
+	protected function _define_page_props()
71
+	{
72
+		$this->_admin_page_title = $this->page_label;
73
+		$this->_labels           = [
74
+			'buttons'      => [
75
+				'add'             => esc_html__('Add New Venue', 'event_espresso'),
76
+				'edit'            => esc_html__('Edit Venue', 'event_espresso'),
77
+				'delete'          => esc_html__('Delete Venue', 'event_espresso'),
78
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
79
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
80
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
81
+			],
82
+			'editor_title' => [
83
+				'espresso_venues' => esc_html__('Enter Venue name here', 'event_espresso'),
84
+			],
85
+			'publishbox'   => [
86
+				'create_new'          => esc_html__('Save New Venue', 'event_espresso'),
87
+				'edit'                => esc_html__('Update Venue', 'event_espresso'),
88
+				'add_category'        => esc_html__('Save New Category', 'event_espresso'),
89
+				'edit_category'       => esc_html__('Update Category', 'event_espresso'),
90
+				'google_map_settings' => esc_html__('Update Settings', 'event_espresso'),
91
+			],
92
+		];
93
+	}
94
+
95
+
96
+	protected function _set_page_routes()
97
+	{
98
+
99
+		// load formatter helper
100
+		// load field generator helper
101
+
102
+		// is there a vnu_id in the request?
103
+		$VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
104
+		$VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
105
+
106
+		$this->_page_routes = [
107
+			'default'                    => [
108
+				'func'       => '_overview_list_table',
109
+				'capability' => 'ee_read_venues',
110
+			],
111
+			'create_new'                 => [
112
+				'func'       => '_create_new_cpt_item',
113
+				'capability' => 'ee_edit_venues',
114
+			],
115
+			'edit'                       => [
116
+				'func'       => '_edit_cpt_item',
117
+				'capability' => 'ee_edit_venue',
118
+				'obj_id'     => $VNU_ID,
119
+			],
120
+			'trash_venue'                => [
121
+				'func'       => '_trash_or_restore_venue',
122
+				'args'       => ['venue_status' => 'trash'],
123
+				'noheader'   => true,
124
+				'capability' => 'ee_delete_venue',
125
+				'obj_id'     => $VNU_ID,
126
+			],
127
+			'trash_venues'               => [
128
+				'func'       => '_trash_or_restore_venues',
129
+				'args'       => ['venue_status' => 'trash'],
130
+				'noheader'   => true,
131
+				'capability' => 'ee_delete_venues',
132
+			],
133
+			'restore_venue'              => [
134
+				'func'       => '_trash_or_restore_venue',
135
+				'args'       => ['venue_status' => 'draft'],
136
+				'noheader'   => true,
137
+				'capability' => 'ee_delete_venue',
138
+				'obj_id'     => $VNU_ID,
139
+			],
140
+			'restore_venues'             => [
141
+				'func'       => '_trash_or_restore_venues',
142
+				'args'       => ['venue_status' => 'draft'],
143
+				'noheader'   => true,
144
+				'capability' => 'ee_delete_venues',
145
+			],
146
+			'delete_venues'              => [
147
+				'func'       => '_delete_venues',
148
+				'noheader'   => true,
149
+				'capability' => 'ee_delete_venues',
150
+			],
151
+			'delete_venue'               => [
152
+				'func'       => '_delete_venue',
153
+				'noheader'   => true,
154
+				'capability' => 'ee_delete_venue',
155
+				'obj_id'     => $VNU_ID,
156
+			],
157
+			// settings related
158
+			'google_map_settings'        => [
159
+				'func'       => '_google_map_settings',
160
+				'capability' => 'manage_options',
161
+			],
162
+			'update_google_map_settings' => [
163
+				'func'       => '_update_google_map_settings',
164
+				'capability' => 'manage_options',
165
+				'noheader'   => true,
166
+			],
167
+			// venue category tab related
168
+			'add_category'               => [
169
+				'func'       => '_category_details',
170
+				'args'       => ['add'],
171
+				'capability' => 'ee_edit_venue_category',
172
+			],
173
+			'edit_category'              => [
174
+				'func'       => '_category_details',
175
+				'args'       => ['edit'],
176
+				'capability' => 'ee_edit_venue_category',
177
+			],
178
+			'delete_categories'          => [
179
+				'func'       => '_delete_categories',
180
+				'noheader'   => true,
181
+				'capability' => 'ee_delete_venue_category',
182
+			],
183
+
184
+			'delete_category' => [
185
+				'func'       => '_delete_categories',
186
+				'noheader'   => true,
187
+				'capability' => 'ee_delete_venue_category',
188
+			],
189
+
190
+			'insert_category' => [
191
+				'func'       => '_insert_or_update_category',
192
+				'args'       => ['new_category' => true],
193
+				'noheader'   => true,
194
+				'capability' => 'ee_edit_venue_category',
195
+			],
196
+
197
+			'update_category'   => [
198
+				'func'       => '_insert_or_update_category',
199
+				'args'       => ['new_category' => false],
200
+				'noheader'   => true,
201
+				'capability' => 'ee_edit_venue_category',
202
+			],
203
+			'export_categories' => [
204
+				'func'       => '_categories_export',
205
+				'noheader'   => true,
206
+				'capability' => 'export',
207
+			],
208
+			'import_categories' => [
209
+				'func'       => '_import_categories',
210
+				'capability' => 'import',
211
+			],
212
+			'category_list'     => [
213
+				'func'       => '_category_list_table',
214
+				'capability' => 'ee_manage_venue_categories',
215
+			],
216
+		];
217
+	}
218
+
219
+
220
+	protected function _set_page_config()
221
+	{
222
+		$VNU_ID     = $this->request->getRequestParam('post', 0, 'int');
223
+		$EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
224
+
225
+		$this->_page_config = [
226
+			'default'             => [
227
+				'nav'           => [
228
+					'label' => esc_html__('Overview', 'event_espresso'),
229
+					'order' => 10,
230
+				],
231
+				'list_table'    => 'Venues_Admin_List_Table',
232
+				'help_tabs'     => [
233
+					'venues_overview_help_tab'                           => [
234
+						'title'    => esc_html__('Venues Overview', 'event_espresso'),
235
+						'filename' => 'venues_overview',
236
+					],
237
+					'venues_overview_table_column_headings_help_tab'     => [
238
+						'title'    => esc_html__('Venues Overview Table Column Headings', 'event_espresso'),
239
+						'filename' => 'venues_overview_table_column_headings',
240
+					],
241
+					'venues_overview_views_bulk_actions_search_help_tab' => [
242
+						'title'    => esc_html__('Venues Overview Views & Bulk Actions & Search', 'event_espresso'),
243
+						'filename' => 'venues_overview_views_bulk_actions_search',
244
+					],
245
+				],
246
+				'metaboxes'     => ['_espresso_news_post_box', '_espresso_links_post_box'],
247
+				'require_nonce' => false,
248
+			],
249
+			'create_new'          => [
250
+				'nav'           => [
251
+					'label'      => esc_html__('Add Venue', 'event_espresso'),
252
+					'order'      => 5,
253
+					'persistent' => false,
254
+				],
255
+				'help_tabs'     => [
256
+					'venues_editor_help_tab'                                               => [
257
+						'title'    => esc_html__('Venue Editor', 'event_espresso'),
258
+						'filename' => 'venues_editor',
259
+					],
260
+					'venues_editor_title_richtexteditor_help_tab'                          => [
261
+						'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
262
+						'filename' => 'venues_editor_title_richtexteditor',
263
+					],
264
+					'venues_editor_tags_categories_help_tab'                               => [
265
+						'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
266
+						'filename' => 'venues_editor_tags_categories',
267
+					],
268
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
269
+						'title'    => esc_html__(
270
+							'Venue Editor Physical Location & Google Map & Virtual Location',
271
+							'event_espresso'
272
+						),
273
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
274
+					],
275
+					'venues_editor_save_new_venue_help_tab'                                => [
276
+						'title'    => esc_html__('Save New Venue', 'event_espresso'),
277
+						'filename' => 'venues_editor_save_new_venue',
278
+					],
279
+					'venues_editor_other_help_tab'                                         => [
280
+						'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
281
+						'filename' => 'venues_editor_other',
282
+					],
283
+				],
284
+				'metaboxes'     => ['_venue_editor_metaboxes'],
285
+				'require_nonce' => false,
286
+			],
287
+			'edit'                => [
288
+				'nav'           => [
289
+					'label'      => esc_html__('Edit Venue', 'event_espresso'),
290
+					'order'      => 5,
291
+					'persistent' => false,
292
+					'url'        => $VNU_ID
293
+						? add_query_arg(['post' => $VNU_ID], $this->_current_page_view_url)
294
+						: $this->_admin_base_url,
295
+				],
296
+				'help_tabs'     => [
297
+					'venues_editor_help_tab'                                               => [
298
+						'title'    => esc_html__('Venue Editor', 'event_espresso'),
299
+						'filename' => 'venues_editor',
300
+					],
301
+					'venues_editor_title_richtexteditor_help_tab'                          => [
302
+						'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
303
+						'filename' => 'venues_editor_title_richtexteditor',
304
+					],
305
+					'venues_editor_tags_categories_help_tab'                               => [
306
+						'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
307
+						'filename' => 'venues_editor_tags_categories',
308
+					],
309
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
310
+						'title'    => esc_html__(
311
+							'Venue Editor Physical Location & Google Map & Virtual Location',
312
+							'event_espresso'
313
+						),
314
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
315
+					],
316
+					'venues_editor_save_new_venue_help_tab'                                => [
317
+						'title'    => esc_html__('Save New Venue', 'event_espresso'),
318
+						'filename' => 'venues_editor_save_new_venue',
319
+					],
320
+					'venues_editor_other_help_tab'                                         => [
321
+						'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
322
+						'filename' => 'venues_editor_other',
323
+					],
324
+				],
325
+				'metaboxes'     => ['_venue_editor_metaboxes'],
326
+				'require_nonce' => false,
327
+			],
328
+			'google_map_settings' => [
329
+				'nav'           => [
330
+					'label' => esc_html__('Google Maps', 'event_espresso'),
331
+					'order' => 40,
332
+				],
333
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
334
+				'help_tabs'     => [
335
+					'general_settings_google_maps_help_tab' => [
336
+						'title'    => esc_html__('Google Maps', 'event_espresso'),
337
+						'filename' => 'general_settings_google_maps',
338
+					],
339
+				],
340
+				'require_nonce' => false,
341
+			],
342
+			// venue category stuff
343
+			'add_category'        => [
344
+				'nav'           => [
345
+					'label'      => esc_html__('Add Category', 'event_espresso'),
346
+					'order'      => 15,
347
+					'persistent' => false,
348
+				],
349
+				'metaboxes'     => ['_publish_post_box'],
350
+				'help_tabs'     => [
351
+					'venues_add_category_help_tab' => [
352
+						'title'    => esc_html__('Add New Venue Category', 'event_espresso'),
353
+						'filename' => 'venues_add_category',
354
+					],
355
+				],
356
+				'require_nonce' => false,
357
+			],
358
+			'edit_category'       => [
359
+				'nav'           => [
360
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
361
+					'order'      => 15,
362
+					'persistent' => false,
363
+					'url'        => $EVT_CAT_ID
364
+						? add_query_arg(['EVT_CAT_ID' => $EVT_CAT_ID], $this->_current_page_view_url)
365
+						: $this->_admin_base_url,
366
+				],
367
+				'metaboxes'     => ['_publish_post_box'],
368
+				'help_tabs'     => [
369
+					'venues_edit_category_help_tab' => [
370
+						'title'    => esc_html__('Edit Venue Category', 'event_espresso'),
371
+						'filename' => 'venues_edit_category',
372
+					],
373
+				],
374
+				'require_nonce' => false,
375
+			],
376
+			'category_list'       => [
377
+				'nav'           => [
378
+					'label' => esc_html__('Categories', 'event_espresso'),
379
+					'order' => 20,
380
+				],
381
+				'list_table'    => 'Venue_Categories_Admin_List_Table',
382
+				'help_tabs'     => [
383
+					'venues_categories_help_tab'                       => [
384
+						'title'    => esc_html__('Venue Categories', 'event_espresso'),
385
+						'filename' => 'venues_categories',
386
+					],
387
+					'venues_categories_table_column_headings_help_tab' => [
388
+						'title'    => esc_html__('Venue Categories Table Column Headings', 'event_espresso'),
389
+						'filename' => 'venues_categories_table_column_headings',
390
+					],
391
+					'venues_categories_views_help_tab'                 => [
392
+						'title'    => esc_html__('Venue Categories Views', 'event_espresso'),
393
+						'filename' => 'venues_categories_views',
394
+					],
395
+					'venues_categories_other_help_tab'                 => [
396
+						'title'    => esc_html__('Venue Categories Other', 'event_espresso'),
397
+						'filename' => 'venues_categories_other',
398
+					],
399
+				],
400
+				'metaboxes'     => $this->_default_espresso_metaboxes,
401
+				'require_nonce' => false,
402
+			],
403
+		];
404
+	}
405
+
406
+
407
+	protected function _add_screen_options()
408
+	{
409
+		// todo
410
+	}
411
+
412
+
413
+	protected function _add_screen_options_default()
414
+	{
415
+		$this->_per_page_screen_option();
416
+	}
417
+
418
+
419
+	protected function _add_screen_options_category_list()
420
+	{
421
+		$page_title              = $this->_admin_page_title;
422
+		$this->_admin_page_title = esc_html__('Venue Categories', 'event_espresso');
423
+		$this->_per_page_screen_option();
424
+		$this->_admin_page_title = $page_title;
425
+	}
426
+
427
+
428
+	// none of the below group are currently used for Event Venues
429
+	protected function _add_feature_pointers()
430
+	{
431
+	}
432
+
433
+
434
+	public function admin_init()
435
+	{
436
+	}
437
+
438
+
439
+	public function admin_notices()
440
+	{
441
+	}
442
+
443
+
444
+	public function admin_footer_scripts()
445
+	{
446
+	}
447
+
448
+
449
+	public function load_scripts_styles_create_new()
450
+	{
451
+		$this->load_scripts_styles_edit();
452
+	}
453
+
454
+
455
+	public function load_scripts_styles()
456
+	{
457
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
458
+		wp_enqueue_style('ee-cat-admin');
459
+	}
460
+
461
+
462
+	public function load_scripts_styles_add_category()
463
+	{
464
+		$this->load_scripts_styles_edit_category();
465
+	}
466
+
467
+
468
+	public function load_scripts_styles_edit_category()
469
+	{
470
+	}
471
+
472
+
473
+	public function load_scripts_styles_edit()
474
+	{
475
+		// styles
476
+		wp_enqueue_style('espresso-ui-theme');
477
+		wp_register_style(
478
+			'espresso_venues',
479
+			EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
480
+			[],
481
+			EVENT_ESPRESSO_VERSION
482
+		);
483
+		wp_enqueue_style('espresso_venues');
484
+	}
485
+
486
+
487
+	protected function _set_list_table_views_default()
488
+	{
489
+		$this->_views = [
490
+			'all' => [
491
+				'slug'        => 'all',
492
+				'label'       => esc_html__('View All Venues', 'event_espresso'),
493
+				'count'       => 0,
494
+				'bulk_action' => [],
495
+			],
496
+		];
497
+
498
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
499
+			$this->_views['all']['bulk_action'] = [
500
+				'trash_venues' => esc_html__('Move to Trash', 'event_espresso'),
501
+			];
502
+			$this->_views['trash']              = [
503
+				'slug'        => 'trash',
504
+				'label'       => esc_html__('Trash', 'event_espresso'),
505
+				'count'       => 0,
506
+				'bulk_action' => [
507
+					'restore_venues' => esc_html__('Restore from Trash', 'event_espresso'),
508
+					'delete_venues'  => esc_html__('Delete', 'event_espresso'),
509
+				],
510
+			];
511
+		}
512
+	}
513
+
514
+
515
+	protected function _set_list_table_views_category_list()
516
+	{
517
+		$this->_views = [
518
+			'all' => [
519
+				'slug'        => 'all',
520
+				'label'       => esc_html__('All', 'event_espresso'),
521
+				'count'       => 0,
522
+				'bulk_action' => [
523
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
524
+				],
525
+			],
526
+		];
527
+	}
528
+
529
+
530
+	/**
531
+	 * @throws EE_Error
532
+	 */
533
+	protected function _overview_list_table()
534
+	{
535
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
536
+		$this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
537
+			get_post_type_archive_link('espresso_venues'),
538
+			esc_html__("View Venue Archive Page", "event_espresso"),
539
+			'button'
540
+		);
541
+
542
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
543
+			'create_new',
544
+			'add',
545
+			[],
546
+			'add-new-h2'
547
+		);
548
+
549
+		$this->_search_btn_label  = esc_html__('Venues', 'event_espresso');
550
+		$this->display_admin_list_table_page_with_sidebar();
551
+	}
552
+
553
+
554
+	/**
555
+	 * @throws EE_Error
556
+	 * @throws ReflectionException
557
+	 */
558
+	public function extra_misc_actions_publish_box()
559
+	{
560
+		$extra_rows = [
561
+			'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
562
+			'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
563
+			'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
564
+		];
565
+		$template   = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
566
+		EEH_Template::display_template($template, $extra_rows);
567
+	}
568
+
569
+
570
+	/*************        Google Maps        *************
571 571
      *
572 572
      * @throws EE_Error
573 573
      * @throws EE_Error
574 574
      */
575 575
 
576 576
 
577
-    protected function _google_map_settings()
578
-    {
579
-
580
-
581
-        $this->_template_args['values']           = $this->_yes_no_values;
582
-        $default_map_settings                     = new stdClass();
583
-        $default_map_settings->use_google_maps    = true;
584
-        $default_map_settings->google_map_api_key = '';
585
-        // for event details pages (reg page)
586
-        $default_map_settings->event_details_map_width    = 585;
587
-        // ee_map_width_single
588
-        $default_map_settings->event_details_map_height   = 362;
589
-        // ee_map_height_single
590
-        $default_map_settings->event_details_map_zoom     = 14;
591
-        // ee_map_zoom_single
592
-        $default_map_settings->event_details_display_nav  = true;
593
-        // ee_map_nav_display_single
594
-        $default_map_settings->event_details_nav_size     = false;
595
-        // ee_map_nav_size_single
596
-        $default_map_settings->event_details_control_type = 'default';
597
-        // ee_map_type_control_single
598
-        $default_map_settings->event_details_map_align    = 'center';
599
-        // ee_map_align_single
600
-
601
-        // for event list pages
602
-        $default_map_settings->event_list_map_width    = 300;
603
-        // ee_map_width
604
-        $default_map_settings->event_list_map_height   = 185;
605
-        // ee_map_height
606
-        $default_map_settings->event_list_map_zoom     = 12;
607
-        // ee_map_zoom
608
-        $default_map_settings->event_list_display_nav  = false;
609
-        // ee_map_nav_display
610
-        $default_map_settings->event_list_nav_size     = true;
611
-        // ee_map_nav_size
612
-        $default_map_settings->event_list_control_type = 'dropdown';
613
-        // ee_map_type_control
614
-        $default_map_settings->event_list_map_align    = 'center';
615
-        // ee_map_align
616
-
617
-        $this->_template_args['map_settings'] =
618
-            isset(EE_Registry::instance()->CFG->map_settings)
619
-            && ! empty(EE_Registry::instance()->CFG->map_settings)
620
-                ? (object) array_merge(
621
-                    (array) $default_map_settings,
622
-                    (array) EE_Registry::instance()->CFG->map_settings
623
-                )
624
-                : $default_map_settings;
625
-
626
-        $this->_set_add_edit_form_tags('update_google_map_settings');
627
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
628
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
629
-            EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
630
-            $this->_template_args,
631
-            true
632
-        );
633
-        $this->display_admin_page_with_sidebar();
634
-    }
635
-
636
-
637
-    /**
638
-     * @throws EE_Error
639
-     */
640
-    protected function _update_google_map_settings()
641
-    {
642
-        $map_settings = EE_Registry::instance()->CFG->map_settings;
643
-
644
-        $settings = [
645
-            'use_google_maps'            => 'int',
646
-            'google_map_api_key'         => 'string',
647
-            'event_details_map_width'    => 'int',
648
-            'event_details_map_zoom'     => 'int',
649
-            'event_details_display_nav'  => 'int',
650
-            'event_details_nav_size'     => 'int',
651
-            'event_details_control_type' => 'string',
652
-            'event_details_map_align'    => 'string',
653
-            'event_list_map_width'       => 'int',
654
-            'event_list_map_height'      => 'int',
655
-            'event_list_map_zoom'        => 'int',
656
-            'event_list_display_nav'     => 'int',
657
-            'event_list_nav_size'        => 'int',
658
-            'event_list_control_type'    => 'string',
659
-            'event_list_map_align'       => 'string',
660
-        ];
661
-
662
-        foreach ($settings as $setting => $type) {
663
-            $map_settings->{$setting} = $this->request->getRequestParam($setting, $map_settings->{$setting}, $type);
664
-        }
665
-
666
-        EE_Registry::instance()->CFG->map_settings = apply_filters(
667
-            'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
668
-            $map_settings
669
-        );
670
-
671
-        $what    = 'Google Map Settings';
672
-        $success = $this->_update_espresso_configuration(
673
-            $what,
674
-            EE_Registry::instance()->CFG->map_settings,
675
-            __FILE__,
676
-            __FUNCTION__,
677
-            __LINE__
678
-        );
679
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'google_map_settings']);
680
-    }
681
-
682
-
683
-    /**
684
-     * @throws EE_Error
685
-     * @throws ReflectionException
686
-     */
687
-    protected function _venue_editor_metaboxes()
688
-    {
689
-        $this->verify_cpt_object();
690
-
691
-        add_meta_box(
692
-            'espresso_venue_address_options',
693
-            esc_html__('Physical Location', 'event_espresso'),
694
-            [$this, 'venue_address_metabox'],
695
-            $this->page_slug,
696
-            'side'
697
-        );
698
-        add_meta_box(
699
-            'espresso_venue_gmap_options',
700
-            esc_html__('Google Map', 'event_espresso'),
701
-            [$this, 'venue_gmap_metabox'],
702
-            $this->page_slug,
703
-            'side'
704
-        );
705
-        add_meta_box(
706
-            'espresso_venue_virtual_loc_options',
707
-            esc_html__('Virtual Location', 'event_espresso'),
708
-            [$this, 'venue_virtual_loc_metabox'],
709
-            $this->page_slug,
710
-            'side'
711
-        );
712
-    }
713
-
714
-
715
-    public function venue_gmap_metabox()
716
-    {
717
-        $template_args = [
718
-            'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
719
-                'vnu_enable_for_gmap',
720
-                $this->get_yes_no_values(),
721
-                $this->_cpt_model_obj instanceof EE_Venue ? $this->_cpt_model_obj->enable_for_gmap() : false
722
-            ),
723
-            'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
724
-        ];
725
-        $template      = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
726
-        EEH_Template::display_template($template, $template_args);
727
-    }
728
-
729
-
730
-    /**
731
-     * @throws EE_Error
732
-     * @throws ReflectionException
733
-     */
734
-    public function venue_address_metabox()
735
-    {
736
-        $template_args['_venue'] = $this->_cpt_model_obj;
737
-
738
-        $template_args['states_dropdown']    = EEH_Form_Fields::generate_form_input(
739
-            new EE_Question_Form_Input(
740
-                EE_Question::new_instance(
741
-                    ['QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state']
742
-                ),
743
-                EE_Answer::new_instance(
744
-                    [
745
-                        'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
746
-                            ? $this->_cpt_model_obj->state_ID()
747
-                            : 0,
748
-                    ]
749
-                ),
750
-                [
751
-                    'input_name'     => 'sta_id',
752
-                    'input_id'       => 'sta_id',
753
-                    'input_class'    => '',
754
-                    'input_prefix'   => '',
755
-                    'append_qstn_id' => false,
756
-                ]
757
-            )
758
-        );
759
-        $template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
760
-            new EE_Question_Form_Input(
761
-                EE_Question::new_instance(
762
-                    ['QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country']
763
-                ),
764
-                EE_Answer::new_instance(
765
-                    [
766
-                        'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
767
-                            ? $this->_cpt_model_obj->country_ID()
768
-                            : 0,
769
-                    ]
770
-                ),
771
-                [
772
-                    'input_name'     => 'cnt_iso',
773
-                    'input_id'       => 'cnt_iso',
774
-                    'input_class'    => '',
775
-                    'input_prefix'   => '',
776
-                    'append_qstn_id' => false,
777
-                ]
778
-            )
779
-        );
780
-
781
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
782
-        EEH_Template::display_template($template, $template_args);
783
-    }
784
-
785
-
786
-    public function venue_virtual_loc_metabox()
787
-    {
788
-        $template_args = [
789
-            '_venue' => $this->_cpt_model_obj,
790
-        ];
791
-        $template      = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
792
-        EEH_Template::display_template($template, $template_args);
793
-    }
794
-
795
-
796
-    protected function _restore_cpt_item($post_id, $revision_id)
797
-    {
798
-        $venue_obj = $this->_venue_model->get_one_by_ID($post_id);
799
-
800
-        // meta revision restore
801
-        $venue_obj->restore_revision($revision_id);
802
-    }
803
-
804
-
805
-    /**
806
-     * Handles updates for venue cpts
807
-     *
808
-     * @param int    $post_id ID of Venue CPT
809
-     * @param WP_Post $post    Post object (with "blessed" WP properties)
810
-     * @return void
811
-     */
812
-    protected function _insert_update_cpt_item($post_id, $post)
813
-    {
814
-
815
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
816
-            return;// get out we're not processing the saving of venues.
817
-        }
818
-
819
-        $wheres = [$this->_venue_model->primary_key_name() => $post_id];
820
-
821
-        $venue_values = [
822
-            'VNU_address'         => $this->request->getRequestParam('vnu_address'),
823
-            'VNU_address2'        => $this->request->getRequestParam('vnu_address2'),
824
-            'VNU_city'            => $this->request->getRequestParam('vnu_city'),
825
-            'STA_ID'              => $this->request->getRequestParam('sta_id'),
826
-            'CNT_ISO'             => $this->request->getRequestParam('cnt_iso'),
827
-            'VNU_zip'             => $this->request->getRequestParam('vnu_zip'),
828
-            'VNU_phone'           => $this->request->getRequestParam('vnu_phone'),
829
-            'VNU_capacity'        => $this->request->requestParamIsSet('vnu_capacity')
830
-                ? str_replace(',', '', $this->request->getRequestParam('vnu_capacity'))
831
-                : EE_INF,
832
-            'VNU_url'             => $this->request->getRequestParam('vnu_url'),
833
-            'VNU_virtual_phone'   => $this->request->getRequestParam('vnu_virtual_phone'),
834
-            'VNU_virtual_url'     => $this->request->getRequestParam('vnu_virtual_url'),
835
-            'VNU_enable_for_gmap' => $this->request->getRequestParam('vnu_enable_for_gmap', false, 'bool'),
836
-            'VNU_google_map_link' => $this->request->getRequestParam('vnu_google_map_link'),
837
-        ];
838
-
839
-        // update venue
840
-        $success = $this->_venue_model->update($venue_values, [$wheres]);
841
-
842
-        // get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
843
-        $get_one_where = [$this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status];
844
-        $venue         = $this->_venue_model->get_one([$get_one_where]);
845
-
846
-        // notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use.  So this is just here for addons to more easily hook into venue saves.
847
-        $venue_update_callbacks = apply_filters(
848
-            'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
849
-            []
850
-        );
851
-        $att_success            = true;
852
-        foreach ($venue_update_callbacks as $v_callback) {
853
-            // if ANY of these updates fail then we want the appropriate global error message
854
-            $att_success = call_user_func_array($v_callback, [$venue, $this->request->requestParams()])
855
-                ? $att_success
856
-                : false;
857
-        }
858
-
859
-        // any errors?
860
-        if ($success && ! $att_success) {
861
-            EE_Error::add_error(
862
-                esc_html__(
863
-                    'Venue Details saved successfully but something went wrong with saving attachments.',
864
-                    'event_espresso'
865
-                ),
866
-                __FILE__,
867
-                __FUNCTION__,
868
-                __LINE__
869
-            );
870
-        } elseif ($success === false) {
871
-            EE_Error::add_error(
872
-                esc_html__('Venue Details did not save successfully.', 'event_espresso'),
873
-                __FILE__,
874
-                __FUNCTION__,
875
-                __LINE__
876
-            );
877
-        }
878
-    }
879
-
880
-
881
-    /**
882
-     * @param int $post_id
883
-     * @throws EE_Error
884
-     * @throws ReflectionException
885
-     */
886
-    public function trash_cpt_item($post_id)
887
-    {
888
-        $this->request->setRequestParam('VNU_ID', $post_id);
889
-        $this->_trash_or_restore_venue('trash', false);
890
-    }
891
-
892
-
893
-    /**
894
-     * @param int $post_id
895
-     * @throws EE_Error
896
-     * @throws ReflectionException
897
-     */
898
-    public function restore_cpt_item($post_id)
899
-    {
900
-        $this->request->setRequestParam('VNU_ID', $post_id);
901
-        $this->_trash_or_restore_venue('draft', false);
902
-    }
903
-
904
-
905
-    /**
906
-     * @param int $post_id
907
-     * @throws EE_Error
908
-     * @throws ReflectionException
909
-     */
910
-    public function delete_cpt_item($post_id)
911
-    {
912
-        $this->request->setRequestParam('VNU_ID', $post_id);
913
-        $this->_delete_venue(false);
914
-    }
915
-
916
-
917
-    public function get_venue_object()
918
-    {
919
-        return $this->_cpt_model_obj;
920
-    }
921
-
922
-
923
-    /**
924
-     * @throws EE_Error
925
-     * @throws ReflectionException
926
-     */
927
-    protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
928
-    {
929
-        $VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
930
-
931
-        // loop thru venues
932
-        if ($VNU_ID) {
933
-            // clean status
934
-            $venue_status = sanitize_key($venue_status);
935
-            // grab status
936
-            if (! empty($venue_status)) {
937
-                $success = $this->_change_venue_status($VNU_ID, $venue_status);
938
-            } else {
939
-                $success = false;
940
-                $msg     = esc_html__(
941
-                    'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
942
-                    'event_espresso'
943
-                );
944
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
945
-            }
946
-        } else {
947
-            $success = false;
948
-            $msg     = esc_html__(
949
-                'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
950
-                'event_espresso'
951
-            );
952
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
953
-        }
954
-        $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
955
-
956
-        if ($redirect_after) {
957
-            $this->_redirect_after_action($success, 'Venue', $action, ['action' => 'default']);
958
-        }
959
-    }
960
-
961
-
962
-    /**
963
-     * @throws EE_Error
964
-     * @throws ReflectionException
965
-     */
966
-    protected function _trash_or_restore_venues($venue_status = 'trash')
967
-    {
968
-        // clean status
969
-        $venue_status = sanitize_key($venue_status);
970
-        // grab status
971
-        if (! empty($venue_status)) {
972
-            $success = true;
973
-            // determine the event id and set to array.
974
-            $VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
975
-            // loop thru events
976
-            foreach ($VNU_IDs as $VNU_ID) {
977
-                if ($VNU_ID = absint($VNU_ID)) {
978
-                    $results = $this->_change_venue_status($VNU_ID, $venue_status);
979
-                    $success = $results !== false ? $success : false;
980
-                } else {
981
-                    $msg = sprintf(
982
-                        esc_html__(
983
-                            'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
984
-                            'event_espresso'
985
-                        ),
986
-                        $VNU_ID
987
-                    );
988
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
989
-                    $success = false;
990
-                }
991
-            }
992
-        } else {
993
-            $success = false;
994
-            $msg     = esc_html__(
995
-                'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
996
-                'event_espresso'
997
-            );
998
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
999
-        }
1000
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1001
-        $success = $success ? 2 : false;
1002
-        $action  = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1003
-        $this->_redirect_after_action($success, 'Venues', $action, ['action' => 'default']);
1004
-    }
1005
-
1006
-
1007
-    /**
1008
-     * _trash_or_restore_venues
1009
-     *
1010
-     * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1011
-     * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1012
-     * accepting a certain number of params.
1013
-     *
1014
-     * @access  private
1015
-     * @param int    $VNU_ID
1016
-     * @param string $venue_status
1017
-     * @return bool
1018
-     * @throws EE_Error
1019
-     * @throws ReflectionException
1020
-     */
1021
-    private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1022
-    {
1023
-        // grab venue id
1024
-        if (! $VNU_ID) {
1025
-            $msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1026
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1027
-            return false;
1028
-        }
1029
-
1030
-        $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1031
-
1032
-        // clean status
1033
-        $venue_status = sanitize_key($venue_status);
1034
-        // grab status
1035
-        if (! $venue_status) {
1036
-            $msg = esc_html__(
1037
-                'An error occurred. No Venue Status or an invalid Venue Status was received.',
1038
-                'event_espresso'
1039
-            );
1040
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1041
-            return false;
1042
-        }
1043
-
1044
-        // was event trashed or restored ?
1045
-        switch ($venue_status) {
1046
-            case 'draft':
1047
-                $action = 'restored from the trash';
1048
-                $hook   = 'AHEE_venue_restored_from_trash';
1049
-                break;
1050
-            case 'trash':
1051
-                $action = 'moved to the trash';
1052
-                $hook   = 'AHEE_venue_moved_to_trash';
1053
-                break;
1054
-            default:
1055
-                $action = 'updated';
1056
-                $hook   = false;
1057
-        }
1058
-        // use class to change status
1059
-        $this->_cpt_model_obj->set_status($venue_status);
1060
-        $success = $this->_cpt_model_obj->save();
1061
-
1062
-        if ($success === false) {
1063
-            $msg = sprintf(esc_html__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1064
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1065
-            return false;
1066
-        }
1067
-        if ($hook) {
1068
-            do_action($hook);
1069
-        }
1070
-        return true;
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     * @param bool $redirect_after
1076
-     * @return void
1077
-     * @throws EE_Error
1078
-     * @throws ReflectionException
1079
-     */
1080
-    protected function _delete_venue($redirect_after = true)
1081
-    {
1082
-        // determine the venue id and set to array.
1083
-        $VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
1084
-        $VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
1085
-
1086
-        // loop thru venues
1087
-        if ($VNU_ID) {
1088
-            $success = $this->_delete_or_trash_venue($VNU_ID);
1089
-        } else {
1090
-            $success = false;
1091
-            $msg     = esc_html__(
1092
-                'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1093
-                'event_espresso'
1094
-            );
1095
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1096
-        }
1097
-        if ($redirect_after) {
1098
-            $this->_redirect_after_action($success, 'Venue', 'deleted', ['action' => 'default']);
1099
-        }
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * @throws EE_Error
1105
-     * @throws ReflectionException
1106
-     */
1107
-    protected function _delete_venues()
1108
-    {
1109
-        $success = true;
1110
-        // determine the event id and set to array.
1111
-        $VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
1112
-        // loop thru events
1113
-        foreach ($VNU_IDs as $VNU_ID) {
1114
-            if ($VNU_ID = absint($VNU_ID)) {
1115
-                $results = $this->_delete_or_trash_venue($VNU_ID);
1116
-                $success = $results !== false ? $success : false;
1117
-            } else {
1118
-                $success = false;
1119
-                $msg     = esc_html__(
1120
-                    'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1121
-                    'event_espresso'
1122
-                );
1123
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1124
-            }
1125
-        }
1126
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1127
-        $success = $success ? 2 : false;
1128
-        $this->_redirect_after_action(
1129
-            $success,
1130
-            esc_html__('Venues', 'event_espresso'),
1131
-            esc_html__('deleted', 'event_espresso'),
1132
-            ['action' => 'default']
1133
-        );
1134
-    }
1135
-
1136
-
1137
-    // todo: put in parent
1138
-
1139
-
1140
-    /**
1141
-     * @throws EE_Error
1142
-     * @throws ReflectionException
1143
-     */
1144
-    private function _delete_or_trash_venue($VNU_ID = false)
1145
-    {
1146
-        // grab event id
1147
-        if (! $VNU_ID = absint($VNU_ID)) {
1148
-            $msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1149
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1150
-            return false;
1151
-        }
1152
-
1153
-
1154
-        $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1155
-        // first need to remove all term relationships
1156
-        $venue->_remove_relations('Term_Taxonomy');
1157
-        $success = $venue->delete_permanently();
1158
-        // did it all go as planned ?
1159
-        if ($success) {
1160
-            $msg = sprintf(esc_html__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1161
-            EE_Error::add_success($msg);
1162
-        } else {
1163
-            $msg =
1164
-                sprintf(
1165
-                    esc_html__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'),
1166
-                    $VNU_ID
1167
-                );
1168
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1169
-            return false;
1170
-        }
1171
-        do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1172
-        return true;
1173
-    }
1174
-
1175
-
1176
-
1177
-
1178
-    /***********/
1179
-    /* QUERIES */
1180
-
1181
-
1182
-    public function get_venues($per_page = 10, $count = false)
1183
-    {
1184
-
1185
-        $orderby = $this->request->getRequestParam('orderby', '');
1186
-
1187
-        switch ($orderby) {
1188
-            case 'id':
1189
-                $orderby = 'VNU_ID';
1190
-                break;
1191
-
1192
-            case 'capacity':
1193
-                $orderby = 'VNU_capacity';
1194
-                break;
1195
-
1196
-            case 'city':
1197
-                $orderby = 'VNU_city';
1198
-                break;
1199
-
1200
-            default:
1201
-                $orderby = 'VNU_name';
1202
-        }
1203
-
1204
-        $sort         = $this->request->getRequestParam('order', 'ASC');
1205
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1206
-        $per_page     = ! empty($per_page) ? $per_page : 10;
1207
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1208
-
1209
-        $offset = ($current_page - 1) * $per_page;
1210
-        $limit  = [$offset, $per_page];
1211
-
1212
-        $category = $this->request->getRequestParam('category');
1213
-        $category = $category > 0 ? $category : null;
1214
-
1215
-        $where = [];
1216
-
1217
-        // only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1218
-        $status = $this->request->getRequestParam('status');
1219
-        if ($status && $status !== 'all') {
1220
-            $where['status'] = $status;
1221
-        }
1222
-
1223
-        $venue_status = $this->request->getRequestParam('venue_status');
1224
-        if ($venue_status) {
1225
-            $where['status'] = $venue_status;
1226
-        }
1227
-
1228
-
1229
-        if ($category) {
1230
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1231
-            $where['Term_Taxonomy.term_id']  = $category;
1232
-        }
1233
-
1234
-
1235
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1236
-            $where['VNU_wp_user'] = get_current_user_id();
1237
-        } else {
1238
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1239
-                $where['OR'] = [
1240
-                    'status*restrict_private' => ['!=', 'private'],
1241
-                    'AND'                     => [
1242
-                        'status*inclusive' => ['=', 'private'],
1243
-                        'VNU_wp_user'      => get_current_user_id(),
1244
-                    ],
1245
-                ];
1246
-            }
1247
-        }
1248
-
1249
-        $search_term = $this->request->getRequestParam('s');
1250
-        if ($search_term) {
1251
-            $search_term = '%' . $search_term . '%';
1252
-            $where['OR'] = [
1253
-                'VNU_name'               => ['LIKE', $search_term],
1254
-                'VNU_desc'               => ['LIKE', $search_term],
1255
-                'VNU_short_desc'         => ['LIKE', $search_term],
1256
-                'VNU_address'            => ['LIKE', $search_term],
1257
-                'VNU_address2'           => ['LIKE', $search_term],
1258
-                'VNU_city'               => ['LIKE', $search_term],
1259
-                'VNU_zip'                => ['LIKE', $search_term],
1260
-                'VNU_phone'              => ['LIKE', $search_term],
1261
-                'VNU_url'                => ['LIKE', $search_term],
1262
-                'VNU_virtual_phone'      => ['LIKE', $search_term],
1263
-                'VNU_virtual_url'        => ['LIKE', $search_term],
1264
-                'VNU_google_map_link'    => ['LIKE', $search_term],
1265
-                'Event.EVT_name'         => ['LIKE', $search_term],
1266
-                'Event.EVT_desc'         => ['LIKE', $search_term],
1267
-                'Event.EVT_phone'        => ['LIKE', $search_term],
1268
-                'Event.EVT_external_URL' => ['LIKE', $search_term],
1269
-            ];
1270
-        }
1271
-
1272
-
1273
-        return $count
1274
-            ? $this->_venue_model->count([$where], 'VNU_ID')
1275
-            : $this->_venue_model->get_all(
1276
-                [$where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort]
1277
-            );
1278
-    }
1279
-
1280
-
1281
-
1282
-
1283
-    /** Venue Category Stuff **/
1284
-
1285
-    /**
1286
-     * set the _category property with the category object for the loaded page.
1287
-     *
1288
-     * @access private
1289
-     * @return void
1290
-     */
1291
-    private function _set_category_object()
1292
-    {
1293
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
1294
-            return;
1295
-        } // already have the category object so get out.
1296
-
1297
-        // set default category object
1298
-        $this->_set_empty_category_object();
1299
-
1300
-        // only set if we've got an id
1301
-        $category_ID = $this->request->getRequestParam('VEN_CAT_ID', 0, 'int');
1302
-        if (! $category_ID) {
1303
-            return;
1304
-        }
1305
-
1306
-        $term = get_term($category_ID, 'espresso_venue_categories');
1307
-
1308
-
1309
-        if (! empty($term)) {
1310
-            $this->_category->category_name       = $term->name;
1311
-            $this->_category->category_identifier = $term->slug;
1312
-            $this->_category->category_desc       = $term->description;
1313
-            $this->_category->id                  = $term->term_id;
1314
-            $this->_category->parent              = $term->parent;
1315
-        }
1316
-    }
1317
-
1318
-
1319
-    private function _set_empty_category_object()
1320
-    {
1321
-        $this->_category                = new stdClass();
1322
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1323
-        $this->_category->id            = $this->_category->parent = 0;
1324
-    }
1325
-
1326
-
1327
-    /**
1328
-     * @throws EE_Error
1329
-     */
1330
-    protected function _category_list_table()
1331
-    {
1332
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1333
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1334
-            'add_category',
1335
-            'add_category',
1336
-            [],
1337
-            'add-new-h2'
1338
-        );
1339
-        $this->_search_btn_label = esc_html__('Venue Categories', 'event_espresso');
1340
-        $this->display_admin_list_table_page_with_sidebar();
1341
-    }
1342
-
1343
-
1344
-    /**
1345
-     * @throws EE_Error
1346
-     */
1347
-    protected function _category_details($view)
1348
-    {
1349
-
1350
-        // load formatter helper
1351
-        // load field generator helper
1352
-
1353
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
1354
-        $this->_set_add_edit_form_tags($route);
1355
-
1356
-        $this->_set_category_object();
1357
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
1358
-
1359
-        $delete_action = 'delete_category';
1360
-
1361
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(['action' => 'category_list'], $this->_admin_base_url);
1362
-
1363
-        $this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1364
-
1365
-        // take care of contents
1366
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
1367
-        $this->display_admin_page_with_sidebar();
1368
-    }
1369
-
1370
-
1371
-    protected function _category_details_content()
1372
-    {
1373
-        $editor_args['category_desc'] = [
1374
-            'type'          => 'wp_editor',
1375
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1376
-            'class'         => 'my_editor_custom',
1377
-            'wpeditor_args' => ['media_buttons' => false],
1378
-        ];
1379
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
1380
-
1381
-        $all_terms = get_terms(
1382
-            ['espresso_venue_categories'],
1383
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
1384
-        );
1385
-
1386
-        // setup category select for term parents.
1387
-        $category_select_values[] = [
1388
-            'text' => esc_html__('No Parent', 'event_espresso'),
1389
-            'id'   => 0,
1390
-        ];
1391
-        foreach ($all_terms as $term) {
1392
-            $category_select_values[] = [
1393
-                'text' => $term->name,
1394
-                'id'   => $term->term_id,
1395
-            ];
1396
-        }
1397
-
1398
-        $category_select = EEH_Form_Fields::select_input(
1399
-            'category_parent',
1400
-            $category_select_values,
1401
-            $this->_category->parent
1402
-        );
1403
-        $template_args   = [
1404
-            'category'                 => $this->_category,
1405
-            'category_select'          => $category_select,
1406
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1407
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1408
-            'disable'                  => '',
1409
-            'disabled_message'         => false,
1410
-        ];
1411
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1412
-        return EEH_Template::display_template($template, $template_args, true);
1413
-    }
1414
-
1415
-
1416
-    /**
1417
-     * @throws EE_Error
1418
-     */
1419
-    protected function _delete_categories()
1420
-    {
1421
-        $category_ID  = $this->request->getRequestParam('category_id', 0, 'int');
1422
-        $category_IDs = $this->request->getRequestParam('VEN_CAT_ID', [$category_ID], 'int', true);
1423
-
1424
-        foreach ($category_IDs as $cat_id) {
1425
-            $this->_delete_category($cat_id);
1426
-        }
1427
-
1428
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
1429
-        $query_args = [
1430
-            'action' => 'category_list',
1431
-        ];
1432
-        $this->_redirect_after_action(0, '', '', $query_args);
1433
-    }
1434
-
1435
-
1436
-    protected function _delete_category($cat_id)
1437
-    {
1438
-        $cat_id = absint($cat_id);
1439
-        wp_delete_term($cat_id, 'espresso_venue_categories');
1440
-    }
1441
-
1442
-
1443
-    /**
1444
-     * @throws EE_Error
1445
-     */
1446
-    protected function _insert_or_update_category($new_category)
1447
-    {
1448
-
1449
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1450
-        $success = 0; // we already have a success message so lets not send another.
1451
-        if ($cat_id) {
1452
-            $query_args = [
1453
-                'action'     => 'edit_category',
1454
-                'VEN_CAT_ID' => $cat_id,
1455
-            ];
1456
-        } else {
1457
-            $query_args = ['action' => 'add_category'];
1458
-        }
1459
-        $this->_redirect_after_action($success, '', '', $query_args, true);
1460
-    }
1461
-
1462
-
1463
-    private function _insert_category($update = false)
1464
-    {
1465
-        $category_ID     = $update ? $this->request->getRequestParam('VEN_CAT_ID', '', 'int') : '';
1466
-        $category_name   = $this->request->getRequestParam('category_name', '');
1467
-        $category_desc   = $this->request->getRequestParam('category_desc', '', 'html');
1468
-        $category_parent = $this->request->getRequestParam('category_parent', 0, 'int');
1469
-
1470
-        if (empty($category_name)) {
1471
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
1472
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1473
-            return false;
1474
-        }
1475
-
1476
-
1477
-        $term_args = [
1478
-            'name'        => $category_name,
1479
-            'description' => $category_desc,
1480
-            'parent'      => $category_parent,
1481
-        ];
1482
-
1483
-        $insert_ids = $update
1484
-            ? wp_update_term($category_ID, 'espresso_venue_categories', $term_args)
1485
-            : wp_insert_term(
1486
-                $category_name,
1487
-                'espresso_venue_categories',
1488
-                $term_args
1489
-            );
1490
-
1491
-        if (! is_array($insert_ids)) {
1492
-            EE_Error::add_error(
1493
-                esc_html__('An error occurred and the category has not been saved to the database.', 'event_espresso'),
1494
-                __FILE__,
1495
-                __FUNCTION__,
1496
-                __LINE__
1497
-            );
1498
-        } else {
1499
-            $category_ID = $insert_ids['term_id'];
1500
-            EE_Error::add_success(
1501
-                sprintf(
1502
-                    esc_html__('The category %s was successfully created', 'event_espresso'),
1503
-                    $category_name
1504
-                )
1505
-            );
1506
-        }
1507
-
1508
-        return $category_ID;
1509
-    }
1510
-
1511
-
1512
-    /**
1513
-     * TODO handle category exports()
1514
-     *
1515
-     * @return void
1516
-     */
1517
-    protected function _categories_export()
1518
-    {
1519
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
1520
-        $this->request->mergeRequestParams(
1521
-            [
1522
-                'export'       => 'report',
1523
-                'action'       => 'categories',
1524
-                'category_ids' => $this->request->getRequestParam('VEN_CAT_ID', 0, 'int'),
1525
-            ]
1526
-        );
1527
-
1528
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1529
-            require_once(EE_CLASSES . 'EE_Export.class.php');
1530
-            $EE_Export = EE_Export::instance($this->request->requestParams());
1531
-            $EE_Export->export();
1532
-        }
1533
-    }
1534
-
1535
-
1536
-    protected function _import_categories()
1537
-    {
1538
-
1539
-        require_once(EE_CLASSES . 'EE_Import.class.php');
1540
-        EE_Import::instance()->import();
1541
-    }
1542
-
1543
-
1544
-    /**
1545
-     * @throws EE_Error
1546
-     */
1547
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
1548
-    {
1549
-
1550
-        // testing term stuff
1551
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
1552
-        $order       = $this->request->getRequestParam('order', 'DESC');
1553
-        $limit       = ($current_page - 1) * $per_page;
1554
-        $where       = ['taxonomy' => 'espresso_venue_categories'];
1555
-        $search_term = $this->request->getRequestParam('s');
1556
-        if ($search_term) {
1557
-            $search_term = '%' . $search_term . '%';
1558
-            $where['OR'] = [
1559
-                'Term.name'   => ['LIKE', $search_term],
1560
-                'description' => ['LIKE', $search_term],
1561
-            ];
1562
-        }
1563
-
1564
-        $query_params = [
1565
-            $where,
1566
-            'order_by'   => [$orderby => $order],
1567
-            'limit'      => $limit . ',' . $per_page,
1568
-            'force_join' => ['Term'],
1569
-        ];
1570
-
1571
-        return $count
1572
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1573
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
1574
-    }
1575
-
1576
-
1577
-    /* end category stuff */
1578
-    /**************/
577
+	protected function _google_map_settings()
578
+	{
579
+
580
+
581
+		$this->_template_args['values']           = $this->_yes_no_values;
582
+		$default_map_settings                     = new stdClass();
583
+		$default_map_settings->use_google_maps    = true;
584
+		$default_map_settings->google_map_api_key = '';
585
+		// for event details pages (reg page)
586
+		$default_map_settings->event_details_map_width    = 585;
587
+		// ee_map_width_single
588
+		$default_map_settings->event_details_map_height   = 362;
589
+		// ee_map_height_single
590
+		$default_map_settings->event_details_map_zoom     = 14;
591
+		// ee_map_zoom_single
592
+		$default_map_settings->event_details_display_nav  = true;
593
+		// ee_map_nav_display_single
594
+		$default_map_settings->event_details_nav_size     = false;
595
+		// ee_map_nav_size_single
596
+		$default_map_settings->event_details_control_type = 'default';
597
+		// ee_map_type_control_single
598
+		$default_map_settings->event_details_map_align    = 'center';
599
+		// ee_map_align_single
600
+
601
+		// for event list pages
602
+		$default_map_settings->event_list_map_width    = 300;
603
+		// ee_map_width
604
+		$default_map_settings->event_list_map_height   = 185;
605
+		// ee_map_height
606
+		$default_map_settings->event_list_map_zoom     = 12;
607
+		// ee_map_zoom
608
+		$default_map_settings->event_list_display_nav  = false;
609
+		// ee_map_nav_display
610
+		$default_map_settings->event_list_nav_size     = true;
611
+		// ee_map_nav_size
612
+		$default_map_settings->event_list_control_type = 'dropdown';
613
+		// ee_map_type_control
614
+		$default_map_settings->event_list_map_align    = 'center';
615
+		// ee_map_align
616
+
617
+		$this->_template_args['map_settings'] =
618
+			isset(EE_Registry::instance()->CFG->map_settings)
619
+			&& ! empty(EE_Registry::instance()->CFG->map_settings)
620
+				? (object) array_merge(
621
+					(array) $default_map_settings,
622
+					(array) EE_Registry::instance()->CFG->map_settings
623
+				)
624
+				: $default_map_settings;
625
+
626
+		$this->_set_add_edit_form_tags('update_google_map_settings');
627
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
628
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
629
+			EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
630
+			$this->_template_args,
631
+			true
632
+		);
633
+		$this->display_admin_page_with_sidebar();
634
+	}
635
+
636
+
637
+	/**
638
+	 * @throws EE_Error
639
+	 */
640
+	protected function _update_google_map_settings()
641
+	{
642
+		$map_settings = EE_Registry::instance()->CFG->map_settings;
643
+
644
+		$settings = [
645
+			'use_google_maps'            => 'int',
646
+			'google_map_api_key'         => 'string',
647
+			'event_details_map_width'    => 'int',
648
+			'event_details_map_zoom'     => 'int',
649
+			'event_details_display_nav'  => 'int',
650
+			'event_details_nav_size'     => 'int',
651
+			'event_details_control_type' => 'string',
652
+			'event_details_map_align'    => 'string',
653
+			'event_list_map_width'       => 'int',
654
+			'event_list_map_height'      => 'int',
655
+			'event_list_map_zoom'        => 'int',
656
+			'event_list_display_nav'     => 'int',
657
+			'event_list_nav_size'        => 'int',
658
+			'event_list_control_type'    => 'string',
659
+			'event_list_map_align'       => 'string',
660
+		];
661
+
662
+		foreach ($settings as $setting => $type) {
663
+			$map_settings->{$setting} = $this->request->getRequestParam($setting, $map_settings->{$setting}, $type);
664
+		}
665
+
666
+		EE_Registry::instance()->CFG->map_settings = apply_filters(
667
+			'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
668
+			$map_settings
669
+		);
670
+
671
+		$what    = 'Google Map Settings';
672
+		$success = $this->_update_espresso_configuration(
673
+			$what,
674
+			EE_Registry::instance()->CFG->map_settings,
675
+			__FILE__,
676
+			__FUNCTION__,
677
+			__LINE__
678
+		);
679
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'google_map_settings']);
680
+	}
681
+
682
+
683
+	/**
684
+	 * @throws EE_Error
685
+	 * @throws ReflectionException
686
+	 */
687
+	protected function _venue_editor_metaboxes()
688
+	{
689
+		$this->verify_cpt_object();
690
+
691
+		add_meta_box(
692
+			'espresso_venue_address_options',
693
+			esc_html__('Physical Location', 'event_espresso'),
694
+			[$this, 'venue_address_metabox'],
695
+			$this->page_slug,
696
+			'side'
697
+		);
698
+		add_meta_box(
699
+			'espresso_venue_gmap_options',
700
+			esc_html__('Google Map', 'event_espresso'),
701
+			[$this, 'venue_gmap_metabox'],
702
+			$this->page_slug,
703
+			'side'
704
+		);
705
+		add_meta_box(
706
+			'espresso_venue_virtual_loc_options',
707
+			esc_html__('Virtual Location', 'event_espresso'),
708
+			[$this, 'venue_virtual_loc_metabox'],
709
+			$this->page_slug,
710
+			'side'
711
+		);
712
+	}
713
+
714
+
715
+	public function venue_gmap_metabox()
716
+	{
717
+		$template_args = [
718
+			'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
719
+				'vnu_enable_for_gmap',
720
+				$this->get_yes_no_values(),
721
+				$this->_cpt_model_obj instanceof EE_Venue ? $this->_cpt_model_obj->enable_for_gmap() : false
722
+			),
723
+			'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
724
+		];
725
+		$template      = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
726
+		EEH_Template::display_template($template, $template_args);
727
+	}
728
+
729
+
730
+	/**
731
+	 * @throws EE_Error
732
+	 * @throws ReflectionException
733
+	 */
734
+	public function venue_address_metabox()
735
+	{
736
+		$template_args['_venue'] = $this->_cpt_model_obj;
737
+
738
+		$template_args['states_dropdown']    = EEH_Form_Fields::generate_form_input(
739
+			new EE_Question_Form_Input(
740
+				EE_Question::new_instance(
741
+					['QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state']
742
+				),
743
+				EE_Answer::new_instance(
744
+					[
745
+						'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
746
+							? $this->_cpt_model_obj->state_ID()
747
+							: 0,
748
+					]
749
+				),
750
+				[
751
+					'input_name'     => 'sta_id',
752
+					'input_id'       => 'sta_id',
753
+					'input_class'    => '',
754
+					'input_prefix'   => '',
755
+					'append_qstn_id' => false,
756
+				]
757
+			)
758
+		);
759
+		$template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
760
+			new EE_Question_Form_Input(
761
+				EE_Question::new_instance(
762
+					['QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country']
763
+				),
764
+				EE_Answer::new_instance(
765
+					[
766
+						'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
767
+							? $this->_cpt_model_obj->country_ID()
768
+							: 0,
769
+					]
770
+				),
771
+				[
772
+					'input_name'     => 'cnt_iso',
773
+					'input_id'       => 'cnt_iso',
774
+					'input_class'    => '',
775
+					'input_prefix'   => '',
776
+					'append_qstn_id' => false,
777
+				]
778
+			)
779
+		);
780
+
781
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
782
+		EEH_Template::display_template($template, $template_args);
783
+	}
784
+
785
+
786
+	public function venue_virtual_loc_metabox()
787
+	{
788
+		$template_args = [
789
+			'_venue' => $this->_cpt_model_obj,
790
+		];
791
+		$template      = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
792
+		EEH_Template::display_template($template, $template_args);
793
+	}
794
+
795
+
796
+	protected function _restore_cpt_item($post_id, $revision_id)
797
+	{
798
+		$venue_obj = $this->_venue_model->get_one_by_ID($post_id);
799
+
800
+		// meta revision restore
801
+		$venue_obj->restore_revision($revision_id);
802
+	}
803
+
804
+
805
+	/**
806
+	 * Handles updates for venue cpts
807
+	 *
808
+	 * @param int    $post_id ID of Venue CPT
809
+	 * @param WP_Post $post    Post object (with "blessed" WP properties)
810
+	 * @return void
811
+	 */
812
+	protected function _insert_update_cpt_item($post_id, $post)
813
+	{
814
+
815
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
816
+			return;// get out we're not processing the saving of venues.
817
+		}
818
+
819
+		$wheres = [$this->_venue_model->primary_key_name() => $post_id];
820
+
821
+		$venue_values = [
822
+			'VNU_address'         => $this->request->getRequestParam('vnu_address'),
823
+			'VNU_address2'        => $this->request->getRequestParam('vnu_address2'),
824
+			'VNU_city'            => $this->request->getRequestParam('vnu_city'),
825
+			'STA_ID'              => $this->request->getRequestParam('sta_id'),
826
+			'CNT_ISO'             => $this->request->getRequestParam('cnt_iso'),
827
+			'VNU_zip'             => $this->request->getRequestParam('vnu_zip'),
828
+			'VNU_phone'           => $this->request->getRequestParam('vnu_phone'),
829
+			'VNU_capacity'        => $this->request->requestParamIsSet('vnu_capacity')
830
+				? str_replace(',', '', $this->request->getRequestParam('vnu_capacity'))
831
+				: EE_INF,
832
+			'VNU_url'             => $this->request->getRequestParam('vnu_url'),
833
+			'VNU_virtual_phone'   => $this->request->getRequestParam('vnu_virtual_phone'),
834
+			'VNU_virtual_url'     => $this->request->getRequestParam('vnu_virtual_url'),
835
+			'VNU_enable_for_gmap' => $this->request->getRequestParam('vnu_enable_for_gmap', false, 'bool'),
836
+			'VNU_google_map_link' => $this->request->getRequestParam('vnu_google_map_link'),
837
+		];
838
+
839
+		// update venue
840
+		$success = $this->_venue_model->update($venue_values, [$wheres]);
841
+
842
+		// get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
843
+		$get_one_where = [$this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status];
844
+		$venue         = $this->_venue_model->get_one([$get_one_where]);
845
+
846
+		// notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use.  So this is just here for addons to more easily hook into venue saves.
847
+		$venue_update_callbacks = apply_filters(
848
+			'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
849
+			[]
850
+		);
851
+		$att_success            = true;
852
+		foreach ($venue_update_callbacks as $v_callback) {
853
+			// if ANY of these updates fail then we want the appropriate global error message
854
+			$att_success = call_user_func_array($v_callback, [$venue, $this->request->requestParams()])
855
+				? $att_success
856
+				: false;
857
+		}
858
+
859
+		// any errors?
860
+		if ($success && ! $att_success) {
861
+			EE_Error::add_error(
862
+				esc_html__(
863
+					'Venue Details saved successfully but something went wrong with saving attachments.',
864
+					'event_espresso'
865
+				),
866
+				__FILE__,
867
+				__FUNCTION__,
868
+				__LINE__
869
+			);
870
+		} elseif ($success === false) {
871
+			EE_Error::add_error(
872
+				esc_html__('Venue Details did not save successfully.', 'event_espresso'),
873
+				__FILE__,
874
+				__FUNCTION__,
875
+				__LINE__
876
+			);
877
+		}
878
+	}
879
+
880
+
881
+	/**
882
+	 * @param int $post_id
883
+	 * @throws EE_Error
884
+	 * @throws ReflectionException
885
+	 */
886
+	public function trash_cpt_item($post_id)
887
+	{
888
+		$this->request->setRequestParam('VNU_ID', $post_id);
889
+		$this->_trash_or_restore_venue('trash', false);
890
+	}
891
+
892
+
893
+	/**
894
+	 * @param int $post_id
895
+	 * @throws EE_Error
896
+	 * @throws ReflectionException
897
+	 */
898
+	public function restore_cpt_item($post_id)
899
+	{
900
+		$this->request->setRequestParam('VNU_ID', $post_id);
901
+		$this->_trash_or_restore_venue('draft', false);
902
+	}
903
+
904
+
905
+	/**
906
+	 * @param int $post_id
907
+	 * @throws EE_Error
908
+	 * @throws ReflectionException
909
+	 */
910
+	public function delete_cpt_item($post_id)
911
+	{
912
+		$this->request->setRequestParam('VNU_ID', $post_id);
913
+		$this->_delete_venue(false);
914
+	}
915
+
916
+
917
+	public function get_venue_object()
918
+	{
919
+		return $this->_cpt_model_obj;
920
+	}
921
+
922
+
923
+	/**
924
+	 * @throws EE_Error
925
+	 * @throws ReflectionException
926
+	 */
927
+	protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
928
+	{
929
+		$VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
930
+
931
+		// loop thru venues
932
+		if ($VNU_ID) {
933
+			// clean status
934
+			$venue_status = sanitize_key($venue_status);
935
+			// grab status
936
+			if (! empty($venue_status)) {
937
+				$success = $this->_change_venue_status($VNU_ID, $venue_status);
938
+			} else {
939
+				$success = false;
940
+				$msg     = esc_html__(
941
+					'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
942
+					'event_espresso'
943
+				);
944
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
945
+			}
946
+		} else {
947
+			$success = false;
948
+			$msg     = esc_html__(
949
+				'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
950
+				'event_espresso'
951
+			);
952
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
953
+		}
954
+		$action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
955
+
956
+		if ($redirect_after) {
957
+			$this->_redirect_after_action($success, 'Venue', $action, ['action' => 'default']);
958
+		}
959
+	}
960
+
961
+
962
+	/**
963
+	 * @throws EE_Error
964
+	 * @throws ReflectionException
965
+	 */
966
+	protected function _trash_or_restore_venues($venue_status = 'trash')
967
+	{
968
+		// clean status
969
+		$venue_status = sanitize_key($venue_status);
970
+		// grab status
971
+		if (! empty($venue_status)) {
972
+			$success = true;
973
+			// determine the event id and set to array.
974
+			$VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
975
+			// loop thru events
976
+			foreach ($VNU_IDs as $VNU_ID) {
977
+				if ($VNU_ID = absint($VNU_ID)) {
978
+					$results = $this->_change_venue_status($VNU_ID, $venue_status);
979
+					$success = $results !== false ? $success : false;
980
+				} else {
981
+					$msg = sprintf(
982
+						esc_html__(
983
+							'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
984
+							'event_espresso'
985
+						),
986
+						$VNU_ID
987
+					);
988
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
989
+					$success = false;
990
+				}
991
+			}
992
+		} else {
993
+			$success = false;
994
+			$msg     = esc_html__(
995
+				'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
996
+				'event_espresso'
997
+			);
998
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
999
+		}
1000
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1001
+		$success = $success ? 2 : false;
1002
+		$action  = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1003
+		$this->_redirect_after_action($success, 'Venues', $action, ['action' => 'default']);
1004
+	}
1005
+
1006
+
1007
+	/**
1008
+	 * _trash_or_restore_venues
1009
+	 *
1010
+	 * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1011
+	 * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1012
+	 * accepting a certain number of params.
1013
+	 *
1014
+	 * @access  private
1015
+	 * @param int    $VNU_ID
1016
+	 * @param string $venue_status
1017
+	 * @return bool
1018
+	 * @throws EE_Error
1019
+	 * @throws ReflectionException
1020
+	 */
1021
+	private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1022
+	{
1023
+		// grab venue id
1024
+		if (! $VNU_ID) {
1025
+			$msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1026
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1027
+			return false;
1028
+		}
1029
+
1030
+		$this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1031
+
1032
+		// clean status
1033
+		$venue_status = sanitize_key($venue_status);
1034
+		// grab status
1035
+		if (! $venue_status) {
1036
+			$msg = esc_html__(
1037
+				'An error occurred. No Venue Status or an invalid Venue Status was received.',
1038
+				'event_espresso'
1039
+			);
1040
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1041
+			return false;
1042
+		}
1043
+
1044
+		// was event trashed or restored ?
1045
+		switch ($venue_status) {
1046
+			case 'draft':
1047
+				$action = 'restored from the trash';
1048
+				$hook   = 'AHEE_venue_restored_from_trash';
1049
+				break;
1050
+			case 'trash':
1051
+				$action = 'moved to the trash';
1052
+				$hook   = 'AHEE_venue_moved_to_trash';
1053
+				break;
1054
+			default:
1055
+				$action = 'updated';
1056
+				$hook   = false;
1057
+		}
1058
+		// use class to change status
1059
+		$this->_cpt_model_obj->set_status($venue_status);
1060
+		$success = $this->_cpt_model_obj->save();
1061
+
1062
+		if ($success === false) {
1063
+			$msg = sprintf(esc_html__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1064
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1065
+			return false;
1066
+		}
1067
+		if ($hook) {
1068
+			do_action($hook);
1069
+		}
1070
+		return true;
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 * @param bool $redirect_after
1076
+	 * @return void
1077
+	 * @throws EE_Error
1078
+	 * @throws ReflectionException
1079
+	 */
1080
+	protected function _delete_venue($redirect_after = true)
1081
+	{
1082
+		// determine the venue id and set to array.
1083
+		$VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
1084
+		$VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
1085
+
1086
+		// loop thru venues
1087
+		if ($VNU_ID) {
1088
+			$success = $this->_delete_or_trash_venue($VNU_ID);
1089
+		} else {
1090
+			$success = false;
1091
+			$msg     = esc_html__(
1092
+				'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1093
+				'event_espresso'
1094
+			);
1095
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1096
+		}
1097
+		if ($redirect_after) {
1098
+			$this->_redirect_after_action($success, 'Venue', 'deleted', ['action' => 'default']);
1099
+		}
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * @throws EE_Error
1105
+	 * @throws ReflectionException
1106
+	 */
1107
+	protected function _delete_venues()
1108
+	{
1109
+		$success = true;
1110
+		// determine the event id and set to array.
1111
+		$VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
1112
+		// loop thru events
1113
+		foreach ($VNU_IDs as $VNU_ID) {
1114
+			if ($VNU_ID = absint($VNU_ID)) {
1115
+				$results = $this->_delete_or_trash_venue($VNU_ID);
1116
+				$success = $results !== false ? $success : false;
1117
+			} else {
1118
+				$success = false;
1119
+				$msg     = esc_html__(
1120
+					'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1121
+					'event_espresso'
1122
+				);
1123
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1124
+			}
1125
+		}
1126
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1127
+		$success = $success ? 2 : false;
1128
+		$this->_redirect_after_action(
1129
+			$success,
1130
+			esc_html__('Venues', 'event_espresso'),
1131
+			esc_html__('deleted', 'event_espresso'),
1132
+			['action' => 'default']
1133
+		);
1134
+	}
1135
+
1136
+
1137
+	// todo: put in parent
1138
+
1139
+
1140
+	/**
1141
+	 * @throws EE_Error
1142
+	 * @throws ReflectionException
1143
+	 */
1144
+	private function _delete_or_trash_venue($VNU_ID = false)
1145
+	{
1146
+		// grab event id
1147
+		if (! $VNU_ID = absint($VNU_ID)) {
1148
+			$msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1149
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1150
+			return false;
1151
+		}
1152
+
1153
+
1154
+		$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1155
+		// first need to remove all term relationships
1156
+		$venue->_remove_relations('Term_Taxonomy');
1157
+		$success = $venue->delete_permanently();
1158
+		// did it all go as planned ?
1159
+		if ($success) {
1160
+			$msg = sprintf(esc_html__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1161
+			EE_Error::add_success($msg);
1162
+		} else {
1163
+			$msg =
1164
+				sprintf(
1165
+					esc_html__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'),
1166
+					$VNU_ID
1167
+				);
1168
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1169
+			return false;
1170
+		}
1171
+		do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1172
+		return true;
1173
+	}
1174
+
1175
+
1176
+
1177
+
1178
+	/***********/
1179
+	/* QUERIES */
1180
+
1181
+
1182
+	public function get_venues($per_page = 10, $count = false)
1183
+	{
1184
+
1185
+		$orderby = $this->request->getRequestParam('orderby', '');
1186
+
1187
+		switch ($orderby) {
1188
+			case 'id':
1189
+				$orderby = 'VNU_ID';
1190
+				break;
1191
+
1192
+			case 'capacity':
1193
+				$orderby = 'VNU_capacity';
1194
+				break;
1195
+
1196
+			case 'city':
1197
+				$orderby = 'VNU_city';
1198
+				break;
1199
+
1200
+			default:
1201
+				$orderby = 'VNU_name';
1202
+		}
1203
+
1204
+		$sort         = $this->request->getRequestParam('order', 'ASC');
1205
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1206
+		$per_page     = ! empty($per_page) ? $per_page : 10;
1207
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1208
+
1209
+		$offset = ($current_page - 1) * $per_page;
1210
+		$limit  = [$offset, $per_page];
1211
+
1212
+		$category = $this->request->getRequestParam('category');
1213
+		$category = $category > 0 ? $category : null;
1214
+
1215
+		$where = [];
1216
+
1217
+		// only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1218
+		$status = $this->request->getRequestParam('status');
1219
+		if ($status && $status !== 'all') {
1220
+			$where['status'] = $status;
1221
+		}
1222
+
1223
+		$venue_status = $this->request->getRequestParam('venue_status');
1224
+		if ($venue_status) {
1225
+			$where['status'] = $venue_status;
1226
+		}
1227
+
1228
+
1229
+		if ($category) {
1230
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1231
+			$where['Term_Taxonomy.term_id']  = $category;
1232
+		}
1233
+
1234
+
1235
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1236
+			$where['VNU_wp_user'] = get_current_user_id();
1237
+		} else {
1238
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1239
+				$where['OR'] = [
1240
+					'status*restrict_private' => ['!=', 'private'],
1241
+					'AND'                     => [
1242
+						'status*inclusive' => ['=', 'private'],
1243
+						'VNU_wp_user'      => get_current_user_id(),
1244
+					],
1245
+				];
1246
+			}
1247
+		}
1248
+
1249
+		$search_term = $this->request->getRequestParam('s');
1250
+		if ($search_term) {
1251
+			$search_term = '%' . $search_term . '%';
1252
+			$where['OR'] = [
1253
+				'VNU_name'               => ['LIKE', $search_term],
1254
+				'VNU_desc'               => ['LIKE', $search_term],
1255
+				'VNU_short_desc'         => ['LIKE', $search_term],
1256
+				'VNU_address'            => ['LIKE', $search_term],
1257
+				'VNU_address2'           => ['LIKE', $search_term],
1258
+				'VNU_city'               => ['LIKE', $search_term],
1259
+				'VNU_zip'                => ['LIKE', $search_term],
1260
+				'VNU_phone'              => ['LIKE', $search_term],
1261
+				'VNU_url'                => ['LIKE', $search_term],
1262
+				'VNU_virtual_phone'      => ['LIKE', $search_term],
1263
+				'VNU_virtual_url'        => ['LIKE', $search_term],
1264
+				'VNU_google_map_link'    => ['LIKE', $search_term],
1265
+				'Event.EVT_name'         => ['LIKE', $search_term],
1266
+				'Event.EVT_desc'         => ['LIKE', $search_term],
1267
+				'Event.EVT_phone'        => ['LIKE', $search_term],
1268
+				'Event.EVT_external_URL' => ['LIKE', $search_term],
1269
+			];
1270
+		}
1271
+
1272
+
1273
+		return $count
1274
+			? $this->_venue_model->count([$where], 'VNU_ID')
1275
+			: $this->_venue_model->get_all(
1276
+				[$where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort]
1277
+			);
1278
+	}
1279
+
1280
+
1281
+
1282
+
1283
+	/** Venue Category Stuff **/
1284
+
1285
+	/**
1286
+	 * set the _category property with the category object for the loaded page.
1287
+	 *
1288
+	 * @access private
1289
+	 * @return void
1290
+	 */
1291
+	private function _set_category_object()
1292
+	{
1293
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
1294
+			return;
1295
+		} // already have the category object so get out.
1296
+
1297
+		// set default category object
1298
+		$this->_set_empty_category_object();
1299
+
1300
+		// only set if we've got an id
1301
+		$category_ID = $this->request->getRequestParam('VEN_CAT_ID', 0, 'int');
1302
+		if (! $category_ID) {
1303
+			return;
1304
+		}
1305
+
1306
+		$term = get_term($category_ID, 'espresso_venue_categories');
1307
+
1308
+
1309
+		if (! empty($term)) {
1310
+			$this->_category->category_name       = $term->name;
1311
+			$this->_category->category_identifier = $term->slug;
1312
+			$this->_category->category_desc       = $term->description;
1313
+			$this->_category->id                  = $term->term_id;
1314
+			$this->_category->parent              = $term->parent;
1315
+		}
1316
+	}
1317
+
1318
+
1319
+	private function _set_empty_category_object()
1320
+	{
1321
+		$this->_category                = new stdClass();
1322
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1323
+		$this->_category->id            = $this->_category->parent = 0;
1324
+	}
1325
+
1326
+
1327
+	/**
1328
+	 * @throws EE_Error
1329
+	 */
1330
+	protected function _category_list_table()
1331
+	{
1332
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1333
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1334
+			'add_category',
1335
+			'add_category',
1336
+			[],
1337
+			'add-new-h2'
1338
+		);
1339
+		$this->_search_btn_label = esc_html__('Venue Categories', 'event_espresso');
1340
+		$this->display_admin_list_table_page_with_sidebar();
1341
+	}
1342
+
1343
+
1344
+	/**
1345
+	 * @throws EE_Error
1346
+	 */
1347
+	protected function _category_details($view)
1348
+	{
1349
+
1350
+		// load formatter helper
1351
+		// load field generator helper
1352
+
1353
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
1354
+		$this->_set_add_edit_form_tags($route);
1355
+
1356
+		$this->_set_category_object();
1357
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
1358
+
1359
+		$delete_action = 'delete_category';
1360
+
1361
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(['action' => 'category_list'], $this->_admin_base_url);
1362
+
1363
+		$this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1364
+
1365
+		// take care of contents
1366
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
1367
+		$this->display_admin_page_with_sidebar();
1368
+	}
1369
+
1370
+
1371
+	protected function _category_details_content()
1372
+	{
1373
+		$editor_args['category_desc'] = [
1374
+			'type'          => 'wp_editor',
1375
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1376
+			'class'         => 'my_editor_custom',
1377
+			'wpeditor_args' => ['media_buttons' => false],
1378
+		];
1379
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
1380
+
1381
+		$all_terms = get_terms(
1382
+			['espresso_venue_categories'],
1383
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
1384
+		);
1385
+
1386
+		// setup category select for term parents.
1387
+		$category_select_values[] = [
1388
+			'text' => esc_html__('No Parent', 'event_espresso'),
1389
+			'id'   => 0,
1390
+		];
1391
+		foreach ($all_terms as $term) {
1392
+			$category_select_values[] = [
1393
+				'text' => $term->name,
1394
+				'id'   => $term->term_id,
1395
+			];
1396
+		}
1397
+
1398
+		$category_select = EEH_Form_Fields::select_input(
1399
+			'category_parent',
1400
+			$category_select_values,
1401
+			$this->_category->parent
1402
+		);
1403
+		$template_args   = [
1404
+			'category'                 => $this->_category,
1405
+			'category_select'          => $category_select,
1406
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1407
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1408
+			'disable'                  => '',
1409
+			'disabled_message'         => false,
1410
+		];
1411
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1412
+		return EEH_Template::display_template($template, $template_args, true);
1413
+	}
1414
+
1415
+
1416
+	/**
1417
+	 * @throws EE_Error
1418
+	 */
1419
+	protected function _delete_categories()
1420
+	{
1421
+		$category_ID  = $this->request->getRequestParam('category_id', 0, 'int');
1422
+		$category_IDs = $this->request->getRequestParam('VEN_CAT_ID', [$category_ID], 'int', true);
1423
+
1424
+		foreach ($category_IDs as $cat_id) {
1425
+			$this->_delete_category($cat_id);
1426
+		}
1427
+
1428
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
1429
+		$query_args = [
1430
+			'action' => 'category_list',
1431
+		];
1432
+		$this->_redirect_after_action(0, '', '', $query_args);
1433
+	}
1434
+
1435
+
1436
+	protected function _delete_category($cat_id)
1437
+	{
1438
+		$cat_id = absint($cat_id);
1439
+		wp_delete_term($cat_id, 'espresso_venue_categories');
1440
+	}
1441
+
1442
+
1443
+	/**
1444
+	 * @throws EE_Error
1445
+	 */
1446
+	protected function _insert_or_update_category($new_category)
1447
+	{
1448
+
1449
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1450
+		$success = 0; // we already have a success message so lets not send another.
1451
+		if ($cat_id) {
1452
+			$query_args = [
1453
+				'action'     => 'edit_category',
1454
+				'VEN_CAT_ID' => $cat_id,
1455
+			];
1456
+		} else {
1457
+			$query_args = ['action' => 'add_category'];
1458
+		}
1459
+		$this->_redirect_after_action($success, '', '', $query_args, true);
1460
+	}
1461
+
1462
+
1463
+	private function _insert_category($update = false)
1464
+	{
1465
+		$category_ID     = $update ? $this->request->getRequestParam('VEN_CAT_ID', '', 'int') : '';
1466
+		$category_name   = $this->request->getRequestParam('category_name', '');
1467
+		$category_desc   = $this->request->getRequestParam('category_desc', '', 'html');
1468
+		$category_parent = $this->request->getRequestParam('category_parent', 0, 'int');
1469
+
1470
+		if (empty($category_name)) {
1471
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
1472
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1473
+			return false;
1474
+		}
1475
+
1476
+
1477
+		$term_args = [
1478
+			'name'        => $category_name,
1479
+			'description' => $category_desc,
1480
+			'parent'      => $category_parent,
1481
+		];
1482
+
1483
+		$insert_ids = $update
1484
+			? wp_update_term($category_ID, 'espresso_venue_categories', $term_args)
1485
+			: wp_insert_term(
1486
+				$category_name,
1487
+				'espresso_venue_categories',
1488
+				$term_args
1489
+			);
1490
+
1491
+		if (! is_array($insert_ids)) {
1492
+			EE_Error::add_error(
1493
+				esc_html__('An error occurred and the category has not been saved to the database.', 'event_espresso'),
1494
+				__FILE__,
1495
+				__FUNCTION__,
1496
+				__LINE__
1497
+			);
1498
+		} else {
1499
+			$category_ID = $insert_ids['term_id'];
1500
+			EE_Error::add_success(
1501
+				sprintf(
1502
+					esc_html__('The category %s was successfully created', 'event_espresso'),
1503
+					$category_name
1504
+				)
1505
+			);
1506
+		}
1507
+
1508
+		return $category_ID;
1509
+	}
1510
+
1511
+
1512
+	/**
1513
+	 * TODO handle category exports()
1514
+	 *
1515
+	 * @return void
1516
+	 */
1517
+	protected function _categories_export()
1518
+	{
1519
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
1520
+		$this->request->mergeRequestParams(
1521
+			[
1522
+				'export'       => 'report',
1523
+				'action'       => 'categories',
1524
+				'category_ids' => $this->request->getRequestParam('VEN_CAT_ID', 0, 'int'),
1525
+			]
1526
+		);
1527
+
1528
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1529
+			require_once(EE_CLASSES . 'EE_Export.class.php');
1530
+			$EE_Export = EE_Export::instance($this->request->requestParams());
1531
+			$EE_Export->export();
1532
+		}
1533
+	}
1534
+
1535
+
1536
+	protected function _import_categories()
1537
+	{
1538
+
1539
+		require_once(EE_CLASSES . 'EE_Import.class.php');
1540
+		EE_Import::instance()->import();
1541
+	}
1542
+
1543
+
1544
+	/**
1545
+	 * @throws EE_Error
1546
+	 */
1547
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
1548
+	{
1549
+
1550
+		// testing term stuff
1551
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
1552
+		$order       = $this->request->getRequestParam('order', 'DESC');
1553
+		$limit       = ($current_page - 1) * $per_page;
1554
+		$where       = ['taxonomy' => 'espresso_venue_categories'];
1555
+		$search_term = $this->request->getRequestParam('s');
1556
+		if ($search_term) {
1557
+			$search_term = '%' . $search_term . '%';
1558
+			$where['OR'] = [
1559
+				'Term.name'   => ['LIKE', $search_term],
1560
+				'description' => ['LIKE', $search_term],
1561
+			];
1562
+		}
1563
+
1564
+		$query_params = [
1565
+			$where,
1566
+			'order_by'   => [$orderby => $order],
1567
+			'limit'      => $limit . ',' . $per_page,
1568
+			'force_join' => ['Term'],
1569
+		];
1570
+
1571
+		return $count
1572
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1573
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
1574
+	}
1575
+
1576
+
1577
+	/* end category stuff */
1578
+	/**************/
1579 1579
 }
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3683 added lines, -3683 removed lines patch added patch discarded remove patch
@@ -19,2227 +19,2227 @@  discard block
 block discarded – undo
19 19
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
21 21
 
22
-    /**
23
-     * @var EE_Registration
24
-     */
25
-    private $_registration;
26
-
27
-    /**
28
-     * @var EE_Event
29
-     */
30
-    private $_reg_event;
31
-
32
-    /**
33
-     * @var EE_Session
34
-     */
35
-    private $_session;
36
-
37
-    /**
38
-     * @var array
39
-     */
40
-    private static $_reg_status;
41
-
42
-    /**
43
-     * Form for displaying the custom questions for this registration.
44
-     * This gets used a few times throughout the request so its best to cache it
45
-     *
46
-     * @var EE_Registration_Custom_Questions_Form
47
-     */
48
-    protected $_reg_custom_questions_form = null;
49
-
50
-    /**
51
-     * @var EEM_Registration $registration_model
52
-     */
53
-    private $registration_model;
54
-
55
-    /**
56
-     * @var EEM_Attendee $attendee_model
57
-     */
58
-    private $attendee_model;
59
-
60
-    /**
61
-     * @var EEM_Event $event_model
62
-     */
63
-    private $event_model;
64
-
65
-    /**
66
-     * @var EEM_Status $status_model
67
-     */
68
-    private $status_model;
69
-
70
-
71
-    /**
72
-     * @param bool $routing
73
-     * @throws EE_Error
74
-     * @throws InvalidArgumentException
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws ReflectionException
78
-     */
79
-    public function __construct($routing = true)
80
-    {
81
-        parent::__construct($routing);
82
-        add_action('wp_loaded', [$this, 'wp_loaded']);
83
-    }
84
-
85
-
86
-    /**
87
-     * @return EEM_Registration
88
-     * @throws InvalidArgumentException
89
-     * @throws InvalidDataTypeException
90
-     * @throws InvalidInterfaceException
91
-     * @since 4.10.2.p
92
-     */
93
-    protected function getRegistrationModel()
94
-    {
95
-        if (! $this->registration_model instanceof EEM_Registration) {
96
-            $this->registration_model = $this->getLoader()->getShared('EEM_Registration');
97
-        }
98
-        return $this->registration_model;
99
-    }
100
-
101
-
102
-    /**
103
-     * @return EEM_Attendee
104
-     * @throws InvalidArgumentException
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidInterfaceException
107
-     * @since 4.10.2.p
108
-     */
109
-    protected function getAttendeeModel()
110
-    {
111
-        if (! $this->attendee_model instanceof EEM_Attendee) {
112
-            $this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
113
-        }
114
-        return $this->attendee_model;
115
-    }
116
-
117
-
118
-    /**
119
-     * @return EEM_Event
120
-     * @throws InvalidArgumentException
121
-     * @throws InvalidDataTypeException
122
-     * @throws InvalidInterfaceException
123
-     * @since 4.10.2.p
124
-     */
125
-    protected function getEventModel()
126
-    {
127
-        if (! $this->event_model instanceof EEM_Event) {
128
-            $this->event_model = $this->getLoader()->getShared('EEM_Event');
129
-        }
130
-        return $this->event_model;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return EEM_Status
136
-     * @throws InvalidArgumentException
137
-     * @throws InvalidDataTypeException
138
-     * @throws InvalidInterfaceException
139
-     * @since 4.10.2.p
140
-     */
141
-    protected function getStatusModel()
142
-    {
143
-        if (! $this->status_model instanceof EEM_Status) {
144
-            $this->status_model = $this->getLoader()->getShared('EEM_Status');
145
-        }
146
-        return $this->status_model;
147
-    }
148
-
149
-
150
-    public function wp_loaded()
151
-    {
152
-        // when adding a new registration...
153
-        $action = $this->request->getRequestParam('action');
154
-        if ($action === 'new_registration') {
155
-            EE_System::do_not_cache();
156
-            if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
157
-                // and it's NOT the attendee information reg step
158
-                // force cookie expiration by setting time to last week
159
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
160
-                // and update the global
161
-                $_COOKIE['ee_registration_added'] = 0;
162
-            }
163
-        }
164
-    }
165
-
166
-
167
-    protected function _init_page_props()
168
-    {
169
-        $this->page_slug        = REG_PG_SLUG;
170
-        $this->_admin_base_url  = REG_ADMIN_URL;
171
-        $this->_admin_base_path = REG_ADMIN;
172
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
173
-        $this->_cpt_routes      = [
174
-            'add_new_attendee' => 'espresso_attendees',
175
-            'edit_attendee'    => 'espresso_attendees',
176
-            'insert_attendee'  => 'espresso_attendees',
177
-            'update_attendee'  => 'espresso_attendees',
178
-        ];
179
-        $this->_cpt_model_names = [
180
-            'add_new_attendee' => 'EEM_Attendee',
181
-            'edit_attendee'    => 'EEM_Attendee',
182
-        ];
183
-        $this->_cpt_edit_routes = [
184
-            'espresso_attendees' => 'edit_attendee',
185
-        ];
186
-        $this->_pagenow_map     = [
187
-            'add_new_attendee' => 'post-new.php',
188
-            'edit_attendee'    => 'post.php',
189
-            'trash'            => 'post.php',
190
-        ];
191
-        add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
192
-        // add filters so that the comment urls don't take users to a confusing 404 page
193
-        add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
194
-    }
195
-
196
-
197
-    /**
198
-     * @param string     $link    The comment permalink with '#comment-$id' appended.
199
-     * @param WP_Comment $comment The current comment object.
200
-     * @return string
201
-     */
202
-    public function clear_comment_link($link, WP_Comment $comment)
203
-    {
204
-        // gotta make sure this only happens on this route
205
-        $post_type = get_post_type($comment->comment_post_ID);
206
-        if ($post_type === 'espresso_attendees') {
207
-            return '#commentsdiv';
208
-        }
209
-        return $link;
210
-    }
211
-
212
-
213
-    protected function _ajax_hooks()
214
-    {
215
-        // todo: all hooks for registrations ajax goes in here
216
-        add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
217
-    }
218
-
219
-
220
-    protected function _define_page_props()
221
-    {
222
-        $this->_admin_page_title = $this->page_label;
223
-        $this->_labels           = [
224
-            'buttons'                      => [
225
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
226
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
227
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
228
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
229
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
230
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
231
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
-            ],
234
-            'publishbox'                   => [
235
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
-            ],
238
-            'hide_add_button_on_cpt_route' => [
239
-                'edit_attendee' => true,
240
-            ],
241
-        ];
242
-    }
243
-
244
-
245
-    /**
246
-     * grab url requests and route them
247
-     *
248
-     * @return void
249
-     * @throws EE_Error
250
-     */
251
-    public function _set_page_routes()
252
-    {
253
-        $this->_get_registration_status_array();
254
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
-        $REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
-        $ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
-        $this->_page_routes = [
259
-            'default'                             => [
260
-                'func'       => '_registrations_overview_list_table',
261
-                'capability' => 'ee_read_registrations',
262
-            ],
263
-            'view_registration'                   => [
264
-                'func'       => '_registration_details',
265
-                'capability' => 'ee_read_registration',
266
-                'obj_id'     => $REG_ID,
267
-            ],
268
-            'edit_registration'                   => [
269
-                'func'               => '_update_attendee_registration_form',
270
-                'noheader'           => true,
271
-                'headers_sent_route' => 'view_registration',
272
-                'capability'         => 'ee_edit_registration',
273
-                'obj_id'             => $REG_ID,
274
-                '_REG_ID'            => $REG_ID,
275
-            ],
276
-            'trash_registrations'                 => [
277
-                'func'       => '_trash_or_restore_registrations',
278
-                'args'       => ['trash' => true],
279
-                'noheader'   => true,
280
-                'capability' => 'ee_delete_registrations',
281
-            ],
282
-            'restore_registrations'               => [
283
-                'func'       => '_trash_or_restore_registrations',
284
-                'args'       => ['trash' => false],
285
-                'noheader'   => true,
286
-                'capability' => 'ee_delete_registrations',
287
-            ],
288
-            'delete_registrations'                => [
289
-                'func'       => '_delete_registrations',
290
-                'noheader'   => true,
291
-                'capability' => 'ee_delete_registrations',
292
-            ],
293
-            'new_registration'                    => [
294
-                'func'       => 'new_registration',
295
-                'capability' => 'ee_edit_registrations',
296
-            ],
297
-            'process_reg_step'                    => [
298
-                'func'       => 'process_reg_step',
299
-                'noheader'   => true,
300
-                'capability' => 'ee_edit_registrations',
301
-            ],
302
-            'redirect_to_txn'                     => [
303
-                'func'       => 'redirect_to_txn',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-            ],
307
-            'change_reg_status'                   => [
308
-                'func'       => '_change_reg_status',
309
-                'noheader'   => true,
310
-                'capability' => 'ee_edit_registration',
311
-                'obj_id'     => $REG_ID,
312
-            ],
313
-            'approve_registration'                => [
314
-                'func'       => 'approve_registration',
315
-                'noheader'   => true,
316
-                'capability' => 'ee_edit_registration',
317
-                'obj_id'     => $REG_ID,
318
-            ],
319
-            'approve_and_notify_registration'     => [
320
-                'func'       => 'approve_registration',
321
-                'noheader'   => true,
322
-                'args'       => [true],
323
-                'capability' => 'ee_edit_registration',
324
-                'obj_id'     => $REG_ID,
325
-            ],
326
-            'approve_registrations'               => [
327
-                'func'       => 'bulk_action_on_registrations',
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_registrations',
330
-                'args'       => ['approve'],
331
-            ],
332
-            'approve_and_notify_registrations'    => [
333
-                'func'       => 'bulk_action_on_registrations',
334
-                'noheader'   => true,
335
-                'capability' => 'ee_edit_registrations',
336
-                'args'       => ['approve', true],
337
-            ],
338
-            'decline_registration'                => [
339
-                'func'       => 'decline_registration',
340
-                'noheader'   => true,
341
-                'capability' => 'ee_edit_registration',
342
-                'obj_id'     => $REG_ID,
343
-            ],
344
-            'decline_and_notify_registration'     => [
345
-                'func'       => 'decline_registration',
346
-                'noheader'   => true,
347
-                'args'       => [true],
348
-                'capability' => 'ee_edit_registration',
349
-                'obj_id'     => $REG_ID,
350
-            ],
351
-            'decline_registrations'               => [
352
-                'func'       => 'bulk_action_on_registrations',
353
-                'noheader'   => true,
354
-                'capability' => 'ee_edit_registrations',
355
-                'args'       => ['decline'],
356
-            ],
357
-            'decline_and_notify_registrations'    => [
358
-                'func'       => 'bulk_action_on_registrations',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_edit_registrations',
361
-                'args'       => ['decline', true],
362
-            ],
363
-            'pending_registration'                => [
364
-                'func'       => 'pending_registration',
365
-                'noheader'   => true,
366
-                'capability' => 'ee_edit_registration',
367
-                'obj_id'     => $REG_ID,
368
-            ],
369
-            'pending_and_notify_registration'     => [
370
-                'func'       => 'pending_registration',
371
-                'noheader'   => true,
372
-                'args'       => [true],
373
-                'capability' => 'ee_edit_registration',
374
-                'obj_id'     => $REG_ID,
375
-            ],
376
-            'pending_registrations'               => [
377
-                'func'       => 'bulk_action_on_registrations',
378
-                'noheader'   => true,
379
-                'capability' => 'ee_edit_registrations',
380
-                'args'       => ['pending'],
381
-            ],
382
-            'pending_and_notify_registrations'    => [
383
-                'func'       => 'bulk_action_on_registrations',
384
-                'noheader'   => true,
385
-                'capability' => 'ee_edit_registrations',
386
-                'args'       => ['pending', true],
387
-            ],
388
-            'no_approve_registration'             => [
389
-                'func'       => 'not_approve_registration',
390
-                'noheader'   => true,
391
-                'capability' => 'ee_edit_registration',
392
-                'obj_id'     => $REG_ID,
393
-            ],
394
-            'no_approve_and_notify_registration'  => [
395
-                'func'       => 'not_approve_registration',
396
-                'noheader'   => true,
397
-                'args'       => [true],
398
-                'capability' => 'ee_edit_registration',
399
-                'obj_id'     => $REG_ID,
400
-            ],
401
-            'no_approve_registrations'            => [
402
-                'func'       => 'bulk_action_on_registrations',
403
-                'noheader'   => true,
404
-                'capability' => 'ee_edit_registrations',
405
-                'args'       => ['not_approve'],
406
-            ],
407
-            'no_approve_and_notify_registrations' => [
408
-                'func'       => 'bulk_action_on_registrations',
409
-                'noheader'   => true,
410
-                'capability' => 'ee_edit_registrations',
411
-                'args'       => ['not_approve', true],
412
-            ],
413
-            'cancel_registration'                 => [
414
-                'func'       => 'cancel_registration',
415
-                'noheader'   => true,
416
-                'capability' => 'ee_edit_registration',
417
-                'obj_id'     => $REG_ID,
418
-            ],
419
-            'cancel_and_notify_registration'      => [
420
-                'func'       => 'cancel_registration',
421
-                'noheader'   => true,
422
-                'args'       => [true],
423
-                'capability' => 'ee_edit_registration',
424
-                'obj_id'     => $REG_ID,
425
-            ],
426
-            'cancel_registrations'                => [
427
-                'func'       => 'bulk_action_on_registrations',
428
-                'noheader'   => true,
429
-                'capability' => 'ee_edit_registrations',
430
-                'args'       => ['cancel'],
431
-            ],
432
-            'cancel_and_notify_registrations'     => [
433
-                'func'       => 'bulk_action_on_registrations',
434
-                'noheader'   => true,
435
-                'capability' => 'ee_edit_registrations',
436
-                'args'       => ['cancel', true],
437
-            ],
438
-            'wait_list_registration'              => [
439
-                'func'       => 'wait_list_registration',
440
-                'noheader'   => true,
441
-                'capability' => 'ee_edit_registration',
442
-                'obj_id'     => $REG_ID,
443
-            ],
444
-            'wait_list_and_notify_registration'   => [
445
-                'func'       => 'wait_list_registration',
446
-                'noheader'   => true,
447
-                'args'       => [true],
448
-                'capability' => 'ee_edit_registration',
449
-                'obj_id'     => $REG_ID,
450
-            ],
451
-            'contact_list'                        => [
452
-                'func'       => '_attendee_contact_list_table',
453
-                'capability' => 'ee_read_contacts',
454
-            ],
455
-            'add_new_attendee'                    => [
456
-                'func' => '_create_new_cpt_item',
457
-                'args' => [
458
-                    'new_attendee' => true,
459
-                    'capability'   => 'ee_edit_contacts',
460
-                ],
461
-            ],
462
-            'edit_attendee'                       => [
463
-                'func'       => '_edit_cpt_item',
464
-                'capability' => 'ee_edit_contacts',
465
-                'obj_id'     => $ATT_ID,
466
-            ],
467
-            'duplicate_attendee'                  => [
468
-                'func'       => '_duplicate_attendee',
469
-                'noheader'   => true,
470
-                'capability' => 'ee_edit_contacts',
471
-                'obj_id'     => $ATT_ID,
472
-            ],
473
-            'insert_attendee'                     => [
474
-                'func'       => '_insert_or_update_attendee',
475
-                'args'       => [
476
-                    'new_attendee' => true,
477
-                ],
478
-                'noheader'   => true,
479
-                'capability' => 'ee_edit_contacts',
480
-            ],
481
-            'update_attendee'                     => [
482
-                'func'       => '_insert_or_update_attendee',
483
-                'args'       => [
484
-                    'new_attendee' => false,
485
-                ],
486
-                'noheader'   => true,
487
-                'capability' => 'ee_edit_contacts',
488
-                'obj_id'     => $ATT_ID,
489
-            ],
490
-            'trash_attendees'                     => [
491
-                'func'       => '_trash_or_restore_attendees',
492
-                'args'       => [
493
-                    'trash' => 'true',
494
-                ],
495
-                'noheader'   => true,
496
-                'capability' => 'ee_delete_contacts',
497
-            ],
498
-            'trash_attendee'                      => [
499
-                'func'       => '_trash_or_restore_attendees',
500
-                'args'       => [
501
-                    'trash' => true,
502
-                ],
503
-                'noheader'   => true,
504
-                'capability' => 'ee_delete_contacts',
505
-                'obj_id'     => $ATT_ID,
506
-            ],
507
-            'restore_attendees'                   => [
508
-                'func'       => '_trash_or_restore_attendees',
509
-                'args'       => [
510
-                    'trash' => false,
511
-                ],
512
-                'noheader'   => true,
513
-                'capability' => 'ee_delete_contacts',
514
-                'obj_id'     => $ATT_ID,
515
-            ],
516
-            'resend_registration'                 => [
517
-                'func'       => '_resend_registration',
518
-                'noheader'   => true,
519
-                'capability' => 'ee_send_message',
520
-            ],
521
-            'registrations_report'                => [
522
-                'func'       => '_registrations_report',
523
-                'noheader'   => true,
524
-                'capability' => 'ee_read_registrations',
525
-            ],
526
-            'contact_list_export'                 => [
527
-                'func'       => '_contact_list_export',
528
-                'noheader'   => true,
529
-                'capability' => 'export',
530
-            ],
531
-            'contact_list_report'                 => [
532
-                'func'       => '_contact_list_report',
533
-                'noheader'   => true,
534
-                'capability' => 'ee_read_contacts',
535
-            ],
536
-        ];
537
-    }
538
-
539
-
540
-    protected function _set_page_config()
541
-    {
542
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
-        $this->_page_config = [
545
-            'default'           => [
546
-                'nav'           => [
547
-                    'label' => esc_html__('Overview', 'event_espresso'),
548
-                    'order' => 5,
549
-                ],
550
-                'help_tabs'     => [
551
-                    'registrations_overview_help_tab'                       => [
552
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
-                        'filename' => 'registrations_overview',
554
-                    ],
555
-                    'registrations_overview_table_column_headings_help_tab' => [
556
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
-                        'filename' => 'registrations_overview_table_column_headings',
558
-                    ],
559
-                    'registrations_overview_filters_help_tab'               => [
560
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
-                        'filename' => 'registrations_overview_filters',
562
-                    ],
563
-                    'registrations_overview_views_help_tab'                 => [
564
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
565
-                        'filename' => 'registrations_overview_views',
566
-                    ],
567
-                    'registrations_regoverview_other_help_tab'              => [
568
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
-                        'filename' => 'registrations_overview_other',
570
-                    ],
571
-                ],
572
-                'qtips'         => ['Registration_List_Table_Tips'],
573
-                'list_table'    => 'EE_Registrations_List_Table',
574
-                'require_nonce' => false,
575
-            ],
576
-            'view_registration' => [
577
-                'nav'           => [
578
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
579
-                    'order'      => 15,
580
-                    'url'        => $REG_ID
581
-                        ? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
582
-                        : $this->_admin_base_url,
583
-                    'persistent' => false,
584
-                ],
585
-                'help_tabs'     => [
586
-                    'registrations_details_help_tab'                    => [
587
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
588
-                        'filename' => 'registrations_details',
589
-                    ],
590
-                    'registrations_details_table_help_tab'              => [
591
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
592
-                        'filename' => 'registrations_details_table',
593
-                    ],
594
-                    'registrations_details_form_answers_help_tab'       => [
595
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
596
-                        'filename' => 'registrations_details_form_answers',
597
-                    ],
598
-                    'registrations_details_registrant_details_help_tab' => [
599
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
600
-                        'filename' => 'registrations_details_registrant_details',
601
-                    ],
602
-                ],
603
-                'metaboxes'     => array_merge(
604
-                    $this->_default_espresso_metaboxes,
605
-                    ['_registration_details_metaboxes']
606
-                ),
607
-                'require_nonce' => false,
608
-            ],
609
-            'new_registration'  => [
610
-                'nav'           => [
611
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
612
-                    'url'        => '#',
613
-                    'order'      => 15,
614
-                    'persistent' => false,
615
-                ],
616
-                'metaboxes'     => $this->_default_espresso_metaboxes,
617
-                'labels'        => [
618
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
619
-                ],
620
-                'require_nonce' => false,
621
-            ],
622
-            'add_new_attendee'  => [
623
-                'nav'           => [
624
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
625
-                    'order'      => 15,
626
-                    'persistent' => false,
627
-                ],
628
-                'metaboxes'     => array_merge(
629
-                    $this->_default_espresso_metaboxes,
630
-                    ['_publish_post_box', 'attendee_editor_metaboxes']
631
-                ),
632
-                'require_nonce' => false,
633
-            ],
634
-            'edit_attendee'     => [
635
-                'nav'           => [
636
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
637
-                    'order'      => 15,
638
-                    'persistent' => false,
639
-                    'url'        => $ATT_ID
640
-                        ? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
641
-                        : $this->_admin_base_url,
642
-                ],
643
-                'metaboxes'     => ['attendee_editor_metaboxes'],
644
-                'require_nonce' => false,
645
-            ],
646
-            'contact_list'      => [
647
-                'nav'           => [
648
-                    'label' => esc_html__('Contact List', 'event_espresso'),
649
-                    'order' => 20,
650
-                ],
651
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
652
-                'help_tabs'     => [
653
-                    'registrations_contact_list_help_tab'                       => [
654
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
655
-                        'filename' => 'registrations_contact_list',
656
-                    ],
657
-                    'registrations_contact-list_table_column_headings_help_tab' => [
658
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
659
-                        'filename' => 'registrations_contact_list_table_column_headings',
660
-                    ],
661
-                    'registrations_contact_list_views_help_tab'                 => [
662
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
663
-                        'filename' => 'registrations_contact_list_views',
664
-                    ],
665
-                    'registrations_contact_list_other_help_tab'                 => [
666
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
667
-                        'filename' => 'registrations_contact_list_other',
668
-                    ],
669
-                ],
670
-                'metaboxes'     => [],
671
-                'require_nonce' => false,
672
-            ],
673
-            // override default cpt routes
674
-            'create_new'        => '',
675
-            'edit'              => '',
676
-        ];
677
-    }
678
-
679
-
680
-    /**
681
-     * The below methods aren't used by this class currently
682
-     */
683
-    protected function _add_screen_options()
684
-    {
685
-    }
686
-
687
-
688
-    protected function _add_feature_pointers()
689
-    {
690
-    }
691
-
692
-
693
-    public function admin_init()
694
-    {
695
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
696
-            'click "Update Registration Questions" to save your changes',
697
-            'event_espresso'
698
-        );
699
-    }
700
-
701
-
702
-    public function admin_notices()
703
-    {
704
-    }
705
-
706
-
707
-    public function admin_footer_scripts()
708
-    {
709
-    }
710
-
711
-
712
-    /**
713
-     * get list of registration statuses
714
-     *
715
-     * @return void
716
-     * @throws EE_Error
717
-     */
718
-    private function _get_registration_status_array()
719
-    {
720
-        self::$_reg_status = EEM_Registration::reg_status_array([], true);
721
-    }
722
-
723
-
724
-    /**
725
-     * @throws InvalidArgumentException
726
-     * @throws InvalidDataTypeException
727
-     * @throws InvalidInterfaceException
728
-     * @since 4.10.2.p
729
-     */
730
-    protected function _add_screen_options_default()
731
-    {
732
-        $this->_per_page_screen_option();
733
-    }
734
-
735
-
736
-    /**
737
-     * @throws InvalidArgumentException
738
-     * @throws InvalidDataTypeException
739
-     * @throws InvalidInterfaceException
740
-     * @since 4.10.2.p
741
-     */
742
-    protected function _add_screen_options_contact_list()
743
-    {
744
-        $page_title              = $this->_admin_page_title;
745
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
746
-        $this->_per_page_screen_option();
747
-        $this->_admin_page_title = $page_title;
748
-    }
749
-
750
-
751
-    public function load_scripts_styles()
752
-    {
753
-        // style
754
-        wp_register_style(
755
-            'espresso_reg',
756
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
757
-            ['ee-admin-css'],
758
-            EVENT_ESPRESSO_VERSION
759
-        );
760
-        wp_enqueue_style('espresso_reg');
761
-        // script
762
-        wp_register_script(
763
-            'espresso_reg',
764
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
765
-            ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
766
-            EVENT_ESPRESSO_VERSION,
767
-            true
768
-        );
769
-        wp_enqueue_script('espresso_reg');
770
-    }
771
-
772
-
773
-    /**
774
-     * @throws EE_Error
775
-     * @throws InvalidArgumentException
776
-     * @throws InvalidDataTypeException
777
-     * @throws InvalidInterfaceException
778
-     * @throws ReflectionException
779
-     * @since 4.10.2.p
780
-     */
781
-    public function load_scripts_styles_edit_attendee()
782
-    {
783
-        // stuff to only show up on our attendee edit details page.
784
-        $attendee_details_translations = [
785
-            'att_publish_text' => sprintf(
786
-            /* translators: The date and time */
787
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
788
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
789
-            ),
790
-        ];
791
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
792
-        wp_enqueue_script('jquery-validate');
793
-    }
794
-
795
-
796
-    /**
797
-     * @throws EE_Error
798
-     * @throws InvalidArgumentException
799
-     * @throws InvalidDataTypeException
800
-     * @throws InvalidInterfaceException
801
-     * @throws ReflectionException
802
-     * @since 4.10.2.p
803
-     */
804
-    public function load_scripts_styles_view_registration()
805
-    {
806
-        // styles
807
-        wp_enqueue_style('espresso-ui-theme');
808
-        // scripts
809
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
810
-        $this->_reg_custom_questions_form->wp_enqueue_scripts();
811
-    }
812
-
813
-
814
-    public function load_scripts_styles_contact_list()
815
-    {
816
-        wp_dequeue_style('espresso_reg');
817
-        wp_register_style(
818
-            'espresso_att',
819
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
820
-            ['ee-admin-css'],
821
-            EVENT_ESPRESSO_VERSION
822
-        );
823
-        wp_enqueue_style('espresso_att');
824
-    }
825
-
826
-
827
-    public function load_scripts_styles_new_registration()
828
-    {
829
-        wp_register_script(
830
-            'ee-spco-for-admin',
831
-            REG_ASSETS_URL . 'spco_for_admin.js',
832
-            ['underscore', 'jquery'],
833
-            EVENT_ESPRESSO_VERSION,
834
-            true
835
-        );
836
-        wp_enqueue_script('ee-spco-for-admin');
837
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
838
-        EE_Form_Section_Proper::wp_enqueue_scripts();
839
-        EED_Ticket_Selector::load_tckt_slctr_assets();
840
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
841
-    }
842
-
843
-
844
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
845
-    {
846
-        add_filter('FHEE_load_EE_messages', '__return_true');
847
-    }
848
-
849
-
850
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
851
-    {
852
-        add_filter('FHEE_load_EE_messages', '__return_true');
853
-    }
854
-
855
-
856
-    /**
857
-     * @throws EE_Error
858
-     * @throws InvalidArgumentException
859
-     * @throws InvalidDataTypeException
860
-     * @throws InvalidInterfaceException
861
-     * @throws ReflectionException
862
-     * @since 4.10.2.p
863
-     */
864
-    protected function _set_list_table_views_default()
865
-    {
866
-        // for notification related bulk actions we need to make sure only active messengers have an option.
867
-        EED_Messages::set_autoloaders();
868
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
869
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
870
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
871
-        // key= bulk_action_slug, value= message type.
872
-        $match_array = [
873
-            'approve_registrations'    => 'registration',
874
-            'decline_registrations'    => 'declined_registration',
875
-            'pending_registrations'    => 'pending_approval',
876
-            'no_approve_registrations' => 'not_approved_registration',
877
-            'cancel_registrations'     => 'cancelled_registration',
878
-        ];
879
-        $can_send    = EE_Registry::instance()->CAP->current_user_can(
880
-            'ee_send_message',
881
-            'batch_send_messages'
882
-        );
883
-        /** setup reg status bulk actions **/
884
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
885
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
886
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
887
-                'Approve and Notify Registrations',
888
-                'event_espresso'
889
-            );
890
-        }
891
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
892
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
893
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
894
-                'Decline and Notify Registrations',
895
-                'event_espresso'
896
-            );
897
-        }
898
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
899
-            'Set Registrations to Pending Payment',
900
-            'event_espresso'
901
-        );
902
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
903
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
904
-                'Set Registrations to Pending Payment and Notify',
905
-                'event_espresso'
906
-            );
907
-        }
908
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
909
-            'Set Registrations to Not Approved',
910
-            'event_espresso'
911
-        );
912
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
913
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
914
-                'Set Registrations to Not Approved and Notify',
915
-                'event_espresso'
916
-            );
917
-        }
918
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
919
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
920
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
921
-                'Cancel Registrations and Notify',
922
-                'event_espresso'
923
-            );
924
-        }
925
-        $def_reg_status_actions = apply_filters(
926
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
927
-            $def_reg_status_actions,
928
-            $active_mts,
929
-            $can_send
930
-        );
931
-
932
-        $this->_views = [
933
-            'all'   => [
934
-                'slug'        => 'all',
935
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
936
-                'count'       => 0,
937
-                'bulk_action' => array_merge(
938
-                    $def_reg_status_actions,
939
-                    [
940
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
941
-                    ]
942
-                ),
943
-            ],
944
-            'month' => [
945
-                'slug'        => 'month',
946
-                'label'       => esc_html__('This Month', 'event_espresso'),
947
-                'count'       => 0,
948
-                'bulk_action' => array_merge(
949
-                    $def_reg_status_actions,
950
-                    [
951
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
952
-                    ]
953
-                ),
954
-            ],
955
-            'today' => [
956
-                'slug'        => 'today',
957
-                'label'       => sprintf(
958
-                    esc_html__('Today - %s', 'event_espresso'),
959
-                    date('M d, Y', current_time('timestamp'))
960
-                ),
961
-                'count'       => 0,
962
-                'bulk_action' => array_merge(
963
-                    $def_reg_status_actions,
964
-                    [
965
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
966
-                    ]
967
-                ),
968
-            ],
969
-        ];
970
-        if (
971
-            EE_Registry::instance()->CAP->current_user_can(
972
-                'ee_delete_registrations',
973
-                'espresso_registrations_delete_registration'
974
-            )
975
-        ) {
976
-            $this->_views['incomplete'] = [
977
-                'slug'        => 'incomplete',
978
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
979
-                'count'       => 0,
980
-                'bulk_action' => [
981
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
982
-                ],
983
-            ];
984
-            $this->_views['trash']      = [
985
-                'slug'        => 'trash',
986
-                'label'       => esc_html__('Trash', 'event_espresso'),
987
-                'count'       => 0,
988
-                'bulk_action' => [
989
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
990
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
991
-                ],
992
-            ];
993
-        }
994
-    }
995
-
996
-
997
-    protected function _set_list_table_views_contact_list()
998
-    {
999
-        $this->_views = [
1000
-            'in_use' => [
1001
-                'slug'        => 'in_use',
1002
-                'label'       => esc_html__('In Use', 'event_espresso'),
1003
-                'count'       => 0,
1004
-                'bulk_action' => [
1005
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1006
-                ],
1007
-            ],
1008
-        ];
1009
-        if (
1010
-            EE_Registry::instance()->CAP->current_user_can(
1011
-                'ee_delete_contacts',
1012
-                'espresso_registrations_trash_attendees'
1013
-            )
1014
-        ) {
1015
-            $this->_views['trash'] = [
1016
-                'slug'        => 'trash',
1017
-                'label'       => esc_html__('Trash', 'event_espresso'),
1018
-                'count'       => 0,
1019
-                'bulk_action' => [
1020
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1021
-                ],
1022
-            ];
1023
-        }
1024
-    }
1025
-
1026
-
1027
-    /**
1028
-     * @return array
1029
-     * @throws EE_Error
1030
-     */
1031
-    protected function _registration_legend_items()
1032
-    {
1033
-        $fc_items = [
1034
-            'star-icon'        => [
1035
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1037
-            ],
1038
-            'view_details'     => [
1039
-                'class' => 'dashicons dashicons-clipboard',
1040
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1041
-            ],
1042
-            'edit_attendee'    => [
1043
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1044
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1045
-            ],
1046
-            'view_transaction' => [
1047
-                'class' => 'dashicons dashicons-cart',
1048
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1049
-            ],
1050
-            'view_invoice'     => [
1051
-                'class' => 'dashicons dashicons-media-spreadsheet',
1052
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1053
-            ],
1054
-        ];
1055
-        if (
1056
-            EE_Registry::instance()->CAP->current_user_can(
1057
-                'ee_send_message',
1058
-                'espresso_registrations_resend_registration'
1059
-            )
1060
-        ) {
1061
-            $fc_items['resend_registration'] = [
1062
-                'class' => 'dashicons dashicons-email-alt',
1063
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1064
-            ];
1065
-        } else {
1066
-            $fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1067
-        }
1068
-        if (
1069
-            EE_Registry::instance()->CAP->current_user_can(
1070
-                'ee_read_global_messages',
1071
-                'view_filtered_messages'
1072
-            )
1073
-        ) {
1074
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1075
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1076
-                $fc_items['view_related_messages'] = [
1077
-                    'class' => $related_for_icon['css_class'],
1078
-                    'desc'  => $related_for_icon['label'],
1079
-                ];
1080
-            }
1081
-        }
1082
-        $sc_items = [
1083
-            'approved_status'   => [
1084
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1085
-                'desc'  => EEH_Template::pretty_status(
1086
-                    EEM_Registration::status_id_approved,
1087
-                    false,
1088
-                    'sentence'
1089
-                ),
1090
-            ],
1091
-            'pending_status'    => [
1092
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1093
-                'desc'  => EEH_Template::pretty_status(
1094
-                    EEM_Registration::status_id_pending_payment,
1095
-                    false,
1096
-                    'sentence'
1097
-                ),
1098
-            ],
1099
-            'wait_list'         => [
1100
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1101
-                'desc'  => EEH_Template::pretty_status(
1102
-                    EEM_Registration::status_id_wait_list,
1103
-                    false,
1104
-                    'sentence'
1105
-                ),
1106
-            ],
1107
-            'incomplete_status' => [
1108
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1109
-                'desc'  => EEH_Template::pretty_status(
1110
-                    EEM_Registration::status_id_incomplete,
1111
-                    false,
1112
-                    'sentence'
1113
-                ),
1114
-            ],
1115
-            'not_approved'      => [
1116
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1117
-                'desc'  => EEH_Template::pretty_status(
1118
-                    EEM_Registration::status_id_not_approved,
1119
-                    false,
1120
-                    'sentence'
1121
-                ),
1122
-            ],
1123
-            'declined_status'   => [
1124
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1125
-                'desc'  => EEH_Template::pretty_status(
1126
-                    EEM_Registration::status_id_declined,
1127
-                    false,
1128
-                    'sentence'
1129
-                ),
1130
-            ],
1131
-            'cancelled_status'  => [
1132
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1133
-                'desc'  => EEH_Template::pretty_status(
1134
-                    EEM_Registration::status_id_cancelled,
1135
-                    false,
1136
-                    'sentence'
1137
-                ),
1138
-            ],
1139
-        ];
1140
-        return array_merge($fc_items, $sc_items);
1141
-    }
1142
-
1143
-
1144
-
1145
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1146
-
1147
-
1148
-    /**
1149
-     * @throws DomainException
1150
-     * @throws EE_Error
1151
-     * @throws InvalidArgumentException
1152
-     * @throws InvalidDataTypeException
1153
-     * @throws InvalidInterfaceException
1154
-     */
1155
-    protected function _registrations_overview_list_table()
1156
-    {
1157
-        $this->appendAddNewRegistrationButtonToPageTitle();
1158
-        $header_text                  = '';
1159
-        $admin_page_header_decorators = [
1160
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1161
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1162
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1163
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1164
-        ];
1165
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1166
-            $filter_header_decorator = $this->getLoader()->getNew($admin_page_header_decorator);
1167
-            $header_text             = $filter_header_decorator->getHeaderText($header_text);
1168
-        }
1169
-        $this->_template_args['admin_page_header'] = $header_text;
1170
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1171
-        $this->display_admin_list_table_page_with_no_sidebar();
1172
-    }
1173
-
1174
-
1175
-    /**
1176
-     * @throws EE_Error
1177
-     * @throws InvalidArgumentException
1178
-     * @throws InvalidDataTypeException
1179
-     * @throws InvalidInterfaceException
1180
-     */
1181
-    private function appendAddNewRegistrationButtonToPageTitle()
1182
-    {
1183
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1184
-        if (
1185
-            $EVT_ID
1186
-            && EE_Registry::instance()->CAP->current_user_can(
1187
-                'ee_edit_registrations',
1188
-                'espresso_registrations_new_registration',
1189
-                $EVT_ID
1190
-            )
1191
-        ) {
1192
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1193
-                'new_registration',
1194
-                'add-registrant',
1195
-                ['event_id' => $EVT_ID],
1196
-                'add-new-h2'
1197
-            );
1198
-        }
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * This sets the _registration property for the registration details screen
1204
-     *
1205
-     * @return void
1206
-     * @throws EE_Error
1207
-     * @throws InvalidArgumentException
1208
-     * @throws InvalidDataTypeException
1209
-     * @throws InvalidInterfaceException
1210
-     */
1211
-    private function _set_registration_object()
1212
-    {
1213
-        // get out if we've already set the object
1214
-        if ($this->_registration instanceof EE_Registration) {
1215
-            return;
1216
-        }
1217
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1218
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1219
-            return;
1220
-        }
1221
-        $error_msg = sprintf(
1222
-            esc_html__(
1223
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1224
-                'event_espresso'
1225
-            ),
1226
-            $REG_ID
1227
-        );
1228
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1229
-        $this->_registration = null;
1230
-    }
1231
-
1232
-
1233
-    /**
1234
-     * Used to retrieve registrations for the list table.
1235
-     *
1236
-     * @param int  $per_page
1237
-     * @param bool $count
1238
-     * @param bool $this_month
1239
-     * @param bool $today
1240
-     * @return EE_Registration[]|int
1241
-     * @throws EE_Error
1242
-     * @throws InvalidArgumentException
1243
-     * @throws InvalidDataTypeException
1244
-     * @throws InvalidInterfaceException
1245
-     */
1246
-    public function get_registrations(
1247
-        $per_page = 10,
1248
-        $count = false,
1249
-        $this_month = false,
1250
-        $today = false
1251
-    ) {
1252
-        if ($this_month) {
1253
-            $this->request->setRequestParam('status', 'month');
1254
-        }
1255
-        if ($today) {
1256
-            $this->request->setRequestParam('status', 'today');
1257
-        }
1258
-        $query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1259
-        /**
1260
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1261
-         *
1262
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1263
-         * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1264
-         *                      or if you have the development copy of EE you can view this at the path:
1265
-         *                      /docs/G--Model-System/model-query-params.md
1266
-         */
1267
-        $query_params['group_by'] = '';
1268
-
1269
-        return $count
1270
-            ? $this->getRegistrationModel()->count($query_params)
1271
-            /** @type EE_Registration[] */
1272
-            : $this->getRegistrationModel()->get_all($query_params);
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1278
-     * Note: this listens to values on the request for some of the query parameters.
1279
-     *
1280
-     * @param array $request
1281
-     * @param int   $per_page
1282
-     * @param bool  $count
1283
-     * @return array
1284
-     * @throws EE_Error
1285
-     * @throws InvalidArgumentException
1286
-     * @throws InvalidDataTypeException
1287
-     * @throws InvalidInterfaceException
1288
-     */
1289
-    protected function _get_registration_query_parameters(
1290
-        $request = [],
1291
-        $per_page = 10,
1292
-        $count = false
1293
-    ) {
1294
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1295
-        $list_table_query_builder = $this->getLoader()->getNew(
1296
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1297
-            [null, null, $request]
1298
-        );
1299
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1300
-    }
1301
-
1302
-
1303
-    public function get_registration_status_array()
1304
-    {
1305
-        return self::$_reg_status;
1306
-    }
1307
-
1308
-
1309
-
1310
-
1311
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1312
-    /**
1313
-     * generates HTML for the View Registration Details Admin page
1314
-     *
1315
-     * @return void
1316
-     * @throws DomainException
1317
-     * @throws EE_Error
1318
-     * @throws InvalidArgumentException
1319
-     * @throws InvalidDataTypeException
1320
-     * @throws InvalidInterfaceException
1321
-     * @throws EntityNotFoundException
1322
-     * @throws ReflectionException
1323
-     */
1324
-    protected function _registration_details()
1325
-    {
1326
-        $this->_template_args = [];
1327
-        $this->_set_registration_object();
1328
-        if (is_object($this->_registration)) {
1329
-            $transaction                                   = $this->_registration->transaction()
1330
-                ? $this->_registration->transaction()
1331
-                : EE_Transaction::new_instance();
1332
-            $this->_session                                = $transaction->session_data();
1333
-            $event_id                                      = $this->_registration->event_ID();
1334
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1335
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1336
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1337
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1338
-            $this->_template_args['grand_total']           = $transaction->total();
1339
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1340
-            // link back to overview
1341
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1342
-            $this->_template_args['registration']                = $this->_registration;
1343
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1344
-                [
1345
-                    'action'   => 'default',
1346
-                    'event_id' => $event_id,
1347
-                ],
1348
-                REG_ADMIN_URL
1349
-            );
1350
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1351
-                [
1352
-                    'action' => 'default',
1353
-                    'EVT_ID' => $event_id,
1354
-                    'page'   => 'espresso_transactions',
1355
-                ],
1356
-                admin_url('admin.php')
1357
-            );
1358
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1359
-                [
1360
-                    'page'   => 'espresso_events',
1361
-                    'action' => 'edit',
1362
-                    'post'   => $event_id,
1363
-                ],
1364
-                admin_url('admin.php')
1365
-            );
1366
-            // next and previous links
1367
-            $next_reg                                      = $this->_registration->next(
1368
-                null,
1369
-                [],
1370
-                'REG_ID'
1371
-            );
1372
-            $this->_template_args['next_registration']     = $next_reg
1373
-                ? $this->_next_link(
1374
-                    EE_Admin_Page::add_query_args_and_nonce(
1375
-                        [
1376
-                            'action'  => 'view_registration',
1377
-                            '_REG_ID' => $next_reg['REG_ID'],
1378
-                        ],
1379
-                        REG_ADMIN_URL
1380
-                    ),
1381
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1382
-                )
1383
-                : '';
1384
-            $previous_reg                                  = $this->_registration->previous(
1385
-                null,
1386
-                [],
1387
-                'REG_ID'
1388
-            );
1389
-            $this->_template_args['previous_registration'] = $previous_reg
1390
-                ? $this->_previous_link(
1391
-                    EE_Admin_Page::add_query_args_and_nonce(
1392
-                        [
1393
-                            'action'  => 'view_registration',
1394
-                            '_REG_ID' => $previous_reg['REG_ID'],
1395
-                        ],
1396
-                        REG_ADMIN_URL
1397
-                    ),
1398
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1399
-                )
1400
-                : '';
1401
-            // grab header
1402
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1403
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1404
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1405
-                $template_path,
1406
-                $this->_template_args,
1407
-                true
1408
-            );
1409
-        } else {
1410
-            $this->_template_args['admin_page_header'] = '';
1411
-            $this->_display_espresso_notices();
1412
-        }
1413
-        // the details template wrapper
1414
-        $this->display_admin_page_with_sidebar();
1415
-    }
1416
-
1417
-
1418
-    /**
1419
-     * @throws EE_Error
1420
-     * @throws InvalidArgumentException
1421
-     * @throws InvalidDataTypeException
1422
-     * @throws InvalidInterfaceException
1423
-     * @throws ReflectionException
1424
-     * @since 4.10.2.p
1425
-     */
1426
-    protected function _registration_details_metaboxes()
1427
-    {
1428
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1429
-        $this->_set_registration_object();
1430
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1431
-        add_meta_box(
1432
-            'edit-reg-status-mbox',
1433
-            esc_html__('Registration Status', 'event_espresso'),
1434
-            [$this, 'set_reg_status_buttons_metabox'],
1435
-            $this->_wp_page_slug,
1436
-            'normal',
1437
-            'high'
1438
-        );
1439
-        add_meta_box(
1440
-            'edit-reg-details-mbox',
1441
-            esc_html__('Registration Details', 'event_espresso'),
1442
-            [$this, '_reg_details_meta_box'],
1443
-            $this->_wp_page_slug,
1444
-            'normal',
1445
-            'high'
1446
-        );
1447
-        if (
1448
-            $attendee instanceof EE_Attendee
1449
-            && EE_Registry::instance()->CAP->current_user_can(
1450
-                'ee_read_registration',
1451
-                'edit-reg-questions-mbox',
1452
-                $this->_registration->ID()
1453
-            )
1454
-        ) {
1455
-            add_meta_box(
1456
-                'edit-reg-questions-mbox',
1457
-                esc_html__('Registration Form Answers', 'event_espresso'),
1458
-                [$this, '_reg_questions_meta_box'],
1459
-                $this->_wp_page_slug,
1460
-                'normal',
1461
-                'high'
1462
-            );
1463
-        }
1464
-        add_meta_box(
1465
-            'edit-reg-registrant-mbox',
1466
-            esc_html__('Contact Details', 'event_espresso'),
1467
-            [$this, '_reg_registrant_side_meta_box'],
1468
-            $this->_wp_page_slug,
1469
-            'side',
1470
-            'high'
1471
-        );
1472
-        if ($this->_registration->group_size() > 1) {
1473
-            add_meta_box(
1474
-                'edit-reg-attendees-mbox',
1475
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1476
-                [$this, '_reg_attendees_meta_box'],
1477
-                $this->_wp_page_slug,
1478
-                'normal',
1479
-                'high'
1480
-            );
1481
-        }
1482
-    }
1483
-
1484
-
1485
-    /**
1486
-     * set_reg_status_buttons_metabox
1487
-     *
1488
-     * @return void
1489
-     * @throws EE_Error
1490
-     * @throws EntityNotFoundException
1491
-     * @throws InvalidArgumentException
1492
-     * @throws InvalidDataTypeException
1493
-     * @throws InvalidInterfaceException
1494
-     * @throws ReflectionException
1495
-     */
1496
-    public function set_reg_status_buttons_metabox()
1497
-    {
1498
-        $this->_set_registration_object();
1499
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1500
-        $output                 = $change_reg_status_form->form_open(
1501
-            self::add_query_args_and_nonce(
1502
-                [
1503
-                    'action' => 'change_reg_status',
1504
-                ],
1505
-                REG_ADMIN_URL
1506
-            )
1507
-        );
1508
-        $output                 .= $change_reg_status_form->get_html();
1509
-        $output                 .= $change_reg_status_form->form_close();
1510
-        echo $output; // already escaped
1511
-    }
1512
-
1513
-
1514
-    /**
1515
-     * @return EE_Form_Section_Proper
1516
-     * @throws EE_Error
1517
-     * @throws InvalidArgumentException
1518
-     * @throws InvalidDataTypeException
1519
-     * @throws InvalidInterfaceException
1520
-     * @throws EntityNotFoundException
1521
-     * @throws ReflectionException
1522
-     */
1523
-    protected function _generate_reg_status_change_form()
1524
-    {
1525
-        $reg_status_change_form_array = [
1526
-            'name'            => 'reg_status_change_form',
1527
-            'html_id'         => 'reg-status-change-form',
1528
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1529
-            'subsections'     => [
1530
-                'return'         => new EE_Hidden_Input(
1531
-                    [
1532
-                        'name'    => 'return',
1533
-                        'default' => 'view_registration',
1534
-                    ]
1535
-                ),
1536
-                'REG_ID'         => new EE_Hidden_Input(
1537
-                    [
1538
-                        'name'    => 'REG_ID',
1539
-                        'default' => $this->_registration->ID(),
1540
-                    ]
1541
-                ),
1542
-                'current_status' => new EE_Form_Section_HTML(
1543
-                    EEH_HTML::table(
1544
-                        EEH_HTML::tr(
1545
-                            EEH_HTML::th(
1546
-                                EEH_HTML::label(
1547
-                                    EEH_HTML::strong(
1548
-                                        esc_html__('Current Registration Status', 'event_espresso')
1549
-                                    )
1550
-                                )
1551
-                            )
1552
-                            . EEH_HTML::td(
1553
-                                EEH_HTML::strong(
1554
-                                    $this->_registration->pretty_status(),
1555
-                                    '',
1556
-                                    'status-' . $this->_registration->status_ID(),
1557
-                                    'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1558
-                                )
1559
-                            )
1560
-                        )
1561
-                    )
1562
-                ),
1563
-            ],
1564
-        ];
1565
-        if (
1566
-            EE_Registry::instance()->CAP->current_user_can(
1567
-                'ee_edit_registration',
1568
-                'toggle_registration_status',
1569
-                $this->_registration->ID()
1570
-            )
1571
-        ) {
1572
-            $reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1573
-                $this->_get_reg_statuses(),
1574
-                [
1575
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1576
-                    'default'         => $this->_registration->status_ID(),
1577
-                ]
1578
-            );
1579
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1580
-                [
1581
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1582
-                    'default'         => false,
1583
-                    'html_help_text'  => esc_html__(
1584
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1585
-                        'event_espresso'
1586
-                    ),
1587
-                ]
1588
-            );
1589
-            $reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1590
-                [
1591
-                    'html_class'      => 'button-primary',
1592
-                    'html_label_text' => '&nbsp;',
1593
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1594
-                ]
1595
-            );
1596
-        }
1597
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1598
-    }
1599
-
1600
-
1601
-    /**
1602
-     * Returns an array of all the buttons for the various statuses and switch status actions
1603
-     *
1604
-     * @return array
1605
-     * @throws EE_Error
1606
-     * @throws InvalidArgumentException
1607
-     * @throws InvalidDataTypeException
1608
-     * @throws InvalidInterfaceException
1609
-     * @throws EntityNotFoundException
1610
-     */
1611
-    protected function _get_reg_statuses()
1612
-    {
1613
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1614
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1615
-        // get current reg status
1616
-        $current_status = $this->_registration->status_ID();
1617
-        // is registration for free event? This will determine whether to display the pending payment option
1618
-        if (
1619
-            $current_status !== EEM_Registration::status_id_pending_payment
1620
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1621
-        ) {
1622
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1623
-        }
1624
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1625
-    }
1626
-
1627
-
1628
-    /**
1629
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1630
-     *
1631
-     * @param bool $status REG status given for changing registrations to.
1632
-     * @param bool $notify Whether to send messages notifications or not.
1633
-     * @return array (array with reg_id(s) updated and whether update was successful.
1634
-     * @throws DomainException
1635
-     * @throws EE_Error
1636
-     * @throws EntityNotFoundException
1637
-     * @throws InvalidArgumentException
1638
-     * @throws InvalidDataTypeException
1639
-     * @throws InvalidInterfaceException
1640
-     * @throws ReflectionException
1641
-     * @throws RuntimeException
1642
-     */
1643
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1644
-    {
1645
-        $REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1646
-            ? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1647
-            : $this->request->getRequestParam('_REG_ID', [], 'int', true);
1648
-
1649
-        // sanitize $REG_IDs
1650
-        $REG_IDs = array_map('absint', $REG_IDs);
1651
-        // and remove empty entries
1652
-        $REG_IDs = array_filter($REG_IDs);
1653
-
1654
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1655
-
1656
-        /**
1657
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1658
-         * Currently this value is used downstream by the _process_resend_registration method.
1659
-         *
1660
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1661
-         * @param bool                     $status           The status registrations were changed to.
1662
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1663
-         * @param Registrations_Admin_Page $admin_page_object
1664
-         */
1665
-        $REG_ID = apply_filters(
1666
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1667
-            $result['REG_ID'],
1668
-            $status,
1669
-            $result['success'],
1670
-            $this
1671
-        );
1672
-        $this->request->setRequestParam('_REG_ID', $REG_ID);
1673
-
1674
-        // notify?
1675
-        if (
1676
-            $notify
1677
-            && $result['success']
1678
-            && ! empty($REG_ID)
1679
-            && EE_Registry::instance()->CAP->current_user_can(
1680
-                'ee_send_message',
1681
-                'espresso_registrations_resend_registration'
1682
-            )
1683
-        ) {
1684
-            $this->_process_resend_registration();
1685
-        }
1686
-        return $result;
1687
-    }
1688
-
1689
-
1690
-    /**
1691
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1692
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1693
-     *
1694
-     * @param array  $REG_IDs
1695
-     * @param string $status
1696
-     * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1697
-     *                       slug sent with setting the registration status.
1698
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1699
-     * @throws EE_Error
1700
-     * @throws InvalidArgumentException
1701
-     * @throws InvalidDataTypeException
1702
-     * @throws InvalidInterfaceException
1703
-     * @throws ReflectionException
1704
-     * @throws RuntimeException
1705
-     * @throws EntityNotFoundException
1706
-     * @throws DomainException
1707
-     */
1708
-    protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1709
-    {
1710
-        $success = false;
1711
-        // typecast $REG_IDs
1712
-        $REG_IDs = (array) $REG_IDs;
1713
-        if (! empty($REG_IDs)) {
1714
-            $success = true;
1715
-            // set default status if none is passed
1716
-            $status         = $status ?: EEM_Registration::status_id_pending_payment;
1717
-            $status_context = $notify
1718
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1719
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1720
-            // loop through REG_ID's and change status
1721
-            foreach ($REG_IDs as $REG_ID) {
1722
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1723
-                if ($registration instanceof EE_Registration) {
1724
-                    $registration->set_status(
1725
-                        $status,
1726
-                        false,
1727
-                        new Context(
1728
-                            $status_context,
1729
-                            esc_html__(
1730
-                                'Manually triggered status change on a Registration Admin Page route.',
1731
-                                'event_espresso'
1732
-                            )
1733
-                        )
1734
-                    );
1735
-                    $result = $registration->save();
1736
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1737
-                    $success = $result !== false ? $success : false;
1738
-                }
1739
-            }
1740
-        }
1741
-
1742
-        // return $success and processed registrations
1743
-        return ['REG_ID' => $REG_IDs, 'success' => $success];
1744
-    }
1745
-
1746
-
1747
-    /**
1748
-     * Common logic for setting up success message and redirecting to appropriate route
1749
-     *
1750
-     * @param string $STS_ID status id for the registration changed to
1751
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1752
-     * @return void
1753
-     * @throws DomainException
1754
-     * @throws EE_Error
1755
-     * @throws EntityNotFoundException
1756
-     * @throws InvalidArgumentException
1757
-     * @throws InvalidDataTypeException
1758
-     * @throws InvalidInterfaceException
1759
-     * @throws ReflectionException
1760
-     * @throws RuntimeException
1761
-     */
1762
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1763
-    {
1764
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1765
-            : ['success' => false];
1766
-        $success = isset($result['success']) && $result['success'];
1767
-        // setup success message
1768
-        if ($success) {
1769
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1770
-                $msg = sprintf(
1771
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1772
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1773
-                );
1774
-            } else {
1775
-                $msg = sprintf(
1776
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1777
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1778
-                );
1779
-            }
1780
-            EE_Error::add_success($msg);
1781
-        } else {
1782
-            EE_Error::add_error(
1783
-                esc_html__(
1784
-                    'Something went wrong, and the status was not changed',
1785
-                    'event_espresso'
1786
-                ),
1787
-                __FILE__,
1788
-                __LINE__,
1789
-                __FUNCTION__
1790
-            );
1791
-        }
1792
-        $return = $this->request->getRequestParam('return');
1793
-        $route  = $return === 'view_registration'
1794
-            ? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1795
-            : ['action' => 'default'];
1796
-        $route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1797
-        $this->_redirect_after_action($success, '', '', $route, true);
1798
-    }
1799
-
1800
-
1801
-    /**
1802
-     * incoming reg status change from reg details page.
1803
-     *
1804
-     * @return void
1805
-     * @throws EE_Error
1806
-     * @throws EntityNotFoundException
1807
-     * @throws InvalidArgumentException
1808
-     * @throws InvalidDataTypeException
1809
-     * @throws InvalidInterfaceException
1810
-     * @throws ReflectionException
1811
-     * @throws RuntimeException
1812
-     * @throws DomainException
1813
-     */
1814
-    protected function _change_reg_status()
1815
-    {
1816
-        $this->request->setRequestParam('return', 'view_registration');
1817
-        // set notify based on whether the send notifications toggle is set or not
1818
-        $notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1819
-        $reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1820
-        $this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1821
-        switch ($reg_status) {
1822
-            case EEM_Registration::status_id_approved:
1823
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1824
-                $this->approve_registration($notify);
1825
-                break;
1826
-            case EEM_Registration::status_id_pending_payment:
1827
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1828
-                $this->pending_registration($notify);
1829
-                break;
1830
-            case EEM_Registration::status_id_not_approved:
1831
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1832
-                $this->not_approve_registration($notify);
1833
-                break;
1834
-            case EEM_Registration::status_id_declined:
1835
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1836
-                $this->decline_registration($notify);
1837
-                break;
1838
-            case EEM_Registration::status_id_cancelled:
1839
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1840
-                $this->cancel_registration($notify);
1841
-                break;
1842
-            case EEM_Registration::status_id_wait_list:
1843
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1844
-                $this->wait_list_registration($notify);
1845
-                break;
1846
-            case EEM_Registration::status_id_incomplete:
1847
-            default:
1848
-                $this->request->unSetRequestParam('return');
1849
-                $this->_reg_status_change_return('');
1850
-                break;
1851
-        }
1852
-    }
1853
-
1854
-
1855
-    /**
1856
-     * Callback for bulk action routes.
1857
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1858
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1859
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1860
-     * when an action is happening on just a single registration).
1861
-     *
1862
-     * @param      $action
1863
-     * @param bool $notify
1864
-     */
1865
-    protected function bulk_action_on_registrations($action, $notify = false)
1866
-    {
1867
-        do_action(
1868
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1869
-            $this,
1870
-            $action,
1871
-            $notify
1872
-        );
1873
-        $method = $action . '_registration';
1874
-        if (method_exists($this, $method)) {
1875
-            $this->$method($notify);
1876
-        }
1877
-    }
1878
-
1879
-
1880
-    /**
1881
-     * approve_registration
1882
-     *
1883
-     * @param bool $notify whether or not to notify the registrant about their approval.
1884
-     * @return void
1885
-     * @throws EE_Error
1886
-     * @throws EntityNotFoundException
1887
-     * @throws InvalidArgumentException
1888
-     * @throws InvalidDataTypeException
1889
-     * @throws InvalidInterfaceException
1890
-     * @throws ReflectionException
1891
-     * @throws RuntimeException
1892
-     * @throws DomainException
1893
-     */
1894
-    protected function approve_registration($notify = false)
1895
-    {
1896
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1897
-    }
1898
-
1899
-
1900
-    /**
1901
-     * decline_registration
1902
-     *
1903
-     * @param bool $notify whether or not to notify the registrant about their status change.
1904
-     * @return void
1905
-     * @throws EE_Error
1906
-     * @throws EntityNotFoundException
1907
-     * @throws InvalidArgumentException
1908
-     * @throws InvalidDataTypeException
1909
-     * @throws InvalidInterfaceException
1910
-     * @throws ReflectionException
1911
-     * @throws RuntimeException
1912
-     * @throws DomainException
1913
-     */
1914
-    protected function decline_registration($notify = false)
1915
-    {
1916
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1917
-    }
1918
-
1919
-
1920
-    /**
1921
-     * cancel_registration
1922
-     *
1923
-     * @param bool $notify whether or not to notify the registrant about their status change.
1924
-     * @return void
1925
-     * @throws EE_Error
1926
-     * @throws EntityNotFoundException
1927
-     * @throws InvalidArgumentException
1928
-     * @throws InvalidDataTypeException
1929
-     * @throws InvalidInterfaceException
1930
-     * @throws ReflectionException
1931
-     * @throws RuntimeException
1932
-     * @throws DomainException
1933
-     */
1934
-    protected function cancel_registration($notify = false)
1935
-    {
1936
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1937
-    }
1938
-
1939
-
1940
-    /**
1941
-     * not_approve_registration
1942
-     *
1943
-     * @param bool $notify whether or not to notify the registrant about their status change.
1944
-     * @return void
1945
-     * @throws EE_Error
1946
-     * @throws EntityNotFoundException
1947
-     * @throws InvalidArgumentException
1948
-     * @throws InvalidDataTypeException
1949
-     * @throws InvalidInterfaceException
1950
-     * @throws ReflectionException
1951
-     * @throws RuntimeException
1952
-     * @throws DomainException
1953
-     */
1954
-    protected function not_approve_registration($notify = false)
1955
-    {
1956
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1957
-    }
1958
-
1959
-
1960
-    /**
1961
-     * decline_registration
1962
-     *
1963
-     * @param bool $notify whether or not to notify the registrant about their status change.
1964
-     * @return void
1965
-     * @throws EE_Error
1966
-     * @throws EntityNotFoundException
1967
-     * @throws InvalidArgumentException
1968
-     * @throws InvalidDataTypeException
1969
-     * @throws InvalidInterfaceException
1970
-     * @throws ReflectionException
1971
-     * @throws RuntimeException
1972
-     * @throws DomainException
1973
-     */
1974
-    protected function pending_registration($notify = false)
1975
-    {
1976
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1977
-    }
1978
-
1979
-
1980
-    /**
1981
-     * waitlist_registration
1982
-     *
1983
-     * @param bool $notify whether or not to notify the registrant about their status change.
1984
-     * @return void
1985
-     * @throws EE_Error
1986
-     * @throws EntityNotFoundException
1987
-     * @throws InvalidArgumentException
1988
-     * @throws InvalidDataTypeException
1989
-     * @throws InvalidInterfaceException
1990
-     * @throws ReflectionException
1991
-     * @throws RuntimeException
1992
-     * @throws DomainException
1993
-     */
1994
-    protected function wait_list_registration($notify = false)
1995
-    {
1996
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1997
-    }
1998
-
1999
-
2000
-    /**
2001
-     * generates HTML for the Registration main meta box
2002
-     *
2003
-     * @return void
2004
-     * @throws DomainException
2005
-     * @throws EE_Error
2006
-     * @throws InvalidArgumentException
2007
-     * @throws InvalidDataTypeException
2008
-     * @throws InvalidInterfaceException
2009
-     * @throws ReflectionException
2010
-     * @throws EntityNotFoundException
2011
-     */
2012
-    public function _reg_details_meta_box()
2013
-    {
2014
-        EEH_Autoloader::register_line_item_display_autoloaders();
2015
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2016
-        EE_Registry::instance()->load_helper('Line_Item');
2017
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2018
-            : EE_Transaction::new_instance();
2019
-        $this->_session = $transaction->session_data();
2020
-        $filters        = new EE_Line_Item_Filter_Collection();
2021
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2022
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
2023
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2024
-            $filters,
2025
-            $transaction->total_line_item()
2026
-        );
2027
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2028
-        $line_item_display                       = new EE_Line_Item_Display(
2029
-            'reg_admin_table',
2030
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2031
-        );
2032
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2033
-            $filtered_line_item_tree,
2034
-            ['EE_Registration' => $this->_registration]
2035
-        );
2036
-        $attendee                                = $this->_registration->attendee();
2037
-        if (
2038
-            EE_Registry::instance()->CAP->current_user_can(
2039
-                'ee_read_transaction',
2040
-                'espresso_transactions_view_transaction'
2041
-            )
2042
-        ) {
2043
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2044
-                EE_Admin_Page::add_query_args_and_nonce(
2045
-                    [
2046
-                        'action' => 'view_transaction',
2047
-                        'TXN_ID' => $transaction->ID(),
2048
-                    ],
2049
-                    TXN_ADMIN_URL
2050
-                ),
2051
-                esc_html__(' View Transaction', 'event_espresso'),
2052
-                'button secondary-button right',
2053
-                'dashicons dashicons-cart'
2054
-            );
2055
-        } else {
2056
-            $this->_template_args['view_transaction_button'] = '';
2057
-        }
2058
-        if (
2059
-            $attendee instanceof EE_Attendee
2060
-            && EE_Registry::instance()->CAP->current_user_can(
2061
-                'ee_send_message',
2062
-                'espresso_registrations_resend_registration'
2063
-            )
2064
-        ) {
2065
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2066
-                EE_Admin_Page::add_query_args_and_nonce(
2067
-                    [
2068
-                        'action'      => 'resend_registration',
2069
-                        '_REG_ID'     => $this->_registration->ID(),
2070
-                        'redirect_to' => 'view_registration',
2071
-                    ],
2072
-                    REG_ADMIN_URL
2073
-                ),
2074
-                esc_html__(' Resend Registration', 'event_espresso'),
2075
-                'button secondary-button right',
2076
-                'dashicons dashicons-email-alt'
2077
-            );
2078
-        } else {
2079
-            $this->_template_args['resend_registration_button'] = '';
2080
-        }
2081
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2082
-        $payment                               = $transaction->get_first_related('Payment');
2083
-        $payment                               = ! $payment instanceof EE_Payment
2084
-            ? EE_Payment::new_instance()
2085
-            : $payment;
2086
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2087
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2088
-            ? EE_Payment_Method::new_instance()
2089
-            : $payment_method;
2090
-        $reg_details                           = [
2091
-            'payment_method'       => $payment_method->name(),
2092
-            'response_msg'         => $payment->gateway_response(),
2093
-            'registration_id'      => $this->_registration->get('REG_code'),
2094
-            'registration_session' => $this->_registration->session_ID(),
2095
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2096
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2097
-        ];
2098
-        if (isset($reg_details['registration_id'])) {
2099
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2100
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2101
-                'Registration ID',
2102
-                'event_espresso'
2103
-            );
2104
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2105
-        }
2106
-        if (isset($reg_details['payment_method'])) {
2107
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2108
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2109
-                'Most Recent Payment Method',
2110
-                'event_espresso'
2111
-            );
2112
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2113
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2114
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2115
-                'Payment method response',
2116
-                'event_espresso'
2117
-            );
2118
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2119
-        }
2120
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2121
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2122
-            'Registration Session',
2123
-            'event_espresso'
2124
-        );
2125
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2126
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2127
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2128
-            'Registration placed from IP',
2129
-            'event_espresso'
2130
-        );
2131
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2132
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2133
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2134
-            'Registrant User Agent',
2135
-            'event_espresso'
2136
-        );
2137
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2138
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2139
-            [
2140
-                'action'   => 'default',
2141
-                'event_id' => $this->_registration->event_ID(),
2142
-            ],
2143
-            REG_ADMIN_URL
2144
-        );
2145
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2146
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2147
-        $template_path                                                        =
2148
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2149
-        EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2150
-    }
2151
-
2152
-
2153
-    /**
2154
-     * generates HTML for the Registration Questions meta box.
2155
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2156
-     * otherwise uses new forms system
2157
-     *
2158
-     * @return void
2159
-     * @throws DomainException
2160
-     * @throws EE_Error
2161
-     * @throws InvalidArgumentException
2162
-     * @throws InvalidDataTypeException
2163
-     * @throws InvalidInterfaceException
2164
-     * @throws ReflectionException
2165
-     */
2166
-    public function _reg_questions_meta_box()
2167
-    {
2168
-        // allow someone to override this method entirely
2169
-        if (
2170
-            apply_filters(
2171
-                'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2172
-                true,
2173
-                $this,
2174
-                $this->_registration
2175
-            )
2176
-        ) {
2177
-            $form                                              = $this->_get_reg_custom_questions_form(
2178
-                $this->_registration->ID()
2179
-            );
2180
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2181
-                ? $form->get_html_and_js()
2182
-                : '';
2183
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2184
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2185
-            $template_path                                     =
2186
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2187
-            EEH_Template::display_template($template_path, $this->_template_args);
2188
-        }
2189
-    }
2190
-
2191
-
2192
-    /**
2193
-     * form_before_question_group
2194
-     *
2195
-     * @param string $output
2196
-     * @return        string
2197
-     * @deprecated    as of 4.8.32.rc.000
2198
-     */
2199
-    public function form_before_question_group($output)
2200
-    {
2201
-        EE_Error::doing_it_wrong(
2202
-            __CLASS__ . '::' . __FUNCTION__,
2203
-            esc_html__(
2204
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2205
-                'event_espresso'
2206
-            ),
2207
-            '4.8.32.rc.000'
2208
-        );
2209
-        return '
22
+	/**
23
+	 * @var EE_Registration
24
+	 */
25
+	private $_registration;
26
+
27
+	/**
28
+	 * @var EE_Event
29
+	 */
30
+	private $_reg_event;
31
+
32
+	/**
33
+	 * @var EE_Session
34
+	 */
35
+	private $_session;
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	private static $_reg_status;
41
+
42
+	/**
43
+	 * Form for displaying the custom questions for this registration.
44
+	 * This gets used a few times throughout the request so its best to cache it
45
+	 *
46
+	 * @var EE_Registration_Custom_Questions_Form
47
+	 */
48
+	protected $_reg_custom_questions_form = null;
49
+
50
+	/**
51
+	 * @var EEM_Registration $registration_model
52
+	 */
53
+	private $registration_model;
54
+
55
+	/**
56
+	 * @var EEM_Attendee $attendee_model
57
+	 */
58
+	private $attendee_model;
59
+
60
+	/**
61
+	 * @var EEM_Event $event_model
62
+	 */
63
+	private $event_model;
64
+
65
+	/**
66
+	 * @var EEM_Status $status_model
67
+	 */
68
+	private $status_model;
69
+
70
+
71
+	/**
72
+	 * @param bool $routing
73
+	 * @throws EE_Error
74
+	 * @throws InvalidArgumentException
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws ReflectionException
78
+	 */
79
+	public function __construct($routing = true)
80
+	{
81
+		parent::__construct($routing);
82
+		add_action('wp_loaded', [$this, 'wp_loaded']);
83
+	}
84
+
85
+
86
+	/**
87
+	 * @return EEM_Registration
88
+	 * @throws InvalidArgumentException
89
+	 * @throws InvalidDataTypeException
90
+	 * @throws InvalidInterfaceException
91
+	 * @since 4.10.2.p
92
+	 */
93
+	protected function getRegistrationModel()
94
+	{
95
+		if (! $this->registration_model instanceof EEM_Registration) {
96
+			$this->registration_model = $this->getLoader()->getShared('EEM_Registration');
97
+		}
98
+		return $this->registration_model;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return EEM_Attendee
104
+	 * @throws InvalidArgumentException
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidInterfaceException
107
+	 * @since 4.10.2.p
108
+	 */
109
+	protected function getAttendeeModel()
110
+	{
111
+		if (! $this->attendee_model instanceof EEM_Attendee) {
112
+			$this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
113
+		}
114
+		return $this->attendee_model;
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return EEM_Event
120
+	 * @throws InvalidArgumentException
121
+	 * @throws InvalidDataTypeException
122
+	 * @throws InvalidInterfaceException
123
+	 * @since 4.10.2.p
124
+	 */
125
+	protected function getEventModel()
126
+	{
127
+		if (! $this->event_model instanceof EEM_Event) {
128
+			$this->event_model = $this->getLoader()->getShared('EEM_Event');
129
+		}
130
+		return $this->event_model;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return EEM_Status
136
+	 * @throws InvalidArgumentException
137
+	 * @throws InvalidDataTypeException
138
+	 * @throws InvalidInterfaceException
139
+	 * @since 4.10.2.p
140
+	 */
141
+	protected function getStatusModel()
142
+	{
143
+		if (! $this->status_model instanceof EEM_Status) {
144
+			$this->status_model = $this->getLoader()->getShared('EEM_Status');
145
+		}
146
+		return $this->status_model;
147
+	}
148
+
149
+
150
+	public function wp_loaded()
151
+	{
152
+		// when adding a new registration...
153
+		$action = $this->request->getRequestParam('action');
154
+		if ($action === 'new_registration') {
155
+			EE_System::do_not_cache();
156
+			if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
157
+				// and it's NOT the attendee information reg step
158
+				// force cookie expiration by setting time to last week
159
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
160
+				// and update the global
161
+				$_COOKIE['ee_registration_added'] = 0;
162
+			}
163
+		}
164
+	}
165
+
166
+
167
+	protected function _init_page_props()
168
+	{
169
+		$this->page_slug        = REG_PG_SLUG;
170
+		$this->_admin_base_url  = REG_ADMIN_URL;
171
+		$this->_admin_base_path = REG_ADMIN;
172
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
173
+		$this->_cpt_routes      = [
174
+			'add_new_attendee' => 'espresso_attendees',
175
+			'edit_attendee'    => 'espresso_attendees',
176
+			'insert_attendee'  => 'espresso_attendees',
177
+			'update_attendee'  => 'espresso_attendees',
178
+		];
179
+		$this->_cpt_model_names = [
180
+			'add_new_attendee' => 'EEM_Attendee',
181
+			'edit_attendee'    => 'EEM_Attendee',
182
+		];
183
+		$this->_cpt_edit_routes = [
184
+			'espresso_attendees' => 'edit_attendee',
185
+		];
186
+		$this->_pagenow_map     = [
187
+			'add_new_attendee' => 'post-new.php',
188
+			'edit_attendee'    => 'post.php',
189
+			'trash'            => 'post.php',
190
+		];
191
+		add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
192
+		// add filters so that the comment urls don't take users to a confusing 404 page
193
+		add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
194
+	}
195
+
196
+
197
+	/**
198
+	 * @param string     $link    The comment permalink with '#comment-$id' appended.
199
+	 * @param WP_Comment $comment The current comment object.
200
+	 * @return string
201
+	 */
202
+	public function clear_comment_link($link, WP_Comment $comment)
203
+	{
204
+		// gotta make sure this only happens on this route
205
+		$post_type = get_post_type($comment->comment_post_ID);
206
+		if ($post_type === 'espresso_attendees') {
207
+			return '#commentsdiv';
208
+		}
209
+		return $link;
210
+	}
211
+
212
+
213
+	protected function _ajax_hooks()
214
+	{
215
+		// todo: all hooks for registrations ajax goes in here
216
+		add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
217
+	}
218
+
219
+
220
+	protected function _define_page_props()
221
+	{
222
+		$this->_admin_page_title = $this->page_label;
223
+		$this->_labels           = [
224
+			'buttons'                      => [
225
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
226
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
227
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
228
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
229
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
230
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
231
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
+			],
234
+			'publishbox'                   => [
235
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
+			],
238
+			'hide_add_button_on_cpt_route' => [
239
+				'edit_attendee' => true,
240
+			],
241
+		];
242
+	}
243
+
244
+
245
+	/**
246
+	 * grab url requests and route them
247
+	 *
248
+	 * @return void
249
+	 * @throws EE_Error
250
+	 */
251
+	public function _set_page_routes()
252
+	{
253
+		$this->_get_registration_status_array();
254
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
+		$REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
+		$ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
+		$this->_page_routes = [
259
+			'default'                             => [
260
+				'func'       => '_registrations_overview_list_table',
261
+				'capability' => 'ee_read_registrations',
262
+			],
263
+			'view_registration'                   => [
264
+				'func'       => '_registration_details',
265
+				'capability' => 'ee_read_registration',
266
+				'obj_id'     => $REG_ID,
267
+			],
268
+			'edit_registration'                   => [
269
+				'func'               => '_update_attendee_registration_form',
270
+				'noheader'           => true,
271
+				'headers_sent_route' => 'view_registration',
272
+				'capability'         => 'ee_edit_registration',
273
+				'obj_id'             => $REG_ID,
274
+				'_REG_ID'            => $REG_ID,
275
+			],
276
+			'trash_registrations'                 => [
277
+				'func'       => '_trash_or_restore_registrations',
278
+				'args'       => ['trash' => true],
279
+				'noheader'   => true,
280
+				'capability' => 'ee_delete_registrations',
281
+			],
282
+			'restore_registrations'               => [
283
+				'func'       => '_trash_or_restore_registrations',
284
+				'args'       => ['trash' => false],
285
+				'noheader'   => true,
286
+				'capability' => 'ee_delete_registrations',
287
+			],
288
+			'delete_registrations'                => [
289
+				'func'       => '_delete_registrations',
290
+				'noheader'   => true,
291
+				'capability' => 'ee_delete_registrations',
292
+			],
293
+			'new_registration'                    => [
294
+				'func'       => 'new_registration',
295
+				'capability' => 'ee_edit_registrations',
296
+			],
297
+			'process_reg_step'                    => [
298
+				'func'       => 'process_reg_step',
299
+				'noheader'   => true,
300
+				'capability' => 'ee_edit_registrations',
301
+			],
302
+			'redirect_to_txn'                     => [
303
+				'func'       => 'redirect_to_txn',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+			],
307
+			'change_reg_status'                   => [
308
+				'func'       => '_change_reg_status',
309
+				'noheader'   => true,
310
+				'capability' => 'ee_edit_registration',
311
+				'obj_id'     => $REG_ID,
312
+			],
313
+			'approve_registration'                => [
314
+				'func'       => 'approve_registration',
315
+				'noheader'   => true,
316
+				'capability' => 'ee_edit_registration',
317
+				'obj_id'     => $REG_ID,
318
+			],
319
+			'approve_and_notify_registration'     => [
320
+				'func'       => 'approve_registration',
321
+				'noheader'   => true,
322
+				'args'       => [true],
323
+				'capability' => 'ee_edit_registration',
324
+				'obj_id'     => $REG_ID,
325
+			],
326
+			'approve_registrations'               => [
327
+				'func'       => 'bulk_action_on_registrations',
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_registrations',
330
+				'args'       => ['approve'],
331
+			],
332
+			'approve_and_notify_registrations'    => [
333
+				'func'       => 'bulk_action_on_registrations',
334
+				'noheader'   => true,
335
+				'capability' => 'ee_edit_registrations',
336
+				'args'       => ['approve', true],
337
+			],
338
+			'decline_registration'                => [
339
+				'func'       => 'decline_registration',
340
+				'noheader'   => true,
341
+				'capability' => 'ee_edit_registration',
342
+				'obj_id'     => $REG_ID,
343
+			],
344
+			'decline_and_notify_registration'     => [
345
+				'func'       => 'decline_registration',
346
+				'noheader'   => true,
347
+				'args'       => [true],
348
+				'capability' => 'ee_edit_registration',
349
+				'obj_id'     => $REG_ID,
350
+			],
351
+			'decline_registrations'               => [
352
+				'func'       => 'bulk_action_on_registrations',
353
+				'noheader'   => true,
354
+				'capability' => 'ee_edit_registrations',
355
+				'args'       => ['decline'],
356
+			],
357
+			'decline_and_notify_registrations'    => [
358
+				'func'       => 'bulk_action_on_registrations',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_edit_registrations',
361
+				'args'       => ['decline', true],
362
+			],
363
+			'pending_registration'                => [
364
+				'func'       => 'pending_registration',
365
+				'noheader'   => true,
366
+				'capability' => 'ee_edit_registration',
367
+				'obj_id'     => $REG_ID,
368
+			],
369
+			'pending_and_notify_registration'     => [
370
+				'func'       => 'pending_registration',
371
+				'noheader'   => true,
372
+				'args'       => [true],
373
+				'capability' => 'ee_edit_registration',
374
+				'obj_id'     => $REG_ID,
375
+			],
376
+			'pending_registrations'               => [
377
+				'func'       => 'bulk_action_on_registrations',
378
+				'noheader'   => true,
379
+				'capability' => 'ee_edit_registrations',
380
+				'args'       => ['pending'],
381
+			],
382
+			'pending_and_notify_registrations'    => [
383
+				'func'       => 'bulk_action_on_registrations',
384
+				'noheader'   => true,
385
+				'capability' => 'ee_edit_registrations',
386
+				'args'       => ['pending', true],
387
+			],
388
+			'no_approve_registration'             => [
389
+				'func'       => 'not_approve_registration',
390
+				'noheader'   => true,
391
+				'capability' => 'ee_edit_registration',
392
+				'obj_id'     => $REG_ID,
393
+			],
394
+			'no_approve_and_notify_registration'  => [
395
+				'func'       => 'not_approve_registration',
396
+				'noheader'   => true,
397
+				'args'       => [true],
398
+				'capability' => 'ee_edit_registration',
399
+				'obj_id'     => $REG_ID,
400
+			],
401
+			'no_approve_registrations'            => [
402
+				'func'       => 'bulk_action_on_registrations',
403
+				'noheader'   => true,
404
+				'capability' => 'ee_edit_registrations',
405
+				'args'       => ['not_approve'],
406
+			],
407
+			'no_approve_and_notify_registrations' => [
408
+				'func'       => 'bulk_action_on_registrations',
409
+				'noheader'   => true,
410
+				'capability' => 'ee_edit_registrations',
411
+				'args'       => ['not_approve', true],
412
+			],
413
+			'cancel_registration'                 => [
414
+				'func'       => 'cancel_registration',
415
+				'noheader'   => true,
416
+				'capability' => 'ee_edit_registration',
417
+				'obj_id'     => $REG_ID,
418
+			],
419
+			'cancel_and_notify_registration'      => [
420
+				'func'       => 'cancel_registration',
421
+				'noheader'   => true,
422
+				'args'       => [true],
423
+				'capability' => 'ee_edit_registration',
424
+				'obj_id'     => $REG_ID,
425
+			],
426
+			'cancel_registrations'                => [
427
+				'func'       => 'bulk_action_on_registrations',
428
+				'noheader'   => true,
429
+				'capability' => 'ee_edit_registrations',
430
+				'args'       => ['cancel'],
431
+			],
432
+			'cancel_and_notify_registrations'     => [
433
+				'func'       => 'bulk_action_on_registrations',
434
+				'noheader'   => true,
435
+				'capability' => 'ee_edit_registrations',
436
+				'args'       => ['cancel', true],
437
+			],
438
+			'wait_list_registration'              => [
439
+				'func'       => 'wait_list_registration',
440
+				'noheader'   => true,
441
+				'capability' => 'ee_edit_registration',
442
+				'obj_id'     => $REG_ID,
443
+			],
444
+			'wait_list_and_notify_registration'   => [
445
+				'func'       => 'wait_list_registration',
446
+				'noheader'   => true,
447
+				'args'       => [true],
448
+				'capability' => 'ee_edit_registration',
449
+				'obj_id'     => $REG_ID,
450
+			],
451
+			'contact_list'                        => [
452
+				'func'       => '_attendee_contact_list_table',
453
+				'capability' => 'ee_read_contacts',
454
+			],
455
+			'add_new_attendee'                    => [
456
+				'func' => '_create_new_cpt_item',
457
+				'args' => [
458
+					'new_attendee' => true,
459
+					'capability'   => 'ee_edit_contacts',
460
+				],
461
+			],
462
+			'edit_attendee'                       => [
463
+				'func'       => '_edit_cpt_item',
464
+				'capability' => 'ee_edit_contacts',
465
+				'obj_id'     => $ATT_ID,
466
+			],
467
+			'duplicate_attendee'                  => [
468
+				'func'       => '_duplicate_attendee',
469
+				'noheader'   => true,
470
+				'capability' => 'ee_edit_contacts',
471
+				'obj_id'     => $ATT_ID,
472
+			],
473
+			'insert_attendee'                     => [
474
+				'func'       => '_insert_or_update_attendee',
475
+				'args'       => [
476
+					'new_attendee' => true,
477
+				],
478
+				'noheader'   => true,
479
+				'capability' => 'ee_edit_contacts',
480
+			],
481
+			'update_attendee'                     => [
482
+				'func'       => '_insert_or_update_attendee',
483
+				'args'       => [
484
+					'new_attendee' => false,
485
+				],
486
+				'noheader'   => true,
487
+				'capability' => 'ee_edit_contacts',
488
+				'obj_id'     => $ATT_ID,
489
+			],
490
+			'trash_attendees'                     => [
491
+				'func'       => '_trash_or_restore_attendees',
492
+				'args'       => [
493
+					'trash' => 'true',
494
+				],
495
+				'noheader'   => true,
496
+				'capability' => 'ee_delete_contacts',
497
+			],
498
+			'trash_attendee'                      => [
499
+				'func'       => '_trash_or_restore_attendees',
500
+				'args'       => [
501
+					'trash' => true,
502
+				],
503
+				'noheader'   => true,
504
+				'capability' => 'ee_delete_contacts',
505
+				'obj_id'     => $ATT_ID,
506
+			],
507
+			'restore_attendees'                   => [
508
+				'func'       => '_trash_or_restore_attendees',
509
+				'args'       => [
510
+					'trash' => false,
511
+				],
512
+				'noheader'   => true,
513
+				'capability' => 'ee_delete_contacts',
514
+				'obj_id'     => $ATT_ID,
515
+			],
516
+			'resend_registration'                 => [
517
+				'func'       => '_resend_registration',
518
+				'noheader'   => true,
519
+				'capability' => 'ee_send_message',
520
+			],
521
+			'registrations_report'                => [
522
+				'func'       => '_registrations_report',
523
+				'noheader'   => true,
524
+				'capability' => 'ee_read_registrations',
525
+			],
526
+			'contact_list_export'                 => [
527
+				'func'       => '_contact_list_export',
528
+				'noheader'   => true,
529
+				'capability' => 'export',
530
+			],
531
+			'contact_list_report'                 => [
532
+				'func'       => '_contact_list_report',
533
+				'noheader'   => true,
534
+				'capability' => 'ee_read_contacts',
535
+			],
536
+		];
537
+	}
538
+
539
+
540
+	protected function _set_page_config()
541
+	{
542
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
+		$this->_page_config = [
545
+			'default'           => [
546
+				'nav'           => [
547
+					'label' => esc_html__('Overview', 'event_espresso'),
548
+					'order' => 5,
549
+				],
550
+				'help_tabs'     => [
551
+					'registrations_overview_help_tab'                       => [
552
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
+						'filename' => 'registrations_overview',
554
+					],
555
+					'registrations_overview_table_column_headings_help_tab' => [
556
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
+						'filename' => 'registrations_overview_table_column_headings',
558
+					],
559
+					'registrations_overview_filters_help_tab'               => [
560
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
+						'filename' => 'registrations_overview_filters',
562
+					],
563
+					'registrations_overview_views_help_tab'                 => [
564
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
565
+						'filename' => 'registrations_overview_views',
566
+					],
567
+					'registrations_regoverview_other_help_tab'              => [
568
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
+						'filename' => 'registrations_overview_other',
570
+					],
571
+				],
572
+				'qtips'         => ['Registration_List_Table_Tips'],
573
+				'list_table'    => 'EE_Registrations_List_Table',
574
+				'require_nonce' => false,
575
+			],
576
+			'view_registration' => [
577
+				'nav'           => [
578
+					'label'      => esc_html__('REG Details', 'event_espresso'),
579
+					'order'      => 15,
580
+					'url'        => $REG_ID
581
+						? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
582
+						: $this->_admin_base_url,
583
+					'persistent' => false,
584
+				],
585
+				'help_tabs'     => [
586
+					'registrations_details_help_tab'                    => [
587
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
588
+						'filename' => 'registrations_details',
589
+					],
590
+					'registrations_details_table_help_tab'              => [
591
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
592
+						'filename' => 'registrations_details_table',
593
+					],
594
+					'registrations_details_form_answers_help_tab'       => [
595
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
596
+						'filename' => 'registrations_details_form_answers',
597
+					],
598
+					'registrations_details_registrant_details_help_tab' => [
599
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
600
+						'filename' => 'registrations_details_registrant_details',
601
+					],
602
+				],
603
+				'metaboxes'     => array_merge(
604
+					$this->_default_espresso_metaboxes,
605
+					['_registration_details_metaboxes']
606
+				),
607
+				'require_nonce' => false,
608
+			],
609
+			'new_registration'  => [
610
+				'nav'           => [
611
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
612
+					'url'        => '#',
613
+					'order'      => 15,
614
+					'persistent' => false,
615
+				],
616
+				'metaboxes'     => $this->_default_espresso_metaboxes,
617
+				'labels'        => [
618
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
619
+				],
620
+				'require_nonce' => false,
621
+			],
622
+			'add_new_attendee'  => [
623
+				'nav'           => [
624
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
625
+					'order'      => 15,
626
+					'persistent' => false,
627
+				],
628
+				'metaboxes'     => array_merge(
629
+					$this->_default_espresso_metaboxes,
630
+					['_publish_post_box', 'attendee_editor_metaboxes']
631
+				),
632
+				'require_nonce' => false,
633
+			],
634
+			'edit_attendee'     => [
635
+				'nav'           => [
636
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
637
+					'order'      => 15,
638
+					'persistent' => false,
639
+					'url'        => $ATT_ID
640
+						? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
641
+						: $this->_admin_base_url,
642
+				],
643
+				'metaboxes'     => ['attendee_editor_metaboxes'],
644
+				'require_nonce' => false,
645
+			],
646
+			'contact_list'      => [
647
+				'nav'           => [
648
+					'label' => esc_html__('Contact List', 'event_espresso'),
649
+					'order' => 20,
650
+				],
651
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
652
+				'help_tabs'     => [
653
+					'registrations_contact_list_help_tab'                       => [
654
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
655
+						'filename' => 'registrations_contact_list',
656
+					],
657
+					'registrations_contact-list_table_column_headings_help_tab' => [
658
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
659
+						'filename' => 'registrations_contact_list_table_column_headings',
660
+					],
661
+					'registrations_contact_list_views_help_tab'                 => [
662
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
663
+						'filename' => 'registrations_contact_list_views',
664
+					],
665
+					'registrations_contact_list_other_help_tab'                 => [
666
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
667
+						'filename' => 'registrations_contact_list_other',
668
+					],
669
+				],
670
+				'metaboxes'     => [],
671
+				'require_nonce' => false,
672
+			],
673
+			// override default cpt routes
674
+			'create_new'        => '',
675
+			'edit'              => '',
676
+		];
677
+	}
678
+
679
+
680
+	/**
681
+	 * The below methods aren't used by this class currently
682
+	 */
683
+	protected function _add_screen_options()
684
+	{
685
+	}
686
+
687
+
688
+	protected function _add_feature_pointers()
689
+	{
690
+	}
691
+
692
+
693
+	public function admin_init()
694
+	{
695
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
696
+			'click "Update Registration Questions" to save your changes',
697
+			'event_espresso'
698
+		);
699
+	}
700
+
701
+
702
+	public function admin_notices()
703
+	{
704
+	}
705
+
706
+
707
+	public function admin_footer_scripts()
708
+	{
709
+	}
710
+
711
+
712
+	/**
713
+	 * get list of registration statuses
714
+	 *
715
+	 * @return void
716
+	 * @throws EE_Error
717
+	 */
718
+	private function _get_registration_status_array()
719
+	{
720
+		self::$_reg_status = EEM_Registration::reg_status_array([], true);
721
+	}
722
+
723
+
724
+	/**
725
+	 * @throws InvalidArgumentException
726
+	 * @throws InvalidDataTypeException
727
+	 * @throws InvalidInterfaceException
728
+	 * @since 4.10.2.p
729
+	 */
730
+	protected function _add_screen_options_default()
731
+	{
732
+		$this->_per_page_screen_option();
733
+	}
734
+
735
+
736
+	/**
737
+	 * @throws InvalidArgumentException
738
+	 * @throws InvalidDataTypeException
739
+	 * @throws InvalidInterfaceException
740
+	 * @since 4.10.2.p
741
+	 */
742
+	protected function _add_screen_options_contact_list()
743
+	{
744
+		$page_title              = $this->_admin_page_title;
745
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
746
+		$this->_per_page_screen_option();
747
+		$this->_admin_page_title = $page_title;
748
+	}
749
+
750
+
751
+	public function load_scripts_styles()
752
+	{
753
+		// style
754
+		wp_register_style(
755
+			'espresso_reg',
756
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
757
+			['ee-admin-css'],
758
+			EVENT_ESPRESSO_VERSION
759
+		);
760
+		wp_enqueue_style('espresso_reg');
761
+		// script
762
+		wp_register_script(
763
+			'espresso_reg',
764
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
765
+			['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
766
+			EVENT_ESPRESSO_VERSION,
767
+			true
768
+		);
769
+		wp_enqueue_script('espresso_reg');
770
+	}
771
+
772
+
773
+	/**
774
+	 * @throws EE_Error
775
+	 * @throws InvalidArgumentException
776
+	 * @throws InvalidDataTypeException
777
+	 * @throws InvalidInterfaceException
778
+	 * @throws ReflectionException
779
+	 * @since 4.10.2.p
780
+	 */
781
+	public function load_scripts_styles_edit_attendee()
782
+	{
783
+		// stuff to only show up on our attendee edit details page.
784
+		$attendee_details_translations = [
785
+			'att_publish_text' => sprintf(
786
+			/* translators: The date and time */
787
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
788
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
789
+			),
790
+		];
791
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
792
+		wp_enqueue_script('jquery-validate');
793
+	}
794
+
795
+
796
+	/**
797
+	 * @throws EE_Error
798
+	 * @throws InvalidArgumentException
799
+	 * @throws InvalidDataTypeException
800
+	 * @throws InvalidInterfaceException
801
+	 * @throws ReflectionException
802
+	 * @since 4.10.2.p
803
+	 */
804
+	public function load_scripts_styles_view_registration()
805
+	{
806
+		// styles
807
+		wp_enqueue_style('espresso-ui-theme');
808
+		// scripts
809
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
810
+		$this->_reg_custom_questions_form->wp_enqueue_scripts();
811
+	}
812
+
813
+
814
+	public function load_scripts_styles_contact_list()
815
+	{
816
+		wp_dequeue_style('espresso_reg');
817
+		wp_register_style(
818
+			'espresso_att',
819
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
820
+			['ee-admin-css'],
821
+			EVENT_ESPRESSO_VERSION
822
+		);
823
+		wp_enqueue_style('espresso_att');
824
+	}
825
+
826
+
827
+	public function load_scripts_styles_new_registration()
828
+	{
829
+		wp_register_script(
830
+			'ee-spco-for-admin',
831
+			REG_ASSETS_URL . 'spco_for_admin.js',
832
+			['underscore', 'jquery'],
833
+			EVENT_ESPRESSO_VERSION,
834
+			true
835
+		);
836
+		wp_enqueue_script('ee-spco-for-admin');
837
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
838
+		EE_Form_Section_Proper::wp_enqueue_scripts();
839
+		EED_Ticket_Selector::load_tckt_slctr_assets();
840
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
841
+	}
842
+
843
+
844
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
845
+	{
846
+		add_filter('FHEE_load_EE_messages', '__return_true');
847
+	}
848
+
849
+
850
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
851
+	{
852
+		add_filter('FHEE_load_EE_messages', '__return_true');
853
+	}
854
+
855
+
856
+	/**
857
+	 * @throws EE_Error
858
+	 * @throws InvalidArgumentException
859
+	 * @throws InvalidDataTypeException
860
+	 * @throws InvalidInterfaceException
861
+	 * @throws ReflectionException
862
+	 * @since 4.10.2.p
863
+	 */
864
+	protected function _set_list_table_views_default()
865
+	{
866
+		// for notification related bulk actions we need to make sure only active messengers have an option.
867
+		EED_Messages::set_autoloaders();
868
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
869
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
870
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
871
+		// key= bulk_action_slug, value= message type.
872
+		$match_array = [
873
+			'approve_registrations'    => 'registration',
874
+			'decline_registrations'    => 'declined_registration',
875
+			'pending_registrations'    => 'pending_approval',
876
+			'no_approve_registrations' => 'not_approved_registration',
877
+			'cancel_registrations'     => 'cancelled_registration',
878
+		];
879
+		$can_send    = EE_Registry::instance()->CAP->current_user_can(
880
+			'ee_send_message',
881
+			'batch_send_messages'
882
+		);
883
+		/** setup reg status bulk actions **/
884
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
885
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
886
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
887
+				'Approve and Notify Registrations',
888
+				'event_espresso'
889
+			);
890
+		}
891
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
892
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
893
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
894
+				'Decline and Notify Registrations',
895
+				'event_espresso'
896
+			);
897
+		}
898
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
899
+			'Set Registrations to Pending Payment',
900
+			'event_espresso'
901
+		);
902
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
903
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
904
+				'Set Registrations to Pending Payment and Notify',
905
+				'event_espresso'
906
+			);
907
+		}
908
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
909
+			'Set Registrations to Not Approved',
910
+			'event_espresso'
911
+		);
912
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
913
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
914
+				'Set Registrations to Not Approved and Notify',
915
+				'event_espresso'
916
+			);
917
+		}
918
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
919
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
920
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
921
+				'Cancel Registrations and Notify',
922
+				'event_espresso'
923
+			);
924
+		}
925
+		$def_reg_status_actions = apply_filters(
926
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
927
+			$def_reg_status_actions,
928
+			$active_mts,
929
+			$can_send
930
+		);
931
+
932
+		$this->_views = [
933
+			'all'   => [
934
+				'slug'        => 'all',
935
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
936
+				'count'       => 0,
937
+				'bulk_action' => array_merge(
938
+					$def_reg_status_actions,
939
+					[
940
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
941
+					]
942
+				),
943
+			],
944
+			'month' => [
945
+				'slug'        => 'month',
946
+				'label'       => esc_html__('This Month', 'event_espresso'),
947
+				'count'       => 0,
948
+				'bulk_action' => array_merge(
949
+					$def_reg_status_actions,
950
+					[
951
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
952
+					]
953
+				),
954
+			],
955
+			'today' => [
956
+				'slug'        => 'today',
957
+				'label'       => sprintf(
958
+					esc_html__('Today - %s', 'event_espresso'),
959
+					date('M d, Y', current_time('timestamp'))
960
+				),
961
+				'count'       => 0,
962
+				'bulk_action' => array_merge(
963
+					$def_reg_status_actions,
964
+					[
965
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
966
+					]
967
+				),
968
+			],
969
+		];
970
+		if (
971
+			EE_Registry::instance()->CAP->current_user_can(
972
+				'ee_delete_registrations',
973
+				'espresso_registrations_delete_registration'
974
+			)
975
+		) {
976
+			$this->_views['incomplete'] = [
977
+				'slug'        => 'incomplete',
978
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
979
+				'count'       => 0,
980
+				'bulk_action' => [
981
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
982
+				],
983
+			];
984
+			$this->_views['trash']      = [
985
+				'slug'        => 'trash',
986
+				'label'       => esc_html__('Trash', 'event_espresso'),
987
+				'count'       => 0,
988
+				'bulk_action' => [
989
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
990
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
991
+				],
992
+			];
993
+		}
994
+	}
995
+
996
+
997
+	protected function _set_list_table_views_contact_list()
998
+	{
999
+		$this->_views = [
1000
+			'in_use' => [
1001
+				'slug'        => 'in_use',
1002
+				'label'       => esc_html__('In Use', 'event_espresso'),
1003
+				'count'       => 0,
1004
+				'bulk_action' => [
1005
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1006
+				],
1007
+			],
1008
+		];
1009
+		if (
1010
+			EE_Registry::instance()->CAP->current_user_can(
1011
+				'ee_delete_contacts',
1012
+				'espresso_registrations_trash_attendees'
1013
+			)
1014
+		) {
1015
+			$this->_views['trash'] = [
1016
+				'slug'        => 'trash',
1017
+				'label'       => esc_html__('Trash', 'event_espresso'),
1018
+				'count'       => 0,
1019
+				'bulk_action' => [
1020
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1021
+				],
1022
+			];
1023
+		}
1024
+	}
1025
+
1026
+
1027
+	/**
1028
+	 * @return array
1029
+	 * @throws EE_Error
1030
+	 */
1031
+	protected function _registration_legend_items()
1032
+	{
1033
+		$fc_items = [
1034
+			'star-icon'        => [
1035
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1037
+			],
1038
+			'view_details'     => [
1039
+				'class' => 'dashicons dashicons-clipboard',
1040
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1041
+			],
1042
+			'edit_attendee'    => [
1043
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1044
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1045
+			],
1046
+			'view_transaction' => [
1047
+				'class' => 'dashicons dashicons-cart',
1048
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1049
+			],
1050
+			'view_invoice'     => [
1051
+				'class' => 'dashicons dashicons-media-spreadsheet',
1052
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1053
+			],
1054
+		];
1055
+		if (
1056
+			EE_Registry::instance()->CAP->current_user_can(
1057
+				'ee_send_message',
1058
+				'espresso_registrations_resend_registration'
1059
+			)
1060
+		) {
1061
+			$fc_items['resend_registration'] = [
1062
+				'class' => 'dashicons dashicons-email-alt',
1063
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1064
+			];
1065
+		} else {
1066
+			$fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1067
+		}
1068
+		if (
1069
+			EE_Registry::instance()->CAP->current_user_can(
1070
+				'ee_read_global_messages',
1071
+				'view_filtered_messages'
1072
+			)
1073
+		) {
1074
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1075
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1076
+				$fc_items['view_related_messages'] = [
1077
+					'class' => $related_for_icon['css_class'],
1078
+					'desc'  => $related_for_icon['label'],
1079
+				];
1080
+			}
1081
+		}
1082
+		$sc_items = [
1083
+			'approved_status'   => [
1084
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1085
+				'desc'  => EEH_Template::pretty_status(
1086
+					EEM_Registration::status_id_approved,
1087
+					false,
1088
+					'sentence'
1089
+				),
1090
+			],
1091
+			'pending_status'    => [
1092
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1093
+				'desc'  => EEH_Template::pretty_status(
1094
+					EEM_Registration::status_id_pending_payment,
1095
+					false,
1096
+					'sentence'
1097
+				),
1098
+			],
1099
+			'wait_list'         => [
1100
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1101
+				'desc'  => EEH_Template::pretty_status(
1102
+					EEM_Registration::status_id_wait_list,
1103
+					false,
1104
+					'sentence'
1105
+				),
1106
+			],
1107
+			'incomplete_status' => [
1108
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1109
+				'desc'  => EEH_Template::pretty_status(
1110
+					EEM_Registration::status_id_incomplete,
1111
+					false,
1112
+					'sentence'
1113
+				),
1114
+			],
1115
+			'not_approved'      => [
1116
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1117
+				'desc'  => EEH_Template::pretty_status(
1118
+					EEM_Registration::status_id_not_approved,
1119
+					false,
1120
+					'sentence'
1121
+				),
1122
+			],
1123
+			'declined_status'   => [
1124
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1125
+				'desc'  => EEH_Template::pretty_status(
1126
+					EEM_Registration::status_id_declined,
1127
+					false,
1128
+					'sentence'
1129
+				),
1130
+			],
1131
+			'cancelled_status'  => [
1132
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1133
+				'desc'  => EEH_Template::pretty_status(
1134
+					EEM_Registration::status_id_cancelled,
1135
+					false,
1136
+					'sentence'
1137
+				),
1138
+			],
1139
+		];
1140
+		return array_merge($fc_items, $sc_items);
1141
+	}
1142
+
1143
+
1144
+
1145
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1146
+
1147
+
1148
+	/**
1149
+	 * @throws DomainException
1150
+	 * @throws EE_Error
1151
+	 * @throws InvalidArgumentException
1152
+	 * @throws InvalidDataTypeException
1153
+	 * @throws InvalidInterfaceException
1154
+	 */
1155
+	protected function _registrations_overview_list_table()
1156
+	{
1157
+		$this->appendAddNewRegistrationButtonToPageTitle();
1158
+		$header_text                  = '';
1159
+		$admin_page_header_decorators = [
1160
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1161
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1162
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1163
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1164
+		];
1165
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1166
+			$filter_header_decorator = $this->getLoader()->getNew($admin_page_header_decorator);
1167
+			$header_text             = $filter_header_decorator->getHeaderText($header_text);
1168
+		}
1169
+		$this->_template_args['admin_page_header'] = $header_text;
1170
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1171
+		$this->display_admin_list_table_page_with_no_sidebar();
1172
+	}
1173
+
1174
+
1175
+	/**
1176
+	 * @throws EE_Error
1177
+	 * @throws InvalidArgumentException
1178
+	 * @throws InvalidDataTypeException
1179
+	 * @throws InvalidInterfaceException
1180
+	 */
1181
+	private function appendAddNewRegistrationButtonToPageTitle()
1182
+	{
1183
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1184
+		if (
1185
+			$EVT_ID
1186
+			&& EE_Registry::instance()->CAP->current_user_can(
1187
+				'ee_edit_registrations',
1188
+				'espresso_registrations_new_registration',
1189
+				$EVT_ID
1190
+			)
1191
+		) {
1192
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1193
+				'new_registration',
1194
+				'add-registrant',
1195
+				['event_id' => $EVT_ID],
1196
+				'add-new-h2'
1197
+			);
1198
+		}
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * This sets the _registration property for the registration details screen
1204
+	 *
1205
+	 * @return void
1206
+	 * @throws EE_Error
1207
+	 * @throws InvalidArgumentException
1208
+	 * @throws InvalidDataTypeException
1209
+	 * @throws InvalidInterfaceException
1210
+	 */
1211
+	private function _set_registration_object()
1212
+	{
1213
+		// get out if we've already set the object
1214
+		if ($this->_registration instanceof EE_Registration) {
1215
+			return;
1216
+		}
1217
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1218
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1219
+			return;
1220
+		}
1221
+		$error_msg = sprintf(
1222
+			esc_html__(
1223
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1224
+				'event_espresso'
1225
+			),
1226
+			$REG_ID
1227
+		);
1228
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1229
+		$this->_registration = null;
1230
+	}
1231
+
1232
+
1233
+	/**
1234
+	 * Used to retrieve registrations for the list table.
1235
+	 *
1236
+	 * @param int  $per_page
1237
+	 * @param bool $count
1238
+	 * @param bool $this_month
1239
+	 * @param bool $today
1240
+	 * @return EE_Registration[]|int
1241
+	 * @throws EE_Error
1242
+	 * @throws InvalidArgumentException
1243
+	 * @throws InvalidDataTypeException
1244
+	 * @throws InvalidInterfaceException
1245
+	 */
1246
+	public function get_registrations(
1247
+		$per_page = 10,
1248
+		$count = false,
1249
+		$this_month = false,
1250
+		$today = false
1251
+	) {
1252
+		if ($this_month) {
1253
+			$this->request->setRequestParam('status', 'month');
1254
+		}
1255
+		if ($today) {
1256
+			$this->request->setRequestParam('status', 'today');
1257
+		}
1258
+		$query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1259
+		/**
1260
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1261
+		 *
1262
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1263
+		 * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1264
+		 *                      or if you have the development copy of EE you can view this at the path:
1265
+		 *                      /docs/G--Model-System/model-query-params.md
1266
+		 */
1267
+		$query_params['group_by'] = '';
1268
+
1269
+		return $count
1270
+			? $this->getRegistrationModel()->count($query_params)
1271
+			/** @type EE_Registration[] */
1272
+			: $this->getRegistrationModel()->get_all($query_params);
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1278
+	 * Note: this listens to values on the request for some of the query parameters.
1279
+	 *
1280
+	 * @param array $request
1281
+	 * @param int   $per_page
1282
+	 * @param bool  $count
1283
+	 * @return array
1284
+	 * @throws EE_Error
1285
+	 * @throws InvalidArgumentException
1286
+	 * @throws InvalidDataTypeException
1287
+	 * @throws InvalidInterfaceException
1288
+	 */
1289
+	protected function _get_registration_query_parameters(
1290
+		$request = [],
1291
+		$per_page = 10,
1292
+		$count = false
1293
+	) {
1294
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1295
+		$list_table_query_builder = $this->getLoader()->getNew(
1296
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1297
+			[null, null, $request]
1298
+		);
1299
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1300
+	}
1301
+
1302
+
1303
+	public function get_registration_status_array()
1304
+	{
1305
+		return self::$_reg_status;
1306
+	}
1307
+
1308
+
1309
+
1310
+
1311
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1312
+	/**
1313
+	 * generates HTML for the View Registration Details Admin page
1314
+	 *
1315
+	 * @return void
1316
+	 * @throws DomainException
1317
+	 * @throws EE_Error
1318
+	 * @throws InvalidArgumentException
1319
+	 * @throws InvalidDataTypeException
1320
+	 * @throws InvalidInterfaceException
1321
+	 * @throws EntityNotFoundException
1322
+	 * @throws ReflectionException
1323
+	 */
1324
+	protected function _registration_details()
1325
+	{
1326
+		$this->_template_args = [];
1327
+		$this->_set_registration_object();
1328
+		if (is_object($this->_registration)) {
1329
+			$transaction                                   = $this->_registration->transaction()
1330
+				? $this->_registration->transaction()
1331
+				: EE_Transaction::new_instance();
1332
+			$this->_session                                = $transaction->session_data();
1333
+			$event_id                                      = $this->_registration->event_ID();
1334
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1335
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1336
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1337
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1338
+			$this->_template_args['grand_total']           = $transaction->total();
1339
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1340
+			// link back to overview
1341
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1342
+			$this->_template_args['registration']                = $this->_registration;
1343
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1344
+				[
1345
+					'action'   => 'default',
1346
+					'event_id' => $event_id,
1347
+				],
1348
+				REG_ADMIN_URL
1349
+			);
1350
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1351
+				[
1352
+					'action' => 'default',
1353
+					'EVT_ID' => $event_id,
1354
+					'page'   => 'espresso_transactions',
1355
+				],
1356
+				admin_url('admin.php')
1357
+			);
1358
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1359
+				[
1360
+					'page'   => 'espresso_events',
1361
+					'action' => 'edit',
1362
+					'post'   => $event_id,
1363
+				],
1364
+				admin_url('admin.php')
1365
+			);
1366
+			// next and previous links
1367
+			$next_reg                                      = $this->_registration->next(
1368
+				null,
1369
+				[],
1370
+				'REG_ID'
1371
+			);
1372
+			$this->_template_args['next_registration']     = $next_reg
1373
+				? $this->_next_link(
1374
+					EE_Admin_Page::add_query_args_and_nonce(
1375
+						[
1376
+							'action'  => 'view_registration',
1377
+							'_REG_ID' => $next_reg['REG_ID'],
1378
+						],
1379
+						REG_ADMIN_URL
1380
+					),
1381
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1382
+				)
1383
+				: '';
1384
+			$previous_reg                                  = $this->_registration->previous(
1385
+				null,
1386
+				[],
1387
+				'REG_ID'
1388
+			);
1389
+			$this->_template_args['previous_registration'] = $previous_reg
1390
+				? $this->_previous_link(
1391
+					EE_Admin_Page::add_query_args_and_nonce(
1392
+						[
1393
+							'action'  => 'view_registration',
1394
+							'_REG_ID' => $previous_reg['REG_ID'],
1395
+						],
1396
+						REG_ADMIN_URL
1397
+					),
1398
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1399
+				)
1400
+				: '';
1401
+			// grab header
1402
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1403
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1404
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1405
+				$template_path,
1406
+				$this->_template_args,
1407
+				true
1408
+			);
1409
+		} else {
1410
+			$this->_template_args['admin_page_header'] = '';
1411
+			$this->_display_espresso_notices();
1412
+		}
1413
+		// the details template wrapper
1414
+		$this->display_admin_page_with_sidebar();
1415
+	}
1416
+
1417
+
1418
+	/**
1419
+	 * @throws EE_Error
1420
+	 * @throws InvalidArgumentException
1421
+	 * @throws InvalidDataTypeException
1422
+	 * @throws InvalidInterfaceException
1423
+	 * @throws ReflectionException
1424
+	 * @since 4.10.2.p
1425
+	 */
1426
+	protected function _registration_details_metaboxes()
1427
+	{
1428
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1429
+		$this->_set_registration_object();
1430
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1431
+		add_meta_box(
1432
+			'edit-reg-status-mbox',
1433
+			esc_html__('Registration Status', 'event_espresso'),
1434
+			[$this, 'set_reg_status_buttons_metabox'],
1435
+			$this->_wp_page_slug,
1436
+			'normal',
1437
+			'high'
1438
+		);
1439
+		add_meta_box(
1440
+			'edit-reg-details-mbox',
1441
+			esc_html__('Registration Details', 'event_espresso'),
1442
+			[$this, '_reg_details_meta_box'],
1443
+			$this->_wp_page_slug,
1444
+			'normal',
1445
+			'high'
1446
+		);
1447
+		if (
1448
+			$attendee instanceof EE_Attendee
1449
+			&& EE_Registry::instance()->CAP->current_user_can(
1450
+				'ee_read_registration',
1451
+				'edit-reg-questions-mbox',
1452
+				$this->_registration->ID()
1453
+			)
1454
+		) {
1455
+			add_meta_box(
1456
+				'edit-reg-questions-mbox',
1457
+				esc_html__('Registration Form Answers', 'event_espresso'),
1458
+				[$this, '_reg_questions_meta_box'],
1459
+				$this->_wp_page_slug,
1460
+				'normal',
1461
+				'high'
1462
+			);
1463
+		}
1464
+		add_meta_box(
1465
+			'edit-reg-registrant-mbox',
1466
+			esc_html__('Contact Details', 'event_espresso'),
1467
+			[$this, '_reg_registrant_side_meta_box'],
1468
+			$this->_wp_page_slug,
1469
+			'side',
1470
+			'high'
1471
+		);
1472
+		if ($this->_registration->group_size() > 1) {
1473
+			add_meta_box(
1474
+				'edit-reg-attendees-mbox',
1475
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1476
+				[$this, '_reg_attendees_meta_box'],
1477
+				$this->_wp_page_slug,
1478
+				'normal',
1479
+				'high'
1480
+			);
1481
+		}
1482
+	}
1483
+
1484
+
1485
+	/**
1486
+	 * set_reg_status_buttons_metabox
1487
+	 *
1488
+	 * @return void
1489
+	 * @throws EE_Error
1490
+	 * @throws EntityNotFoundException
1491
+	 * @throws InvalidArgumentException
1492
+	 * @throws InvalidDataTypeException
1493
+	 * @throws InvalidInterfaceException
1494
+	 * @throws ReflectionException
1495
+	 */
1496
+	public function set_reg_status_buttons_metabox()
1497
+	{
1498
+		$this->_set_registration_object();
1499
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1500
+		$output                 = $change_reg_status_form->form_open(
1501
+			self::add_query_args_and_nonce(
1502
+				[
1503
+					'action' => 'change_reg_status',
1504
+				],
1505
+				REG_ADMIN_URL
1506
+			)
1507
+		);
1508
+		$output                 .= $change_reg_status_form->get_html();
1509
+		$output                 .= $change_reg_status_form->form_close();
1510
+		echo $output; // already escaped
1511
+	}
1512
+
1513
+
1514
+	/**
1515
+	 * @return EE_Form_Section_Proper
1516
+	 * @throws EE_Error
1517
+	 * @throws InvalidArgumentException
1518
+	 * @throws InvalidDataTypeException
1519
+	 * @throws InvalidInterfaceException
1520
+	 * @throws EntityNotFoundException
1521
+	 * @throws ReflectionException
1522
+	 */
1523
+	protected function _generate_reg_status_change_form()
1524
+	{
1525
+		$reg_status_change_form_array = [
1526
+			'name'            => 'reg_status_change_form',
1527
+			'html_id'         => 'reg-status-change-form',
1528
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1529
+			'subsections'     => [
1530
+				'return'         => new EE_Hidden_Input(
1531
+					[
1532
+						'name'    => 'return',
1533
+						'default' => 'view_registration',
1534
+					]
1535
+				),
1536
+				'REG_ID'         => new EE_Hidden_Input(
1537
+					[
1538
+						'name'    => 'REG_ID',
1539
+						'default' => $this->_registration->ID(),
1540
+					]
1541
+				),
1542
+				'current_status' => new EE_Form_Section_HTML(
1543
+					EEH_HTML::table(
1544
+						EEH_HTML::tr(
1545
+							EEH_HTML::th(
1546
+								EEH_HTML::label(
1547
+									EEH_HTML::strong(
1548
+										esc_html__('Current Registration Status', 'event_espresso')
1549
+									)
1550
+								)
1551
+							)
1552
+							. EEH_HTML::td(
1553
+								EEH_HTML::strong(
1554
+									$this->_registration->pretty_status(),
1555
+									'',
1556
+									'status-' . $this->_registration->status_ID(),
1557
+									'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1558
+								)
1559
+							)
1560
+						)
1561
+					)
1562
+				),
1563
+			],
1564
+		];
1565
+		if (
1566
+			EE_Registry::instance()->CAP->current_user_can(
1567
+				'ee_edit_registration',
1568
+				'toggle_registration_status',
1569
+				$this->_registration->ID()
1570
+			)
1571
+		) {
1572
+			$reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1573
+				$this->_get_reg_statuses(),
1574
+				[
1575
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1576
+					'default'         => $this->_registration->status_ID(),
1577
+				]
1578
+			);
1579
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1580
+				[
1581
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1582
+					'default'         => false,
1583
+					'html_help_text'  => esc_html__(
1584
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1585
+						'event_espresso'
1586
+					),
1587
+				]
1588
+			);
1589
+			$reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1590
+				[
1591
+					'html_class'      => 'button-primary',
1592
+					'html_label_text' => '&nbsp;',
1593
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1594
+				]
1595
+			);
1596
+		}
1597
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1598
+	}
1599
+
1600
+
1601
+	/**
1602
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1603
+	 *
1604
+	 * @return array
1605
+	 * @throws EE_Error
1606
+	 * @throws InvalidArgumentException
1607
+	 * @throws InvalidDataTypeException
1608
+	 * @throws InvalidInterfaceException
1609
+	 * @throws EntityNotFoundException
1610
+	 */
1611
+	protected function _get_reg_statuses()
1612
+	{
1613
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1614
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1615
+		// get current reg status
1616
+		$current_status = $this->_registration->status_ID();
1617
+		// is registration for free event? This will determine whether to display the pending payment option
1618
+		if (
1619
+			$current_status !== EEM_Registration::status_id_pending_payment
1620
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1621
+		) {
1622
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1623
+		}
1624
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1625
+	}
1626
+
1627
+
1628
+	/**
1629
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1630
+	 *
1631
+	 * @param bool $status REG status given for changing registrations to.
1632
+	 * @param bool $notify Whether to send messages notifications or not.
1633
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1634
+	 * @throws DomainException
1635
+	 * @throws EE_Error
1636
+	 * @throws EntityNotFoundException
1637
+	 * @throws InvalidArgumentException
1638
+	 * @throws InvalidDataTypeException
1639
+	 * @throws InvalidInterfaceException
1640
+	 * @throws ReflectionException
1641
+	 * @throws RuntimeException
1642
+	 */
1643
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1644
+	{
1645
+		$REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1646
+			? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1647
+			: $this->request->getRequestParam('_REG_ID', [], 'int', true);
1648
+
1649
+		// sanitize $REG_IDs
1650
+		$REG_IDs = array_map('absint', $REG_IDs);
1651
+		// and remove empty entries
1652
+		$REG_IDs = array_filter($REG_IDs);
1653
+
1654
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1655
+
1656
+		/**
1657
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1658
+		 * Currently this value is used downstream by the _process_resend_registration method.
1659
+		 *
1660
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1661
+		 * @param bool                     $status           The status registrations were changed to.
1662
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1663
+		 * @param Registrations_Admin_Page $admin_page_object
1664
+		 */
1665
+		$REG_ID = apply_filters(
1666
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1667
+			$result['REG_ID'],
1668
+			$status,
1669
+			$result['success'],
1670
+			$this
1671
+		);
1672
+		$this->request->setRequestParam('_REG_ID', $REG_ID);
1673
+
1674
+		// notify?
1675
+		if (
1676
+			$notify
1677
+			&& $result['success']
1678
+			&& ! empty($REG_ID)
1679
+			&& EE_Registry::instance()->CAP->current_user_can(
1680
+				'ee_send_message',
1681
+				'espresso_registrations_resend_registration'
1682
+			)
1683
+		) {
1684
+			$this->_process_resend_registration();
1685
+		}
1686
+		return $result;
1687
+	}
1688
+
1689
+
1690
+	/**
1691
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1692
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1693
+	 *
1694
+	 * @param array  $REG_IDs
1695
+	 * @param string $status
1696
+	 * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1697
+	 *                       slug sent with setting the registration status.
1698
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1699
+	 * @throws EE_Error
1700
+	 * @throws InvalidArgumentException
1701
+	 * @throws InvalidDataTypeException
1702
+	 * @throws InvalidInterfaceException
1703
+	 * @throws ReflectionException
1704
+	 * @throws RuntimeException
1705
+	 * @throws EntityNotFoundException
1706
+	 * @throws DomainException
1707
+	 */
1708
+	protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1709
+	{
1710
+		$success = false;
1711
+		// typecast $REG_IDs
1712
+		$REG_IDs = (array) $REG_IDs;
1713
+		if (! empty($REG_IDs)) {
1714
+			$success = true;
1715
+			// set default status if none is passed
1716
+			$status         = $status ?: EEM_Registration::status_id_pending_payment;
1717
+			$status_context = $notify
1718
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1719
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1720
+			// loop through REG_ID's and change status
1721
+			foreach ($REG_IDs as $REG_ID) {
1722
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1723
+				if ($registration instanceof EE_Registration) {
1724
+					$registration->set_status(
1725
+						$status,
1726
+						false,
1727
+						new Context(
1728
+							$status_context,
1729
+							esc_html__(
1730
+								'Manually triggered status change on a Registration Admin Page route.',
1731
+								'event_espresso'
1732
+							)
1733
+						)
1734
+					);
1735
+					$result = $registration->save();
1736
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1737
+					$success = $result !== false ? $success : false;
1738
+				}
1739
+			}
1740
+		}
1741
+
1742
+		// return $success and processed registrations
1743
+		return ['REG_ID' => $REG_IDs, 'success' => $success];
1744
+	}
1745
+
1746
+
1747
+	/**
1748
+	 * Common logic for setting up success message and redirecting to appropriate route
1749
+	 *
1750
+	 * @param string $STS_ID status id for the registration changed to
1751
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1752
+	 * @return void
1753
+	 * @throws DomainException
1754
+	 * @throws EE_Error
1755
+	 * @throws EntityNotFoundException
1756
+	 * @throws InvalidArgumentException
1757
+	 * @throws InvalidDataTypeException
1758
+	 * @throws InvalidInterfaceException
1759
+	 * @throws ReflectionException
1760
+	 * @throws RuntimeException
1761
+	 */
1762
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1763
+	{
1764
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1765
+			: ['success' => false];
1766
+		$success = isset($result['success']) && $result['success'];
1767
+		// setup success message
1768
+		if ($success) {
1769
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1770
+				$msg = sprintf(
1771
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1772
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1773
+				);
1774
+			} else {
1775
+				$msg = sprintf(
1776
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1777
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1778
+				);
1779
+			}
1780
+			EE_Error::add_success($msg);
1781
+		} else {
1782
+			EE_Error::add_error(
1783
+				esc_html__(
1784
+					'Something went wrong, and the status was not changed',
1785
+					'event_espresso'
1786
+				),
1787
+				__FILE__,
1788
+				__LINE__,
1789
+				__FUNCTION__
1790
+			);
1791
+		}
1792
+		$return = $this->request->getRequestParam('return');
1793
+		$route  = $return === 'view_registration'
1794
+			? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1795
+			: ['action' => 'default'];
1796
+		$route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1797
+		$this->_redirect_after_action($success, '', '', $route, true);
1798
+	}
1799
+
1800
+
1801
+	/**
1802
+	 * incoming reg status change from reg details page.
1803
+	 *
1804
+	 * @return void
1805
+	 * @throws EE_Error
1806
+	 * @throws EntityNotFoundException
1807
+	 * @throws InvalidArgumentException
1808
+	 * @throws InvalidDataTypeException
1809
+	 * @throws InvalidInterfaceException
1810
+	 * @throws ReflectionException
1811
+	 * @throws RuntimeException
1812
+	 * @throws DomainException
1813
+	 */
1814
+	protected function _change_reg_status()
1815
+	{
1816
+		$this->request->setRequestParam('return', 'view_registration');
1817
+		// set notify based on whether the send notifications toggle is set or not
1818
+		$notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1819
+		$reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1820
+		$this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1821
+		switch ($reg_status) {
1822
+			case EEM_Registration::status_id_approved:
1823
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1824
+				$this->approve_registration($notify);
1825
+				break;
1826
+			case EEM_Registration::status_id_pending_payment:
1827
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1828
+				$this->pending_registration($notify);
1829
+				break;
1830
+			case EEM_Registration::status_id_not_approved:
1831
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1832
+				$this->not_approve_registration($notify);
1833
+				break;
1834
+			case EEM_Registration::status_id_declined:
1835
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1836
+				$this->decline_registration($notify);
1837
+				break;
1838
+			case EEM_Registration::status_id_cancelled:
1839
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1840
+				$this->cancel_registration($notify);
1841
+				break;
1842
+			case EEM_Registration::status_id_wait_list:
1843
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1844
+				$this->wait_list_registration($notify);
1845
+				break;
1846
+			case EEM_Registration::status_id_incomplete:
1847
+			default:
1848
+				$this->request->unSetRequestParam('return');
1849
+				$this->_reg_status_change_return('');
1850
+				break;
1851
+		}
1852
+	}
1853
+
1854
+
1855
+	/**
1856
+	 * Callback for bulk action routes.
1857
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1858
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1859
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1860
+	 * when an action is happening on just a single registration).
1861
+	 *
1862
+	 * @param      $action
1863
+	 * @param bool $notify
1864
+	 */
1865
+	protected function bulk_action_on_registrations($action, $notify = false)
1866
+	{
1867
+		do_action(
1868
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1869
+			$this,
1870
+			$action,
1871
+			$notify
1872
+		);
1873
+		$method = $action . '_registration';
1874
+		if (method_exists($this, $method)) {
1875
+			$this->$method($notify);
1876
+		}
1877
+	}
1878
+
1879
+
1880
+	/**
1881
+	 * approve_registration
1882
+	 *
1883
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1884
+	 * @return void
1885
+	 * @throws EE_Error
1886
+	 * @throws EntityNotFoundException
1887
+	 * @throws InvalidArgumentException
1888
+	 * @throws InvalidDataTypeException
1889
+	 * @throws InvalidInterfaceException
1890
+	 * @throws ReflectionException
1891
+	 * @throws RuntimeException
1892
+	 * @throws DomainException
1893
+	 */
1894
+	protected function approve_registration($notify = false)
1895
+	{
1896
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1897
+	}
1898
+
1899
+
1900
+	/**
1901
+	 * decline_registration
1902
+	 *
1903
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1904
+	 * @return void
1905
+	 * @throws EE_Error
1906
+	 * @throws EntityNotFoundException
1907
+	 * @throws InvalidArgumentException
1908
+	 * @throws InvalidDataTypeException
1909
+	 * @throws InvalidInterfaceException
1910
+	 * @throws ReflectionException
1911
+	 * @throws RuntimeException
1912
+	 * @throws DomainException
1913
+	 */
1914
+	protected function decline_registration($notify = false)
1915
+	{
1916
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1917
+	}
1918
+
1919
+
1920
+	/**
1921
+	 * cancel_registration
1922
+	 *
1923
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1924
+	 * @return void
1925
+	 * @throws EE_Error
1926
+	 * @throws EntityNotFoundException
1927
+	 * @throws InvalidArgumentException
1928
+	 * @throws InvalidDataTypeException
1929
+	 * @throws InvalidInterfaceException
1930
+	 * @throws ReflectionException
1931
+	 * @throws RuntimeException
1932
+	 * @throws DomainException
1933
+	 */
1934
+	protected function cancel_registration($notify = false)
1935
+	{
1936
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1937
+	}
1938
+
1939
+
1940
+	/**
1941
+	 * not_approve_registration
1942
+	 *
1943
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1944
+	 * @return void
1945
+	 * @throws EE_Error
1946
+	 * @throws EntityNotFoundException
1947
+	 * @throws InvalidArgumentException
1948
+	 * @throws InvalidDataTypeException
1949
+	 * @throws InvalidInterfaceException
1950
+	 * @throws ReflectionException
1951
+	 * @throws RuntimeException
1952
+	 * @throws DomainException
1953
+	 */
1954
+	protected function not_approve_registration($notify = false)
1955
+	{
1956
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1957
+	}
1958
+
1959
+
1960
+	/**
1961
+	 * decline_registration
1962
+	 *
1963
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1964
+	 * @return void
1965
+	 * @throws EE_Error
1966
+	 * @throws EntityNotFoundException
1967
+	 * @throws InvalidArgumentException
1968
+	 * @throws InvalidDataTypeException
1969
+	 * @throws InvalidInterfaceException
1970
+	 * @throws ReflectionException
1971
+	 * @throws RuntimeException
1972
+	 * @throws DomainException
1973
+	 */
1974
+	protected function pending_registration($notify = false)
1975
+	{
1976
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1977
+	}
1978
+
1979
+
1980
+	/**
1981
+	 * waitlist_registration
1982
+	 *
1983
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1984
+	 * @return void
1985
+	 * @throws EE_Error
1986
+	 * @throws EntityNotFoundException
1987
+	 * @throws InvalidArgumentException
1988
+	 * @throws InvalidDataTypeException
1989
+	 * @throws InvalidInterfaceException
1990
+	 * @throws ReflectionException
1991
+	 * @throws RuntimeException
1992
+	 * @throws DomainException
1993
+	 */
1994
+	protected function wait_list_registration($notify = false)
1995
+	{
1996
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1997
+	}
1998
+
1999
+
2000
+	/**
2001
+	 * generates HTML for the Registration main meta box
2002
+	 *
2003
+	 * @return void
2004
+	 * @throws DomainException
2005
+	 * @throws EE_Error
2006
+	 * @throws InvalidArgumentException
2007
+	 * @throws InvalidDataTypeException
2008
+	 * @throws InvalidInterfaceException
2009
+	 * @throws ReflectionException
2010
+	 * @throws EntityNotFoundException
2011
+	 */
2012
+	public function _reg_details_meta_box()
2013
+	{
2014
+		EEH_Autoloader::register_line_item_display_autoloaders();
2015
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2016
+		EE_Registry::instance()->load_helper('Line_Item');
2017
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2018
+			: EE_Transaction::new_instance();
2019
+		$this->_session = $transaction->session_data();
2020
+		$filters        = new EE_Line_Item_Filter_Collection();
2021
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2022
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
2023
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2024
+			$filters,
2025
+			$transaction->total_line_item()
2026
+		);
2027
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2028
+		$line_item_display                       = new EE_Line_Item_Display(
2029
+			'reg_admin_table',
2030
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2031
+		);
2032
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2033
+			$filtered_line_item_tree,
2034
+			['EE_Registration' => $this->_registration]
2035
+		);
2036
+		$attendee                                = $this->_registration->attendee();
2037
+		if (
2038
+			EE_Registry::instance()->CAP->current_user_can(
2039
+				'ee_read_transaction',
2040
+				'espresso_transactions_view_transaction'
2041
+			)
2042
+		) {
2043
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2044
+				EE_Admin_Page::add_query_args_and_nonce(
2045
+					[
2046
+						'action' => 'view_transaction',
2047
+						'TXN_ID' => $transaction->ID(),
2048
+					],
2049
+					TXN_ADMIN_URL
2050
+				),
2051
+				esc_html__(' View Transaction', 'event_espresso'),
2052
+				'button secondary-button right',
2053
+				'dashicons dashicons-cart'
2054
+			);
2055
+		} else {
2056
+			$this->_template_args['view_transaction_button'] = '';
2057
+		}
2058
+		if (
2059
+			$attendee instanceof EE_Attendee
2060
+			&& EE_Registry::instance()->CAP->current_user_can(
2061
+				'ee_send_message',
2062
+				'espresso_registrations_resend_registration'
2063
+			)
2064
+		) {
2065
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2066
+				EE_Admin_Page::add_query_args_and_nonce(
2067
+					[
2068
+						'action'      => 'resend_registration',
2069
+						'_REG_ID'     => $this->_registration->ID(),
2070
+						'redirect_to' => 'view_registration',
2071
+					],
2072
+					REG_ADMIN_URL
2073
+				),
2074
+				esc_html__(' Resend Registration', 'event_espresso'),
2075
+				'button secondary-button right',
2076
+				'dashicons dashicons-email-alt'
2077
+			);
2078
+		} else {
2079
+			$this->_template_args['resend_registration_button'] = '';
2080
+		}
2081
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2082
+		$payment                               = $transaction->get_first_related('Payment');
2083
+		$payment                               = ! $payment instanceof EE_Payment
2084
+			? EE_Payment::new_instance()
2085
+			: $payment;
2086
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2087
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2088
+			? EE_Payment_Method::new_instance()
2089
+			: $payment_method;
2090
+		$reg_details                           = [
2091
+			'payment_method'       => $payment_method->name(),
2092
+			'response_msg'         => $payment->gateway_response(),
2093
+			'registration_id'      => $this->_registration->get('REG_code'),
2094
+			'registration_session' => $this->_registration->session_ID(),
2095
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2096
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2097
+		];
2098
+		if (isset($reg_details['registration_id'])) {
2099
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2100
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2101
+				'Registration ID',
2102
+				'event_espresso'
2103
+			);
2104
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2105
+		}
2106
+		if (isset($reg_details['payment_method'])) {
2107
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2108
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2109
+				'Most Recent Payment Method',
2110
+				'event_espresso'
2111
+			);
2112
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2113
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2114
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2115
+				'Payment method response',
2116
+				'event_espresso'
2117
+			);
2118
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2119
+		}
2120
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2121
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2122
+			'Registration Session',
2123
+			'event_espresso'
2124
+		);
2125
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2126
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2127
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2128
+			'Registration placed from IP',
2129
+			'event_espresso'
2130
+		);
2131
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2132
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2133
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2134
+			'Registrant User Agent',
2135
+			'event_espresso'
2136
+		);
2137
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2138
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2139
+			[
2140
+				'action'   => 'default',
2141
+				'event_id' => $this->_registration->event_ID(),
2142
+			],
2143
+			REG_ADMIN_URL
2144
+		);
2145
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2146
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2147
+		$template_path                                                        =
2148
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2149
+		EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2150
+	}
2151
+
2152
+
2153
+	/**
2154
+	 * generates HTML for the Registration Questions meta box.
2155
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2156
+	 * otherwise uses new forms system
2157
+	 *
2158
+	 * @return void
2159
+	 * @throws DomainException
2160
+	 * @throws EE_Error
2161
+	 * @throws InvalidArgumentException
2162
+	 * @throws InvalidDataTypeException
2163
+	 * @throws InvalidInterfaceException
2164
+	 * @throws ReflectionException
2165
+	 */
2166
+	public function _reg_questions_meta_box()
2167
+	{
2168
+		// allow someone to override this method entirely
2169
+		if (
2170
+			apply_filters(
2171
+				'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2172
+				true,
2173
+				$this,
2174
+				$this->_registration
2175
+			)
2176
+		) {
2177
+			$form                                              = $this->_get_reg_custom_questions_form(
2178
+				$this->_registration->ID()
2179
+			);
2180
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2181
+				? $form->get_html_and_js()
2182
+				: '';
2183
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2184
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2185
+			$template_path                                     =
2186
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2187
+			EEH_Template::display_template($template_path, $this->_template_args);
2188
+		}
2189
+	}
2190
+
2191
+
2192
+	/**
2193
+	 * form_before_question_group
2194
+	 *
2195
+	 * @param string $output
2196
+	 * @return        string
2197
+	 * @deprecated    as of 4.8.32.rc.000
2198
+	 */
2199
+	public function form_before_question_group($output)
2200
+	{
2201
+		EE_Error::doing_it_wrong(
2202
+			__CLASS__ . '::' . __FUNCTION__,
2203
+			esc_html__(
2204
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2205
+				'event_espresso'
2206
+			),
2207
+			'4.8.32.rc.000'
2208
+		);
2209
+		return '
2210 2210
 	<table class="form-table ee-width-100">
2211 2211
 		<tbody>
2212 2212
 			';
2213
-    }
2214
-
2215
-
2216
-    /**
2217
-     * form_after_question_group
2218
-     *
2219
-     * @param string $output
2220
-     * @return        string
2221
-     * @deprecated    as of 4.8.32.rc.000
2222
-     */
2223
-    public function form_after_question_group($output)
2224
-    {
2225
-        EE_Error::doing_it_wrong(
2226
-            __CLASS__ . '::' . __FUNCTION__,
2227
-            esc_html__(
2228
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2229
-                'event_espresso'
2230
-            ),
2231
-            '4.8.32.rc.000'
2232
-        );
2233
-        return '
2213
+	}
2214
+
2215
+
2216
+	/**
2217
+	 * form_after_question_group
2218
+	 *
2219
+	 * @param string $output
2220
+	 * @return        string
2221
+	 * @deprecated    as of 4.8.32.rc.000
2222
+	 */
2223
+	public function form_after_question_group($output)
2224
+	{
2225
+		EE_Error::doing_it_wrong(
2226
+			__CLASS__ . '::' . __FUNCTION__,
2227
+			esc_html__(
2228
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2229
+				'event_espresso'
2230
+			),
2231
+			'4.8.32.rc.000'
2232
+		);
2233
+		return '
2234 2234
 			<tr class="hide-if-no-js">
2235 2235
 				<th> </th>
2236 2236
 				<td class="reg-admin-edit-attendee-question-td">
2237 2237
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2238
-               . esc_attr__('click to edit question', 'event_espresso')
2239
-               . '">
2238
+			   . esc_attr__('click to edit question', 'event_espresso')
2239
+			   . '">
2240 2240
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2241
-               . esc_html__('edit the above question group', 'event_espresso')
2242
-               . '</span>
2241
+			   . esc_html__('edit the above question group', 'event_espresso')
2242
+			   . '</span>
2243 2243
 						<div class="dashicons dashicons-edit"></div>
2244 2244
 					</a>
2245 2245
 				</td>
@@ -2247,637 +2247,637 @@  discard block
 block discarded – undo
2247 2247
 		</tbody>
2248 2248
 	</table>
2249 2249
 ';
2250
-    }
2251
-
2252
-
2253
-    /**
2254
-     * form_form_field_label_wrap
2255
-     *
2256
-     * @param string $label
2257
-     * @return        string
2258
-     * @deprecated    as of 4.8.32.rc.000
2259
-     */
2260
-    public function form_form_field_label_wrap($label)
2261
-    {
2262
-        EE_Error::doing_it_wrong(
2263
-            __CLASS__ . '::' . __FUNCTION__,
2264
-            esc_html__(
2265
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2266
-                'event_espresso'
2267
-            ),
2268
-            '4.8.32.rc.000'
2269
-        );
2270
-        return '
2250
+	}
2251
+
2252
+
2253
+	/**
2254
+	 * form_form_field_label_wrap
2255
+	 *
2256
+	 * @param string $label
2257
+	 * @return        string
2258
+	 * @deprecated    as of 4.8.32.rc.000
2259
+	 */
2260
+	public function form_form_field_label_wrap($label)
2261
+	{
2262
+		EE_Error::doing_it_wrong(
2263
+			__CLASS__ . '::' . __FUNCTION__,
2264
+			esc_html__(
2265
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2266
+				'event_espresso'
2267
+			),
2268
+			'4.8.32.rc.000'
2269
+		);
2270
+		return '
2271 2271
 			<tr>
2272 2272
 				<th>
2273 2273
 					' . $label . '
2274 2274
 				</th>';
2275
-    }
2276
-
2277
-
2278
-    /**
2279
-     * form_form_field_input__wrap
2280
-     *
2281
-     * @param string $input
2282
-     * @return        string
2283
-     * @deprecated    as of 4.8.32.rc.000
2284
-     */
2285
-    public function form_form_field_input__wrap($input)
2286
-    {
2287
-        EE_Error::doing_it_wrong(
2288
-            __CLASS__ . '::' . __FUNCTION__,
2289
-            esc_html__(
2290
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2291
-                'event_espresso'
2292
-            ),
2293
-            '4.8.32.rc.000'
2294
-        );
2295
-        return '
2275
+	}
2276
+
2277
+
2278
+	/**
2279
+	 * form_form_field_input__wrap
2280
+	 *
2281
+	 * @param string $input
2282
+	 * @return        string
2283
+	 * @deprecated    as of 4.8.32.rc.000
2284
+	 */
2285
+	public function form_form_field_input__wrap($input)
2286
+	{
2287
+		EE_Error::doing_it_wrong(
2288
+			__CLASS__ . '::' . __FUNCTION__,
2289
+			esc_html__(
2290
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2291
+				'event_espresso'
2292
+			),
2293
+			'4.8.32.rc.000'
2294
+		);
2295
+		return '
2296 2296
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2297 2297
 					' . $input . '
2298 2298
 				</td>
2299 2299
 			</tr>';
2300
-    }
2301
-
2302
-
2303
-    /**
2304
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2305
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2306
-     * to display the page
2307
-     *
2308
-     * @return void
2309
-     * @throws EE_Error
2310
-     * @throws InvalidArgumentException
2311
-     * @throws InvalidDataTypeException
2312
-     * @throws InvalidInterfaceException
2313
-     * @throws ReflectionException
2314
-     */
2315
-    protected function _update_attendee_registration_form()
2316
-    {
2317
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2318
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2319
-            $REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2320
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2321
-            if ($success) {
2322
-                $what  = esc_html__('Registration Form', 'event_espresso');
2323
-                $route = $REG_ID
2324
-                    ? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2325
-                    : ['action' => 'default'];
2326
-                $this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2327
-            }
2328
-        }
2329
-    }
2330
-
2331
-
2332
-    /**
2333
-     * Gets the form for saving registrations custom questions (if done
2334
-     * previously retrieves the cached form object, which may have validation errors in it)
2335
-     *
2336
-     * @param int $REG_ID
2337
-     * @return EE_Registration_Custom_Questions_Form
2338
-     * @throws EE_Error
2339
-     * @throws InvalidArgumentException
2340
-     * @throws InvalidDataTypeException
2341
-     * @throws InvalidInterfaceException
2342
-     * @throws ReflectionException
2343
-     */
2344
-    protected function _get_reg_custom_questions_form($REG_ID)
2345
-    {
2346
-        if (! $this->_reg_custom_questions_form) {
2347
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2348
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2349
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2350
-            );
2351
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2352
-        }
2353
-        return $this->_reg_custom_questions_form;
2354
-    }
2355
-
2356
-
2357
-    /**
2358
-     * Saves
2359
-     *
2360
-     * @param bool $REG_ID
2361
-     * @return bool
2362
-     * @throws EE_Error
2363
-     * @throws InvalidArgumentException
2364
-     * @throws InvalidDataTypeException
2365
-     * @throws InvalidInterfaceException
2366
-     * @throws ReflectionException
2367
-     */
2368
-    private function _save_reg_custom_questions_form($REG_ID = 0)
2369
-    {
2370
-        if (! $REG_ID) {
2371
-            EE_Error::add_error(
2372
-                esc_html__(
2373
-                    'An error occurred. No registration ID was received.',
2374
-                    'event_espresso'
2375
-                ),
2376
-                __FILE__,
2377
-                __FUNCTION__,
2378
-                __LINE__
2379
-            );
2380
-        }
2381
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2382
-        $form->receive_form_submission($this->request->requestParams());
2383
-        $success = false;
2384
-        if ($form->is_valid()) {
2385
-            foreach ($form->subforms() as $question_group_form) {
2386
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2387
-                    $where_conditions    = [
2388
-                        'QST_ID' => $question_id,
2389
-                        'REG_ID' => $REG_ID,
2390
-                    ];
2391
-                    $possibly_new_values = [
2392
-                        'ANS_value' => $input->normalized_value(),
2393
-                    ];
2394
-                    $answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2395
-                    if ($answer instanceof EE_Answer) {
2396
-                        $success = $answer->save($possibly_new_values);
2397
-                    } else {
2398
-                        // insert it then
2399
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2400
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2401
-                        $success     = $answer->save();
2402
-                    }
2403
-                }
2404
-            }
2405
-        } else {
2406
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2407
-        }
2408
-        return $success;
2409
-    }
2410
-
2411
-
2412
-    /**
2413
-     * generates HTML for the Registration main meta box
2414
-     *
2415
-     * @return void
2416
-     * @throws DomainException
2417
-     * @throws EE_Error
2418
-     * @throws InvalidArgumentException
2419
-     * @throws InvalidDataTypeException
2420
-     * @throws InvalidInterfaceException
2421
-     * @throws ReflectionException
2422
-     */
2423
-    public function _reg_attendees_meta_box()
2424
-    {
2425
-        $REG = $this->getRegistrationModel();
2426
-        // get all other registrations on this transaction, and cache
2427
-        // the attendees for them so we don't have to run another query using force_join
2428
-        $registrations                           = $REG->get_all(
2429
-            [
2430
-                [
2431
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2432
-                    'REG_ID' => ['!=', $this->_registration->ID()],
2433
-                ],
2434
-                'force_join'               => ['Attendee'],
2435
-                'default_where_conditions' => 'other_models_only',
2436
-            ]
2437
-        );
2438
-        $this->_template_args['attendees']       = [];
2439
-        $this->_template_args['attendee_notice'] = '';
2440
-        if (
2441
-            empty($registrations)
2442
-            || (is_array($registrations)
2443
-                && ! EEH_Array::get_one_item_from_array($registrations))
2444
-        ) {
2445
-            EE_Error::add_error(
2446
-                esc_html__(
2447
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2448
-                    'event_espresso'
2449
-                ),
2450
-                __FILE__,
2451
-                __FUNCTION__,
2452
-                __LINE__
2453
-            );
2454
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2455
-        } else {
2456
-            $att_nmbr = 1;
2457
-            foreach ($registrations as $registration) {
2458
-                /* @var $registration EE_Registration */
2459
-                $attendee                                                      = $registration->attendee()
2460
-                    ? $registration->attendee()
2461
-                    : $this->getAttendeeModel()->create_default_object();
2462
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2463
-                $this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2464
-                $this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2465
-                $this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2466
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2467
-                $this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2468
-                    ', ',
2469
-                    $attendee->full_address_as_array()
2470
-                );
2471
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2472
-                    [
2473
-                        'action' => 'edit_attendee',
2474
-                        'post'   => $attendee->ID(),
2475
-                    ],
2476
-                    REG_ADMIN_URL
2477
-                );
2478
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2479
-                    $registration->event_obj() instanceof EE_Event
2480
-                        ? $registration->event_obj()->name()
2481
-                        : '';
2482
-                $att_nmbr++;
2483
-            }
2484
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2485
-        }
2486
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2487
-        EEH_Template::display_template($template_path, $this->_template_args);
2488
-    }
2489
-
2490
-
2491
-    /**
2492
-     * generates HTML for the Edit Registration side meta box
2493
-     *
2494
-     * @return void
2495
-     * @throws DomainException
2496
-     * @throws EE_Error
2497
-     * @throws InvalidArgumentException
2498
-     * @throws InvalidDataTypeException
2499
-     * @throws InvalidInterfaceException
2500
-     * @throws ReflectionException
2501
-     */
2502
-    public function _reg_registrant_side_meta_box()
2503
-    {
2504
-        /*@var $attendee EE_Attendee */
2505
-        $att_check = $this->_registration->attendee();
2506
-        $attendee  = $att_check instanceof EE_Attendee
2507
-            ? $att_check
2508
-            : $this->getAttendeeModel()->create_default_object();
2509
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2510
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2511
-        // primary registration object (that way we know if we need to show create button or not)
2512
-        if (! $this->_registration->is_primary_registrant()) {
2513
-            $primary_registration = $this->_registration->get_primary_registration();
2514
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2515
-                : null;
2516
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2517
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2518
-                // custom attendee object so let's not worry about the primary reg.
2519
-                $primary_registration = null;
2520
-            }
2521
-        } else {
2522
-            $primary_registration = null;
2523
-        }
2524
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2525
-        $this->_template_args['fname']             = $attendee->fname();
2526
-        $this->_template_args['lname']             = $attendee->lname();
2527
-        $this->_template_args['email']             = $attendee->email();
2528
-        $this->_template_args['phone']             = $attendee->phone();
2529
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2530
-        // edit link
2531
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2532
-            [
2533
-                'action' => 'edit_attendee',
2534
-                'post'   => $attendee->ID(),
2535
-            ],
2536
-            REG_ADMIN_URL
2537
-        );
2538
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2539
-        // create link
2540
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2541
-            ? EE_Admin_Page::add_query_args_and_nonce(
2542
-                [
2543
-                    'action'  => 'duplicate_attendee',
2544
-                    '_REG_ID' => $this->_registration->ID(),
2545
-                ],
2546
-                REG_ADMIN_URL
2547
-            ) : '';
2548
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2549
-        $this->_template_args['att_check']    = $att_check;
2550
-        $template_path                        =
2551
-            REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2552
-        EEH_Template::display_template($template_path, $this->_template_args);
2553
-    }
2554
-
2555
-
2556
-    /**
2557
-     * trash or restore registrations
2558
-     *
2559
-     * @param boolean $trash whether to archive or restore
2560
-     * @return void
2561
-     * @throws EE_Error
2562
-     * @throws InvalidArgumentException
2563
-     * @throws InvalidDataTypeException
2564
-     * @throws InvalidInterfaceException
2565
-     * @throws RuntimeException
2566
-     */
2567
-    protected function _trash_or_restore_registrations($trash = true)
2568
-    {
2569
-        // if empty _REG_ID then get out because there's nothing to do
2570
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2571
-        if (empty($REG_IDs)) {
2572
-            EE_Error::add_error(
2573
-                sprintf(
2574
-                    esc_html__(
2575
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2576
-                        'event_espresso'
2577
-                    ),
2578
-                    $trash ? 'trash' : 'restore'
2579
-                ),
2580
-                __FILE__,
2581
-                __LINE__,
2582
-                __FUNCTION__
2583
-            );
2584
-            $this->_redirect_after_action(false, '', '', [], true);
2585
-        }
2586
-        $success        = 0;
2587
-        $overwrite_msgs = false;
2588
-        // Checkboxes
2589
-        $reg_count = count($REG_IDs);
2590
-        // cycle thru checkboxes
2591
-        foreach ($REG_IDs as $REG_ID) {
2592
-            /** @var EE_Registration $REG */
2593
-            $REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2594
-            $payments = $REG->registration_payments();
2595
-            if (! empty($payments)) {
2596
-                $name           = $REG->attendee() instanceof EE_Attendee
2597
-                    ? $REG->attendee()->full_name()
2598
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2599
-                $overwrite_msgs = true;
2600
-                EE_Error::add_error(
2601
-                    sprintf(
2602
-                        esc_html__(
2603
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2604
-                            'event_espresso'
2605
-                        ),
2606
-                        $name
2607
-                    ),
2608
-                    __FILE__,
2609
-                    __FUNCTION__,
2610
-                    __LINE__
2611
-                );
2612
-                // can't trash this registration because it has payments.
2613
-                continue;
2614
-            }
2615
-            $updated = $trash ? $REG->delete() : $REG->restore();
2616
-            if ($updated) {
2617
-                $success++;
2618
-            }
2619
-        }
2620
-        $this->_redirect_after_action(
2621
-            $success === $reg_count, // were ALL registrations affected?
2622
-            $success > 1
2623
-                ? esc_html__('Registrations', 'event_espresso')
2624
-                : esc_html__('Registration', 'event_espresso'),
2625
-            $trash
2626
-                ? esc_html__('moved to the trash', 'event_espresso')
2627
-                : esc_html__('restored', 'event_espresso'),
2628
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2629
-            $overwrite_msgs
2630
-        );
2631
-    }
2632
-
2633
-
2634
-    /**
2635
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2636
-     * registration but also.
2637
-     * 1. Removing relations to EE_Attendee
2638
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2639
-     * ALSO trashed.
2640
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2641
-     * 4. Removing relationships between all tickets and the related registrations
2642
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2643
-     * 6. Deleting permanently any related Checkins.
2644
-     *
2645
-     * @return void
2646
-     * @throws EE_Error
2647
-     * @throws InvalidArgumentException
2648
-     * @throws InvalidDataTypeException
2649
-     * @throws InvalidInterfaceException
2650
-     * @throws ReflectionException
2651
-     */
2652
-    protected function _delete_registrations()
2653
-    {
2654
-        $REG_MDL = $this->getRegistrationModel();
2655
-        $success = 0;
2656
-        // Checkboxes
2657
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2658
-
2659
-        if (! empty($REG_IDs)) {
2660
-            // if array has more than one element than success message should be plural
2661
-            $success = count($REG_IDs) > 1 ? 2 : 1;
2662
-            // cycle thru checkboxes
2663
-            foreach ($REG_IDs as $REG_ID) {
2664
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2665
-                if (! $REG instanceof EE_Registration) {
2666
-                    continue;
2667
-                }
2668
-                $deleted = $this->_delete_registration($REG);
2669
-                if (! $deleted) {
2670
-                    $success = 0;
2671
-                }
2672
-            }
2673
-        }
2674
-
2675
-        $what        = $success > 1
2676
-            ? esc_html__('Registrations', 'event_espresso')
2677
-            : esc_html__('Registration', 'event_espresso');
2678
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2679
-        $this->_redirect_after_action(
2680
-            $success,
2681
-            $what,
2682
-            $action_desc,
2683
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2684
-            true
2685
-        );
2686
-    }
2687
-
2688
-
2689
-    /**
2690
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2691
-     * models get affected.
2692
-     *
2693
-     * @param EE_Registration $REG registration to be deleted permanently
2694
-     * @return bool true = successful deletion, false = fail.
2695
-     * @throws EE_Error
2696
-     * @throws InvalidArgumentException
2697
-     * @throws InvalidDataTypeException
2698
-     * @throws InvalidInterfaceException
2699
-     * @throws ReflectionException
2700
-     */
2701
-    protected function _delete_registration(EE_Registration $REG)
2702
-    {
2703
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2704
-        // registrations on the transaction that are NOT trashed.
2705
-        $TXN = $REG->get_first_related('Transaction');
2706
-        if (! $TXN instanceof EE_Transaction) {
2707
-            EE_Error::add_error(
2708
-                sprintf(
2709
-                    esc_html__(
2710
-                        'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2711
-                        'event_espresso'
2712
-                    ),
2713
-                    $REG->id()
2714
-                ),
2715
-                __FILE__,
2716
-                __FUNCTION__,
2717
-                __LINE__
2718
-            );
2719
-            return false;
2720
-        }
2721
-        $REGS        = $TXN->get_many_related('Registration');
2722
-        $all_trashed = true;
2723
-        foreach ($REGS as $registration) {
2724
-            if (! $registration->get('REG_deleted')) {
2725
-                $all_trashed = false;
2726
-            }
2727
-        }
2728
-        if (! $all_trashed) {
2729
-            EE_Error::add_error(
2730
-                esc_html__(
2731
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2732
-                    'event_espresso'
2733
-                ),
2734
-                __FILE__,
2735
-                __FUNCTION__,
2736
-                __LINE__
2737
-            );
2738
-            return false;
2739
-        }
2740
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2741
-        // separately from THIS one).
2742
-        foreach ($REGS as $registration) {
2743
-            // delete related answers
2744
-            $registration->delete_related_permanently('Answer');
2745
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2746
-            $attendee = $registration->get_first_related('Attendee');
2747
-            if ($attendee instanceof EE_Attendee) {
2748
-                $registration->_remove_relation_to($attendee, 'Attendee');
2749
-            }
2750
-            // now remove relationships to tickets on this registration.
2751
-            $registration->_remove_relations('Ticket');
2752
-            // now delete permanently the checkins related to this registration.
2753
-            $registration->delete_related_permanently('Checkin');
2754
-            if ($registration->ID() === $REG->ID()) {
2755
-                continue;
2756
-            } //we don't want to delete permanently the existing registration just yet.
2757
-            // remove relation to transaction for these registrations if NOT the existing registrations
2758
-            $registration->_remove_relations('Transaction');
2759
-            // delete permanently any related messages.
2760
-            $registration->delete_related_permanently('Message');
2761
-            // now delete this registration permanently
2762
-            $registration->delete_permanently();
2763
-        }
2764
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2765
-        // (the transaction and line items should be all that's left).
2766
-        // delete the line items related to the transaction for this registration.
2767
-        $TXN->delete_related_permanently('Line_Item');
2768
-        // we need to remove all the relationships on the transaction
2769
-        $TXN->delete_related_permanently('Payment');
2770
-        $TXN->delete_related_permanently('Extra_Meta');
2771
-        $TXN->delete_related_permanently('Message');
2772
-        // now we can delete this REG permanently (and the transaction of course)
2773
-        $REG->delete_related_permanently('Transaction');
2774
-        return $REG->delete_permanently();
2775
-    }
2776
-
2777
-
2778
-    /**
2779
-     *    generates HTML for the Register New Attendee Admin page
2780
-     *
2781
-     * @throws DomainException
2782
-     * @throws EE_Error
2783
-     * @throws InvalidArgumentException
2784
-     * @throws InvalidDataTypeException
2785
-     * @throws InvalidInterfaceException
2786
-     * @throws ReflectionException
2787
-     */
2788
-    public function new_registration()
2789
-    {
2790
-        if (! $this->_set_reg_event()) {
2791
-            throw new EE_Error(
2792
-                esc_html__(
2793
-                    'Unable to continue with registering because there is no Event ID in the request',
2794
-                    'event_espresso'
2795
-                )
2796
-            );
2797
-        }
2798
-        /** @var CurrentPage $current_page */
2799
-        $current_page = $this->loader->getShared(CurrentPage::class);
2800
-        $current_page->setEspressoPage(true);
2801
-        // gotta start with a clean slate if we're not coming here via ajax
2802
-        if (
2803
-            ! $this->request->isAjax()
2804
-            && (
2805
-                ! $this->request->requestParamIsSet('processing_registration')
2806
-                || $this->request->requestParamIsSet('step_error')
2807
-            )
2808
-        ) {
2809
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2810
-        }
2811
-        $this->_template_args['event_name'] = '';
2812
-        // event name
2813
-        if ($this->_reg_event) {
2814
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2815
-            $edit_event_url                     = self::add_query_args_and_nonce(
2816
-                [
2817
-                    'action' => 'edit',
2818
-                    'post'   => $this->_reg_event->ID(),
2819
-                ],
2820
-                EVENTS_ADMIN_URL
2821
-            );
2822
-            $edit_event_lnk                     = '<a href="'
2823
-                                                  . $edit_event_url
2824
-                                                  . '" title="'
2825
-                                                  . esc_attr__('Edit ', 'event_espresso')
2826
-                                                  . $this->_reg_event->name()
2827
-                                                  . '">'
2828
-                                                  . esc_html__('Edit Event', 'event_espresso')
2829
-                                                  . '</a>';
2830
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2831
-                                                   . $edit_event_lnk
2832
-                                                   . '</span>';
2833
-        }
2834
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2835
-        if ($this->request->isAjax()) {
2836
-            $this->_return_json();
2837
-        }
2838
-        // grab header
2839
-        $template_path                              =
2840
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2841
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2842
-            $template_path,
2843
-            $this->_template_args,
2844
-            true
2845
-        );
2846
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2847
-        // the details template wrapper
2848
-        $this->display_admin_page_with_sidebar();
2849
-    }
2850
-
2851
-
2852
-    /**
2853
-     * This returns the content for a registration step
2854
-     *
2855
-     * @return string html
2856
-     * @throws DomainException
2857
-     * @throws EE_Error
2858
-     * @throws InvalidArgumentException
2859
-     * @throws InvalidDataTypeException
2860
-     * @throws InvalidInterfaceException
2861
-     * @throws ReflectionException
2862
-     */
2863
-    protected function _get_registration_step_content()
2864
-    {
2865
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2866
-            $warning_msg = sprintf(
2867
-                esc_html__(
2868
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2869
-                    'event_espresso'
2870
-                ),
2871
-                '<br />',
2872
-                '<h3 class="important-notice">',
2873
-                '</h3>',
2874
-                '<div class="float-right">',
2875
-                '<span id="redirect_timer" class="important-notice">30</span>',
2876
-                '</div>',
2877
-                '<b>',
2878
-                '</b>'
2879
-            );
2880
-            return '
2300
+	}
2301
+
2302
+
2303
+	/**
2304
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2305
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2306
+	 * to display the page
2307
+	 *
2308
+	 * @return void
2309
+	 * @throws EE_Error
2310
+	 * @throws InvalidArgumentException
2311
+	 * @throws InvalidDataTypeException
2312
+	 * @throws InvalidInterfaceException
2313
+	 * @throws ReflectionException
2314
+	 */
2315
+	protected function _update_attendee_registration_form()
2316
+	{
2317
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2318
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2319
+			$REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2320
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2321
+			if ($success) {
2322
+				$what  = esc_html__('Registration Form', 'event_espresso');
2323
+				$route = $REG_ID
2324
+					? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2325
+					: ['action' => 'default'];
2326
+				$this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2327
+			}
2328
+		}
2329
+	}
2330
+
2331
+
2332
+	/**
2333
+	 * Gets the form for saving registrations custom questions (if done
2334
+	 * previously retrieves the cached form object, which may have validation errors in it)
2335
+	 *
2336
+	 * @param int $REG_ID
2337
+	 * @return EE_Registration_Custom_Questions_Form
2338
+	 * @throws EE_Error
2339
+	 * @throws InvalidArgumentException
2340
+	 * @throws InvalidDataTypeException
2341
+	 * @throws InvalidInterfaceException
2342
+	 * @throws ReflectionException
2343
+	 */
2344
+	protected function _get_reg_custom_questions_form($REG_ID)
2345
+	{
2346
+		if (! $this->_reg_custom_questions_form) {
2347
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2348
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2349
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2350
+			);
2351
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2352
+		}
2353
+		return $this->_reg_custom_questions_form;
2354
+	}
2355
+
2356
+
2357
+	/**
2358
+	 * Saves
2359
+	 *
2360
+	 * @param bool $REG_ID
2361
+	 * @return bool
2362
+	 * @throws EE_Error
2363
+	 * @throws InvalidArgumentException
2364
+	 * @throws InvalidDataTypeException
2365
+	 * @throws InvalidInterfaceException
2366
+	 * @throws ReflectionException
2367
+	 */
2368
+	private function _save_reg_custom_questions_form($REG_ID = 0)
2369
+	{
2370
+		if (! $REG_ID) {
2371
+			EE_Error::add_error(
2372
+				esc_html__(
2373
+					'An error occurred. No registration ID was received.',
2374
+					'event_espresso'
2375
+				),
2376
+				__FILE__,
2377
+				__FUNCTION__,
2378
+				__LINE__
2379
+			);
2380
+		}
2381
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2382
+		$form->receive_form_submission($this->request->requestParams());
2383
+		$success = false;
2384
+		if ($form->is_valid()) {
2385
+			foreach ($form->subforms() as $question_group_form) {
2386
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2387
+					$where_conditions    = [
2388
+						'QST_ID' => $question_id,
2389
+						'REG_ID' => $REG_ID,
2390
+					];
2391
+					$possibly_new_values = [
2392
+						'ANS_value' => $input->normalized_value(),
2393
+					];
2394
+					$answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2395
+					if ($answer instanceof EE_Answer) {
2396
+						$success = $answer->save($possibly_new_values);
2397
+					} else {
2398
+						// insert it then
2399
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2400
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2401
+						$success     = $answer->save();
2402
+					}
2403
+				}
2404
+			}
2405
+		} else {
2406
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2407
+		}
2408
+		return $success;
2409
+	}
2410
+
2411
+
2412
+	/**
2413
+	 * generates HTML for the Registration main meta box
2414
+	 *
2415
+	 * @return void
2416
+	 * @throws DomainException
2417
+	 * @throws EE_Error
2418
+	 * @throws InvalidArgumentException
2419
+	 * @throws InvalidDataTypeException
2420
+	 * @throws InvalidInterfaceException
2421
+	 * @throws ReflectionException
2422
+	 */
2423
+	public function _reg_attendees_meta_box()
2424
+	{
2425
+		$REG = $this->getRegistrationModel();
2426
+		// get all other registrations on this transaction, and cache
2427
+		// the attendees for them so we don't have to run another query using force_join
2428
+		$registrations                           = $REG->get_all(
2429
+			[
2430
+				[
2431
+					'TXN_ID' => $this->_registration->transaction_ID(),
2432
+					'REG_ID' => ['!=', $this->_registration->ID()],
2433
+				],
2434
+				'force_join'               => ['Attendee'],
2435
+				'default_where_conditions' => 'other_models_only',
2436
+			]
2437
+		);
2438
+		$this->_template_args['attendees']       = [];
2439
+		$this->_template_args['attendee_notice'] = '';
2440
+		if (
2441
+			empty($registrations)
2442
+			|| (is_array($registrations)
2443
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2444
+		) {
2445
+			EE_Error::add_error(
2446
+				esc_html__(
2447
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2448
+					'event_espresso'
2449
+				),
2450
+				__FILE__,
2451
+				__FUNCTION__,
2452
+				__LINE__
2453
+			);
2454
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2455
+		} else {
2456
+			$att_nmbr = 1;
2457
+			foreach ($registrations as $registration) {
2458
+				/* @var $registration EE_Registration */
2459
+				$attendee                                                      = $registration->attendee()
2460
+					? $registration->attendee()
2461
+					: $this->getAttendeeModel()->create_default_object();
2462
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2463
+				$this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2464
+				$this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2465
+				$this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2466
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2467
+				$this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2468
+					', ',
2469
+					$attendee->full_address_as_array()
2470
+				);
2471
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2472
+					[
2473
+						'action' => 'edit_attendee',
2474
+						'post'   => $attendee->ID(),
2475
+					],
2476
+					REG_ADMIN_URL
2477
+				);
2478
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2479
+					$registration->event_obj() instanceof EE_Event
2480
+						? $registration->event_obj()->name()
2481
+						: '';
2482
+				$att_nmbr++;
2483
+			}
2484
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2485
+		}
2486
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2487
+		EEH_Template::display_template($template_path, $this->_template_args);
2488
+	}
2489
+
2490
+
2491
+	/**
2492
+	 * generates HTML for the Edit Registration side meta box
2493
+	 *
2494
+	 * @return void
2495
+	 * @throws DomainException
2496
+	 * @throws EE_Error
2497
+	 * @throws InvalidArgumentException
2498
+	 * @throws InvalidDataTypeException
2499
+	 * @throws InvalidInterfaceException
2500
+	 * @throws ReflectionException
2501
+	 */
2502
+	public function _reg_registrant_side_meta_box()
2503
+	{
2504
+		/*@var $attendee EE_Attendee */
2505
+		$att_check = $this->_registration->attendee();
2506
+		$attendee  = $att_check instanceof EE_Attendee
2507
+			? $att_check
2508
+			: $this->getAttendeeModel()->create_default_object();
2509
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2510
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2511
+		// primary registration object (that way we know if we need to show create button or not)
2512
+		if (! $this->_registration->is_primary_registrant()) {
2513
+			$primary_registration = $this->_registration->get_primary_registration();
2514
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2515
+				: null;
2516
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2517
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2518
+				// custom attendee object so let's not worry about the primary reg.
2519
+				$primary_registration = null;
2520
+			}
2521
+		} else {
2522
+			$primary_registration = null;
2523
+		}
2524
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2525
+		$this->_template_args['fname']             = $attendee->fname();
2526
+		$this->_template_args['lname']             = $attendee->lname();
2527
+		$this->_template_args['email']             = $attendee->email();
2528
+		$this->_template_args['phone']             = $attendee->phone();
2529
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2530
+		// edit link
2531
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2532
+			[
2533
+				'action' => 'edit_attendee',
2534
+				'post'   => $attendee->ID(),
2535
+			],
2536
+			REG_ADMIN_URL
2537
+		);
2538
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2539
+		// create link
2540
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2541
+			? EE_Admin_Page::add_query_args_and_nonce(
2542
+				[
2543
+					'action'  => 'duplicate_attendee',
2544
+					'_REG_ID' => $this->_registration->ID(),
2545
+				],
2546
+				REG_ADMIN_URL
2547
+			) : '';
2548
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2549
+		$this->_template_args['att_check']    = $att_check;
2550
+		$template_path                        =
2551
+			REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2552
+		EEH_Template::display_template($template_path, $this->_template_args);
2553
+	}
2554
+
2555
+
2556
+	/**
2557
+	 * trash or restore registrations
2558
+	 *
2559
+	 * @param boolean $trash whether to archive or restore
2560
+	 * @return void
2561
+	 * @throws EE_Error
2562
+	 * @throws InvalidArgumentException
2563
+	 * @throws InvalidDataTypeException
2564
+	 * @throws InvalidInterfaceException
2565
+	 * @throws RuntimeException
2566
+	 */
2567
+	protected function _trash_or_restore_registrations($trash = true)
2568
+	{
2569
+		// if empty _REG_ID then get out because there's nothing to do
2570
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2571
+		if (empty($REG_IDs)) {
2572
+			EE_Error::add_error(
2573
+				sprintf(
2574
+					esc_html__(
2575
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2576
+						'event_espresso'
2577
+					),
2578
+					$trash ? 'trash' : 'restore'
2579
+				),
2580
+				__FILE__,
2581
+				__LINE__,
2582
+				__FUNCTION__
2583
+			);
2584
+			$this->_redirect_after_action(false, '', '', [], true);
2585
+		}
2586
+		$success        = 0;
2587
+		$overwrite_msgs = false;
2588
+		// Checkboxes
2589
+		$reg_count = count($REG_IDs);
2590
+		// cycle thru checkboxes
2591
+		foreach ($REG_IDs as $REG_ID) {
2592
+			/** @var EE_Registration $REG */
2593
+			$REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2594
+			$payments = $REG->registration_payments();
2595
+			if (! empty($payments)) {
2596
+				$name           = $REG->attendee() instanceof EE_Attendee
2597
+					? $REG->attendee()->full_name()
2598
+					: esc_html__('Unknown Attendee', 'event_espresso');
2599
+				$overwrite_msgs = true;
2600
+				EE_Error::add_error(
2601
+					sprintf(
2602
+						esc_html__(
2603
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2604
+							'event_espresso'
2605
+						),
2606
+						$name
2607
+					),
2608
+					__FILE__,
2609
+					__FUNCTION__,
2610
+					__LINE__
2611
+				);
2612
+				// can't trash this registration because it has payments.
2613
+				continue;
2614
+			}
2615
+			$updated = $trash ? $REG->delete() : $REG->restore();
2616
+			if ($updated) {
2617
+				$success++;
2618
+			}
2619
+		}
2620
+		$this->_redirect_after_action(
2621
+			$success === $reg_count, // were ALL registrations affected?
2622
+			$success > 1
2623
+				? esc_html__('Registrations', 'event_espresso')
2624
+				: esc_html__('Registration', 'event_espresso'),
2625
+			$trash
2626
+				? esc_html__('moved to the trash', 'event_espresso')
2627
+				: esc_html__('restored', 'event_espresso'),
2628
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2629
+			$overwrite_msgs
2630
+		);
2631
+	}
2632
+
2633
+
2634
+	/**
2635
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2636
+	 * registration but also.
2637
+	 * 1. Removing relations to EE_Attendee
2638
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2639
+	 * ALSO trashed.
2640
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2641
+	 * 4. Removing relationships between all tickets and the related registrations
2642
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2643
+	 * 6. Deleting permanently any related Checkins.
2644
+	 *
2645
+	 * @return void
2646
+	 * @throws EE_Error
2647
+	 * @throws InvalidArgumentException
2648
+	 * @throws InvalidDataTypeException
2649
+	 * @throws InvalidInterfaceException
2650
+	 * @throws ReflectionException
2651
+	 */
2652
+	protected function _delete_registrations()
2653
+	{
2654
+		$REG_MDL = $this->getRegistrationModel();
2655
+		$success = 0;
2656
+		// Checkboxes
2657
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2658
+
2659
+		if (! empty($REG_IDs)) {
2660
+			// if array has more than one element than success message should be plural
2661
+			$success = count($REG_IDs) > 1 ? 2 : 1;
2662
+			// cycle thru checkboxes
2663
+			foreach ($REG_IDs as $REG_ID) {
2664
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2665
+				if (! $REG instanceof EE_Registration) {
2666
+					continue;
2667
+				}
2668
+				$deleted = $this->_delete_registration($REG);
2669
+				if (! $deleted) {
2670
+					$success = 0;
2671
+				}
2672
+			}
2673
+		}
2674
+
2675
+		$what        = $success > 1
2676
+			? esc_html__('Registrations', 'event_espresso')
2677
+			: esc_html__('Registration', 'event_espresso');
2678
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2679
+		$this->_redirect_after_action(
2680
+			$success,
2681
+			$what,
2682
+			$action_desc,
2683
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2684
+			true
2685
+		);
2686
+	}
2687
+
2688
+
2689
+	/**
2690
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2691
+	 * models get affected.
2692
+	 *
2693
+	 * @param EE_Registration $REG registration to be deleted permanently
2694
+	 * @return bool true = successful deletion, false = fail.
2695
+	 * @throws EE_Error
2696
+	 * @throws InvalidArgumentException
2697
+	 * @throws InvalidDataTypeException
2698
+	 * @throws InvalidInterfaceException
2699
+	 * @throws ReflectionException
2700
+	 */
2701
+	protected function _delete_registration(EE_Registration $REG)
2702
+	{
2703
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2704
+		// registrations on the transaction that are NOT trashed.
2705
+		$TXN = $REG->get_first_related('Transaction');
2706
+		if (! $TXN instanceof EE_Transaction) {
2707
+			EE_Error::add_error(
2708
+				sprintf(
2709
+					esc_html__(
2710
+						'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2711
+						'event_espresso'
2712
+					),
2713
+					$REG->id()
2714
+				),
2715
+				__FILE__,
2716
+				__FUNCTION__,
2717
+				__LINE__
2718
+			);
2719
+			return false;
2720
+		}
2721
+		$REGS        = $TXN->get_many_related('Registration');
2722
+		$all_trashed = true;
2723
+		foreach ($REGS as $registration) {
2724
+			if (! $registration->get('REG_deleted')) {
2725
+				$all_trashed = false;
2726
+			}
2727
+		}
2728
+		if (! $all_trashed) {
2729
+			EE_Error::add_error(
2730
+				esc_html__(
2731
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2732
+					'event_espresso'
2733
+				),
2734
+				__FILE__,
2735
+				__FUNCTION__,
2736
+				__LINE__
2737
+			);
2738
+			return false;
2739
+		}
2740
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2741
+		// separately from THIS one).
2742
+		foreach ($REGS as $registration) {
2743
+			// delete related answers
2744
+			$registration->delete_related_permanently('Answer');
2745
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2746
+			$attendee = $registration->get_first_related('Attendee');
2747
+			if ($attendee instanceof EE_Attendee) {
2748
+				$registration->_remove_relation_to($attendee, 'Attendee');
2749
+			}
2750
+			// now remove relationships to tickets on this registration.
2751
+			$registration->_remove_relations('Ticket');
2752
+			// now delete permanently the checkins related to this registration.
2753
+			$registration->delete_related_permanently('Checkin');
2754
+			if ($registration->ID() === $REG->ID()) {
2755
+				continue;
2756
+			} //we don't want to delete permanently the existing registration just yet.
2757
+			// remove relation to transaction for these registrations if NOT the existing registrations
2758
+			$registration->_remove_relations('Transaction');
2759
+			// delete permanently any related messages.
2760
+			$registration->delete_related_permanently('Message');
2761
+			// now delete this registration permanently
2762
+			$registration->delete_permanently();
2763
+		}
2764
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2765
+		// (the transaction and line items should be all that's left).
2766
+		// delete the line items related to the transaction for this registration.
2767
+		$TXN->delete_related_permanently('Line_Item');
2768
+		// we need to remove all the relationships on the transaction
2769
+		$TXN->delete_related_permanently('Payment');
2770
+		$TXN->delete_related_permanently('Extra_Meta');
2771
+		$TXN->delete_related_permanently('Message');
2772
+		// now we can delete this REG permanently (and the transaction of course)
2773
+		$REG->delete_related_permanently('Transaction');
2774
+		return $REG->delete_permanently();
2775
+	}
2776
+
2777
+
2778
+	/**
2779
+	 *    generates HTML for the Register New Attendee Admin page
2780
+	 *
2781
+	 * @throws DomainException
2782
+	 * @throws EE_Error
2783
+	 * @throws InvalidArgumentException
2784
+	 * @throws InvalidDataTypeException
2785
+	 * @throws InvalidInterfaceException
2786
+	 * @throws ReflectionException
2787
+	 */
2788
+	public function new_registration()
2789
+	{
2790
+		if (! $this->_set_reg_event()) {
2791
+			throw new EE_Error(
2792
+				esc_html__(
2793
+					'Unable to continue with registering because there is no Event ID in the request',
2794
+					'event_espresso'
2795
+				)
2796
+			);
2797
+		}
2798
+		/** @var CurrentPage $current_page */
2799
+		$current_page = $this->loader->getShared(CurrentPage::class);
2800
+		$current_page->setEspressoPage(true);
2801
+		// gotta start with a clean slate if we're not coming here via ajax
2802
+		if (
2803
+			! $this->request->isAjax()
2804
+			&& (
2805
+				! $this->request->requestParamIsSet('processing_registration')
2806
+				|| $this->request->requestParamIsSet('step_error')
2807
+			)
2808
+		) {
2809
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2810
+		}
2811
+		$this->_template_args['event_name'] = '';
2812
+		// event name
2813
+		if ($this->_reg_event) {
2814
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2815
+			$edit_event_url                     = self::add_query_args_and_nonce(
2816
+				[
2817
+					'action' => 'edit',
2818
+					'post'   => $this->_reg_event->ID(),
2819
+				],
2820
+				EVENTS_ADMIN_URL
2821
+			);
2822
+			$edit_event_lnk                     = '<a href="'
2823
+												  . $edit_event_url
2824
+												  . '" title="'
2825
+												  . esc_attr__('Edit ', 'event_espresso')
2826
+												  . $this->_reg_event->name()
2827
+												  . '">'
2828
+												  . esc_html__('Edit Event', 'event_espresso')
2829
+												  . '</a>';
2830
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2831
+												   . $edit_event_lnk
2832
+												   . '</span>';
2833
+		}
2834
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2835
+		if ($this->request->isAjax()) {
2836
+			$this->_return_json();
2837
+		}
2838
+		// grab header
2839
+		$template_path                              =
2840
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2841
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2842
+			$template_path,
2843
+			$this->_template_args,
2844
+			true
2845
+		);
2846
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2847
+		// the details template wrapper
2848
+		$this->display_admin_page_with_sidebar();
2849
+	}
2850
+
2851
+
2852
+	/**
2853
+	 * This returns the content for a registration step
2854
+	 *
2855
+	 * @return string html
2856
+	 * @throws DomainException
2857
+	 * @throws EE_Error
2858
+	 * @throws InvalidArgumentException
2859
+	 * @throws InvalidDataTypeException
2860
+	 * @throws InvalidInterfaceException
2861
+	 * @throws ReflectionException
2862
+	 */
2863
+	protected function _get_registration_step_content()
2864
+	{
2865
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2866
+			$warning_msg = sprintf(
2867
+				esc_html__(
2868
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2869
+					'event_espresso'
2870
+				),
2871
+				'<br />',
2872
+				'<h3 class="important-notice">',
2873
+				'</h3>',
2874
+				'<div class="float-right">',
2875
+				'<span id="redirect_timer" class="important-notice">30</span>',
2876
+				'</div>',
2877
+				'<b>',
2878
+				'</b>'
2879
+			);
2880
+			return '
2881 2881
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2882 2882
 	<script >
2883 2883
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2890,851 +2890,851 @@  discard block
 block discarded – undo
2890 2890
 	        }
2891 2891
 	    }, 800 );
2892 2892
 	</script >';
2893
-        }
2894
-        $template_args = [
2895
-            'title'                    => '',
2896
-            'content'                  => '',
2897
-            'step_button_text'         => '',
2898
-            'show_notification_toggle' => false,
2899
-        ];
2900
-        // to indicate we're processing a new registration
2901
-        $hidden_fields = [
2902
-            'processing_registration' => [
2903
-                'type'  => 'hidden',
2904
-                'value' => 0,
2905
-            ],
2906
-            'event_id'                => [
2907
-                'type'  => 'hidden',
2908
-                'value' => $this->_reg_event->ID(),
2909
-            ],
2910
-        ];
2911
-        // if the cart is empty then we know we're at step one, so we'll display the ticket selector
2912
-        $cart = EE_Registry::instance()->SSN->cart();
2913
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2914
-        switch ($step) {
2915
-            case 'ticket':
2916
-                $hidden_fields['processing_registration']['value'] = 1;
2917
-                $template_args['title']                            = esc_html__(
2918
-                    'Step One: Select the Ticket for this registration',
2919
-                    'event_espresso'
2920
-                );
2921
-                $template_args['content']                          =
2922
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2923
-                $template_args['content']                          .= '</div>';
2924
-                $template_args['step_button_text']                 = esc_html__(
2925
-                    'Add Tickets and Continue to Registrant Details',
2926
-                    'event_espresso'
2927
-                );
2928
-                $template_args['show_notification_toggle']         = false;
2929
-                break;
2930
-            case 'questions':
2931
-                $hidden_fields['processing_registration']['value'] = 2;
2932
-                $template_args['title']                            = esc_html__(
2933
-                    'Step Two: Add Registrant Details for this Registration',
2934
-                    'event_espresso'
2935
-                );
2936
-                // in theory, we should be able to run EED_SPCO at this point
2937
-                // because the cart should have been set up properly by the first process_reg_step run.
2938
-                $template_args['content']                  =
2939
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2940
-                $template_args['step_button_text']         = esc_html__(
2941
-                    'Save Registration and Continue to Details',
2942
-                    'event_espresso'
2943
-                );
2944
-                $template_args['show_notification_toggle'] = true;
2945
-                break;
2946
-        }
2947
-        // we come back to the process_registration_step route.
2948
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2949
-        return EEH_Template::display_template(
2950
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2951
-            $template_args,
2952
-            true
2953
-        );
2954
-    }
2955
-
2956
-
2957
-    /**
2958
-     * set_reg_event
2959
-     *
2960
-     * @return bool
2961
-     * @throws EE_Error
2962
-     * @throws InvalidArgumentException
2963
-     * @throws InvalidDataTypeException
2964
-     * @throws InvalidInterfaceException
2965
-     */
2966
-    private function _set_reg_event()
2967
-    {
2968
-        if (is_object($this->_reg_event)) {
2969
-            return true;
2970
-        }
2971
-
2972
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2973
-        if (! $EVT_ID) {
2974
-            return false;
2975
-        }
2976
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2977
-        return true;
2978
-    }
2979
-
2980
-
2981
-    /**
2982
-     * process_reg_step
2983
-     *
2984
-     * @return void
2985
-     * @throws DomainException
2986
-     * @throws EE_Error
2987
-     * @throws InvalidArgumentException
2988
-     * @throws InvalidDataTypeException
2989
-     * @throws InvalidInterfaceException
2990
-     * @throws ReflectionException
2991
-     * @throws RuntimeException
2992
-     */
2993
-    public function process_reg_step()
2994
-    {
2995
-        EE_System::do_not_cache();
2996
-        $this->_set_reg_event();
2997
-        /** @var CurrentPage $current_page */
2998
-        $current_page = $this->loader->getShared(CurrentPage::class);
2999
-        $current_page->setEspressoPage(true);
3000
-        $this->request->setRequestParam('uts', time());
3001
-        // what step are we on?
3002
-        $cart = EE_Registry::instance()->SSN->cart();
3003
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3004
-        // if doing ajax then we need to verify the nonce
3005
-        if ($this->request->isAjax()) {
3006
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
3007
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3008
-        }
3009
-        switch ($step) {
3010
-            case 'ticket':
3011
-                // process ticket selection
3012
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3013
-                if ($success) {
3014
-                    EE_Error::add_success(
3015
-                        esc_html__(
3016
-                            'Tickets Selected. Now complete the registration.',
3017
-                            'event_espresso'
3018
-                        )
3019
-                    );
3020
-                } else {
3021
-                    $this->request->setRequestParam('step_error', true);
3022
-                    $query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
3023
-                }
3024
-                if ($this->request->isAjax()) {
3025
-                    $this->new_registration(); // display next step
3026
-                } else {
3027
-                    $query_args = [
3028
-                        'action'                  => 'new_registration',
3029
-                        'processing_registration' => 1,
3030
-                        'event_id'                => $this->_reg_event->ID(),
3031
-                        'uts'                     => time(),
3032
-                    ];
3033
-                    $this->_redirect_after_action(
3034
-                        false,
3035
-                        '',
3036
-                        '',
3037
-                        $query_args,
3038
-                        true
3039
-                    );
3040
-                }
3041
-                break;
3042
-            case 'questions':
3043
-                if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3044
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3045
-                }
3046
-                // process registration
3047
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3048
-                if ($cart instanceof EE_Cart) {
3049
-                    $grand_total = $cart->get_grand_total();
3050
-                    if ($grand_total instanceof EE_Line_Item) {
3051
-                        $grand_total->save_this_and_descendants_to_txn();
3052
-                    }
3053
-                }
3054
-                if (! $transaction instanceof EE_Transaction) {
3055
-                    $query_args = [
3056
-                        'action'                  => 'new_registration',
3057
-                        'processing_registration' => 2,
3058
-                        'event_id'                => $this->_reg_event->ID(),
3059
-                        'uts'                     => time(),
3060
-                    ];
3061
-                    if ($this->request->isAjax()) {
3062
-                        // display registration form again because there are errors (maybe validation?)
3063
-                        $this->new_registration();
3064
-                        return;
3065
-                    }
3066
-                    $this->_redirect_after_action(
3067
-                        false,
3068
-                        '',
3069
-                        '',
3070
-                        $query_args,
3071
-                        true
3072
-                    );
3073
-                    return;
3074
-                }
3075
-                // maybe update status, and make sure to save transaction if not done already
3076
-                if (! $transaction->update_status_based_on_total_paid()) {
3077
-                    $transaction->save();
3078
-                }
3079
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3080
-                $query_args = [
3081
-                    'action'        => 'redirect_to_txn',
3082
-                    'TXN_ID'        => $transaction->ID(),
3083
-                    'EVT_ID'        => $this->_reg_event->ID(),
3084
-                    'event_name'    => urlencode($this->_reg_event->name()),
3085
-                    'redirect_from' => 'new_registration',
3086
-                ];
3087
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3088
-                break;
3089
-        }
3090
-        // what are you looking here for?  Should be nothing to do at this point.
3091
-    }
3092
-
3093
-
3094
-    /**
3095
-     * redirect_to_txn
3096
-     *
3097
-     * @return void
3098
-     * @throws EE_Error
3099
-     * @throws InvalidArgumentException
3100
-     * @throws InvalidDataTypeException
3101
-     * @throws InvalidInterfaceException
3102
-     * @throws ReflectionException
3103
-     */
3104
-    public function redirect_to_txn()
3105
-    {
3106
-        EE_System::do_not_cache();
3107
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3108
-        $query_args = [
3109
-            'action' => 'view_transaction',
3110
-            'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3111
-            'page'   => 'espresso_transactions',
3112
-        ];
3113
-        if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3114
-            $query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3115
-            $query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3116
-            $query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3117
-        }
3118
-        EE_Error::add_success(
3119
-            esc_html__(
3120
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3121
-                'event_espresso'
3122
-            )
3123
-        );
3124
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3125
-    }
3126
-
3127
-
3128
-    /**
3129
-     * generates HTML for the Attendee Contact List
3130
-     *
3131
-     * @return void
3132
-     * @throws DomainException
3133
-     * @throws EE_Error
3134
-     */
3135
-    protected function _attendee_contact_list_table()
3136
-    {
3137
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3138
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3139
-        $this->display_admin_list_table_page_with_no_sidebar();
3140
-    }
3141
-
3142
-
3143
-    /**
3144
-     * get_attendees
3145
-     *
3146
-     * @param      $per_page
3147
-     * @param bool $count whether to return count or data.
3148
-     * @param bool $trash
3149
-     * @return array|int
3150
-     * @throws EE_Error
3151
-     * @throws InvalidArgumentException
3152
-     * @throws InvalidDataTypeException
3153
-     * @throws InvalidInterfaceException
3154
-     */
3155
-    public function get_attendees($per_page, $count = false, $trash = false)
3156
-    {
3157
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3158
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3159
-        $orderby = $this->request->getRequestParam('orderby');
3160
-        switch ($orderby) {
3161
-            case 'ATT_ID':
3162
-            case 'ATT_fname':
3163
-            case 'ATT_email':
3164
-            case 'ATT_city':
3165
-            case 'STA_ID':
3166
-            case 'CNT_ID':
3167
-                break;
3168
-            case 'Registration_Count':
3169
-                $orderby = 'Registration_Count';
3170
-                break;
3171
-            default:
3172
-                $orderby = 'ATT_lname';
3173
-        }
3174
-        $sort         = $this->request->getRequestParam('order', 'ASC');
3175
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
3176
-        $per_page     = absint($per_page) ? $per_page : 10;
3177
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3178
-        $_where       = [];
3179
-        $search_term  = $this->request->getRequestParam('s');
3180
-        if ($search_term) {
3181
-            $search_term  = '%' . $search_term . '%';
3182
-            $_where['OR'] = [
3183
-                'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3184
-                'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3185
-                'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3186
-                'ATT_fname'                         => ['LIKE', $search_term],
3187
-                'ATT_lname'                         => ['LIKE', $search_term],
3188
-                'ATT_short_bio'                     => ['LIKE', $search_term],
3189
-                'ATT_email'                         => ['LIKE', $search_term],
3190
-                'ATT_address'                       => ['LIKE', $search_term],
3191
-                'ATT_address2'                      => ['LIKE', $search_term],
3192
-                'ATT_city'                          => ['LIKE', $search_term],
3193
-                'Country.CNT_name'                  => ['LIKE', $search_term],
3194
-                'State.STA_name'                    => ['LIKE', $search_term],
3195
-                'ATT_phone'                         => ['LIKE', $search_term],
3196
-                'Registration.REG_final_price'      => ['LIKE', $search_term],
3197
-                'Registration.REG_code'             => ['LIKE', $search_term],
3198
-                'Registration.REG_group_size'       => ['LIKE', $search_term],
3199
-            ];
3200
-        }
3201
-        $offset     = ($current_page - 1) * $per_page;
3202
-        $limit      = $count ? null : [$offset, $per_page];
3203
-        $query_args = [
3204
-            $_where,
3205
-            'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3206
-            'limit'         => $limit,
3207
-        ];
3208
-        if (! $count) {
3209
-            $query_args['order_by'] = [$orderby => $sort];
3210
-        }
3211
-        $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3212
-        return $count
3213
-            ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3214
-            : $this->getAttendeeModel()->get_all($query_args);
3215
-    }
3216
-
3217
-
3218
-    /**
3219
-     * This is just taking care of resending the registration confirmation
3220
-     *
3221
-     * @return void
3222
-     * @throws EE_Error
3223
-     * @throws InvalidArgumentException
3224
-     * @throws InvalidDataTypeException
3225
-     * @throws InvalidInterfaceException
3226
-     * @throws ReflectionException
3227
-     */
3228
-    protected function _resend_registration()
3229
-    {
3230
-        $this->_process_resend_registration();
3231
-        $REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3232
-        $redirect_to = $this->request->getRequestParam('redirect_to');
3233
-        $query_args  = $redirect_to
3234
-            ? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3235
-            : ['action' => 'default'];
3236
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3237
-    }
3238
-
3239
-
3240
-    /**
3241
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3242
-     * to use when selecting registrations
3243
-     *
3244
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3245
-     *                                                     the query parameters from the request
3246
-     * @return void ends the request with a redirect or download
3247
-     */
3248
-    public function _registrations_report_base($method_name_for_getting_query_params)
3249
-    {
3250
-        $EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3251
-            ? $this->request->getRequestParam('EVT_ID', 0, 'int')
3252
-            : null;
3253
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3254
-            $request_params = $this->request->requestParams();
3255
-            wp_redirect(
3256
-                EE_Admin_Page::add_query_args_and_nonce(
3257
-                    [
3258
-                        'page'        => 'espresso_batch',
3259
-                        'batch'       => 'file',
3260
-                        'EVT_ID'      => $EVT_ID,
3261
-                        'filters'     => urlencode(
3262
-                            serialize(
3263
-                                $this->$method_name_for_getting_query_params(
3264
-                                    EEH_Array::is_set($request_params, 'filters', [])
3265
-                                )
3266
-                            )
3267
-                        ),
3268
-                        'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3269
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3270
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3271
-                    ]
3272
-                )
3273
-            );
3274
-        } else {
3275
-            // Pull the current request params
3276
-            $request_args = $this->request->requestParams();
3277
-            // Set the required request_args to be passed to the export
3278
-            $required_request_args = [
3279
-                'export' => 'report',
3280
-                'action' => 'registrations_report_for_event',
3281
-                'EVT_ID' => $EVT_ID,
3282
-            ];
3283
-            // Merge required request args, overriding any currently set
3284
-            $request_args = array_merge($request_args, $required_request_args);
3285
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3286
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3287
-                $EE_Export = EE_Export::instance($request_args);
3288
-                $EE_Export->export();
3289
-            }
3290
-        }
3291
-    }
3292
-
3293
-
3294
-    /**
3295
-     * Creates a registration report using only query parameters in the request
3296
-     *
3297
-     * @return void
3298
-     */
3299
-    public function _registrations_report()
3300
-    {
3301
-        $this->_registrations_report_base('_get_registration_query_parameters');
3302
-    }
3303
-
3304
-
3305
-    public function _contact_list_export()
3306
-    {
3307
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3308
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3309
-            $EE_Export = EE_Export::instance($this->request->requestParams());
3310
-            $EE_Export->export_attendees();
3311
-        }
3312
-    }
3313
-
3314
-
3315
-    public function _contact_list_report()
3316
-    {
3317
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3318
-            wp_redirect(
3319
-                EE_Admin_Page::add_query_args_and_nonce(
3320
-                    [
3321
-                        'page'        => 'espresso_batch',
3322
-                        'batch'       => 'file',
3323
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3324
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3325
-                    ]
3326
-                )
3327
-            );
3328
-        } else {
3329
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3330
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3331
-                $EE_Export = EE_Export::instance($this->request->requestParams());
3332
-                $EE_Export->report_attendees();
3333
-            }
3334
-        }
3335
-    }
3336
-
3337
-
3338
-
3339
-
3340
-
3341
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3342
-    /**
3343
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3344
-     *
3345
-     * @return void
3346
-     * @throws EE_Error
3347
-     * @throws InvalidArgumentException
3348
-     * @throws InvalidDataTypeException
3349
-     * @throws InvalidInterfaceException
3350
-     * @throws ReflectionException
3351
-     */
3352
-    protected function _duplicate_attendee()
3353
-    {
3354
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3355
-        $action = $this->request->getRequestParam('return', 'default');
3356
-        // verify we have necessary info
3357
-        if (! $REG_ID) {
3358
-            EE_Error::add_error(
3359
-                esc_html__(
3360
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3361
-                    'event_espresso'
3362
-                ),
3363
-                __FILE__,
3364
-                __LINE__,
3365
-                __FUNCTION__
3366
-            );
3367
-            $query_args = ['action' => $action];
3368
-            $this->_redirect_after_action('', '', '', $query_args, true);
3369
-        }
3370
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3371
-        $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3372
-        if (! $registration instanceof EE_Registration) {
3373
-            throw new RuntimeException(
3374
-                sprintf(
3375
-                    esc_html__(
3376
-                        'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3377
-                        'event_espresso'
3378
-                    ),
3379
-                    $REG_ID
3380
-                )
3381
-            );
3382
-        }
3383
-        $attendee = $registration->attendee();
3384
-        // remove relation of existing attendee on registration
3385
-        $registration->_remove_relation_to($attendee, 'Attendee');
3386
-        // new attendee
3387
-        $new_attendee = clone $attendee;
3388
-        $new_attendee->set('ATT_ID', 0);
3389
-        $new_attendee->save();
3390
-        // add new attendee to reg
3391
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3392
-        EE_Error::add_success(
3393
-            esc_html__(
3394
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3395
-                'event_espresso'
3396
-            )
3397
-        );
3398
-        // redirect to edit page for attendee
3399
-        $query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3400
-        $this->_redirect_after_action('', '', '', $query_args, true);
3401
-    }
3402
-
3403
-
3404
-    /**
3405
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3406
-     *
3407
-     * @param int     $post_id
3408
-     * @param WP_Post $post
3409
-     * @throws DomainException
3410
-     * @throws EE_Error
3411
-     * @throws InvalidArgumentException
3412
-     * @throws InvalidDataTypeException
3413
-     * @throws InvalidInterfaceException
3414
-     * @throws LogicException
3415
-     * @throws InvalidFormSubmissionException
3416
-     * @throws ReflectionException
3417
-     */
3418
-    protected function _insert_update_cpt_item($post_id, $post)
3419
-    {
3420
-        $success  = true;
3421
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3422
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3423
-            : null;
3424
-        // for attendee updates
3425
-        if ($attendee instanceof EE_Attendee) {
3426
-            // note we should only be UPDATING attendees at this point.
3427
-            $fname          = $this->request->getRequestParam('ATT_fname', '');
3428
-            $lname          = $this->request->getRequestParam('ATT_lname', '');
3429
-            $updated_fields = [
3430
-                'ATT_fname'     => $fname,
3431
-                'ATT_lname'     => $lname,
3432
-                'ATT_full_name' => "{$fname} {$lname}",
3433
-                'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3434
-                'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3435
-                'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3436
-                'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3437
-                'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3438
-                'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3439
-            ];
3440
-            foreach ($updated_fields as $field => $value) {
3441
-                $attendee->set($field, $value);
3442
-            }
3443
-
3444
-            // process contact details metabox form handler (which will also save the attendee)
3445
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3446
-            $success              = $contact_details_form->process($this->request->requestParams());
3447
-
3448
-            $attendee_update_callbacks = apply_filters(
3449
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3450
-                []
3451
-            );
3452
-            foreach ($attendee_update_callbacks as $a_callback) {
3453
-                if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3454
-                    throw new EE_Error(
3455
-                        sprintf(
3456
-                            esc_html__(
3457
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3458
-                                'event_espresso'
3459
-                            ),
3460
-                            $a_callback
3461
-                        )
3462
-                    );
3463
-                }
3464
-            }
3465
-        }
3466
-
3467
-        if ($success === false) {
3468
-            EE_Error::add_error(
3469
-                esc_html__(
3470
-                    'Something went wrong with updating the meta table data for the registration.',
3471
-                    'event_espresso'
3472
-                ),
3473
-                __FILE__,
3474
-                __FUNCTION__,
3475
-                __LINE__
3476
-            );
3477
-        }
3478
-    }
3479
-
3480
-
3481
-    public function trash_cpt_item($post_id)
3482
-    {
3483
-    }
3484
-
3485
-
3486
-    public function delete_cpt_item($post_id)
3487
-    {
3488
-    }
3489
-
3490
-
3491
-    public function restore_cpt_item($post_id)
3492
-    {
3493
-    }
3494
-
3495
-
3496
-    protected function _restore_cpt_item($post_id, $revision_id)
3497
-    {
3498
-    }
3499
-
3500
-
3501
-    /**
3502
-     * @throws EE_Error
3503
-     * @throws ReflectionException
3504
-     * @since 4.10.2.p
3505
-     */
3506
-    public function attendee_editor_metaboxes()
3507
-    {
3508
-        $this->verify_cpt_object();
3509
-        remove_meta_box(
3510
-            'postexcerpt',
3511
-            $this->_cpt_routes[ $this->_req_action ],
3512
-            'normal'
3513
-        );
3514
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3515
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3516
-            add_meta_box(
3517
-                'postexcerpt',
3518
-                esc_html__('Short Biography', 'event_espresso'),
3519
-                'post_excerpt_meta_box',
3520
-                $this->_cpt_routes[ $this->_req_action ],
3521
-                'normal'
3522
-            );
3523
-        }
3524
-        if (post_type_supports('espresso_attendees', 'comments')) {
3525
-            add_meta_box(
3526
-                'commentsdiv',
3527
-                esc_html__('Notes on the Contact', 'event_espresso'),
3528
-                'post_comment_meta_box',
3529
-                $this->_cpt_routes[ $this->_req_action ],
3530
-                'normal',
3531
-                'core'
3532
-            );
3533
-        }
3534
-        add_meta_box(
3535
-            'attendee_contact_info',
3536
-            esc_html__('Contact Info', 'event_espresso'),
3537
-            [$this, 'attendee_contact_info'],
3538
-            $this->_cpt_routes[ $this->_req_action ],
3539
-            'side',
3540
-            'core'
3541
-        );
3542
-        add_meta_box(
3543
-            'attendee_details_address',
3544
-            esc_html__('Address Details', 'event_espresso'),
3545
-            [$this, 'attendee_address_details'],
3546
-            $this->_cpt_routes[ $this->_req_action ],
3547
-            'normal',
3548
-            'core'
3549
-        );
3550
-        add_meta_box(
3551
-            'attendee_registrations',
3552
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3553
-            [$this, 'attendee_registrations_meta_box'],
3554
-            $this->_cpt_routes[ $this->_req_action ],
3555
-            'normal',
3556
-            'high'
3557
-        );
3558
-    }
3559
-
3560
-
3561
-    /**
3562
-     * Metabox for attendee contact info
3563
-     *
3564
-     * @param WP_Post $post wp post object
3565
-     * @return void attendee contact info ( and form )
3566
-     * @throws EE_Error
3567
-     * @throws InvalidArgumentException
3568
-     * @throws InvalidDataTypeException
3569
-     * @throws InvalidInterfaceException
3570
-     * @throws LogicException
3571
-     * @throws DomainException
3572
-     */
3573
-    public function attendee_contact_info($post)
3574
-    {
3575
-        // get attendee object ( should already have it )
3576
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3577
-        $form->enqueueStylesAndScripts();
3578
-        echo $form->display(); // already escaped
3579
-    }
3580
-
3581
-
3582
-    /**
3583
-     * Return form handler for the contact details metabox
3584
-     *
3585
-     * @param EE_Attendee $attendee
3586
-     * @return AttendeeContactDetailsMetaboxFormHandler
3587
-     * @throws DomainException
3588
-     * @throws InvalidArgumentException
3589
-     * @throws InvalidDataTypeException
3590
-     * @throws InvalidInterfaceException
3591
-     */
3592
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3593
-    {
3594
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3595
-    }
3596
-
3597
-
3598
-    /**
3599
-     * Metabox for attendee details
3600
-     *
3601
-     * @param WP_Post $post wp post object
3602
-     * @throws EE_Error
3603
-     * @throws ReflectionException
3604
-     */
3605
-    public function attendee_address_details($post)
3606
-    {
3607
-        // get attendee object (should already have it)
3608
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3609
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3610
-            new EE_Question_Form_Input(
3611
-                EE_Question::new_instance(
3612
-                    [
3613
-                        'QST_ID'           => 0,
3614
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3615
-                        'QST_system'       => 'admin-state',
3616
-                    ]
3617
-                ),
3618
-                EE_Answer::new_instance(
3619
-                    [
3620
-                        'ANS_ID'    => 0,
3621
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3622
-                    ]
3623
-                ),
3624
-                [
3625
-                    'input_id'       => 'STA_ID',
3626
-                    'input_name'     => 'STA_ID',
3627
-                    'input_prefix'   => '',
3628
-                    'append_qstn_id' => false,
3629
-                ]
3630
-            )
3631
-        );
3632
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3633
-            new EE_Question_Form_Input(
3634
-                EE_Question::new_instance(
3635
-                    [
3636
-                        'QST_ID'           => 0,
3637
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3638
-                        'QST_system'       => 'admin-country',
3639
-                    ]
3640
-                ),
3641
-                EE_Answer::new_instance(
3642
-                    [
3643
-                        'ANS_ID'    => 0,
3644
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3645
-                    ]
3646
-                ),
3647
-                [
3648
-                    'input_id'       => 'CNT_ISO',
3649
-                    'input_name'     => 'CNT_ISO',
3650
-                    'input_prefix'   => '',
3651
-                    'append_qstn_id' => false,
3652
-                ]
3653
-            )
3654
-        );
3655
-        $template                             =
3656
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3657
-        EEH_Template::display_template($template, $this->_template_args);
3658
-    }
3659
-
3660
-
3661
-    /**
3662
-     * _attendee_details
3663
-     *
3664
-     * @param $post
3665
-     * @return void
3666
-     * @throws DomainException
3667
-     * @throws EE_Error
3668
-     * @throws InvalidArgumentException
3669
-     * @throws InvalidDataTypeException
3670
-     * @throws InvalidInterfaceException
3671
-     * @throws ReflectionException
3672
-     */
3673
-    public function attendee_registrations_meta_box($post)
3674
-    {
3675
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3676
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3677
-        $template                              =
3678
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3679
-        EEH_Template::display_template($template, $this->_template_args);
3680
-    }
3681
-
3682
-
3683
-    /**
3684
-     * add in the form fields for the attendee edit
3685
-     *
3686
-     * @param WP_Post $post wp post object
3687
-     * @return void echos html for new form.
3688
-     * @throws DomainException
3689
-     */
3690
-    public function after_title_form_fields($post)
3691
-    {
3692
-        if ($post->post_type === 'espresso_attendees') {
3693
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3694
-            $template_args['attendee'] = $this->_cpt_model_obj;
3695
-            EEH_Template::display_template($template, $template_args);
3696
-        }
3697
-    }
3698
-
3699
-
3700
-    /**
3701
-     * _trash_or_restore_attendee
3702
-     *
3703
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3704
-     * @return void
3705
-     * @throws EE_Error
3706
-     * @throws InvalidArgumentException
3707
-     * @throws InvalidDataTypeException
3708
-     * @throws InvalidInterfaceException
3709
-     */
3710
-    protected function _trash_or_restore_attendees($trash = true)
3711
-    {
3712
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3713
-        $status = $trash ? 'trash' : 'publish';
3714
-        // Checkboxes
3715
-        if ($this->request->requestParamIsSet('checkbox')) {
3716
-            $ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3717
-            // if array has more than one element than success message should be plural
3718
-            $success = count($ATT_IDs) > 1 ? 2 : 1;
3719
-            // cycle thru checkboxes
3720
-            foreach ($ATT_IDs as $ATT_ID) {
3721
-                $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3722
-                if (! $updated) {
3723
-                    $success = 0;
3724
-                }
3725
-            }
3726
-        } else {
3727
-            // grab single id and delete
3728
-            $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3729
-            // update attendee
3730
-            $success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3731
-        }
3732
-        $what        = $success > 1
3733
-            ? esc_html__('Contacts', 'event_espresso')
3734
-            : esc_html__('Contact', 'event_espresso');
3735
-        $action_desc = $trash
3736
-            ? esc_html__('moved to the trash', 'event_espresso')
3737
-            : esc_html__('restored', 'event_espresso');
3738
-        $this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3739
-    }
2893
+		}
2894
+		$template_args = [
2895
+			'title'                    => '',
2896
+			'content'                  => '',
2897
+			'step_button_text'         => '',
2898
+			'show_notification_toggle' => false,
2899
+		];
2900
+		// to indicate we're processing a new registration
2901
+		$hidden_fields = [
2902
+			'processing_registration' => [
2903
+				'type'  => 'hidden',
2904
+				'value' => 0,
2905
+			],
2906
+			'event_id'                => [
2907
+				'type'  => 'hidden',
2908
+				'value' => $this->_reg_event->ID(),
2909
+			],
2910
+		];
2911
+		// if the cart is empty then we know we're at step one, so we'll display the ticket selector
2912
+		$cart = EE_Registry::instance()->SSN->cart();
2913
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2914
+		switch ($step) {
2915
+			case 'ticket':
2916
+				$hidden_fields['processing_registration']['value'] = 1;
2917
+				$template_args['title']                            = esc_html__(
2918
+					'Step One: Select the Ticket for this registration',
2919
+					'event_espresso'
2920
+				);
2921
+				$template_args['content']                          =
2922
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2923
+				$template_args['content']                          .= '</div>';
2924
+				$template_args['step_button_text']                 = esc_html__(
2925
+					'Add Tickets and Continue to Registrant Details',
2926
+					'event_espresso'
2927
+				);
2928
+				$template_args['show_notification_toggle']         = false;
2929
+				break;
2930
+			case 'questions':
2931
+				$hidden_fields['processing_registration']['value'] = 2;
2932
+				$template_args['title']                            = esc_html__(
2933
+					'Step Two: Add Registrant Details for this Registration',
2934
+					'event_espresso'
2935
+				);
2936
+				// in theory, we should be able to run EED_SPCO at this point
2937
+				// because the cart should have been set up properly by the first process_reg_step run.
2938
+				$template_args['content']                  =
2939
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2940
+				$template_args['step_button_text']         = esc_html__(
2941
+					'Save Registration and Continue to Details',
2942
+					'event_espresso'
2943
+				);
2944
+				$template_args['show_notification_toggle'] = true;
2945
+				break;
2946
+		}
2947
+		// we come back to the process_registration_step route.
2948
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2949
+		return EEH_Template::display_template(
2950
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2951
+			$template_args,
2952
+			true
2953
+		);
2954
+	}
2955
+
2956
+
2957
+	/**
2958
+	 * set_reg_event
2959
+	 *
2960
+	 * @return bool
2961
+	 * @throws EE_Error
2962
+	 * @throws InvalidArgumentException
2963
+	 * @throws InvalidDataTypeException
2964
+	 * @throws InvalidInterfaceException
2965
+	 */
2966
+	private function _set_reg_event()
2967
+	{
2968
+		if (is_object($this->_reg_event)) {
2969
+			return true;
2970
+		}
2971
+
2972
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2973
+		if (! $EVT_ID) {
2974
+			return false;
2975
+		}
2976
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2977
+		return true;
2978
+	}
2979
+
2980
+
2981
+	/**
2982
+	 * process_reg_step
2983
+	 *
2984
+	 * @return void
2985
+	 * @throws DomainException
2986
+	 * @throws EE_Error
2987
+	 * @throws InvalidArgumentException
2988
+	 * @throws InvalidDataTypeException
2989
+	 * @throws InvalidInterfaceException
2990
+	 * @throws ReflectionException
2991
+	 * @throws RuntimeException
2992
+	 */
2993
+	public function process_reg_step()
2994
+	{
2995
+		EE_System::do_not_cache();
2996
+		$this->_set_reg_event();
2997
+		/** @var CurrentPage $current_page */
2998
+		$current_page = $this->loader->getShared(CurrentPage::class);
2999
+		$current_page->setEspressoPage(true);
3000
+		$this->request->setRequestParam('uts', time());
3001
+		// what step are we on?
3002
+		$cart = EE_Registry::instance()->SSN->cart();
3003
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3004
+		// if doing ajax then we need to verify the nonce
3005
+		if ($this->request->isAjax()) {
3006
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
3007
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3008
+		}
3009
+		switch ($step) {
3010
+			case 'ticket':
3011
+				// process ticket selection
3012
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3013
+				if ($success) {
3014
+					EE_Error::add_success(
3015
+						esc_html__(
3016
+							'Tickets Selected. Now complete the registration.',
3017
+							'event_espresso'
3018
+						)
3019
+					);
3020
+				} else {
3021
+					$this->request->setRequestParam('step_error', true);
3022
+					$query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
3023
+				}
3024
+				if ($this->request->isAjax()) {
3025
+					$this->new_registration(); // display next step
3026
+				} else {
3027
+					$query_args = [
3028
+						'action'                  => 'new_registration',
3029
+						'processing_registration' => 1,
3030
+						'event_id'                => $this->_reg_event->ID(),
3031
+						'uts'                     => time(),
3032
+					];
3033
+					$this->_redirect_after_action(
3034
+						false,
3035
+						'',
3036
+						'',
3037
+						$query_args,
3038
+						true
3039
+					);
3040
+				}
3041
+				break;
3042
+			case 'questions':
3043
+				if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3044
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3045
+				}
3046
+				// process registration
3047
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3048
+				if ($cart instanceof EE_Cart) {
3049
+					$grand_total = $cart->get_grand_total();
3050
+					if ($grand_total instanceof EE_Line_Item) {
3051
+						$grand_total->save_this_and_descendants_to_txn();
3052
+					}
3053
+				}
3054
+				if (! $transaction instanceof EE_Transaction) {
3055
+					$query_args = [
3056
+						'action'                  => 'new_registration',
3057
+						'processing_registration' => 2,
3058
+						'event_id'                => $this->_reg_event->ID(),
3059
+						'uts'                     => time(),
3060
+					];
3061
+					if ($this->request->isAjax()) {
3062
+						// display registration form again because there are errors (maybe validation?)
3063
+						$this->new_registration();
3064
+						return;
3065
+					}
3066
+					$this->_redirect_after_action(
3067
+						false,
3068
+						'',
3069
+						'',
3070
+						$query_args,
3071
+						true
3072
+					);
3073
+					return;
3074
+				}
3075
+				// maybe update status, and make sure to save transaction if not done already
3076
+				if (! $transaction->update_status_based_on_total_paid()) {
3077
+					$transaction->save();
3078
+				}
3079
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3080
+				$query_args = [
3081
+					'action'        => 'redirect_to_txn',
3082
+					'TXN_ID'        => $transaction->ID(),
3083
+					'EVT_ID'        => $this->_reg_event->ID(),
3084
+					'event_name'    => urlencode($this->_reg_event->name()),
3085
+					'redirect_from' => 'new_registration',
3086
+				];
3087
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3088
+				break;
3089
+		}
3090
+		// what are you looking here for?  Should be nothing to do at this point.
3091
+	}
3092
+
3093
+
3094
+	/**
3095
+	 * redirect_to_txn
3096
+	 *
3097
+	 * @return void
3098
+	 * @throws EE_Error
3099
+	 * @throws InvalidArgumentException
3100
+	 * @throws InvalidDataTypeException
3101
+	 * @throws InvalidInterfaceException
3102
+	 * @throws ReflectionException
3103
+	 */
3104
+	public function redirect_to_txn()
3105
+	{
3106
+		EE_System::do_not_cache();
3107
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3108
+		$query_args = [
3109
+			'action' => 'view_transaction',
3110
+			'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3111
+			'page'   => 'espresso_transactions',
3112
+		];
3113
+		if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3114
+			$query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3115
+			$query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3116
+			$query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3117
+		}
3118
+		EE_Error::add_success(
3119
+			esc_html__(
3120
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3121
+				'event_espresso'
3122
+			)
3123
+		);
3124
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3125
+	}
3126
+
3127
+
3128
+	/**
3129
+	 * generates HTML for the Attendee Contact List
3130
+	 *
3131
+	 * @return void
3132
+	 * @throws DomainException
3133
+	 * @throws EE_Error
3134
+	 */
3135
+	protected function _attendee_contact_list_table()
3136
+	{
3137
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3138
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3139
+		$this->display_admin_list_table_page_with_no_sidebar();
3140
+	}
3141
+
3142
+
3143
+	/**
3144
+	 * get_attendees
3145
+	 *
3146
+	 * @param      $per_page
3147
+	 * @param bool $count whether to return count or data.
3148
+	 * @param bool $trash
3149
+	 * @return array|int
3150
+	 * @throws EE_Error
3151
+	 * @throws InvalidArgumentException
3152
+	 * @throws InvalidDataTypeException
3153
+	 * @throws InvalidInterfaceException
3154
+	 */
3155
+	public function get_attendees($per_page, $count = false, $trash = false)
3156
+	{
3157
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3158
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3159
+		$orderby = $this->request->getRequestParam('orderby');
3160
+		switch ($orderby) {
3161
+			case 'ATT_ID':
3162
+			case 'ATT_fname':
3163
+			case 'ATT_email':
3164
+			case 'ATT_city':
3165
+			case 'STA_ID':
3166
+			case 'CNT_ID':
3167
+				break;
3168
+			case 'Registration_Count':
3169
+				$orderby = 'Registration_Count';
3170
+				break;
3171
+			default:
3172
+				$orderby = 'ATT_lname';
3173
+		}
3174
+		$sort         = $this->request->getRequestParam('order', 'ASC');
3175
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
3176
+		$per_page     = absint($per_page) ? $per_page : 10;
3177
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3178
+		$_where       = [];
3179
+		$search_term  = $this->request->getRequestParam('s');
3180
+		if ($search_term) {
3181
+			$search_term  = '%' . $search_term . '%';
3182
+			$_where['OR'] = [
3183
+				'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3184
+				'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3185
+				'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3186
+				'ATT_fname'                         => ['LIKE', $search_term],
3187
+				'ATT_lname'                         => ['LIKE', $search_term],
3188
+				'ATT_short_bio'                     => ['LIKE', $search_term],
3189
+				'ATT_email'                         => ['LIKE', $search_term],
3190
+				'ATT_address'                       => ['LIKE', $search_term],
3191
+				'ATT_address2'                      => ['LIKE', $search_term],
3192
+				'ATT_city'                          => ['LIKE', $search_term],
3193
+				'Country.CNT_name'                  => ['LIKE', $search_term],
3194
+				'State.STA_name'                    => ['LIKE', $search_term],
3195
+				'ATT_phone'                         => ['LIKE', $search_term],
3196
+				'Registration.REG_final_price'      => ['LIKE', $search_term],
3197
+				'Registration.REG_code'             => ['LIKE', $search_term],
3198
+				'Registration.REG_group_size'       => ['LIKE', $search_term],
3199
+			];
3200
+		}
3201
+		$offset     = ($current_page - 1) * $per_page;
3202
+		$limit      = $count ? null : [$offset, $per_page];
3203
+		$query_args = [
3204
+			$_where,
3205
+			'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3206
+			'limit'         => $limit,
3207
+		];
3208
+		if (! $count) {
3209
+			$query_args['order_by'] = [$orderby => $sort];
3210
+		}
3211
+		$query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3212
+		return $count
3213
+			? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3214
+			: $this->getAttendeeModel()->get_all($query_args);
3215
+	}
3216
+
3217
+
3218
+	/**
3219
+	 * This is just taking care of resending the registration confirmation
3220
+	 *
3221
+	 * @return void
3222
+	 * @throws EE_Error
3223
+	 * @throws InvalidArgumentException
3224
+	 * @throws InvalidDataTypeException
3225
+	 * @throws InvalidInterfaceException
3226
+	 * @throws ReflectionException
3227
+	 */
3228
+	protected function _resend_registration()
3229
+	{
3230
+		$this->_process_resend_registration();
3231
+		$REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3232
+		$redirect_to = $this->request->getRequestParam('redirect_to');
3233
+		$query_args  = $redirect_to
3234
+			? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3235
+			: ['action' => 'default'];
3236
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3237
+	}
3238
+
3239
+
3240
+	/**
3241
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3242
+	 * to use when selecting registrations
3243
+	 *
3244
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3245
+	 *                                                     the query parameters from the request
3246
+	 * @return void ends the request with a redirect or download
3247
+	 */
3248
+	public function _registrations_report_base($method_name_for_getting_query_params)
3249
+	{
3250
+		$EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3251
+			? $this->request->getRequestParam('EVT_ID', 0, 'int')
3252
+			: null;
3253
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3254
+			$request_params = $this->request->requestParams();
3255
+			wp_redirect(
3256
+				EE_Admin_Page::add_query_args_and_nonce(
3257
+					[
3258
+						'page'        => 'espresso_batch',
3259
+						'batch'       => 'file',
3260
+						'EVT_ID'      => $EVT_ID,
3261
+						'filters'     => urlencode(
3262
+							serialize(
3263
+								$this->$method_name_for_getting_query_params(
3264
+									EEH_Array::is_set($request_params, 'filters', [])
3265
+								)
3266
+							)
3267
+						),
3268
+						'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3269
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3270
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3271
+					]
3272
+				)
3273
+			);
3274
+		} else {
3275
+			// Pull the current request params
3276
+			$request_args = $this->request->requestParams();
3277
+			// Set the required request_args to be passed to the export
3278
+			$required_request_args = [
3279
+				'export' => 'report',
3280
+				'action' => 'registrations_report_for_event',
3281
+				'EVT_ID' => $EVT_ID,
3282
+			];
3283
+			// Merge required request args, overriding any currently set
3284
+			$request_args = array_merge($request_args, $required_request_args);
3285
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3286
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3287
+				$EE_Export = EE_Export::instance($request_args);
3288
+				$EE_Export->export();
3289
+			}
3290
+		}
3291
+	}
3292
+
3293
+
3294
+	/**
3295
+	 * Creates a registration report using only query parameters in the request
3296
+	 *
3297
+	 * @return void
3298
+	 */
3299
+	public function _registrations_report()
3300
+	{
3301
+		$this->_registrations_report_base('_get_registration_query_parameters');
3302
+	}
3303
+
3304
+
3305
+	public function _contact_list_export()
3306
+	{
3307
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3308
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3309
+			$EE_Export = EE_Export::instance($this->request->requestParams());
3310
+			$EE_Export->export_attendees();
3311
+		}
3312
+	}
3313
+
3314
+
3315
+	public function _contact_list_report()
3316
+	{
3317
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3318
+			wp_redirect(
3319
+				EE_Admin_Page::add_query_args_and_nonce(
3320
+					[
3321
+						'page'        => 'espresso_batch',
3322
+						'batch'       => 'file',
3323
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3324
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3325
+					]
3326
+				)
3327
+			);
3328
+		} else {
3329
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3330
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3331
+				$EE_Export = EE_Export::instance($this->request->requestParams());
3332
+				$EE_Export->report_attendees();
3333
+			}
3334
+		}
3335
+	}
3336
+
3337
+
3338
+
3339
+
3340
+
3341
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3342
+	/**
3343
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3344
+	 *
3345
+	 * @return void
3346
+	 * @throws EE_Error
3347
+	 * @throws InvalidArgumentException
3348
+	 * @throws InvalidDataTypeException
3349
+	 * @throws InvalidInterfaceException
3350
+	 * @throws ReflectionException
3351
+	 */
3352
+	protected function _duplicate_attendee()
3353
+	{
3354
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3355
+		$action = $this->request->getRequestParam('return', 'default');
3356
+		// verify we have necessary info
3357
+		if (! $REG_ID) {
3358
+			EE_Error::add_error(
3359
+				esc_html__(
3360
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3361
+					'event_espresso'
3362
+				),
3363
+				__FILE__,
3364
+				__LINE__,
3365
+				__FUNCTION__
3366
+			);
3367
+			$query_args = ['action' => $action];
3368
+			$this->_redirect_after_action('', '', '', $query_args, true);
3369
+		}
3370
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3371
+		$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3372
+		if (! $registration instanceof EE_Registration) {
3373
+			throw new RuntimeException(
3374
+				sprintf(
3375
+					esc_html__(
3376
+						'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3377
+						'event_espresso'
3378
+					),
3379
+					$REG_ID
3380
+				)
3381
+			);
3382
+		}
3383
+		$attendee = $registration->attendee();
3384
+		// remove relation of existing attendee on registration
3385
+		$registration->_remove_relation_to($attendee, 'Attendee');
3386
+		// new attendee
3387
+		$new_attendee = clone $attendee;
3388
+		$new_attendee->set('ATT_ID', 0);
3389
+		$new_attendee->save();
3390
+		// add new attendee to reg
3391
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3392
+		EE_Error::add_success(
3393
+			esc_html__(
3394
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3395
+				'event_espresso'
3396
+			)
3397
+		);
3398
+		// redirect to edit page for attendee
3399
+		$query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3400
+		$this->_redirect_after_action('', '', '', $query_args, true);
3401
+	}
3402
+
3403
+
3404
+	/**
3405
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3406
+	 *
3407
+	 * @param int     $post_id
3408
+	 * @param WP_Post $post
3409
+	 * @throws DomainException
3410
+	 * @throws EE_Error
3411
+	 * @throws InvalidArgumentException
3412
+	 * @throws InvalidDataTypeException
3413
+	 * @throws InvalidInterfaceException
3414
+	 * @throws LogicException
3415
+	 * @throws InvalidFormSubmissionException
3416
+	 * @throws ReflectionException
3417
+	 */
3418
+	protected function _insert_update_cpt_item($post_id, $post)
3419
+	{
3420
+		$success  = true;
3421
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3422
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3423
+			: null;
3424
+		// for attendee updates
3425
+		if ($attendee instanceof EE_Attendee) {
3426
+			// note we should only be UPDATING attendees at this point.
3427
+			$fname          = $this->request->getRequestParam('ATT_fname', '');
3428
+			$lname          = $this->request->getRequestParam('ATT_lname', '');
3429
+			$updated_fields = [
3430
+				'ATT_fname'     => $fname,
3431
+				'ATT_lname'     => $lname,
3432
+				'ATT_full_name' => "{$fname} {$lname}",
3433
+				'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3434
+				'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3435
+				'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3436
+				'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3437
+				'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3438
+				'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3439
+			];
3440
+			foreach ($updated_fields as $field => $value) {
3441
+				$attendee->set($field, $value);
3442
+			}
3443
+
3444
+			// process contact details metabox form handler (which will also save the attendee)
3445
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3446
+			$success              = $contact_details_form->process($this->request->requestParams());
3447
+
3448
+			$attendee_update_callbacks = apply_filters(
3449
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3450
+				[]
3451
+			);
3452
+			foreach ($attendee_update_callbacks as $a_callback) {
3453
+				if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3454
+					throw new EE_Error(
3455
+						sprintf(
3456
+							esc_html__(
3457
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3458
+								'event_espresso'
3459
+							),
3460
+							$a_callback
3461
+						)
3462
+					);
3463
+				}
3464
+			}
3465
+		}
3466
+
3467
+		if ($success === false) {
3468
+			EE_Error::add_error(
3469
+				esc_html__(
3470
+					'Something went wrong with updating the meta table data for the registration.',
3471
+					'event_espresso'
3472
+				),
3473
+				__FILE__,
3474
+				__FUNCTION__,
3475
+				__LINE__
3476
+			);
3477
+		}
3478
+	}
3479
+
3480
+
3481
+	public function trash_cpt_item($post_id)
3482
+	{
3483
+	}
3484
+
3485
+
3486
+	public function delete_cpt_item($post_id)
3487
+	{
3488
+	}
3489
+
3490
+
3491
+	public function restore_cpt_item($post_id)
3492
+	{
3493
+	}
3494
+
3495
+
3496
+	protected function _restore_cpt_item($post_id, $revision_id)
3497
+	{
3498
+	}
3499
+
3500
+
3501
+	/**
3502
+	 * @throws EE_Error
3503
+	 * @throws ReflectionException
3504
+	 * @since 4.10.2.p
3505
+	 */
3506
+	public function attendee_editor_metaboxes()
3507
+	{
3508
+		$this->verify_cpt_object();
3509
+		remove_meta_box(
3510
+			'postexcerpt',
3511
+			$this->_cpt_routes[ $this->_req_action ],
3512
+			'normal'
3513
+		);
3514
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3515
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3516
+			add_meta_box(
3517
+				'postexcerpt',
3518
+				esc_html__('Short Biography', 'event_espresso'),
3519
+				'post_excerpt_meta_box',
3520
+				$this->_cpt_routes[ $this->_req_action ],
3521
+				'normal'
3522
+			);
3523
+		}
3524
+		if (post_type_supports('espresso_attendees', 'comments')) {
3525
+			add_meta_box(
3526
+				'commentsdiv',
3527
+				esc_html__('Notes on the Contact', 'event_espresso'),
3528
+				'post_comment_meta_box',
3529
+				$this->_cpt_routes[ $this->_req_action ],
3530
+				'normal',
3531
+				'core'
3532
+			);
3533
+		}
3534
+		add_meta_box(
3535
+			'attendee_contact_info',
3536
+			esc_html__('Contact Info', 'event_espresso'),
3537
+			[$this, 'attendee_contact_info'],
3538
+			$this->_cpt_routes[ $this->_req_action ],
3539
+			'side',
3540
+			'core'
3541
+		);
3542
+		add_meta_box(
3543
+			'attendee_details_address',
3544
+			esc_html__('Address Details', 'event_espresso'),
3545
+			[$this, 'attendee_address_details'],
3546
+			$this->_cpt_routes[ $this->_req_action ],
3547
+			'normal',
3548
+			'core'
3549
+		);
3550
+		add_meta_box(
3551
+			'attendee_registrations',
3552
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3553
+			[$this, 'attendee_registrations_meta_box'],
3554
+			$this->_cpt_routes[ $this->_req_action ],
3555
+			'normal',
3556
+			'high'
3557
+		);
3558
+	}
3559
+
3560
+
3561
+	/**
3562
+	 * Metabox for attendee contact info
3563
+	 *
3564
+	 * @param WP_Post $post wp post object
3565
+	 * @return void attendee contact info ( and form )
3566
+	 * @throws EE_Error
3567
+	 * @throws InvalidArgumentException
3568
+	 * @throws InvalidDataTypeException
3569
+	 * @throws InvalidInterfaceException
3570
+	 * @throws LogicException
3571
+	 * @throws DomainException
3572
+	 */
3573
+	public function attendee_contact_info($post)
3574
+	{
3575
+		// get attendee object ( should already have it )
3576
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3577
+		$form->enqueueStylesAndScripts();
3578
+		echo $form->display(); // already escaped
3579
+	}
3580
+
3581
+
3582
+	/**
3583
+	 * Return form handler for the contact details metabox
3584
+	 *
3585
+	 * @param EE_Attendee $attendee
3586
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3587
+	 * @throws DomainException
3588
+	 * @throws InvalidArgumentException
3589
+	 * @throws InvalidDataTypeException
3590
+	 * @throws InvalidInterfaceException
3591
+	 */
3592
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3593
+	{
3594
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3595
+	}
3596
+
3597
+
3598
+	/**
3599
+	 * Metabox for attendee details
3600
+	 *
3601
+	 * @param WP_Post $post wp post object
3602
+	 * @throws EE_Error
3603
+	 * @throws ReflectionException
3604
+	 */
3605
+	public function attendee_address_details($post)
3606
+	{
3607
+		// get attendee object (should already have it)
3608
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3609
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3610
+			new EE_Question_Form_Input(
3611
+				EE_Question::new_instance(
3612
+					[
3613
+						'QST_ID'           => 0,
3614
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3615
+						'QST_system'       => 'admin-state',
3616
+					]
3617
+				),
3618
+				EE_Answer::new_instance(
3619
+					[
3620
+						'ANS_ID'    => 0,
3621
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3622
+					]
3623
+				),
3624
+				[
3625
+					'input_id'       => 'STA_ID',
3626
+					'input_name'     => 'STA_ID',
3627
+					'input_prefix'   => '',
3628
+					'append_qstn_id' => false,
3629
+				]
3630
+			)
3631
+		);
3632
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3633
+			new EE_Question_Form_Input(
3634
+				EE_Question::new_instance(
3635
+					[
3636
+						'QST_ID'           => 0,
3637
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3638
+						'QST_system'       => 'admin-country',
3639
+					]
3640
+				),
3641
+				EE_Answer::new_instance(
3642
+					[
3643
+						'ANS_ID'    => 0,
3644
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3645
+					]
3646
+				),
3647
+				[
3648
+					'input_id'       => 'CNT_ISO',
3649
+					'input_name'     => 'CNT_ISO',
3650
+					'input_prefix'   => '',
3651
+					'append_qstn_id' => false,
3652
+				]
3653
+			)
3654
+		);
3655
+		$template                             =
3656
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3657
+		EEH_Template::display_template($template, $this->_template_args);
3658
+	}
3659
+
3660
+
3661
+	/**
3662
+	 * _attendee_details
3663
+	 *
3664
+	 * @param $post
3665
+	 * @return void
3666
+	 * @throws DomainException
3667
+	 * @throws EE_Error
3668
+	 * @throws InvalidArgumentException
3669
+	 * @throws InvalidDataTypeException
3670
+	 * @throws InvalidInterfaceException
3671
+	 * @throws ReflectionException
3672
+	 */
3673
+	public function attendee_registrations_meta_box($post)
3674
+	{
3675
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3676
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3677
+		$template                              =
3678
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3679
+		EEH_Template::display_template($template, $this->_template_args);
3680
+	}
3681
+
3682
+
3683
+	/**
3684
+	 * add in the form fields for the attendee edit
3685
+	 *
3686
+	 * @param WP_Post $post wp post object
3687
+	 * @return void echos html for new form.
3688
+	 * @throws DomainException
3689
+	 */
3690
+	public function after_title_form_fields($post)
3691
+	{
3692
+		if ($post->post_type === 'espresso_attendees') {
3693
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3694
+			$template_args['attendee'] = $this->_cpt_model_obj;
3695
+			EEH_Template::display_template($template, $template_args);
3696
+		}
3697
+	}
3698
+
3699
+
3700
+	/**
3701
+	 * _trash_or_restore_attendee
3702
+	 *
3703
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3704
+	 * @return void
3705
+	 * @throws EE_Error
3706
+	 * @throws InvalidArgumentException
3707
+	 * @throws InvalidDataTypeException
3708
+	 * @throws InvalidInterfaceException
3709
+	 */
3710
+	protected function _trash_or_restore_attendees($trash = true)
3711
+	{
3712
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3713
+		$status = $trash ? 'trash' : 'publish';
3714
+		// Checkboxes
3715
+		if ($this->request->requestParamIsSet('checkbox')) {
3716
+			$ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3717
+			// if array has more than one element than success message should be plural
3718
+			$success = count($ATT_IDs) > 1 ? 2 : 1;
3719
+			// cycle thru checkboxes
3720
+			foreach ($ATT_IDs as $ATT_ID) {
3721
+				$updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3722
+				if (! $updated) {
3723
+					$success = 0;
3724
+				}
3725
+			}
3726
+		} else {
3727
+			// grab single id and delete
3728
+			$ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3729
+			// update attendee
3730
+			$success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3731
+		}
3732
+		$what        = $success > 1
3733
+			? esc_html__('Contacts', 'event_espresso')
3734
+			: esc_html__('Contact', 'event_espresso');
3735
+		$action_desc = $trash
3736
+			? esc_html__('moved to the trash', 'event_espresso')
3737
+			: esc_html__('restored', 'event_espresso');
3738
+		$this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3739
+	}
3740 3740
 }
Please login to merge, or discard this patch.
admin_pages/events/templates/event_tickets_metabox_ticket_row.template.php 1 patch
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -84,12 +84,15 @@  discard block
 block discarded – undo
84 84
                    name="edit_prices[<?php echo esc_attr($ticketrow); ?>][1][PRC_amount]"
85 85
                    value="<?php echo esc_attr($PRC_amount); ?>"
86 86
             />
87
-        <?php else : ?>
87
+        <?php else {
88
+	: ?>
88 89
             <input type="text"
89 90
                    size="1"
90 91
                    class="edit-price-PRC_amount ee-small-text-inp ee-inp-right"
91 92
                    name="disabled_price_amount"
92
-                   value="<?php echo esc_attr($PRC_amount); ?>"
93
+                   value="<?php echo esc_attr($PRC_amount);
94
+}
95
+?>"
93 96
                 <?php echo esc_attr($disabled); ?>
94 97
             />
95 98
             <input type="hidden"
@@ -123,11 +126,14 @@  discard block
 block discarded – undo
123 126
                    name="<?php echo esc_attr("{$edit_ticketrow_name}[{$ticketrow}][TKT_qty]"); ?>"
124 127
                    value="<?php echo absint($TKT_qty); ?>"
125 128
             />
126
-        <?php else : ?>
129
+        <?php else {
130
+	: ?>
127 131
             <input type="text"
128 132
                    class="edit-ticket-TKT_qty ee-small-text-inp ee-inp-right"
129 133
                    name="disabled_tkt_qty"
130
-                   value="<?php echo absint($TKT_qty); ?>"
134
+                   value="<?php echo absint($TKT_qty);
135
+}
136
+?>"
131 137
                 <?php echo esc_attr($disabled); ?>
132 138
             />
133 139
             <input type="hidden"
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2797 added lines, -2797 removed lines patch added patch discarded remove patch
@@ -16,2804 +16,2804 @@
 block discarded – undo
16 16
 class Events_Admin_Page extends EE_Admin_Page_CPT
17 17
 {
18 18
 
19
-    /**
20
-     * This will hold the event object for event_details screen.
19
+	/**
20
+	 * This will hold the event object for event_details screen.
21
+	 *
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+	/**
44
+	 * @var EE_Event
45
+	 */
46
+	protected $_cpt_model_obj = false;
47
+
48
+
49
+	/**
50
+	 * @var NodeGroupDao
51
+	 */
52
+	protected $model_obj_node_group_persister;
53
+
54
+
55
+	/**
56
+	 * Initialize page props for this admin page group.
57
+	 */
58
+	protected function _init_page_props()
59
+	{
60
+		$this->page_slug        = EVENTS_PG_SLUG;
61
+		$this->page_label       = EVENTS_LABEL;
62
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
63
+		$this->_admin_base_path = EVENTS_ADMIN;
64
+		$this->_cpt_model_names = [
65
+			'create_new' => 'EEM_Event',
66
+			'edit'       => 'EEM_Event',
67
+		];
68
+		$this->_cpt_edit_routes = [
69
+			'espresso_events' => 'edit',
70
+		];
71
+		add_action(
72
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
+			[$this, 'verify_event_edit'],
74
+			10,
75
+			2
76
+		);
77
+	}
78
+
79
+
80
+	/**
81
+	 * Sets the ajax hooks used for this admin page group.
82
+	 */
83
+	protected function _ajax_hooks()
84
+	{
85
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
+	}
87
+
88
+
89
+	/**
90
+	 * Sets the page properties for this admin page group.
91
+	 */
92
+	protected function _define_page_props()
93
+	{
94
+		$this->_admin_page_title = EVENTS_LABEL;
95
+		$this->_labels           = [
96
+			'buttons'      => [
97
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
98
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
+			],
104
+			'editor_title' => [
105
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
+			],
107
+			'publishbox'   => [
108
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
110
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
+			],
114
+		];
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets the page routes property for this admin page group.
120
+	 */
121
+	protected function _set_page_routes()
122
+	{
123
+		// load formatter helper
124
+		// load field generator helper
125
+		// is there a evt_id in the request?
126
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
+
129
+		$this->_page_routes = [
130
+			'default'                       => [
131
+				'func'       => '_events_overview_list_table',
132
+				'capability' => 'ee_read_events',
133
+			],
134
+			'create_new'                    => [
135
+				'func'       => '_create_new_cpt_item',
136
+				'capability' => 'ee_edit_events',
137
+			],
138
+			'edit'                          => [
139
+				'func'       => '_edit_cpt_item',
140
+				'capability' => 'ee_edit_event',
141
+				'obj_id'     => $EVT_ID,
142
+			],
143
+			'copy_event'                    => [
144
+				'func'       => '_copy_events',
145
+				'capability' => 'ee_edit_event',
146
+				'obj_id'     => $EVT_ID,
147
+				'noheader'   => true,
148
+			],
149
+			'trash_event'                   => [
150
+				'func'       => '_trash_or_restore_event',
151
+				'args'       => ['event_status' => 'trash'],
152
+				'capability' => 'ee_delete_event',
153
+				'obj_id'     => $EVT_ID,
154
+				'noheader'   => true,
155
+			],
156
+			'trash_events'                  => [
157
+				'func'       => '_trash_or_restore_events',
158
+				'args'       => ['event_status' => 'trash'],
159
+				'capability' => 'ee_delete_events',
160
+				'noheader'   => true,
161
+			],
162
+			'restore_event'                 => [
163
+				'func'       => '_trash_or_restore_event',
164
+				'args'       => ['event_status' => 'draft'],
165
+				'capability' => 'ee_delete_event',
166
+				'obj_id'     => $EVT_ID,
167
+				'noheader'   => true,
168
+			],
169
+			'restore_events'                => [
170
+				'func'       => '_trash_or_restore_events',
171
+				'args'       => ['event_status' => 'draft'],
172
+				'capability' => 'ee_delete_events',
173
+				'noheader'   => true,
174
+			],
175
+			'delete_event'                  => [
176
+				'func'       => '_delete_event',
177
+				'capability' => 'ee_delete_event',
178
+				'obj_id'     => $EVT_ID,
179
+				'noheader'   => true,
180
+			],
181
+			'delete_events'                 => [
182
+				'func'       => '_delete_events',
183
+				'capability' => 'ee_delete_events',
184
+				'noheader'   => true,
185
+			],
186
+			'view_report'                   => [
187
+				'func'       => '_view_report',
188
+				'capability' => 'ee_edit_events',
189
+			],
190
+			'default_event_settings'        => [
191
+				'func'       => '_default_event_settings',
192
+				'capability' => 'manage_options',
193
+			],
194
+			'update_default_event_settings' => [
195
+				'func'       => '_update_default_event_settings',
196
+				'capability' => 'manage_options',
197
+				'noheader'   => true,
198
+			],
199
+			'template_settings'             => [
200
+				'func'       => '_template_settings',
201
+				'capability' => 'manage_options',
202
+			],
203
+			// event category tab related
204
+			'add_category'                  => [
205
+				'func'       => '_category_details',
206
+				'capability' => 'ee_edit_event_category',
207
+				'args'       => ['add'],
208
+			],
209
+			'edit_category'                 => [
210
+				'func'       => '_category_details',
211
+				'capability' => 'ee_edit_event_category',
212
+				'args'       => ['edit'],
213
+			],
214
+			'delete_categories'             => [
215
+				'func'       => '_delete_categories',
216
+				'capability' => 'ee_delete_event_category',
217
+				'noheader'   => true,
218
+			],
219
+			'delete_category'               => [
220
+				'func'       => '_delete_categories',
221
+				'capability' => 'ee_delete_event_category',
222
+				'noheader'   => true,
223
+			],
224
+			'insert_category'               => [
225
+				'func'       => '_insert_or_update_category',
226
+				'args'       => ['new_category' => true],
227
+				'capability' => 'ee_edit_event_category',
228
+				'noheader'   => true,
229
+			],
230
+			'update_category'               => [
231
+				'func'       => '_insert_or_update_category',
232
+				'args'       => ['new_category' => false],
233
+				'capability' => 'ee_edit_event_category',
234
+				'noheader'   => true,
235
+			],
236
+			'category_list'                 => [
237
+				'func'       => '_category_list_table',
238
+				'capability' => 'ee_manage_event_categories',
239
+			],
240
+			'preview_deletion'              => [
241
+				'func'       => 'previewDeletion',
242
+				'capability' => 'ee_delete_events',
243
+			],
244
+			'confirm_deletion'              => [
245
+				'func'       => 'confirmDeletion',
246
+				'capability' => 'ee_delete_events',
247
+				'noheader'   => true,
248
+			],
249
+		];
250
+	}
251
+
252
+
253
+	/**
254
+	 * Set the _page_config property for this admin page group.
255
+	 */
256
+	protected function _set_page_config()
257
+	{
258
+		$post_id            = $this->request->getRequestParam('post', 0, 'int');
259
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
+		$this->_page_config = [
261
+			'default'                => [
262
+				'nav'           => [
263
+					'label' => esc_html__('Overview', 'event_espresso'),
264
+					'order' => 10,
265
+				],
266
+				'list_table'    => 'Events_Admin_List_Table',
267
+				'help_tabs'     => [
268
+					'events_overview_help_tab'                       => [
269
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
270
+						'filename' => 'events_overview',
271
+					],
272
+					'events_overview_table_column_headings_help_tab' => [
273
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
+						'filename' => 'events_overview_table_column_headings',
275
+					],
276
+					'events_overview_filters_help_tab'               => [
277
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
+						'filename' => 'events_overview_filters',
279
+					],
280
+					'events_overview_view_help_tab'                  => [
281
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
+						'filename' => 'events_overview_views',
283
+					],
284
+					'events_overview_other_help_tab'                 => [
285
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
+						'filename' => 'events_overview_other',
287
+					],
288
+				],
289
+				'qtips'         => [
290
+					'EE_Event_List_Table_Tips',
291
+				],
292
+				'require_nonce' => false,
293
+			],
294
+			'create_new'             => [
295
+				'nav'           => [
296
+					'label'      => esc_html__('Add Event', 'event_espresso'),
297
+					'order'      => 5,
298
+					'persistent' => false,
299
+				],
300
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
301
+				'help_tabs'     => [
302
+					'event_editor_help_tab'                            => [
303
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
304
+						'filename' => 'event_editor',
305
+					],
306
+					'event_editor_title_richtexteditor_help_tab'       => [
307
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
308
+						'filename' => 'event_editor_title_richtexteditor',
309
+					],
310
+					'event_editor_venue_details_help_tab'              => [
311
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
312
+						'filename' => 'event_editor_venue_details',
313
+					],
314
+					'event_editor_event_datetimes_help_tab'            => [
315
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
316
+						'filename' => 'event_editor_event_datetimes',
317
+					],
318
+					'event_editor_event_tickets_help_tab'              => [
319
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
320
+						'filename' => 'event_editor_event_tickets',
321
+					],
322
+					'event_editor_event_registration_options_help_tab' => [
323
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
324
+						'filename' => 'event_editor_event_registration_options',
325
+					],
326
+					'event_editor_tags_categories_help_tab'            => [
327
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
328
+						'filename' => 'event_editor_tags_categories',
329
+					],
330
+					'event_editor_questions_registrants_help_tab'      => [
331
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
332
+						'filename' => 'event_editor_questions_registrants',
333
+					],
334
+					'event_editor_save_new_event_help_tab'             => [
335
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
336
+						'filename' => 'event_editor_save_new_event',
337
+					],
338
+					'event_editor_other_help_tab'                      => [
339
+						'title'    => esc_html__('Event Other', 'event_espresso'),
340
+						'filename' => 'event_editor_other',
341
+					],
342
+				],
343
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
344
+				'require_nonce' => false,
345
+			],
346
+			'edit'                   => [
347
+				'nav'           => [
348
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
349
+					'order'      => 5,
350
+					'persistent' => false,
351
+					'url'        => $post_id
352
+						? EE_Admin_Page::add_query_args_and_nonce(
353
+							['post' => $post_id, 'action' => 'edit'],
354
+							$this->_current_page_view_url
355
+						)
356
+						: $this->_admin_base_url,
357
+				],
358
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
359
+				'help_tabs'     => [
360
+					'event_editor_help_tab'                            => [
361
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
362
+						'filename' => 'event_editor',
363
+					],
364
+					'event_editor_title_richtexteditor_help_tab'       => [
365
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
366
+						'filename' => 'event_editor_title_richtexteditor',
367
+					],
368
+					'event_editor_venue_details_help_tab'              => [
369
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
370
+						'filename' => 'event_editor_venue_details',
371
+					],
372
+					'event_editor_event_datetimes_help_tab'            => [
373
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
374
+						'filename' => 'event_editor_event_datetimes',
375
+					],
376
+					'event_editor_event_tickets_help_tab'              => [
377
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
378
+						'filename' => 'event_editor_event_tickets',
379
+					],
380
+					'event_editor_event_registration_options_help_tab' => [
381
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
382
+						'filename' => 'event_editor_event_registration_options',
383
+					],
384
+					'event_editor_tags_categories_help_tab'            => [
385
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
386
+						'filename' => 'event_editor_tags_categories',
387
+					],
388
+					'event_editor_questions_registrants_help_tab'      => [
389
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
390
+						'filename' => 'event_editor_questions_registrants',
391
+					],
392
+					'event_editor_save_new_event_help_tab'             => [
393
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
394
+						'filename' => 'event_editor_save_new_event',
395
+					],
396
+					'event_editor_other_help_tab'                      => [
397
+						'title'    => esc_html__('Event Other', 'event_espresso'),
398
+						'filename' => 'event_editor_other',
399
+					],
400
+				],
401
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
402
+				'require_nonce' => false,
403
+			],
404
+			'default_event_settings' => [
405
+				'nav'           => [
406
+					'label' => esc_html__('Default Settings', 'event_espresso'),
407
+					'order' => 40,
408
+				],
409
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
410
+				'labels'        => [
411
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
412
+				],
413
+				'help_tabs'     => [
414
+					'default_settings_help_tab'        => [
415
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
416
+						'filename' => 'events_default_settings',
417
+					],
418
+					'default_settings_status_help_tab' => [
419
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
420
+						'filename' => 'events_default_settings_status',
421
+					],
422
+					'default_maximum_tickets_help_tab' => [
423
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
424
+						'filename' => 'events_default_settings_max_tickets',
425
+					],
426
+				],
427
+				'require_nonce' => false,
428
+			],
429
+			// template settings
430
+			'template_settings'      => [
431
+				'nav'           => [
432
+					'label' => esc_html__('Templates', 'event_espresso'),
433
+					'order' => 30,
434
+				],
435
+				'metaboxes'     => $this->_default_espresso_metaboxes,
436
+				'help_tabs'     => [
437
+					'general_settings_templates_help_tab' => [
438
+						'title'    => esc_html__('Templates', 'event_espresso'),
439
+						'filename' => 'general_settings_templates',
440
+					],
441
+				],
442
+				'require_nonce' => false,
443
+			],
444
+			// event category stuff
445
+			'add_category'           => [
446
+				'nav'           => [
447
+					'label'      => esc_html__('Add Category', 'event_espresso'),
448
+					'order'      => 15,
449
+					'persistent' => false,
450
+				],
451
+				'help_tabs'     => [
452
+					'add_category_help_tab' => [
453
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
454
+						'filename' => 'events_add_category',
455
+					],
456
+				],
457
+				'metaboxes'     => ['_publish_post_box'],
458
+				'require_nonce' => false,
459
+			],
460
+			'edit_category'          => [
461
+				'nav'           => [
462
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
463
+					'order'      => 15,
464
+					'persistent' => false,
465
+					'url'        => $EVT_CAT_ID
466
+						? add_query_arg(
467
+							['EVT_CAT_ID' => $EVT_CAT_ID],
468
+							$this->_current_page_view_url
469
+						)
470
+						: $this->_admin_base_url,
471
+				],
472
+				'help_tabs'     => [
473
+					'edit_category_help_tab' => [
474
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
475
+						'filename' => 'events_edit_category',
476
+					],
477
+				],
478
+				'metaboxes'     => ['_publish_post_box'],
479
+				'require_nonce' => false,
480
+			],
481
+			'category_list'          => [
482
+				'nav'           => [
483
+					'label' => esc_html__('Categories', 'event_espresso'),
484
+					'order' => 20,
485
+				],
486
+				'list_table'    => 'Event_Categories_Admin_List_Table',
487
+				'help_tabs'     => [
488
+					'events_categories_help_tab'                       => [
489
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
490
+						'filename' => 'events_categories',
491
+					],
492
+					'events_categories_table_column_headings_help_tab' => [
493
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
494
+						'filename' => 'events_categories_table_column_headings',
495
+					],
496
+					'events_categories_view_help_tab'                  => [
497
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
498
+						'filename' => 'events_categories_views',
499
+					],
500
+					'events_categories_other_help_tab'                 => [
501
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
502
+						'filename' => 'events_categories_other',
503
+					],
504
+				],
505
+				'metaboxes'     => $this->_default_espresso_metaboxes,
506
+				'require_nonce' => false,
507
+			],
508
+			'preview_deletion'       => [
509
+				'nav'           => [
510
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
511
+					'order'      => 15,
512
+					'persistent' => false,
513
+					'url'        => '',
514
+				],
515
+				'require_nonce' => false,
516
+			],
517
+		];
518
+	}
519
+
520
+
521
+	/**
522
+	 * Used to register any global screen options if necessary for every route in this admin page group.
523
+	 */
524
+	protected function _add_screen_options()
525
+	{
526
+	}
527
+
528
+
529
+	/**
530
+	 * Implementing the screen options for the 'default' route.
531
+	 */
532
+	protected function _add_screen_options_default()
533
+	{
534
+		$this->_per_page_screen_option();
535
+	}
536
+
537
+
538
+	/**
539
+	 * Implementing screen options for the category list route.
540
+	 */
541
+	protected function _add_screen_options_category_list()
542
+	{
543
+		$page_title              = $this->_admin_page_title;
544
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
545
+		$this->_per_page_screen_option();
546
+		$this->_admin_page_title = $page_title;
547
+	}
548
+
549
+
550
+	/**
551
+	 * Used to register any global feature pointers for the admin page group.
552
+	 */
553
+	protected function _add_feature_pointers()
554
+	{
555
+	}
556
+
557
+
558
+	/**
559
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
560
+	 */
561
+	public function load_scripts_styles()
562
+	{
563
+		wp_register_style(
564
+			'events-admin-css',
565
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
566
+			[],
567
+			EVENT_ESPRESSO_VERSION
568
+		);
569
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
570
+		wp_enqueue_style('events-admin-css');
571
+		wp_enqueue_style('ee-cat-admin');
572
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
573
+		// registers for all views
574
+		// scripts
575
+		wp_register_script(
576
+			'event_editor_js',
577
+			EVENTS_ASSETS_URL . 'event_editor.js',
578
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
579
+			EVENT_ESPRESSO_VERSION,
580
+			true
581
+		);
582
+	}
583
+
584
+
585
+	/**
586
+	 * Enqueuing scripts and styles specific to this view
587
+	 */
588
+	public function load_scripts_styles_create_new()
589
+	{
590
+		$this->load_scripts_styles_edit();
591
+	}
592
+
593
+
594
+	/**
595
+	 * Enqueuing scripts and styles specific to this view
596
+	 */
597
+	public function load_scripts_styles_edit()
598
+	{
599
+		// styles
600
+		wp_enqueue_style('espresso-ui-theme');
601
+		wp_register_style(
602
+			'event-editor-css',
603
+			EVENTS_ASSETS_URL . 'event-editor.css',
604
+			['ee-admin-css'],
605
+			EVENT_ESPRESSO_VERSION
606
+		);
607
+		wp_enqueue_style('event-editor-css');
608
+		// scripts
609
+		wp_register_script(
610
+			'event-datetime-metabox',
611
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
612
+			['event_editor_js', 'ee-datepicker'],
613
+			EVENT_ESPRESSO_VERSION
614
+		);
615
+		wp_enqueue_script('event-datetime-metabox');
616
+	}
617
+
618
+
619
+	/**
620
+	 * Populating the _views property for the category list table view.
621
+	 */
622
+	protected function _set_list_table_views_category_list()
623
+	{
624
+		$this->_views = [
625
+			'all' => [
626
+				'slug'        => 'all',
627
+				'label'       => esc_html__('All', 'event_espresso'),
628
+				'count'       => 0,
629
+				'bulk_action' => [
630
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
631
+				],
632
+			],
633
+		];
634
+	}
635
+
636
+
637
+	/**
638
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
639
+	 */
640
+	public function admin_init()
641
+	{
642
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
643
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
644
+			'event_espresso'
645
+		);
646
+	}
647
+
648
+
649
+	/**
650
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
651
+	 * group.
652
+	 */
653
+	public function admin_notices()
654
+	{
655
+	}
656
+
657
+
658
+	/**
659
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
660
+	 * this admin page group.
661
+	 */
662
+	public function admin_footer_scripts()
663
+	{
664
+	}
665
+
666
+
667
+	/**
668
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
669
+	 * warning (via EE_Error::add_error());
670
+	 *
671
+	 * @param EE_Event $event Event object
672
+	 * @param string   $req_type
673
+	 * @return void
674
+	 * @throws EE_Error
675
+	 * @throws ReflectionException
676
+	 */
677
+	public function verify_event_edit($event = null, $req_type = '')
678
+	{
679
+		// don't need to do this when processing
680
+		if (! empty($req_type)) {
681
+			return;
682
+		}
683
+		// no event?
684
+		if (empty($event)) {
685
+			// set event
686
+			$event = $this->_cpt_model_obj;
687
+		}
688
+		// STILL no event?
689
+		if (! $event instanceof EE_Event) {
690
+			return;
691
+		}
692
+		$orig_status = $event->status();
693
+		// first check if event is active.
694
+		if (
695
+			$orig_status === EEM_Event::cancelled
696
+			|| $orig_status === EEM_Event::postponed
697
+			|| $event->is_expired()
698
+			|| $event->is_inactive()
699
+		) {
700
+			return;
701
+		}
702
+		// made it here so it IS active... next check that any of the tickets are sold.
703
+		if ($event->is_sold_out(true)) {
704
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
705
+				EE_Error::add_attention(
706
+					sprintf(
707
+						esc_html__(
708
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
709
+							'event_espresso'
710
+						),
711
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
712
+					)
713
+				);
714
+			}
715
+			return;
716
+		} elseif ($orig_status === EEM_Event::sold_out) {
717
+			EE_Error::add_attention(
718
+				sprintf(
719
+					esc_html__(
720
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
721
+						'event_espresso'
722
+					),
723
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
724
+				)
725
+			);
726
+		}
727
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
728
+		if (! $event->tickets_on_sale()) {
729
+			return;
730
+		}
731
+		// made it here so show warning
732
+		$this->_edit_event_warning();
733
+	}
734
+
735
+
736
+	/**
737
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
738
+	 * When needed, hook this into a EE_Error::add_error() notice.
739
+	 *
740
+	 * @access protected
741
+	 * @return void
742
+	 */
743
+	protected function _edit_event_warning()
744
+	{
745
+		// we don't want to add warnings during these requests
746
+		if ($this->request->getRequestParam('action') === 'editpost') {
747
+			return;
748
+		}
749
+		EE_Error::add_attention(
750
+			sprintf(
751
+				esc_html__(
752
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
753
+					'event_espresso'
754
+				),
755
+				'<a class="espresso-help-tab-lnk">',
756
+				'</a>'
757
+			)
758
+		);
759
+	}
760
+
761
+
762
+	/**
763
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
764
+	 * Otherwise, do the normal logic
765
+	 *
766
+	 * @return void
767
+	 * @throws EE_Error
768
+	 */
769
+	protected function _create_new_cpt_item()
770
+	{
771
+		$has_timezone_string = get_option('timezone_string');
772
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
773
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
774
+			EE_Error::add_attention(
775
+				sprintf(
776
+					esc_html__(
777
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
778
+						'event_espresso'
779
+					),
780
+					'<br>',
781
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
782
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
783
+					. '</select>',
784
+					'<button class="button button-secondary timezone-submit">',
785
+					'</button><span class="spinner"></span>'
786
+				),
787
+				__FILE__,
788
+				__FUNCTION__,
789
+				__LINE__
790
+			);
791
+		}
792
+		parent::_create_new_cpt_item();
793
+	}
794
+
795
+
796
+	/**
797
+	 * Sets the _views property for the default route in this admin page group.
798
+	 */
799
+	protected function _set_list_table_views_default()
800
+	{
801
+		$this->_views = [
802
+			'all'   => [
803
+				'slug'        => 'all',
804
+				'label'       => esc_html__('View All Events', 'event_espresso'),
805
+				'count'       => 0,
806
+				'bulk_action' => [
807
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
808
+				],
809
+			],
810
+			'draft' => [
811
+				'slug'        => 'draft',
812
+				'label'       => esc_html__('Draft', 'event_espresso'),
813
+				'count'       => 0,
814
+				'bulk_action' => [
815
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
816
+				],
817
+			],
818
+		];
819
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
820
+			$this->_views['trash'] = [
821
+				'slug'        => 'trash',
822
+				'label'       => esc_html__('Trash', 'event_espresso'),
823
+				'count'       => 0,
824
+				'bulk_action' => [
825
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
826
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
827
+				],
828
+			];
829
+		}
830
+	}
831
+
832
+
833
+	/**
834
+	 * Provides the legend item array for the default list table view.
835
+	 *
836
+	 * @return array
837
+	 * @throws EE_Error
838
+	 * @throws EE_Error
839
+	 */
840
+	protected function _event_legend_items()
841
+	{
842
+		$items    = [
843
+			'view_details'   => [
844
+				'class' => 'dashicons dashicons-search',
845
+				'desc'  => esc_html__('View Event', 'event_espresso'),
846
+			],
847
+			'edit_event'     => [
848
+				'class' => 'ee-icon ee-icon-calendar-edit',
849
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
850
+			],
851
+			'view_attendees' => [
852
+				'class' => 'dashicons dashicons-groups',
853
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
854
+			],
855
+		];
856
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
857
+		$statuses = [
858
+			'sold_out_status'  => [
859
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
860
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
861
+			],
862
+			'active_status'    => [
863
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
864
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
865
+			],
866
+			'upcoming_status'  => [
867
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
868
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
869
+			],
870
+			'postponed_status' => [
871
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
872
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
873
+			],
874
+			'cancelled_status' => [
875
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
876
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
877
+			],
878
+			'expired_status'   => [
879
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
880
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
881
+			],
882
+			'inactive_status'  => [
883
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
884
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
885
+			],
886
+		];
887
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
888
+		return array_merge($items, $statuses);
889
+	}
890
+
891
+
892
+	/**
893
+	 * @return EEM_Event
894
+	 * @throws EE_Error
895
+	 * @throws ReflectionException
896
+	 */
897
+	private function _event_model()
898
+	{
899
+		if (! $this->_event_model instanceof EEM_Event) {
900
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
901
+		}
902
+		return $this->_event_model;
903
+	}
904
+
905
+
906
+	/**
907
+	 * Adds extra buttons to the WP CPT permalink field row.
908
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
909
+	 *
910
+	 * @param string $return    the current html
911
+	 * @param int    $id        the post id for the page
912
+	 * @param string $new_title What the title is
913
+	 * @param string $new_slug  what the slug is
914
+	 * @return string            The new html string for the permalink area
915
+	 */
916
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
917
+	{
918
+		// make sure this is only when editing
919
+		if (! empty($id)) {
920
+			$post   = get_post($id);
921
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
922
+					   . esc_html__('Shortcode', 'event_espresso')
923
+					   . '</a> ';
924
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
925
+					   . $post->ID
926
+					   . ']">';
927
+		}
928
+		return $return;
929
+	}
930
+
931
+
932
+	/**
933
+	 * _events_overview_list_table
934
+	 * This contains the logic for showing the events_overview list
935
+	 *
936
+	 * @access protected
937
+	 * @return void
938
+	 * @throws EE_Error
939
+	 */
940
+	protected function _events_overview_list_table()
941
+	{
942
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
943
+		$this->_template_args['after_list_table']                           =
944
+			! empty($this->_template_args['after_list_table'])
945
+				? (array) $this->_template_args['after_list_table']
946
+				: [];
947
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
948
+			. EEH_Template::get_button_or_link(
949
+				get_post_type_archive_link('espresso_events'),
950
+				esc_html__("View Event Archive Page", "event_espresso"),
951
+				'button'
952
+			);
953
+		$this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
954
+			$this->_event_legend_items()
955
+		);
956
+		$this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
957
+			'create_new',
958
+			'add',
959
+			[],
960
+			'add-new-h2'
961
+		);
962
+		$this->display_admin_list_table_page_with_no_sidebar();
963
+	}
964
+
965
+
966
+	/**
967
+	 * this allows for extra misc actions in the default WP publish box
968
+	 *
969
+	 * @return void
970
+	 * @throws EE_Error
971
+	 * @throws ReflectionException
972
+	 */
973
+	public function extra_misc_actions_publish_box()
974
+	{
975
+		$this->_generate_publish_box_extra_content();
976
+	}
977
+
978
+
979
+	/**
980
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
981
+	 * saved.
982
+	 * Typically you would use this to save any additional data.
983
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
984
+	 * ALSO very important.  When a post transitions from scheduled to published,
985
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
986
+	 * other meta saves. So MAKE sure that you handle this accordingly.
987
+	 *
988
+	 * @access protected
989
+	 * @abstract
990
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
991
+	 * @param WP_Post $post    The post object of the cpt that was saved.
992
+	 * @return void
993
+	 * @throws EE_Error
994
+	 * @throws ReflectionException
995
+	 */
996
+	protected function _insert_update_cpt_item($post_id, $post)
997
+	{
998
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
999
+			// get out we're not processing an event save.
1000
+			return;
1001
+		}
1002
+
1003
+		$event_values = [
1004
+			'EVT_display_desc'                => $this->request->getRequestParam('display_desc', false, 'bool'),
1005
+			'EVT_display_ticket_selector'     => $this->request->getRequestParam(
1006
+				'display_ticket_selector',
1007
+				false,
1008
+				'bool'
1009
+			),
1010
+			'EVT_additional_limit'            => min(
1011
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1012
+				$this->request->getRequestParam('additional_limit', null, 'int')
1013
+			),
1014
+			'EVT_default_registration_status' => $this->request->getRequestParam(
1015
+				'EVT_default_registration_status',
1016
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1017
+			),
1018
+
1019
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1020
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1021
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1022
+			'EVT_external_URL'    => $this->request->getRequestParam('externalURL'),
1023
+			'EVT_phone'           => $this->request->getRequestParam('event_phone'),
1024
+		];
1025
+		// update event
1026
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1027
+		// get event_object for other metaboxes...
1028
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1029
+		// i have to setup where conditions to override the filters in the model
1030
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1031
+		$event = $this->_event_model()->get_one(
1032
+			[
1033
+				[
1034
+					$this->_event_model()->primary_key_name() => $post_id,
1035
+					'OR'                                      => [
1036
+						'status'   => $post->post_status,
1037
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1038
+						// but the returned object here has a status of "publish", so use the original post status as well
1039
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1040
+					],
1041
+				],
1042
+			]
1043
+		);
1044
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1045
+		$event_update_callbacks = apply_filters(
1046
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1047
+			[
1048
+				[$this, '_default_venue_update'],
1049
+				[$this, '_default_tickets_update'],
1050
+			]
1051
+		);
1052
+		$att_success            = true;
1053
+		foreach ($event_update_callbacks as $e_callback) {
1054
+			$_success = is_callable($e_callback)
1055
+				? call_user_func($e_callback, $event, $this->request->requestParams())
1056
+				: false;
1057
+			// if ANY of these updates fail then we want the appropriate global error message
1058
+			$att_success = ! $att_success ? $att_success : $_success;
1059
+		}
1060
+		// any errors?
1061
+		if ($success && false === $att_success) {
1062
+			EE_Error::add_error(
1063
+				esc_html__(
1064
+					'Event Details saved successfully but something went wrong with saving attachments.',
1065
+					'event_espresso'
1066
+				),
1067
+				__FILE__,
1068
+				__FUNCTION__,
1069
+				__LINE__
1070
+			);
1071
+		} elseif ($success === false) {
1072
+			EE_Error::add_error(
1073
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1074
+				__FILE__,
1075
+				__FUNCTION__,
1076
+				__LINE__
1077
+			);
1078
+		}
1079
+	}
1080
+
1081
+
1082
+	/**
1083
+	 * @param int $post_id
1084
+	 * @param int $revision_id
1085
+	 * @throws EE_Error
1086
+	 * @throws EE_Error
1087
+	 * @throws ReflectionException
1088
+	 * @see parent::restore_item()
1089
+	 */
1090
+	protected function _restore_cpt_item($post_id, $revision_id)
1091
+	{
1092
+		// copy existing event meta to new post
1093
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1094
+		if ($post_evt instanceof EE_Event) {
1095
+			// meta revision restore
1096
+			$post_evt->restore_revision($revision_id);
1097
+			// related objs restore
1098
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1099
+		}
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * Attach the venue to the Event
1105
+	 *
1106
+	 * @param EE_Event $event Event Object to add the venue to
1107
+	 * @param array    $data  The request data from the form
1108
+	 * @return bool           Success or fail.
1109
+	 * @throws EE_Error
1110
+	 * @throws ReflectionException
1111
+	 */
1112
+	protected function _default_venue_update(EE_Event $event, $data)
1113
+	{
1114
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1115
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1116
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1117
+		// very important.  If we don't have a venue name...
1118
+		// then we'll get out because not necessary to create empty venue
1119
+		if (empty($data['venue_title'])) {
1120
+			return false;
1121
+		}
1122
+		$venue_array = [
1123
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1124
+			'VNU_name'            => $data['venue_title'],
1125
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1126
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1127
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1128
+				? $data['venue_short_description']
1129
+				: null,
1130
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1131
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1132
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1133
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1134
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1135
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1136
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1137
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1138
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1139
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1140
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1141
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1142
+			'status'              => 'publish',
1143
+		];
1144
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1145
+		if (! empty($venue_id)) {
1146
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1147
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1148
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1149
+			$event->_add_relation_to($venue_id, 'Venue');
1150
+			return $rows_affected > 0;
1151
+		}
1152
+		// we insert the venue
1153
+		$venue_id = $venue_model->insert($venue_array);
1154
+		$event->_add_relation_to($venue_id, 'Venue');
1155
+		return ! empty($venue_id);
1156
+		// when we have the ancestor come in it's already been handled by the revision save.
1157
+	}
1158
+
1159
+
1160
+	/**
1161
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1162
+	 *
1163
+	 * @param EE_Event $event The Event object we're attaching data to
1164
+	 * @param array    $data  The request data from the form
1165
+	 * @return array
1166
+	 * @throws EE_Error
1167
+	 * @throws ReflectionException
1168
+	 * @throws Exception
1169
+	 */
1170
+	protected function _default_tickets_update(EE_Event $event, $data)
1171
+	{
1172
+		$datetime       = null;
1173
+		$saved_tickets  = [];
1174
+		$event_timezone = $event->get_timezone();
1175
+		$date_formats   = ['Y-m-d', 'h:i a'];
1176
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1177
+			// trim all values to ensure any excess whitespace is removed.
1178
+			$datetime_data                = array_map('trim', $datetime_data);
1179
+			$datetime_data['DTT_EVT_end'] =
1180
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1181
+					? $datetime_data['DTT_EVT_end']
1182
+					: $datetime_data['DTT_EVT_start'];
1183
+			$datetime_values              = [
1184
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1185
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1186
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1187
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1188
+				'DTT_order'     => $row,
1189
+			];
1190
+			// if we have an id then let's get existing object first and then set the new values.
1191
+			//  Otherwise we instantiate a new object for save.
1192
+			if (! empty($datetime_data['DTT_ID'])) {
1193
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1194
+				if (! $datetime instanceof EE_Datetime) {
1195
+					throw new RuntimeException(
1196
+						sprintf(
1197
+							esc_html__(
1198
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1199
+								'event_espresso'
1200
+							),
1201
+							$datetime_data['DTT_ID']
1202
+						)
1203
+					);
1204
+				}
1205
+				$datetime->set_date_format($date_formats[0]);
1206
+				$datetime->set_time_format($date_formats[1]);
1207
+				foreach ($datetime_values as $field => $value) {
1208
+					$datetime->set($field, $value);
1209
+				}
1210
+			} else {
1211
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1212
+			}
1213
+			if (! $datetime instanceof EE_Datetime) {
1214
+				throw new RuntimeException(
1215
+					sprintf(
1216
+						esc_html__(
1217
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1218
+							'event_espresso'
1219
+						),
1220
+						print_r($datetime_values, true)
1221
+					)
1222
+				);
1223
+			}
1224
+			// before going any further make sure our dates are setup correctly
1225
+			// so that the end date is always equal or greater than the start date.
1226
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1227
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1228
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1229
+			}
1230
+			$datetime->save();
1231
+			$event->_add_relation_to($datetime, 'Datetime');
1232
+		}
1233
+		// no datetimes get deleted so we don't do any of that logic here.
1234
+		// update tickets next
1235
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1236
+
1237
+		// set up some default start and end dates in case those are not present in the incoming data
1238
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1239
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1240
+		// use the start date of the first datetime for the end date
1241
+		$first_datetime   = $event->first_datetime();
1242
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1243
+
1244
+		// now process the incoming data
1245
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1246
+			$update_prices = false;
1247
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1248
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1249
+				: 0;
1250
+			// trim inputs to ensure any excess whitespace is removed.
1251
+			$ticket_data   = array_map('trim', $ticket_data);
1252
+			$ticket_values = [
1253
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1254
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1255
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1256
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1257
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1258
+					? $ticket_data['TKT_start_date']
1259
+					: $default_start_date,
1260
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1261
+					? $ticket_data['TKT_end_date']
1262
+					: $default_end_date,
1263
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1264
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1265
+					? $ticket_data['TKT_qty']
1266
+					: EE_INF,
1267
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1268
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1269
+					? $ticket_data['TKT_uses']
1270
+					: EE_INF,
1271
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1272
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1273
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1274
+				'TKT_price'       => $ticket_price,
1275
+				'TKT_row'         => $row,
1276
+			];
1277
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1278
+			// which means in turn that the prices will become new prices as well.
1279
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1280
+				$ticket_values['TKT_ID']         = 0;
1281
+				$ticket_values['TKT_is_default'] = 0;
1282
+				$update_prices                   = true;
1283
+			}
1284
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1285
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1286
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1287
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1288
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1289
+			if (! empty($ticket_data['TKT_ID'])) {
1290
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1291
+				if (! $existing_ticket instanceof EE_Ticket) {
1292
+					throw new RuntimeException(
1293
+						sprintf(
1294
+							esc_html__(
1295
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1296
+								'event_espresso'
1297
+							),
1298
+							$ticket_data['TKT_ID']
1299
+						)
1300
+					);
1301
+				}
1302
+				$ticket_sold = $existing_ticket->count_related(
1303
+					'Registration',
1304
+					[
1305
+						[
1306
+							'STS_ID' => [
1307
+								'NOT IN',
1308
+								[EEM_Registration::status_id_incomplete],
1309
+							],
1310
+						],
1311
+					]
1312
+				) > 0;
1313
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1314
+				// if they are different then we create a new ticket (if $ticket_sold)
1315
+				// if they aren't different then we go ahead and modify existing ticket.
1316
+				$create_new_ticket = $ticket_sold
1317
+									 && $ticket_price !== $existing_ticket->price()
1318
+									 && ! $existing_ticket->deleted();
1319
+				$existing_ticket->set_date_format($date_formats[0]);
1320
+				$existing_ticket->set_time_format($date_formats[1]);
1321
+				// set new values
1322
+				foreach ($ticket_values as $field => $value) {
1323
+					if ($field == 'TKT_qty') {
1324
+						$existing_ticket->set_qty($value);
1325
+					} elseif ($field == 'TKT_price') {
1326
+						$existing_ticket->set('TKT_price', $ticket_price);
1327
+					} else {
1328
+						$existing_ticket->set($field, $value);
1329
+					}
1330
+				}
1331
+				$ticket = $existing_ticket;
1332
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1333
+				//  Otherwise we have to create a new ticket.
1334
+				if ($create_new_ticket) {
1335
+					// archive the old ticket first
1336
+					$existing_ticket->set('TKT_deleted', 1);
1337
+					$existing_ticket->save();
1338
+					// make sure this ticket is still recorded in our $saved_tickets
1339
+					// so we don't run it through the regular trash routine.
1340
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1341
+					// create new ticket that's a copy of the existing except,
1342
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1343
+					$new_ticket = clone $existing_ticket;
1344
+					$new_ticket->set('TKT_ID', 0);
1345
+					$new_ticket->set('TKT_deleted', 0);
1346
+					$new_ticket->set('TKT_sold', 0);
1347
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1348
+					$update_prices = true;
1349
+					$ticket        = $new_ticket;
1350
+				}
1351
+			} else {
1352
+				// no TKT_id so a new ticket
1353
+				$ticket_values['TKT_price'] = $ticket_price;
1354
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1355
+				$update_prices              = true;
1356
+			}
1357
+			if (! $ticket instanceof EE_Ticket) {
1358
+				throw new RuntimeException(
1359
+					sprintf(
1360
+						esc_html__(
1361
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1362
+							'event_espresso'
1363
+						),
1364
+						print_r($ticket_values, true)
1365
+					)
1366
+				);
1367
+			}
1368
+			// cap ticket qty by datetime reg limits
1369
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1370
+			// update ticket.
1371
+			$ticket->save();
1372
+			// before going any further make sure our dates are setup correctly
1373
+			// so that the end date is always equal or greater than the start date.
1374
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1375
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1376
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1377
+				$ticket->save();
1378
+			}
1379
+			// initially let's add the ticket to the datetime
1380
+			$datetime->_add_relation_to($ticket, 'Ticket');
1381
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1382
+			// add prices to ticket
1383
+			$prices_data = (
1384
+				isset($data['edit_prices'][ $row ])
1385
+				&& is_array($data['edit_prices'][ $row ])
1386
+			) ? $data['edit_prices'][ $row ] : [];
1387
+			$this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1388
+		}
1389
+		// however now we need to handle permanently deleting tickets via the ui.
1390
+		//  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1391
+		//  However, it does allow for deleting tickets that have no tickets sold,
1392
+		// in which case we want to get rid of permanently because there is no need to save in db.
1393
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets;
1394
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1395
+		foreach ($tickets_removed as $id) {
1396
+			$id = absint($id);
1397
+			// get the ticket for this id
1398
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1399
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1400
+				continue;
1401
+			}
1402
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1403
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1404
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1405
+			foreach ($related_datetimes as $related_datetime) {
1406
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1407
+			}
1408
+			// need to do the same for prices (except these prices can also be deleted because again,
1409
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1410
+			$ticket_to_remove->delete_related_permanently('Price');
1411
+			// finally let's delete this ticket
1412
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1413
+			$ticket_to_remove->delete_permanently();
1414
+		}
1415
+		return [$datetime, $saved_tickets];
1416
+	}
1417
+
1418
+
1419
+	/**
1420
+	 * This attaches a list of given prices to a ticket.
1421
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1422
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1423
+	 * price info and prices are automatically "archived" via the ticket.
1424
+	 *
1425
+	 * @access  private
1426
+	 * @param array     $prices_data Array of prices from the form.
1427
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1428
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1429
+	 * @return  void
1430
+	 * @throws EE_Error
1431
+	 * @throws ReflectionException
1432
+	 */
1433
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1434
+	{
1435
+		$timezone = $ticket->get_timezone();
1436
+		foreach ($prices_data as $row => $price_data) {
1437
+			$price_values = [
1438
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1439
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1440
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1441
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1442
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1443
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1444
+				'PRC_order'      => $row,
1445
+			];
1446
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1447
+				$price_values['PRC_ID'] = 0;
1448
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1449
+			} else {
1450
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1451
+				// update this price with new values
1452
+				foreach ($price_values as $field => $new_price) {
1453
+					$price->set($field, $new_price);
1454
+				}
1455
+			}
1456
+			if (! $price instanceof EE_Price) {
1457
+				throw new RuntimeException(
1458
+					sprintf(
1459
+						esc_html__(
1460
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1461
+							'event_espresso'
1462
+						),
1463
+						print_r($price_values, true)
1464
+					)
1465
+				);
1466
+			}
1467
+			$price->save();
1468
+			$ticket->_add_relation_to($price, 'Price');
1469
+		}
1470
+	}
1471
+
1472
+
1473
+	/**
1474
+	 * Add in our autosave ajax handlers
1475
+	 *
1476
+	 */
1477
+	protected function _ee_autosave_create_new()
1478
+	{
1479
+	}
1480
+
1481
+
1482
+	/**
1483
+	 * More autosave handlers.
1484
+	 */
1485
+	protected function _ee_autosave_edit()
1486
+	{
1487
+		// TEMPORARILY EXITING CAUSE THIS IS A TODO
1488
+	}
1489
+
1490
+
1491
+	/**
1492
+	 * @throws EE_Error
1493
+	 * @throws ReflectionException
1494
+	 */
1495
+	private function _generate_publish_box_extra_content()
1496
+	{
1497
+		// load formatter helper
1498
+		// args for getting related registrations
1499
+		$approved_query_args        = [
1500
+			[
1501
+				'REG_deleted' => 0,
1502
+				'STS_ID'      => EEM_Registration::status_id_approved,
1503
+			],
1504
+		];
1505
+		$not_approved_query_args    = [
1506
+			[
1507
+				'REG_deleted' => 0,
1508
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1509
+			],
1510
+		];
1511
+		$pending_payment_query_args = [
1512
+			[
1513
+				'REG_deleted' => 0,
1514
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1515
+			],
1516
+		];
1517
+		// publish box
1518
+		$publish_box_extra_args = [
1519
+			'view_approved_reg_url'        => add_query_arg(
1520
+				[
1521
+					'action'      => 'default',
1522
+					'event_id'    => $this->_cpt_model_obj->ID(),
1523
+					'_reg_status' => EEM_Registration::status_id_approved,
1524
+				],
1525
+				REG_ADMIN_URL
1526
+			),
1527
+			'view_not_approved_reg_url'    => add_query_arg(
1528
+				[
1529
+					'action'      => 'default',
1530
+					'event_id'    => $this->_cpt_model_obj->ID(),
1531
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1532
+				],
1533
+				REG_ADMIN_URL
1534
+			),
1535
+			'view_pending_payment_reg_url' => add_query_arg(
1536
+				[
1537
+					'action'      => 'default',
1538
+					'event_id'    => $this->_cpt_model_obj->ID(),
1539
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1540
+				],
1541
+				REG_ADMIN_URL
1542
+			),
1543
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1544
+				'Registration',
1545
+				$approved_query_args
1546
+			),
1547
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1548
+				'Registration',
1549
+				$not_approved_query_args
1550
+			),
1551
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1552
+				'Registration',
1553
+				$pending_payment_query_args
1554
+			),
1555
+			'misc_pub_section_class'       => apply_filters(
1556
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1557
+				'misc-pub-section'
1558
+			),
1559
+		];
1560
+		ob_start();
1561
+		do_action(
1562
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1563
+			$this->_cpt_model_obj
1564
+		);
1565
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1566
+		// load template
1567
+		EEH_Template::display_template(
1568
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1569
+			$publish_box_extra_args
1570
+		);
1571
+	}
1572
+
1573
+
1574
+	/**
1575
+	 * @return EE_Event
1576
+	 */
1577
+	public function get_event_object()
1578
+	{
1579
+		return $this->_cpt_model_obj;
1580
+	}
1581
+
1582
+
1583
+
1584
+
1585
+	/** METABOXES * */
1586
+	/**
1587
+	 * _register_event_editor_meta_boxes
1588
+	 * add all metaboxes related to the event_editor
1589
+	 *
1590
+	 * @return void
1591
+	 * @throws EE_Error
1592
+	 * @throws ReflectionException
1593
+	 */
1594
+	protected function _register_event_editor_meta_boxes()
1595
+	{
1596
+		$this->verify_cpt_object();
1597
+		add_meta_box(
1598
+			'espresso_event_editor_tickets',
1599
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1600
+			[$this, 'ticket_metabox'],
1601
+			$this->page_slug,
1602
+			'normal',
1603
+			'high'
1604
+		);
1605
+		add_meta_box(
1606
+			'espresso_event_editor_event_options',
1607
+			esc_html__('Event Registration Options', 'event_espresso'),
1608
+			[$this, 'registration_options_meta_box'],
1609
+			$this->page_slug,
1610
+			'side'
1611
+		);
1612
+		// NOTE: if you're looking for other metaboxes in here,
1613
+		// where a metabox has a related management page in the admin
1614
+		// you will find it setup in the related management page's "_Hooks" file.
1615
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1616
+	}
1617
+
1618
+
1619
+	/**
1620
+	 * @throws DomainException
1621
+	 * @throws EE_Error
1622
+	 * @throws ReflectionException
1623
+	 */
1624
+	public function ticket_metabox()
1625
+	{
1626
+		$existing_datetime_ids = $existing_ticket_ids = [];
1627
+		// defaults for template args
1628
+		$template_args = [
1629
+			'existing_datetime_ids'    => '',
1630
+			'event_datetime_help_link' => '',
1631
+			'ticket_options_help_link' => '',
1632
+			'time'                     => null,
1633
+			'ticket_rows'              => '',
1634
+			'existing_ticket_ids'      => '',
1635
+			'total_ticket_rows'        => 1,
1636
+			'ticket_js_structure'      => '',
1637
+			'trash_icon'               => 'ee-lock-icon',
1638
+			'disabled'                 => '',
1639
+		];
1640
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1641
+		/**
1642
+		 * 1. Start with retrieving Datetimes
1643
+		 * 2. Fore each datetime get related tickets
1644
+		 * 3. For each ticket get related prices
1645
+		 */
1646
+		$times          = EEM_Datetime::instance()->get_all_event_dates($event_id);
1647
+		$first_datetime = reset($times);
1648
+		// do we get related tickets?
1649
+		if (
1650
+			$first_datetime instanceof EE_Datetime
1651
+			&& $first_datetime->ID() !== 0
1652
+		) {
1653
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1654
+			$template_args['time']   = $first_datetime;
1655
+			$related_tickets         = $first_datetime->tickets(
1656
+				[
1657
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1658
+					'default_where_conditions' => 'none',
1659
+				]
1660
+			);
1661
+			if (! empty($related_tickets)) {
1662
+				$template_args['total_ticket_rows'] = count($related_tickets);
1663
+				$row                                = 0;
1664
+				foreach ($related_tickets as $ticket) {
1665
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1666
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1667
+					$row++;
1668
+				}
1669
+			} else {
1670
+				$template_args['total_ticket_rows'] = 1;
1671
+				/** @type EE_Ticket $ticket */
1672
+				$ticket                       = EEM_Ticket::instance()->create_default_object();
1673
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1674
+			}
1675
+		} else {
1676
+			$template_args['time']        = $times[0];
1677
+			$tickets                      = EEM_Ticket::instance()->get_all_default_tickets();
1678
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1679
+			// NOTE: we're just sending the first default row
1680
+			// (decaf can't manage default tickets so this should be sufficient);
1681
+		}
1682
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1683
+			'event_editor_event_datetimes_help_tab'
1684
+		);
1685
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1686
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1687
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1688
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1689
+			EEM_Ticket::instance()->create_default_object(),
1690
+			true
1691
+		);
1692
+		$template                                  = apply_filters(
1693
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1694
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1695
+		);
1696
+		EEH_Template::display_template($template, $template_args);
1697
+	}
1698
+
1699
+
1700
+	/**
1701
+	 * Setup an individual ticket form for the decaf event editor page
1702
+	 *
1703
+	 * @access private
1704
+	 * @param EE_Ticket $ticket   the ticket object
1705
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1706
+	 * @param int       $row
1707
+	 * @return string generated html for the ticket row.
1708
+	 * @throws EE_Error
1709
+	 * @throws ReflectionException
1710
+	 */
1711
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1712
+	{
1713
+		$template_args = [
1714
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1715
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1716
+				: '',
1717
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1718
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1719
+			'TKT_name'            => $ticket->get('TKT_name'),
1720
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1721
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1722
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1723
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1724
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1725
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1726
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1727
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1728
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1729
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1730
+				: ' disabled=disabled',
1731
+		];
1732
+		$price         = $ticket->ID() !== 0
1733
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1734
+			: null;
1735
+		$price         = $price instanceof EE_Price
1736
+			? $price
1737
+			: EEM_Price::instance()->create_default_object();
1738
+		$price_args    = [
1739
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1740
+			'PRC_amount'            => $price->get('PRC_amount'),
1741
+			'PRT_ID'                => $price->get('PRT_ID'),
1742
+			'PRC_ID'                => $price->get('PRC_ID'),
1743
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1744
+		];
1745
+		// make sure we have default start and end dates if skeleton
1746
+		// handle rows that should NOT be empty
1747
+		if (empty($template_args['TKT_start_date'])) {
1748
+			// if empty then the start date will be now.
1749
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1750
+		}
1751
+		if (empty($template_args['TKT_end_date'])) {
1752
+			// get the earliest datetime (if present);
1753
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1754
+				? $this->_cpt_model_obj->get_first_related(
1755
+					'Datetime',
1756
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1757
+				)
1758
+				: null;
1759
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1760
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1761
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1762
+		}
1763
+		$template_args = array_merge($template_args, $price_args);
1764
+		$template      = apply_filters(
1765
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1766
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1767
+			$ticket
1768
+		);
1769
+		return EEH_Template::display_template($template, $template_args, true);
1770
+	}
1771
+
1772
+
1773
+	/**
1774
+	 * @throws EE_Error
1775
+	 * @throws ReflectionException
1776
+	 */
1777
+	public function registration_options_meta_box()
1778
+	{
1779
+		$yes_no_values             = [
1780
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1781
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1782
+		];
1783
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1784
+			[
1785
+				EEM_Registration::status_id_cancelled,
1786
+				EEM_Registration::status_id_declined,
1787
+				EEM_Registration::status_id_incomplete,
1788
+			],
1789
+			true
1790
+		);
1791
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1792
+		$template_args['_event']                          = $this->_cpt_model_obj;
1793
+		$template_args['event']                           = $this->_cpt_model_obj;
1794
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1795
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1796
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1797
+			'default_reg_status',
1798
+			$default_reg_status_values,
1799
+			$this->_cpt_model_obj->default_registration_status()
1800
+		);
1801
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1802
+			'display_desc',
1803
+			$yes_no_values,
1804
+			$this->_cpt_model_obj->display_description()
1805
+		);
1806
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1807
+			'display_ticket_selector',
1808
+			$yes_no_values,
1809
+			$this->_cpt_model_obj->display_ticket_selector(),
1810
+			'',
1811
+			'',
1812
+			false
1813
+		);
1814
+		$template_args['additional_registration_options'] = apply_filters(
1815
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1816
+			'',
1817
+			$template_args,
1818
+			$yes_no_values,
1819
+			$default_reg_status_values
1820
+		);
1821
+		EEH_Template::display_template(
1822
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1823
+			$template_args
1824
+		);
1825
+	}
1826
+
1827
+
1828
+	/**
1829
+	 * _get_events()
1830
+	 * This method simply returns all the events (for the given _view and paging)
1831
+	 *
1832
+	 * @access public
1833
+	 * @param int  $per_page     count of items per page (20 default);
1834
+	 * @param int  $current_page what is the current page being viewed.
1835
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1836
+	 *                           If FALSE then we return an array of event objects
1837
+	 *                           that match the given _view and paging parameters.
1838
+	 * @return array|int         an array of event objects or a count of them.
1839
+	 * @throws Exception
1840
+	 */
1841
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1842
+	{
1843
+		$EEM_Event   = $this->_event_model();
1844
+		$offset      = ($current_page - 1) * $per_page;
1845
+		$limit       = $count ? null : $offset . ',' . $per_page;
1846
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1847
+		$order       = $this->request->getRequestParam('order', 'DESC');
1848
+		$month_range = $this->request->getRequestParam('month_range');
1849
+		if ($month_range) {
1850
+			$pieces = explode(' ', $month_range, 3);
1851
+			// simulate the FIRST day of the month, that fixes issues for months like February
1852
+			// where PHP doesn't know what to assume for date.
1853
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1854
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1855
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1856
+		}
1857
+		$where  = [];
1858
+		$status = $this->request->getRequestParam('status');
1859
+		// determine what post_status our condition will have for the query.
1860
+		switch ($status) {
1861
+			case 'month':
1862
+			case 'today':
1863
+			case null:
1864
+			case 'all':
1865
+				break;
1866
+			case 'draft':
1867
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1868
+				break;
1869
+			default:
1870
+				$where['status'] = $status;
1871
+		}
1872
+		// categories? The default for all categories is -1
1873
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1874
+		if ($category !== -1) {
1875
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1876
+			$where['Term_Taxonomy.term_id']  = $category;
1877
+		}
1878
+		// date where conditions
1879
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1880
+		if ($month_range) {
1881
+			$DateTime = new DateTime(
1882
+				$year_r . '-' . $month_r . '-01 00:00:00',
1883
+				new DateTimeZone('UTC')
1884
+			);
1885
+			$start    = $DateTime->getTimestamp();
1886
+			// set the datetime to be the end of the month
1887
+			$DateTime->setDate(
1888
+				$year_r,
1889
+				$month_r,
1890
+				$DateTime->format('t')
1891
+			)->setTime(23, 59, 59);
1892
+			$end                             = $DateTime->getTimestamp();
1893
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1894
+		} elseif ($status === 'today') {
1895
+			$DateTime                        =
1896
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1897
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1898
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1899
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1900
+		} elseif ($status === 'month') {
1901
+			$now                             = date('Y-m-01');
1902
+			$DateTime                        =
1903
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1904
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1905
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1906
+														->setTime(23, 59, 59)
1907
+														->format(implode(' ', $start_formats));
1908
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1909
+		}
1910
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1911
+			$where['EVT_wp_user'] = get_current_user_id();
1912
+		} else {
1913
+			if (! isset($where['status'])) {
1914
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1915
+					$where['OR'] = [
1916
+						'status*restrict_private' => ['!=', 'private'],
1917
+						'AND'                     => [
1918
+							'status*inclusive' => ['=', 'private'],
1919
+							'EVT_wp_user'      => get_current_user_id(),
1920
+						],
1921
+					];
1922
+				}
1923
+			}
1924
+		}
1925
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1926
+		if (
1927
+			$wp_user
1928
+			&& $wp_user !== get_current_user_id()
1929
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1930
+		) {
1931
+			$where['EVT_wp_user'] = $wp_user;
1932
+		}
1933
+		// search query handling
1934
+		$search_term = $this->request->getRequestParam('s');
1935
+		if ($search_term) {
1936
+			$search_term = '%' . $search_term . '%';
1937
+			$where['OR'] = [
1938
+				'EVT_name'       => ['LIKE', $search_term],
1939
+				'EVT_desc'       => ['LIKE', $search_term],
1940
+				'EVT_short_desc' => ['LIKE', $search_term],
1941
+			];
1942
+		}
1943
+		// filter events by venue.
1944
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
1945
+		if ($venue) {
1946
+			$where['Venue.VNU_ID'] = $venue;
1947
+		}
1948
+		$request_params = $this->request->requestParams();
1949
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
1950
+		$query_params   = apply_filters(
1951
+			'FHEE__Events_Admin_Page__get_events__query_params',
1952
+			[
1953
+				$where,
1954
+				'limit'    => $limit,
1955
+				'order_by' => $orderby,
1956
+				'order'    => $order,
1957
+				'group_by' => 'EVT_ID',
1958
+			],
1959
+			$request_params
1960
+		);
1961
+
1962
+		// let's first check if we have special requests coming in.
1963
+		$active_status = $this->request->getRequestParam('active_status');
1964
+		if ($active_status) {
1965
+			switch ($active_status) {
1966
+				case 'upcoming':
1967
+					return $EEM_Event->get_upcoming_events($query_params, $count);
1968
+				case 'expired':
1969
+					return $EEM_Event->get_expired_events($query_params, $count);
1970
+				case 'active':
1971
+					return $EEM_Event->get_active_events($query_params, $count);
1972
+				case 'inactive':
1973
+					return $EEM_Event->get_inactive_events($query_params, $count);
1974
+			}
1975
+		}
1976
+
1977
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
1978
+	}
1979
+
1980
+
1981
+	/**
1982
+	 * handling for WordPress CPT actions (trash, restore, delete)
1983
+	 *
1984
+	 * @param string $post_id
1985
+	 * @throws EE_Error
1986
+	 * @throws ReflectionException
1987
+	 */
1988
+	public function trash_cpt_item($post_id)
1989
+	{
1990
+		$this->request->setRequestParam('EVT_ID', $post_id);
1991
+		$this->_trash_or_restore_event('trash', false);
1992
+	}
1993
+
1994
+
1995
+	/**
1996
+	 * @param string $post_id
1997
+	 * @throws EE_Error
1998
+	 * @throws ReflectionException
1999
+	 */
2000
+	public function restore_cpt_item($post_id)
2001
+	{
2002
+		$this->request->setRequestParam('EVT_ID', $post_id);
2003
+		$this->_trash_or_restore_event('draft', false);
2004
+	}
2005
+
2006
+
2007
+	/**
2008
+	 * @param string $post_id
2009
+	 * @throws EE_Error
2010
+	 * @throws EE_Error
2011
+	 */
2012
+	public function delete_cpt_item($post_id)
2013
+	{
2014
+		throw new EE_Error(
2015
+			esc_html__(
2016
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2017
+				'event_espresso'
2018
+			)
2019
+		);
2020
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2021
+		// $this->_delete_event();
2022
+	}
2023
+
2024
+
2025
+	/**
2026
+	 * _trash_or_restore_event
2027
+	 *
2028
+	 * @access protected
2029
+	 * @param string $event_status
2030
+	 * @param bool   $redirect_after
2031
+	 * @throws EE_Error
2032
+	 * @throws EE_Error
2033
+	 * @throws ReflectionException
2034
+	 */
2035
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2036
+	{
2037
+		// determine the event id and set to array.
2038
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2039
+		// loop thru events
2040
+		if ($EVT_ID) {
2041
+			// clean status
2042
+			$event_status = sanitize_key($event_status);
2043
+			// grab status
2044
+			if (! empty($event_status)) {
2045
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2046
+			} else {
2047
+				$success = false;
2048
+				$msg     = esc_html__(
2049
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2050
+					'event_espresso'
2051
+				);
2052
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2053
+			}
2054
+		} else {
2055
+			$success = false;
2056
+			$msg     = esc_html__(
2057
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2058
+				'event_espresso'
2059
+			);
2060
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2061
+		}
2062
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2063
+		if ($redirect_after) {
2064
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2065
+		}
2066
+	}
2067
+
2068
+
2069
+	/**
2070
+	 * _trash_or_restore_events
2071
+	 *
2072
+	 * @access protected
2073
+	 * @param string $event_status
2074
+	 * @return void
2075
+	 * @throws EE_Error
2076
+	 * @throws EE_Error
2077
+	 * @throws ReflectionException
2078
+	 */
2079
+	protected function _trash_or_restore_events($event_status = 'trash')
2080
+	{
2081
+		// clean status
2082
+		$event_status = sanitize_key($event_status);
2083
+		// grab status
2084
+		if (! empty($event_status)) {
2085
+			$success = true;
2086
+			// determine the event id and set to array.
2087
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2088
+			// loop thru events
2089
+			foreach ($EVT_IDs as $EVT_ID) {
2090
+				if ($EVT_ID = absint($EVT_ID)) {
2091
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2092
+					$success = $results !== false ? $success : false;
2093
+				} else {
2094
+					$msg = sprintf(
2095
+						esc_html__(
2096
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2097
+							'event_espresso'
2098
+						),
2099
+						$EVT_ID
2100
+					);
2101
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2102
+					$success = false;
2103
+				}
2104
+			}
2105
+		} else {
2106
+			$success = false;
2107
+			$msg     = esc_html__(
2108
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2109
+				'event_espresso'
2110
+			);
2111
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2112
+		}
2113
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2114
+		$success = $success ? 2 : false;
2115
+		$action  = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2116
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2117
+	}
2118
+
2119
+
2120
+	/**
2121
+	 * @param int    $EVT_ID
2122
+	 * @param string $event_status
2123
+	 * @return bool
2124
+	 * @throws EE_Error
2125
+	 * @throws ReflectionException
2126
+	 */
2127
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2128
+	{
2129
+		// grab event id
2130
+		if (! $EVT_ID) {
2131
+			$msg = esc_html__(
2132
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2133
+				'event_espresso'
2134
+			);
2135
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2136
+			return false;
2137
+		}
2138
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2139
+		// clean status
2140
+		$event_status = sanitize_key($event_status);
2141
+		// grab status
2142
+		if (empty($event_status)) {
2143
+			$msg = esc_html__(
2144
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2145
+				'event_espresso'
2146
+			);
2147
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2148
+			return false;
2149
+		}
2150
+		// was event trashed or restored ?
2151
+		switch ($event_status) {
2152
+			case 'draft':
2153
+				$action = 'restored from the trash';
2154
+				$hook   = 'AHEE_event_restored_from_trash';
2155
+				break;
2156
+			case 'trash':
2157
+				$action = 'moved to the trash';
2158
+				$hook   = 'AHEE_event_moved_to_trash';
2159
+				break;
2160
+			default:
2161
+				$action = 'updated';
2162
+				$hook   = false;
2163
+		}
2164
+		// use class to change status
2165
+		$this->_cpt_model_obj->set_status($event_status);
2166
+		$success = $this->_cpt_model_obj->save();
2167
+		if (! $success) {
2168
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2169
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2170
+			return false;
2171
+		}
2172
+		if ($hook) {
2173
+			do_action($hook);
2174
+		}
2175
+		return true;
2176
+	}
2177
+
2178
+
2179
+	/**
2180
+	 * @param array $event_ids
2181
+	 * @return array
2182
+	 * @since   4.10.23.p
2183
+	 */
2184
+	private function cleanEventIds(array $event_ids)
2185
+	{
2186
+		return array_map('absint', $event_ids);
2187
+	}
2188
+
2189
+
2190
+	/**
2191
+	 * @return array
2192
+	 * @since   4.10.23.p
2193
+	 */
2194
+	private function getEventIdsFromRequest()
2195
+	{
2196
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2197
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2198
+		} else {
2199
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2200
+		}
2201
+	}
2202
+
2203
+
2204
+	/**
2205
+	 * @param bool $preview_delete
2206
+	 * @throws EE_Error
2207
+	 */
2208
+	protected function _delete_event($preview_delete = true)
2209
+	{
2210
+		$this->_delete_events($preview_delete);
2211
+	}
2212
+
2213
+
2214
+	/**
2215
+	 * Gets the tree traversal batch persister.
2216
+	 *
2217
+	 * @return NodeGroupDao
2218
+	 * @throws InvalidArgumentException
2219
+	 * @throws InvalidDataTypeException
2220
+	 * @throws InvalidInterfaceException
2221
+	 * @since 4.10.12.p
2222
+	 */
2223
+	protected function getModelObjNodeGroupPersister()
2224
+	{
2225
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2226
+			$this->model_obj_node_group_persister =
2227
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2228
+		}
2229
+		return $this->model_obj_node_group_persister;
2230
+	}
2231
+
2232
+
2233
+	/**
2234
+	 * @param bool $preview_delete
2235
+	 * @return void
2236
+	 * @throws EE_Error
2237
+	 */
2238
+	protected function _delete_events($preview_delete = true)
2239
+	{
2240
+		$event_ids = $this->getEventIdsFromRequest();
2241
+		if ($preview_delete) {
2242
+			$this->generateDeletionPreview($event_ids);
2243
+		} else {
2244
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2245
+		}
2246
+	}
2247
+
2248
+
2249
+	/**
2250
+	 * @param array $event_ids
2251
+	 */
2252
+	protected function generateDeletionPreview(array $event_ids)
2253
+	{
2254
+		$event_ids = $this->cleanEventIds($event_ids);
2255
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2256
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2257
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2258
+			[
2259
+				'action'            => 'preview_deletion',
2260
+				'deletion_job_code' => $deletion_job_code,
2261
+			],
2262
+			$this->_admin_base_url
2263
+		);
2264
+		EEH_URL::safeRedirectAndExit(
2265
+			EE_Admin_Page::add_query_args_and_nonce(
2266
+				[
2267
+					'page'              => 'espresso_batch',
2268
+					'batch'             => EED_Batch::batch_job,
2269
+					'EVT_IDs'           => $event_ids,
2270
+					'deletion_job_code' => $deletion_job_code,
2271
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2272
+					'return_url'        => urlencode($return_url),
2273
+				],
2274
+				admin_url()
2275
+			)
2276
+		);
2277
+	}
2278
+
2279
+
2280
+	/**
2281
+	 * Checks for a POST submission
2282
+	 *
2283
+	 * @since 4.10.12.p
2284
+	 */
2285
+	protected function confirmDeletion()
2286
+	{
2287
+		$deletion_redirect_logic =
2288
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2289
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2290
+	}
2291
+
2292
+
2293
+	/**
2294
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2295
+	 *
2296
+	 * @throws EE_Error
2297
+	 * @since 4.10.12.p
2298
+	 */
2299
+	protected function previewDeletion()
2300
+	{
2301
+		$preview_deletion_logic =
2302
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2303
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2304
+		$this->display_admin_page_with_no_sidebar();
2305
+	}
2306
+
2307
+
2308
+	/**
2309
+	 * get total number of events
2310
+	 *
2311
+	 * @access public
2312
+	 * @return int
2313
+	 * @throws EE_Error
2314
+	 * @throws EE_Error
2315
+	 */
2316
+	public function total_events()
2317
+	{
2318
+		return EEM_Event::instance()->count(
2319
+			['caps' => 'read_admin'],
2320
+			'EVT_ID',
2321
+			true
2322
+		);
2323
+	}
2324
+
2325
+
2326
+	/**
2327
+	 * get total number of draft events
2328
+	 *
2329
+	 * @access public
2330
+	 * @return int
2331
+	 * @throws EE_Error
2332
+	 * @throws EE_Error
2333
+	 */
2334
+	public function total_events_draft()
2335
+	{
2336
+		return EEM_Event::instance()->count(
2337
+			[
2338
+				['status' => ['IN', ['draft', 'auto-draft']]],
2339
+				'caps' => 'read_admin',
2340
+			],
2341
+			'EVT_ID',
2342
+			true
2343
+		);
2344
+	}
2345
+
2346
+
2347
+	/**
2348
+	 * get total number of trashed events
2349
+	 *
2350
+	 * @access public
2351
+	 * @return int
2352
+	 * @throws EE_Error
2353
+	 * @throws EE_Error
2354
+	 */
2355
+	public function total_trashed_events()
2356
+	{
2357
+		return EEM_Event::instance()->count(
2358
+			[
2359
+				['status' => 'trash'],
2360
+				'caps' => 'read_admin',
2361
+			],
2362
+			'EVT_ID',
2363
+			true
2364
+		);
2365
+	}
2366
+
2367
+
2368
+	/**
2369
+	 *    _default_event_settings
2370
+	 *    This generates the Default Settings Tab
2371
+	 *
2372
+	 * @return void
2373
+	 * @throws EE_Error
2374
+	 */
2375
+	protected function _default_event_settings()
2376
+	{
2377
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2378
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2379
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2380
+		$this->display_admin_page_with_sidebar();
2381
+	}
2382
+
2383
+
2384
+	/**
2385
+	 * Return the form for event settings.
2386
+	 *
2387
+	 * @return EE_Form_Section_Proper
2388
+	 * @throws EE_Error
2389
+	 */
2390
+	protected function _default_event_settings_form()
2391
+	{
2392
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2393
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2394
+		// exclude
2395
+			[
2396
+				EEM_Registration::status_id_cancelled,
2397
+				EEM_Registration::status_id_declined,
2398
+				EEM_Registration::status_id_incomplete,
2399
+				EEM_Registration::status_id_wait_list,
2400
+			],
2401
+			true
2402
+		);
2403
+		return new EE_Form_Section_Proper(
2404
+			[
2405
+				'name'            => 'update_default_event_settings',
2406
+				'html_id'         => 'update_default_event_settings',
2407
+				'html_class'      => 'form-table',
2408
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2409
+				'subsections'     => apply_filters(
2410
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2411
+					[
2412
+						'default_reg_status'  => new EE_Select_Input(
2413
+							$registration_stati_for_selection,
2414
+							[
2415
+								'default'         => isset($registration_config->default_STS_ID)
2416
+													 && array_key_exists(
2417
+														 $registration_config->default_STS_ID,
2418
+														 $registration_stati_for_selection
2419
+													 )
2420
+									? sanitize_text_field($registration_config->default_STS_ID)
2421
+									: EEM_Registration::status_id_pending_payment,
2422
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2423
+													 . EEH_Template::get_help_tab_link(
2424
+														 'default_settings_status_help_tab'
2425
+													 ),
2426
+								'html_help_text'  => esc_html__(
2427
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2428
+									'event_espresso'
2429
+								),
2430
+							]
2431
+						),
2432
+						'default_max_tickets' => new EE_Integer_Input(
2433
+							[
2434
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2435
+									? $registration_config->default_maximum_number_of_tickets
2436
+									: EEM_Event::get_default_additional_limit(),
2437
+								'html_label_text' => esc_html__(
2438
+									'Default Maximum Tickets Allowed Per Order:',
2439
+									'event_espresso'
2440
+								)
2441
+								. EEH_Template::get_help_tab_link(
2442
+									'default_maximum_tickets_help_tab"'
2443
+								),
2444
+								'html_help_text'  => esc_html__(
2445
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2446
+									'event_espresso'
2447
+								),
2448
+							]
2449
+						),
2450
+					]
2451
+				),
2452
+			]
2453
+		);
2454
+	}
2455
+
2456
+
2457
+	/**
2458
+	 * _update_default_event_settings
2459
+	 *
2460
+	 * @access protected
2461
+	 * @return void
2462
+	 * @throws EE_Error
2463
+	 */
2464
+	protected function _update_default_event_settings()
2465
+	{
2466
+		$registration_config = EE_Registry::instance()->CFG->registration;
2467
+		$form                = $this->_default_event_settings_form();
2468
+		if ($form->was_submitted()) {
2469
+			$form->receive_form_submission();
2470
+			if ($form->is_valid()) {
2471
+				$valid_data = $form->valid_data();
2472
+				if (isset($valid_data['default_reg_status'])) {
2473
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2474
+				}
2475
+				if (isset($valid_data['default_max_tickets'])) {
2476
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2477
+				}
2478
+				// update because data was valid!
2479
+				EE_Registry::instance()->CFG->update_espresso_config();
2480
+				EE_Error::overwrite_success();
2481
+				EE_Error::add_success(
2482
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2483
+				);
2484
+			}
2485
+		}
2486
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2487
+	}
2488
+
2489
+
2490
+	/*************        Templates        *************
21 2491
      *
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $_cpt_model_obj = false;
47
-
48
-
49
-    /**
50
-     * @var NodeGroupDao
51
-     */
52
-    protected $model_obj_node_group_persister;
53
-
54
-
55
-    /**
56
-     * Initialize page props for this admin page group.
57
-     */
58
-    protected function _init_page_props()
59
-    {
60
-        $this->page_slug        = EVENTS_PG_SLUG;
61
-        $this->page_label       = EVENTS_LABEL;
62
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
63
-        $this->_admin_base_path = EVENTS_ADMIN;
64
-        $this->_cpt_model_names = [
65
-            'create_new' => 'EEM_Event',
66
-            'edit'       => 'EEM_Event',
67
-        ];
68
-        $this->_cpt_edit_routes = [
69
-            'espresso_events' => 'edit',
70
-        ];
71
-        add_action(
72
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
-            [$this, 'verify_event_edit'],
74
-            10,
75
-            2
76
-        );
77
-    }
78
-
79
-
80
-    /**
81
-     * Sets the ajax hooks used for this admin page group.
82
-     */
83
-    protected function _ajax_hooks()
84
-    {
85
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
-    }
87
-
88
-
89
-    /**
90
-     * Sets the page properties for this admin page group.
91
-     */
92
-    protected function _define_page_props()
93
-    {
94
-        $this->_admin_page_title = EVENTS_LABEL;
95
-        $this->_labels           = [
96
-            'buttons'      => [
97
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
98
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
-            ],
104
-            'editor_title' => [
105
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
-            ],
107
-            'publishbox'   => [
108
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
110
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
-            ],
114
-        ];
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets the page routes property for this admin page group.
120
-     */
121
-    protected function _set_page_routes()
122
-    {
123
-        // load formatter helper
124
-        // load field generator helper
125
-        // is there a evt_id in the request?
126
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
-
129
-        $this->_page_routes = [
130
-            'default'                       => [
131
-                'func'       => '_events_overview_list_table',
132
-                'capability' => 'ee_read_events',
133
-            ],
134
-            'create_new'                    => [
135
-                'func'       => '_create_new_cpt_item',
136
-                'capability' => 'ee_edit_events',
137
-            ],
138
-            'edit'                          => [
139
-                'func'       => '_edit_cpt_item',
140
-                'capability' => 'ee_edit_event',
141
-                'obj_id'     => $EVT_ID,
142
-            ],
143
-            'copy_event'                    => [
144
-                'func'       => '_copy_events',
145
-                'capability' => 'ee_edit_event',
146
-                'obj_id'     => $EVT_ID,
147
-                'noheader'   => true,
148
-            ],
149
-            'trash_event'                   => [
150
-                'func'       => '_trash_or_restore_event',
151
-                'args'       => ['event_status' => 'trash'],
152
-                'capability' => 'ee_delete_event',
153
-                'obj_id'     => $EVT_ID,
154
-                'noheader'   => true,
155
-            ],
156
-            'trash_events'                  => [
157
-                'func'       => '_trash_or_restore_events',
158
-                'args'       => ['event_status' => 'trash'],
159
-                'capability' => 'ee_delete_events',
160
-                'noheader'   => true,
161
-            ],
162
-            'restore_event'                 => [
163
-                'func'       => '_trash_or_restore_event',
164
-                'args'       => ['event_status' => 'draft'],
165
-                'capability' => 'ee_delete_event',
166
-                'obj_id'     => $EVT_ID,
167
-                'noheader'   => true,
168
-            ],
169
-            'restore_events'                => [
170
-                'func'       => '_trash_or_restore_events',
171
-                'args'       => ['event_status' => 'draft'],
172
-                'capability' => 'ee_delete_events',
173
-                'noheader'   => true,
174
-            ],
175
-            'delete_event'                  => [
176
-                'func'       => '_delete_event',
177
-                'capability' => 'ee_delete_event',
178
-                'obj_id'     => $EVT_ID,
179
-                'noheader'   => true,
180
-            ],
181
-            'delete_events'                 => [
182
-                'func'       => '_delete_events',
183
-                'capability' => 'ee_delete_events',
184
-                'noheader'   => true,
185
-            ],
186
-            'view_report'                   => [
187
-                'func'       => '_view_report',
188
-                'capability' => 'ee_edit_events',
189
-            ],
190
-            'default_event_settings'        => [
191
-                'func'       => '_default_event_settings',
192
-                'capability' => 'manage_options',
193
-            ],
194
-            'update_default_event_settings' => [
195
-                'func'       => '_update_default_event_settings',
196
-                'capability' => 'manage_options',
197
-                'noheader'   => true,
198
-            ],
199
-            'template_settings'             => [
200
-                'func'       => '_template_settings',
201
-                'capability' => 'manage_options',
202
-            ],
203
-            // event category tab related
204
-            'add_category'                  => [
205
-                'func'       => '_category_details',
206
-                'capability' => 'ee_edit_event_category',
207
-                'args'       => ['add'],
208
-            ],
209
-            'edit_category'                 => [
210
-                'func'       => '_category_details',
211
-                'capability' => 'ee_edit_event_category',
212
-                'args'       => ['edit'],
213
-            ],
214
-            'delete_categories'             => [
215
-                'func'       => '_delete_categories',
216
-                'capability' => 'ee_delete_event_category',
217
-                'noheader'   => true,
218
-            ],
219
-            'delete_category'               => [
220
-                'func'       => '_delete_categories',
221
-                'capability' => 'ee_delete_event_category',
222
-                'noheader'   => true,
223
-            ],
224
-            'insert_category'               => [
225
-                'func'       => '_insert_or_update_category',
226
-                'args'       => ['new_category' => true],
227
-                'capability' => 'ee_edit_event_category',
228
-                'noheader'   => true,
229
-            ],
230
-            'update_category'               => [
231
-                'func'       => '_insert_or_update_category',
232
-                'args'       => ['new_category' => false],
233
-                'capability' => 'ee_edit_event_category',
234
-                'noheader'   => true,
235
-            ],
236
-            'category_list'                 => [
237
-                'func'       => '_category_list_table',
238
-                'capability' => 'ee_manage_event_categories',
239
-            ],
240
-            'preview_deletion'              => [
241
-                'func'       => 'previewDeletion',
242
-                'capability' => 'ee_delete_events',
243
-            ],
244
-            'confirm_deletion'              => [
245
-                'func'       => 'confirmDeletion',
246
-                'capability' => 'ee_delete_events',
247
-                'noheader'   => true,
248
-            ],
249
-        ];
250
-    }
251
-
252
-
253
-    /**
254
-     * Set the _page_config property for this admin page group.
255
-     */
256
-    protected function _set_page_config()
257
-    {
258
-        $post_id            = $this->request->getRequestParam('post', 0, 'int');
259
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
-        $this->_page_config = [
261
-            'default'                => [
262
-                'nav'           => [
263
-                    'label' => esc_html__('Overview', 'event_espresso'),
264
-                    'order' => 10,
265
-                ],
266
-                'list_table'    => 'Events_Admin_List_Table',
267
-                'help_tabs'     => [
268
-                    'events_overview_help_tab'                       => [
269
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
270
-                        'filename' => 'events_overview',
271
-                    ],
272
-                    'events_overview_table_column_headings_help_tab' => [
273
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
-                        'filename' => 'events_overview_table_column_headings',
275
-                    ],
276
-                    'events_overview_filters_help_tab'               => [
277
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
-                        'filename' => 'events_overview_filters',
279
-                    ],
280
-                    'events_overview_view_help_tab'                  => [
281
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
-                        'filename' => 'events_overview_views',
283
-                    ],
284
-                    'events_overview_other_help_tab'                 => [
285
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
-                        'filename' => 'events_overview_other',
287
-                    ],
288
-                ],
289
-                'qtips'         => [
290
-                    'EE_Event_List_Table_Tips',
291
-                ],
292
-                'require_nonce' => false,
293
-            ],
294
-            'create_new'             => [
295
-                'nav'           => [
296
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
297
-                    'order'      => 5,
298
-                    'persistent' => false,
299
-                ],
300
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
301
-                'help_tabs'     => [
302
-                    'event_editor_help_tab'                            => [
303
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
304
-                        'filename' => 'event_editor',
305
-                    ],
306
-                    'event_editor_title_richtexteditor_help_tab'       => [
307
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
308
-                        'filename' => 'event_editor_title_richtexteditor',
309
-                    ],
310
-                    'event_editor_venue_details_help_tab'              => [
311
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
312
-                        'filename' => 'event_editor_venue_details',
313
-                    ],
314
-                    'event_editor_event_datetimes_help_tab'            => [
315
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
316
-                        'filename' => 'event_editor_event_datetimes',
317
-                    ],
318
-                    'event_editor_event_tickets_help_tab'              => [
319
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
320
-                        'filename' => 'event_editor_event_tickets',
321
-                    ],
322
-                    'event_editor_event_registration_options_help_tab' => [
323
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
324
-                        'filename' => 'event_editor_event_registration_options',
325
-                    ],
326
-                    'event_editor_tags_categories_help_tab'            => [
327
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
328
-                        'filename' => 'event_editor_tags_categories',
329
-                    ],
330
-                    'event_editor_questions_registrants_help_tab'      => [
331
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
332
-                        'filename' => 'event_editor_questions_registrants',
333
-                    ],
334
-                    'event_editor_save_new_event_help_tab'             => [
335
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
336
-                        'filename' => 'event_editor_save_new_event',
337
-                    ],
338
-                    'event_editor_other_help_tab'                      => [
339
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
340
-                        'filename' => 'event_editor_other',
341
-                    ],
342
-                ],
343
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
344
-                'require_nonce' => false,
345
-            ],
346
-            'edit'                   => [
347
-                'nav'           => [
348
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
349
-                    'order'      => 5,
350
-                    'persistent' => false,
351
-                    'url'        => $post_id
352
-                        ? EE_Admin_Page::add_query_args_and_nonce(
353
-                            ['post' => $post_id, 'action' => 'edit'],
354
-                            $this->_current_page_view_url
355
-                        )
356
-                        : $this->_admin_base_url,
357
-                ],
358
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
359
-                'help_tabs'     => [
360
-                    'event_editor_help_tab'                            => [
361
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
362
-                        'filename' => 'event_editor',
363
-                    ],
364
-                    'event_editor_title_richtexteditor_help_tab'       => [
365
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
366
-                        'filename' => 'event_editor_title_richtexteditor',
367
-                    ],
368
-                    'event_editor_venue_details_help_tab'              => [
369
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
370
-                        'filename' => 'event_editor_venue_details',
371
-                    ],
372
-                    'event_editor_event_datetimes_help_tab'            => [
373
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
374
-                        'filename' => 'event_editor_event_datetimes',
375
-                    ],
376
-                    'event_editor_event_tickets_help_tab'              => [
377
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
378
-                        'filename' => 'event_editor_event_tickets',
379
-                    ],
380
-                    'event_editor_event_registration_options_help_tab' => [
381
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
382
-                        'filename' => 'event_editor_event_registration_options',
383
-                    ],
384
-                    'event_editor_tags_categories_help_tab'            => [
385
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
386
-                        'filename' => 'event_editor_tags_categories',
387
-                    ],
388
-                    'event_editor_questions_registrants_help_tab'      => [
389
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
390
-                        'filename' => 'event_editor_questions_registrants',
391
-                    ],
392
-                    'event_editor_save_new_event_help_tab'             => [
393
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
394
-                        'filename' => 'event_editor_save_new_event',
395
-                    ],
396
-                    'event_editor_other_help_tab'                      => [
397
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
398
-                        'filename' => 'event_editor_other',
399
-                    ],
400
-                ],
401
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
402
-                'require_nonce' => false,
403
-            ],
404
-            'default_event_settings' => [
405
-                'nav'           => [
406
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
407
-                    'order' => 40,
408
-                ],
409
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
410
-                'labels'        => [
411
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
412
-                ],
413
-                'help_tabs'     => [
414
-                    'default_settings_help_tab'        => [
415
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
416
-                        'filename' => 'events_default_settings',
417
-                    ],
418
-                    'default_settings_status_help_tab' => [
419
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
420
-                        'filename' => 'events_default_settings_status',
421
-                    ],
422
-                    'default_maximum_tickets_help_tab' => [
423
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
424
-                        'filename' => 'events_default_settings_max_tickets',
425
-                    ],
426
-                ],
427
-                'require_nonce' => false,
428
-            ],
429
-            // template settings
430
-            'template_settings'      => [
431
-                'nav'           => [
432
-                    'label' => esc_html__('Templates', 'event_espresso'),
433
-                    'order' => 30,
434
-                ],
435
-                'metaboxes'     => $this->_default_espresso_metaboxes,
436
-                'help_tabs'     => [
437
-                    'general_settings_templates_help_tab' => [
438
-                        'title'    => esc_html__('Templates', 'event_espresso'),
439
-                        'filename' => 'general_settings_templates',
440
-                    ],
441
-                ],
442
-                'require_nonce' => false,
443
-            ],
444
-            // event category stuff
445
-            'add_category'           => [
446
-                'nav'           => [
447
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
448
-                    'order'      => 15,
449
-                    'persistent' => false,
450
-                ],
451
-                'help_tabs'     => [
452
-                    'add_category_help_tab' => [
453
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
454
-                        'filename' => 'events_add_category',
455
-                    ],
456
-                ],
457
-                'metaboxes'     => ['_publish_post_box'],
458
-                'require_nonce' => false,
459
-            ],
460
-            'edit_category'          => [
461
-                'nav'           => [
462
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
463
-                    'order'      => 15,
464
-                    'persistent' => false,
465
-                    'url'        => $EVT_CAT_ID
466
-                        ? add_query_arg(
467
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
468
-                            $this->_current_page_view_url
469
-                        )
470
-                        : $this->_admin_base_url,
471
-                ],
472
-                'help_tabs'     => [
473
-                    'edit_category_help_tab' => [
474
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
475
-                        'filename' => 'events_edit_category',
476
-                    ],
477
-                ],
478
-                'metaboxes'     => ['_publish_post_box'],
479
-                'require_nonce' => false,
480
-            ],
481
-            'category_list'          => [
482
-                'nav'           => [
483
-                    'label' => esc_html__('Categories', 'event_espresso'),
484
-                    'order' => 20,
485
-                ],
486
-                'list_table'    => 'Event_Categories_Admin_List_Table',
487
-                'help_tabs'     => [
488
-                    'events_categories_help_tab'                       => [
489
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
490
-                        'filename' => 'events_categories',
491
-                    ],
492
-                    'events_categories_table_column_headings_help_tab' => [
493
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
494
-                        'filename' => 'events_categories_table_column_headings',
495
-                    ],
496
-                    'events_categories_view_help_tab'                  => [
497
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
498
-                        'filename' => 'events_categories_views',
499
-                    ],
500
-                    'events_categories_other_help_tab'                 => [
501
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
502
-                        'filename' => 'events_categories_other',
503
-                    ],
504
-                ],
505
-                'metaboxes'     => $this->_default_espresso_metaboxes,
506
-                'require_nonce' => false,
507
-            ],
508
-            'preview_deletion'       => [
509
-                'nav'           => [
510
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
511
-                    'order'      => 15,
512
-                    'persistent' => false,
513
-                    'url'        => '',
514
-                ],
515
-                'require_nonce' => false,
516
-            ],
517
-        ];
518
-    }
519
-
520
-
521
-    /**
522
-     * Used to register any global screen options if necessary for every route in this admin page group.
523
-     */
524
-    protected function _add_screen_options()
525
-    {
526
-    }
527
-
528
-
529
-    /**
530
-     * Implementing the screen options for the 'default' route.
531
-     */
532
-    protected function _add_screen_options_default()
533
-    {
534
-        $this->_per_page_screen_option();
535
-    }
536
-
537
-
538
-    /**
539
-     * Implementing screen options for the category list route.
540
-     */
541
-    protected function _add_screen_options_category_list()
542
-    {
543
-        $page_title              = $this->_admin_page_title;
544
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
545
-        $this->_per_page_screen_option();
546
-        $this->_admin_page_title = $page_title;
547
-    }
548
-
549
-
550
-    /**
551
-     * Used to register any global feature pointers for the admin page group.
552
-     */
553
-    protected function _add_feature_pointers()
554
-    {
555
-    }
556
-
557
-
558
-    /**
559
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
560
-     */
561
-    public function load_scripts_styles()
562
-    {
563
-        wp_register_style(
564
-            'events-admin-css',
565
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
566
-            [],
567
-            EVENT_ESPRESSO_VERSION
568
-        );
569
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
570
-        wp_enqueue_style('events-admin-css');
571
-        wp_enqueue_style('ee-cat-admin');
572
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
573
-        // registers for all views
574
-        // scripts
575
-        wp_register_script(
576
-            'event_editor_js',
577
-            EVENTS_ASSETS_URL . 'event_editor.js',
578
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
579
-            EVENT_ESPRESSO_VERSION,
580
-            true
581
-        );
582
-    }
583
-
584
-
585
-    /**
586
-     * Enqueuing scripts and styles specific to this view
587
-     */
588
-    public function load_scripts_styles_create_new()
589
-    {
590
-        $this->load_scripts_styles_edit();
591
-    }
592
-
593
-
594
-    /**
595
-     * Enqueuing scripts and styles specific to this view
596
-     */
597
-    public function load_scripts_styles_edit()
598
-    {
599
-        // styles
600
-        wp_enqueue_style('espresso-ui-theme');
601
-        wp_register_style(
602
-            'event-editor-css',
603
-            EVENTS_ASSETS_URL . 'event-editor.css',
604
-            ['ee-admin-css'],
605
-            EVENT_ESPRESSO_VERSION
606
-        );
607
-        wp_enqueue_style('event-editor-css');
608
-        // scripts
609
-        wp_register_script(
610
-            'event-datetime-metabox',
611
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
612
-            ['event_editor_js', 'ee-datepicker'],
613
-            EVENT_ESPRESSO_VERSION
614
-        );
615
-        wp_enqueue_script('event-datetime-metabox');
616
-    }
617
-
618
-
619
-    /**
620
-     * Populating the _views property for the category list table view.
621
-     */
622
-    protected function _set_list_table_views_category_list()
623
-    {
624
-        $this->_views = [
625
-            'all' => [
626
-                'slug'        => 'all',
627
-                'label'       => esc_html__('All', 'event_espresso'),
628
-                'count'       => 0,
629
-                'bulk_action' => [
630
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
631
-                ],
632
-            ],
633
-        ];
634
-    }
635
-
636
-
637
-    /**
638
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
639
-     */
640
-    public function admin_init()
641
-    {
642
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
643
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
644
-            'event_espresso'
645
-        );
646
-    }
647
-
648
-
649
-    /**
650
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
651
-     * group.
652
-     */
653
-    public function admin_notices()
654
-    {
655
-    }
656
-
657
-
658
-    /**
659
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
660
-     * this admin page group.
661
-     */
662
-    public function admin_footer_scripts()
663
-    {
664
-    }
665
-
666
-
667
-    /**
668
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
669
-     * warning (via EE_Error::add_error());
670
-     *
671
-     * @param EE_Event $event Event object
672
-     * @param string   $req_type
673
-     * @return void
674
-     * @throws EE_Error
675
-     * @throws ReflectionException
676
-     */
677
-    public function verify_event_edit($event = null, $req_type = '')
678
-    {
679
-        // don't need to do this when processing
680
-        if (! empty($req_type)) {
681
-            return;
682
-        }
683
-        // no event?
684
-        if (empty($event)) {
685
-            // set event
686
-            $event = $this->_cpt_model_obj;
687
-        }
688
-        // STILL no event?
689
-        if (! $event instanceof EE_Event) {
690
-            return;
691
-        }
692
-        $orig_status = $event->status();
693
-        // first check if event is active.
694
-        if (
695
-            $orig_status === EEM_Event::cancelled
696
-            || $orig_status === EEM_Event::postponed
697
-            || $event->is_expired()
698
-            || $event->is_inactive()
699
-        ) {
700
-            return;
701
-        }
702
-        // made it here so it IS active... next check that any of the tickets are sold.
703
-        if ($event->is_sold_out(true)) {
704
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
705
-                EE_Error::add_attention(
706
-                    sprintf(
707
-                        esc_html__(
708
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
709
-                            'event_espresso'
710
-                        ),
711
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
712
-                    )
713
-                );
714
-            }
715
-            return;
716
-        } elseif ($orig_status === EEM_Event::sold_out) {
717
-            EE_Error::add_attention(
718
-                sprintf(
719
-                    esc_html__(
720
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
721
-                        'event_espresso'
722
-                    ),
723
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
724
-                )
725
-            );
726
-        }
727
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
728
-        if (! $event->tickets_on_sale()) {
729
-            return;
730
-        }
731
-        // made it here so show warning
732
-        $this->_edit_event_warning();
733
-    }
734
-
735
-
736
-    /**
737
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
738
-     * When needed, hook this into a EE_Error::add_error() notice.
739
-     *
740
-     * @access protected
741
-     * @return void
742
-     */
743
-    protected function _edit_event_warning()
744
-    {
745
-        // we don't want to add warnings during these requests
746
-        if ($this->request->getRequestParam('action') === 'editpost') {
747
-            return;
748
-        }
749
-        EE_Error::add_attention(
750
-            sprintf(
751
-                esc_html__(
752
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
753
-                    'event_espresso'
754
-                ),
755
-                '<a class="espresso-help-tab-lnk">',
756
-                '</a>'
757
-            )
758
-        );
759
-    }
760
-
761
-
762
-    /**
763
-     * When a user is creating a new event, notify them if they haven't set their timezone.
764
-     * Otherwise, do the normal logic
765
-     *
766
-     * @return void
767
-     * @throws EE_Error
768
-     */
769
-    protected function _create_new_cpt_item()
770
-    {
771
-        $has_timezone_string = get_option('timezone_string');
772
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
773
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
774
-            EE_Error::add_attention(
775
-                sprintf(
776
-                    esc_html__(
777
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
778
-                        'event_espresso'
779
-                    ),
780
-                    '<br>',
781
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
782
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
783
-                    . '</select>',
784
-                    '<button class="button button-secondary timezone-submit">',
785
-                    '</button><span class="spinner"></span>'
786
-                ),
787
-                __FILE__,
788
-                __FUNCTION__,
789
-                __LINE__
790
-            );
791
-        }
792
-        parent::_create_new_cpt_item();
793
-    }
794
-
795
-
796
-    /**
797
-     * Sets the _views property for the default route in this admin page group.
798
-     */
799
-    protected function _set_list_table_views_default()
800
-    {
801
-        $this->_views = [
802
-            'all'   => [
803
-                'slug'        => 'all',
804
-                'label'       => esc_html__('View All Events', 'event_espresso'),
805
-                'count'       => 0,
806
-                'bulk_action' => [
807
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
808
-                ],
809
-            ],
810
-            'draft' => [
811
-                'slug'        => 'draft',
812
-                'label'       => esc_html__('Draft', 'event_espresso'),
813
-                'count'       => 0,
814
-                'bulk_action' => [
815
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
816
-                ],
817
-            ],
818
-        ];
819
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
820
-            $this->_views['trash'] = [
821
-                'slug'        => 'trash',
822
-                'label'       => esc_html__('Trash', 'event_espresso'),
823
-                'count'       => 0,
824
-                'bulk_action' => [
825
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
826
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
827
-                ],
828
-            ];
829
-        }
830
-    }
831
-
832
-
833
-    /**
834
-     * Provides the legend item array for the default list table view.
835
-     *
836
-     * @return array
837
-     * @throws EE_Error
838
-     * @throws EE_Error
839
-     */
840
-    protected function _event_legend_items()
841
-    {
842
-        $items    = [
843
-            'view_details'   => [
844
-                'class' => 'dashicons dashicons-search',
845
-                'desc'  => esc_html__('View Event', 'event_espresso'),
846
-            ],
847
-            'edit_event'     => [
848
-                'class' => 'ee-icon ee-icon-calendar-edit',
849
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
850
-            ],
851
-            'view_attendees' => [
852
-                'class' => 'dashicons dashicons-groups',
853
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
854
-            ],
855
-        ];
856
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
857
-        $statuses = [
858
-            'sold_out_status'  => [
859
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
860
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
861
-            ],
862
-            'active_status'    => [
863
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
864
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
865
-            ],
866
-            'upcoming_status'  => [
867
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
868
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
869
-            ],
870
-            'postponed_status' => [
871
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
872
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
873
-            ],
874
-            'cancelled_status' => [
875
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
876
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
877
-            ],
878
-            'expired_status'   => [
879
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
880
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
881
-            ],
882
-            'inactive_status'  => [
883
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
884
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
885
-            ],
886
-        ];
887
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
888
-        return array_merge($items, $statuses);
889
-    }
890
-
891
-
892
-    /**
893
-     * @return EEM_Event
894
-     * @throws EE_Error
895
-     * @throws ReflectionException
896
-     */
897
-    private function _event_model()
898
-    {
899
-        if (! $this->_event_model instanceof EEM_Event) {
900
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
901
-        }
902
-        return $this->_event_model;
903
-    }
904
-
905
-
906
-    /**
907
-     * Adds extra buttons to the WP CPT permalink field row.
908
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
909
-     *
910
-     * @param string $return    the current html
911
-     * @param int    $id        the post id for the page
912
-     * @param string $new_title What the title is
913
-     * @param string $new_slug  what the slug is
914
-     * @return string            The new html string for the permalink area
915
-     */
916
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
917
-    {
918
-        // make sure this is only when editing
919
-        if (! empty($id)) {
920
-            $post   = get_post($id);
921
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
922
-                       . esc_html__('Shortcode', 'event_espresso')
923
-                       . '</a> ';
924
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
925
-                       . $post->ID
926
-                       . ']">';
927
-        }
928
-        return $return;
929
-    }
930
-
931
-
932
-    /**
933
-     * _events_overview_list_table
934
-     * This contains the logic for showing the events_overview list
935
-     *
936
-     * @access protected
937
-     * @return void
938
-     * @throws EE_Error
939
-     */
940
-    protected function _events_overview_list_table()
941
-    {
942
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
943
-        $this->_template_args['after_list_table']                           =
944
-            ! empty($this->_template_args['after_list_table'])
945
-                ? (array) $this->_template_args['after_list_table']
946
-                : [];
947
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
948
-            . EEH_Template::get_button_or_link(
949
-                get_post_type_archive_link('espresso_events'),
950
-                esc_html__("View Event Archive Page", "event_espresso"),
951
-                'button'
952
-            );
953
-        $this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
954
-            $this->_event_legend_items()
955
-        );
956
-        $this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
957
-            'create_new',
958
-            'add',
959
-            [],
960
-            'add-new-h2'
961
-        );
962
-        $this->display_admin_list_table_page_with_no_sidebar();
963
-    }
964
-
965
-
966
-    /**
967
-     * this allows for extra misc actions in the default WP publish box
968
-     *
969
-     * @return void
970
-     * @throws EE_Error
971
-     * @throws ReflectionException
972
-     */
973
-    public function extra_misc_actions_publish_box()
974
-    {
975
-        $this->_generate_publish_box_extra_content();
976
-    }
977
-
978
-
979
-    /**
980
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
981
-     * saved.
982
-     * Typically you would use this to save any additional data.
983
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
984
-     * ALSO very important.  When a post transitions from scheduled to published,
985
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
986
-     * other meta saves. So MAKE sure that you handle this accordingly.
987
-     *
988
-     * @access protected
989
-     * @abstract
990
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
991
-     * @param WP_Post $post    The post object of the cpt that was saved.
992
-     * @return void
993
-     * @throws EE_Error
994
-     * @throws ReflectionException
995
-     */
996
-    protected function _insert_update_cpt_item($post_id, $post)
997
-    {
998
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
999
-            // get out we're not processing an event save.
1000
-            return;
1001
-        }
1002
-
1003
-        $event_values = [
1004
-            'EVT_display_desc'                => $this->request->getRequestParam('display_desc', false, 'bool'),
1005
-            'EVT_display_ticket_selector'     => $this->request->getRequestParam(
1006
-                'display_ticket_selector',
1007
-                false,
1008
-                'bool'
1009
-            ),
1010
-            'EVT_additional_limit'            => min(
1011
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1012
-                $this->request->getRequestParam('additional_limit', null, 'int')
1013
-            ),
1014
-            'EVT_default_registration_status' => $this->request->getRequestParam(
1015
-                'EVT_default_registration_status',
1016
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1017
-            ),
1018
-
1019
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1020
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1021
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1022
-            'EVT_external_URL'    => $this->request->getRequestParam('externalURL'),
1023
-            'EVT_phone'           => $this->request->getRequestParam('event_phone'),
1024
-        ];
1025
-        // update event
1026
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1027
-        // get event_object for other metaboxes...
1028
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1029
-        // i have to setup where conditions to override the filters in the model
1030
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1031
-        $event = $this->_event_model()->get_one(
1032
-            [
1033
-                [
1034
-                    $this->_event_model()->primary_key_name() => $post_id,
1035
-                    'OR'                                      => [
1036
-                        'status'   => $post->post_status,
1037
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1038
-                        // but the returned object here has a status of "publish", so use the original post status as well
1039
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1040
-                    ],
1041
-                ],
1042
-            ]
1043
-        );
1044
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1045
-        $event_update_callbacks = apply_filters(
1046
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1047
-            [
1048
-                [$this, '_default_venue_update'],
1049
-                [$this, '_default_tickets_update'],
1050
-            ]
1051
-        );
1052
-        $att_success            = true;
1053
-        foreach ($event_update_callbacks as $e_callback) {
1054
-            $_success = is_callable($e_callback)
1055
-                ? call_user_func($e_callback, $event, $this->request->requestParams())
1056
-                : false;
1057
-            // if ANY of these updates fail then we want the appropriate global error message
1058
-            $att_success = ! $att_success ? $att_success : $_success;
1059
-        }
1060
-        // any errors?
1061
-        if ($success && false === $att_success) {
1062
-            EE_Error::add_error(
1063
-                esc_html__(
1064
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1065
-                    'event_espresso'
1066
-                ),
1067
-                __FILE__,
1068
-                __FUNCTION__,
1069
-                __LINE__
1070
-            );
1071
-        } elseif ($success === false) {
1072
-            EE_Error::add_error(
1073
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1074
-                __FILE__,
1075
-                __FUNCTION__,
1076
-                __LINE__
1077
-            );
1078
-        }
1079
-    }
1080
-
1081
-
1082
-    /**
1083
-     * @param int $post_id
1084
-     * @param int $revision_id
1085
-     * @throws EE_Error
1086
-     * @throws EE_Error
1087
-     * @throws ReflectionException
1088
-     * @see parent::restore_item()
1089
-     */
1090
-    protected function _restore_cpt_item($post_id, $revision_id)
1091
-    {
1092
-        // copy existing event meta to new post
1093
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1094
-        if ($post_evt instanceof EE_Event) {
1095
-            // meta revision restore
1096
-            $post_evt->restore_revision($revision_id);
1097
-            // related objs restore
1098
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1099
-        }
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * Attach the venue to the Event
1105
-     *
1106
-     * @param EE_Event $event Event Object to add the venue to
1107
-     * @param array    $data  The request data from the form
1108
-     * @return bool           Success or fail.
1109
-     * @throws EE_Error
1110
-     * @throws ReflectionException
1111
-     */
1112
-    protected function _default_venue_update(EE_Event $event, $data)
1113
-    {
1114
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1115
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1116
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1117
-        // very important.  If we don't have a venue name...
1118
-        // then we'll get out because not necessary to create empty venue
1119
-        if (empty($data['venue_title'])) {
1120
-            return false;
1121
-        }
1122
-        $venue_array = [
1123
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1124
-            'VNU_name'            => $data['venue_title'],
1125
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1126
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1127
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1128
-                ? $data['venue_short_description']
1129
-                : null,
1130
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1131
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1132
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1133
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1134
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1135
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1136
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1137
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1138
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1139
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1140
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1141
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1142
-            'status'              => 'publish',
1143
-        ];
1144
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1145
-        if (! empty($venue_id)) {
1146
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1147
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1148
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1149
-            $event->_add_relation_to($venue_id, 'Venue');
1150
-            return $rows_affected > 0;
1151
-        }
1152
-        // we insert the venue
1153
-        $venue_id = $venue_model->insert($venue_array);
1154
-        $event->_add_relation_to($venue_id, 'Venue');
1155
-        return ! empty($venue_id);
1156
-        // when we have the ancestor come in it's already been handled by the revision save.
1157
-    }
1158
-
1159
-
1160
-    /**
1161
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1162
-     *
1163
-     * @param EE_Event $event The Event object we're attaching data to
1164
-     * @param array    $data  The request data from the form
1165
-     * @return array
1166
-     * @throws EE_Error
1167
-     * @throws ReflectionException
1168
-     * @throws Exception
1169
-     */
1170
-    protected function _default_tickets_update(EE_Event $event, $data)
1171
-    {
1172
-        $datetime       = null;
1173
-        $saved_tickets  = [];
1174
-        $event_timezone = $event->get_timezone();
1175
-        $date_formats   = ['Y-m-d', 'h:i a'];
1176
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1177
-            // trim all values to ensure any excess whitespace is removed.
1178
-            $datetime_data                = array_map('trim', $datetime_data);
1179
-            $datetime_data['DTT_EVT_end'] =
1180
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1181
-                    ? $datetime_data['DTT_EVT_end']
1182
-                    : $datetime_data['DTT_EVT_start'];
1183
-            $datetime_values              = [
1184
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1185
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1186
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1187
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1188
-                'DTT_order'     => $row,
1189
-            ];
1190
-            // if we have an id then let's get existing object first and then set the new values.
1191
-            //  Otherwise we instantiate a new object for save.
1192
-            if (! empty($datetime_data['DTT_ID'])) {
1193
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1194
-                if (! $datetime instanceof EE_Datetime) {
1195
-                    throw new RuntimeException(
1196
-                        sprintf(
1197
-                            esc_html__(
1198
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1199
-                                'event_espresso'
1200
-                            ),
1201
-                            $datetime_data['DTT_ID']
1202
-                        )
1203
-                    );
1204
-                }
1205
-                $datetime->set_date_format($date_formats[0]);
1206
-                $datetime->set_time_format($date_formats[1]);
1207
-                foreach ($datetime_values as $field => $value) {
1208
-                    $datetime->set($field, $value);
1209
-                }
1210
-            } else {
1211
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1212
-            }
1213
-            if (! $datetime instanceof EE_Datetime) {
1214
-                throw new RuntimeException(
1215
-                    sprintf(
1216
-                        esc_html__(
1217
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1218
-                            'event_espresso'
1219
-                        ),
1220
-                        print_r($datetime_values, true)
1221
-                    )
1222
-                );
1223
-            }
1224
-            // before going any further make sure our dates are setup correctly
1225
-            // so that the end date is always equal or greater than the start date.
1226
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1227
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1228
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1229
-            }
1230
-            $datetime->save();
1231
-            $event->_add_relation_to($datetime, 'Datetime');
1232
-        }
1233
-        // no datetimes get deleted so we don't do any of that logic here.
1234
-        // update tickets next
1235
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1236
-
1237
-        // set up some default start and end dates in case those are not present in the incoming data
1238
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1239
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1240
-        // use the start date of the first datetime for the end date
1241
-        $first_datetime   = $event->first_datetime();
1242
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1243
-
1244
-        // now process the incoming data
1245
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1246
-            $update_prices = false;
1247
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1248
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1249
-                : 0;
1250
-            // trim inputs to ensure any excess whitespace is removed.
1251
-            $ticket_data   = array_map('trim', $ticket_data);
1252
-            $ticket_values = [
1253
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1254
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1255
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1256
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1257
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1258
-                    ? $ticket_data['TKT_start_date']
1259
-                    : $default_start_date,
1260
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1261
-                    ? $ticket_data['TKT_end_date']
1262
-                    : $default_end_date,
1263
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1264
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1265
-                    ? $ticket_data['TKT_qty']
1266
-                    : EE_INF,
1267
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1268
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1269
-                    ? $ticket_data['TKT_uses']
1270
-                    : EE_INF,
1271
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1272
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1273
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1274
-                'TKT_price'       => $ticket_price,
1275
-                'TKT_row'         => $row,
1276
-            ];
1277
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1278
-            // which means in turn that the prices will become new prices as well.
1279
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1280
-                $ticket_values['TKT_ID']         = 0;
1281
-                $ticket_values['TKT_is_default'] = 0;
1282
-                $update_prices                   = true;
1283
-            }
1284
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1285
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1286
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1287
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1288
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1289
-            if (! empty($ticket_data['TKT_ID'])) {
1290
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1291
-                if (! $existing_ticket instanceof EE_Ticket) {
1292
-                    throw new RuntimeException(
1293
-                        sprintf(
1294
-                            esc_html__(
1295
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1296
-                                'event_espresso'
1297
-                            ),
1298
-                            $ticket_data['TKT_ID']
1299
-                        )
1300
-                    );
1301
-                }
1302
-                $ticket_sold = $existing_ticket->count_related(
1303
-                    'Registration',
1304
-                    [
1305
-                        [
1306
-                            'STS_ID' => [
1307
-                                'NOT IN',
1308
-                                [EEM_Registration::status_id_incomplete],
1309
-                            ],
1310
-                        ],
1311
-                    ]
1312
-                ) > 0;
1313
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1314
-                // if they are different then we create a new ticket (if $ticket_sold)
1315
-                // if they aren't different then we go ahead and modify existing ticket.
1316
-                $create_new_ticket = $ticket_sold
1317
-                                     && $ticket_price !== $existing_ticket->price()
1318
-                                     && ! $existing_ticket->deleted();
1319
-                $existing_ticket->set_date_format($date_formats[0]);
1320
-                $existing_ticket->set_time_format($date_formats[1]);
1321
-                // set new values
1322
-                foreach ($ticket_values as $field => $value) {
1323
-                    if ($field == 'TKT_qty') {
1324
-                        $existing_ticket->set_qty($value);
1325
-                    } elseif ($field == 'TKT_price') {
1326
-                        $existing_ticket->set('TKT_price', $ticket_price);
1327
-                    } else {
1328
-                        $existing_ticket->set($field, $value);
1329
-                    }
1330
-                }
1331
-                $ticket = $existing_ticket;
1332
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1333
-                //  Otherwise we have to create a new ticket.
1334
-                if ($create_new_ticket) {
1335
-                    // archive the old ticket first
1336
-                    $existing_ticket->set('TKT_deleted', 1);
1337
-                    $existing_ticket->save();
1338
-                    // make sure this ticket is still recorded in our $saved_tickets
1339
-                    // so we don't run it through the regular trash routine.
1340
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1341
-                    // create new ticket that's a copy of the existing except,
1342
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1343
-                    $new_ticket = clone $existing_ticket;
1344
-                    $new_ticket->set('TKT_ID', 0);
1345
-                    $new_ticket->set('TKT_deleted', 0);
1346
-                    $new_ticket->set('TKT_sold', 0);
1347
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1348
-                    $update_prices = true;
1349
-                    $ticket        = $new_ticket;
1350
-                }
1351
-            } else {
1352
-                // no TKT_id so a new ticket
1353
-                $ticket_values['TKT_price'] = $ticket_price;
1354
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1355
-                $update_prices              = true;
1356
-            }
1357
-            if (! $ticket instanceof EE_Ticket) {
1358
-                throw new RuntimeException(
1359
-                    sprintf(
1360
-                        esc_html__(
1361
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1362
-                            'event_espresso'
1363
-                        ),
1364
-                        print_r($ticket_values, true)
1365
-                    )
1366
-                );
1367
-            }
1368
-            // cap ticket qty by datetime reg limits
1369
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1370
-            // update ticket.
1371
-            $ticket->save();
1372
-            // before going any further make sure our dates are setup correctly
1373
-            // so that the end date is always equal or greater than the start date.
1374
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1375
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1376
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1377
-                $ticket->save();
1378
-            }
1379
-            // initially let's add the ticket to the datetime
1380
-            $datetime->_add_relation_to($ticket, 'Ticket');
1381
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1382
-            // add prices to ticket
1383
-            $prices_data = (
1384
-                isset($data['edit_prices'][ $row ])
1385
-                && is_array($data['edit_prices'][ $row ])
1386
-            ) ? $data['edit_prices'][ $row ] : [];
1387
-            $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1388
-        }
1389
-        // however now we need to handle permanently deleting tickets via the ui.
1390
-        //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1391
-        //  However, it does allow for deleting tickets that have no tickets sold,
1392
-        // in which case we want to get rid of permanently because there is no need to save in db.
1393
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets;
1394
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1395
-        foreach ($tickets_removed as $id) {
1396
-            $id = absint($id);
1397
-            // get the ticket for this id
1398
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1399
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1400
-                continue;
1401
-            }
1402
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1403
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1404
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1405
-            foreach ($related_datetimes as $related_datetime) {
1406
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1407
-            }
1408
-            // need to do the same for prices (except these prices can also be deleted because again,
1409
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1410
-            $ticket_to_remove->delete_related_permanently('Price');
1411
-            // finally let's delete this ticket
1412
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1413
-            $ticket_to_remove->delete_permanently();
1414
-        }
1415
-        return [$datetime, $saved_tickets];
1416
-    }
1417
-
1418
-
1419
-    /**
1420
-     * This attaches a list of given prices to a ticket.
1421
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1422
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1423
-     * price info and prices are automatically "archived" via the ticket.
1424
-     *
1425
-     * @access  private
1426
-     * @param array     $prices_data Array of prices from the form.
1427
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1428
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1429
-     * @return  void
1430
-     * @throws EE_Error
1431
-     * @throws ReflectionException
1432
-     */
1433
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1434
-    {
1435
-        $timezone = $ticket->get_timezone();
1436
-        foreach ($prices_data as $row => $price_data) {
1437
-            $price_values = [
1438
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1439
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1440
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1441
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1442
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1443
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1444
-                'PRC_order'      => $row,
1445
-            ];
1446
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1447
-                $price_values['PRC_ID'] = 0;
1448
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1449
-            } else {
1450
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1451
-                // update this price with new values
1452
-                foreach ($price_values as $field => $new_price) {
1453
-                    $price->set($field, $new_price);
1454
-                }
1455
-            }
1456
-            if (! $price instanceof EE_Price) {
1457
-                throw new RuntimeException(
1458
-                    sprintf(
1459
-                        esc_html__(
1460
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1461
-                            'event_espresso'
1462
-                        ),
1463
-                        print_r($price_values, true)
1464
-                    )
1465
-                );
1466
-            }
1467
-            $price->save();
1468
-            $ticket->_add_relation_to($price, 'Price');
1469
-        }
1470
-    }
1471
-
1472
-
1473
-    /**
1474
-     * Add in our autosave ajax handlers
1475
-     *
1476
-     */
1477
-    protected function _ee_autosave_create_new()
1478
-    {
1479
-    }
1480
-
1481
-
1482
-    /**
1483
-     * More autosave handlers.
1484
-     */
1485
-    protected function _ee_autosave_edit()
1486
-    {
1487
-        // TEMPORARILY EXITING CAUSE THIS IS A TODO
1488
-    }
1489
-
1490
-
1491
-    /**
1492
-     * @throws EE_Error
1493
-     * @throws ReflectionException
1494
-     */
1495
-    private function _generate_publish_box_extra_content()
1496
-    {
1497
-        // load formatter helper
1498
-        // args for getting related registrations
1499
-        $approved_query_args        = [
1500
-            [
1501
-                'REG_deleted' => 0,
1502
-                'STS_ID'      => EEM_Registration::status_id_approved,
1503
-            ],
1504
-        ];
1505
-        $not_approved_query_args    = [
1506
-            [
1507
-                'REG_deleted' => 0,
1508
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1509
-            ],
1510
-        ];
1511
-        $pending_payment_query_args = [
1512
-            [
1513
-                'REG_deleted' => 0,
1514
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1515
-            ],
1516
-        ];
1517
-        // publish box
1518
-        $publish_box_extra_args = [
1519
-            'view_approved_reg_url'        => add_query_arg(
1520
-                [
1521
-                    'action'      => 'default',
1522
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1523
-                    '_reg_status' => EEM_Registration::status_id_approved,
1524
-                ],
1525
-                REG_ADMIN_URL
1526
-            ),
1527
-            'view_not_approved_reg_url'    => add_query_arg(
1528
-                [
1529
-                    'action'      => 'default',
1530
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1531
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1532
-                ],
1533
-                REG_ADMIN_URL
1534
-            ),
1535
-            'view_pending_payment_reg_url' => add_query_arg(
1536
-                [
1537
-                    'action'      => 'default',
1538
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1539
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1540
-                ],
1541
-                REG_ADMIN_URL
1542
-            ),
1543
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1544
-                'Registration',
1545
-                $approved_query_args
1546
-            ),
1547
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1548
-                'Registration',
1549
-                $not_approved_query_args
1550
-            ),
1551
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1552
-                'Registration',
1553
-                $pending_payment_query_args
1554
-            ),
1555
-            'misc_pub_section_class'       => apply_filters(
1556
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1557
-                'misc-pub-section'
1558
-            ),
1559
-        ];
1560
-        ob_start();
1561
-        do_action(
1562
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1563
-            $this->_cpt_model_obj
1564
-        );
1565
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1566
-        // load template
1567
-        EEH_Template::display_template(
1568
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1569
-            $publish_box_extra_args
1570
-        );
1571
-    }
1572
-
1573
-
1574
-    /**
1575
-     * @return EE_Event
1576
-     */
1577
-    public function get_event_object()
1578
-    {
1579
-        return $this->_cpt_model_obj;
1580
-    }
1581
-
1582
-
1583
-
1584
-
1585
-    /** METABOXES * */
1586
-    /**
1587
-     * _register_event_editor_meta_boxes
1588
-     * add all metaboxes related to the event_editor
1589
-     *
1590
-     * @return void
1591
-     * @throws EE_Error
1592
-     * @throws ReflectionException
1593
-     */
1594
-    protected function _register_event_editor_meta_boxes()
1595
-    {
1596
-        $this->verify_cpt_object();
1597
-        add_meta_box(
1598
-            'espresso_event_editor_tickets',
1599
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1600
-            [$this, 'ticket_metabox'],
1601
-            $this->page_slug,
1602
-            'normal',
1603
-            'high'
1604
-        );
1605
-        add_meta_box(
1606
-            'espresso_event_editor_event_options',
1607
-            esc_html__('Event Registration Options', 'event_espresso'),
1608
-            [$this, 'registration_options_meta_box'],
1609
-            $this->page_slug,
1610
-            'side'
1611
-        );
1612
-        // NOTE: if you're looking for other metaboxes in here,
1613
-        // where a metabox has a related management page in the admin
1614
-        // you will find it setup in the related management page's "_Hooks" file.
1615
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1616
-    }
1617
-
1618
-
1619
-    /**
1620
-     * @throws DomainException
1621
-     * @throws EE_Error
1622
-     * @throws ReflectionException
1623
-     */
1624
-    public function ticket_metabox()
1625
-    {
1626
-        $existing_datetime_ids = $existing_ticket_ids = [];
1627
-        // defaults for template args
1628
-        $template_args = [
1629
-            'existing_datetime_ids'    => '',
1630
-            'event_datetime_help_link' => '',
1631
-            'ticket_options_help_link' => '',
1632
-            'time'                     => null,
1633
-            'ticket_rows'              => '',
1634
-            'existing_ticket_ids'      => '',
1635
-            'total_ticket_rows'        => 1,
1636
-            'ticket_js_structure'      => '',
1637
-            'trash_icon'               => 'ee-lock-icon',
1638
-            'disabled'                 => '',
1639
-        ];
1640
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1641
-        /**
1642
-         * 1. Start with retrieving Datetimes
1643
-         * 2. Fore each datetime get related tickets
1644
-         * 3. For each ticket get related prices
1645
-         */
1646
-        $times          = EEM_Datetime::instance()->get_all_event_dates($event_id);
1647
-        $first_datetime = reset($times);
1648
-        // do we get related tickets?
1649
-        if (
1650
-            $first_datetime instanceof EE_Datetime
1651
-            && $first_datetime->ID() !== 0
1652
-        ) {
1653
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1654
-            $template_args['time']   = $first_datetime;
1655
-            $related_tickets         = $first_datetime->tickets(
1656
-                [
1657
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1658
-                    'default_where_conditions' => 'none',
1659
-                ]
1660
-            );
1661
-            if (! empty($related_tickets)) {
1662
-                $template_args['total_ticket_rows'] = count($related_tickets);
1663
-                $row                                = 0;
1664
-                foreach ($related_tickets as $ticket) {
1665
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1666
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1667
-                    $row++;
1668
-                }
1669
-            } else {
1670
-                $template_args['total_ticket_rows'] = 1;
1671
-                /** @type EE_Ticket $ticket */
1672
-                $ticket                       = EEM_Ticket::instance()->create_default_object();
1673
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1674
-            }
1675
-        } else {
1676
-            $template_args['time']        = $times[0];
1677
-            $tickets                      = EEM_Ticket::instance()->get_all_default_tickets();
1678
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1679
-            // NOTE: we're just sending the first default row
1680
-            // (decaf can't manage default tickets so this should be sufficient);
1681
-        }
1682
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1683
-            'event_editor_event_datetimes_help_tab'
1684
-        );
1685
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1686
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1687
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1688
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1689
-            EEM_Ticket::instance()->create_default_object(),
1690
-            true
1691
-        );
1692
-        $template                                  = apply_filters(
1693
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1694
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1695
-        );
1696
-        EEH_Template::display_template($template, $template_args);
1697
-    }
1698
-
1699
-
1700
-    /**
1701
-     * Setup an individual ticket form for the decaf event editor page
1702
-     *
1703
-     * @access private
1704
-     * @param EE_Ticket $ticket   the ticket object
1705
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1706
-     * @param int       $row
1707
-     * @return string generated html for the ticket row.
1708
-     * @throws EE_Error
1709
-     * @throws ReflectionException
1710
-     */
1711
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1712
-    {
1713
-        $template_args = [
1714
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1715
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1716
-                : '',
1717
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1718
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1719
-            'TKT_name'            => $ticket->get('TKT_name'),
1720
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1721
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1722
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1723
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1724
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1725
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1726
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1727
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1728
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1729
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1730
-                : ' disabled=disabled',
1731
-        ];
1732
-        $price         = $ticket->ID() !== 0
1733
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1734
-            : null;
1735
-        $price         = $price instanceof EE_Price
1736
-            ? $price
1737
-            : EEM_Price::instance()->create_default_object();
1738
-        $price_args    = [
1739
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1740
-            'PRC_amount'            => $price->get('PRC_amount'),
1741
-            'PRT_ID'                => $price->get('PRT_ID'),
1742
-            'PRC_ID'                => $price->get('PRC_ID'),
1743
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1744
-        ];
1745
-        // make sure we have default start and end dates if skeleton
1746
-        // handle rows that should NOT be empty
1747
-        if (empty($template_args['TKT_start_date'])) {
1748
-            // if empty then the start date will be now.
1749
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1750
-        }
1751
-        if (empty($template_args['TKT_end_date'])) {
1752
-            // get the earliest datetime (if present);
1753
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1754
-                ? $this->_cpt_model_obj->get_first_related(
1755
-                    'Datetime',
1756
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1757
-                )
1758
-                : null;
1759
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1760
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1761
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1762
-        }
1763
-        $template_args = array_merge($template_args, $price_args);
1764
-        $template      = apply_filters(
1765
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1766
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1767
-            $ticket
1768
-        );
1769
-        return EEH_Template::display_template($template, $template_args, true);
1770
-    }
1771
-
1772
-
1773
-    /**
1774
-     * @throws EE_Error
1775
-     * @throws ReflectionException
1776
-     */
1777
-    public function registration_options_meta_box()
1778
-    {
1779
-        $yes_no_values             = [
1780
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1781
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1782
-        ];
1783
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1784
-            [
1785
-                EEM_Registration::status_id_cancelled,
1786
-                EEM_Registration::status_id_declined,
1787
-                EEM_Registration::status_id_incomplete,
1788
-            ],
1789
-            true
1790
-        );
1791
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1792
-        $template_args['_event']                          = $this->_cpt_model_obj;
1793
-        $template_args['event']                           = $this->_cpt_model_obj;
1794
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1795
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1796
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1797
-            'default_reg_status',
1798
-            $default_reg_status_values,
1799
-            $this->_cpt_model_obj->default_registration_status()
1800
-        );
1801
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1802
-            'display_desc',
1803
-            $yes_no_values,
1804
-            $this->_cpt_model_obj->display_description()
1805
-        );
1806
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1807
-            'display_ticket_selector',
1808
-            $yes_no_values,
1809
-            $this->_cpt_model_obj->display_ticket_selector(),
1810
-            '',
1811
-            '',
1812
-            false
1813
-        );
1814
-        $template_args['additional_registration_options'] = apply_filters(
1815
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1816
-            '',
1817
-            $template_args,
1818
-            $yes_no_values,
1819
-            $default_reg_status_values
1820
-        );
1821
-        EEH_Template::display_template(
1822
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1823
-            $template_args
1824
-        );
1825
-    }
1826
-
1827
-
1828
-    /**
1829
-     * _get_events()
1830
-     * This method simply returns all the events (for the given _view and paging)
1831
-     *
1832
-     * @access public
1833
-     * @param int  $per_page     count of items per page (20 default);
1834
-     * @param int  $current_page what is the current page being viewed.
1835
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1836
-     *                           If FALSE then we return an array of event objects
1837
-     *                           that match the given _view and paging parameters.
1838
-     * @return array|int         an array of event objects or a count of them.
1839
-     * @throws Exception
1840
-     */
1841
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1842
-    {
1843
-        $EEM_Event   = $this->_event_model();
1844
-        $offset      = ($current_page - 1) * $per_page;
1845
-        $limit       = $count ? null : $offset . ',' . $per_page;
1846
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1847
-        $order       = $this->request->getRequestParam('order', 'DESC');
1848
-        $month_range = $this->request->getRequestParam('month_range');
1849
-        if ($month_range) {
1850
-            $pieces = explode(' ', $month_range, 3);
1851
-            // simulate the FIRST day of the month, that fixes issues for months like February
1852
-            // where PHP doesn't know what to assume for date.
1853
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1854
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1855
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1856
-        }
1857
-        $where  = [];
1858
-        $status = $this->request->getRequestParam('status');
1859
-        // determine what post_status our condition will have for the query.
1860
-        switch ($status) {
1861
-            case 'month':
1862
-            case 'today':
1863
-            case null:
1864
-            case 'all':
1865
-                break;
1866
-            case 'draft':
1867
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1868
-                break;
1869
-            default:
1870
-                $where['status'] = $status;
1871
-        }
1872
-        // categories? The default for all categories is -1
1873
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1874
-        if ($category !== -1) {
1875
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1876
-            $where['Term_Taxonomy.term_id']  = $category;
1877
-        }
1878
-        // date where conditions
1879
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1880
-        if ($month_range) {
1881
-            $DateTime = new DateTime(
1882
-                $year_r . '-' . $month_r . '-01 00:00:00',
1883
-                new DateTimeZone('UTC')
1884
-            );
1885
-            $start    = $DateTime->getTimestamp();
1886
-            // set the datetime to be the end of the month
1887
-            $DateTime->setDate(
1888
-                $year_r,
1889
-                $month_r,
1890
-                $DateTime->format('t')
1891
-            )->setTime(23, 59, 59);
1892
-            $end                             = $DateTime->getTimestamp();
1893
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1894
-        } elseif ($status === 'today') {
1895
-            $DateTime                        =
1896
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1897
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1898
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1899
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1900
-        } elseif ($status === 'month') {
1901
-            $now                             = date('Y-m-01');
1902
-            $DateTime                        =
1903
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1904
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1905
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1906
-                                                        ->setTime(23, 59, 59)
1907
-                                                        ->format(implode(' ', $start_formats));
1908
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1909
-        }
1910
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1911
-            $where['EVT_wp_user'] = get_current_user_id();
1912
-        } else {
1913
-            if (! isset($where['status'])) {
1914
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1915
-                    $where['OR'] = [
1916
-                        'status*restrict_private' => ['!=', 'private'],
1917
-                        'AND'                     => [
1918
-                            'status*inclusive' => ['=', 'private'],
1919
-                            'EVT_wp_user'      => get_current_user_id(),
1920
-                        ],
1921
-                    ];
1922
-                }
1923
-            }
1924
-        }
1925
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1926
-        if (
1927
-            $wp_user
1928
-            && $wp_user !== get_current_user_id()
1929
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1930
-        ) {
1931
-            $where['EVT_wp_user'] = $wp_user;
1932
-        }
1933
-        // search query handling
1934
-        $search_term = $this->request->getRequestParam('s');
1935
-        if ($search_term) {
1936
-            $search_term = '%' . $search_term . '%';
1937
-            $where['OR'] = [
1938
-                'EVT_name'       => ['LIKE', $search_term],
1939
-                'EVT_desc'       => ['LIKE', $search_term],
1940
-                'EVT_short_desc' => ['LIKE', $search_term],
1941
-            ];
1942
-        }
1943
-        // filter events by venue.
1944
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
1945
-        if ($venue) {
1946
-            $where['Venue.VNU_ID'] = $venue;
1947
-        }
1948
-        $request_params = $this->request->requestParams();
1949
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
1950
-        $query_params   = apply_filters(
1951
-            'FHEE__Events_Admin_Page__get_events__query_params',
1952
-            [
1953
-                $where,
1954
-                'limit'    => $limit,
1955
-                'order_by' => $orderby,
1956
-                'order'    => $order,
1957
-                'group_by' => 'EVT_ID',
1958
-            ],
1959
-            $request_params
1960
-        );
1961
-
1962
-        // let's first check if we have special requests coming in.
1963
-        $active_status = $this->request->getRequestParam('active_status');
1964
-        if ($active_status) {
1965
-            switch ($active_status) {
1966
-                case 'upcoming':
1967
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
1968
-                case 'expired':
1969
-                    return $EEM_Event->get_expired_events($query_params, $count);
1970
-                case 'active':
1971
-                    return $EEM_Event->get_active_events($query_params, $count);
1972
-                case 'inactive':
1973
-                    return $EEM_Event->get_inactive_events($query_params, $count);
1974
-            }
1975
-        }
1976
-
1977
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
1978
-    }
1979
-
1980
-
1981
-    /**
1982
-     * handling for WordPress CPT actions (trash, restore, delete)
1983
-     *
1984
-     * @param string $post_id
1985
-     * @throws EE_Error
1986
-     * @throws ReflectionException
1987
-     */
1988
-    public function trash_cpt_item($post_id)
1989
-    {
1990
-        $this->request->setRequestParam('EVT_ID', $post_id);
1991
-        $this->_trash_or_restore_event('trash', false);
1992
-    }
1993
-
1994
-
1995
-    /**
1996
-     * @param string $post_id
1997
-     * @throws EE_Error
1998
-     * @throws ReflectionException
1999
-     */
2000
-    public function restore_cpt_item($post_id)
2001
-    {
2002
-        $this->request->setRequestParam('EVT_ID', $post_id);
2003
-        $this->_trash_or_restore_event('draft', false);
2004
-    }
2005
-
2006
-
2007
-    /**
2008
-     * @param string $post_id
2009
-     * @throws EE_Error
2010
-     * @throws EE_Error
2011
-     */
2012
-    public function delete_cpt_item($post_id)
2013
-    {
2014
-        throw new EE_Error(
2015
-            esc_html__(
2016
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2017
-                'event_espresso'
2018
-            )
2019
-        );
2020
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2021
-        // $this->_delete_event();
2022
-    }
2023
-
2024
-
2025
-    /**
2026
-     * _trash_or_restore_event
2027
-     *
2028
-     * @access protected
2029
-     * @param string $event_status
2030
-     * @param bool   $redirect_after
2031
-     * @throws EE_Error
2032
-     * @throws EE_Error
2033
-     * @throws ReflectionException
2034
-     */
2035
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2036
-    {
2037
-        // determine the event id and set to array.
2038
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2039
-        // loop thru events
2040
-        if ($EVT_ID) {
2041
-            // clean status
2042
-            $event_status = sanitize_key($event_status);
2043
-            // grab status
2044
-            if (! empty($event_status)) {
2045
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2046
-            } else {
2047
-                $success = false;
2048
-                $msg     = esc_html__(
2049
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2050
-                    'event_espresso'
2051
-                );
2052
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2053
-            }
2054
-        } else {
2055
-            $success = false;
2056
-            $msg     = esc_html__(
2057
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2058
-                'event_espresso'
2059
-            );
2060
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2061
-        }
2062
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2063
-        if ($redirect_after) {
2064
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2065
-        }
2066
-    }
2067
-
2068
-
2069
-    /**
2070
-     * _trash_or_restore_events
2071
-     *
2072
-     * @access protected
2073
-     * @param string $event_status
2074
-     * @return void
2075
-     * @throws EE_Error
2076
-     * @throws EE_Error
2077
-     * @throws ReflectionException
2078
-     */
2079
-    protected function _trash_or_restore_events($event_status = 'trash')
2080
-    {
2081
-        // clean status
2082
-        $event_status = sanitize_key($event_status);
2083
-        // grab status
2084
-        if (! empty($event_status)) {
2085
-            $success = true;
2086
-            // determine the event id and set to array.
2087
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2088
-            // loop thru events
2089
-            foreach ($EVT_IDs as $EVT_ID) {
2090
-                if ($EVT_ID = absint($EVT_ID)) {
2091
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2092
-                    $success = $results !== false ? $success : false;
2093
-                } else {
2094
-                    $msg = sprintf(
2095
-                        esc_html__(
2096
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2097
-                            'event_espresso'
2098
-                        ),
2099
-                        $EVT_ID
2100
-                    );
2101
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2102
-                    $success = false;
2103
-                }
2104
-            }
2105
-        } else {
2106
-            $success = false;
2107
-            $msg     = esc_html__(
2108
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2109
-                'event_espresso'
2110
-            );
2111
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2112
-        }
2113
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2114
-        $success = $success ? 2 : false;
2115
-        $action  = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2116
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2117
-    }
2118
-
2119
-
2120
-    /**
2121
-     * @param int    $EVT_ID
2122
-     * @param string $event_status
2123
-     * @return bool
2124
-     * @throws EE_Error
2125
-     * @throws ReflectionException
2126
-     */
2127
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2128
-    {
2129
-        // grab event id
2130
-        if (! $EVT_ID) {
2131
-            $msg = esc_html__(
2132
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2133
-                'event_espresso'
2134
-            );
2135
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2136
-            return false;
2137
-        }
2138
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2139
-        // clean status
2140
-        $event_status = sanitize_key($event_status);
2141
-        // grab status
2142
-        if (empty($event_status)) {
2143
-            $msg = esc_html__(
2144
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2145
-                'event_espresso'
2146
-            );
2147
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2148
-            return false;
2149
-        }
2150
-        // was event trashed or restored ?
2151
-        switch ($event_status) {
2152
-            case 'draft':
2153
-                $action = 'restored from the trash';
2154
-                $hook   = 'AHEE_event_restored_from_trash';
2155
-                break;
2156
-            case 'trash':
2157
-                $action = 'moved to the trash';
2158
-                $hook   = 'AHEE_event_moved_to_trash';
2159
-                break;
2160
-            default:
2161
-                $action = 'updated';
2162
-                $hook   = false;
2163
-        }
2164
-        // use class to change status
2165
-        $this->_cpt_model_obj->set_status($event_status);
2166
-        $success = $this->_cpt_model_obj->save();
2167
-        if (! $success) {
2168
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2169
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2170
-            return false;
2171
-        }
2172
-        if ($hook) {
2173
-            do_action($hook);
2174
-        }
2175
-        return true;
2176
-    }
2177
-
2178
-
2179
-    /**
2180
-     * @param array $event_ids
2181
-     * @return array
2182
-     * @since   4.10.23.p
2183
-     */
2184
-    private function cleanEventIds(array $event_ids)
2185
-    {
2186
-        return array_map('absint', $event_ids);
2187
-    }
2188
-
2189
-
2190
-    /**
2191
-     * @return array
2192
-     * @since   4.10.23.p
2193
-     */
2194
-    private function getEventIdsFromRequest()
2195
-    {
2196
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2197
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2198
-        } else {
2199
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2200
-        }
2201
-    }
2202
-
2203
-
2204
-    /**
2205
-     * @param bool $preview_delete
2206
-     * @throws EE_Error
2207
-     */
2208
-    protected function _delete_event($preview_delete = true)
2209
-    {
2210
-        $this->_delete_events($preview_delete);
2211
-    }
2212
-
2213
-
2214
-    /**
2215
-     * Gets the tree traversal batch persister.
2216
-     *
2217
-     * @return NodeGroupDao
2218
-     * @throws InvalidArgumentException
2219
-     * @throws InvalidDataTypeException
2220
-     * @throws InvalidInterfaceException
2221
-     * @since 4.10.12.p
2222
-     */
2223
-    protected function getModelObjNodeGroupPersister()
2224
-    {
2225
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2226
-            $this->model_obj_node_group_persister =
2227
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2228
-        }
2229
-        return $this->model_obj_node_group_persister;
2230
-    }
2231
-
2232
-
2233
-    /**
2234
-     * @param bool $preview_delete
2235
-     * @return void
2236
-     * @throws EE_Error
2237
-     */
2238
-    protected function _delete_events($preview_delete = true)
2239
-    {
2240
-        $event_ids = $this->getEventIdsFromRequest();
2241
-        if ($preview_delete) {
2242
-            $this->generateDeletionPreview($event_ids);
2243
-        } else {
2244
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2245
-        }
2246
-    }
2247
-
2248
-
2249
-    /**
2250
-     * @param array $event_ids
2251
-     */
2252
-    protected function generateDeletionPreview(array $event_ids)
2253
-    {
2254
-        $event_ids = $this->cleanEventIds($event_ids);
2255
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2256
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2257
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2258
-            [
2259
-                'action'            => 'preview_deletion',
2260
-                'deletion_job_code' => $deletion_job_code,
2261
-            ],
2262
-            $this->_admin_base_url
2263
-        );
2264
-        EEH_URL::safeRedirectAndExit(
2265
-            EE_Admin_Page::add_query_args_and_nonce(
2266
-                [
2267
-                    'page'              => 'espresso_batch',
2268
-                    'batch'             => EED_Batch::batch_job,
2269
-                    'EVT_IDs'           => $event_ids,
2270
-                    'deletion_job_code' => $deletion_job_code,
2271
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2272
-                    'return_url'        => urlencode($return_url),
2273
-                ],
2274
-                admin_url()
2275
-            )
2276
-        );
2277
-    }
2278
-
2279
-
2280
-    /**
2281
-     * Checks for a POST submission
2282
-     *
2283
-     * @since 4.10.12.p
2284
-     */
2285
-    protected function confirmDeletion()
2286
-    {
2287
-        $deletion_redirect_logic =
2288
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2289
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2290
-    }
2291
-
2292
-
2293
-    /**
2294
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2295
-     *
2296
-     * @throws EE_Error
2297
-     * @since 4.10.12.p
2298
-     */
2299
-    protected function previewDeletion()
2300
-    {
2301
-        $preview_deletion_logic =
2302
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2303
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2304
-        $this->display_admin_page_with_no_sidebar();
2305
-    }
2306
-
2307
-
2308
-    /**
2309
-     * get total number of events
2310
-     *
2311
-     * @access public
2312
-     * @return int
2313
-     * @throws EE_Error
2314
-     * @throws EE_Error
2315
-     */
2316
-    public function total_events()
2317
-    {
2318
-        return EEM_Event::instance()->count(
2319
-            ['caps' => 'read_admin'],
2320
-            'EVT_ID',
2321
-            true
2322
-        );
2323
-    }
2324
-
2325
-
2326
-    /**
2327
-     * get total number of draft events
2328
-     *
2329
-     * @access public
2330
-     * @return int
2331
-     * @throws EE_Error
2332
-     * @throws EE_Error
2333
-     */
2334
-    public function total_events_draft()
2335
-    {
2336
-        return EEM_Event::instance()->count(
2337
-            [
2338
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2339
-                'caps' => 'read_admin',
2340
-            ],
2341
-            'EVT_ID',
2342
-            true
2343
-        );
2344
-    }
2345
-
2346
-
2347
-    /**
2348
-     * get total number of trashed events
2349
-     *
2350
-     * @access public
2351
-     * @return int
2352
-     * @throws EE_Error
2353
-     * @throws EE_Error
2354
-     */
2355
-    public function total_trashed_events()
2356
-    {
2357
-        return EEM_Event::instance()->count(
2358
-            [
2359
-                ['status' => 'trash'],
2360
-                'caps' => 'read_admin',
2361
-            ],
2362
-            'EVT_ID',
2363
-            true
2364
-        );
2365
-    }
2366
-
2367
-
2368
-    /**
2369
-     *    _default_event_settings
2370
-     *    This generates the Default Settings Tab
2371
-     *
2372
-     * @return void
2373
-     * @throws EE_Error
2374
-     */
2375
-    protected function _default_event_settings()
2376
-    {
2377
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2378
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2379
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2380
-        $this->display_admin_page_with_sidebar();
2381
-    }
2382
-
2383
-
2384
-    /**
2385
-     * Return the form for event settings.
2386
-     *
2387
-     * @return EE_Form_Section_Proper
2388
-     * @throws EE_Error
2389
-     */
2390
-    protected function _default_event_settings_form()
2391
-    {
2392
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2393
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2394
-        // exclude
2395
-            [
2396
-                EEM_Registration::status_id_cancelled,
2397
-                EEM_Registration::status_id_declined,
2398
-                EEM_Registration::status_id_incomplete,
2399
-                EEM_Registration::status_id_wait_list,
2400
-            ],
2401
-            true
2402
-        );
2403
-        return new EE_Form_Section_Proper(
2404
-            [
2405
-                'name'            => 'update_default_event_settings',
2406
-                'html_id'         => 'update_default_event_settings',
2407
-                'html_class'      => 'form-table',
2408
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2409
-                'subsections'     => apply_filters(
2410
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2411
-                    [
2412
-                        'default_reg_status'  => new EE_Select_Input(
2413
-                            $registration_stati_for_selection,
2414
-                            [
2415
-                                'default'         => isset($registration_config->default_STS_ID)
2416
-                                                     && array_key_exists(
2417
-                                                         $registration_config->default_STS_ID,
2418
-                                                         $registration_stati_for_selection
2419
-                                                     )
2420
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2421
-                                    : EEM_Registration::status_id_pending_payment,
2422
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2423
-                                                     . EEH_Template::get_help_tab_link(
2424
-                                                         'default_settings_status_help_tab'
2425
-                                                     ),
2426
-                                'html_help_text'  => esc_html__(
2427
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2428
-                                    'event_espresso'
2429
-                                ),
2430
-                            ]
2431
-                        ),
2432
-                        'default_max_tickets' => new EE_Integer_Input(
2433
-                            [
2434
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2435
-                                    ? $registration_config->default_maximum_number_of_tickets
2436
-                                    : EEM_Event::get_default_additional_limit(),
2437
-                                'html_label_text' => esc_html__(
2438
-                                    'Default Maximum Tickets Allowed Per Order:',
2439
-                                    'event_espresso'
2440
-                                )
2441
-                                . EEH_Template::get_help_tab_link(
2442
-                                    'default_maximum_tickets_help_tab"'
2443
-                                ),
2444
-                                'html_help_text'  => esc_html__(
2445
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2446
-                                    'event_espresso'
2447
-                                ),
2448
-                            ]
2449
-                        ),
2450
-                    ]
2451
-                ),
2452
-            ]
2453
-        );
2454
-    }
2455
-
2456
-
2457
-    /**
2458
-     * _update_default_event_settings
2459
-     *
2460
-     * @access protected
2461
-     * @return void
2462
-     * @throws EE_Error
2463
-     */
2464
-    protected function _update_default_event_settings()
2465
-    {
2466
-        $registration_config = EE_Registry::instance()->CFG->registration;
2467
-        $form                = $this->_default_event_settings_form();
2468
-        if ($form->was_submitted()) {
2469
-            $form->receive_form_submission();
2470
-            if ($form->is_valid()) {
2471
-                $valid_data = $form->valid_data();
2472
-                if (isset($valid_data['default_reg_status'])) {
2473
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2474
-                }
2475
-                if (isset($valid_data['default_max_tickets'])) {
2476
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2477
-                }
2478
-                // update because data was valid!
2479
-                EE_Registry::instance()->CFG->update_espresso_config();
2480
-                EE_Error::overwrite_success();
2481
-                EE_Error::add_success(
2482
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2483
-                );
2484
-            }
2485
-        }
2486
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2487
-    }
2488
-
2489
-
2490
-    /*************        Templates        *************
2491
-     *
2492
-     * @throws EE_Error
2493
-     */
2494
-    protected function _template_settings()
2495
-    {
2496
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2497
-        $this->_template_args['preview_img']  = '<img src="'
2498
-                                                . EVENTS_ASSETS_URL
2499
-                                                . '/images/'
2500
-                                                . 'caffeinated_template_features.jpg" alt="'
2501
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2502
-                                                . '" />';
2503
-        $this->_template_args['preview_text'] = '<strong>'
2504
-                                                . esc_html__(
2505
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2506
-                                                    'event_espresso'
2507
-                                                ) . '</strong>';
2508
-        $this->display_admin_caf_preview_page('template_settings_tab');
2509
-    }
2510
-
2511
-
2512
-    /** Event Category Stuff **/
2513
-    /**
2514
-     * set the _category property with the category object for the loaded page.
2515
-     *
2516
-     * @access private
2517
-     * @return void
2518
-     */
2519
-    private function _set_category_object()
2520
-    {
2521
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2522
-            return;
2523
-        } //already have the category object so get out.
2524
-        // set default category object
2525
-        $this->_set_empty_category_object();
2526
-        // only set if we've got an id
2527
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2528
-        if (! $category_ID) {
2529
-            return;
2530
-        }
2531
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2532
-        if (! empty($term)) {
2533
-            $this->_category->category_name       = $term->name;
2534
-            $this->_category->category_identifier = $term->slug;
2535
-            $this->_category->category_desc       = $term->description;
2536
-            $this->_category->id                  = $term->term_id;
2537
-            $this->_category->parent              = $term->parent;
2538
-        }
2539
-    }
2540
-
2541
-
2542
-    /**
2543
-     * Clears out category properties.
2544
-     */
2545
-    private function _set_empty_category_object()
2546
-    {
2547
-        $this->_category                = new stdClass();
2548
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2549
-        $this->_category->id            = $this->_category->parent = 0;
2550
-    }
2551
-
2552
-
2553
-    /**
2554
-     * @throws EE_Error
2555
-     */
2556
-    protected function _category_list_table()
2557
-    {
2558
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2559
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2560
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2561
-            'add_category',
2562
-            'add_category',
2563
-            [],
2564
-            'add-new-h2'
2565
-        );
2566
-        $this->display_admin_list_table_page_with_sidebar();
2567
-    }
2568
-
2569
-
2570
-    /**
2571
-     * Output category details view.
2572
-     *
2573
-     * @throws EE_Error
2574
-     * @throws EE_Error
2575
-     */
2576
-    protected function _category_details($view)
2577
-    {
2578
-        // load formatter helper
2579
-        // load field generator helper
2580
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2581
-        $this->_set_add_edit_form_tags($route);
2582
-        $this->_set_category_object();
2583
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2584
-        $delete_action = 'delete_category';
2585
-        // custom redirect
2586
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2587
-            ['action' => 'category_list'],
2588
-            $this->_admin_base_url
2589
-        );
2590
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2591
-        // take care of contents
2592
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2593
-        $this->display_admin_page_with_sidebar();
2594
-    }
2595
-
2596
-
2597
-    /**
2598
-     * Output category details content.
2599
-     */
2600
-    protected function _category_details_content()
2601
-    {
2602
-        $editor_args['category_desc'] = [
2603
-            'type'          => 'wp_editor',
2604
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2605
-            'class'         => 'my_editor_custom',
2606
-            'wpeditor_args' => ['media_buttons' => false],
2607
-        ];
2608
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2609
-        $all_terms                    = get_terms(
2610
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2611
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2612
-        );
2613
-        // setup category select for term parents.
2614
-        $category_select_values[] = [
2615
-            'text' => esc_html__('No Parent', 'event_espresso'),
2616
-            'id'   => 0,
2617
-        ];
2618
-        foreach ($all_terms as $term) {
2619
-            $category_select_values[] = [
2620
-                'text' => $term->name,
2621
-                'id'   => $term->term_id,
2622
-            ];
2623
-        }
2624
-        $category_select = EEH_Form_Fields::select_input(
2625
-            'category_parent',
2626
-            $category_select_values,
2627
-            $this->_category->parent
2628
-        );
2629
-        $template_args   = [
2630
-            'category'                 => $this->_category,
2631
-            'category_select'          => $category_select,
2632
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2633
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2634
-            'disable'                  => '',
2635
-            'disabled_message'         => false,
2636
-        ];
2637
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2638
-        return EEH_Template::display_template($template, $template_args, true);
2639
-    }
2640
-
2641
-
2642
-    /**
2643
-     * Handles deleting categories.
2644
-     *
2645
-     * @throws EE_Error
2646
-     */
2647
-    protected function _delete_categories()
2648
-    {
2649
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2650
-        foreach ($category_IDs as $category_ID) {
2651
-            $this->_delete_category($category_ID);
2652
-        }
2653
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2654
-        $query_args = [
2655
-            'action' => 'category_list',
2656
-        ];
2657
-        $this->_redirect_after_action(0, '', '', $query_args);
2658
-    }
2659
-
2660
-
2661
-    /**
2662
-     * Handles deleting specific category.
2663
-     *
2664
-     * @param int $cat_id
2665
-     */
2666
-    protected function _delete_category($cat_id)
2667
-    {
2668
-        $cat_id = absint($cat_id);
2669
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2670
-    }
2671
-
2672
-
2673
-    /**
2674
-     * Handles triggering the update or insertion of a new category.
2675
-     *
2676
-     * @param bool $new_category true means we're triggering the insert of a new category.
2677
-     * @throws EE_Error
2678
-     * @throws EE_Error
2679
-     */
2680
-    protected function _insert_or_update_category($new_category)
2681
-    {
2682
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2683
-        $success = 0; // we already have a success message so lets not send another.
2684
-        if ($cat_id) {
2685
-            $query_args = [
2686
-                'action'     => 'edit_category',
2687
-                'EVT_CAT_ID' => $cat_id,
2688
-            ];
2689
-        } else {
2690
-            $query_args = ['action' => 'add_category'];
2691
-        }
2692
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2693
-    }
2694
-
2695
-
2696
-    /**
2697
-     * Inserts or updates category
2698
-     *
2699
-     * @param bool $update (true indicates we're updating a category).
2700
-     * @return bool|mixed|string
2701
-     */
2702
-    private function _insert_category($update = false)
2703
-    {
2704
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2705
-        $category_name       = $this->request->getRequestParam('category_name', '');
2706
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2707
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2708
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2709
-
2710
-        if (empty($category_name)) {
2711
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2712
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2713
-            return false;
2714
-        }
2715
-        $term_args = [
2716
-            'name'        => $category_name,
2717
-            'description' => $category_desc,
2718
-            'parent'      => $category_parent,
2719
-        ];
2720
-        // was the category_identifier input disabled?
2721
-        if ($category_identifier) {
2722
-            $term_args['slug'] = $category_identifier;
2723
-        }
2724
-        $insert_ids = $update
2725
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2726
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2727
-        if (! is_array($insert_ids)) {
2728
-            $msg = esc_html__(
2729
-                'An error occurred and the category has not been saved to the database.',
2730
-                'event_espresso'
2731
-            );
2732
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2733
-        } else {
2734
-            $category_ID = $insert_ids['term_id'];
2735
-            $msg         =
2736
-                sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2737
-            EE_Error::add_success($msg);
2738
-        }
2739
-        return $category_ID;
2740
-    }
2741
-
2742
-
2743
-    /**
2744
-     * Gets categories or count of categories matching the arguments in the request.
2745
-     *
2746
-     * @param int  $per_page
2747
-     * @param int  $current_page
2748
-     * @param bool $count
2749
-     * @return EE_Term_Taxonomy[]|int
2750
-     * @throws EE_Error
2751
-     * @throws EE_Error
2752
-     */
2753
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2754
-    {
2755
-        // testing term stuff
2756
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2757
-        $order       = $this->request->getRequestParam('order', 'DESC');
2758
-        $limit       = ($current_page - 1) * $per_page;
2759
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2760
-        $search_term = $this->request->getRequestParam('s');
2761
-        if ($search_term) {
2762
-            $search_term = '%' . $search_term . '%';
2763
-            $where['OR'] = [
2764
-                'Term.name'   => ['LIKE', $search_term],
2765
-                'description' => ['LIKE', $search_term],
2766
-            ];
2767
-        }
2768
-        $query_params = [
2769
-            $where,
2770
-            'order_by'   => [$orderby => $order],
2771
-            'limit'      => $limit . ',' . $per_page,
2772
-            'force_join' => ['Term'],
2773
-        ];
2774
-        return $count
2775
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2776
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2777
-    }
2778
-
2779
-    /* end category stuff */
2780
-    /**************/
2781
-
2782
-
2783
-    /**
2784
-     * Callback for the `ee_save_timezone_setting` ajax action.
2785
-     *
2786
-     * @throws EE_Error
2787
-     */
2788
-    public function saveTimezoneString()
2789
-    {
2790
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2791
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2792
-            EE_Error::add_error(
2793
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2794
-                __FILE__,
2795
-                __FUNCTION__,
2796
-                __LINE__
2797
-            );
2798
-            $this->_template_args['error'] = true;
2799
-            $this->_return_json();
2800
-        }
2801
-
2802
-        update_option('timezone_string', $timezone_string);
2803
-        EE_Error::add_success(
2804
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2805
-        );
2806
-        $this->_template_args['success'] = true;
2807
-        $this->_return_json(true, ['action' => 'create_new']);
2808
-    }
2809
-
2810
-
2811
-    /**
2812 2492
      * @throws EE_Error
2813
-     * @deprecated 4.10.25.p
2814 2493
      */
2815
-    public function save_timezonestring_setting()
2816
-    {
2817
-        $this->saveTimezoneString();
2818
-    }
2494
+	protected function _template_settings()
2495
+	{
2496
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2497
+		$this->_template_args['preview_img']  = '<img src="'
2498
+												. EVENTS_ASSETS_URL
2499
+												. '/images/'
2500
+												. 'caffeinated_template_features.jpg" alt="'
2501
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2502
+												. '" />';
2503
+		$this->_template_args['preview_text'] = '<strong>'
2504
+												. esc_html__(
2505
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2506
+													'event_espresso'
2507
+												) . '</strong>';
2508
+		$this->display_admin_caf_preview_page('template_settings_tab');
2509
+	}
2510
+
2511
+
2512
+	/** Event Category Stuff **/
2513
+	/**
2514
+	 * set the _category property with the category object for the loaded page.
2515
+	 *
2516
+	 * @access private
2517
+	 * @return void
2518
+	 */
2519
+	private function _set_category_object()
2520
+	{
2521
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2522
+			return;
2523
+		} //already have the category object so get out.
2524
+		// set default category object
2525
+		$this->_set_empty_category_object();
2526
+		// only set if we've got an id
2527
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2528
+		if (! $category_ID) {
2529
+			return;
2530
+		}
2531
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2532
+		if (! empty($term)) {
2533
+			$this->_category->category_name       = $term->name;
2534
+			$this->_category->category_identifier = $term->slug;
2535
+			$this->_category->category_desc       = $term->description;
2536
+			$this->_category->id                  = $term->term_id;
2537
+			$this->_category->parent              = $term->parent;
2538
+		}
2539
+	}
2540
+
2541
+
2542
+	/**
2543
+	 * Clears out category properties.
2544
+	 */
2545
+	private function _set_empty_category_object()
2546
+	{
2547
+		$this->_category                = new stdClass();
2548
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2549
+		$this->_category->id            = $this->_category->parent = 0;
2550
+	}
2551
+
2552
+
2553
+	/**
2554
+	 * @throws EE_Error
2555
+	 */
2556
+	protected function _category_list_table()
2557
+	{
2558
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2559
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2560
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2561
+			'add_category',
2562
+			'add_category',
2563
+			[],
2564
+			'add-new-h2'
2565
+		);
2566
+		$this->display_admin_list_table_page_with_sidebar();
2567
+	}
2568
+
2569
+
2570
+	/**
2571
+	 * Output category details view.
2572
+	 *
2573
+	 * @throws EE_Error
2574
+	 * @throws EE_Error
2575
+	 */
2576
+	protected function _category_details($view)
2577
+	{
2578
+		// load formatter helper
2579
+		// load field generator helper
2580
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2581
+		$this->_set_add_edit_form_tags($route);
2582
+		$this->_set_category_object();
2583
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2584
+		$delete_action = 'delete_category';
2585
+		// custom redirect
2586
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2587
+			['action' => 'category_list'],
2588
+			$this->_admin_base_url
2589
+		);
2590
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2591
+		// take care of contents
2592
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2593
+		$this->display_admin_page_with_sidebar();
2594
+	}
2595
+
2596
+
2597
+	/**
2598
+	 * Output category details content.
2599
+	 */
2600
+	protected function _category_details_content()
2601
+	{
2602
+		$editor_args['category_desc'] = [
2603
+			'type'          => 'wp_editor',
2604
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2605
+			'class'         => 'my_editor_custom',
2606
+			'wpeditor_args' => ['media_buttons' => false],
2607
+		];
2608
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2609
+		$all_terms                    = get_terms(
2610
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2611
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2612
+		);
2613
+		// setup category select for term parents.
2614
+		$category_select_values[] = [
2615
+			'text' => esc_html__('No Parent', 'event_espresso'),
2616
+			'id'   => 0,
2617
+		];
2618
+		foreach ($all_terms as $term) {
2619
+			$category_select_values[] = [
2620
+				'text' => $term->name,
2621
+				'id'   => $term->term_id,
2622
+			];
2623
+		}
2624
+		$category_select = EEH_Form_Fields::select_input(
2625
+			'category_parent',
2626
+			$category_select_values,
2627
+			$this->_category->parent
2628
+		);
2629
+		$template_args   = [
2630
+			'category'                 => $this->_category,
2631
+			'category_select'          => $category_select,
2632
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2633
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2634
+			'disable'                  => '',
2635
+			'disabled_message'         => false,
2636
+		];
2637
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2638
+		return EEH_Template::display_template($template, $template_args, true);
2639
+	}
2640
+
2641
+
2642
+	/**
2643
+	 * Handles deleting categories.
2644
+	 *
2645
+	 * @throws EE_Error
2646
+	 */
2647
+	protected function _delete_categories()
2648
+	{
2649
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2650
+		foreach ($category_IDs as $category_ID) {
2651
+			$this->_delete_category($category_ID);
2652
+		}
2653
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2654
+		$query_args = [
2655
+			'action' => 'category_list',
2656
+		];
2657
+		$this->_redirect_after_action(0, '', '', $query_args);
2658
+	}
2659
+
2660
+
2661
+	/**
2662
+	 * Handles deleting specific category.
2663
+	 *
2664
+	 * @param int $cat_id
2665
+	 */
2666
+	protected function _delete_category($cat_id)
2667
+	{
2668
+		$cat_id = absint($cat_id);
2669
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2670
+	}
2671
+
2672
+
2673
+	/**
2674
+	 * Handles triggering the update or insertion of a new category.
2675
+	 *
2676
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2677
+	 * @throws EE_Error
2678
+	 * @throws EE_Error
2679
+	 */
2680
+	protected function _insert_or_update_category($new_category)
2681
+	{
2682
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2683
+		$success = 0; // we already have a success message so lets not send another.
2684
+		if ($cat_id) {
2685
+			$query_args = [
2686
+				'action'     => 'edit_category',
2687
+				'EVT_CAT_ID' => $cat_id,
2688
+			];
2689
+		} else {
2690
+			$query_args = ['action' => 'add_category'];
2691
+		}
2692
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2693
+	}
2694
+
2695
+
2696
+	/**
2697
+	 * Inserts or updates category
2698
+	 *
2699
+	 * @param bool $update (true indicates we're updating a category).
2700
+	 * @return bool|mixed|string
2701
+	 */
2702
+	private function _insert_category($update = false)
2703
+	{
2704
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2705
+		$category_name       = $this->request->getRequestParam('category_name', '');
2706
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2707
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2708
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2709
+
2710
+		if (empty($category_name)) {
2711
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2712
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2713
+			return false;
2714
+		}
2715
+		$term_args = [
2716
+			'name'        => $category_name,
2717
+			'description' => $category_desc,
2718
+			'parent'      => $category_parent,
2719
+		];
2720
+		// was the category_identifier input disabled?
2721
+		if ($category_identifier) {
2722
+			$term_args['slug'] = $category_identifier;
2723
+		}
2724
+		$insert_ids = $update
2725
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2726
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2727
+		if (! is_array($insert_ids)) {
2728
+			$msg = esc_html__(
2729
+				'An error occurred and the category has not been saved to the database.',
2730
+				'event_espresso'
2731
+			);
2732
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2733
+		} else {
2734
+			$category_ID = $insert_ids['term_id'];
2735
+			$msg         =
2736
+				sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2737
+			EE_Error::add_success($msg);
2738
+		}
2739
+		return $category_ID;
2740
+	}
2741
+
2742
+
2743
+	/**
2744
+	 * Gets categories or count of categories matching the arguments in the request.
2745
+	 *
2746
+	 * @param int  $per_page
2747
+	 * @param int  $current_page
2748
+	 * @param bool $count
2749
+	 * @return EE_Term_Taxonomy[]|int
2750
+	 * @throws EE_Error
2751
+	 * @throws EE_Error
2752
+	 */
2753
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2754
+	{
2755
+		// testing term stuff
2756
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2757
+		$order       = $this->request->getRequestParam('order', 'DESC');
2758
+		$limit       = ($current_page - 1) * $per_page;
2759
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2760
+		$search_term = $this->request->getRequestParam('s');
2761
+		if ($search_term) {
2762
+			$search_term = '%' . $search_term . '%';
2763
+			$where['OR'] = [
2764
+				'Term.name'   => ['LIKE', $search_term],
2765
+				'description' => ['LIKE', $search_term],
2766
+			];
2767
+		}
2768
+		$query_params = [
2769
+			$where,
2770
+			'order_by'   => [$orderby => $order],
2771
+			'limit'      => $limit . ',' . $per_page,
2772
+			'force_join' => ['Term'],
2773
+		];
2774
+		return $count
2775
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2776
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2777
+	}
2778
+
2779
+	/* end category stuff */
2780
+	/**************/
2781
+
2782
+
2783
+	/**
2784
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2785
+	 *
2786
+	 * @throws EE_Error
2787
+	 */
2788
+	public function saveTimezoneString()
2789
+	{
2790
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2791
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2792
+			EE_Error::add_error(
2793
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2794
+				__FILE__,
2795
+				__FUNCTION__,
2796
+				__LINE__
2797
+			);
2798
+			$this->_template_args['error'] = true;
2799
+			$this->_return_json();
2800
+		}
2801
+
2802
+		update_option('timezone_string', $timezone_string);
2803
+		EE_Error::add_success(
2804
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2805
+		);
2806
+		$this->_template_args['success'] = true;
2807
+		$this->_return_json(true, ['action' => 'create_new']);
2808
+	}
2809
+
2810
+
2811
+	/**
2812
+	 * @throws EE_Error
2813
+	 * @deprecated 4.10.25.p
2814
+	 */
2815
+	public function save_timezonestring_setting()
2816
+	{
2817
+		$this->saveTimezoneString();
2818
+	}
2819 2819
 }
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -562,11 +562,11 @@  discard block
 block discarded – undo
562 562
     {
563 563
         wp_register_style(
564 564
             'events-admin-css',
565
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
565
+            EVENTS_ASSETS_URL.'events-admin-page.css',
566 566
             [],
567 567
             EVENT_ESPRESSO_VERSION
568 568
         );
569
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
569
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
570 570
         wp_enqueue_style('events-admin-css');
571 571
         wp_enqueue_style('ee-cat-admin');
572 572
         // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
         // scripts
575 575
         wp_register_script(
576 576
             'event_editor_js',
577
-            EVENTS_ASSETS_URL . 'event_editor.js',
577
+            EVENTS_ASSETS_URL.'event_editor.js',
578 578
             ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
579 579
             EVENT_ESPRESSO_VERSION,
580 580
             true
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
         wp_enqueue_style('espresso-ui-theme');
601 601
         wp_register_style(
602 602
             'event-editor-css',
603
-            EVENTS_ASSETS_URL . 'event-editor.css',
603
+            EVENTS_ASSETS_URL.'event-editor.css',
604 604
             ['ee-admin-css'],
605 605
             EVENT_ESPRESSO_VERSION
606 606
         );
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
         // scripts
609 609
         wp_register_script(
610 610
             'event-datetime-metabox',
611
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
611
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
612 612
             ['event_editor_js', 'ee-datepicker'],
613 613
             EVENT_ESPRESSO_VERSION
614 614
         );
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
     public function verify_event_edit($event = null, $req_type = '')
678 678
     {
679 679
         // don't need to do this when processing
680
-        if (! empty($req_type)) {
680
+        if ( ! empty($req_type)) {
681 681
             return;
682 682
         }
683 683
         // no event?
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
             $event = $this->_cpt_model_obj;
687 687
         }
688 688
         // STILL no event?
689
-        if (! $event instanceof EE_Event) {
689
+        if ( ! $event instanceof EE_Event) {
690 690
             return;
691 691
         }
692 692
         $orig_status = $event->status();
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
             );
726 726
         }
727 727
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
728
-        if (! $event->tickets_on_sale()) {
728
+        if ( ! $event->tickets_on_sale()) {
729 729
             return;
730 730
         }
731 731
         // made it here so show warning
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
     {
771 771
         $has_timezone_string = get_option('timezone_string');
772 772
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
773
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
773
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
774 774
             EE_Error::add_attention(
775 775
                 sprintf(
776 776
                     esc_html__(
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
      */
840 840
     protected function _event_legend_items()
841 841
     {
842
-        $items    = [
842
+        $items = [
843 843
             'view_details'   => [
844 844
                 'class' => 'dashicons dashicons-search',
845 845
                 'desc'  => esc_html__('View Event', 'event_espresso'),
@@ -856,31 +856,31 @@  discard block
 block discarded – undo
856 856
         $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
857 857
         $statuses = [
858 858
             'sold_out_status'  => [
859
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
859
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
860 860
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
861 861
             ],
862 862
             'active_status'    => [
863
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
863
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
864 864
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
865 865
             ],
866 866
             'upcoming_status'  => [
867
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
867
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
868 868
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
869 869
             ],
870 870
             'postponed_status' => [
871
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
871
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
872 872
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
873 873
             ],
874 874
             'cancelled_status' => [
875
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
875
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
876 876
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
877 877
             ],
878 878
             'expired_status'   => [
879
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
879
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
880 880
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
881 881
             ],
882 882
             'inactive_status'  => [
883
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
883
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
884 884
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
885 885
             ],
886 886
         ];
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
      */
897 897
     private function _event_model()
898 898
     {
899
-        if (! $this->_event_model instanceof EEM_Event) {
899
+        if ( ! $this->_event_model instanceof EEM_Event) {
900 900
             $this->_event_model = EE_Registry::instance()->load_model('Event');
901 901
         }
902 902
         return $this->_event_model;
@@ -916,8 +916,8 @@  discard block
 block discarded – undo
916 916
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
917 917
     {
918 918
         // make sure this is only when editing
919
-        if (! empty($id)) {
920
-            $post   = get_post($id);
919
+        if ( ! empty($id)) {
920
+            $post = get_post($id);
921 921
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
922 922
                        . esc_html__('Shortcode', 'event_espresso')
923 923
                        . '</a> ';
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
     protected function _events_overview_list_table()
941 941
     {
942 942
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
943
-        $this->_template_args['after_list_table']                           =
943
+        $this->_template_args['after_list_table'] =
944 944
             ! empty($this->_template_args['after_list_table'])
945 945
                 ? (array) $this->_template_args['after_list_table']
946 946
                 : [];
@@ -950,10 +950,10 @@  discard block
 block discarded – undo
950 950
                 esc_html__("View Event Archive Page", "event_espresso"),
951 951
                 'button'
952 952
             );
953
-        $this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
953
+        $this->_template_args['after_list_table']['legend'] = $this->_display_legend(
954 954
             $this->_event_legend_items()
955 955
         );
956
-        $this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
956
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
957 957
             'create_new',
958 958
             'add',
959 959
             [],
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
                 [$this, '_default_tickets_update'],
1050 1050
             ]
1051 1051
         );
1052
-        $att_success            = true;
1052
+        $att_success = true;
1053 1053
         foreach ($event_update_callbacks as $e_callback) {
1054 1054
             $_success = is_callable($e_callback)
1055 1055
                 ? call_user_func($e_callback, $event, $this->request->requestParams())
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
      */
1112 1112
     protected function _default_venue_update(EE_Event $event, $data)
1113 1113
     {
1114
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1114
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1115 1115
         $venue_model = EE_Registry::instance()->load_model('Venue');
1116 1116
         $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1117 1117
         // very important.  If we don't have a venue name...
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
             'status'              => 'publish',
1143 1143
         ];
1144 1144
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1145
-        if (! empty($venue_id)) {
1145
+        if ( ! empty($venue_id)) {
1146 1146
             $update_where  = [$venue_model->primary_key_name() => $venue_id];
1147 1147
             $rows_affected = $venue_model->update($venue_array, [$update_where]);
1148 1148
             // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
                 isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1181 1181
                     ? $datetime_data['DTT_EVT_end']
1182 1182
                     : $datetime_data['DTT_EVT_start'];
1183
-            $datetime_values              = [
1183
+            $datetime_values = [
1184 1184
                 'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1185 1185
                 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1186 1186
                 'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
@@ -1189,9 +1189,9 @@  discard block
 block discarded – undo
1189 1189
             ];
1190 1190
             // if we have an id then let's get existing object first and then set the new values.
1191 1191
             //  Otherwise we instantiate a new object for save.
1192
-            if (! empty($datetime_data['DTT_ID'])) {
1192
+            if ( ! empty($datetime_data['DTT_ID'])) {
1193 1193
                 $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1194
-                if (! $datetime instanceof EE_Datetime) {
1194
+                if ( ! $datetime instanceof EE_Datetime) {
1195 1195
                     throw new RuntimeException(
1196 1196
                         sprintf(
1197 1197
                             esc_html__(
@@ -1210,7 +1210,7 @@  discard block
 block discarded – undo
1210 1210
             } else {
1211 1211
                 $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1212 1212
             }
1213
-            if (! $datetime instanceof EE_Datetime) {
1213
+            if ( ! $datetime instanceof EE_Datetime) {
1214 1214
                 throw new RuntimeException(
1215 1215
                     sprintf(
1216 1216
                         esc_html__(
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
 
1237 1237
         // set up some default start and end dates in case those are not present in the incoming data
1238 1238
         $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1239
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1239
+        $default_start_date = $default_start_date->format($date_formats[0].' '.$date_formats[1]);
1240 1240
         // use the start date of the first datetime for the end date
1241 1241
         $first_datetime   = $event->first_datetime();
1242 1242
         $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
@@ -1244,8 +1244,8 @@  discard block
 block discarded – undo
1244 1244
         // now process the incoming data
1245 1245
         foreach ($data['edit_tickets'] as $row => $ticket_data) {
1246 1246
             $update_prices = false;
1247
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1248
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1247
+            $ticket_price  = isset($data['edit_prices'][$row][1]['PRC_amount'])
1248
+                ? $data['edit_prices'][$row][1]['PRC_amount']
1249 1249
                 : 0;
1250 1250
             // trim inputs to ensure any excess whitespace is removed.
1251 1251
             $ticket_data   = array_map('trim', $ticket_data);
@@ -1286,9 +1286,9 @@  discard block
 block discarded – undo
1286 1286
             // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1287 1287
             // keep in mind that if the ticket has been sold (and we have changed pricing information),
1288 1288
             // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1289
-            if (! empty($ticket_data['TKT_ID'])) {
1289
+            if ( ! empty($ticket_data['TKT_ID'])) {
1290 1290
                 $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1291
-                if (! $existing_ticket instanceof EE_Ticket) {
1291
+                if ( ! $existing_ticket instanceof EE_Ticket) {
1292 1292
                     throw new RuntimeException(
1293 1293
                         sprintf(
1294 1294
                             esc_html__(
@@ -1337,7 +1337,7 @@  discard block
 block discarded – undo
1337 1337
                     $existing_ticket->save();
1338 1338
                     // make sure this ticket is still recorded in our $saved_tickets
1339 1339
                     // so we don't run it through the regular trash routine.
1340
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1340
+                    $saved_tickets[$existing_ticket->ID()] = $existing_ticket;
1341 1341
                     // create new ticket that's a copy of the existing except,
1342 1342
                     // (a new id of course and not archived) AND has the new TKT_price associated with it.
1343 1343
                     $new_ticket = clone $existing_ticket;
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
                 $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1355 1355
                 $update_prices              = true;
1356 1356
             }
1357
-            if (! $ticket instanceof EE_Ticket) {
1357
+            if ( ! $ticket instanceof EE_Ticket) {
1358 1358
                 throw new RuntimeException(
1359 1359
                     sprintf(
1360 1360
                         esc_html__(
@@ -1378,12 +1378,12 @@  discard block
 block discarded – undo
1378 1378
             }
1379 1379
             // initially let's add the ticket to the datetime
1380 1380
             $datetime->_add_relation_to($ticket, 'Ticket');
1381
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1381
+            $saved_tickets[$ticket->ID()] = $ticket;
1382 1382
             // add prices to ticket
1383 1383
             $prices_data = (
1384
-                isset($data['edit_prices'][ $row ])
1385
-                && is_array($data['edit_prices'][ $row ])
1386
-            ) ? $data['edit_prices'][ $row ] : [];
1384
+                isset($data['edit_prices'][$row])
1385
+                && is_array($data['edit_prices'][$row])
1386
+            ) ? $data['edit_prices'][$row] : [];
1387 1387
             $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1388 1388
         }
1389 1389
         // however now we need to handle permanently deleting tickets via the ui.
@@ -1396,7 +1396,7 @@  discard block
 block discarded – undo
1396 1396
             $id = absint($id);
1397 1397
             // get the ticket for this id
1398 1398
             $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1399
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1399
+            if ( ! $ticket_to_remove instanceof EE_Ticket) {
1400 1400
                 continue;
1401 1401
             }
1402 1402
             // need to get all the related datetimes on this ticket and remove from every single one of them
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
                     $price->set($field, $new_price);
1454 1454
                 }
1455 1455
             }
1456
-            if (! $price instanceof EE_Price) {
1456
+            if ( ! $price instanceof EE_Price) {
1457 1457
                 throw new RuntimeException(
1458 1458
                     sprintf(
1459 1459
                         esc_html__(
@@ -1496,13 +1496,13 @@  discard block
 block discarded – undo
1496 1496
     {
1497 1497
         // load formatter helper
1498 1498
         // args for getting related registrations
1499
-        $approved_query_args        = [
1499
+        $approved_query_args = [
1500 1500
             [
1501 1501
                 'REG_deleted' => 0,
1502 1502
                 'STS_ID'      => EEM_Registration::status_id_approved,
1503 1503
             ],
1504 1504
         ];
1505
-        $not_approved_query_args    = [
1505
+        $not_approved_query_args = [
1506 1506
             [
1507 1507
                 'REG_deleted' => 0,
1508 1508
                 'STS_ID'      => EEM_Registration::status_id_not_approved,
@@ -1565,7 +1565,7 @@  discard block
 block discarded – undo
1565 1565
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1566 1566
         // load template
1567 1567
         EEH_Template::display_template(
1568
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1568
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1569 1569
             $publish_box_extra_args
1570 1570
         );
1571 1571
     }
@@ -1637,7 +1637,7 @@  discard block
 block discarded – undo
1637 1637
             'trash_icon'               => 'ee-lock-icon',
1638 1638
             'disabled'                 => '',
1639 1639
         ];
1640
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1640
+        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1641 1641
         /**
1642 1642
          * 1. Start with retrieving Datetimes
1643 1643
          * 2. Fore each datetime get related tickets
@@ -1658,18 +1658,18 @@  discard block
 block discarded – undo
1658 1658
                     'default_where_conditions' => 'none',
1659 1659
                 ]
1660 1660
             );
1661
-            if (! empty($related_tickets)) {
1661
+            if ( ! empty($related_tickets)) {
1662 1662
                 $template_args['total_ticket_rows'] = count($related_tickets);
1663 1663
                 $row                                = 0;
1664 1664
                 foreach ($related_tickets as $ticket) {
1665
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1665
+                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1666 1666
                     $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1667 1667
                     $row++;
1668 1668
                 }
1669 1669
             } else {
1670 1670
                 $template_args['total_ticket_rows'] = 1;
1671 1671
                 /** @type EE_Ticket $ticket */
1672
-                $ticket                       = EEM_Ticket::instance()->create_default_object();
1672
+                $ticket = EEM_Ticket::instance()->create_default_object();
1673 1673
                 $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1674 1674
             }
1675 1675
         } else {
@@ -1689,9 +1689,9 @@  discard block
 block discarded – undo
1689 1689
             EEM_Ticket::instance()->create_default_object(),
1690 1690
             true
1691 1691
         );
1692
-        $template                                  = apply_filters(
1692
+        $template = apply_filters(
1693 1693
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1694
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1694
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1695 1695
         );
1696 1696
         EEH_Template::display_template($template, $template_args);
1697 1697
     }
@@ -1711,7 +1711,7 @@  discard block
 block discarded – undo
1711 1711
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1712 1712
     {
1713 1713
         $template_args = [
1714
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1714
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1715 1715
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1716 1716
                 : '',
1717 1717
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1723,10 +1723,10 @@  discard block
 block discarded – undo
1723 1723
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1724 1724
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1725 1725
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1726
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1727
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1726
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1727
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1728 1728
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1729
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1729
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1730 1730
                 : ' disabled=disabled',
1731 1731
         ];
1732 1732
         $price         = $ticket->ID() !== 0
@@ -1750,7 +1750,7 @@  discard block
 block discarded – undo
1750 1750
         }
1751 1751
         if (empty($template_args['TKT_end_date'])) {
1752 1752
             // get the earliest datetime (if present);
1753
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1753
+            $earliest_datetime = $this->_cpt_model_obj->ID() > 0
1754 1754
                 ? $this->_cpt_model_obj->get_first_related(
1755 1755
                     'Datetime',
1756 1756
                     ['order_by' => ['DTT_EVT_start' => 'ASC']]
@@ -1763,7 +1763,7 @@  discard block
 block discarded – undo
1763 1763
         $template_args = array_merge($template_args, $price_args);
1764 1764
         $template      = apply_filters(
1765 1765
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1766
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1766
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1767 1767
             $ticket
1768 1768
         );
1769 1769
         return EEH_Template::display_template($template, $template_args, true);
@@ -1776,7 +1776,7 @@  discard block
 block discarded – undo
1776 1776
      */
1777 1777
     public function registration_options_meta_box()
1778 1778
     {
1779
-        $yes_no_values             = [
1779
+        $yes_no_values = [
1780 1780
             ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1781 1781
             ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1782 1782
         ];
@@ -1798,12 +1798,12 @@  discard block
 block discarded – undo
1798 1798
             $default_reg_status_values,
1799 1799
             $this->_cpt_model_obj->default_registration_status()
1800 1800
         );
1801
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1801
+        $template_args['display_description'] = EEH_Form_Fields::select_input(
1802 1802
             'display_desc',
1803 1803
             $yes_no_values,
1804 1804
             $this->_cpt_model_obj->display_description()
1805 1805
         );
1806
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1806
+        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1807 1807
             'display_ticket_selector',
1808 1808
             $yes_no_values,
1809 1809
             $this->_cpt_model_obj->display_ticket_selector(),
@@ -1819,7 +1819,7 @@  discard block
 block discarded – undo
1819 1819
             $default_reg_status_values
1820 1820
         );
1821 1821
         EEH_Template::display_template(
1822
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1822
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1823 1823
             $template_args
1824 1824
         );
1825 1825
     }
@@ -1842,7 +1842,7 @@  discard block
 block discarded – undo
1842 1842
     {
1843 1843
         $EEM_Event   = $this->_event_model();
1844 1844
         $offset      = ($current_page - 1) * $per_page;
1845
-        $limit       = $count ? null : $offset . ',' . $per_page;
1845
+        $limit       = $count ? null : $offset.','.$per_page;
1846 1846
         $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1847 1847
         $order       = $this->request->getRequestParam('order', 'DESC');
1848 1848
         $month_range = $this->request->getRequestParam('month_range');
@@ -1879,10 +1879,10 @@  discard block
 block discarded – undo
1879 1879
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1880 1880
         if ($month_range) {
1881 1881
             $DateTime = new DateTime(
1882
-                $year_r . '-' . $month_r . '-01 00:00:00',
1882
+                $year_r.'-'.$month_r.'-01 00:00:00',
1883 1883
                 new DateTimeZone('UTC')
1884 1884
             );
1885
-            $start    = $DateTime->getTimestamp();
1885
+            $start = $DateTime->getTimestamp();
1886 1886
             // set the datetime to be the end of the month
1887 1887
             $DateTime->setDate(
1888 1888
                 $year_r,
@@ -1907,11 +1907,11 @@  discard block
 block discarded – undo
1907 1907
                                                         ->format(implode(' ', $start_formats));
1908 1908
             $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1909 1909
         }
1910
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1910
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1911 1911
             $where['EVT_wp_user'] = get_current_user_id();
1912 1912
         } else {
1913
-            if (! isset($where['status'])) {
1914
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1913
+            if ( ! isset($where['status'])) {
1914
+                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1915 1915
                     $where['OR'] = [
1916 1916
                         'status*restrict_private' => ['!=', 'private'],
1917 1917
                         'AND'                     => [
@@ -1933,7 +1933,7 @@  discard block
 block discarded – undo
1933 1933
         // search query handling
1934 1934
         $search_term = $this->request->getRequestParam('s');
1935 1935
         if ($search_term) {
1936
-            $search_term = '%' . $search_term . '%';
1936
+            $search_term = '%'.$search_term.'%';
1937 1937
             $where['OR'] = [
1938 1938
                 'EVT_name'       => ['LIKE', $search_term],
1939 1939
                 'EVT_desc'       => ['LIKE', $search_term],
@@ -2041,7 +2041,7 @@  discard block
 block discarded – undo
2041 2041
             // clean status
2042 2042
             $event_status = sanitize_key($event_status);
2043 2043
             // grab status
2044
-            if (! empty($event_status)) {
2044
+            if ( ! empty($event_status)) {
2045 2045
                 $success = $this->_change_event_status($EVT_ID, $event_status);
2046 2046
             } else {
2047 2047
                 $success = false;
@@ -2081,7 +2081,7 @@  discard block
 block discarded – undo
2081 2081
         // clean status
2082 2082
         $event_status = sanitize_key($event_status);
2083 2083
         // grab status
2084
-        if (! empty($event_status)) {
2084
+        if ( ! empty($event_status)) {
2085 2085
             $success = true;
2086 2086
             // determine the event id and set to array.
2087 2087
             $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
@@ -2127,7 +2127,7 @@  discard block
 block discarded – undo
2127 2127
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2128 2128
     {
2129 2129
         // grab event id
2130
-        if (! $EVT_ID) {
2130
+        if ( ! $EVT_ID) {
2131 2131
             $msg = esc_html__(
2132 2132
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2133 2133
                 'event_espresso'
@@ -2164,7 +2164,7 @@  discard block
 block discarded – undo
2164 2164
         // use class to change status
2165 2165
         $this->_cpt_model_obj->set_status($event_status);
2166 2166
         $success = $this->_cpt_model_obj->save();
2167
-        if (! $success) {
2167
+        if ( ! $success) {
2168 2168
             $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2169 2169
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2170 2170
             return false;
@@ -2222,7 +2222,7 @@  discard block
 block discarded – undo
2222 2222
      */
2223 2223
     protected function getModelObjNodeGroupPersister()
2224 2224
     {
2225
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2225
+        if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2226 2226
             $this->model_obj_node_group_persister =
2227 2227
                 $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2228 2228
         }
@@ -2504,7 +2504,7 @@  discard block
 block discarded – undo
2504 2504
                                                 . esc_html__(
2505 2505
                                                     'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2506 2506
                                                     'event_espresso'
2507
-                                                ) . '</strong>';
2507
+                                                ).'</strong>';
2508 2508
         $this->display_admin_caf_preview_page('template_settings_tab');
2509 2509
     }
2510 2510
 
@@ -2525,11 +2525,11 @@  discard block
 block discarded – undo
2525 2525
         $this->_set_empty_category_object();
2526 2526
         // only set if we've got an id
2527 2527
         $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2528
-        if (! $category_ID) {
2528
+        if ( ! $category_ID) {
2529 2529
             return;
2530 2530
         }
2531 2531
         $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2532
-        if (! empty($term)) {
2532
+        if ( ! empty($term)) {
2533 2533
             $this->_category->category_name       = $term->name;
2534 2534
             $this->_category->category_identifier = $term->slug;
2535 2535
             $this->_category->category_desc       = $term->description;
@@ -2557,7 +2557,7 @@  discard block
 block discarded – undo
2557 2557
     {
2558 2558
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2559 2559
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2560
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2560
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2561 2561
             'add_category',
2562 2562
             'add_category',
2563 2563
             [],
@@ -2626,7 +2626,7 @@  discard block
 block discarded – undo
2626 2626
             $category_select_values,
2627 2627
             $this->_category->parent
2628 2628
         );
2629
-        $template_args   = [
2629
+        $template_args = [
2630 2630
             'category'                 => $this->_category,
2631 2631
             'category_select'          => $category_select,
2632 2632
             'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
@@ -2634,7 +2634,7 @@  discard block
 block discarded – undo
2634 2634
             'disable'                  => '',
2635 2635
             'disabled_message'         => false,
2636 2636
         ];
2637
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2637
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2638 2638
         return EEH_Template::display_template($template, $template_args, true);
2639 2639
     }
2640 2640
 
@@ -2724,7 +2724,7 @@  discard block
 block discarded – undo
2724 2724
         $insert_ids = $update
2725 2725
             ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2726 2726
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2727
-        if (! is_array($insert_ids)) {
2727
+        if ( ! is_array($insert_ids)) {
2728 2728
             $msg = esc_html__(
2729 2729
                 'An error occurred and the category has not been saved to the database.',
2730 2730
                 'event_espresso'
@@ -2759,7 +2759,7 @@  discard block
 block discarded – undo
2759 2759
         $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2760 2760
         $search_term = $this->request->getRequestParam('s');
2761 2761
         if ($search_term) {
2762
-            $search_term = '%' . $search_term . '%';
2762
+            $search_term = '%'.$search_term.'%';
2763 2763
             $where['OR'] = [
2764 2764
                 'Term.name'   => ['LIKE', $search_term],
2765 2765
                 'description' => ['LIKE', $search_term],
@@ -2768,7 +2768,7 @@  discard block
 block discarded – undo
2768 2768
         $query_params = [
2769 2769
             $where,
2770 2770
             'order_by'   => [$orderby => $order],
2771
-            'limit'      => $limit . ',' . $per_page,
2771
+            'limit'      => $limit.','.$per_page,
2772 2772
             'force_join' => ['Term'],
2773 2773
         ];
2774 2774
         return $count
Please login to merge, or discard this patch.