Completed
Branch master (8d9631)
by
unknown
56:07 queued 43:57
created
core/services/orm/tree_traversal/BaseNode.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
      */
69 69
     public function visit($model_objects_to_identify)
70 70
     {
71
-        if (! $this->isDiscovered()) {
71
+        if ( ! $this->isDiscovered()) {
72 72
             $this->discover();
73 73
         }
74 74
         if ($this->isComplete()) {
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
     /**
103 103
      * Make sure we encode whether its complete or not, but don't use such a long name.
104 104
      * @since $VID:$
105
-     * @return array
105
+     * @return string[]
106 106
      */
107 107
     public function __sleep()
108 108
     {
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -31,105 +31,105 @@
 block discarded – undo
31 31
  */
32 32
 abstract class BaseNode
33 33
 {
34
-    /**
35
-     * @var boolean
36
-     */
37
-    protected $complete;
34
+	/**
35
+	 * @var boolean
36
+	 */
37
+	protected $complete;
38 38
 
39 39
 
40
-    /**
41
-     * @var array of model names we don't want to traverse
42
-     */
43
-    protected $dont_traverse_models;
40
+	/**
41
+	 * @var array of model names we don't want to traverse
42
+	 */
43
+	protected $dont_traverse_models;
44 44
 
45
-    /**
46
-     * Whether this item has already been initialized
47
-     */
48
-    abstract protected function isDiscovered();
45
+	/**
46
+	 * Whether this item has already been initialized
47
+	 */
48
+	abstract protected function isDiscovered();
49 49
 
50
-    /**
51
-     * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling
52
-     * discover().
53
-     * @since $VID:$
54
-     * @return boolean
55
-     */
56
-    abstract public function isComplete();
50
+	/**
51
+	 * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling
52
+	 * discover().
53
+	 * @since $VID:$
54
+	 * @return boolean
55
+	 */
56
+	abstract public function isComplete();
57 57
 
58
-    /**
59
-     * Discovers what work needs to be done to complete traversing this node and its children.
60
-     * Note that this is separate from the constructor, so we can create child nodes without
61
-     * discovering them immediately.
62
-     * @since $VID:$
63
-     * @return mixed
64
-     */
65
-    abstract protected function discover();
58
+	/**
59
+	 * Discovers what work needs to be done to complete traversing this node and its children.
60
+	 * Note that this is separate from the constructor, so we can create child nodes without
61
+	 * discovering them immediately.
62
+	 * @since $VID:$
63
+	 * @return mixed
64
+	 */
65
+	abstract protected function discover();
66 66
 
67
-    /**
68
-     * Identifies model objects, up to the limit $model_objects_to_identify.
69
-     * @since $VID:$
70
-     * @param int $model_objects_to_identify
71
-     * @return int units of work done
72
-     */
73
-    abstract protected function work($model_objects_to_identify);
67
+	/**
68
+	 * Identifies model objects, up to the limit $model_objects_to_identify.
69
+	 * @since $VID:$
70
+	 * @param int $model_objects_to_identify
71
+	 * @return int units of work done
72
+	 */
73
+	abstract protected function work($model_objects_to_identify);
74 74
 
75
-    /**
76
-     * Shows the entity/relation node as an array.
77
-     * @since $VID:$
78
-     * @return array
79
-     */
80
-    abstract public function toArray();
75
+	/**
76
+	 * Shows the entity/relation node as an array.
77
+	 * @since $VID:$
78
+	 * @return array
79
+	 */
80
+	abstract public function toArray();
81 81
 
82
-    /**
83
-     * Discovers how much work there is to do, double-checks the work isn't already finished, and then does the work.
84
-     * Note: do not call when site is in maintenance mode level 2.
85
-     *
86
-     * @since $VID:$
87
-     * @param $model_objects_to_identify
88
-     * @return int number of model objects we want to identify during this call. On subsequent calls we'll continue
89
-     * where we left off.
90
-     */
91
-    public function visit($model_objects_to_identify)
92
-    {
93
-        if (! $this->isDiscovered()) {
94
-            $this->discover();
95
-        }
96
-        if ($this->isComplete()) {
97
-            return 0;
98
-        }
99
-        return $this->work($model_objects_to_identify);
100
-    }
82
+	/**
83
+	 * Discovers how much work there is to do, double-checks the work isn't already finished, and then does the work.
84
+	 * Note: do not call when site is in maintenance mode level 2.
85
+	 *
86
+	 * @since $VID:$
87
+	 * @param $model_objects_to_identify
88
+	 * @return int number of model objects we want to identify during this call. On subsequent calls we'll continue
89
+	 * where we left off.
90
+	 */
91
+	public function visit($model_objects_to_identify)
92
+	{
93
+		if (! $this->isDiscovered()) {
94
+			$this->discover();
95
+		}
96
+		if ($this->isComplete()) {
97
+			return 0;
98
+		}
99
+		return $this->work($model_objects_to_identify);
100
+	}
101 101
 
102
-    /**
103
-     * Gets the IDs of completely identified model objects that can be deleted.
104
-     * @since $VID:$
105
-     * @return mixed
106
-     */
107
-    abstract public function getIds();
102
+	/**
103
+	 * Gets the IDs of completely identified model objects that can be deleted.
104
+	 * @since $VID:$
105
+	 * @return mixed
106
+	 */
107
+	abstract public function getIds();
108 108
 
109
-    /**
110
-     * Make sure we encode whether its complete or not, but don't use such a long name.
111
-     * @since $VID:$
112
-     * @return array
113
-     */
114
-    public function __sleep()
115
-    {
116
-        $this->c = $this->complete;
117
-        $this->dtm = $this->dont_traverse_models;
118
-        return [
119
-            'c',
120
-            'dtm'
121
-        ];
122
-    }
109
+	/**
110
+	 * Make sure we encode whether its complete or not, but don't use such a long name.
111
+	 * @since $VID:$
112
+	 * @return array
113
+	 */
114
+	public function __sleep()
115
+	{
116
+		$this->c = $this->complete;
117
+		$this->dtm = $this->dont_traverse_models;
118
+		return [
119
+			'c',
120
+			'dtm'
121
+		];
122
+	}
123 123
 
124
-    /**
125
-     * Use the dynamic property to set the "complete" property.
126
-     * @since $VID:$
127
-     */
128
-    public function __wakeup()
129
-    {
130
-        $this->complete = $this->c;
131
-        $this->dont_traverse_models = $this->dtm;
132
-    }
124
+	/**
125
+	 * Use the dynamic property to set the "complete" property.
126
+	 * @since $VID:$
127
+	 */
128
+	public function __wakeup()
129
+	{
130
+		$this->complete = $this->c;
131
+		$this->dont_traverse_models = $this->dtm;
132
+	}
133 133
 }
134 134
 // End of file BaseNode.php
135 135
 // Location: EventEspresso\core\services\orm\tree_traversal/BaseNode.php
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 4 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -2086,7 +2086,6 @@
 block discarded – undo
2086 2086
      * _delete_event
2087 2087
      *
2088 2088
      * @access protected
2089
-     * @param bool $redirect_after
2090 2089
      */
2091 2090
     protected function _delete_event()
2092 2091
     {
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -1,11 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-use EventEspresso\admin_pages\events\form_sections\ConfirmEventDeletionForm;
4 3
 use EventEspresso\core\exceptions\InvalidDataTypeException;
5 4
 use EventEspresso\core\exceptions\InvalidInterfaceException;
6
-use EventEspresso\core\exceptions\UnexpectedEntityException;
7 5
 use EventEspresso\core\services\orm\tree_traversal\NodeGroupDao;
8
-use EventEspresso\core\services\orm\tree_traversal\ModelObjNode;
9 6
 
10 7
 /**
11 8
  * Events_Admin_Page
Please login to merge, or discard this patch.
Indentation   +2641 added lines, -2641 removed lines patch added patch discarded remove patch
@@ -19,2645 +19,2645 @@
 block discarded – undo
19 19
 class Events_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
21 21
 
22
-    /**
23
-     * This will hold the event object for event_details screen.
24
-     *
25
-     * @access protected
26
-     * @var EE_Event $_event
27
-     */
28
-    protected $_event;
29
-
30
-
31
-    /**
32
-     * This will hold the category object for category_details screen.
33
-     *
34
-     * @var stdClass $_category
35
-     */
36
-    protected $_category;
37
-
38
-
39
-    /**
40
-     * This will hold the event model instance
41
-     *
42
-     * @var EEM_Event $_event_model
43
-     */
44
-    protected $_event_model;
45
-
46
-
47
-    /**
48
-     * @var EE_Event
49
-     */
50
-    protected $_cpt_model_obj = false;
51
-
52
-
53
-    /**
54
-     * @var NodeGroupDao
55
-     */
56
-    protected $model_obj_node_group_persister;
57
-
58
-    /**
59
-     * Initialize page props for this admin page group.
60
-     */
61
-    protected function _init_page_props()
62
-    {
63
-        $this->page_slug = EVENTS_PG_SLUG;
64
-        $this->page_label = EVENTS_LABEL;
65
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
66
-        $this->_admin_base_path = EVENTS_ADMIN;
67
-        $this->_cpt_model_names = array(
68
-            'create_new' => 'EEM_Event',
69
-            'edit'       => 'EEM_Event',
70
-        );
71
-        $this->_cpt_edit_routes = array(
72
-            'espresso_events' => 'edit',
73
-        );
74
-        add_action(
75
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
76
-            array($this, 'verify_event_edit'),
77
-            10,
78
-            2
79
-        );
80
-    }
81
-
82
-
83
-    /**
84
-     * Sets the ajax hooks used for this admin page group.
85
-     */
86
-    protected function _ajax_hooks()
87
-    {
88
-        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
89
-    }
90
-
91
-
92
-    /**
93
-     * Sets the page properties for this admin page group.
94
-     */
95
-    protected function _define_page_props()
96
-    {
97
-        $this->_admin_page_title = EVENTS_LABEL;
98
-        $this->_labels = array(
99
-            'buttons'      => array(
100
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
101
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
102
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
103
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
104
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
105
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
106
-            ),
107
-            'editor_title' => array(
108
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
109
-            ),
110
-            'publishbox'   => array(
111
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
112
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
113
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
114
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
115
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
116
-            ),
117
-        );
118
-    }
119
-
120
-
121
-    /**
122
-     * Sets the page routes property for this admin page group.
123
-     */
124
-    protected function _set_page_routes()
125
-    {
126
-        // load formatter helper
127
-        // load field generator helper
128
-        // is there a evt_id in the request?
129
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
130
-            ? $this->_req_data['EVT_ID']
131
-            : 0;
132
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
133
-        $this->_page_routes = array(
134
-            'default'                       => array(
135
-                'func'       => '_events_overview_list_table',
136
-                'capability' => 'ee_read_events',
137
-            ),
138
-            'create_new'                    => array(
139
-                'func'       => '_create_new_cpt_item',
140
-                'capability' => 'ee_edit_events',
141
-            ),
142
-            'edit'                          => array(
143
-                'func'       => '_edit_cpt_item',
144
-                'capability' => 'ee_edit_event',
145
-                'obj_id'     => $evt_id,
146
-            ),
147
-            'copy_event'                    => array(
148
-                'func'       => '_copy_events',
149
-                'capability' => 'ee_edit_event',
150
-                'obj_id'     => $evt_id,
151
-                'noheader'   => true,
152
-            ),
153
-            'trash_event'                   => array(
154
-                'func'       => '_trash_or_restore_event',
155
-                'args'       => array('event_status' => 'trash'),
156
-                'capability' => 'ee_delete_event',
157
-                'obj_id'     => $evt_id,
158
-                'noheader'   => true,
159
-            ),
160
-            'trash_events'                  => array(
161
-                'func'       => '_trash_or_restore_events',
162
-                'args'       => array('event_status' => 'trash'),
163
-                'capability' => 'ee_delete_events',
164
-                'noheader'   => true,
165
-            ),
166
-            'restore_event'                 => array(
167
-                'func'       => '_trash_or_restore_event',
168
-                'args'       => array('event_status' => 'draft'),
169
-                'capability' => 'ee_delete_event',
170
-                'obj_id'     => $evt_id,
171
-                'noheader'   => true,
172
-            ),
173
-            'restore_events'                => array(
174
-                'func'       => '_trash_or_restore_events',
175
-                'args'       => array('event_status' => 'draft'),
176
-                'capability' => 'ee_delete_events',
177
-                'noheader'   => true,
178
-            ),
179
-            'delete_event'                  => array(
180
-                'func'       => '_delete_event',
181
-                'capability' => 'ee_delete_event',
182
-                'obj_id'     => $evt_id,
183
-                'noheader'   => true,
184
-            ),
185
-            'delete_events'                 => array(
186
-                'func'       => '_delete_events',
187
-                'capability' => 'ee_delete_events',
188
-                'noheader'   => true,
189
-            ),
190
-            'view_report'                   => array(
191
-                'func'      => '_view_report',
192
-                'capablity' => 'ee_edit_events',
193
-            ),
194
-            'default_event_settings'        => array(
195
-                'func'       => '_default_event_settings',
196
-                'capability' => 'manage_options',
197
-            ),
198
-            'update_default_event_settings' => array(
199
-                'func'       => '_update_default_event_settings',
200
-                'capability' => 'manage_options',
201
-                'noheader'   => true,
202
-            ),
203
-            'template_settings'             => array(
204
-                'func'       => '_template_settings',
205
-                'capability' => 'manage_options',
206
-            ),
207
-            // event category tab related
208
-            'add_category'                  => array(
209
-                'func'       => '_category_details',
210
-                'capability' => 'ee_edit_event_category',
211
-                'args'       => array('add'),
212
-            ),
213
-            'edit_category'                 => array(
214
-                'func'       => '_category_details',
215
-                'capability' => 'ee_edit_event_category',
216
-                'args'       => array('edit'),
217
-            ),
218
-            'delete_categories'             => array(
219
-                'func'       => '_delete_categories',
220
-                'capability' => 'ee_delete_event_category',
221
-                'noheader'   => true,
222
-            ),
223
-            'delete_category'               => array(
224
-                'func'       => '_delete_categories',
225
-                'capability' => 'ee_delete_event_category',
226
-                'noheader'   => true,
227
-            ),
228
-            'insert_category'               => array(
229
-                'func'       => '_insert_or_update_category',
230
-                'args'       => array('new_category' => true),
231
-                'capability' => 'ee_edit_event_category',
232
-                'noheader'   => true,
233
-            ),
234
-            'update_category'               => array(
235
-                'func'       => '_insert_or_update_category',
236
-                'args'       => array('new_category' => false),
237
-                'capability' => 'ee_edit_event_category',
238
-                'noheader'   => true,
239
-            ),
240
-            'category_list'                 => array(
241
-                'func'       => '_category_list_table',
242
-                'capability' => 'ee_manage_event_categories',
243
-            ),
244
-            'preview_deletion' => [
245
-                'func' => 'previewDeletion',
246
-                'capability' => 'ee_delete_events',
247
-            ],
248
-            'confirm_deletion' => [
249
-                'func' => 'confirmDeletion',
250
-                'capability' => 'ee_delete_events',
251
-                'noheader' => true,
252
-            ]
253
-        );
254
-    }
255
-
256
-
257
-    /**
258
-     * Set the _page_config property for this admin page group.
259
-     */
260
-    protected function _set_page_config()
261
-    {
262
-        $this->_page_config = array(
263
-            'default'                => array(
264
-                'nav'           => array(
265
-                    'label' => esc_html__('Overview', 'event_espresso'),
266
-                    'order' => 10,
267
-                ),
268
-                'list_table'    => 'Events_Admin_List_Table',
269
-                'help_tabs'     => array(
270
-                    'events_overview_help_tab'                       => array(
271
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
272
-                        'filename' => 'events_overview',
273
-                    ),
274
-                    'events_overview_table_column_headings_help_tab' => array(
275
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
276
-                        'filename' => 'events_overview_table_column_headings',
277
-                    ),
278
-                    'events_overview_filters_help_tab'               => array(
279
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
280
-                        'filename' => 'events_overview_filters',
281
-                    ),
282
-                    'events_overview_view_help_tab'                  => array(
283
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
284
-                        'filename' => 'events_overview_views',
285
-                    ),
286
-                    'events_overview_other_help_tab'                 => array(
287
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
288
-                        'filename' => 'events_overview_other',
289
-                    ),
290
-                ),
291
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
292
-                // 'help_tour'     => array(
293
-                //     'Event_Overview_Help_Tour',
294
-                //     // 'New_Features_Test_Help_Tour' for testing multiple help tour
295
-                // ),
296
-                'qtips'         => array(
297
-                    'EE_Event_List_Table_Tips',
298
-                ),
299
-                'require_nonce' => false,
300
-            ),
301
-            'create_new'             => array(
302
-                'nav'           => array(
303
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
304
-                    'order'      => 5,
305
-                    'persistent' => false,
306
-                ),
307
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
308
-                'help_tabs'     => array(
309
-                    'event_editor_help_tab'                            => array(
310
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
311
-                        'filename' => 'event_editor',
312
-                    ),
313
-                    'event_editor_title_richtexteditor_help_tab'       => array(
314
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
315
-                        'filename' => 'event_editor_title_richtexteditor',
316
-                    ),
317
-                    'event_editor_venue_details_help_tab'              => array(
318
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
319
-                        'filename' => 'event_editor_venue_details',
320
-                    ),
321
-                    'event_editor_event_datetimes_help_tab'            => array(
322
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
323
-                        'filename' => 'event_editor_event_datetimes',
324
-                    ),
325
-                    'event_editor_event_tickets_help_tab'              => array(
326
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
327
-                        'filename' => 'event_editor_event_tickets',
328
-                    ),
329
-                    'event_editor_event_registration_options_help_tab' => array(
330
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
331
-                        'filename' => 'event_editor_event_registration_options',
332
-                    ),
333
-                    'event_editor_tags_categories_help_tab'            => array(
334
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
335
-                        'filename' => 'event_editor_tags_categories',
336
-                    ),
337
-                    'event_editor_questions_registrants_help_tab'      => array(
338
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
339
-                        'filename' => 'event_editor_questions_registrants',
340
-                    ),
341
-                    'event_editor_save_new_event_help_tab'             => array(
342
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
343
-                        'filename' => 'event_editor_save_new_event',
344
-                    ),
345
-                    'event_editor_other_help_tab'                      => array(
346
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
347
-                        'filename' => 'event_editor_other',
348
-                    ),
349
-                ),
350
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
351
-                // 'help_tour'     => array(
352
-                //     'Event_Editor_Help_Tour',
353
-                // ),
354
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
355
-                'require_nonce' => false,
356
-            ),
357
-            'edit'                   => array(
358
-                'nav'           => array(
359
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
360
-                    'order'      => 5,
361
-                    'persistent' => false,
362
-                    'url'        => isset($this->_req_data['post'])
363
-                        ? EE_Admin_Page::add_query_args_and_nonce(
364
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
365
-                            $this->_current_page_view_url
366
-                        )
367
-                        : $this->_admin_base_url,
368
-                ),
369
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
370
-                'help_tabs'     => array(
371
-                    'event_editor_help_tab'                            => array(
372
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
373
-                        'filename' => 'event_editor',
374
-                    ),
375
-                    'event_editor_title_richtexteditor_help_tab'       => array(
376
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
377
-                        'filename' => 'event_editor_title_richtexteditor',
378
-                    ),
379
-                    'event_editor_venue_details_help_tab'              => array(
380
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
381
-                        'filename' => 'event_editor_venue_details',
382
-                    ),
383
-                    'event_editor_event_datetimes_help_tab'            => array(
384
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
385
-                        'filename' => 'event_editor_event_datetimes',
386
-                    ),
387
-                    'event_editor_event_tickets_help_tab'              => array(
388
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
389
-                        'filename' => 'event_editor_event_tickets',
390
-                    ),
391
-                    'event_editor_event_registration_options_help_tab' => array(
392
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
393
-                        'filename' => 'event_editor_event_registration_options',
394
-                    ),
395
-                    'event_editor_tags_categories_help_tab'            => array(
396
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
397
-                        'filename' => 'event_editor_tags_categories',
398
-                    ),
399
-                    'event_editor_questions_registrants_help_tab'      => array(
400
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
401
-                        'filename' => 'event_editor_questions_registrants',
402
-                    ),
403
-                    'event_editor_save_new_event_help_tab'             => array(
404
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
405
-                        'filename' => 'event_editor_save_new_event',
406
-                    ),
407
-                    'event_editor_other_help_tab'                      => array(
408
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
409
-                        'filename' => 'event_editor_other',
410
-                    ),
411
-                ),
412
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
413
-                'require_nonce' => false,
414
-            ),
415
-            'default_event_settings' => array(
416
-                'nav'           => array(
417
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
418
-                    'order' => 40,
419
-                ),
420
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
421
-                'labels'        => array(
422
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
423
-                ),
424
-                'help_tabs'     => array(
425
-                    'default_settings_help_tab'        => array(
426
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
427
-                        'filename' => 'events_default_settings',
428
-                    ),
429
-                    'default_settings_status_help_tab' => array(
430
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
431
-                        'filename' => 'events_default_settings_status',
432
-                    ),
433
-                    'default_maximum_tickets_help_tab' => array(
434
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
435
-                        'filename' => 'events_default_settings_max_tickets',
436
-                    ),
437
-                ),
438
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
439
-                // 'help_tour'     => array('Event_Default_Settings_Help_Tour'),
440
-                'require_nonce' => false,
441
-            ),
442
-            // template settings
443
-            'template_settings'      => array(
444
-                'nav'           => array(
445
-                    'label' => esc_html__('Templates', 'event_espresso'),
446
-                    'order' => 30,
447
-                ),
448
-                'metaboxes'     => $this->_default_espresso_metaboxes,
449
-                'help_tabs'     => array(
450
-                    'general_settings_templates_help_tab' => array(
451
-                        'title'    => esc_html__('Templates', 'event_espresso'),
452
-                        'filename' => 'general_settings_templates',
453
-                    ),
454
-                ),
455
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
456
-                // 'help_tour'     => array('Templates_Help_Tour'),
457
-                'require_nonce' => false,
458
-            ),
459
-            // event category stuff
460
-            'add_category'           => array(
461
-                'nav'           => array(
462
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
463
-                    'order'      => 15,
464
-                    'persistent' => false,
465
-                ),
466
-                'help_tabs'     => array(
467
-                    'add_category_help_tab' => array(
468
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
469
-                        'filename' => 'events_add_category',
470
-                    ),
471
-                ),
472
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
473
-                // 'help_tour'     => array('Event_Add_Category_Help_Tour'),
474
-                'metaboxes'     => array('_publish_post_box'),
475
-                'require_nonce' => false,
476
-            ),
477
-            'edit_category'          => array(
478
-                'nav'           => array(
479
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
480
-                    'order'      => 15,
481
-                    'persistent' => false,
482
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
483
-                        ? add_query_arg(
484
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
485
-                            $this->_current_page_view_url
486
-                        )
487
-                        : $this->_admin_base_url,
488
-                ),
489
-                'help_tabs'     => array(
490
-                    'edit_category_help_tab' => array(
491
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
492
-                        'filename' => 'events_edit_category',
493
-                    ),
494
-                ),
495
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
496
-                'metaboxes'     => array('_publish_post_box'),
497
-                'require_nonce' => false,
498
-            ),
499
-            'category_list'          => array(
500
-                'nav'           => array(
501
-                    'label' => esc_html__('Categories', 'event_espresso'),
502
-                    'order' => 20,
503
-                ),
504
-                'list_table'    => 'Event_Categories_Admin_List_Table',
505
-                'help_tabs'     => array(
506
-                    'events_categories_help_tab'                       => array(
507
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
508
-                        'filename' => 'events_categories',
509
-                    ),
510
-                    'events_categories_table_column_headings_help_tab' => array(
511
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
512
-                        'filename' => 'events_categories_table_column_headings',
513
-                    ),
514
-                    'events_categories_view_help_tab'                  => array(
515
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
516
-                        'filename' => 'events_categories_views',
517
-                    ),
518
-                    'events_categories_other_help_tab'                 => array(
519
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
520
-                        'filename' => 'events_categories_other',
521
-                    ),
522
-                ),
523
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
524
-                // 'help_tour'     => array(
525
-                //     'Event_Categories_Help_Tour',
526
-                // ),
527
-                'metaboxes'     => $this->_default_espresso_metaboxes,
528
-                'require_nonce' => false,
529
-            ),
530
-            'preview_deletion'           => array(
531
-                'nav'           => array(
532
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
533
-                    'order'      => 15,
534
-                    'persistent' => false,
535
-                    'url'        => '',
536
-                ),
537
-                'require_nonce' => false
538
-            )
539
-        );
540
-    }
541
-
542
-
543
-    /**
544
-     * Used to register any global screen options if necessary for every route in this admin page group.
545
-     */
546
-    protected function _add_screen_options()
547
-    {
548
-    }
549
-
550
-
551
-    /**
552
-     * Implementing the screen options for the 'default' route.
553
-     */
554
-    protected function _add_screen_options_default()
555
-    {
556
-        $this->_per_page_screen_option();
557
-    }
558
-
559
-
560
-    /**
561
-     * Implementing screen options for the category list route.
562
-     */
563
-    protected function _add_screen_options_category_list()
564
-    {
565
-        $page_title = $this->_admin_page_title;
566
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
567
-        $this->_per_page_screen_option();
568
-        $this->_admin_page_title = $page_title;
569
-    }
570
-
571
-
572
-    /**
573
-     * Used to register any global feature pointers for the admin page group.
574
-     */
575
-    protected function _add_feature_pointers()
576
-    {
577
-    }
578
-
579
-
580
-    /**
581
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
582
-     */
583
-    public function load_scripts_styles()
584
-    {
585
-        wp_register_style(
586
-            'events-admin-css',
587
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
588
-            array(),
589
-            EVENT_ESPRESSO_VERSION
590
-        );
591
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
592
-        wp_enqueue_style('events-admin-css');
593
-        wp_enqueue_style('ee-cat-admin');
594
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
595
-        // registers for all views
596
-        // scripts
597
-        wp_register_script(
598
-            'event_editor_js',
599
-            EVENTS_ASSETS_URL . 'event_editor.js',
600
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
601
-            EVENT_ESPRESSO_VERSION,
602
-            true
603
-        );
604
-    }
605
-
606
-
607
-    /**
608
-     * Enqueuing scripts and styles specific to this view
609
-     */
610
-    public function load_scripts_styles_create_new()
611
-    {
612
-        $this->load_scripts_styles_edit();
613
-    }
614
-
615
-
616
-    /**
617
-     * Enqueuing scripts and styles specific to this view
618
-     */
619
-    public function load_scripts_styles_edit()
620
-    {
621
-        // styles
622
-        wp_enqueue_style('espresso-ui-theme');
623
-        wp_register_style(
624
-            'event-editor-css',
625
-            EVENTS_ASSETS_URL . 'event-editor.css',
626
-            array('ee-admin-css'),
627
-            EVENT_ESPRESSO_VERSION
628
-        );
629
-        wp_enqueue_style('event-editor-css');
630
-        // scripts
631
-        wp_register_script(
632
-            'event-datetime-metabox',
633
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
634
-            array('event_editor_js', 'ee-datepicker'),
635
-            EVENT_ESPRESSO_VERSION
636
-        );
637
-        wp_enqueue_script('event-datetime-metabox');
638
-    }
639
-
640
-
641
-    /**
642
-     * Populating the _views property for the category list table view.
643
-     */
644
-    protected function _set_list_table_views_category_list()
645
-    {
646
-        $this->_views = array(
647
-            'all' => array(
648
-                'slug'        => 'all',
649
-                'label'       => esc_html__('All', 'event_espresso'),
650
-                'count'       => 0,
651
-                'bulk_action' => array(
652
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
653
-                ),
654
-            ),
655
-        );
656
-    }
657
-
658
-
659
-    /**
660
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
661
-     */
662
-    public function admin_init()
663
-    {
664
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
665
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
666
-            'event_espresso'
667
-        );
668
-    }
669
-
670
-
671
-    /**
672
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
673
-     * group.
674
-     */
675
-    public function admin_notices()
676
-    {
677
-    }
678
-
679
-
680
-    /**
681
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
682
-     * this admin page group.
683
-     */
684
-    public function admin_footer_scripts()
685
-    {
686
-    }
687
-
688
-
689
-    /**
690
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
691
-     * warning (via EE_Error::add_error());
692
-     *
693
-     * @param  EE_Event $event Event object
694
-     * @param string    $req_type
695
-     * @return void
696
-     * @throws EE_Error
697
-     * @access public
698
-     */
699
-    public function verify_event_edit($event = null, $req_type = '')
700
-    {
701
-        // don't need to do this when processing
702
-        if (! empty($req_type)) {
703
-            return;
704
-        }
705
-        // no event?
706
-        if (empty($event)) {
707
-            // set event
708
-            $event = $this->_cpt_model_obj;
709
-        }
710
-        // STILL no event?
711
-        if (! $event instanceof EE_Event) {
712
-            return;
713
-        }
714
-        $orig_status = $event->status();
715
-        // first check if event is active.
716
-        if ($orig_status === EEM_Event::cancelled
717
-            || $orig_status === EEM_Event::postponed
718
-            || $event->is_expired()
719
-            || $event->is_inactive()
720
-        ) {
721
-            return;
722
-        }
723
-        // made it here so it IS active... next check that any of the tickets are sold.
724
-        if ($event->is_sold_out(true)) {
725
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
726
-                EE_Error::add_attention(
727
-                    sprintf(
728
-                        esc_html__(
729
-                            '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.',
730
-                            'event_espresso'
731
-                        ),
732
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
733
-                    )
734
-                );
735
-            }
736
-            return;
737
-        } elseif ($orig_status === EEM_Event::sold_out) {
738
-            EE_Error::add_attention(
739
-                sprintf(
740
-                    esc_html__(
741
-                        '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.',
742
-                        'event_espresso'
743
-                    ),
744
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
745
-                )
746
-            );
747
-        }
748
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
-        if (! $event->tickets_on_sale()) {
750
-            return;
751
-        }
752
-        // made it here so show warning
753
-        $this->_edit_event_warning();
754
-    }
755
-
756
-
757
-    /**
758
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
759
-     * When needed, hook this into a EE_Error::add_error() notice.
760
-     *
761
-     * @access protected
762
-     * @return void
763
-     */
764
-    protected function _edit_event_warning()
765
-    {
766
-        // we don't want to add warnings during these requests
767
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
768
-            return;
769
-        }
770
-        EE_Error::add_attention(
771
-            sprintf(
772
-                esc_html__(
773
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
774
-                    'event_espresso'
775
-                ),
776
-                '<a class="espresso-help-tab-lnk">',
777
-                '</a>'
778
-            )
779
-        );
780
-    }
781
-
782
-
783
-    /**
784
-     * When a user is creating a new event, notify them if they haven't set their timezone.
785
-     * Otherwise, do the normal logic
786
-     *
787
-     * @return string
788
-     * @throws \EE_Error
789
-     */
790
-    protected function _create_new_cpt_item()
791
-    {
792
-        $has_timezone_string = get_option('timezone_string');
793
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
794
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795
-            EE_Error::add_attention(
796
-                sprintf(
797
-                    __(
798
-                        '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',
799
-                        'event_espresso'
800
-                    ),
801
-                    '<br>',
802
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
803
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
804
-                    . '</select>',
805
-                    '<button class="button button-secondary timezone-submit">',
806
-                    '</button><span class="spinner"></span>'
807
-                ),
808
-                __FILE__,
809
-                __FUNCTION__,
810
-                __LINE__
811
-            );
812
-        }
813
-        return parent::_create_new_cpt_item();
814
-    }
815
-
816
-
817
-    /**
818
-     * Sets the _views property for the default route in this admin page group.
819
-     */
820
-    protected function _set_list_table_views_default()
821
-    {
822
-        $this->_views = array(
823
-            'all'   => array(
824
-                'slug'        => 'all',
825
-                'label'       => esc_html__('View All Events', 'event_espresso'),
826
-                'count'       => 0,
827
-                'bulk_action' => array(
828
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
829
-                ),
830
-            ),
831
-            'draft' => array(
832
-                'slug'        => 'draft',
833
-                'label'       => esc_html__('Draft', 'event_espresso'),
834
-                'count'       => 0,
835
-                'bulk_action' => array(
836
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
837
-                ),
838
-            ),
839
-        );
840
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
841
-            $this->_views['trash'] = array(
842
-                'slug'        => 'trash',
843
-                'label'       => esc_html__('Trash', 'event_espresso'),
844
-                'count'       => 0,
845
-                'bulk_action' => array(
846
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
847
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
848
-                ),
849
-            );
850
-        }
851
-    }
852
-
853
-
854
-    /**
855
-     * Provides the legend item array for the default list table view.
856
-     *
857
-     * @return array
858
-     */
859
-    protected function _event_legend_items()
860
-    {
861
-        $items = array(
862
-            'view_details'   => array(
863
-                'class' => 'dashicons dashicons-search',
864
-                'desc'  => esc_html__('View Event', 'event_espresso'),
865
-            ),
866
-            'edit_event'     => array(
867
-                'class' => 'ee-icon ee-icon-calendar-edit',
868
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
869
-            ),
870
-            'view_attendees' => array(
871
-                'class' => 'dashicons dashicons-groups',
872
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
873
-            ),
874
-        );
875
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876
-        $statuses = array(
877
-            'sold_out_status'  => array(
878
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
879
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880
-            ),
881
-            'active_status'    => array(
882
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
883
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884
-            ),
885
-            'upcoming_status'  => array(
886
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
887
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888
-            ),
889
-            'postponed_status' => array(
890
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
891
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892
-            ),
893
-            'cancelled_status' => array(
894
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
895
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896
-            ),
897
-            'expired_status'   => array(
898
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
899
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900
-            ),
901
-            'inactive_status'  => array(
902
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
903
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904
-            ),
905
-        );
906
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
907
-        return array_merge($items, $statuses);
908
-    }
909
-
910
-
911
-    /**
912
-     * @return EEM_Event
913
-     */
914
-    private function _event_model()
915
-    {
916
-        if (! $this->_event_model instanceof EEM_Event) {
917
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
918
-        }
919
-        return $this->_event_model;
920
-    }
921
-
922
-
923
-    /**
924
-     * Adds extra buttons to the WP CPT permalink field row.
925
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
926
-     *
927
-     * @param  string $return    the current html
928
-     * @param  int    $id        the post id for the page
929
-     * @param  string $new_title What the title is
930
-     * @param  string $new_slug  what the slug is
931
-     * @return string            The new html string for the permalink area
932
-     */
933
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934
-    {
935
-        // make sure this is only when editing
936
-        if (! empty($id)) {
937
-            $post = get_post($id);
938
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939
-                       . esc_html__('Shortcode', 'event_espresso')
940
-                       . '</a> ';
941
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
942
-                       . $post->ID
943
-                       . ']">';
944
-        }
945
-        return $return;
946
-    }
947
-
948
-
949
-    /**
950
-     * _events_overview_list_table
951
-     * This contains the logic for showing the events_overview list
952
-     *
953
-     * @access protected
954
-     * @return void
955
-     * @throws \EE_Error
956
-     */
957
-    protected function _events_overview_list_table()
958
-    {
959
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
960
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
961
-            ? (array) $this->_template_args['after_list_table']
962
-            : array();
963
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
964
-                . EEH_Template::get_button_or_link(
965
-                    get_post_type_archive_link('espresso_events'),
966
-                    esc_html__("View Event Archive Page", "event_espresso"),
967
-                    'button'
968
-                );
969
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
971
-            'create_new',
972
-            'add',
973
-            array(),
974
-            'add-new-h2'
975
-        );
976
-        $this->display_admin_list_table_page_with_no_sidebar();
977
-    }
978
-
979
-
980
-    /**
981
-     * this allows for extra misc actions in the default WP publish box
982
-     *
983
-     * @return void
984
-     */
985
-    public function extra_misc_actions_publish_box()
986
-    {
987
-        $this->_generate_publish_box_extra_content();
988
-    }
989
-
990
-
991
-    /**
992
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
993
-     * saved.
994
-     * Typically you would use this to save any additional data.
995
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
996
-     * ALSO very important.  When a post transitions from scheduled to published,
997
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
998
-     * other meta saves. So MAKE sure that you handle this accordingly.
999
-     *
1000
-     * @access protected
1001
-     * @abstract
1002
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
1003
-     * @param  object $post    The post object of the cpt that was saved.
1004
-     * @return void
1005
-     * @throws \EE_Error
1006
-     */
1007
-    protected function _insert_update_cpt_item($post_id, $post)
1008
-    {
1009
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1010
-            // get out we're not processing an event save.
1011
-            return;
1012
-        }
1013
-        $event_values = array(
1014
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1015
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1016
-            'EVT_additional_limit'            => min(
1017
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1018
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1019
-            ),
1020
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1021
-                ? $this->_req_data['EVT_default_registration_status']
1022
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
1023
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1024
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1025
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1026
-                ? $this->_req_data['timezone_string'] : null,
1027
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1028
-                ? $this->_req_data['externalURL'] : null,
1029
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1030
-                ? $this->_req_data['event_phone'] : null,
1031
-        );
1032
-        // update event
1033
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1034
-        // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_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!
1035
-        $get_one_where = array(
1036
-            $this->_event_model()->primary_key_name() => $post_id,
1037
-            'OR'                                      => array(
1038
-                'status'   => $post->post_status,
1039
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1040
-                // but the returned object here has a status of "publish", so use the original post status as well
1041
-                'status*1' => $this->_req_data['original_post_status'],
1042
-            ),
1043
-        );
1044
-        $event = $this->_event_model()->get_one(array($get_one_where));
1045
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1046
-        $event_update_callbacks = apply_filters(
1047
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1048
-            array(
1049
-                array($this, '_default_venue_update'),
1050
-                array($this, '_default_tickets_update'),
1051
-            )
1052
-        );
1053
-        $att_success = true;
1054
-        foreach ($event_update_callbacks as $e_callback) {
1055
-            $_success = is_callable($e_callback)
1056
-                ? call_user_func($e_callback, $event, $this->_req_data)
1057
-                : false;
1058
-            // if ANY of these updates fail then we want the appropriate global error message
1059
-            $att_success = ! $att_success ? $att_success : $_success;
1060
-        }
1061
-        // any errors?
1062
-        if ($success && false === $att_success) {
1063
-            EE_Error::add_error(
1064
-                esc_html__(
1065
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1066
-                    'event_espresso'
1067
-                ),
1068
-                __FILE__,
1069
-                __FUNCTION__,
1070
-                __LINE__
1071
-            );
1072
-        } elseif ($success === false) {
1073
-            EE_Error::add_error(
1074
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1075
-                __FILE__,
1076
-                __FUNCTION__,
1077
-                __LINE__
1078
-            );
1079
-        }
1080
-    }
1081
-
1082
-
1083
-    /**
1084
-     * @see parent::restore_item()
1085
-     * @param int $post_id
1086
-     * @param int $revision_id
1087
-     */
1088
-    protected function _restore_cpt_item($post_id, $revision_id)
1089
-    {
1090
-        // copy existing event meta to new post
1091
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1092
-        if ($post_evt instanceof EE_Event) {
1093
-            // meta revision restore
1094
-            $post_evt->restore_revision($revision_id);
1095
-            // related objs restore
1096
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1097
-        }
1098
-    }
1099
-
1100
-
1101
-    /**
1102
-     * Attach the venue to the Event
1103
-     *
1104
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1105
-     * @param  array     $data   The request data from the form
1106
-     * @return bool           Success or fail.
1107
-     */
1108
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1109
-    {
1110
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1111
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1112
-        $rows_affected = null;
1113
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1114
-        // very important.  If we don't have a venue name...
1115
-        // then we'll get out because not necessary to create empty venue
1116
-        if (empty($data['venue_title'])) {
1117
-            return false;
1118
-        }
1119
-        $venue_array = array(
1120
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1121
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1122
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1123
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1124
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1125
-                : null,
1126
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1127
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1128
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1129
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1130
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1131
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1132
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1133
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1134
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1135
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1136
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1137
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1138
-            'status'              => 'publish',
1139
-        );
1140
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
-        if (! empty($venue_id)) {
1142
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1143
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1144
-            // 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.
1145
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1146
-            return $rows_affected > 0 ? true : false;
1147
-        } else {
1148
-            // we insert the venue
1149
-            $venue_id = $venue_model->insert($venue_array);
1150
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1151
-            return ! empty($venue_id) ? true : false;
1152
-        }
1153
-        // when we have the ancestor come in it's already been handled by the revision save.
1154
-    }
1155
-
1156
-
1157
-    /**
1158
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1159
-     *
1160
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1161
-     * @param  array    $data   The request data from the form
1162
-     * @return array
1163
-     */
1164
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1165
-    {
1166
-        $success = true;
1167
-        $saved_dtt = null;
1168
-        $saved_tickets = array();
1169
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1170
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1171
-            // trim all values to ensure any excess whitespace is removed.
1172
-            $dtt = array_map('trim', $dtt);
1173
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1174
-                : $dtt['DTT_EVT_start'];
1175
-            $datetime_values = array(
1176
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1177
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1178
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1179
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1180
-                'DTT_order'     => $row,
1181
-            );
1182
-            // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
-            if (! empty($dtt['DTT_ID'])) {
1184
-                $DTM = EE_Registry::instance()
1185
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1186
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1187
-                $DTM->set_date_format($incoming_date_formats[0]);
1188
-                $DTM->set_time_format($incoming_date_formats[1]);
1189
-                foreach ($datetime_values as $field => $value) {
1190
-                    $DTM->set($field, $value);
1191
-                }
1192
-                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1194
-            } else {
1195
-                $DTM = EE_Registry::instance()->load_class(
1196
-                    'Datetime',
1197
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1198
-                    false,
1199
-                    false
1200
-                );
1201
-                foreach ($datetime_values as $field => $value) {
1202
-                    $DTM->set($field, $value);
1203
-                }
1204
-            }
1205
-            $DTM->save();
1206
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1207
-            // load DTT helper
1208
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1209
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1210
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1211
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1212
-                $DTT->save();
1213
-            }
1214
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1215
-            $saved_dtt = $DTT;
1216
-            $success = ! $success ? $success : $DTT;
1217
-            // if ANY of these updates fail then we want the appropriate global error message.
1218
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1219
-        }
1220
-        // no dtts get deleted so we don't do any of that logic here.
1221
-        // update tickets next
1222
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1223
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1224
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1225
-            $update_prices = false;
1226
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1228
-            // trim inputs to ensure any excess whitespace is removed.
1229
-            $tkt = array_map('trim', $tkt);
1230
-            if (empty($tkt['TKT_start_date'])) {
1231
-                // let's use now in the set timezone.
1232
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1234
-            }
1235
-            if (empty($tkt['TKT_end_date'])) {
1236
-                // use the start date of the first datetime
1237
-                $dtt = $evtobj->first_datetime();
1238
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1239
-                    $incoming_date_formats[0],
1240
-                    $incoming_date_formats[1]
1241
-                );
1242
-            }
1243
-            $TKT_values = array(
1244
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1245
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1246
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1247
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1248
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1249
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1250
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1251
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1252
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1253
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1254
-                'TKT_row'         => $row,
1255
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1256
-                'TKT_price'       => $ticket_price,
1257
-            );
1258
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1259
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1260
-                $TKT_values['TKT_ID'] = 0;
1261
-                $TKT_values['TKT_is_default'] = 0;
1262
-                $TKT_values['TKT_price'] = $ticket_price;
1263
-                $update_prices = true;
1264
-            }
1265
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266
-            // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267
-            // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
-            if (! empty($tkt['TKT_ID'])) {
1269
-                $TKT = EE_Registry::instance()
1270
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1271
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1272
-                if ($TKT instanceof EE_Ticket) {
1273
-                    $ticket_sold = $TKT->count_related(
1274
-                        'Registration',
1275
-                        array(
1276
-                            array(
1277
-                                'STS_ID' => array(
1278
-                                    'NOT IN',
1279
-                                    array(EEM_Registration::status_id_incomplete),
1280
-                                ),
1281
-                            ),
1282
-                        )
1283
-                    ) > 0 ? true : false;
1284
-                    // let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1285
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1286
-                                      && ! $TKT->get('TKT_deleted');
1287
-                    $TKT->set_date_format($incoming_date_formats[0]);
1288
-                    $TKT->set_time_format($incoming_date_formats[1]);
1289
-                    // set new values
1290
-                    foreach ($TKT_values as $field => $value) {
1291
-                        if ($field == 'TKT_qty') {
1292
-                            $TKT->set_qty($value);
1293
-                        } else {
1294
-                            $TKT->set($field, $value);
1295
-                        }
1296
-                    }
1297
-                    // if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1298
-                    if ($create_new_TKT) {
1299
-                        // archive the old ticket first
1300
-                        $TKT->set('TKT_deleted', 1);
1301
-                        $TKT->save();
1302
-                        // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1304
-                        // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305
-                        $TKT = clone $TKT;
1306
-                        $TKT->set('TKT_ID', 0);
1307
-                        $TKT->set('TKT_deleted', 0);
1308
-                        $TKT->set('TKT_price', $ticket_price);
1309
-                        $TKT->set('TKT_sold', 0);
1310
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1311
-                        $update_prices = true;
1312
-                    }
1313
-                    // make sure price is set if it hasn't been already
1314
-                    $TKT->set('TKT_price', $ticket_price);
1315
-                }
1316
-            } else {
1317
-                // no TKT_id so a new TKT
1318
-                $TKT_values['TKT_price'] = $ticket_price;
1319
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1320
-                if ($TKT instanceof EE_Ticket) {
1321
-                    // need to reset values to properly account for the date formats
1322
-                    $TKT->set_date_format($incoming_date_formats[0]);
1323
-                    $TKT->set_time_format($incoming_date_formats[1]);
1324
-                    $TKT->set_timezone($evtobj->get_timezone());
1325
-                    // set new values
1326
-                    foreach ($TKT_values as $field => $value) {
1327
-                        if ($field == 'TKT_qty') {
1328
-                            $TKT->set_qty($value);
1329
-                        } else {
1330
-                            $TKT->set($field, $value);
1331
-                        }
1332
-                    }
1333
-                    $update_prices = true;
1334
-                }
1335
-            }
1336
-            // cap ticket qty by datetime reg limits
1337
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1338
-            // update ticket.
1339
-            $TKT->save();
1340
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1341
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1342
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1343
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1344
-                $TKT->save();
1345
-            }
1346
-            // initially let's add the ticket to the dtt
1347
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1349
-            // add prices to ticket
1350
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1351
-        }
1352
-        // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1354
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1355
-        foreach ($tickets_removed as $id) {
1356
-            $id = absint($id);
1357
-            // get the ticket for this id
1358
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1359
-            // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1360
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1361
-            foreach ($dtts as $dtt) {
1362
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1363
-            }
1364
-            // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1365
-            $tkt_to_remove->delete_related_permanently('Price');
1366
-            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1367
-            $tkt_to_remove->delete_permanently();
1368
-        }
1369
-        return array($saved_dtt, $saved_tickets);
1370
-    }
1371
-
1372
-
1373
-    /**
1374
-     * This attaches a list of given prices to a ticket.
1375
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1376
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1377
-     * price info and prices are automatically "archived" via the ticket.
1378
-     *
1379
-     * @access  private
1380
-     * @param array     $prices     Array of prices from the form.
1381
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1382
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1383
-     * @return  void
1384
-     */
1385
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1386
-    {
1387
-        foreach ($prices as $row => $prc) {
1388
-            $PRC_values = array(
1389
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1390
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1391
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1392
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1393
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1394
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1395
-                'PRC_order'      => $row,
1396
-            );
1397
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1398
-                $PRC_values['PRC_ID'] = 0;
1399
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1400
-            } else {
1401
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1402
-                // update this price with new values
1403
-                foreach ($PRC_values as $field => $newprc) {
1404
-                    $PRC->set($field, $newprc);
1405
-                }
1406
-                $PRC->save();
1407
-            }
1408
-            $ticket->_add_relation_to($PRC, 'Price');
1409
-        }
1410
-    }
1411
-
1412
-
1413
-    /**
1414
-     * Add in our autosave ajax handlers
1415
-     *
1416
-     */
1417
-    protected function _ee_autosave_create_new()
1418
-    {
1419
-    }
1420
-
1421
-
1422
-    /**
1423
-     * More autosave handlers.
1424
-     */
1425
-    protected function _ee_autosave_edit()
1426
-    {
1427
-        return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1428
-    }
1429
-
1430
-
1431
-    /**
1432
-     *    _generate_publish_box_extra_content
1433
-     */
1434
-    private function _generate_publish_box_extra_content()
1435
-    {
1436
-        // load formatter helper
1437
-        // args for getting related registrations
1438
-        $approved_query_args = array(
1439
-            array(
1440
-                'REG_deleted' => 0,
1441
-                'STS_ID'      => EEM_Registration::status_id_approved,
1442
-            ),
1443
-        );
1444
-        $not_approved_query_args = array(
1445
-            array(
1446
-                'REG_deleted' => 0,
1447
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1448
-            ),
1449
-        );
1450
-        $pending_payment_query_args = array(
1451
-            array(
1452
-                'REG_deleted' => 0,
1453
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1454
-            ),
1455
-        );
1456
-        // publish box
1457
-        $publish_box_extra_args = array(
1458
-            'view_approved_reg_url'        => add_query_arg(
1459
-                array(
1460
-                    'action'      => 'default',
1461
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1462
-                    '_reg_status' => EEM_Registration::status_id_approved,
1463
-                ),
1464
-                REG_ADMIN_URL
1465
-            ),
1466
-            'view_not_approved_reg_url'    => add_query_arg(
1467
-                array(
1468
-                    'action'      => 'default',
1469
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1470
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1471
-                ),
1472
-                REG_ADMIN_URL
1473
-            ),
1474
-            'view_pending_payment_reg_url' => add_query_arg(
1475
-                array(
1476
-                    'action'      => 'default',
1477
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1478
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1479
-                ),
1480
-                REG_ADMIN_URL
1481
-            ),
1482
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1483
-                'Registration',
1484
-                $approved_query_args
1485
-            ),
1486
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1487
-                'Registration',
1488
-                $not_approved_query_args
1489
-            ),
1490
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1491
-                'Registration',
1492
-                $pending_payment_query_args
1493
-            ),
1494
-            'misc_pub_section_class'       => apply_filters(
1495
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1496
-                'misc-pub-section'
1497
-            ),
1498
-        );
1499
-        ob_start();
1500
-        do_action(
1501
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1502
-            $this->_cpt_model_obj
1503
-        );
1504
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1505
-        // load template
1506
-        EEH_Template::display_template(
1507
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1508
-            $publish_box_extra_args
1509
-        );
1510
-    }
1511
-
1512
-
1513
-    /**
1514
-     * @return EE_Event
1515
-     */
1516
-    public function get_event_object()
1517
-    {
1518
-        return $this->_cpt_model_obj;
1519
-    }
1520
-
1521
-
1522
-
1523
-
1524
-    /** METABOXES * */
1525
-    /**
1526
-     * _register_event_editor_meta_boxes
1527
-     * add all metaboxes related to the event_editor
1528
-     *
1529
-     * @return void
1530
-     */
1531
-    protected function _register_event_editor_meta_boxes()
1532
-    {
1533
-        $this->verify_cpt_object();
1534
-        add_meta_box(
1535
-            'espresso_event_editor_tickets',
1536
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1537
-            array($this, 'ticket_metabox'),
1538
-            $this->page_slug,
1539
-            'normal',
1540
-            'high'
1541
-        );
1542
-        add_meta_box(
1543
-            'espresso_event_editor_event_options',
1544
-            esc_html__('Event Registration Options', 'event_espresso'),
1545
-            array($this, 'registration_options_meta_box'),
1546
-            $this->page_slug,
1547
-            'side',
1548
-            'default'
1549
-        );
1550
-        // NOTE: if you're looking for other metaboxes in here,
1551
-        // where a metabox has a related management page in the admin
1552
-        // you will find it setup in the related management page's "_Hooks" file.
1553
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1554
-    }
1555
-
1556
-
1557
-    /**
1558
-     * @throws DomainException
1559
-     * @throws EE_Error
1560
-     */
1561
-    public function ticket_metabox()
1562
-    {
1563
-        $existing_datetime_ids = $existing_ticket_ids = array();
1564
-        // defaults for template args
1565
-        $template_args = array(
1566
-            'existing_datetime_ids'    => '',
1567
-            'event_datetime_help_link' => '',
1568
-            'ticket_options_help_link' => '',
1569
-            'time'                     => null,
1570
-            'ticket_rows'              => '',
1571
-            'existing_ticket_ids'      => '',
1572
-            'total_ticket_rows'        => 1,
1573
-            'ticket_js_structure'      => '',
1574
-            'trash_icon'               => 'ee-lock-icon',
1575
-            'disabled'                 => '',
1576
-        );
1577
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1578
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1579
-        /**
1580
-         * 1. Start with retrieving Datetimes
1581
-         * 2. Fore each datetime get related tickets
1582
-         * 3. For each ticket get related prices
1583
-         */
1584
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1585
-        /** @type EE_Datetime $first_datetime */
1586
-        $first_datetime = reset($times);
1587
-        // do we get related tickets?
1588
-        if ($first_datetime instanceof EE_Datetime
1589
-            && $first_datetime->ID() !== 0
1590
-        ) {
1591
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1592
-            $template_args['time'] = $first_datetime;
1593
-            $related_tickets = $first_datetime->tickets(
1594
-                array(
1595
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1596
-                    'default_where_conditions' => 'none',
1597
-                )
1598
-            );
1599
-            if (! empty($related_tickets)) {
1600
-                $template_args['total_ticket_rows'] = count($related_tickets);
1601
-                $row = 0;
1602
-                foreach ($related_tickets as $ticket) {
1603
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1604
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1605
-                    $row++;
1606
-                }
1607
-            } else {
1608
-                $template_args['total_ticket_rows'] = 1;
1609
-                /** @type EE_Ticket $ticket */
1610
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1611
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1612
-            }
1613
-        } else {
1614
-            $template_args['time'] = $times[0];
1615
-            /** @type EE_Ticket $ticket */
1616
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1617
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1618
-            // NOTE: we're just sending the first default row
1619
-            // (decaf can't manage default tickets so this should be sufficient);
1620
-        }
1621
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1622
-            'event_editor_event_datetimes_help_tab'
1623
-        );
1624
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1625
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1626
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1627
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1628
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1629
-            true
1630
-        );
1631
-        $template = apply_filters(
1632
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1633
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1634
-        );
1635
-        EEH_Template::display_template($template, $template_args);
1636
-    }
1637
-
1638
-
1639
-    /**
1640
-     * Setup an individual ticket form for the decaf event editor page
1641
-     *
1642
-     * @access private
1643
-     * @param  EE_Ticket $ticket   the ticket object
1644
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1645
-     * @param int        $row
1646
-     * @return string generated html for the ticket row.
1647
-     */
1648
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1649
-    {
1650
-        $template_args = array(
1651
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1652
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1653
-                : '',
1654
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1655
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1656
-            'TKT_name'            => $ticket->get('TKT_name'),
1657
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1658
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1659
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1660
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1661
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1662
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1663
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1664
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1665
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1666
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1667
-                : ' disabled=disabled',
1668
-        );
1669
-        $price = $ticket->ID() !== 0
1670
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1671
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1672
-        $price_args = array(
1673
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1674
-            'PRC_amount'            => $price->get('PRC_amount'),
1675
-            'PRT_ID'                => $price->get('PRT_ID'),
1676
-            'PRC_ID'                => $price->get('PRC_ID'),
1677
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1678
-        );
1679
-        // make sure we have default start and end dates if skeleton
1680
-        // handle rows that should NOT be empty
1681
-        if (empty($template_args['TKT_start_date'])) {
1682
-            // if empty then the start date will be now.
1683
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1684
-        }
1685
-        if (empty($template_args['TKT_end_date'])) {
1686
-            // get the earliest datetime (if present);
1687
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1688
-                ? $this->_cpt_model_obj->get_first_related(
1689
-                    'Datetime',
1690
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1691
-                )
1692
-                : null;
1693
-            if (! empty($earliest_dtt)) {
1694
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1695
-            } else {
1696
-                $template_args['TKT_end_date'] = date(
1697
-                    'Y-m-d h:i a',
1698
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1699
-                );
1700
-            }
1701
-        }
1702
-        $template_args = array_merge($template_args, $price_args);
1703
-        $template = apply_filters(
1704
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1705
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1706
-            $ticket
1707
-        );
1708
-        return EEH_Template::display_template($template, $template_args, true);
1709
-    }
1710
-
1711
-
1712
-    /**
1713
-     * @throws DomainException
1714
-     */
1715
-    public function registration_options_meta_box()
1716
-    {
1717
-        $yes_no_values = array(
1718
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1719
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1720
-        );
1721
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1722
-            array(
1723
-                EEM_Registration::status_id_cancelled,
1724
-                EEM_Registration::status_id_declined,
1725
-                EEM_Registration::status_id_incomplete,
1726
-            ),
1727
-            true
1728
-        );
1729
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1730
-        $template_args['_event'] = $this->_cpt_model_obj;
1731
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1732
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1733
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1734
-            'default_reg_status',
1735
-            $default_reg_status_values,
1736
-            $this->_cpt_model_obj->default_registration_status()
1737
-        );
1738
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1739
-            'display_desc',
1740
-            $yes_no_values,
1741
-            $this->_cpt_model_obj->display_description()
1742
-        );
1743
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1744
-            'display_ticket_selector',
1745
-            $yes_no_values,
1746
-            $this->_cpt_model_obj->display_ticket_selector(),
1747
-            '',
1748
-            '',
1749
-            false
1750
-        );
1751
-        $template_args['additional_registration_options'] = apply_filters(
1752
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1753
-            '',
1754
-            $template_args,
1755
-            $yes_no_values,
1756
-            $default_reg_status_values
1757
-        );
1758
-        EEH_Template::display_template(
1759
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1760
-            $template_args
1761
-        );
1762
-    }
1763
-
1764
-
1765
-    /**
1766
-     * _get_events()
1767
-     * This method simply returns all the events (for the given _view and paging)
1768
-     *
1769
-     * @access public
1770
-     * @param int  $per_page     count of items per page (20 default);
1771
-     * @param int  $current_page what is the current page being viewed.
1772
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1773
-     *                           If FALSE then we return an array of event objects
1774
-     *                           that match the given _view and paging parameters.
1775
-     * @return array an array of event objects.
1776
-     */
1777
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1778
-    {
1779
-        $EEME = $this->_event_model();
1780
-        $offset = ($current_page - 1) * $per_page;
1781
-        $limit = $count ? null : $offset . ',' . $per_page;
1782
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1783
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1784
-        if (isset($this->_req_data['month_range'])) {
1785
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1786
-            // simulate the FIRST day of the month, that fixes issues for months like February
1787
-            // where PHP doesn't know what to assume for date.
1788
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1789
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1790
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1791
-        }
1792
-        $where = array();
1793
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1794
-        // determine what post_status our condition will have for the query.
1795
-        switch ($status) {
1796
-            case 'month':
1797
-            case 'today':
1798
-            case null:
1799
-            case 'all':
1800
-                break;
1801
-            case 'draft':
1802
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1803
-                break;
1804
-            default:
1805
-                $where['status'] = $status;
1806
-        }
1807
-        // categories?
1808
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1809
-            ? $this->_req_data['EVT_CAT'] : null;
1810
-        if (! empty($category)) {
1811
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1812
-            $where['Term_Taxonomy.term_id'] = $category;
1813
-        }
1814
-        // date where conditions
1815
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1816
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1817
-            $DateTime = new DateTime(
1818
-                $year_r . '-' . $month_r . '-01 00:00:00',
1819
-                new DateTimeZone('UTC')
1820
-            );
1821
-            $start = $DateTime->getTimestamp();
1822
-            // set the datetime to be the end of the month
1823
-            $DateTime->setDate(
1824
-                $year_r,
1825
-                $month_r,
1826
-                $DateTime->format('t')
1827
-            )->setTime(23, 59, 59);
1828
-            $end = $DateTime->getTimestamp();
1829
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1830
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1831
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1832
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1833
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1834
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1835
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1836
-            $now = date('Y-m-01');
1837
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1838
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1839
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1840
-                            ->setTime(23, 59, 59)
1841
-                            ->format(implode(' ', $start_formats));
1842
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1843
-        }
1844
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1845
-            $where['EVT_wp_user'] = get_current_user_id();
1846
-        } else {
1847
-            if (! isset($where['status'])) {
1848
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1849
-                    $where['OR'] = array(
1850
-                        'status*restrict_private' => array('!=', 'private'),
1851
-                        'AND'                     => array(
1852
-                            'status*inclusive' => array('=', 'private'),
1853
-                            'EVT_wp_user'      => get_current_user_id(),
1854
-                        ),
1855
-                    );
1856
-                }
1857
-            }
1858
-        }
1859
-        if (isset($this->_req_data['EVT_wp_user'])) {
1860
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1861
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1862
-            ) {
1863
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1864
-            }
1865
-        }
1866
-        // search query handling
1867
-        if (isset($this->_req_data['s'])) {
1868
-            $search_string = '%' . $this->_req_data['s'] . '%';
1869
-            $where['OR'] = array(
1870
-                'EVT_name'       => array('LIKE', $search_string),
1871
-                'EVT_desc'       => array('LIKE', $search_string),
1872
-                'EVT_short_desc' => array('LIKE', $search_string),
1873
-            );
1874
-        }
1875
-        // filter events by venue.
1876
-        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1877
-            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1878
-        }
1879
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1880
-        $query_params = apply_filters(
1881
-            'FHEE__Events_Admin_Page__get_events__query_params',
1882
-            array(
1883
-                $where,
1884
-                'limit'    => $limit,
1885
-                'order_by' => $orderby,
1886
-                'order'    => $order,
1887
-                'group_by' => 'EVT_ID',
1888
-            ),
1889
-            $this->_req_data
1890
-        );
1891
-
1892
-        // let's first check if we have special requests coming in.
1893
-        if (isset($this->_req_data['active_status'])) {
1894
-            switch ($this->_req_data['active_status']) {
1895
-                case 'upcoming':
1896
-                    return $EEME->get_upcoming_events($query_params, $count);
1897
-                    break;
1898
-                case 'expired':
1899
-                    return $EEME->get_expired_events($query_params, $count);
1900
-                    break;
1901
-                case 'active':
1902
-                    return $EEME->get_active_events($query_params, $count);
1903
-                    break;
1904
-                case 'inactive':
1905
-                    return $EEME->get_inactive_events($query_params, $count);
1906
-                    break;
1907
-            }
1908
-        }
1909
-
1910
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1911
-        return $events;
1912
-    }
1913
-
1914
-
1915
-    /**
1916
-     * handling for WordPress CPT actions (trash, restore, delete)
1917
-     *
1918
-     * @param string $post_id
1919
-     */
1920
-    public function trash_cpt_item($post_id)
1921
-    {
1922
-        $this->_req_data['EVT_ID'] = $post_id;
1923
-        $this->_trash_or_restore_event('trash', false);
1924
-    }
1925
-
1926
-
1927
-    /**
1928
-     * @param string $post_id
1929
-     */
1930
-    public function restore_cpt_item($post_id)
1931
-    {
1932
-        $this->_req_data['EVT_ID'] = $post_id;
1933
-        $this->_trash_or_restore_event('draft', false);
1934
-    }
1935
-
1936
-
1937
-    /**
1938
-     * @param string $post_id
1939
-     */
1940
-    public function delete_cpt_item($post_id)
1941
-    {
1942
-        throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso'));
1943
-        $this->_req_data['EVT_ID'] = $post_id;
1944
-        $this->_delete_event();
1945
-    }
1946
-
1947
-
1948
-    /**
1949
-     * _trash_or_restore_event
1950
-     *
1951
-     * @access protected
1952
-     * @param  string $event_status
1953
-     * @param bool    $redirect_after
1954
-     */
1955
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1956
-    {
1957
-        // determine the event id and set to array.
1958
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1959
-        // loop thru events
1960
-        if ($EVT_ID) {
1961
-            // clean status
1962
-            $event_status = sanitize_key($event_status);
1963
-            // grab status
1964
-            if (! empty($event_status)) {
1965
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1966
-            } else {
1967
-                $success = false;
1968
-                $msg = esc_html__(
1969
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1970
-                    'event_espresso'
1971
-                );
1972
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1973
-            }
1974
-        } else {
1975
-            $success = false;
1976
-            $msg = esc_html__(
1977
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1978
-                'event_espresso'
1979
-            );
1980
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1981
-        }
1982
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1983
-        if ($redirect_after) {
1984
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1985
-        }
1986
-    }
1987
-
1988
-
1989
-    /**
1990
-     * _trash_or_restore_events
1991
-     *
1992
-     * @access protected
1993
-     * @param  string $event_status
1994
-     * @return void
1995
-     */
1996
-    protected function _trash_or_restore_events($event_status = 'trash')
1997
-    {
1998
-        // clean status
1999
-        $event_status = sanitize_key($event_status);
2000
-        // grab status
2001
-        if (! empty($event_status)) {
2002
-            $success = true;
2003
-            // determine the event id and set to array.
2004
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2005
-            // loop thru events
2006
-            foreach ($EVT_IDs as $EVT_ID) {
2007
-                if ($EVT_ID = absint($EVT_ID)) {
2008
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2009
-                    $success = $results !== false ? $success : false;
2010
-                } else {
2011
-                    $msg = sprintf(
2012
-                        esc_html__(
2013
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2014
-                            'event_espresso'
2015
-                        ),
2016
-                        $EVT_ID
2017
-                    );
2018
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2019
-                    $success = false;
2020
-                }
2021
-            }
2022
-        } else {
2023
-            $success = false;
2024
-            $msg = esc_html__(
2025
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2026
-                'event_espresso'
2027
-            );
2028
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2029
-        }
2030
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2031
-        $success = $success ? 2 : false;
2032
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2033
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2034
-    }
2035
-
2036
-
2037
-    /**
2038
-     * _trash_or_restore_events
2039
-     *
2040
-     * @access  private
2041
-     * @param  int    $EVT_ID
2042
-     * @param  string $event_status
2043
-     * @return bool
2044
-     */
2045
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2046
-    {
2047
-        // grab event id
2048
-        if (! $EVT_ID) {
2049
-            $msg = esc_html__(
2050
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2051
-                'event_espresso'
2052
-            );
2053
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2054
-            return false;
2055
-        }
2056
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2057
-        // clean status
2058
-        $event_status = sanitize_key($event_status);
2059
-        // grab status
2060
-        if (empty($event_status)) {
2061
-            $msg = esc_html__(
2062
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2063
-                'event_espresso'
2064
-            );
2065
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2066
-            return false;
2067
-        }
2068
-        // was event trashed or restored ?
2069
-        switch ($event_status) {
2070
-            case 'draft':
2071
-                $action = 'restored from the trash';
2072
-                $hook = 'AHEE_event_restored_from_trash';
2073
-                break;
2074
-            case 'trash':
2075
-                $action = 'moved to the trash';
2076
-                $hook = 'AHEE_event_moved_to_trash';
2077
-                break;
2078
-            default:
2079
-                $action = 'updated';
2080
-                $hook = false;
2081
-        }
2082
-        // use class to change status
2083
-        $this->_cpt_model_obj->set_status($event_status);
2084
-        $success = $this->_cpt_model_obj->save();
2085
-        if ($success === false) {
2086
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2087
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2088
-            return false;
2089
-        }
2090
-        if ($hook) {
2091
-            do_action($hook);
2092
-        }
2093
-        return true;
2094
-    }
2095
-
2096
-
2097
-    /**
2098
-     * _delete_event
2099
-     *
2100
-     * @access protected
2101
-     * @param bool $redirect_after
2102
-     */
2103
-    protected function _delete_event()
2104
-    {
2105
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : array());
2106
-    }
2107
-
2108
-    /**
2109
-     * Gets the tree traversal batch persister.
2110
-     * @since $VID:$
2111
-     * @return NodeGroupDao
2112
-     * @throws InvalidArgumentException
2113
-     * @throws InvalidDataTypeException
2114
-     * @throws InvalidInterfaceException
2115
-     */
2116
-    protected function getModelObjNodeGroupPersister()
2117
-    {
2118
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2119
-            $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2120
-        }
2121
-        return $this->model_obj_node_group_persister;
2122
-    }
2123
-
2124
-    /**
2125
-     * _delete_events
2126
-     *
2127
-     * @access protected
2128
-     * @return void
2129
-     */
2130
-    protected function _delete_events()
2131
-    {
2132
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array());
2133
-    }
2134
-
2135
-    protected function generateDeletionPreview($event_ids)
2136
-    {
2137
-        $event_ids = (array) $event_ids;
2138
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2139
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2140
-        $return_url = EE_Admin_Page::add_query_args_and_nonce(
2141
-            [
2142
-                'action' => 'preview_deletion',
2143
-                'deletion_job_code' => $deletion_job_code,
2144
-            ],
2145
-            $this->_admin_base_url
2146
-        );
2147
-        $event_ids = array_map(
2148
-            'intval',
2149
-            $event_ids
2150
-        );
2151
-
2152
-        EEH_URL::safeRedirectAndExit(
2153
-            EE_Admin_Page::add_query_args_and_nonce(
2154
-                array(
2155
-                    'page'        => 'espresso_batch',
2156
-                    'batch'       => EED_Batch::batch_job,
2157
-                    'EVT_IDs'      => $event_ids,
2158
-                    'deletion_job_code' => $deletion_job_code,
2159
-                    'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2160
-                    'return_url'  => urlencode($return_url),
2161
-                ),
2162
-                admin_url()
2163
-            )
2164
-        );
2165
-    }
2166
-
2167
-    /**
2168
-     * Checks for a POST submission
2169
-     * @since $VID:$
2170
-     */
2171
-    protected function confirmDeletion()
2172
-    {
2173
-        $deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2174
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2175
-    }
2176
-
2177
-    /**
2178
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2179
-     * @since $VID:$
2180
-     * @throws EE_Error
2181
-     */
2182
-    protected function previewDeletion()
2183
-    {
2184
-        $preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2185
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2186
-        $this->display_admin_page_with_no_sidebar();
2187
-    }
2188
-
2189
-    /**
2190
-     * get total number of events
2191
-     *
2192
-     * @access public
2193
-     * @return int
2194
-     */
2195
-    public function total_events()
2196
-    {
2197
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2198
-        return $count;
2199
-    }
2200
-
2201
-
2202
-    /**
2203
-     * get total number of draft events
2204
-     *
2205
-     * @access public
2206
-     * @return int
2207
-     */
2208
-    public function total_events_draft()
2209
-    {
2210
-        $where = array(
2211
-            'status' => array('IN', array('draft', 'auto-draft')),
2212
-        );
2213
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2214
-        return $count;
2215
-    }
2216
-
2217
-
2218
-    /**
2219
-     * get total number of trashed events
2220
-     *
2221
-     * @access public
2222
-     * @return int
2223
-     */
2224
-    public function total_trashed_events()
2225
-    {
2226
-        $where = array(
2227
-            'status' => 'trash',
2228
-        );
2229
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2230
-        return $count;
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     *    _default_event_settings
2236
-     *    This generates the Default Settings Tab
2237
-     *
2238
-     * @return void
2239
-     * @throws EE_Error
2240
-     */
2241
-    protected function _default_event_settings()
2242
-    {
2243
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2244
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2245
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2246
-        $this->display_admin_page_with_sidebar();
2247
-    }
2248
-
2249
-
2250
-    /**
2251
-     * Return the form for event settings.
2252
-     *
2253
-     * @return EE_Form_Section_Proper
2254
-     * @throws EE_Error
2255
-     */
2256
-    protected function _default_event_settings_form()
2257
-    {
2258
-        $registration_config = EE_Registry::instance()->CFG->registration;
2259
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2260
-            // exclude
2261
-            array(
2262
-                EEM_Registration::status_id_cancelled,
2263
-                EEM_Registration::status_id_declined,
2264
-                EEM_Registration::status_id_incomplete,
2265
-                EEM_Registration::status_id_wait_list,
2266
-            ),
2267
-            true
2268
-        );
2269
-        return new EE_Form_Section_Proper(
2270
-            array(
2271
-                'name'            => 'update_default_event_settings',
2272
-                'html_id'         => 'update_default_event_settings',
2273
-                'html_class'      => 'form-table',
2274
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2275
-                'subsections'     => apply_filters(
2276
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2277
-                    array(
2278
-                        'default_reg_status'  => new EE_Select_Input(
2279
-                            $registration_stati_for_selection,
2280
-                            array(
2281
-                                'default'         => isset($registration_config->default_STS_ID)
2282
-                                                     && array_key_exists(
2283
-                                                         $registration_config->default_STS_ID,
2284
-                                                         $registration_stati_for_selection
2285
-                                                     )
2286
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2287
-                                    : EEM_Registration::status_id_pending_payment,
2288
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2289
-                                                     . EEH_Template::get_help_tab_link(
2290
-                                                         'default_settings_status_help_tab'
2291
-                                                     ),
2292
-                                'html_help_text'  => esc_html__(
2293
-                                    '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.',
2294
-                                    'event_espresso'
2295
-                                ),
2296
-                            )
2297
-                        ),
2298
-                        'default_max_tickets' => new EE_Integer_Input(
2299
-                            array(
2300
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2301
-                                    ? $registration_config->default_maximum_number_of_tickets
2302
-                                    : EEM_Event::get_default_additional_limit(),
2303
-                                'html_label_text' => esc_html__(
2304
-                                    'Default Maximum Tickets Allowed Per Order:',
2305
-                                    'event_espresso'
2306
-                                )
2307
-                                                     . EEH_Template::get_help_tab_link(
2308
-                                                         'default_maximum_tickets_help_tab"'
2309
-                                                     ),
2310
-                                'html_help_text'  => esc_html__(
2311
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2312
-                                    'event_espresso'
2313
-                                ),
2314
-                            )
2315
-                        ),
2316
-                    )
2317
-                ),
2318
-            )
2319
-        );
2320
-    }
2321
-
2322
-
2323
-    /**
2324
-     * _update_default_event_settings
2325
-     *
2326
-     * @access protected
2327
-     * @return void
2328
-     * @throws EE_Error
2329
-     */
2330
-    protected function _update_default_event_settings()
2331
-    {
2332
-        $registration_config = EE_Registry::instance()->CFG->registration;
2333
-        $form = $this->_default_event_settings_form();
2334
-        if ($form->was_submitted()) {
2335
-            $form->receive_form_submission();
2336
-            if ($form->is_valid()) {
2337
-                $valid_data = $form->valid_data();
2338
-                if (isset($valid_data['default_reg_status'])) {
2339
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2340
-                }
2341
-                if (isset($valid_data['default_max_tickets'])) {
2342
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2343
-                }
2344
-                // update because data was valid!
2345
-                EE_Registry::instance()->CFG->update_espresso_config();
2346
-                EE_Error::overwrite_success();
2347
-                EE_Error::add_success(
2348
-                    __('Default Event Settings were updated', 'event_espresso')
2349
-                );
2350
-            }
2351
-        }
2352
-        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2353
-    }
2354
-
2355
-
2356
-    /*************        Templates        *************/
2357
-    protected function _template_settings()
2358
-    {
2359
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2360
-        $this->_template_args['preview_img'] = '<img src="'
2361
-                                               . EVENTS_ASSETS_URL
2362
-                                               . '/images/'
2363
-                                               . 'caffeinated_template_features.jpg" alt="'
2364
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2365
-                                               . '" />';
2366
-        $this->_template_args['preview_text'] = '<strong>'
2367
-                                                . esc_html__(
2368
-                                                    '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.',
2369
-                                                    'event_espresso'
2370
-                                                ) . '</strong>';
2371
-        $this->display_admin_caf_preview_page('template_settings_tab');
2372
-    }
2373
-
2374
-
2375
-    /** Event Category Stuff **/
2376
-    /**
2377
-     * set the _category property with the category object for the loaded page.
2378
-     *
2379
-     * @access private
2380
-     * @return void
2381
-     */
2382
-    private function _set_category_object()
2383
-    {
2384
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2385
-            return;
2386
-        } //already have the category object so get out.
2387
-        // set default category object
2388
-        $this->_set_empty_category_object();
2389
-        // only set if we've got an id
2390
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2391
-            return;
2392
-        }
2393
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2394
-        $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2395
-        if (! empty($term)) {
2396
-            $this->_category->category_name = $term->name;
2397
-            $this->_category->category_identifier = $term->slug;
2398
-            $this->_category->category_desc = $term->description;
2399
-            $this->_category->id = $term->term_id;
2400
-            $this->_category->parent = $term->parent;
2401
-        }
2402
-    }
2403
-
2404
-
2405
-    /**
2406
-     * Clears out category properties.
2407
-     */
2408
-    private function _set_empty_category_object()
2409
-    {
2410
-        $this->_category = new stdClass();
2411
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2412
-        $this->_category->id = $this->_category->parent = 0;
2413
-    }
2414
-
2415
-
2416
-    /**
2417
-     * @throws EE_Error
2418
-     */
2419
-    protected function _category_list_table()
2420
-    {
2421
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2422
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2423
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2424
-            'add_category',
2425
-            'add_category',
2426
-            array(),
2427
-            'add-new-h2'
2428
-        );
2429
-        $this->display_admin_list_table_page_with_sidebar();
2430
-    }
2431
-
2432
-
2433
-    /**
2434
-     * Output category details view.
2435
-     */
2436
-    protected function _category_details($view)
2437
-    {
2438
-        // load formatter helper
2439
-        // load field generator helper
2440
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2441
-        $this->_set_add_edit_form_tags($route);
2442
-        $this->_set_category_object();
2443
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2444
-        $delete_action = 'delete_category';
2445
-        // custom redirect
2446
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2447
-            array('action' => 'category_list'),
2448
-            $this->_admin_base_url
2449
-        );
2450
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2451
-        // take care of contents
2452
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2453
-        $this->display_admin_page_with_sidebar();
2454
-    }
2455
-
2456
-
2457
-    /**
2458
-     * Output category details content.
2459
-     */
2460
-    protected function _category_details_content()
2461
-    {
2462
-        $editor_args['category_desc'] = array(
2463
-            'type'          => 'wp_editor',
2464
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2465
-            'class'         => 'my_editor_custom',
2466
-            'wpeditor_args' => array('media_buttons' => false),
2467
-        );
2468
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2469
-        $all_terms = get_terms(
2470
-            array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2471
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2472
-        );
2473
-        // setup category select for term parents.
2474
-        $category_select_values[] = array(
2475
-            'text' => esc_html__('No Parent', 'event_espresso'),
2476
-            'id'   => 0,
2477
-        );
2478
-        foreach ($all_terms as $term) {
2479
-            $category_select_values[] = array(
2480
-                'text' => $term->name,
2481
-                'id'   => $term->term_id,
2482
-            );
2483
-        }
2484
-        $category_select = EEH_Form_Fields::select_input(
2485
-            'category_parent',
2486
-            $category_select_values,
2487
-            $this->_category->parent
2488
-        );
2489
-        $template_args = array(
2490
-            'category'                 => $this->_category,
2491
-            'category_select'          => $category_select,
2492
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2493
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2494
-            'disable'                  => '',
2495
-            'disabled_message'         => false,
2496
-        );
2497
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2498
-        return EEH_Template::display_template($template, $template_args, true);
2499
-    }
2500
-
2501
-
2502
-    /**
2503
-     * Handles deleting categories.
2504
-     */
2505
-    protected function _delete_categories()
2506
-    {
2507
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2508
-            : (array) $this->_req_data['category_id'];
2509
-        foreach ($cat_ids as $cat_id) {
2510
-            $this->_delete_category($cat_id);
2511
-        }
2512
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2513
-        $query_args = array(
2514
-            'action' => 'category_list',
2515
-        );
2516
-        $this->_redirect_after_action(0, '', '', $query_args);
2517
-    }
2518
-
2519
-
2520
-    /**
2521
-     * Handles deleting specific category.
2522
-     *
2523
-     * @param int $cat_id
2524
-     */
2525
-    protected function _delete_category($cat_id)
2526
-    {
2527
-        $cat_id = absint($cat_id);
2528
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2529
-    }
2530
-
2531
-
2532
-    /**
2533
-     * Handles triggering the update or insertion of a new category.
2534
-     *
2535
-     * @param bool $new_category true means we're triggering the insert of a new category.
2536
-     */
2537
-    protected function _insert_or_update_category($new_category)
2538
-    {
2539
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2540
-        $success = 0; // we already have a success message so lets not send another.
2541
-        if ($cat_id) {
2542
-            $query_args = array(
2543
-                'action'     => 'edit_category',
2544
-                'EVT_CAT_ID' => $cat_id,
2545
-            );
2546
-        } else {
2547
-            $query_args = array('action' => 'add_category');
2548
-        }
2549
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2550
-    }
2551
-
2552
-
2553
-    /**
2554
-     * Inserts or updates category
2555
-     *
2556
-     * @param bool $update (true indicates we're updating a category).
2557
-     * @return bool|mixed|string
2558
-     */
2559
-    private function _insert_category($update = false)
2560
-    {
2561
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2562
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2563
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2564
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2565
-        if (empty($category_name)) {
2566
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2567
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2568
-            return false;
2569
-        }
2570
-        $term_args = array(
2571
-            'name'        => $category_name,
2572
-            'description' => $category_desc,
2573
-            'parent'      => $category_parent,
2574
-        );
2575
-        // was the category_identifier input disabled?
2576
-        if (isset($this->_req_data['category_identifier'])) {
2577
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2578
-        }
2579
-        $insert_ids = $update
2580
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2581
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2582
-        if (! is_array($insert_ids)) {
2583
-            $msg = esc_html__(
2584
-                'An error occurred and the category has not been saved to the database.',
2585
-                'event_espresso'
2586
-            );
2587
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2588
-        } else {
2589
-            $cat_id = $insert_ids['term_id'];
2590
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2591
-            EE_Error::add_success($msg);
2592
-        }
2593
-        return $cat_id;
2594
-    }
2595
-
2596
-
2597
-    /**
2598
-     * Gets categories or count of categories matching the arguments in the request.
2599
-     *
2600
-     * @param int  $per_page
2601
-     * @param int  $current_page
2602
-     * @param bool $count
2603
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2604
-     */
2605
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2606
-    {
2607
-        // testing term stuff
2608
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2609
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2610
-        $limit = ($current_page - 1) * $per_page;
2611
-        $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2612
-        if (isset($this->_req_data['s'])) {
2613
-            $sstr = '%' . $this->_req_data['s'] . '%';
2614
-            $where['OR'] = array(
2615
-                'Term.name'   => array('LIKE', $sstr),
2616
-                'description' => array('LIKE', $sstr),
2617
-            );
2618
-        }
2619
-        $query_params = array(
2620
-            $where,
2621
-            'order_by'   => array($orderby => $order),
2622
-            'limit'      => $limit . ',' . $per_page,
2623
-            'force_join' => array('Term'),
2624
-        );
2625
-        $categories = $count
2626
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2627
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2628
-        return $categories;
2629
-    }
2630
-
2631
-    /* end category stuff */
2632
-    /**************/
2633
-
2634
-
2635
-    /**
2636
-     * Callback for the `ee_save_timezone_setting` ajax action.
2637
-     *
2638
-     * @throws EE_Error
2639
-     */
2640
-    public function save_timezonestring_setting()
2641
-    {
2642
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2643
-            ? $this->_req_data['timezone_selected']
2644
-            : '';
2645
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2646
-            EE_Error::add_error(
2647
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2648
-                __FILE__,
2649
-                __FUNCTION__,
2650
-                __LINE__
2651
-            );
2652
-            $this->_template_args['error'] = true;
2653
-            $this->_return_json();
2654
-        }
2655
-
2656
-        update_option('timezone_string', $timezone_string);
2657
-        EE_Error::add_success(
2658
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2659
-        );
2660
-        $this->_template_args['success'] = true;
2661
-        $this->_return_json(true, array('action' => 'create_new'));
2662
-    }
22
+	/**
23
+	 * This will hold the event object for event_details screen.
24
+	 *
25
+	 * @access protected
26
+	 * @var EE_Event $_event
27
+	 */
28
+	protected $_event;
29
+
30
+
31
+	/**
32
+	 * This will hold the category object for category_details screen.
33
+	 *
34
+	 * @var stdClass $_category
35
+	 */
36
+	protected $_category;
37
+
38
+
39
+	/**
40
+	 * This will hold the event model instance
41
+	 *
42
+	 * @var EEM_Event $_event_model
43
+	 */
44
+	protected $_event_model;
45
+
46
+
47
+	/**
48
+	 * @var EE_Event
49
+	 */
50
+	protected $_cpt_model_obj = false;
51
+
52
+
53
+	/**
54
+	 * @var NodeGroupDao
55
+	 */
56
+	protected $model_obj_node_group_persister;
57
+
58
+	/**
59
+	 * Initialize page props for this admin page group.
60
+	 */
61
+	protected function _init_page_props()
62
+	{
63
+		$this->page_slug = EVENTS_PG_SLUG;
64
+		$this->page_label = EVENTS_LABEL;
65
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
66
+		$this->_admin_base_path = EVENTS_ADMIN;
67
+		$this->_cpt_model_names = array(
68
+			'create_new' => 'EEM_Event',
69
+			'edit'       => 'EEM_Event',
70
+		);
71
+		$this->_cpt_edit_routes = array(
72
+			'espresso_events' => 'edit',
73
+		);
74
+		add_action(
75
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
76
+			array($this, 'verify_event_edit'),
77
+			10,
78
+			2
79
+		);
80
+	}
81
+
82
+
83
+	/**
84
+	 * Sets the ajax hooks used for this admin page group.
85
+	 */
86
+	protected function _ajax_hooks()
87
+	{
88
+		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
89
+	}
90
+
91
+
92
+	/**
93
+	 * Sets the page properties for this admin page group.
94
+	 */
95
+	protected function _define_page_props()
96
+	{
97
+		$this->_admin_page_title = EVENTS_LABEL;
98
+		$this->_labels = array(
99
+			'buttons'      => array(
100
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
101
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
102
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
103
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
104
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
105
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
106
+			),
107
+			'editor_title' => array(
108
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
109
+			),
110
+			'publishbox'   => array(
111
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
112
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
113
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
114
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
115
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
116
+			),
117
+		);
118
+	}
119
+
120
+
121
+	/**
122
+	 * Sets the page routes property for this admin page group.
123
+	 */
124
+	protected function _set_page_routes()
125
+	{
126
+		// load formatter helper
127
+		// load field generator helper
128
+		// is there a evt_id in the request?
129
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
130
+			? $this->_req_data['EVT_ID']
131
+			: 0;
132
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
133
+		$this->_page_routes = array(
134
+			'default'                       => array(
135
+				'func'       => '_events_overview_list_table',
136
+				'capability' => 'ee_read_events',
137
+			),
138
+			'create_new'                    => array(
139
+				'func'       => '_create_new_cpt_item',
140
+				'capability' => 'ee_edit_events',
141
+			),
142
+			'edit'                          => array(
143
+				'func'       => '_edit_cpt_item',
144
+				'capability' => 'ee_edit_event',
145
+				'obj_id'     => $evt_id,
146
+			),
147
+			'copy_event'                    => array(
148
+				'func'       => '_copy_events',
149
+				'capability' => 'ee_edit_event',
150
+				'obj_id'     => $evt_id,
151
+				'noheader'   => true,
152
+			),
153
+			'trash_event'                   => array(
154
+				'func'       => '_trash_or_restore_event',
155
+				'args'       => array('event_status' => 'trash'),
156
+				'capability' => 'ee_delete_event',
157
+				'obj_id'     => $evt_id,
158
+				'noheader'   => true,
159
+			),
160
+			'trash_events'                  => array(
161
+				'func'       => '_trash_or_restore_events',
162
+				'args'       => array('event_status' => 'trash'),
163
+				'capability' => 'ee_delete_events',
164
+				'noheader'   => true,
165
+			),
166
+			'restore_event'                 => array(
167
+				'func'       => '_trash_or_restore_event',
168
+				'args'       => array('event_status' => 'draft'),
169
+				'capability' => 'ee_delete_event',
170
+				'obj_id'     => $evt_id,
171
+				'noheader'   => true,
172
+			),
173
+			'restore_events'                => array(
174
+				'func'       => '_trash_or_restore_events',
175
+				'args'       => array('event_status' => 'draft'),
176
+				'capability' => 'ee_delete_events',
177
+				'noheader'   => true,
178
+			),
179
+			'delete_event'                  => array(
180
+				'func'       => '_delete_event',
181
+				'capability' => 'ee_delete_event',
182
+				'obj_id'     => $evt_id,
183
+				'noheader'   => true,
184
+			),
185
+			'delete_events'                 => array(
186
+				'func'       => '_delete_events',
187
+				'capability' => 'ee_delete_events',
188
+				'noheader'   => true,
189
+			),
190
+			'view_report'                   => array(
191
+				'func'      => '_view_report',
192
+				'capablity' => 'ee_edit_events',
193
+			),
194
+			'default_event_settings'        => array(
195
+				'func'       => '_default_event_settings',
196
+				'capability' => 'manage_options',
197
+			),
198
+			'update_default_event_settings' => array(
199
+				'func'       => '_update_default_event_settings',
200
+				'capability' => 'manage_options',
201
+				'noheader'   => true,
202
+			),
203
+			'template_settings'             => array(
204
+				'func'       => '_template_settings',
205
+				'capability' => 'manage_options',
206
+			),
207
+			// event category tab related
208
+			'add_category'                  => array(
209
+				'func'       => '_category_details',
210
+				'capability' => 'ee_edit_event_category',
211
+				'args'       => array('add'),
212
+			),
213
+			'edit_category'                 => array(
214
+				'func'       => '_category_details',
215
+				'capability' => 'ee_edit_event_category',
216
+				'args'       => array('edit'),
217
+			),
218
+			'delete_categories'             => array(
219
+				'func'       => '_delete_categories',
220
+				'capability' => 'ee_delete_event_category',
221
+				'noheader'   => true,
222
+			),
223
+			'delete_category'               => array(
224
+				'func'       => '_delete_categories',
225
+				'capability' => 'ee_delete_event_category',
226
+				'noheader'   => true,
227
+			),
228
+			'insert_category'               => array(
229
+				'func'       => '_insert_or_update_category',
230
+				'args'       => array('new_category' => true),
231
+				'capability' => 'ee_edit_event_category',
232
+				'noheader'   => true,
233
+			),
234
+			'update_category'               => array(
235
+				'func'       => '_insert_or_update_category',
236
+				'args'       => array('new_category' => false),
237
+				'capability' => 'ee_edit_event_category',
238
+				'noheader'   => true,
239
+			),
240
+			'category_list'                 => array(
241
+				'func'       => '_category_list_table',
242
+				'capability' => 'ee_manage_event_categories',
243
+			),
244
+			'preview_deletion' => [
245
+				'func' => 'previewDeletion',
246
+				'capability' => 'ee_delete_events',
247
+			],
248
+			'confirm_deletion' => [
249
+				'func' => 'confirmDeletion',
250
+				'capability' => 'ee_delete_events',
251
+				'noheader' => true,
252
+			]
253
+		);
254
+	}
255
+
256
+
257
+	/**
258
+	 * Set the _page_config property for this admin page group.
259
+	 */
260
+	protected function _set_page_config()
261
+	{
262
+		$this->_page_config = array(
263
+			'default'                => array(
264
+				'nav'           => array(
265
+					'label' => esc_html__('Overview', 'event_espresso'),
266
+					'order' => 10,
267
+				),
268
+				'list_table'    => 'Events_Admin_List_Table',
269
+				'help_tabs'     => array(
270
+					'events_overview_help_tab'                       => array(
271
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
272
+						'filename' => 'events_overview',
273
+					),
274
+					'events_overview_table_column_headings_help_tab' => array(
275
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
276
+						'filename' => 'events_overview_table_column_headings',
277
+					),
278
+					'events_overview_filters_help_tab'               => array(
279
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
280
+						'filename' => 'events_overview_filters',
281
+					),
282
+					'events_overview_view_help_tab'                  => array(
283
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
284
+						'filename' => 'events_overview_views',
285
+					),
286
+					'events_overview_other_help_tab'                 => array(
287
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
288
+						'filename' => 'events_overview_other',
289
+					),
290
+				),
291
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
292
+				// 'help_tour'     => array(
293
+				//     'Event_Overview_Help_Tour',
294
+				//     // 'New_Features_Test_Help_Tour' for testing multiple help tour
295
+				// ),
296
+				'qtips'         => array(
297
+					'EE_Event_List_Table_Tips',
298
+				),
299
+				'require_nonce' => false,
300
+			),
301
+			'create_new'             => array(
302
+				'nav'           => array(
303
+					'label'      => esc_html__('Add Event', 'event_espresso'),
304
+					'order'      => 5,
305
+					'persistent' => false,
306
+				),
307
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
308
+				'help_tabs'     => array(
309
+					'event_editor_help_tab'                            => array(
310
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
311
+						'filename' => 'event_editor',
312
+					),
313
+					'event_editor_title_richtexteditor_help_tab'       => array(
314
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
315
+						'filename' => 'event_editor_title_richtexteditor',
316
+					),
317
+					'event_editor_venue_details_help_tab'              => array(
318
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
319
+						'filename' => 'event_editor_venue_details',
320
+					),
321
+					'event_editor_event_datetimes_help_tab'            => array(
322
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
323
+						'filename' => 'event_editor_event_datetimes',
324
+					),
325
+					'event_editor_event_tickets_help_tab'              => array(
326
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
327
+						'filename' => 'event_editor_event_tickets',
328
+					),
329
+					'event_editor_event_registration_options_help_tab' => array(
330
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
331
+						'filename' => 'event_editor_event_registration_options',
332
+					),
333
+					'event_editor_tags_categories_help_tab'            => array(
334
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
335
+						'filename' => 'event_editor_tags_categories',
336
+					),
337
+					'event_editor_questions_registrants_help_tab'      => array(
338
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
339
+						'filename' => 'event_editor_questions_registrants',
340
+					),
341
+					'event_editor_save_new_event_help_tab'             => array(
342
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
343
+						'filename' => 'event_editor_save_new_event',
344
+					),
345
+					'event_editor_other_help_tab'                      => array(
346
+						'title'    => esc_html__('Event Other', 'event_espresso'),
347
+						'filename' => 'event_editor_other',
348
+					),
349
+				),
350
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
351
+				// 'help_tour'     => array(
352
+				//     'Event_Editor_Help_Tour',
353
+				// ),
354
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
355
+				'require_nonce' => false,
356
+			),
357
+			'edit'                   => array(
358
+				'nav'           => array(
359
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
360
+					'order'      => 5,
361
+					'persistent' => false,
362
+					'url'        => isset($this->_req_data['post'])
363
+						? EE_Admin_Page::add_query_args_and_nonce(
364
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
365
+							$this->_current_page_view_url
366
+						)
367
+						: $this->_admin_base_url,
368
+				),
369
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
370
+				'help_tabs'     => array(
371
+					'event_editor_help_tab'                            => array(
372
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
373
+						'filename' => 'event_editor',
374
+					),
375
+					'event_editor_title_richtexteditor_help_tab'       => array(
376
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
377
+						'filename' => 'event_editor_title_richtexteditor',
378
+					),
379
+					'event_editor_venue_details_help_tab'              => array(
380
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
381
+						'filename' => 'event_editor_venue_details',
382
+					),
383
+					'event_editor_event_datetimes_help_tab'            => array(
384
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
385
+						'filename' => 'event_editor_event_datetimes',
386
+					),
387
+					'event_editor_event_tickets_help_tab'              => array(
388
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
389
+						'filename' => 'event_editor_event_tickets',
390
+					),
391
+					'event_editor_event_registration_options_help_tab' => array(
392
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
393
+						'filename' => 'event_editor_event_registration_options',
394
+					),
395
+					'event_editor_tags_categories_help_tab'            => array(
396
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
397
+						'filename' => 'event_editor_tags_categories',
398
+					),
399
+					'event_editor_questions_registrants_help_tab'      => array(
400
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
401
+						'filename' => 'event_editor_questions_registrants',
402
+					),
403
+					'event_editor_save_new_event_help_tab'             => array(
404
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
405
+						'filename' => 'event_editor_save_new_event',
406
+					),
407
+					'event_editor_other_help_tab'                      => array(
408
+						'title'    => esc_html__('Event Other', 'event_espresso'),
409
+						'filename' => 'event_editor_other',
410
+					),
411
+				),
412
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
413
+				'require_nonce' => false,
414
+			),
415
+			'default_event_settings' => array(
416
+				'nav'           => array(
417
+					'label' => esc_html__('Default Settings', 'event_espresso'),
418
+					'order' => 40,
419
+				),
420
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
421
+				'labels'        => array(
422
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
423
+				),
424
+				'help_tabs'     => array(
425
+					'default_settings_help_tab'        => array(
426
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
427
+						'filename' => 'events_default_settings',
428
+					),
429
+					'default_settings_status_help_tab' => array(
430
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
431
+						'filename' => 'events_default_settings_status',
432
+					),
433
+					'default_maximum_tickets_help_tab' => array(
434
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
435
+						'filename' => 'events_default_settings_max_tickets',
436
+					),
437
+				),
438
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
439
+				// 'help_tour'     => array('Event_Default_Settings_Help_Tour'),
440
+				'require_nonce' => false,
441
+			),
442
+			// template settings
443
+			'template_settings'      => array(
444
+				'nav'           => array(
445
+					'label' => esc_html__('Templates', 'event_espresso'),
446
+					'order' => 30,
447
+				),
448
+				'metaboxes'     => $this->_default_espresso_metaboxes,
449
+				'help_tabs'     => array(
450
+					'general_settings_templates_help_tab' => array(
451
+						'title'    => esc_html__('Templates', 'event_espresso'),
452
+						'filename' => 'general_settings_templates',
453
+					),
454
+				),
455
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
456
+				// 'help_tour'     => array('Templates_Help_Tour'),
457
+				'require_nonce' => false,
458
+			),
459
+			// event category stuff
460
+			'add_category'           => array(
461
+				'nav'           => array(
462
+					'label'      => esc_html__('Add Category', 'event_espresso'),
463
+					'order'      => 15,
464
+					'persistent' => false,
465
+				),
466
+				'help_tabs'     => array(
467
+					'add_category_help_tab' => array(
468
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
469
+						'filename' => 'events_add_category',
470
+					),
471
+				),
472
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
473
+				// 'help_tour'     => array('Event_Add_Category_Help_Tour'),
474
+				'metaboxes'     => array('_publish_post_box'),
475
+				'require_nonce' => false,
476
+			),
477
+			'edit_category'          => array(
478
+				'nav'           => array(
479
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
480
+					'order'      => 15,
481
+					'persistent' => false,
482
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
483
+						? add_query_arg(
484
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
485
+							$this->_current_page_view_url
486
+						)
487
+						: $this->_admin_base_url,
488
+				),
489
+				'help_tabs'     => array(
490
+					'edit_category_help_tab' => array(
491
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
492
+						'filename' => 'events_edit_category',
493
+					),
494
+				),
495
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
496
+				'metaboxes'     => array('_publish_post_box'),
497
+				'require_nonce' => false,
498
+			),
499
+			'category_list'          => array(
500
+				'nav'           => array(
501
+					'label' => esc_html__('Categories', 'event_espresso'),
502
+					'order' => 20,
503
+				),
504
+				'list_table'    => 'Event_Categories_Admin_List_Table',
505
+				'help_tabs'     => array(
506
+					'events_categories_help_tab'                       => array(
507
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
508
+						'filename' => 'events_categories',
509
+					),
510
+					'events_categories_table_column_headings_help_tab' => array(
511
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
512
+						'filename' => 'events_categories_table_column_headings',
513
+					),
514
+					'events_categories_view_help_tab'                  => array(
515
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
516
+						'filename' => 'events_categories_views',
517
+					),
518
+					'events_categories_other_help_tab'                 => array(
519
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
520
+						'filename' => 'events_categories_other',
521
+					),
522
+				),
523
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
524
+				// 'help_tour'     => array(
525
+				//     'Event_Categories_Help_Tour',
526
+				// ),
527
+				'metaboxes'     => $this->_default_espresso_metaboxes,
528
+				'require_nonce' => false,
529
+			),
530
+			'preview_deletion'           => array(
531
+				'nav'           => array(
532
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
533
+					'order'      => 15,
534
+					'persistent' => false,
535
+					'url'        => '',
536
+				),
537
+				'require_nonce' => false
538
+			)
539
+		);
540
+	}
541
+
542
+
543
+	/**
544
+	 * Used to register any global screen options if necessary for every route in this admin page group.
545
+	 */
546
+	protected function _add_screen_options()
547
+	{
548
+	}
549
+
550
+
551
+	/**
552
+	 * Implementing the screen options for the 'default' route.
553
+	 */
554
+	protected function _add_screen_options_default()
555
+	{
556
+		$this->_per_page_screen_option();
557
+	}
558
+
559
+
560
+	/**
561
+	 * Implementing screen options for the category list route.
562
+	 */
563
+	protected function _add_screen_options_category_list()
564
+	{
565
+		$page_title = $this->_admin_page_title;
566
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
567
+		$this->_per_page_screen_option();
568
+		$this->_admin_page_title = $page_title;
569
+	}
570
+
571
+
572
+	/**
573
+	 * Used to register any global feature pointers for the admin page group.
574
+	 */
575
+	protected function _add_feature_pointers()
576
+	{
577
+	}
578
+
579
+
580
+	/**
581
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
582
+	 */
583
+	public function load_scripts_styles()
584
+	{
585
+		wp_register_style(
586
+			'events-admin-css',
587
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
588
+			array(),
589
+			EVENT_ESPRESSO_VERSION
590
+		);
591
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
592
+		wp_enqueue_style('events-admin-css');
593
+		wp_enqueue_style('ee-cat-admin');
594
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
595
+		// registers for all views
596
+		// scripts
597
+		wp_register_script(
598
+			'event_editor_js',
599
+			EVENTS_ASSETS_URL . 'event_editor.js',
600
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
601
+			EVENT_ESPRESSO_VERSION,
602
+			true
603
+		);
604
+	}
605
+
606
+
607
+	/**
608
+	 * Enqueuing scripts and styles specific to this view
609
+	 */
610
+	public function load_scripts_styles_create_new()
611
+	{
612
+		$this->load_scripts_styles_edit();
613
+	}
614
+
615
+
616
+	/**
617
+	 * Enqueuing scripts and styles specific to this view
618
+	 */
619
+	public function load_scripts_styles_edit()
620
+	{
621
+		// styles
622
+		wp_enqueue_style('espresso-ui-theme');
623
+		wp_register_style(
624
+			'event-editor-css',
625
+			EVENTS_ASSETS_URL . 'event-editor.css',
626
+			array('ee-admin-css'),
627
+			EVENT_ESPRESSO_VERSION
628
+		);
629
+		wp_enqueue_style('event-editor-css');
630
+		// scripts
631
+		wp_register_script(
632
+			'event-datetime-metabox',
633
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
634
+			array('event_editor_js', 'ee-datepicker'),
635
+			EVENT_ESPRESSO_VERSION
636
+		);
637
+		wp_enqueue_script('event-datetime-metabox');
638
+	}
639
+
640
+
641
+	/**
642
+	 * Populating the _views property for the category list table view.
643
+	 */
644
+	protected function _set_list_table_views_category_list()
645
+	{
646
+		$this->_views = array(
647
+			'all' => array(
648
+				'slug'        => 'all',
649
+				'label'       => esc_html__('All', 'event_espresso'),
650
+				'count'       => 0,
651
+				'bulk_action' => array(
652
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
653
+				),
654
+			),
655
+		);
656
+	}
657
+
658
+
659
+	/**
660
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
661
+	 */
662
+	public function admin_init()
663
+	{
664
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
665
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
666
+			'event_espresso'
667
+		);
668
+	}
669
+
670
+
671
+	/**
672
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
673
+	 * group.
674
+	 */
675
+	public function admin_notices()
676
+	{
677
+	}
678
+
679
+
680
+	/**
681
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
682
+	 * this admin page group.
683
+	 */
684
+	public function admin_footer_scripts()
685
+	{
686
+	}
687
+
688
+
689
+	/**
690
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
691
+	 * warning (via EE_Error::add_error());
692
+	 *
693
+	 * @param  EE_Event $event Event object
694
+	 * @param string    $req_type
695
+	 * @return void
696
+	 * @throws EE_Error
697
+	 * @access public
698
+	 */
699
+	public function verify_event_edit($event = null, $req_type = '')
700
+	{
701
+		// don't need to do this when processing
702
+		if (! empty($req_type)) {
703
+			return;
704
+		}
705
+		// no event?
706
+		if (empty($event)) {
707
+			// set event
708
+			$event = $this->_cpt_model_obj;
709
+		}
710
+		// STILL no event?
711
+		if (! $event instanceof EE_Event) {
712
+			return;
713
+		}
714
+		$orig_status = $event->status();
715
+		// first check if event is active.
716
+		if ($orig_status === EEM_Event::cancelled
717
+			|| $orig_status === EEM_Event::postponed
718
+			|| $event->is_expired()
719
+			|| $event->is_inactive()
720
+		) {
721
+			return;
722
+		}
723
+		// made it here so it IS active... next check that any of the tickets are sold.
724
+		if ($event->is_sold_out(true)) {
725
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
726
+				EE_Error::add_attention(
727
+					sprintf(
728
+						esc_html__(
729
+							'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.',
730
+							'event_espresso'
731
+						),
732
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
733
+					)
734
+				);
735
+			}
736
+			return;
737
+		} elseif ($orig_status === EEM_Event::sold_out) {
738
+			EE_Error::add_attention(
739
+				sprintf(
740
+					esc_html__(
741
+						'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.',
742
+						'event_espresso'
743
+					),
744
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
745
+				)
746
+			);
747
+		}
748
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
+		if (! $event->tickets_on_sale()) {
750
+			return;
751
+		}
752
+		// made it here so show warning
753
+		$this->_edit_event_warning();
754
+	}
755
+
756
+
757
+	/**
758
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
759
+	 * When needed, hook this into a EE_Error::add_error() notice.
760
+	 *
761
+	 * @access protected
762
+	 * @return void
763
+	 */
764
+	protected function _edit_event_warning()
765
+	{
766
+		// we don't want to add warnings during these requests
767
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
768
+			return;
769
+		}
770
+		EE_Error::add_attention(
771
+			sprintf(
772
+				esc_html__(
773
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
774
+					'event_espresso'
775
+				),
776
+				'<a class="espresso-help-tab-lnk">',
777
+				'</a>'
778
+			)
779
+		);
780
+	}
781
+
782
+
783
+	/**
784
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
785
+	 * Otherwise, do the normal logic
786
+	 *
787
+	 * @return string
788
+	 * @throws \EE_Error
789
+	 */
790
+	protected function _create_new_cpt_item()
791
+	{
792
+		$has_timezone_string = get_option('timezone_string');
793
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
794
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795
+			EE_Error::add_attention(
796
+				sprintf(
797
+					__(
798
+						'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',
799
+						'event_espresso'
800
+					),
801
+					'<br>',
802
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
803
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
804
+					. '</select>',
805
+					'<button class="button button-secondary timezone-submit">',
806
+					'</button><span class="spinner"></span>'
807
+				),
808
+				__FILE__,
809
+				__FUNCTION__,
810
+				__LINE__
811
+			);
812
+		}
813
+		return parent::_create_new_cpt_item();
814
+	}
815
+
816
+
817
+	/**
818
+	 * Sets the _views property for the default route in this admin page group.
819
+	 */
820
+	protected function _set_list_table_views_default()
821
+	{
822
+		$this->_views = array(
823
+			'all'   => array(
824
+				'slug'        => 'all',
825
+				'label'       => esc_html__('View All Events', 'event_espresso'),
826
+				'count'       => 0,
827
+				'bulk_action' => array(
828
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
829
+				),
830
+			),
831
+			'draft' => array(
832
+				'slug'        => 'draft',
833
+				'label'       => esc_html__('Draft', 'event_espresso'),
834
+				'count'       => 0,
835
+				'bulk_action' => array(
836
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
837
+				),
838
+			),
839
+		);
840
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
841
+			$this->_views['trash'] = array(
842
+				'slug'        => 'trash',
843
+				'label'       => esc_html__('Trash', 'event_espresso'),
844
+				'count'       => 0,
845
+				'bulk_action' => array(
846
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
847
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
848
+				),
849
+			);
850
+		}
851
+	}
852
+
853
+
854
+	/**
855
+	 * Provides the legend item array for the default list table view.
856
+	 *
857
+	 * @return array
858
+	 */
859
+	protected function _event_legend_items()
860
+	{
861
+		$items = array(
862
+			'view_details'   => array(
863
+				'class' => 'dashicons dashicons-search',
864
+				'desc'  => esc_html__('View Event', 'event_espresso'),
865
+			),
866
+			'edit_event'     => array(
867
+				'class' => 'ee-icon ee-icon-calendar-edit',
868
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
869
+			),
870
+			'view_attendees' => array(
871
+				'class' => 'dashicons dashicons-groups',
872
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
873
+			),
874
+		);
875
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876
+		$statuses = array(
877
+			'sold_out_status'  => array(
878
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
879
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880
+			),
881
+			'active_status'    => array(
882
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
883
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884
+			),
885
+			'upcoming_status'  => array(
886
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
887
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888
+			),
889
+			'postponed_status' => array(
890
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
891
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892
+			),
893
+			'cancelled_status' => array(
894
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
895
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896
+			),
897
+			'expired_status'   => array(
898
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
899
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900
+			),
901
+			'inactive_status'  => array(
902
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
903
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904
+			),
905
+		);
906
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
907
+		return array_merge($items, $statuses);
908
+	}
909
+
910
+
911
+	/**
912
+	 * @return EEM_Event
913
+	 */
914
+	private function _event_model()
915
+	{
916
+		if (! $this->_event_model instanceof EEM_Event) {
917
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
918
+		}
919
+		return $this->_event_model;
920
+	}
921
+
922
+
923
+	/**
924
+	 * Adds extra buttons to the WP CPT permalink field row.
925
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
926
+	 *
927
+	 * @param  string $return    the current html
928
+	 * @param  int    $id        the post id for the page
929
+	 * @param  string $new_title What the title is
930
+	 * @param  string $new_slug  what the slug is
931
+	 * @return string            The new html string for the permalink area
932
+	 */
933
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934
+	{
935
+		// make sure this is only when editing
936
+		if (! empty($id)) {
937
+			$post = get_post($id);
938
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939
+					   . esc_html__('Shortcode', 'event_espresso')
940
+					   . '</a> ';
941
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
942
+					   . $post->ID
943
+					   . ']">';
944
+		}
945
+		return $return;
946
+	}
947
+
948
+
949
+	/**
950
+	 * _events_overview_list_table
951
+	 * This contains the logic for showing the events_overview list
952
+	 *
953
+	 * @access protected
954
+	 * @return void
955
+	 * @throws \EE_Error
956
+	 */
957
+	protected function _events_overview_list_table()
958
+	{
959
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
960
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
961
+			? (array) $this->_template_args['after_list_table']
962
+			: array();
963
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
964
+				. EEH_Template::get_button_or_link(
965
+					get_post_type_archive_link('espresso_events'),
966
+					esc_html__("View Event Archive Page", "event_espresso"),
967
+					'button'
968
+				);
969
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
971
+			'create_new',
972
+			'add',
973
+			array(),
974
+			'add-new-h2'
975
+		);
976
+		$this->display_admin_list_table_page_with_no_sidebar();
977
+	}
978
+
979
+
980
+	/**
981
+	 * this allows for extra misc actions in the default WP publish box
982
+	 *
983
+	 * @return void
984
+	 */
985
+	public function extra_misc_actions_publish_box()
986
+	{
987
+		$this->_generate_publish_box_extra_content();
988
+	}
989
+
990
+
991
+	/**
992
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
993
+	 * saved.
994
+	 * Typically you would use this to save any additional data.
995
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
996
+	 * ALSO very important.  When a post transitions from scheduled to published,
997
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
998
+	 * other meta saves. So MAKE sure that you handle this accordingly.
999
+	 *
1000
+	 * @access protected
1001
+	 * @abstract
1002
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
1003
+	 * @param  object $post    The post object of the cpt that was saved.
1004
+	 * @return void
1005
+	 * @throws \EE_Error
1006
+	 */
1007
+	protected function _insert_update_cpt_item($post_id, $post)
1008
+	{
1009
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1010
+			// get out we're not processing an event save.
1011
+			return;
1012
+		}
1013
+		$event_values = array(
1014
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1015
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1016
+			'EVT_additional_limit'            => min(
1017
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1018
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1019
+			),
1020
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1021
+				? $this->_req_data['EVT_default_registration_status']
1022
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
1023
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1024
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1025
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1026
+				? $this->_req_data['timezone_string'] : null,
1027
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1028
+				? $this->_req_data['externalURL'] : null,
1029
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1030
+				? $this->_req_data['event_phone'] : null,
1031
+		);
1032
+		// update event
1033
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1034
+		// get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_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!
1035
+		$get_one_where = array(
1036
+			$this->_event_model()->primary_key_name() => $post_id,
1037
+			'OR'                                      => array(
1038
+				'status'   => $post->post_status,
1039
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1040
+				// but the returned object here has a status of "publish", so use the original post status as well
1041
+				'status*1' => $this->_req_data['original_post_status'],
1042
+			),
1043
+		);
1044
+		$event = $this->_event_model()->get_one(array($get_one_where));
1045
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1046
+		$event_update_callbacks = apply_filters(
1047
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1048
+			array(
1049
+				array($this, '_default_venue_update'),
1050
+				array($this, '_default_tickets_update'),
1051
+			)
1052
+		);
1053
+		$att_success = true;
1054
+		foreach ($event_update_callbacks as $e_callback) {
1055
+			$_success = is_callable($e_callback)
1056
+				? call_user_func($e_callback, $event, $this->_req_data)
1057
+				: false;
1058
+			// if ANY of these updates fail then we want the appropriate global error message
1059
+			$att_success = ! $att_success ? $att_success : $_success;
1060
+		}
1061
+		// any errors?
1062
+		if ($success && false === $att_success) {
1063
+			EE_Error::add_error(
1064
+				esc_html__(
1065
+					'Event Details saved successfully but something went wrong with saving attachments.',
1066
+					'event_espresso'
1067
+				),
1068
+				__FILE__,
1069
+				__FUNCTION__,
1070
+				__LINE__
1071
+			);
1072
+		} elseif ($success === false) {
1073
+			EE_Error::add_error(
1074
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1075
+				__FILE__,
1076
+				__FUNCTION__,
1077
+				__LINE__
1078
+			);
1079
+		}
1080
+	}
1081
+
1082
+
1083
+	/**
1084
+	 * @see parent::restore_item()
1085
+	 * @param int $post_id
1086
+	 * @param int $revision_id
1087
+	 */
1088
+	protected function _restore_cpt_item($post_id, $revision_id)
1089
+	{
1090
+		// copy existing event meta to new post
1091
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1092
+		if ($post_evt instanceof EE_Event) {
1093
+			// meta revision restore
1094
+			$post_evt->restore_revision($revision_id);
1095
+			// related objs restore
1096
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1097
+		}
1098
+	}
1099
+
1100
+
1101
+	/**
1102
+	 * Attach the venue to the Event
1103
+	 *
1104
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1105
+	 * @param  array     $data   The request data from the form
1106
+	 * @return bool           Success or fail.
1107
+	 */
1108
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1109
+	{
1110
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1111
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1112
+		$rows_affected = null;
1113
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1114
+		// very important.  If we don't have a venue name...
1115
+		// then we'll get out because not necessary to create empty venue
1116
+		if (empty($data['venue_title'])) {
1117
+			return false;
1118
+		}
1119
+		$venue_array = array(
1120
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1121
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1122
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1123
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1124
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1125
+				: null,
1126
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1127
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1128
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1129
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1130
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1131
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1132
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1133
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1134
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1135
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1136
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1137
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1138
+			'status'              => 'publish',
1139
+		);
1140
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
+		if (! empty($venue_id)) {
1142
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1143
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1144
+			// 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.
1145
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1146
+			return $rows_affected > 0 ? true : false;
1147
+		} else {
1148
+			// we insert the venue
1149
+			$venue_id = $venue_model->insert($venue_array);
1150
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1151
+			return ! empty($venue_id) ? true : false;
1152
+		}
1153
+		// when we have the ancestor come in it's already been handled by the revision save.
1154
+	}
1155
+
1156
+
1157
+	/**
1158
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1159
+	 *
1160
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1161
+	 * @param  array    $data   The request data from the form
1162
+	 * @return array
1163
+	 */
1164
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1165
+	{
1166
+		$success = true;
1167
+		$saved_dtt = null;
1168
+		$saved_tickets = array();
1169
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1170
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1171
+			// trim all values to ensure any excess whitespace is removed.
1172
+			$dtt = array_map('trim', $dtt);
1173
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1174
+				: $dtt['DTT_EVT_start'];
1175
+			$datetime_values = array(
1176
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1177
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1178
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1179
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1180
+				'DTT_order'     => $row,
1181
+			);
1182
+			// if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
+			if (! empty($dtt['DTT_ID'])) {
1184
+				$DTM = EE_Registry::instance()
1185
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1186
+								  ->get_one_by_ID($dtt['DTT_ID']);
1187
+				$DTM->set_date_format($incoming_date_formats[0]);
1188
+				$DTM->set_time_format($incoming_date_formats[1]);
1189
+				foreach ($datetime_values as $field => $value) {
1190
+					$DTM->set($field, $value);
1191
+				}
1192
+				// make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1194
+			} else {
1195
+				$DTM = EE_Registry::instance()->load_class(
1196
+					'Datetime',
1197
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1198
+					false,
1199
+					false
1200
+				);
1201
+				foreach ($datetime_values as $field => $value) {
1202
+					$DTM->set($field, $value);
1203
+				}
1204
+			}
1205
+			$DTM->save();
1206
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1207
+			// load DTT helper
1208
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1209
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1210
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1211
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1212
+				$DTT->save();
1213
+			}
1214
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1215
+			$saved_dtt = $DTT;
1216
+			$success = ! $success ? $success : $DTT;
1217
+			// if ANY of these updates fail then we want the appropriate global error message.
1218
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1219
+		}
1220
+		// no dtts get deleted so we don't do any of that logic here.
1221
+		// update tickets next
1222
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1223
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1224
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1225
+			$update_prices = false;
1226
+			$ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
+				? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1228
+			// trim inputs to ensure any excess whitespace is removed.
1229
+			$tkt = array_map('trim', $tkt);
1230
+			if (empty($tkt['TKT_start_date'])) {
1231
+				// let's use now in the set timezone.
1232
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1234
+			}
1235
+			if (empty($tkt['TKT_end_date'])) {
1236
+				// use the start date of the first datetime
1237
+				$dtt = $evtobj->first_datetime();
1238
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1239
+					$incoming_date_formats[0],
1240
+					$incoming_date_formats[1]
1241
+				);
1242
+			}
1243
+			$TKT_values = array(
1244
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1245
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1246
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1247
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1248
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1249
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1250
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1251
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1252
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1253
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1254
+				'TKT_row'         => $row,
1255
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1256
+				'TKT_price'       => $ticket_price,
1257
+			);
1258
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1259
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1260
+				$TKT_values['TKT_ID'] = 0;
1261
+				$TKT_values['TKT_is_default'] = 0;
1262
+				$TKT_values['TKT_price'] = $ticket_price;
1263
+				$update_prices = true;
1264
+			}
1265
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266
+			// we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267
+			// keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
+			if (! empty($tkt['TKT_ID'])) {
1269
+				$TKT = EE_Registry::instance()
1270
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1271
+								  ->get_one_by_ID($tkt['TKT_ID']);
1272
+				if ($TKT instanceof EE_Ticket) {
1273
+					$ticket_sold = $TKT->count_related(
1274
+						'Registration',
1275
+						array(
1276
+							array(
1277
+								'STS_ID' => array(
1278
+									'NOT IN',
1279
+									array(EEM_Registration::status_id_incomplete),
1280
+								),
1281
+							),
1282
+						)
1283
+					) > 0 ? true : false;
1284
+					// let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1285
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1286
+									  && ! $TKT->get('TKT_deleted');
1287
+					$TKT->set_date_format($incoming_date_formats[0]);
1288
+					$TKT->set_time_format($incoming_date_formats[1]);
1289
+					// set new values
1290
+					foreach ($TKT_values as $field => $value) {
1291
+						if ($field == 'TKT_qty') {
1292
+							$TKT->set_qty($value);
1293
+						} else {
1294
+							$TKT->set($field, $value);
1295
+						}
1296
+					}
1297
+					// if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1298
+					if ($create_new_TKT) {
1299
+						// archive the old ticket first
1300
+						$TKT->set('TKT_deleted', 1);
1301
+						$TKT->save();
1302
+						// make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1304
+						// create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305
+						$TKT = clone $TKT;
1306
+						$TKT->set('TKT_ID', 0);
1307
+						$TKT->set('TKT_deleted', 0);
1308
+						$TKT->set('TKT_price', $ticket_price);
1309
+						$TKT->set('TKT_sold', 0);
1310
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1311
+						$update_prices = true;
1312
+					}
1313
+					// make sure price is set if it hasn't been already
1314
+					$TKT->set('TKT_price', $ticket_price);
1315
+				}
1316
+			} else {
1317
+				// no TKT_id so a new TKT
1318
+				$TKT_values['TKT_price'] = $ticket_price;
1319
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1320
+				if ($TKT instanceof EE_Ticket) {
1321
+					// need to reset values to properly account for the date formats
1322
+					$TKT->set_date_format($incoming_date_formats[0]);
1323
+					$TKT->set_time_format($incoming_date_formats[1]);
1324
+					$TKT->set_timezone($evtobj->get_timezone());
1325
+					// set new values
1326
+					foreach ($TKT_values as $field => $value) {
1327
+						if ($field == 'TKT_qty') {
1328
+							$TKT->set_qty($value);
1329
+						} else {
1330
+							$TKT->set($field, $value);
1331
+						}
1332
+					}
1333
+					$update_prices = true;
1334
+				}
1335
+			}
1336
+			// cap ticket qty by datetime reg limits
1337
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1338
+			// update ticket.
1339
+			$TKT->save();
1340
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1341
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1342
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1343
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1344
+				$TKT->save();
1345
+			}
1346
+			// initially let's add the ticket to the dtt
1347
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1349
+			// add prices to ticket
1350
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1351
+		}
1352
+		// however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1354
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1355
+		foreach ($tickets_removed as $id) {
1356
+			$id = absint($id);
1357
+			// get the ticket for this id
1358
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1359
+			// need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1360
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1361
+			foreach ($dtts as $dtt) {
1362
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1363
+			}
1364
+			// need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1365
+			$tkt_to_remove->delete_related_permanently('Price');
1366
+			// finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1367
+			$tkt_to_remove->delete_permanently();
1368
+		}
1369
+		return array($saved_dtt, $saved_tickets);
1370
+	}
1371
+
1372
+
1373
+	/**
1374
+	 * This attaches a list of given prices to a ticket.
1375
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1376
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1377
+	 * price info and prices are automatically "archived" via the ticket.
1378
+	 *
1379
+	 * @access  private
1380
+	 * @param array     $prices     Array of prices from the form.
1381
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1382
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1383
+	 * @return  void
1384
+	 */
1385
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1386
+	{
1387
+		foreach ($prices as $row => $prc) {
1388
+			$PRC_values = array(
1389
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1390
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1391
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1392
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1393
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1394
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1395
+				'PRC_order'      => $row,
1396
+			);
1397
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1398
+				$PRC_values['PRC_ID'] = 0;
1399
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1400
+			} else {
1401
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1402
+				// update this price with new values
1403
+				foreach ($PRC_values as $field => $newprc) {
1404
+					$PRC->set($field, $newprc);
1405
+				}
1406
+				$PRC->save();
1407
+			}
1408
+			$ticket->_add_relation_to($PRC, 'Price');
1409
+		}
1410
+	}
1411
+
1412
+
1413
+	/**
1414
+	 * Add in our autosave ajax handlers
1415
+	 *
1416
+	 */
1417
+	protected function _ee_autosave_create_new()
1418
+	{
1419
+	}
1420
+
1421
+
1422
+	/**
1423
+	 * More autosave handlers.
1424
+	 */
1425
+	protected function _ee_autosave_edit()
1426
+	{
1427
+		return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1428
+	}
1429
+
1430
+
1431
+	/**
1432
+	 *    _generate_publish_box_extra_content
1433
+	 */
1434
+	private function _generate_publish_box_extra_content()
1435
+	{
1436
+		// load formatter helper
1437
+		// args for getting related registrations
1438
+		$approved_query_args = array(
1439
+			array(
1440
+				'REG_deleted' => 0,
1441
+				'STS_ID'      => EEM_Registration::status_id_approved,
1442
+			),
1443
+		);
1444
+		$not_approved_query_args = array(
1445
+			array(
1446
+				'REG_deleted' => 0,
1447
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1448
+			),
1449
+		);
1450
+		$pending_payment_query_args = array(
1451
+			array(
1452
+				'REG_deleted' => 0,
1453
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1454
+			),
1455
+		);
1456
+		// publish box
1457
+		$publish_box_extra_args = array(
1458
+			'view_approved_reg_url'        => add_query_arg(
1459
+				array(
1460
+					'action'      => 'default',
1461
+					'event_id'    => $this->_cpt_model_obj->ID(),
1462
+					'_reg_status' => EEM_Registration::status_id_approved,
1463
+				),
1464
+				REG_ADMIN_URL
1465
+			),
1466
+			'view_not_approved_reg_url'    => add_query_arg(
1467
+				array(
1468
+					'action'      => 'default',
1469
+					'event_id'    => $this->_cpt_model_obj->ID(),
1470
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1471
+				),
1472
+				REG_ADMIN_URL
1473
+			),
1474
+			'view_pending_payment_reg_url' => add_query_arg(
1475
+				array(
1476
+					'action'      => 'default',
1477
+					'event_id'    => $this->_cpt_model_obj->ID(),
1478
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1479
+				),
1480
+				REG_ADMIN_URL
1481
+			),
1482
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1483
+				'Registration',
1484
+				$approved_query_args
1485
+			),
1486
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1487
+				'Registration',
1488
+				$not_approved_query_args
1489
+			),
1490
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1491
+				'Registration',
1492
+				$pending_payment_query_args
1493
+			),
1494
+			'misc_pub_section_class'       => apply_filters(
1495
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1496
+				'misc-pub-section'
1497
+			),
1498
+		);
1499
+		ob_start();
1500
+		do_action(
1501
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1502
+			$this->_cpt_model_obj
1503
+		);
1504
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1505
+		// load template
1506
+		EEH_Template::display_template(
1507
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1508
+			$publish_box_extra_args
1509
+		);
1510
+	}
1511
+
1512
+
1513
+	/**
1514
+	 * @return EE_Event
1515
+	 */
1516
+	public function get_event_object()
1517
+	{
1518
+		return $this->_cpt_model_obj;
1519
+	}
1520
+
1521
+
1522
+
1523
+
1524
+	/** METABOXES * */
1525
+	/**
1526
+	 * _register_event_editor_meta_boxes
1527
+	 * add all metaboxes related to the event_editor
1528
+	 *
1529
+	 * @return void
1530
+	 */
1531
+	protected function _register_event_editor_meta_boxes()
1532
+	{
1533
+		$this->verify_cpt_object();
1534
+		add_meta_box(
1535
+			'espresso_event_editor_tickets',
1536
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1537
+			array($this, 'ticket_metabox'),
1538
+			$this->page_slug,
1539
+			'normal',
1540
+			'high'
1541
+		);
1542
+		add_meta_box(
1543
+			'espresso_event_editor_event_options',
1544
+			esc_html__('Event Registration Options', 'event_espresso'),
1545
+			array($this, 'registration_options_meta_box'),
1546
+			$this->page_slug,
1547
+			'side',
1548
+			'default'
1549
+		);
1550
+		// NOTE: if you're looking for other metaboxes in here,
1551
+		// where a metabox has a related management page in the admin
1552
+		// you will find it setup in the related management page's "_Hooks" file.
1553
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1554
+	}
1555
+
1556
+
1557
+	/**
1558
+	 * @throws DomainException
1559
+	 * @throws EE_Error
1560
+	 */
1561
+	public function ticket_metabox()
1562
+	{
1563
+		$existing_datetime_ids = $existing_ticket_ids = array();
1564
+		// defaults for template args
1565
+		$template_args = array(
1566
+			'existing_datetime_ids'    => '',
1567
+			'event_datetime_help_link' => '',
1568
+			'ticket_options_help_link' => '',
1569
+			'time'                     => null,
1570
+			'ticket_rows'              => '',
1571
+			'existing_ticket_ids'      => '',
1572
+			'total_ticket_rows'        => 1,
1573
+			'ticket_js_structure'      => '',
1574
+			'trash_icon'               => 'ee-lock-icon',
1575
+			'disabled'                 => '',
1576
+		);
1577
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1578
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1579
+		/**
1580
+		 * 1. Start with retrieving Datetimes
1581
+		 * 2. Fore each datetime get related tickets
1582
+		 * 3. For each ticket get related prices
1583
+		 */
1584
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1585
+		/** @type EE_Datetime $first_datetime */
1586
+		$first_datetime = reset($times);
1587
+		// do we get related tickets?
1588
+		if ($first_datetime instanceof EE_Datetime
1589
+			&& $first_datetime->ID() !== 0
1590
+		) {
1591
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1592
+			$template_args['time'] = $first_datetime;
1593
+			$related_tickets = $first_datetime->tickets(
1594
+				array(
1595
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1596
+					'default_where_conditions' => 'none',
1597
+				)
1598
+			);
1599
+			if (! empty($related_tickets)) {
1600
+				$template_args['total_ticket_rows'] = count($related_tickets);
1601
+				$row = 0;
1602
+				foreach ($related_tickets as $ticket) {
1603
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1604
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1605
+					$row++;
1606
+				}
1607
+			} else {
1608
+				$template_args['total_ticket_rows'] = 1;
1609
+				/** @type EE_Ticket $ticket */
1610
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1611
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1612
+			}
1613
+		} else {
1614
+			$template_args['time'] = $times[0];
1615
+			/** @type EE_Ticket $ticket */
1616
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1617
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1618
+			// NOTE: we're just sending the first default row
1619
+			// (decaf can't manage default tickets so this should be sufficient);
1620
+		}
1621
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1622
+			'event_editor_event_datetimes_help_tab'
1623
+		);
1624
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1625
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1626
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1627
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1628
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1629
+			true
1630
+		);
1631
+		$template = apply_filters(
1632
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1633
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1634
+		);
1635
+		EEH_Template::display_template($template, $template_args);
1636
+	}
1637
+
1638
+
1639
+	/**
1640
+	 * Setup an individual ticket form for the decaf event editor page
1641
+	 *
1642
+	 * @access private
1643
+	 * @param  EE_Ticket $ticket   the ticket object
1644
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1645
+	 * @param int        $row
1646
+	 * @return string generated html for the ticket row.
1647
+	 */
1648
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1649
+	{
1650
+		$template_args = array(
1651
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1652
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1653
+				: '',
1654
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1655
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1656
+			'TKT_name'            => $ticket->get('TKT_name'),
1657
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1658
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1659
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1660
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1661
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1662
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1663
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1664
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1665
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1666
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1667
+				: ' disabled=disabled',
1668
+		);
1669
+		$price = $ticket->ID() !== 0
1670
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1671
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1672
+		$price_args = array(
1673
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1674
+			'PRC_amount'            => $price->get('PRC_amount'),
1675
+			'PRT_ID'                => $price->get('PRT_ID'),
1676
+			'PRC_ID'                => $price->get('PRC_ID'),
1677
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1678
+		);
1679
+		// make sure we have default start and end dates if skeleton
1680
+		// handle rows that should NOT be empty
1681
+		if (empty($template_args['TKT_start_date'])) {
1682
+			// if empty then the start date will be now.
1683
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1684
+		}
1685
+		if (empty($template_args['TKT_end_date'])) {
1686
+			// get the earliest datetime (if present);
1687
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1688
+				? $this->_cpt_model_obj->get_first_related(
1689
+					'Datetime',
1690
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1691
+				)
1692
+				: null;
1693
+			if (! empty($earliest_dtt)) {
1694
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1695
+			} else {
1696
+				$template_args['TKT_end_date'] = date(
1697
+					'Y-m-d h:i a',
1698
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1699
+				);
1700
+			}
1701
+		}
1702
+		$template_args = array_merge($template_args, $price_args);
1703
+		$template = apply_filters(
1704
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1705
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1706
+			$ticket
1707
+		);
1708
+		return EEH_Template::display_template($template, $template_args, true);
1709
+	}
1710
+
1711
+
1712
+	/**
1713
+	 * @throws DomainException
1714
+	 */
1715
+	public function registration_options_meta_box()
1716
+	{
1717
+		$yes_no_values = array(
1718
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1719
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1720
+		);
1721
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1722
+			array(
1723
+				EEM_Registration::status_id_cancelled,
1724
+				EEM_Registration::status_id_declined,
1725
+				EEM_Registration::status_id_incomplete,
1726
+			),
1727
+			true
1728
+		);
1729
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1730
+		$template_args['_event'] = $this->_cpt_model_obj;
1731
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1732
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1733
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1734
+			'default_reg_status',
1735
+			$default_reg_status_values,
1736
+			$this->_cpt_model_obj->default_registration_status()
1737
+		);
1738
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1739
+			'display_desc',
1740
+			$yes_no_values,
1741
+			$this->_cpt_model_obj->display_description()
1742
+		);
1743
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1744
+			'display_ticket_selector',
1745
+			$yes_no_values,
1746
+			$this->_cpt_model_obj->display_ticket_selector(),
1747
+			'',
1748
+			'',
1749
+			false
1750
+		);
1751
+		$template_args['additional_registration_options'] = apply_filters(
1752
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1753
+			'',
1754
+			$template_args,
1755
+			$yes_no_values,
1756
+			$default_reg_status_values
1757
+		);
1758
+		EEH_Template::display_template(
1759
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1760
+			$template_args
1761
+		);
1762
+	}
1763
+
1764
+
1765
+	/**
1766
+	 * _get_events()
1767
+	 * This method simply returns all the events (for the given _view and paging)
1768
+	 *
1769
+	 * @access public
1770
+	 * @param int  $per_page     count of items per page (20 default);
1771
+	 * @param int  $current_page what is the current page being viewed.
1772
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1773
+	 *                           If FALSE then we return an array of event objects
1774
+	 *                           that match the given _view and paging parameters.
1775
+	 * @return array an array of event objects.
1776
+	 */
1777
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1778
+	{
1779
+		$EEME = $this->_event_model();
1780
+		$offset = ($current_page - 1) * $per_page;
1781
+		$limit = $count ? null : $offset . ',' . $per_page;
1782
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1783
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1784
+		if (isset($this->_req_data['month_range'])) {
1785
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1786
+			// simulate the FIRST day of the month, that fixes issues for months like February
1787
+			// where PHP doesn't know what to assume for date.
1788
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1789
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1790
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1791
+		}
1792
+		$where = array();
1793
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1794
+		// determine what post_status our condition will have for the query.
1795
+		switch ($status) {
1796
+			case 'month':
1797
+			case 'today':
1798
+			case null:
1799
+			case 'all':
1800
+				break;
1801
+			case 'draft':
1802
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1803
+				break;
1804
+			default:
1805
+				$where['status'] = $status;
1806
+		}
1807
+		// categories?
1808
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1809
+			? $this->_req_data['EVT_CAT'] : null;
1810
+		if (! empty($category)) {
1811
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1812
+			$where['Term_Taxonomy.term_id'] = $category;
1813
+		}
1814
+		// date where conditions
1815
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1816
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1817
+			$DateTime = new DateTime(
1818
+				$year_r . '-' . $month_r . '-01 00:00:00',
1819
+				new DateTimeZone('UTC')
1820
+			);
1821
+			$start = $DateTime->getTimestamp();
1822
+			// set the datetime to be the end of the month
1823
+			$DateTime->setDate(
1824
+				$year_r,
1825
+				$month_r,
1826
+				$DateTime->format('t')
1827
+			)->setTime(23, 59, 59);
1828
+			$end = $DateTime->getTimestamp();
1829
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1830
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1831
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1832
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1833
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1834
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1835
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1836
+			$now = date('Y-m-01');
1837
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1838
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1839
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1840
+							->setTime(23, 59, 59)
1841
+							->format(implode(' ', $start_formats));
1842
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1843
+		}
1844
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1845
+			$where['EVT_wp_user'] = get_current_user_id();
1846
+		} else {
1847
+			if (! isset($where['status'])) {
1848
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1849
+					$where['OR'] = array(
1850
+						'status*restrict_private' => array('!=', 'private'),
1851
+						'AND'                     => array(
1852
+							'status*inclusive' => array('=', 'private'),
1853
+							'EVT_wp_user'      => get_current_user_id(),
1854
+						),
1855
+					);
1856
+				}
1857
+			}
1858
+		}
1859
+		if (isset($this->_req_data['EVT_wp_user'])) {
1860
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1861
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1862
+			) {
1863
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1864
+			}
1865
+		}
1866
+		// search query handling
1867
+		if (isset($this->_req_data['s'])) {
1868
+			$search_string = '%' . $this->_req_data['s'] . '%';
1869
+			$where['OR'] = array(
1870
+				'EVT_name'       => array('LIKE', $search_string),
1871
+				'EVT_desc'       => array('LIKE', $search_string),
1872
+				'EVT_short_desc' => array('LIKE', $search_string),
1873
+			);
1874
+		}
1875
+		// filter events by venue.
1876
+		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1877
+			$where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1878
+		}
1879
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1880
+		$query_params = apply_filters(
1881
+			'FHEE__Events_Admin_Page__get_events__query_params',
1882
+			array(
1883
+				$where,
1884
+				'limit'    => $limit,
1885
+				'order_by' => $orderby,
1886
+				'order'    => $order,
1887
+				'group_by' => 'EVT_ID',
1888
+			),
1889
+			$this->_req_data
1890
+		);
1891
+
1892
+		// let's first check if we have special requests coming in.
1893
+		if (isset($this->_req_data['active_status'])) {
1894
+			switch ($this->_req_data['active_status']) {
1895
+				case 'upcoming':
1896
+					return $EEME->get_upcoming_events($query_params, $count);
1897
+					break;
1898
+				case 'expired':
1899
+					return $EEME->get_expired_events($query_params, $count);
1900
+					break;
1901
+				case 'active':
1902
+					return $EEME->get_active_events($query_params, $count);
1903
+					break;
1904
+				case 'inactive':
1905
+					return $EEME->get_inactive_events($query_params, $count);
1906
+					break;
1907
+			}
1908
+		}
1909
+
1910
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1911
+		return $events;
1912
+	}
1913
+
1914
+
1915
+	/**
1916
+	 * handling for WordPress CPT actions (trash, restore, delete)
1917
+	 *
1918
+	 * @param string $post_id
1919
+	 */
1920
+	public function trash_cpt_item($post_id)
1921
+	{
1922
+		$this->_req_data['EVT_ID'] = $post_id;
1923
+		$this->_trash_or_restore_event('trash', false);
1924
+	}
1925
+
1926
+
1927
+	/**
1928
+	 * @param string $post_id
1929
+	 */
1930
+	public function restore_cpt_item($post_id)
1931
+	{
1932
+		$this->_req_data['EVT_ID'] = $post_id;
1933
+		$this->_trash_or_restore_event('draft', false);
1934
+	}
1935
+
1936
+
1937
+	/**
1938
+	 * @param string $post_id
1939
+	 */
1940
+	public function delete_cpt_item($post_id)
1941
+	{
1942
+		throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso'));
1943
+		$this->_req_data['EVT_ID'] = $post_id;
1944
+		$this->_delete_event();
1945
+	}
1946
+
1947
+
1948
+	/**
1949
+	 * _trash_or_restore_event
1950
+	 *
1951
+	 * @access protected
1952
+	 * @param  string $event_status
1953
+	 * @param bool    $redirect_after
1954
+	 */
1955
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1956
+	{
1957
+		// determine the event id and set to array.
1958
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1959
+		// loop thru events
1960
+		if ($EVT_ID) {
1961
+			// clean status
1962
+			$event_status = sanitize_key($event_status);
1963
+			// grab status
1964
+			if (! empty($event_status)) {
1965
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1966
+			} else {
1967
+				$success = false;
1968
+				$msg = esc_html__(
1969
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1970
+					'event_espresso'
1971
+				);
1972
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1973
+			}
1974
+		} else {
1975
+			$success = false;
1976
+			$msg = esc_html__(
1977
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1978
+				'event_espresso'
1979
+			);
1980
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1981
+		}
1982
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1983
+		if ($redirect_after) {
1984
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1985
+		}
1986
+	}
1987
+
1988
+
1989
+	/**
1990
+	 * _trash_or_restore_events
1991
+	 *
1992
+	 * @access protected
1993
+	 * @param  string $event_status
1994
+	 * @return void
1995
+	 */
1996
+	protected function _trash_or_restore_events($event_status = 'trash')
1997
+	{
1998
+		// clean status
1999
+		$event_status = sanitize_key($event_status);
2000
+		// grab status
2001
+		if (! empty($event_status)) {
2002
+			$success = true;
2003
+			// determine the event id and set to array.
2004
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2005
+			// loop thru events
2006
+			foreach ($EVT_IDs as $EVT_ID) {
2007
+				if ($EVT_ID = absint($EVT_ID)) {
2008
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2009
+					$success = $results !== false ? $success : false;
2010
+				} else {
2011
+					$msg = sprintf(
2012
+						esc_html__(
2013
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2014
+							'event_espresso'
2015
+						),
2016
+						$EVT_ID
2017
+					);
2018
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2019
+					$success = false;
2020
+				}
2021
+			}
2022
+		} else {
2023
+			$success = false;
2024
+			$msg = esc_html__(
2025
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2026
+				'event_espresso'
2027
+			);
2028
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2029
+		}
2030
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2031
+		$success = $success ? 2 : false;
2032
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2033
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2034
+	}
2035
+
2036
+
2037
+	/**
2038
+	 * _trash_or_restore_events
2039
+	 *
2040
+	 * @access  private
2041
+	 * @param  int    $EVT_ID
2042
+	 * @param  string $event_status
2043
+	 * @return bool
2044
+	 */
2045
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2046
+	{
2047
+		// grab event id
2048
+		if (! $EVT_ID) {
2049
+			$msg = esc_html__(
2050
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2051
+				'event_espresso'
2052
+			);
2053
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2054
+			return false;
2055
+		}
2056
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2057
+		// clean status
2058
+		$event_status = sanitize_key($event_status);
2059
+		// grab status
2060
+		if (empty($event_status)) {
2061
+			$msg = esc_html__(
2062
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2063
+				'event_espresso'
2064
+			);
2065
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2066
+			return false;
2067
+		}
2068
+		// was event trashed or restored ?
2069
+		switch ($event_status) {
2070
+			case 'draft':
2071
+				$action = 'restored from the trash';
2072
+				$hook = 'AHEE_event_restored_from_trash';
2073
+				break;
2074
+			case 'trash':
2075
+				$action = 'moved to the trash';
2076
+				$hook = 'AHEE_event_moved_to_trash';
2077
+				break;
2078
+			default:
2079
+				$action = 'updated';
2080
+				$hook = false;
2081
+		}
2082
+		// use class to change status
2083
+		$this->_cpt_model_obj->set_status($event_status);
2084
+		$success = $this->_cpt_model_obj->save();
2085
+		if ($success === false) {
2086
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2087
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2088
+			return false;
2089
+		}
2090
+		if ($hook) {
2091
+			do_action($hook);
2092
+		}
2093
+		return true;
2094
+	}
2095
+
2096
+
2097
+	/**
2098
+	 * _delete_event
2099
+	 *
2100
+	 * @access protected
2101
+	 * @param bool $redirect_after
2102
+	 */
2103
+	protected function _delete_event()
2104
+	{
2105
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : array());
2106
+	}
2107
+
2108
+	/**
2109
+	 * Gets the tree traversal batch persister.
2110
+	 * @since $VID:$
2111
+	 * @return NodeGroupDao
2112
+	 * @throws InvalidArgumentException
2113
+	 * @throws InvalidDataTypeException
2114
+	 * @throws InvalidInterfaceException
2115
+	 */
2116
+	protected function getModelObjNodeGroupPersister()
2117
+	{
2118
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2119
+			$this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2120
+		}
2121
+		return $this->model_obj_node_group_persister;
2122
+	}
2123
+
2124
+	/**
2125
+	 * _delete_events
2126
+	 *
2127
+	 * @access protected
2128
+	 * @return void
2129
+	 */
2130
+	protected function _delete_events()
2131
+	{
2132
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array());
2133
+	}
2134
+
2135
+	protected function generateDeletionPreview($event_ids)
2136
+	{
2137
+		$event_ids = (array) $event_ids;
2138
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2139
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2140
+		$return_url = EE_Admin_Page::add_query_args_and_nonce(
2141
+			[
2142
+				'action' => 'preview_deletion',
2143
+				'deletion_job_code' => $deletion_job_code,
2144
+			],
2145
+			$this->_admin_base_url
2146
+		);
2147
+		$event_ids = array_map(
2148
+			'intval',
2149
+			$event_ids
2150
+		);
2151
+
2152
+		EEH_URL::safeRedirectAndExit(
2153
+			EE_Admin_Page::add_query_args_and_nonce(
2154
+				array(
2155
+					'page'        => 'espresso_batch',
2156
+					'batch'       => EED_Batch::batch_job,
2157
+					'EVT_IDs'      => $event_ids,
2158
+					'deletion_job_code' => $deletion_job_code,
2159
+					'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2160
+					'return_url'  => urlencode($return_url),
2161
+				),
2162
+				admin_url()
2163
+			)
2164
+		);
2165
+	}
2166
+
2167
+	/**
2168
+	 * Checks for a POST submission
2169
+	 * @since $VID:$
2170
+	 */
2171
+	protected function confirmDeletion()
2172
+	{
2173
+		$deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2174
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2175
+	}
2176
+
2177
+	/**
2178
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2179
+	 * @since $VID:$
2180
+	 * @throws EE_Error
2181
+	 */
2182
+	protected function previewDeletion()
2183
+	{
2184
+		$preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2185
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2186
+		$this->display_admin_page_with_no_sidebar();
2187
+	}
2188
+
2189
+	/**
2190
+	 * get total number of events
2191
+	 *
2192
+	 * @access public
2193
+	 * @return int
2194
+	 */
2195
+	public function total_events()
2196
+	{
2197
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2198
+		return $count;
2199
+	}
2200
+
2201
+
2202
+	/**
2203
+	 * get total number of draft events
2204
+	 *
2205
+	 * @access public
2206
+	 * @return int
2207
+	 */
2208
+	public function total_events_draft()
2209
+	{
2210
+		$where = array(
2211
+			'status' => array('IN', array('draft', 'auto-draft')),
2212
+		);
2213
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2214
+		return $count;
2215
+	}
2216
+
2217
+
2218
+	/**
2219
+	 * get total number of trashed events
2220
+	 *
2221
+	 * @access public
2222
+	 * @return int
2223
+	 */
2224
+	public function total_trashed_events()
2225
+	{
2226
+		$where = array(
2227
+			'status' => 'trash',
2228
+		);
2229
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2230
+		return $count;
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 *    _default_event_settings
2236
+	 *    This generates the Default Settings Tab
2237
+	 *
2238
+	 * @return void
2239
+	 * @throws EE_Error
2240
+	 */
2241
+	protected function _default_event_settings()
2242
+	{
2243
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2244
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2245
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2246
+		$this->display_admin_page_with_sidebar();
2247
+	}
2248
+
2249
+
2250
+	/**
2251
+	 * Return the form for event settings.
2252
+	 *
2253
+	 * @return EE_Form_Section_Proper
2254
+	 * @throws EE_Error
2255
+	 */
2256
+	protected function _default_event_settings_form()
2257
+	{
2258
+		$registration_config = EE_Registry::instance()->CFG->registration;
2259
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2260
+			// exclude
2261
+			array(
2262
+				EEM_Registration::status_id_cancelled,
2263
+				EEM_Registration::status_id_declined,
2264
+				EEM_Registration::status_id_incomplete,
2265
+				EEM_Registration::status_id_wait_list,
2266
+			),
2267
+			true
2268
+		);
2269
+		return new EE_Form_Section_Proper(
2270
+			array(
2271
+				'name'            => 'update_default_event_settings',
2272
+				'html_id'         => 'update_default_event_settings',
2273
+				'html_class'      => 'form-table',
2274
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2275
+				'subsections'     => apply_filters(
2276
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2277
+					array(
2278
+						'default_reg_status'  => new EE_Select_Input(
2279
+							$registration_stati_for_selection,
2280
+							array(
2281
+								'default'         => isset($registration_config->default_STS_ID)
2282
+													 && array_key_exists(
2283
+														 $registration_config->default_STS_ID,
2284
+														 $registration_stati_for_selection
2285
+													 )
2286
+									? sanitize_text_field($registration_config->default_STS_ID)
2287
+									: EEM_Registration::status_id_pending_payment,
2288
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2289
+													 . EEH_Template::get_help_tab_link(
2290
+														 'default_settings_status_help_tab'
2291
+													 ),
2292
+								'html_help_text'  => esc_html__(
2293
+									'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.',
2294
+									'event_espresso'
2295
+								),
2296
+							)
2297
+						),
2298
+						'default_max_tickets' => new EE_Integer_Input(
2299
+							array(
2300
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2301
+									? $registration_config->default_maximum_number_of_tickets
2302
+									: EEM_Event::get_default_additional_limit(),
2303
+								'html_label_text' => esc_html__(
2304
+									'Default Maximum Tickets Allowed Per Order:',
2305
+									'event_espresso'
2306
+								)
2307
+													 . EEH_Template::get_help_tab_link(
2308
+														 'default_maximum_tickets_help_tab"'
2309
+													 ),
2310
+								'html_help_text'  => esc_html__(
2311
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2312
+									'event_espresso'
2313
+								),
2314
+							)
2315
+						),
2316
+					)
2317
+				),
2318
+			)
2319
+		);
2320
+	}
2321
+
2322
+
2323
+	/**
2324
+	 * _update_default_event_settings
2325
+	 *
2326
+	 * @access protected
2327
+	 * @return void
2328
+	 * @throws EE_Error
2329
+	 */
2330
+	protected function _update_default_event_settings()
2331
+	{
2332
+		$registration_config = EE_Registry::instance()->CFG->registration;
2333
+		$form = $this->_default_event_settings_form();
2334
+		if ($form->was_submitted()) {
2335
+			$form->receive_form_submission();
2336
+			if ($form->is_valid()) {
2337
+				$valid_data = $form->valid_data();
2338
+				if (isset($valid_data['default_reg_status'])) {
2339
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2340
+				}
2341
+				if (isset($valid_data['default_max_tickets'])) {
2342
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2343
+				}
2344
+				// update because data was valid!
2345
+				EE_Registry::instance()->CFG->update_espresso_config();
2346
+				EE_Error::overwrite_success();
2347
+				EE_Error::add_success(
2348
+					__('Default Event Settings were updated', 'event_espresso')
2349
+				);
2350
+			}
2351
+		}
2352
+		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2353
+	}
2354
+
2355
+
2356
+	/*************        Templates        *************/
2357
+	protected function _template_settings()
2358
+	{
2359
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2360
+		$this->_template_args['preview_img'] = '<img src="'
2361
+											   . EVENTS_ASSETS_URL
2362
+											   . '/images/'
2363
+											   . 'caffeinated_template_features.jpg" alt="'
2364
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2365
+											   . '" />';
2366
+		$this->_template_args['preview_text'] = '<strong>'
2367
+												. esc_html__(
2368
+													'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.',
2369
+													'event_espresso'
2370
+												) . '</strong>';
2371
+		$this->display_admin_caf_preview_page('template_settings_tab');
2372
+	}
2373
+
2374
+
2375
+	/** Event Category Stuff **/
2376
+	/**
2377
+	 * set the _category property with the category object for the loaded page.
2378
+	 *
2379
+	 * @access private
2380
+	 * @return void
2381
+	 */
2382
+	private function _set_category_object()
2383
+	{
2384
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2385
+			return;
2386
+		} //already have the category object so get out.
2387
+		// set default category object
2388
+		$this->_set_empty_category_object();
2389
+		// only set if we've got an id
2390
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2391
+			return;
2392
+		}
2393
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2394
+		$term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2395
+		if (! empty($term)) {
2396
+			$this->_category->category_name = $term->name;
2397
+			$this->_category->category_identifier = $term->slug;
2398
+			$this->_category->category_desc = $term->description;
2399
+			$this->_category->id = $term->term_id;
2400
+			$this->_category->parent = $term->parent;
2401
+		}
2402
+	}
2403
+
2404
+
2405
+	/**
2406
+	 * Clears out category properties.
2407
+	 */
2408
+	private function _set_empty_category_object()
2409
+	{
2410
+		$this->_category = new stdClass();
2411
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2412
+		$this->_category->id = $this->_category->parent = 0;
2413
+	}
2414
+
2415
+
2416
+	/**
2417
+	 * @throws EE_Error
2418
+	 */
2419
+	protected function _category_list_table()
2420
+	{
2421
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2422
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2423
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2424
+			'add_category',
2425
+			'add_category',
2426
+			array(),
2427
+			'add-new-h2'
2428
+		);
2429
+		$this->display_admin_list_table_page_with_sidebar();
2430
+	}
2431
+
2432
+
2433
+	/**
2434
+	 * Output category details view.
2435
+	 */
2436
+	protected function _category_details($view)
2437
+	{
2438
+		// load formatter helper
2439
+		// load field generator helper
2440
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2441
+		$this->_set_add_edit_form_tags($route);
2442
+		$this->_set_category_object();
2443
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2444
+		$delete_action = 'delete_category';
2445
+		// custom redirect
2446
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2447
+			array('action' => 'category_list'),
2448
+			$this->_admin_base_url
2449
+		);
2450
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2451
+		// take care of contents
2452
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2453
+		$this->display_admin_page_with_sidebar();
2454
+	}
2455
+
2456
+
2457
+	/**
2458
+	 * Output category details content.
2459
+	 */
2460
+	protected function _category_details_content()
2461
+	{
2462
+		$editor_args['category_desc'] = array(
2463
+			'type'          => 'wp_editor',
2464
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2465
+			'class'         => 'my_editor_custom',
2466
+			'wpeditor_args' => array('media_buttons' => false),
2467
+		);
2468
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2469
+		$all_terms = get_terms(
2470
+			array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2471
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2472
+		);
2473
+		// setup category select for term parents.
2474
+		$category_select_values[] = array(
2475
+			'text' => esc_html__('No Parent', 'event_espresso'),
2476
+			'id'   => 0,
2477
+		);
2478
+		foreach ($all_terms as $term) {
2479
+			$category_select_values[] = array(
2480
+				'text' => $term->name,
2481
+				'id'   => $term->term_id,
2482
+			);
2483
+		}
2484
+		$category_select = EEH_Form_Fields::select_input(
2485
+			'category_parent',
2486
+			$category_select_values,
2487
+			$this->_category->parent
2488
+		);
2489
+		$template_args = array(
2490
+			'category'                 => $this->_category,
2491
+			'category_select'          => $category_select,
2492
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2493
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2494
+			'disable'                  => '',
2495
+			'disabled_message'         => false,
2496
+		);
2497
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2498
+		return EEH_Template::display_template($template, $template_args, true);
2499
+	}
2500
+
2501
+
2502
+	/**
2503
+	 * Handles deleting categories.
2504
+	 */
2505
+	protected function _delete_categories()
2506
+	{
2507
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2508
+			: (array) $this->_req_data['category_id'];
2509
+		foreach ($cat_ids as $cat_id) {
2510
+			$this->_delete_category($cat_id);
2511
+		}
2512
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2513
+		$query_args = array(
2514
+			'action' => 'category_list',
2515
+		);
2516
+		$this->_redirect_after_action(0, '', '', $query_args);
2517
+	}
2518
+
2519
+
2520
+	/**
2521
+	 * Handles deleting specific category.
2522
+	 *
2523
+	 * @param int $cat_id
2524
+	 */
2525
+	protected function _delete_category($cat_id)
2526
+	{
2527
+		$cat_id = absint($cat_id);
2528
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2529
+	}
2530
+
2531
+
2532
+	/**
2533
+	 * Handles triggering the update or insertion of a new category.
2534
+	 *
2535
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2536
+	 */
2537
+	protected function _insert_or_update_category($new_category)
2538
+	{
2539
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2540
+		$success = 0; // we already have a success message so lets not send another.
2541
+		if ($cat_id) {
2542
+			$query_args = array(
2543
+				'action'     => 'edit_category',
2544
+				'EVT_CAT_ID' => $cat_id,
2545
+			);
2546
+		} else {
2547
+			$query_args = array('action' => 'add_category');
2548
+		}
2549
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2550
+	}
2551
+
2552
+
2553
+	/**
2554
+	 * Inserts or updates category
2555
+	 *
2556
+	 * @param bool $update (true indicates we're updating a category).
2557
+	 * @return bool|mixed|string
2558
+	 */
2559
+	private function _insert_category($update = false)
2560
+	{
2561
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2562
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2563
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2564
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2565
+		if (empty($category_name)) {
2566
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2567
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2568
+			return false;
2569
+		}
2570
+		$term_args = array(
2571
+			'name'        => $category_name,
2572
+			'description' => $category_desc,
2573
+			'parent'      => $category_parent,
2574
+		);
2575
+		// was the category_identifier input disabled?
2576
+		if (isset($this->_req_data['category_identifier'])) {
2577
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2578
+		}
2579
+		$insert_ids = $update
2580
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2581
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2582
+		if (! is_array($insert_ids)) {
2583
+			$msg = esc_html__(
2584
+				'An error occurred and the category has not been saved to the database.',
2585
+				'event_espresso'
2586
+			);
2587
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2588
+		} else {
2589
+			$cat_id = $insert_ids['term_id'];
2590
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2591
+			EE_Error::add_success($msg);
2592
+		}
2593
+		return $cat_id;
2594
+	}
2595
+
2596
+
2597
+	/**
2598
+	 * Gets categories or count of categories matching the arguments in the request.
2599
+	 *
2600
+	 * @param int  $per_page
2601
+	 * @param int  $current_page
2602
+	 * @param bool $count
2603
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2604
+	 */
2605
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2606
+	{
2607
+		// testing term stuff
2608
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2609
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2610
+		$limit = ($current_page - 1) * $per_page;
2611
+		$where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2612
+		if (isset($this->_req_data['s'])) {
2613
+			$sstr = '%' . $this->_req_data['s'] . '%';
2614
+			$where['OR'] = array(
2615
+				'Term.name'   => array('LIKE', $sstr),
2616
+				'description' => array('LIKE', $sstr),
2617
+			);
2618
+		}
2619
+		$query_params = array(
2620
+			$where,
2621
+			'order_by'   => array($orderby => $order),
2622
+			'limit'      => $limit . ',' . $per_page,
2623
+			'force_join' => array('Term'),
2624
+		);
2625
+		$categories = $count
2626
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2627
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2628
+		return $categories;
2629
+	}
2630
+
2631
+	/* end category stuff */
2632
+	/**************/
2633
+
2634
+
2635
+	/**
2636
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2637
+	 *
2638
+	 * @throws EE_Error
2639
+	 */
2640
+	public function save_timezonestring_setting()
2641
+	{
2642
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2643
+			? $this->_req_data['timezone_selected']
2644
+			: '';
2645
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2646
+			EE_Error::add_error(
2647
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2648
+				__FILE__,
2649
+				__FUNCTION__,
2650
+				__LINE__
2651
+			);
2652
+			$this->_template_args['error'] = true;
2653
+			$this->_return_json();
2654
+		}
2655
+
2656
+		update_option('timezone_string', $timezone_string);
2657
+		EE_Error::add_success(
2658
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2659
+		);
2660
+		$this->_template_args['success'] = true;
2661
+		$this->_return_json(true, array('action' => 'create_new'));
2662
+	}
2663 2663
 }
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -584,11 +584,11 @@  discard block
 block discarded – undo
584 584
     {
585 585
         wp_register_style(
586 586
             'events-admin-css',
587
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
587
+            EVENTS_ASSETS_URL.'events-admin-page.css',
588 588
             array(),
589 589
             EVENT_ESPRESSO_VERSION
590 590
         );
591
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
591
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
592 592
         wp_enqueue_style('events-admin-css');
593 593
         wp_enqueue_style('ee-cat-admin');
594 594
         // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
         // scripts
597 597
         wp_register_script(
598 598
             'event_editor_js',
599
-            EVENTS_ASSETS_URL . 'event_editor.js',
599
+            EVENTS_ASSETS_URL.'event_editor.js',
600 600
             array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
601 601
             EVENT_ESPRESSO_VERSION,
602 602
             true
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
         wp_enqueue_style('espresso-ui-theme');
623 623
         wp_register_style(
624 624
             'event-editor-css',
625
-            EVENTS_ASSETS_URL . 'event-editor.css',
625
+            EVENTS_ASSETS_URL.'event-editor.css',
626 626
             array('ee-admin-css'),
627 627
             EVENT_ESPRESSO_VERSION
628 628
         );
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
         // scripts
631 631
         wp_register_script(
632 632
             'event-datetime-metabox',
633
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
633
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
634 634
             array('event_editor_js', 'ee-datepicker'),
635 635
             EVENT_ESPRESSO_VERSION
636 636
         );
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
     public function verify_event_edit($event = null, $req_type = '')
700 700
     {
701 701
         // don't need to do this when processing
702
-        if (! empty($req_type)) {
702
+        if ( ! empty($req_type)) {
703 703
             return;
704 704
         }
705 705
         // no event?
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
             $event = $this->_cpt_model_obj;
709 709
         }
710 710
         // STILL no event?
711
-        if (! $event instanceof EE_Event) {
711
+        if ( ! $event instanceof EE_Event) {
712 712
             return;
713 713
         }
714 714
         $orig_status = $event->status();
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
             );
747 747
         }
748 748
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
-        if (! $event->tickets_on_sale()) {
749
+        if ( ! $event->tickets_on_sale()) {
750 750
             return;
751 751
         }
752 752
         // made it here so show warning
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
     {
792 792
         $has_timezone_string = get_option('timezone_string');
793 793
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
794
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
794
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795 795
             EE_Error::add_attention(
796 796
                 sprintf(
797 797
                     __(
@@ -875,31 +875,31 @@  discard block
 block discarded – undo
875 875
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876 876
         $statuses = array(
877 877
             'sold_out_status'  => array(
878
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
878
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
879 879
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880 880
             ),
881 881
             'active_status'    => array(
882
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
882
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
883 883
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884 884
             ),
885 885
             'upcoming_status'  => array(
886
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
886
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
887 887
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888 888
             ),
889 889
             'postponed_status' => array(
890
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
890
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
891 891
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892 892
             ),
893 893
             'cancelled_status' => array(
894
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
894
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
895 895
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896 896
             ),
897 897
             'expired_status'   => array(
898
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
898
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
899 899
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900 900
             ),
901 901
             'inactive_status'  => array(
902
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
902
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
903 903
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904 904
             ),
905 905
         );
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
      */
914 914
     private function _event_model()
915 915
     {
916
-        if (! $this->_event_model instanceof EEM_Event) {
916
+        if ( ! $this->_event_model instanceof EEM_Event) {
917 917
             $this->_event_model = EE_Registry::instance()->load_model('Event');
918 918
         }
919 919
         return $this->_event_model;
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934 934
     {
935 935
         // make sure this is only when editing
936
-        if (! empty($id)) {
936
+        if ( ! empty($id)) {
937 937
             $post = get_post($id);
938 938
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939 939
                        . esc_html__('Shortcode', 'event_espresso')
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
                     'button'
968 968
                 );
969 969
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
970
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
971 971
             'create_new',
972 972
             'add',
973 973
             array(),
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
      */
1108 1108
     protected function _default_venue_update(\EE_Event $evtobj, $data)
1109 1109
     {
1110
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1110
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1111 1111
         $venue_model = EE_Registry::instance()->load_model('Venue');
1112 1112
         $rows_affected = null;
1113 1113
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
             'status'              => 'publish',
1139 1139
         );
1140 1140
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
-        if (! empty($venue_id)) {
1141
+        if ( ! empty($venue_id)) {
1142 1142
             $update_where = array($venue_model->primary_key_name() => $venue_id);
1143 1143
             $rows_affected = $venue_model->update($venue_array, array($update_where));
1144 1144
             // 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
                 'DTT_order'     => $row,
1181 1181
             );
1182 1182
             // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
-            if (! empty($dtt['DTT_ID'])) {
1183
+            if ( ! empty($dtt['DTT_ID'])) {
1184 1184
                 $DTM = EE_Registry::instance()
1185 1185
                                   ->load_model('Datetime', array($evtobj->get_timezone()))
1186 1186
                                   ->get_one_by_ID($dtt['DTT_ID']);
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
                     $DTM->set($field, $value);
1191 1191
                 }
1192 1192
                 // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1193
+                $saved_dtts[$DTM->ID()] = $DTM;
1194 1194
             } else {
1195 1195
                 $DTM = EE_Registry::instance()->load_class(
1196 1196
                     'Datetime',
@@ -1223,14 +1223,14 @@  discard block
 block discarded – undo
1223 1223
         foreach ($data['edit_tickets'] as $row => $tkt) {
1224 1224
             $incoming_date_formats = array('Y-m-d', 'h:i a');
1225 1225
             $update_prices = false;
1226
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1226
+            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1227
+                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1228 1228
             // trim inputs to ensure any excess whitespace is removed.
1229 1229
             $tkt = array_map('trim', $tkt);
1230 1230
             if (empty($tkt['TKT_start_date'])) {
1231 1231
                 // let's use now in the set timezone.
1232 1232
                 $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1233
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1234 1234
             }
1235 1235
             if (empty($tkt['TKT_end_date'])) {
1236 1236
                 // use the start date of the first datetime
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
             // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266 1266
             // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267 1267
             // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
-            if (! empty($tkt['TKT_ID'])) {
1268
+            if ( ! empty($tkt['TKT_ID'])) {
1269 1269
                 $TKT = EE_Registry::instance()
1270 1270
                                   ->load_model('Ticket', array($evtobj->get_timezone()))
1271 1271
                                   ->get_one_by_ID($tkt['TKT_ID']);
@@ -1300,7 +1300,7 @@  discard block
 block discarded – undo
1300 1300
                         $TKT->set('TKT_deleted', 1);
1301 1301
                         $TKT->save();
1302 1302
                         // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1303
+                        $saved_tickets[$TKT->ID()] = $TKT;
1304 1304
                         // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305 1305
                         $TKT = clone $TKT;
1306 1306
                         $TKT->set('TKT_ID', 0);
@@ -1345,9 +1345,9 @@  discard block
 block discarded – undo
1345 1345
             }
1346 1346
             // initially let's add the ticket to the dtt
1347 1347
             $saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1348
+            $saved_tickets[$TKT->ID()] = $TKT;
1349 1349
             // add prices to ticket
1350
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1350
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1351 1351
         }
1352 1352
         // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353 1353
         $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
@@ -1504,7 +1504,7 @@  discard block
 block discarded – undo
1504 1504
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1505 1505
         // load template
1506 1506
         EEH_Template::display_template(
1507
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1507
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1508 1508
             $publish_box_extra_args
1509 1509
         );
1510 1510
     }
@@ -1596,7 +1596,7 @@  discard block
 block discarded – undo
1596 1596
                     'default_where_conditions' => 'none',
1597 1597
                 )
1598 1598
             );
1599
-            if (! empty($related_tickets)) {
1599
+            if ( ! empty($related_tickets)) {
1600 1600
                 $template_args['total_ticket_rows'] = count($related_tickets);
1601 1601
                 $row = 0;
1602 1602
                 foreach ($related_tickets as $ticket) {
@@ -1630,7 +1630,7 @@  discard block
 block discarded – undo
1630 1630
         );
1631 1631
         $template = apply_filters(
1632 1632
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1633
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1633
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1634 1634
         );
1635 1635
         EEH_Template::display_template($template, $template_args);
1636 1636
     }
@@ -1648,7 +1648,7 @@  discard block
 block discarded – undo
1648 1648
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1649 1649
     {
1650 1650
         $template_args = array(
1651
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1651
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1652 1652
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1653 1653
                 : '',
1654 1654
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1660,10 +1660,10 @@  discard block
 block discarded – undo
1660 1660
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1661 1661
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1662 1662
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1663
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1664
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1663
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1664
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1665 1665
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1666
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1666
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1667 1667
                 : ' disabled=disabled',
1668 1668
         );
1669 1669
         $price = $ticket->ID() !== 0
@@ -1690,7 +1690,7 @@  discard block
 block discarded – undo
1690 1690
                     array('order_by' => array('DTT_EVT_start' => 'ASC'))
1691 1691
                 )
1692 1692
                 : null;
1693
-            if (! empty($earliest_dtt)) {
1693
+            if ( ! empty($earliest_dtt)) {
1694 1694
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1695 1695
             } else {
1696 1696
                 $template_args['TKT_end_date'] = date(
@@ -1702,7 +1702,7 @@  discard block
 block discarded – undo
1702 1702
         $template_args = array_merge($template_args, $price_args);
1703 1703
         $template = apply_filters(
1704 1704
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1705
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1705
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1706 1706
             $ticket
1707 1707
         );
1708 1708
         return EEH_Template::display_template($template, $template_args, true);
@@ -1756,7 +1756,7 @@  discard block
 block discarded – undo
1756 1756
             $default_reg_status_values
1757 1757
         );
1758 1758
         EEH_Template::display_template(
1759
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1759
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1760 1760
             $template_args
1761 1761
         );
1762 1762
     }
@@ -1778,7 +1778,7 @@  discard block
 block discarded – undo
1778 1778
     {
1779 1779
         $EEME = $this->_event_model();
1780 1780
         $offset = ($current_page - 1) * $per_page;
1781
-        $limit = $count ? null : $offset . ',' . $per_page;
1781
+        $limit = $count ? null : $offset.','.$per_page;
1782 1782
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1783 1783
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1784 1784
         if (isset($this->_req_data['month_range'])) {
@@ -1807,7 +1807,7 @@  discard block
 block discarded – undo
1807 1807
         // categories?
1808 1808
         $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1809 1809
             ? $this->_req_data['EVT_CAT'] : null;
1810
-        if (! empty($category)) {
1810
+        if ( ! empty($category)) {
1811 1811
             $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1812 1812
             $where['Term_Taxonomy.term_id'] = $category;
1813 1813
         }
@@ -1815,7 +1815,7 @@  discard block
 block discarded – undo
1815 1815
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1816 1816
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1817 1817
             $DateTime = new DateTime(
1818
-                $year_r . '-' . $month_r . '-01 00:00:00',
1818
+                $year_r.'-'.$month_r.'-01 00:00:00',
1819 1819
                 new DateTimeZone('UTC')
1820 1820
             );
1821 1821
             $start = $DateTime->getTimestamp();
@@ -1841,11 +1841,11 @@  discard block
 block discarded – undo
1841 1841
                             ->format(implode(' ', $start_formats));
1842 1842
             $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1843 1843
         }
1844
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1844
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1845 1845
             $where['EVT_wp_user'] = get_current_user_id();
1846 1846
         } else {
1847
-            if (! isset($where['status'])) {
1848
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1847
+            if ( ! isset($where['status'])) {
1848
+                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1849 1849
                     $where['OR'] = array(
1850 1850
                         'status*restrict_private' => array('!=', 'private'),
1851 1851
                         'AND'                     => array(
@@ -1865,7 +1865,7 @@  discard block
 block discarded – undo
1865 1865
         }
1866 1866
         // search query handling
1867 1867
         if (isset($this->_req_data['s'])) {
1868
-            $search_string = '%' . $this->_req_data['s'] . '%';
1868
+            $search_string = '%'.$this->_req_data['s'].'%';
1869 1869
             $where['OR'] = array(
1870 1870
                 'EVT_name'       => array('LIKE', $search_string),
1871 1871
                 'EVT_desc'       => array('LIKE', $search_string),
@@ -1961,7 +1961,7 @@  discard block
 block discarded – undo
1961 1961
             // clean status
1962 1962
             $event_status = sanitize_key($event_status);
1963 1963
             // grab status
1964
-            if (! empty($event_status)) {
1964
+            if ( ! empty($event_status)) {
1965 1965
                 $success = $this->_change_event_status($EVT_ID, $event_status);
1966 1966
             } else {
1967 1967
                 $success = false;
@@ -1998,7 +1998,7 @@  discard block
 block discarded – undo
1998 1998
         // clean status
1999 1999
         $event_status = sanitize_key($event_status);
2000 2000
         // grab status
2001
-        if (! empty($event_status)) {
2001
+        if ( ! empty($event_status)) {
2002 2002
             $success = true;
2003 2003
             // determine the event id and set to array.
2004 2004
             $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
@@ -2045,7 +2045,7 @@  discard block
 block discarded – undo
2045 2045
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2046 2046
     {
2047 2047
         // grab event id
2048
-        if (! $EVT_ID) {
2048
+        if ( ! $EVT_ID) {
2049 2049
             $msg = esc_html__(
2050 2050
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2051 2051
                 'event_espresso'
@@ -2115,7 +2115,7 @@  discard block
 block discarded – undo
2115 2115
      */
2116 2116
     protected function getModelObjNodeGroupPersister()
2117 2117
     {
2118
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2118
+        if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2119 2119
             $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2120 2120
         }
2121 2121
         return $this->model_obj_node_group_persister;
@@ -2367,7 +2367,7 @@  discard block
 block discarded – undo
2367 2367
                                                 . esc_html__(
2368 2368
                                                     '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.',
2369 2369
                                                     'event_espresso'
2370
-                                                ) . '</strong>';
2370
+                                                ).'</strong>';
2371 2371
         $this->display_admin_caf_preview_page('template_settings_tab');
2372 2372
     }
2373 2373
 
@@ -2387,12 +2387,12 @@  discard block
 block discarded – undo
2387 2387
         // set default category object
2388 2388
         $this->_set_empty_category_object();
2389 2389
         // only set if we've got an id
2390
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2390
+        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2391 2391
             return;
2392 2392
         }
2393 2393
         $category_id = absint($this->_req_data['EVT_CAT_ID']);
2394 2394
         $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2395
-        if (! empty($term)) {
2395
+        if ( ! empty($term)) {
2396 2396
             $this->_category->category_name = $term->name;
2397 2397
             $this->_category->category_identifier = $term->slug;
2398 2398
             $this->_category->category_desc = $term->description;
@@ -2420,7 +2420,7 @@  discard block
 block discarded – undo
2420 2420
     {
2421 2421
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2422 2422
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2423
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2423
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2424 2424
             'add_category',
2425 2425
             'add_category',
2426 2426
             array(),
@@ -2494,7 +2494,7 @@  discard block
 block discarded – undo
2494 2494
             'disable'                  => '',
2495 2495
             'disabled_message'         => false,
2496 2496
         );
2497
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2497
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2498 2498
         return EEH_Template::display_template($template, $template_args, true);
2499 2499
     }
2500 2500
 
@@ -2579,7 +2579,7 @@  discard block
 block discarded – undo
2579 2579
         $insert_ids = $update
2580 2580
             ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2581 2581
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2582
-        if (! is_array($insert_ids)) {
2582
+        if ( ! is_array($insert_ids)) {
2583 2583
             $msg = esc_html__(
2584 2584
                 'An error occurred and the category has not been saved to the database.',
2585 2585
                 'event_espresso'
@@ -2610,7 +2610,7 @@  discard block
 block discarded – undo
2610 2610
         $limit = ($current_page - 1) * $per_page;
2611 2611
         $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2612 2612
         if (isset($this->_req_data['s'])) {
2613
-            $sstr = '%' . $this->_req_data['s'] . '%';
2613
+            $sstr = '%'.$this->_req_data['s'].'%';
2614 2614
             $where['OR'] = array(
2615 2615
                 'Term.name'   => array('LIKE', $sstr),
2616 2616
                 'description' => array('LIKE', $sstr),
@@ -2619,7 +2619,7 @@  discard block
 block discarded – undo
2619 2619
         $query_params = array(
2620 2620
             $where,
2621 2621
             'order_by'   => array($orderby => $order),
2622
-            'limit'      => $limit . ',' . $per_page,
2622
+            'limit'      => $limit.','.$per_page,
2623 2623
             'force_join' => array('Term'),
2624 2624
         );
2625 2625
         $categories = $count
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_List_Table.class.php 2 patches
Indentation   +544 added lines, -544 removed lines patch added patch discarded remove patch
@@ -15,548 +15,548 @@
 block discarded – undo
15 15
 class Events_Admin_List_Table extends EE_Admin_List_Table
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Datetime
20
-     */
21
-    private $_dtt;
22
-
23
-
24
-    /**
25
-     * Initial setup of data properties for the list table.
26
-     */
27
-    protected function _setup_data()
28
-    {
29
-        $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
30
-        $this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
31
-    }
32
-
33
-
34
-    /**
35
-     * Set up of additional properties for the list table.
36
-     */
37
-    protected function _set_properties()
38
-    {
39
-        $this->_wp_list_args = array(
40
-            'singular' => esc_html__('event', 'event_espresso'),
41
-            'plural'   => esc_html__('events', 'event_espresso'),
42
-            'ajax'     => true, // for now
43
-            'screen'   => $this->_admin_page->get_current_screen()->id,
44
-        );
45
-        $this->_columns = array(
46
-            'cb'              => '<input type="checkbox" />',
47
-            'id'              => esc_html__('ID', 'event_espresso'),
48
-            'name'            => esc_html__('Name', 'event_espresso'),
49
-            'author'          => esc_html__('Author', 'event_espresso'),
50
-            'venue'           => esc_html__('Venue', 'event_espresso'),
51
-            'start_date_time' => esc_html__('Event Start', 'event_espresso'),
52
-            'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
53
-            'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
54
-                                 . '<span class="screen-reader-text">'
55
-                                 . esc_html__('Approved Registrations', 'event_espresso')
56
-                                 . '</span>'
57
-                                 . '</span>',
58
-            // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
59
-            'actions'         => esc_html__('Actions', 'event_espresso'),
60
-        );
61
-        $this->addConditionalColumns();
62
-        $this->_sortable_columns = array(
63
-            'id'              => array('EVT_ID' => true),
64
-            'name'            => array('EVT_name' => false),
65
-            'author'          => array('EVT_wp_user' => false),
66
-            'venue'           => array('Venue.VNU_name' => false),
67
-            'start_date_time' => array('Datetime.DTT_EVT_start' => false),
68
-            'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
69
-        );
70
-
71
-        $this->_primary_column = 'id';
72
-        $this->_hidden_columns = array('author', 'event_category');
73
-    }
74
-
75
-
76
-    /**
77
-     * @return array
78
-     */
79
-    protected function _get_table_filters()
80
-    {
81
-        return array(); // no filters with decaf
82
-    }
83
-
84
-
85
-    /**
86
-     * Setup of views properties.
87
-     *
88
-     * @throws InvalidDataTypeException
89
-     * @throws InvalidInterfaceException
90
-     * @throws InvalidArgumentException
91
-     */
92
-    protected function _add_view_counts()
93
-    {
94
-        $this->_views['all']['count'] = $this->_admin_page->total_events();
95
-        $this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
96
-        if (EE_Registry::instance()->CAP->current_user_can(
97
-            'ee_delete_events',
98
-            'espresso_events_trash_events'
99
-        )) {
100
-            $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
101
-        }
102
-    }
103
-
104
-
105
-    /**
106
-     * @param EE_Event $item
107
-     * @return string
108
-     * @throws EE_Error
109
-     */
110
-    protected function _get_row_class($item)
111
-    {
112
-        $class = parent::_get_row_class($item);
113
-        // add status class
114
-        $class .= $item instanceof EE_Event
115
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
116
-            : '';
117
-        if ($this->_has_checkbox_column) {
118
-            $class .= ' has-checkbox-column';
119
-        }
120
-        return $class;
121
-    }
122
-
123
-
124
-    /**
125
-     * @param EE_Event $item
126
-     * @return string
127
-     * @throws EE_Error
128
-     */
129
-    public function column_status(EE_Event $item)
130
-    {
131
-        return '<span class="ee-status-strip ee-status-strip-td event-status-'
132
-               . $item->get_active_status()
133
-               . '"></span>';
134
-    }
135
-
136
-
137
-    /**
138
-     * @param  EE_Event $item
139
-     * @return string
140
-     * @throws EE_Error
141
-     */
142
-    public function column_cb($item)
143
-    {
144
-        if (! $item instanceof EE_Event) {
145
-            return '';
146
-        }
147
-        $this->_dtt = $item->primary_datetime(); // set this for use in other columns
148
-        return sprintf(
149
-            '<input type="checkbox" name="EVT_IDs[]" value="%s" />',
150
-            $item->ID()
151
-        );
152
-    }
153
-
154
-
155
-    /**
156
-     * @param EE_Event $item
157
-     * @return mixed|string
158
-     * @throws EE_Error
159
-     */
160
-    public function column_id(EE_Event $item)
161
-    {
162
-        $content = $item->ID();
163
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
164
-        return $content;
165
-    }
166
-
167
-
168
-    /**
169
-     * @param EE_Event $item
170
-     * @return string
171
-     * @throws EE_Error
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidDataTypeException
174
-     * @throws InvalidInterfaceException
175
-     */
176
-    public function column_name(EE_Event $item)
177
-    {
178
-        $edit_query_args = array(
179
-            'action' => 'edit',
180
-            'post'   => $item->ID(),
181
-        );
182
-        $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
183
-        $actions = $this->_column_name_action_setup($item);
184
-        $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
185
-        $content = '<strong><a class="row-title" href="'
186
-                   . $edit_link . '">'
187
-                   . $item->name()
188
-                   . '</a></strong>'
189
-                   . $status;
190
-        $content .= '<br><span class="ee-status-text-small">'
191
-                    . EEH_Template::pretty_status(
192
-                        $item->get_active_status(),
193
-                        false,
194
-                        'sentence'
195
-                    )
196
-                    . '</span>';
197
-        $content .= $this->row_actions($actions);
198
-        return $content;
199
-    }
200
-
201
-
202
-    /**
203
-     * Just a method for setting up the actions for the name column
204
-     *
205
-     * @param EE_Event $item
206
-     * @return array array of actions
207
-     * @throws EE_Error
208
-     * @throws InvalidArgumentException
209
-     * @throws InvalidDataTypeException
210
-     * @throws InvalidInterfaceException
211
-     */
212
-    protected function _column_name_action_setup(EE_Event $item)
213
-    {
214
-        // todo: remove when attendees is active
215
-        if (! defined('REG_ADMIN_URL')) {
216
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
217
-        }
218
-        $actions = array();
219
-        $restore_event_link = '';
220
-        $delete_event_link = '';
221
-        $trash_event_link = '';
222
-        if (EE_Registry::instance()->CAP->current_user_can(
223
-            'ee_edit_event',
224
-            'espresso_events_edit',
225
-            $item->ID()
226
-        )) {
227
-            $edit_query_args = array(
228
-                'action' => 'edit',
229
-                'post'   => $item->ID(),
230
-            );
231
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
232
-            $actions['edit'] = '<a href="' . $edit_link . '"'
233
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
234
-                               . esc_html__('Edit', 'event_espresso')
235
-                               . '</a>';
236
-        }
237
-        if (EE_Registry::instance()->CAP->current_user_can(
238
-            'ee_read_registrations',
239
-            'espresso_registrations_view_registration'
240
-        )
241
-            && EE_Registry::instance()->CAP->current_user_can(
242
-                'ee_read_event',
243
-                'espresso_registrations_view_registration',
244
-                $item->ID()
245
-            )
246
-        ) {
247
-            $attendees_query_args = array(
248
-                'action'   => 'default',
249
-                'event_id' => $item->ID(),
250
-            );
251
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
252
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
253
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
254
-                                    . esc_html__('Registrations', 'event_espresso')
255
-                                    . '</a>';
256
-        }
257
-        if (EE_Registry::instance()->CAP->current_user_can(
258
-            'ee_delete_event',
259
-            'espresso_events_trash_event',
260
-            $item->ID()
261
-        )) {
262
-            $trash_event_query_args = array(
263
-                'action' => 'trash_event',
264
-                'EVT_ID' => $item->ID(),
265
-            );
266
-            $trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
267
-                $trash_event_query_args,
268
-                EVENTS_ADMIN_URL
269
-            );
270
-        }
271
-        if (EE_Registry::instance()->CAP->current_user_can(
272
-            'ee_delete_event',
273
-            'espresso_events_restore_event',
274
-            $item->ID()
275
-        )) {
276
-            $restore_event_query_args = array(
277
-                'action' => 'restore_event',
278
-                'EVT_ID' => $item->ID(),
279
-            );
280
-            $restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
281
-                $restore_event_query_args,
282
-                EVENTS_ADMIN_URL
283
-            );
284
-        }
285
-        if (EE_Registry::instance()->CAP->current_user_can(
286
-            'ee_delete_event',
287
-            'espresso_events_delete_event',
288
-            $item->ID()
289
-        )) {
290
-            $delete_event_query_args = array(
291
-                'action' => 'delete_event',
292
-                'EVT_ID' => $item->ID(),
293
-            );
294
-            $delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
295
-                $delete_event_query_args,
296
-                EVENTS_ADMIN_URL
297
-            );
298
-        }
299
-        $view_link = get_permalink($item->ID());
300
-        $actions['view'] = '<a href="' . $view_link . '"'
301
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
302
-                           . esc_html__('View', 'event_espresso')
303
-                           . '</a>';
304
-        if ($item->get('status') === 'trash') {
305
-            if (EE_Registry::instance()->CAP->current_user_can(
306
-                'ee_delete_event',
307
-                'espresso_events_restore_event',
308
-                $item->ID()
309
-            )) {
310
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
311
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
312
-                                                 . '">'
313
-                                                 . esc_html__('Restore from Trash', 'event_espresso')
314
-                                                 . '</a>';
315
-            }
316
-            if (EE_Registry::instance()->CAP->current_user_can(
317
-                'ee_delete_event',
318
-                'espresso_events_delete_event',
319
-                $item->ID()
320
-            )
321
-            ) {
322
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
323
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
324
-                                     . esc_html__('Delete Permanently', 'event_espresso')
325
-                                     . '</a>';
326
-            }
327
-        } else {
328
-            if (EE_Registry::instance()->CAP->current_user_can(
329
-                'ee_delete_event',
330
-                'espresso_events_trash_event',
331
-                $item->ID()
332
-            )) {
333
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
334
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
335
-                                            . esc_html__('Trash', 'event_espresso')
336
-                                            . '</a>';
337
-            }
338
-        }
339
-        return $actions;
340
-    }
341
-
342
-
343
-    /**
344
-     * @param EE_Event $item
345
-     * @return string
346
-     * @throws EE_Error
347
-     */
348
-    public function column_author(EE_Event $item)
349
-    {
350
-        // user author info
351
-        $event_author = get_userdata($item->wp_user());
352
-        $gravatar = get_avatar($item->wp_user(), '15');
353
-        // filter link
354
-        $query_args = array(
355
-            'action'      => 'default',
356
-            'EVT_wp_user' => $item->wp_user(),
357
-        );
358
-        $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
359
-        return $gravatar . '  <a href="' . $filter_url . '"'
360
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
361
-               . $event_author->display_name
362
-               . '</a>';
363
-    }
364
-
365
-
366
-    /**
367
-     * @param EE_Event $event
368
-     * @return string
369
-     * @throws EE_Error
370
-     */
371
-    public function column_event_category(EE_Event $event)
372
-    {
373
-        $event_categories = $event->get_all_event_categories();
374
-        return implode(
375
-            ', ',
376
-            array_map(
377
-                function (EE_Term $category) {
378
-                    return $category->name();
379
-                },
380
-                $event_categories
381
-            )
382
-        );
383
-    }
384
-
385
-
386
-    /**
387
-     * @param EE_Event $item
388
-     * @return string
389
-     * @throws EE_Error
390
-     */
391
-    public function column_venue(EE_Event $item)
392
-    {
393
-        $venue = $item->get_first_related('Venue');
394
-        return ! empty($venue)
395
-            ? $venue->name()
396
-            : '';
397
-    }
398
-
399
-
400
-    /**
401
-     * @param EE_Event $item
402
-     * @return string
403
-     * @throws EE_Error
404
-     */
405
-    public function column_start_date_time(EE_Event $item)
406
-    {
407
-        return $this->_dtt instanceof EE_Datetime
408
-            ? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
409
-            : esc_html__('No Date was saved for this Event', 'event_espresso');
410
-    }
411
-
412
-
413
-    /**
414
-     * @param EE_Event $item
415
-     * @return string
416
-     * @throws EE_Error
417
-     */
418
-    public function column_reg_begins(EE_Event $item)
419
-    {
420
-        $reg_start = $item->get_ticket_with_earliest_start_time();
421
-        return $reg_start instanceof EE_Ticket
422
-            ? $reg_start->get_i18n_datetime('TKT_start_date')
423
-            : esc_html__('No Tickets have been setup for this Event', 'event_espresso');
424
-    }
425
-
426
-
427
-    /**
428
-     * @param EE_Event $item
429
-     * @return int|string
430
-     * @throws EE_Error
431
-     * @throws InvalidArgumentException
432
-     * @throws InvalidDataTypeException
433
-     * @throws InvalidInterfaceException
434
-     */
435
-    public function column_attendees(EE_Event $item)
436
-    {
437
-        $attendees_query_args = array(
438
-            'action'   => 'default',
439
-            'event_id' => $item->ID(),
440
-        );
441
-        $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
442
-        $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
443
-        return EE_Registry::instance()->CAP->current_user_can(
444
-            'ee_read_event',
445
-            'espresso_registrations_view_registration',
446
-            $item->ID()
447
-        )
448
-               && EE_Registry::instance()->CAP->current_user_can(
449
-                   'ee_read_registrations',
450
-                   'espresso_registrations_view_registration'
451
-               )
452
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
453
-            : $registered_attendees;
454
-    }
455
-
456
-
457
-    /**
458
-     * @param EE_Event $item
459
-     * @return float
460
-     * @throws EE_Error
461
-     * @throws InvalidArgumentException
462
-     * @throws InvalidDataTypeException
463
-     * @throws InvalidInterfaceException
464
-     */
465
-    public function column_tkts_sold(EE_Event $item)
466
-    {
467
-        return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
468
-    }
469
-
470
-
471
-    /**
472
-     * @param EE_Event $item
473
-     * @return string
474
-     * @throws EE_Error
475
-     * @throws InvalidArgumentException
476
-     * @throws InvalidDataTypeException
477
-     * @throws InvalidInterfaceException
478
-     */
479
-    public function column_actions(EE_Event $item)
480
-    {
481
-        // todo: remove when attendees is active
482
-        if (! defined('REG_ADMIN_URL')) {
483
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
484
-        }
485
-        $action_links = array();
486
-        $view_link = get_permalink($item->ID());
487
-        $action_links[] = '<a href="' . $view_link . '"'
488
-                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
489
-        $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
490
-        if (EE_Registry::instance()->CAP->current_user_can(
491
-            'ee_edit_event',
492
-            'espresso_events_edit',
493
-            $item->ID()
494
-        )) {
495
-            $edit_query_args = array(
496
-                'action' => 'edit',
497
-                'post'   => $item->ID(),
498
-            );
499
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
500
-            $action_links[] = '<a href="' . $edit_link . '"'
501
-                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
502
-                              . '<div class="ee-icon ee-icon-calendar-edit"></div>'
503
-                              . '</a>';
504
-        }
505
-        if (EE_Registry::instance()->CAP->current_user_can(
506
-            'ee_read_registrations',
507
-            'espresso_registrations_view_registration'
508
-        ) && EE_Registry::instance()->CAP->current_user_can(
509
-            'ee_read_event',
510
-            'espresso_registrations_view_registration',
511
-            $item->ID()
512
-        )
513
-        ) {
514
-            $attendees_query_args = array(
515
-                'action'   => 'default',
516
-                'event_id' => $item->ID(),
517
-            );
518
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
519
-            $action_links[] = '<a href="' . $attendees_link . '"'
520
-                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
521
-                              . '<div class="dashicons dashicons-groups"></div>'
522
-                              . '</a>';
523
-        }
524
-        $action_links = apply_filters(
525
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
526
-            $action_links,
527
-            $item
528
-        );
529
-        return $this->_action_string(
530
-            implode("\n\t", $action_links),
531
-            $item,
532
-            'div'
533
-        );
534
-    }
535
-
536
-
537
-    /**
538
-     * Helper for adding columns conditionally
539
-     *
540
-     * @throws EE_Error
541
-     * @throws InvalidArgumentException
542
-     * @throws InvalidDataTypeException
543
-     * @throws InvalidInterfaceException
544
-     */
545
-    private function addConditionalColumns()
546
-    {
547
-        $event_category_count = EEM_Term::instance()->count(
548
-            [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
549
-        );
550
-        if ($event_category_count === 0) {
551
-            return;
552
-        }
553
-        $column_array = [];
554
-        foreach ($this->_columns as $column => $column_label) {
555
-            $column_array[ $column ] = $column_label;
556
-            if ($column === 'venue') {
557
-                $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
558
-            }
559
-        }
560
-        $this->_columns = $column_array;
561
-    }
18
+	/**
19
+	 * @var EE_Datetime
20
+	 */
21
+	private $_dtt;
22
+
23
+
24
+	/**
25
+	 * Initial setup of data properties for the list table.
26
+	 */
27
+	protected function _setup_data()
28
+	{
29
+		$this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
30
+		$this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
31
+	}
32
+
33
+
34
+	/**
35
+	 * Set up of additional properties for the list table.
36
+	 */
37
+	protected function _set_properties()
38
+	{
39
+		$this->_wp_list_args = array(
40
+			'singular' => esc_html__('event', 'event_espresso'),
41
+			'plural'   => esc_html__('events', 'event_espresso'),
42
+			'ajax'     => true, // for now
43
+			'screen'   => $this->_admin_page->get_current_screen()->id,
44
+		);
45
+		$this->_columns = array(
46
+			'cb'              => '<input type="checkbox" />',
47
+			'id'              => esc_html__('ID', 'event_espresso'),
48
+			'name'            => esc_html__('Name', 'event_espresso'),
49
+			'author'          => esc_html__('Author', 'event_espresso'),
50
+			'venue'           => esc_html__('Venue', 'event_espresso'),
51
+			'start_date_time' => esc_html__('Event Start', 'event_espresso'),
52
+			'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
53
+			'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
54
+								 . '<span class="screen-reader-text">'
55
+								 . esc_html__('Approved Registrations', 'event_espresso')
56
+								 . '</span>'
57
+								 . '</span>',
58
+			// 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
59
+			'actions'         => esc_html__('Actions', 'event_espresso'),
60
+		);
61
+		$this->addConditionalColumns();
62
+		$this->_sortable_columns = array(
63
+			'id'              => array('EVT_ID' => true),
64
+			'name'            => array('EVT_name' => false),
65
+			'author'          => array('EVT_wp_user' => false),
66
+			'venue'           => array('Venue.VNU_name' => false),
67
+			'start_date_time' => array('Datetime.DTT_EVT_start' => false),
68
+			'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
69
+		);
70
+
71
+		$this->_primary_column = 'id';
72
+		$this->_hidden_columns = array('author', 'event_category');
73
+	}
74
+
75
+
76
+	/**
77
+	 * @return array
78
+	 */
79
+	protected function _get_table_filters()
80
+	{
81
+		return array(); // no filters with decaf
82
+	}
83
+
84
+
85
+	/**
86
+	 * Setup of views properties.
87
+	 *
88
+	 * @throws InvalidDataTypeException
89
+	 * @throws InvalidInterfaceException
90
+	 * @throws InvalidArgumentException
91
+	 */
92
+	protected function _add_view_counts()
93
+	{
94
+		$this->_views['all']['count'] = $this->_admin_page->total_events();
95
+		$this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
96
+		if (EE_Registry::instance()->CAP->current_user_can(
97
+			'ee_delete_events',
98
+			'espresso_events_trash_events'
99
+		)) {
100
+			$this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
101
+		}
102
+	}
103
+
104
+
105
+	/**
106
+	 * @param EE_Event $item
107
+	 * @return string
108
+	 * @throws EE_Error
109
+	 */
110
+	protected function _get_row_class($item)
111
+	{
112
+		$class = parent::_get_row_class($item);
113
+		// add status class
114
+		$class .= $item instanceof EE_Event
115
+			? ' ee-status-strip event-status-' . $item->get_active_status()
116
+			: '';
117
+		if ($this->_has_checkbox_column) {
118
+			$class .= ' has-checkbox-column';
119
+		}
120
+		return $class;
121
+	}
122
+
123
+
124
+	/**
125
+	 * @param EE_Event $item
126
+	 * @return string
127
+	 * @throws EE_Error
128
+	 */
129
+	public function column_status(EE_Event $item)
130
+	{
131
+		return '<span class="ee-status-strip ee-status-strip-td event-status-'
132
+			   . $item->get_active_status()
133
+			   . '"></span>';
134
+	}
135
+
136
+
137
+	/**
138
+	 * @param  EE_Event $item
139
+	 * @return string
140
+	 * @throws EE_Error
141
+	 */
142
+	public function column_cb($item)
143
+	{
144
+		if (! $item instanceof EE_Event) {
145
+			return '';
146
+		}
147
+		$this->_dtt = $item->primary_datetime(); // set this for use in other columns
148
+		return sprintf(
149
+			'<input type="checkbox" name="EVT_IDs[]" value="%s" />',
150
+			$item->ID()
151
+		);
152
+	}
153
+
154
+
155
+	/**
156
+	 * @param EE_Event $item
157
+	 * @return mixed|string
158
+	 * @throws EE_Error
159
+	 */
160
+	public function column_id(EE_Event $item)
161
+	{
162
+		$content = $item->ID();
163
+		$content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
164
+		return $content;
165
+	}
166
+
167
+
168
+	/**
169
+	 * @param EE_Event $item
170
+	 * @return string
171
+	 * @throws EE_Error
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidDataTypeException
174
+	 * @throws InvalidInterfaceException
175
+	 */
176
+	public function column_name(EE_Event $item)
177
+	{
178
+		$edit_query_args = array(
179
+			'action' => 'edit',
180
+			'post'   => $item->ID(),
181
+		);
182
+		$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
183
+		$actions = $this->_column_name_action_setup($item);
184
+		$status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
185
+		$content = '<strong><a class="row-title" href="'
186
+				   . $edit_link . '">'
187
+				   . $item->name()
188
+				   . '</a></strong>'
189
+				   . $status;
190
+		$content .= '<br><span class="ee-status-text-small">'
191
+					. EEH_Template::pretty_status(
192
+						$item->get_active_status(),
193
+						false,
194
+						'sentence'
195
+					)
196
+					. '</span>';
197
+		$content .= $this->row_actions($actions);
198
+		return $content;
199
+	}
200
+
201
+
202
+	/**
203
+	 * Just a method for setting up the actions for the name column
204
+	 *
205
+	 * @param EE_Event $item
206
+	 * @return array array of actions
207
+	 * @throws EE_Error
208
+	 * @throws InvalidArgumentException
209
+	 * @throws InvalidDataTypeException
210
+	 * @throws InvalidInterfaceException
211
+	 */
212
+	protected function _column_name_action_setup(EE_Event $item)
213
+	{
214
+		// todo: remove when attendees is active
215
+		if (! defined('REG_ADMIN_URL')) {
216
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
217
+		}
218
+		$actions = array();
219
+		$restore_event_link = '';
220
+		$delete_event_link = '';
221
+		$trash_event_link = '';
222
+		if (EE_Registry::instance()->CAP->current_user_can(
223
+			'ee_edit_event',
224
+			'espresso_events_edit',
225
+			$item->ID()
226
+		)) {
227
+			$edit_query_args = array(
228
+				'action' => 'edit',
229
+				'post'   => $item->ID(),
230
+			);
231
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
232
+			$actions['edit'] = '<a href="' . $edit_link . '"'
233
+							   . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
234
+							   . esc_html__('Edit', 'event_espresso')
235
+							   . '</a>';
236
+		}
237
+		if (EE_Registry::instance()->CAP->current_user_can(
238
+			'ee_read_registrations',
239
+			'espresso_registrations_view_registration'
240
+		)
241
+			&& EE_Registry::instance()->CAP->current_user_can(
242
+				'ee_read_event',
243
+				'espresso_registrations_view_registration',
244
+				$item->ID()
245
+			)
246
+		) {
247
+			$attendees_query_args = array(
248
+				'action'   => 'default',
249
+				'event_id' => $item->ID(),
250
+			);
251
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
252
+			$actions['attendees'] = '<a href="' . $attendees_link . '"'
253
+									. ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
254
+									. esc_html__('Registrations', 'event_espresso')
255
+									. '</a>';
256
+		}
257
+		if (EE_Registry::instance()->CAP->current_user_can(
258
+			'ee_delete_event',
259
+			'espresso_events_trash_event',
260
+			$item->ID()
261
+		)) {
262
+			$trash_event_query_args = array(
263
+				'action' => 'trash_event',
264
+				'EVT_ID' => $item->ID(),
265
+			);
266
+			$trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
267
+				$trash_event_query_args,
268
+				EVENTS_ADMIN_URL
269
+			);
270
+		}
271
+		if (EE_Registry::instance()->CAP->current_user_can(
272
+			'ee_delete_event',
273
+			'espresso_events_restore_event',
274
+			$item->ID()
275
+		)) {
276
+			$restore_event_query_args = array(
277
+				'action' => 'restore_event',
278
+				'EVT_ID' => $item->ID(),
279
+			);
280
+			$restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
281
+				$restore_event_query_args,
282
+				EVENTS_ADMIN_URL
283
+			);
284
+		}
285
+		if (EE_Registry::instance()->CAP->current_user_can(
286
+			'ee_delete_event',
287
+			'espresso_events_delete_event',
288
+			$item->ID()
289
+		)) {
290
+			$delete_event_query_args = array(
291
+				'action' => 'delete_event',
292
+				'EVT_ID' => $item->ID(),
293
+			);
294
+			$delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
295
+				$delete_event_query_args,
296
+				EVENTS_ADMIN_URL
297
+			);
298
+		}
299
+		$view_link = get_permalink($item->ID());
300
+		$actions['view'] = '<a href="' . $view_link . '"'
301
+						   . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
302
+						   . esc_html__('View', 'event_espresso')
303
+						   . '</a>';
304
+		if ($item->get('status') === 'trash') {
305
+			if (EE_Registry::instance()->CAP->current_user_can(
306
+				'ee_delete_event',
307
+				'espresso_events_restore_event',
308
+				$item->ID()
309
+			)) {
310
+				$actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
311
+												 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
312
+												 . '">'
313
+												 . esc_html__('Restore from Trash', 'event_espresso')
314
+												 . '</a>';
315
+			}
316
+			if (EE_Registry::instance()->CAP->current_user_can(
317
+				'ee_delete_event',
318
+				'espresso_events_delete_event',
319
+				$item->ID()
320
+			)
321
+			) {
322
+				$actions['delete'] = '<a href="' . $delete_event_link . '"'
323
+									 . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
324
+									 . esc_html__('Delete Permanently', 'event_espresso')
325
+									 . '</a>';
326
+			}
327
+		} else {
328
+			if (EE_Registry::instance()->CAP->current_user_can(
329
+				'ee_delete_event',
330
+				'espresso_events_trash_event',
331
+				$item->ID()
332
+			)) {
333
+				$actions['move to trash'] = '<a href="' . $trash_event_link . '"'
334
+											. ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
335
+											. esc_html__('Trash', 'event_espresso')
336
+											. '</a>';
337
+			}
338
+		}
339
+		return $actions;
340
+	}
341
+
342
+
343
+	/**
344
+	 * @param EE_Event $item
345
+	 * @return string
346
+	 * @throws EE_Error
347
+	 */
348
+	public function column_author(EE_Event $item)
349
+	{
350
+		// user author info
351
+		$event_author = get_userdata($item->wp_user());
352
+		$gravatar = get_avatar($item->wp_user(), '15');
353
+		// filter link
354
+		$query_args = array(
355
+			'action'      => 'default',
356
+			'EVT_wp_user' => $item->wp_user(),
357
+		);
358
+		$filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
359
+		return $gravatar . '  <a href="' . $filter_url . '"'
360
+			   . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
361
+			   . $event_author->display_name
362
+			   . '</a>';
363
+	}
364
+
365
+
366
+	/**
367
+	 * @param EE_Event $event
368
+	 * @return string
369
+	 * @throws EE_Error
370
+	 */
371
+	public function column_event_category(EE_Event $event)
372
+	{
373
+		$event_categories = $event->get_all_event_categories();
374
+		return implode(
375
+			', ',
376
+			array_map(
377
+				function (EE_Term $category) {
378
+					return $category->name();
379
+				},
380
+				$event_categories
381
+			)
382
+		);
383
+	}
384
+
385
+
386
+	/**
387
+	 * @param EE_Event $item
388
+	 * @return string
389
+	 * @throws EE_Error
390
+	 */
391
+	public function column_venue(EE_Event $item)
392
+	{
393
+		$venue = $item->get_first_related('Venue');
394
+		return ! empty($venue)
395
+			? $venue->name()
396
+			: '';
397
+	}
398
+
399
+
400
+	/**
401
+	 * @param EE_Event $item
402
+	 * @return string
403
+	 * @throws EE_Error
404
+	 */
405
+	public function column_start_date_time(EE_Event $item)
406
+	{
407
+		return $this->_dtt instanceof EE_Datetime
408
+			? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
409
+			: esc_html__('No Date was saved for this Event', 'event_espresso');
410
+	}
411
+
412
+
413
+	/**
414
+	 * @param EE_Event $item
415
+	 * @return string
416
+	 * @throws EE_Error
417
+	 */
418
+	public function column_reg_begins(EE_Event $item)
419
+	{
420
+		$reg_start = $item->get_ticket_with_earliest_start_time();
421
+		return $reg_start instanceof EE_Ticket
422
+			? $reg_start->get_i18n_datetime('TKT_start_date')
423
+			: esc_html__('No Tickets have been setup for this Event', 'event_espresso');
424
+	}
425
+
426
+
427
+	/**
428
+	 * @param EE_Event $item
429
+	 * @return int|string
430
+	 * @throws EE_Error
431
+	 * @throws InvalidArgumentException
432
+	 * @throws InvalidDataTypeException
433
+	 * @throws InvalidInterfaceException
434
+	 */
435
+	public function column_attendees(EE_Event $item)
436
+	{
437
+		$attendees_query_args = array(
438
+			'action'   => 'default',
439
+			'event_id' => $item->ID(),
440
+		);
441
+		$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
442
+		$registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
443
+		return EE_Registry::instance()->CAP->current_user_can(
444
+			'ee_read_event',
445
+			'espresso_registrations_view_registration',
446
+			$item->ID()
447
+		)
448
+			   && EE_Registry::instance()->CAP->current_user_can(
449
+				   'ee_read_registrations',
450
+				   'espresso_registrations_view_registration'
451
+			   )
452
+			? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
453
+			: $registered_attendees;
454
+	}
455
+
456
+
457
+	/**
458
+	 * @param EE_Event $item
459
+	 * @return float
460
+	 * @throws EE_Error
461
+	 * @throws InvalidArgumentException
462
+	 * @throws InvalidDataTypeException
463
+	 * @throws InvalidInterfaceException
464
+	 */
465
+	public function column_tkts_sold(EE_Event $item)
466
+	{
467
+		return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
468
+	}
469
+
470
+
471
+	/**
472
+	 * @param EE_Event $item
473
+	 * @return string
474
+	 * @throws EE_Error
475
+	 * @throws InvalidArgumentException
476
+	 * @throws InvalidDataTypeException
477
+	 * @throws InvalidInterfaceException
478
+	 */
479
+	public function column_actions(EE_Event $item)
480
+	{
481
+		// todo: remove when attendees is active
482
+		if (! defined('REG_ADMIN_URL')) {
483
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
484
+		}
485
+		$action_links = array();
486
+		$view_link = get_permalink($item->ID());
487
+		$action_links[] = '<a href="' . $view_link . '"'
488
+						  . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
489
+		$action_links[] = '<div class="dashicons dashicons-search"></div></a>';
490
+		if (EE_Registry::instance()->CAP->current_user_can(
491
+			'ee_edit_event',
492
+			'espresso_events_edit',
493
+			$item->ID()
494
+		)) {
495
+			$edit_query_args = array(
496
+				'action' => 'edit',
497
+				'post'   => $item->ID(),
498
+			);
499
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
500
+			$action_links[] = '<a href="' . $edit_link . '"'
501
+							  . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
502
+							  . '<div class="ee-icon ee-icon-calendar-edit"></div>'
503
+							  . '</a>';
504
+		}
505
+		if (EE_Registry::instance()->CAP->current_user_can(
506
+			'ee_read_registrations',
507
+			'espresso_registrations_view_registration'
508
+		) && EE_Registry::instance()->CAP->current_user_can(
509
+			'ee_read_event',
510
+			'espresso_registrations_view_registration',
511
+			$item->ID()
512
+		)
513
+		) {
514
+			$attendees_query_args = array(
515
+				'action'   => 'default',
516
+				'event_id' => $item->ID(),
517
+			);
518
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
519
+			$action_links[] = '<a href="' . $attendees_link . '"'
520
+							  . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
521
+							  . '<div class="dashicons dashicons-groups"></div>'
522
+							  . '</a>';
523
+		}
524
+		$action_links = apply_filters(
525
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
526
+			$action_links,
527
+			$item
528
+		);
529
+		return $this->_action_string(
530
+			implode("\n\t", $action_links),
531
+			$item,
532
+			'div'
533
+		);
534
+	}
535
+
536
+
537
+	/**
538
+	 * Helper for adding columns conditionally
539
+	 *
540
+	 * @throws EE_Error
541
+	 * @throws InvalidArgumentException
542
+	 * @throws InvalidDataTypeException
543
+	 * @throws InvalidInterfaceException
544
+	 */
545
+	private function addConditionalColumns()
546
+	{
547
+		$event_category_count = EEM_Term::instance()->count(
548
+			[['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
549
+		);
550
+		if ($event_category_count === 0) {
551
+			return;
552
+		}
553
+		$column_array = [];
554
+		foreach ($this->_columns as $column => $column_label) {
555
+			$column_array[ $column ] = $column_label;
556
+			if ($column === 'venue') {
557
+				$column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
558
+			}
559
+		}
560
+		$this->_columns = $column_array;
561
+	}
562 562
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         $class = parent::_get_row_class($item);
113 113
         // add status class
114 114
         $class .= $item instanceof EE_Event
115
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
115
+            ? ' ee-status-strip event-status-'.$item->get_active_status()
116 116
             : '';
117 117
         if ($this->_has_checkbox_column) {
118 118
             $class .= ' has-checkbox-column';
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function column_cb($item)
143 143
     {
144
-        if (! $item instanceof EE_Event) {
144
+        if ( ! $item instanceof EE_Event) {
145 145
             return '';
146 146
         }
147 147
         $this->_dtt = $item->primary_datetime(); // set this for use in other columns
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
     public function column_id(EE_Event $item)
161 161
     {
162 162
         $content = $item->ID();
163
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
163
+        $content .= '  <span class="show-on-mobile-view-only">'.$item->name().'</span>';
164 164
         return $content;
165 165
     }
166 166
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
         $actions = $this->_column_name_action_setup($item);
184 184
         $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
185 185
         $content = '<strong><a class="row-title" href="'
186
-                   . $edit_link . '">'
186
+                   . $edit_link.'">'
187 187
                    . $item->name()
188 188
                    . '</a></strong>'
189 189
                    . $status;
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
     protected function _column_name_action_setup(EE_Event $item)
213 213
     {
214 214
         // todo: remove when attendees is active
215
-        if (! defined('REG_ADMIN_URL')) {
215
+        if ( ! defined('REG_ADMIN_URL')) {
216 216
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
217 217
         }
218 218
         $actions = array();
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
                 'post'   => $item->ID(),
230 230
             );
231 231
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
232
-            $actions['edit'] = '<a href="' . $edit_link . '"'
233
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
232
+            $actions['edit'] = '<a href="'.$edit_link.'"'
233
+                               . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">'
234 234
                                . esc_html__('Edit', 'event_espresso')
235 235
                                . '</a>';
236 236
         }
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
                 'event_id' => $item->ID(),
250 250
             );
251 251
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
252
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
253
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
252
+            $actions['attendees'] = '<a href="'.$attendees_link.'"'
253
+                                    . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">'
254 254
                                     . esc_html__('Registrations', 'event_espresso')
255 255
                                     . '</a>';
256 256
         }
@@ -297,8 +297,8 @@  discard block
 block discarded – undo
297 297
             );
298 298
         }
299 299
         $view_link = get_permalink($item->ID());
300
-        $actions['view'] = '<a href="' . $view_link . '"'
301
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
300
+        $actions['view'] = '<a href="'.$view_link.'"'
301
+                           . ' title="'.esc_attr__('View Event', 'event_espresso').'">'
302 302
                            . esc_html__('View', 'event_espresso')
303 303
                            . '</a>';
304 304
         if ($item->get('status') === 'trash') {
@@ -307,8 +307,8 @@  discard block
 block discarded – undo
307 307
                 'espresso_events_restore_event',
308 308
                 $item->ID()
309 309
             )) {
310
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
311
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
310
+                $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"'
311
+                                                 . ' title="'.esc_attr__('Restore from Trash', 'event_espresso')
312 312
                                                  . '">'
313 313
                                                  . esc_html__('Restore from Trash', 'event_espresso')
314 314
                                                  . '</a>';
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
                 $item->ID()
320 320
             )
321 321
             ) {
322
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
323
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
322
+                $actions['delete'] = '<a href="'.$delete_event_link.'"'
323
+                                     . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">'
324 324
                                      . esc_html__('Delete Permanently', 'event_espresso')
325 325
                                      . '</a>';
326 326
             }
@@ -330,8 +330,8 @@  discard block
 block discarded – undo
330 330
                 'espresso_events_trash_event',
331 331
                 $item->ID()
332 332
             )) {
333
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
334
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
333
+                $actions['move to trash'] = '<a href="'.$trash_event_link.'"'
334
+                                            . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">'
335 335
                                             . esc_html__('Trash', 'event_espresso')
336 336
                                             . '</a>';
337 337
             }
@@ -356,8 +356,8 @@  discard block
 block discarded – undo
356 356
             'EVT_wp_user' => $item->wp_user(),
357 357
         );
358 358
         $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
359
-        return $gravatar . '  <a href="' . $filter_url . '"'
360
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
359
+        return $gravatar.'  <a href="'.$filter_url.'"'
360
+               . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">'
361 361
                . $event_author->display_name
362 362
                . '</a>';
363 363
     }
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
         return implode(
375 375
             ', ',
376 376
             array_map(
377
-                function (EE_Term $category) {
377
+                function(EE_Term $category) {
378 378
                     return $category->name();
379 379
                 },
380 380
                 $event_categories
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
                    'ee_read_registrations',
450 450
                    'espresso_registrations_view_registration'
451 451
                )
452
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
452
+            ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>'
453 453
             : $registered_attendees;
454 454
     }
455 455
 
@@ -479,13 +479,13 @@  discard block
 block discarded – undo
479 479
     public function column_actions(EE_Event $item)
480 480
     {
481 481
         // todo: remove when attendees is active
482
-        if (! defined('REG_ADMIN_URL')) {
482
+        if ( ! defined('REG_ADMIN_URL')) {
483 483
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
484 484
         }
485 485
         $action_links = array();
486 486
         $view_link = get_permalink($item->ID());
487
-        $action_links[] = '<a href="' . $view_link . '"'
488
-                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
487
+        $action_links[] = '<a href="'.$view_link.'"'
488
+                          . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">';
489 489
         $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
490 490
         if (EE_Registry::instance()->CAP->current_user_can(
491 491
             'ee_edit_event',
@@ -497,8 +497,8 @@  discard block
 block discarded – undo
497 497
                 'post'   => $item->ID(),
498 498
             );
499 499
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
500
-            $action_links[] = '<a href="' . $edit_link . '"'
501
-                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
500
+            $action_links[] = '<a href="'.$edit_link.'"'
501
+                              . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">'
502 502
                               . '<div class="ee-icon ee-icon-calendar-edit"></div>'
503 503
                               . '</a>';
504 504
         }
@@ -516,8 +516,8 @@  discard block
 block discarded – undo
516 516
                 'event_id' => $item->ID(),
517 517
             );
518 518
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
519
-            $action_links[] = '<a href="' . $attendees_link . '"'
520
-                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
519
+            $action_links[] = '<a href="'.$attendees_link.'"'
520
+                              . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">'
521 521
                               . '<div class="dashicons dashicons-groups"></div>'
522 522
                               . '</a>';
523 523
         }
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
         }
553 553
         $column_array = [];
554 554
         foreach ($this->_columns as $column => $column_label) {
555
-            $column_array[ $column ] = $column_label;
555
+            $column_array[$column] = $column_label;
556 556
             if ($column === 'venue') {
557 557
                 $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
558 558
             }
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/RelationNode.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@
 block discarded – undo
130 130
      * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
131 131
      * @since $VID:$
132 132
      * @param ModelObjNode[] $model_obj_nodes
133
-     * @param $work_budget
133
+     * @param integer $work_budget
134 134
      * @return int
135 135
      */
136 136
     protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -2,15 +2,12 @@
 block discarded – undo
2 2
 
3 3
 namespace EventEspresso\core\services\orm\tree_traversal;
4 4
 
5
-use EE_Base_Class;
6 5
 use EE_Error;
7 6
 use EE_Has_Many_Any_Relation;
8
-use EE_Model_Relation_Base;
9 7
 use EE_Registry;
10 8
 use EEM_Base;
11 9
 use EventEspresso\core\exceptions\InvalidDataTypeException;
12 10
 use EventEspresso\core\exceptions\InvalidInterfaceException;
13
-use EventEspresso\core\services\payment_methods\forms\PayPalSettingsForm;
14 11
 use InvalidArgumentException;
15 12
 use ReflectionException;
16 13
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
             // Add entity nodes for each of the model objects we fetched.
94 94
             foreach ($related_model_objs as $related_model_obj) {
95 95
                 $entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models);
96
-                $this->nodes[ $related_model_obj->ID() ] = $entity_node;
97
-                $new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
96
+                $this->nodes[$related_model_obj->ID()] = $entity_node;
97
+                $new_item_nodes[$related_model_obj->ID()] = $entity_node;
98 98
             }
99 99
             $num_identified += count($new_item_nodes);
100 100
             if ($num_identified < $model_objects_to_identify) {
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     protected function allChildrenComplete()
121 121
     {
122 122
         foreach ($this->nodes as $model_obj_node) {
123
-            if (! $model_obj_node->isComplete()) {
123
+            if ( ! $model_obj_node->isComplete()) {
124 124
                 return false;
125 125
             }
126 126
         }
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
138 138
     {
139 139
         $work_done = 0;
140
-        if (! $model_obj_nodes) {
140
+        if ( ! $model_obj_nodes) {
141 141
             return 0;
142 142
         }
143 143
         foreach ($model_obj_nodes as $model_obj_node) {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     protected function whereQueryParams()
201 201
     {
202
-        $where_params =  [
202
+        $where_params = [
203 203
             $this->related_model->get_foreign_key_to(
204 204
                 $this->main_model->get_this_model_name()
205 205
             )->get_name() => $this->id
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
             $relation_settings = null;
213 213
         }
214 214
         if ($relation_settings instanceof EE_Has_Many_Any_Relation) {
215
-            $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name();
215
+            $where_params[$this->related_model->get_field_containing_related_model_name()->get_name()] = $this->main_model->get_this_model_name();
216 216
         }
217 217
         return $where_params;
218 218
     }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
             'objs' => []
229 229
         ];
230 230
         foreach ($this->nodes as $id => $model_obj_node) {
231
-            $tree['objs'][ $id ] = $model_obj_node->toArray();
231
+            $tree['objs'][$id] = $model_obj_node->toArray();
232 232
         }
233 233
         return $tree;
234 234
     }
Please login to merge, or discard this patch.
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -28,289 +28,289 @@
 block discarded – undo
28 28
 class RelationNode extends BaseNode
29 29
 {
30 30
 
31
-    /**
32
-     * @var string|int
33
-     */
34
-    protected $id;
31
+	/**
32
+	 * @var string|int
33
+	 */
34
+	protected $id;
35 35
 
36
-    /**
37
-     * @var EEM_Base
38
-     */
39
-    protected $main_model;
36
+	/**
37
+	 * @var EEM_Base
38
+	 */
39
+	protected $main_model;
40 40
 
41
-    /**
42
-     * @var int
43
-     */
44
-    protected $count;
41
+	/**
42
+	 * @var int
43
+	 */
44
+	protected $count;
45 45
 
46
-    /**
47
-     * @var EEM_Base
48
-     */
49
-    protected $related_model;
46
+	/**
47
+	 * @var EEM_Base
48
+	 */
49
+	protected $related_model;
50 50
 
51
-    /**
52
-     * @var ModelObjNode[]
53
-     */
54
-    protected $nodes;
51
+	/**
52
+	 * @var ModelObjNode[]
53
+	 */
54
+	protected $nodes;
55 55
 
56
-    /**
57
-     * RelationNode constructor.
58
-     * @param $main_model_obj_id
59
-     * @param EEM_Base $main_model
60
-     * @param EEM_Base $related_model
61
-     * @param array $dont_traverse_models array of model names we DON'T want to traverse
62
-     */
63
-    public function __construct(
64
-        $main_model_obj_id,
65
-        EEM_Base $main_model,
66
-        EEM_Base $related_model,
67
-        array $dont_traverse_models = []
68
-    ) {
69
-        $this->id = $main_model_obj_id;
70
-        $this->main_model = $main_model;
71
-        $this->related_model = $related_model;
72
-        $this->nodes = [];
73
-        $this->dont_traverse_models = $dont_traverse_models;
74
-    }
56
+	/**
57
+	 * RelationNode constructor.
58
+	 * @param $main_model_obj_id
59
+	 * @param EEM_Base $main_model
60
+	 * @param EEM_Base $related_model
61
+	 * @param array $dont_traverse_models array of model names we DON'T want to traverse
62
+	 */
63
+	public function __construct(
64
+		$main_model_obj_id,
65
+		EEM_Base $main_model,
66
+		EEM_Base $related_model,
67
+		array $dont_traverse_models = []
68
+	) {
69
+		$this->id = $main_model_obj_id;
70
+		$this->main_model = $main_model;
71
+		$this->related_model = $related_model;
72
+		$this->nodes = [];
73
+		$this->dont_traverse_models = $dont_traverse_models;
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * Here is where most of the work happens. We've counted how many related model objects exist, here we identify
79
-     * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc.
80
-     * @since $VID:$
81
-     * @param int $model_objects_to_identify
82
-     * @return int
83
-     * @throws EE_Error
84
-     * @throws InvalidArgumentException
85
-     * @throws InvalidDataTypeException
86
-     * @throws InvalidInterfaceException
87
-     * @throws ReflectionException
88
-     */
89
-    protected function work($model_objects_to_identify)
90
-    {
91
-        $num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify);
92
-        if ($num_identified < $model_objects_to_identify) {
93
-            $related_model_objs = $this->related_model->get_all(
94
-                [
95
-                    $this->whereQueryParams(),
96
-                    'limit' => [
97
-                        count($this->nodes),
98
-                        $model_objects_to_identify - $num_identified
99
-                    ]
100
-                ]
101
-            );
102
-            $new_item_nodes = [];
77
+	/**
78
+	 * Here is where most of the work happens. We've counted how many related model objects exist, here we identify
79
+	 * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc.
80
+	 * @since $VID:$
81
+	 * @param int $model_objects_to_identify
82
+	 * @return int
83
+	 * @throws EE_Error
84
+	 * @throws InvalidArgumentException
85
+	 * @throws InvalidDataTypeException
86
+	 * @throws InvalidInterfaceException
87
+	 * @throws ReflectionException
88
+	 */
89
+	protected function work($model_objects_to_identify)
90
+	{
91
+		$num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify);
92
+		if ($num_identified < $model_objects_to_identify) {
93
+			$related_model_objs = $this->related_model->get_all(
94
+				[
95
+					$this->whereQueryParams(),
96
+					'limit' => [
97
+						count($this->nodes),
98
+						$model_objects_to_identify - $num_identified
99
+					]
100
+				]
101
+			);
102
+			$new_item_nodes = [];
103 103
 
104
-            // Add entity nodes for each of the model objects we fetched.
105
-            foreach ($related_model_objs as $related_model_obj) {
106
-                $entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models);
107
-                $this->nodes[ $related_model_obj->ID() ] = $entity_node;
108
-                $new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
109
-            }
110
-            $num_identified += count($new_item_nodes);
111
-            if ($num_identified < $model_objects_to_identify) {
112
-                // And lastly do the work.
113
-                $num_identified += $this->visitAlreadyDiscoveredNodes(
114
-                    $new_item_nodes,
115
-                    $model_objects_to_identify - $num_identified
116
-                );
117
-            }
118
-        }
104
+			// Add entity nodes for each of the model objects we fetched.
105
+			foreach ($related_model_objs as $related_model_obj) {
106
+				$entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models);
107
+				$this->nodes[ $related_model_obj->ID() ] = $entity_node;
108
+				$new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
109
+			}
110
+			$num_identified += count($new_item_nodes);
111
+			if ($num_identified < $model_objects_to_identify) {
112
+				// And lastly do the work.
113
+				$num_identified += $this->visitAlreadyDiscoveredNodes(
114
+					$new_item_nodes,
115
+					$model_objects_to_identify - $num_identified
116
+				);
117
+			}
118
+		}
119 119
 
120
-        if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) {
121
-            $this->complete = true;
122
-        }
123
-        return $num_identified;
124
-    }
120
+		if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) {
121
+			$this->complete = true;
122
+		}
123
+		return $num_identified;
124
+	}
125 125
 
126
-    /**
127
-     * Checks if all the identified child nodes are complete or not.
128
-     * @since $VID:$
129
-     * @return bool
130
-     */
131
-    protected function allChildrenComplete()
132
-    {
133
-        foreach ($this->nodes as $model_obj_node) {
134
-            if (! $model_obj_node->isComplete()) {
135
-                return false;
136
-            }
137
-        }
138
-        return true;
139
-    }
126
+	/**
127
+	 * Checks if all the identified child nodes are complete or not.
128
+	 * @since $VID:$
129
+	 * @return bool
130
+	 */
131
+	protected function allChildrenComplete()
132
+	{
133
+		foreach ($this->nodes as $model_obj_node) {
134
+			if (! $model_obj_node->isComplete()) {
135
+				return false;
136
+			}
137
+		}
138
+		return true;
139
+	}
140 140
 
141
-    /**
142
-     * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
143
-     * @since $VID:$
144
-     * @param ModelObjNode[] $model_obj_nodes
145
-     * @param $work_budget
146
-     * @return int
147
-     */
148
-    protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
149
-    {
150
-        $work_done = 0;
151
-        if (! $model_obj_nodes) {
152
-            return 0;
153
-        }
154
-        foreach ($model_obj_nodes as $model_obj_node) {
155
-            if ($work_done >= $work_budget) {
156
-                break;
157
-            }
158
-            $work_done += $model_obj_node->visit($work_budget - $work_done);
159
-        }
160
-        return $work_done;
161
-    }
141
+	/**
142
+	 * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
143
+	 * @since $VID:$
144
+	 * @param ModelObjNode[] $model_obj_nodes
145
+	 * @param $work_budget
146
+	 * @return int
147
+	 */
148
+	protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
149
+	{
150
+		$work_done = 0;
151
+		if (! $model_obj_nodes) {
152
+			return 0;
153
+		}
154
+		foreach ($model_obj_nodes as $model_obj_node) {
155
+			if ($work_done >= $work_budget) {
156
+				break;
157
+			}
158
+			$work_done += $model_obj_node->visit($work_budget - $work_done);
159
+		}
160
+		return $work_done;
161
+	}
162 162
 
163
-    /**
164
-     * Whether this item has already been initialized
165
-     */
166
-    protected function isDiscovered()
167
-    {
168
-        return $this->count !== null;
169
-    }
163
+	/**
164
+	 * Whether this item has already been initialized
165
+	 */
166
+	protected function isDiscovered()
167
+	{
168
+		return $this->count !== null;
169
+	}
170 170
 
171
-    /**
172
-     * @since $VID:$
173
-     * @return boolean
174
-     */
175
-    public function isComplete()
176
-    {
177
-        if ($this->complete === null) {
178
-            if (count($this->nodes) === $this->count) {
179
-                $this->complete = true;
180
-            } else {
181
-                $this->complete = false;
182
-            }
183
-        }
184
-        return $this->complete;
185
-    }
171
+	/**
172
+	 * @since $VID:$
173
+	 * @return boolean
174
+	 */
175
+	public function isComplete()
176
+	{
177
+		if ($this->complete === null) {
178
+			if (count($this->nodes) === $this->count) {
179
+				$this->complete = true;
180
+			} else {
181
+				$this->complete = false;
182
+			}
183
+		}
184
+		return $this->complete;
185
+	}
186 186
 
187
-    /**
188
-     * Discovers how many related model objects exist.
189
-     * @since $VID:$
190
-     * @return mixed|void
191
-     * @throws EE_Error
192
-     * @throws InvalidArgumentException
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidInterfaceException
195
-     * @throws ReflectionException
196
-     */
197
-    protected function discover()
198
-    {
199
-        $this->count = $this->related_model->count([$this->whereQueryParams()]);
200
-    }
187
+	/**
188
+	 * Discovers how many related model objects exist.
189
+	 * @since $VID:$
190
+	 * @return mixed|void
191
+	 * @throws EE_Error
192
+	 * @throws InvalidArgumentException
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidInterfaceException
195
+	 * @throws ReflectionException
196
+	 */
197
+	protected function discover()
198
+	{
199
+		$this->count = $this->related_model->count([$this->whereQueryParams()]);
200
+	}
201 201
 
202
-    /**
203
-     * @since $VID:$
204
-     * @return array
205
-     * @throws EE_Error
206
-     * @throws InvalidDataTypeException
207
-     * @throws InvalidInterfaceException
208
-     * @throws InvalidArgumentException
209
-     * @throws ReflectionException
210
-     */
211
-    protected function whereQueryParams()
212
-    {
213
-        $where_params =  [
214
-            $this->related_model->get_foreign_key_to(
215
-                $this->main_model->get_this_model_name()
216
-            )->get_name() => $this->id
217
-        ];
218
-        try {
219
-            $relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name());
220
-        } catch (EE_Error $e) {
221
-            // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table
222
-            // which hasn't been explicitly declared in the main model object's model's relations.
223
-            $relation_settings = null;
224
-        }
225
-        if ($relation_settings instanceof EE_Has_Many_Any_Relation) {
226
-            $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name();
227
-        }
228
-        return $where_params;
229
-    }
230
-    /**
231
-     * @since $VID:$
232
-     * @return array
233
-     */
234
-    public function toArray()
235
-    {
236
-        $tree = [
237
-            'count' => $this->count,
238
-            'complete' => $this->isComplete(),
239
-            'objs' => []
240
-        ];
241
-        foreach ($this->nodes as $id => $model_obj_node) {
242
-            $tree['objs'][ $id ] = $model_obj_node->toArray();
243
-        }
244
-        return $tree;
245
-    }
202
+	/**
203
+	 * @since $VID:$
204
+	 * @return array
205
+	 * @throws EE_Error
206
+	 * @throws InvalidDataTypeException
207
+	 * @throws InvalidInterfaceException
208
+	 * @throws InvalidArgumentException
209
+	 * @throws ReflectionException
210
+	 */
211
+	protected function whereQueryParams()
212
+	{
213
+		$where_params =  [
214
+			$this->related_model->get_foreign_key_to(
215
+				$this->main_model->get_this_model_name()
216
+			)->get_name() => $this->id
217
+		];
218
+		try {
219
+			$relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name());
220
+		} catch (EE_Error $e) {
221
+			// This will happen for has-and-belongs-to-many relations, when this node's related model is that join table
222
+			// which hasn't been explicitly declared in the main model object's model's relations.
223
+			$relation_settings = null;
224
+		}
225
+		if ($relation_settings instanceof EE_Has_Many_Any_Relation) {
226
+			$where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name();
227
+		}
228
+		return $where_params;
229
+	}
230
+	/**
231
+	 * @since $VID:$
232
+	 * @return array
233
+	 */
234
+	public function toArray()
235
+	{
236
+		$tree = [
237
+			'count' => $this->count,
238
+			'complete' => $this->isComplete(),
239
+			'objs' => []
240
+		];
241
+		foreach ($this->nodes as $id => $model_obj_node) {
242
+			$tree['objs'][ $id ] = $model_obj_node->toArray();
243
+		}
244
+		return $tree;
245
+	}
246 246
 
247
-    /**
248
-     * Gets the IDs of all the model objects to delete; indexed first by model object name.
249
-     * @since $VID:$
250
-     * @return array
251
-     */
252
-    public function getIds()
253
-    {
254
-        if (empty($this->nodes)) {
255
-            return [];
256
-        }
257
-        $ids = [
258
-            $this->related_model->get_this_model_name() => array_combine(
259
-                array_keys($this->nodes),
260
-                array_keys($this->nodes)
261
-            )
262
-        ];
263
-        foreach ($this->nodes as $model_obj_node) {
264
-            $ids = array_replace_recursive($ids, $model_obj_node->getIds());
265
-        }
266
-        return $ids;
267
-    }
247
+	/**
248
+	 * Gets the IDs of all the model objects to delete; indexed first by model object name.
249
+	 * @since $VID:$
250
+	 * @return array
251
+	 */
252
+	public function getIds()
253
+	{
254
+		if (empty($this->nodes)) {
255
+			return [];
256
+		}
257
+		$ids = [
258
+			$this->related_model->get_this_model_name() => array_combine(
259
+				array_keys($this->nodes),
260
+				array_keys($this->nodes)
261
+			)
262
+		];
263
+		foreach ($this->nodes as $model_obj_node) {
264
+			$ids = array_replace_recursive($ids, $model_obj_node->getIds());
265
+		}
266
+		return $ids;
267
+	}
268 268
 
269
-    /**
270
-     * Returns the number of sub-nodes found (ie, related model objects across this relation.)
271
-     * @since $VID:$
272
-     * @return int
273
-     */
274
-    public function countSubNodes()
275
-    {
276
-        return count($this->nodes);
277
-    }
269
+	/**
270
+	 * Returns the number of sub-nodes found (ie, related model objects across this relation.)
271
+	 * @since $VID:$
272
+	 * @return int
273
+	 */
274
+	public function countSubNodes()
275
+	{
276
+		return count($this->nodes);
277
+	}
278 278
 
279
-    /**
280
-     * Don't serialize the models. Just record their names on some dynamic properties.
281
-     * @since $VID:$
282
-     */
283
-    public function __sleep()
284
-    {
285
-        $this->m = $this->main_model->get_this_model_name();
286
-        $this->rm = $this->related_model->get_this_model_name();
287
-        return array_merge(
288
-            [
289
-                'm',
290
-                'rm',
291
-                'id',
292
-                'count',
293
-                'nodes',
294
-            ],
295
-            parent::__sleep()
296
-        );
297
-    }
279
+	/**
280
+	 * Don't serialize the models. Just record their names on some dynamic properties.
281
+	 * @since $VID:$
282
+	 */
283
+	public function __sleep()
284
+	{
285
+		$this->m = $this->main_model->get_this_model_name();
286
+		$this->rm = $this->related_model->get_this_model_name();
287
+		return array_merge(
288
+			[
289
+				'm',
290
+				'rm',
291
+				'id',
292
+				'count',
293
+				'nodes',
294
+			],
295
+			parent::__sleep()
296
+		);
297
+	}
298 298
 
299
-    /**
300
-     * Use the dynamic properties to instantiate the models we use.
301
-     * @since $VID:$
302
-     * @throws EE_Error
303
-     * @throws InvalidArgumentException
304
-     * @throws InvalidDataTypeException
305
-     * @throws InvalidInterfaceException
306
-     * @throws ReflectionException
307
-     */
308
-    public function __wakeup()
309
-    {
310
-        $this->main_model = EE_Registry::instance()->load_model($this->m);
311
-        $this->related_model = EE_Registry::instance()->load_model($this->rm);
312
-        parent::__wakeup();
313
-    }
299
+	/**
300
+	 * Use the dynamic properties to instantiate the models we use.
301
+	 * @since $VID:$
302
+	 * @throws EE_Error
303
+	 * @throws InvalidArgumentException
304
+	 * @throws InvalidDataTypeException
305
+	 * @throws InvalidInterfaceException
306
+	 * @throws ReflectionException
307
+	 */
308
+	public function __wakeup()
309
+	{
310
+		$this->main_model = EE_Registry::instance()->load_model($this->m);
311
+		$this->related_model = EE_Registry::instance()->load_model($this->rm);
312
+		parent::__wakeup();
313
+	}
314 314
 }
315 315
 // End of file RelationNode.php
316 316
 // Location: EventEspresso\core\services\orm\tree_traversal/RelationNode.php
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 1 patch
Indentation   +1524 added lines, -1524 removed lines patch added patch discarded remove patch
@@ -14,1528 +14,1528 @@
 block discarded – undo
14 14
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
15 15
 {
16 16
 
17
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
-
19
-    /**
20
-     * Subsections
21
-     *
22
-     * @var EE_Form_Section_Validatable[]
23
-     */
24
-    protected $_subsections = array();
25
-
26
-    /**
27
-     * Strategy for laying out the form
28
-     *
29
-     * @var EE_Form_Section_Layout_Base
30
-     */
31
-    protected $_layout_strategy;
32
-
33
-    /**
34
-     * Whether or not this form has received and validated a form submission yet
35
-     *
36
-     * @var boolean
37
-     */
38
-    protected $_received_submission = false;
39
-
40
-    /**
41
-     * message displayed to users upon successful form submission
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_form_submission_success_message = '';
46
-
47
-    /**
48
-     * message displayed to users upon unsuccessful form submission
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_form_submission_error_message = '';
53
-
54
-    /**
55
-     * @var array like $_REQUEST
56
-     */
57
-    protected $cached_request_data;
58
-
59
-    /**
60
-     * Stores whether this form (and its sub-sections) were found to be valid or not.
61
-     * Starts off as null, but once the form is validated, it set to either true or false
62
-     * @var boolean|null
63
-     */
64
-    protected $is_valid;
65
-
66
-    /**
67
-     * Stores all the data that will localized for form validation
68
-     *
69
-     * @var array
70
-     */
71
-    static protected $_js_localization = array();
72
-
73
-    /**
74
-     * whether or not the form's localized validation JS vars have been set
75
-     *
76
-     * @type boolean
77
-     */
78
-    static protected $_scripts_localized = false;
79
-
80
-
81
-    /**
82
-     * when constructing a proper form section, calls _construct_finalize on children
83
-     * so that they know who their parent is, and what name they've been given.
84
-     *
85
-     * @param array[] $options_array   {
86
-     * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
-     * @type          $include         string[] numerically-indexed where values are section names to be included,
88
-     *                                 and in that order. This is handy if you want
89
-     *                                 the subsections to be ordered differently than the default, and if you override
90
-     *                                 which fields are shown
91
-     * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
-     *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
-     *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
-     *                                 items from that list of inclusions)
95
-     * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
-     *                                 } @see EE_Form_Section_Validatable::__construct()
97
-     * @throws EE_Error
98
-     */
99
-    public function __construct($options_array = array())
100
-    {
101
-        $options_array = (array) apply_filters(
102
-            'FHEE__EE_Form_Section_Proper___construct__options_array',
103
-            $options_array,
104
-            $this
105
-        );
106
-        // call parent first, as it may be setting the name
107
-        parent::__construct($options_array);
108
-        // if they've included subsections in the constructor, add them now
109
-        if (isset($options_array['include'])) {
110
-            // we are going to make sure we ONLY have those subsections to include
111
-            // AND we are going to make sure they're in that specified order
112
-            $reordered_subsections = array();
113
-            foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
-                }
117
-            }
118
-            $this->_subsections = $reordered_subsections;
119
-        }
120
-        if (isset($options_array['exclude'])) {
121
-            $exclude            = $options_array['exclude'];
122
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
-        }
124
-        if (isset($options_array['layout_strategy'])) {
125
-            $this->_layout_strategy = $options_array['layout_strategy'];
126
-        }
127
-        if (! $this->_layout_strategy) {
128
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
-        }
130
-        $this->_layout_strategy->_construct_finalize($this);
131
-        // ok so we are definitely going to want the forms JS,
132
-        // so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
-            // ok so they've constructed this object after when they should have.
135
-            // just enqueue the generic form scripts and initialize the form immediately in the JS
136
-            EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
-        } else {
138
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
-        }
141
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
-        /**
143
-         * Gives other plugins a chance to hook in before construct finalize is called.
144
-         * The form probably doesn't yet have a parent form section.
145
-         * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
-         * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
-         *
149
-         * @since 4.9.32
150
-         * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
-         *                                              except maybe calling _construct_finalize has been done
152
-         * @param array                  $options_array options passed into the constructor
153
-         */
154
-        do_action(
155
-            'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
-            $this,
157
-            $options_array
158
-        );
159
-        if (isset($options_array['name'])) {
160
-            $this->_construct_finalize(null, $options_array['name']);
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Finishes construction given the parent form section and this form section's name
167
-     *
168
-     * @param EE_Form_Section_Proper $parent_form_section
169
-     * @param string                 $name
170
-     * @throws EE_Error
171
-     */
172
-    public function _construct_finalize($parent_form_section, $name)
173
-    {
174
-        parent::_construct_finalize($parent_form_section, $name);
175
-        $this->_set_default_name_if_empty();
176
-        $this->_set_default_html_id_if_empty();
177
-        foreach ($this->_subsections as $subsection_name => $subsection) {
178
-            if ($subsection instanceof EE_Form_Section_Base) {
179
-                $subsection->_construct_finalize($this, $subsection_name);
180
-            } else {
181
-                throw new EE_Error(
182
-                    sprintf(
183
-                        esc_html__(
184
-                            'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
-                            'event_espresso'
186
-                        ),
187
-                        $subsection_name,
188
-                        get_class($this),
189
-                        $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
-                    )
191
-                );
192
-            }
193
-        }
194
-        /**
195
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
-         * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
-         * This might only happen just before displaying the form, or just before it receives form submission data.
199
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
-         * ensured it has a name, HTML IDs, etc
201
-         *
202
-         * @param EE_Form_Section_Proper      $this
203
-         * @param EE_Form_Section_Proper|null $parent_form_section
204
-         * @param string                      $name
205
-         */
206
-        do_action(
207
-            'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
-            $this,
209
-            $parent_form_section,
210
-            $name
211
-        );
212
-    }
213
-
214
-
215
-    /**
216
-     * Gets the layout strategy for this form section
217
-     *
218
-     * @return EE_Form_Section_Layout_Base
219
-     */
220
-    public function get_layout_strategy()
221
-    {
222
-        return $this->_layout_strategy;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets the HTML for a single input for this form section according
228
-     * to the layout strategy
229
-     *
230
-     * @param EE_Form_Input_Base $input
231
-     * @return string
232
-     */
233
-    public function get_html_for_input($input)
234
-    {
235
-        return $this->_layout_strategy->layout_input($input);
236
-    }
237
-
238
-
239
-    /**
240
-     * was_submitted - checks if form inputs are present in request data
241
-     * Basically an alias for form_data_present_in() (which is used by both
242
-     * proper form sections and form inputs)
243
-     *
244
-     * @param null $form_data
245
-     * @return boolean
246
-     * @throws EE_Error
247
-     */
248
-    public function was_submitted($form_data = null)
249
-    {
250
-        return $this->form_data_present_in($form_data);
251
-    }
252
-
253
-    /**
254
-     * Gets the cached request data; but if there is none, or $req_data was set with
255
-     * something different, refresh the cache, and then return it
256
-     * @param null $req_data
257
-     * @return array
258
-     */
259
-    protected function getCachedRequest($req_data = null)
260
-    {
261
-        if ($this->cached_request_data === null
262
-            || (
263
-                $req_data !== null &&
264
-                $req_data !== $this->cached_request_data
265
-            )
266
-        ) {
267
-            $req_data = apply_filters(
268
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
-                $req_data,
270
-                $this
271
-            );
272
-            if ($req_data === null) {
273
-                $req_data = array_merge($_GET, $_POST);
274
-            }
275
-            $req_data = apply_filters(
276
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
-                $req_data,
278
-                $this
279
-            );
280
-            $this->cached_request_data = (array) $req_data;
281
-        }
282
-        return $this->cached_request_data;
283
-    }
284
-
285
-
286
-    /**
287
-     * After the form section is initially created, call this to sanitize the data in the submission
288
-     * which relates to this form section, validate it, and set it as properties on the form.
289
-     *
290
-     * @param array|null $req_data should usually be $_POST (the default).
291
-     *                             However, you CAN supply a different array.
292
-     *                             Consider using set_defaults() instead however.
293
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
294
-     *                             the inputs will have the correct name in the request data for this function
295
-     *                             to find them and populate the form with them.
296
-     *                             If you have a flat form (with only input subsections),
297
-     *                             you can supply a flat array where keys
298
-     *                             are the form input names and values are their values)
299
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
-     *                             of course, to validate that data, and set errors on the invalid values.
301
-     *                             But if the data has already been validated
302
-     *                             (eg you validated the data then stored it in the DB)
303
-     *                             you may want to skip this step.
304
-     * @throws InvalidArgumentException
305
-     * @throws InvalidInterfaceException
306
-     * @throws InvalidDataTypeException
307
-     * @throws EE_Error
308
-     */
309
-    public function receive_form_submission($req_data = null, $validate = true)
310
-    {
311
-        $req_data = $this->getCachedRequest($req_data);
312
-        $this->_normalize($req_data);
313
-        if ($validate) {
314
-            $this->_validate();
315
-            // if it's invalid, we're going to want to re-display so remember what they submitted
316
-            if (! $this->is_valid()) {
317
-                $this->store_submitted_form_data_in_session();
318
-            }
319
-        }
320
-        if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
-            $this->set_submission_error_message();
322
-        }
323
-        do_action(
324
-            'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
-            $req_data,
326
-            $this,
327
-            $validate
328
-        );
329
-    }
330
-
331
-
332
-    /**
333
-     * caches the originally submitted input values in the session
334
-     * so that they can be used to repopulate the form if it failed validation
335
-     *
336
-     * @return boolean whether or not the data was successfully stored in the session
337
-     * @throws InvalidArgumentException
338
-     * @throws InvalidInterfaceException
339
-     * @throws InvalidDataTypeException
340
-     * @throws EE_Error
341
-     */
342
-    protected function store_submitted_form_data_in_session()
343
-    {
344
-        return EE_Registry::instance()->SSN->set_session_data(
345
-            array(
346
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
-            )
348
-        );
349
-    }
350
-
351
-
352
-    /**
353
-     * retrieves the originally submitted input values in the session
354
-     * so that they can be used to repopulate the form if it failed validation
355
-     *
356
-     * @return array
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidInterfaceException
359
-     * @throws InvalidDataTypeException
360
-     */
361
-    protected function get_submitted_form_data_from_session()
362
-    {
363
-        $session = EE_Registry::instance()->SSN;
364
-        if ($session instanceof EE_Session) {
365
-            return $session->get_session_data(
366
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
-            );
368
-        }
369
-        return array();
370
-    }
371
-
372
-
373
-    /**
374
-     * flushed the originally submitted input values from the session
375
-     *
376
-     * @return boolean whether or not the data was successfully removed from the session
377
-     * @throws InvalidArgumentException
378
-     * @throws InvalidInterfaceException
379
-     * @throws InvalidDataTypeException
380
-     */
381
-    public static function flush_submitted_form_data_from_session()
382
-    {
383
-        return EE_Registry::instance()->SSN->reset_data(
384
-            array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
-        );
386
-    }
387
-
388
-
389
-    /**
390
-     * Populates this form and its subsections with data from the session.
391
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
-     * validation errors when displaying too)
393
-     * Returns true if the form was populated from the session, false otherwise
394
-     *
395
-     * @return boolean
396
-     * @throws InvalidArgumentException
397
-     * @throws InvalidInterfaceException
398
-     * @throws InvalidDataTypeException
399
-     * @throws EE_Error
400
-     */
401
-    public function populate_from_session()
402
-    {
403
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
404
-        if (empty($form_data_in_session)) {
405
-            return false;
406
-        }
407
-        $this->receive_form_submission($form_data_in_session);
408
-        add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session'));
409
-        if ($this->form_data_present_in($form_data_in_session)) {
410
-            return true;
411
-        }
412
-        return false;
413
-    }
414
-
415
-
416
-    /**
417
-     * Populates the default data for the form, given an array where keys are
418
-     * the input names, and values are their values (preferably normalized to be their
419
-     * proper PHP types, not all strings... although that should be ok too).
420
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
421
-     * the value being an array formatted in teh same way
422
-     *
423
-     * @param array $default_data
424
-     * @throws EE_Error
425
-     */
426
-    public function populate_defaults($default_data)
427
-    {
428
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
-            if (isset($default_data[ $subsection_name ])) {
430
-                if ($subsection instanceof EE_Form_Input_Base) {
431
-                    $subsection->set_default($default_data[ $subsection_name ]);
432
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
433
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
434
-                }
435
-            }
436
-        }
437
-    }
438
-
439
-
440
-    /**
441
-     * returns true if subsection exists
442
-     *
443
-     * @param string $name
444
-     * @return boolean
445
-     */
446
-    public function subsection_exists($name)
447
-    {
448
-        return isset($this->_subsections[ $name ]) ? true : false;
449
-    }
450
-
451
-
452
-    /**
453
-     * Gets the subsection specified by its name
454
-     *
455
-     * @param string  $name
456
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
-     *                                                      so that the inputs will be properly configured.
458
-     *                                                      However, some client code may be ok
459
-     *                                                      with construction finalize being called later
460
-     *                                                      (realizing that the subsections' html names
461
-     *                                                      might not be set yet, etc.)
462
-     * @return EE_Form_Section_Base
463
-     * @throws EE_Error
464
-     */
465
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
466
-    {
467
-        if ($require_construction_to_be_finalized) {
468
-            $this->ensure_construct_finalized_called();
469
-        }
470
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
-    }
472
-
473
-
474
-    /**
475
-     * Gets all the validatable subsections of this form section
476
-     *
477
-     * @return EE_Form_Section_Validatable[]
478
-     * @throws EE_Error
479
-     */
480
-    public function get_validatable_subsections()
481
-    {
482
-        $validatable_subsections = array();
483
-        foreach ($this->subsections() as $name => $obj) {
484
-            if ($obj instanceof EE_Form_Section_Validatable) {
485
-                $validatable_subsections[ $name ] = $obj;
486
-            }
487
-        }
488
-        return $validatable_subsections;
489
-    }
490
-
491
-
492
-    /**
493
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
-     * throw an EE_Error.
495
-     *
496
-     * @param string  $name
497
-     * @param boolean $require_construction_to_be_finalized most client code should
498
-     *                                                      leave this as TRUE so that the inputs will be properly
499
-     *                                                      configured. However, some client code may be ok with
500
-     *                                                      construction finalize being called later
501
-     *                                                      (realizing that the subsections' html names might not be
502
-     *                                                      set yet, etc.)
503
-     * @return EE_Form_Input_Base
504
-     * @throws EE_Error
505
-     */
506
-    public function get_input($name, $require_construction_to_be_finalized = true)
507
-    {
508
-        $subsection = $this->get_subsection(
509
-            $name,
510
-            $require_construction_to_be_finalized
511
-        );
512
-        if (! $subsection instanceof EE_Form_Input_Base) {
513
-            throw new EE_Error(
514
-                sprintf(
515
-                    esc_html__(
516
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
-                        'event_espresso'
518
-                    ),
519
-                    $name,
520
-                    get_class($this),
521
-                    $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
-                )
523
-            );
524
-        }
525
-        return $subsection;
526
-    }
527
-
528
-
529
-    /**
530
-     * Like get_input(), gets the proper subsection of the form given the name,
531
-     * otherwise throws an EE_Error
532
-     *
533
-     * @param string  $name
534
-     * @param boolean $require_construction_to_be_finalized most client code should
535
-     *                                                      leave this as TRUE so that the inputs will be properly
536
-     *                                                      configured. However, some client code may be ok with
537
-     *                                                      construction finalize being called later
538
-     *                                                      (realizing that the subsections' html names might not be
539
-     *                                                      set yet, etc.)
540
-     * @return EE_Form_Section_Proper
541
-     * @throws EE_Error
542
-     */
543
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
-    {
545
-        $subsection = $this->get_subsection(
546
-            $name,
547
-            $require_construction_to_be_finalized
548
-        );
549
-        if (! $subsection instanceof EE_Form_Section_Proper) {
550
-            throw new EE_Error(
551
-                sprintf(
552
-                    esc_html__(
553
-                        "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
-                        'event_espresso'
555
-                    ),
556
-                    $name,
557
-                    get_class($this)
558
-                )
559
-            );
560
-        }
561
-        return $subsection;
562
-    }
563
-
564
-
565
-    /**
566
-     * Gets the value of the specified input. Should be called after receive_form_submission()
567
-     * or populate_defaults() on the form, where the normalized value on the input is set.
568
-     *
569
-     * @param string $name
570
-     * @return mixed depending on the input's type and its normalization strategy
571
-     * @throws EE_Error
572
-     */
573
-    public function get_input_value($name)
574
-    {
575
-        $input = $this->get_input($name);
576
-        return $input->normalized_value();
577
-    }
578
-
579
-
580
-    /**
581
-     * Checks if this form section itself is valid, and then checks its subsections
582
-     *
583
-     * @throws EE_Error
584
-     * @return boolean
585
-     */
586
-    public function is_valid()
587
-    {
588
-        if ($this->is_valid === null) {
589
-            if (! $this->has_received_submission()) {
590
-                throw new EE_Error(
591
-                    sprintf(
592
-                        esc_html__(
593
-                            'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
-                            'event_espresso'
595
-                        )
596
-                    )
597
-                );
598
-            }
599
-            if (! parent::is_valid()) {
600
-                $this->is_valid = false;
601
-            } else {
602
-                // ok so no general errors to this entire form section.
603
-                // so let's check the subsections, but only set errors if that hasn't been done yet
604
-                $this->is_valid = true;
605
-                foreach ($this->get_validatable_subsections() as $subsection) {
606
-                    if (! $subsection->is_valid()) {
607
-                        $this->is_valid = false;
608
-                    }
609
-                }
610
-            }
611
-        }
612
-        return $this->is_valid;
613
-    }
614
-
615
-
616
-    /**
617
-     * gets the default name of this form section if none is specified
618
-     *
619
-     * @return void
620
-     */
621
-    protected function _set_default_name_if_empty()
622
-    {
623
-        if (! $this->_name) {
624
-            $classname    = get_class($this);
625
-            $default_name = str_replace('EE_', '', $classname);
626
-            $this->_name  = $default_name;
627
-        }
628
-    }
629
-
630
-
631
-    /**
632
-     * Returns the HTML for the form, except for the form opening and closing tags
633
-     * (as the form section doesn't know where you necessarily want to send the information to),
634
-     * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
-     * Not doing_it_wrong because theoretically this CAN be used properly,
637
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
-     * any CSS.
639
-     *
640
-     * @throws InvalidArgumentException
641
-     * @throws InvalidInterfaceException
642
-     * @throws InvalidDataTypeException
643
-     * @throws EE_Error
644
-     */
645
-    public function get_html_and_js()
646
-    {
647
-        $this->enqueue_js();
648
-        return $this->get_html();
649
-    }
650
-
651
-
652
-    /**
653
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
-     *
655
-     * @param bool $display_previously_submitted_data
656
-     * @return string
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidInterfaceException
659
-     * @throws InvalidDataTypeException
660
-     * @throws EE_Error
661
-     * @throws EE_Error
662
-     * @throws EE_Error
663
-     */
664
-    public function get_html($display_previously_submitted_data = true)
665
-    {
666
-        $this->ensure_construct_finalized_called();
667
-        if ($display_previously_submitted_data) {
668
-            $this->populate_from_session();
669
-        }
670
-        return $this->_form_html_filter
671
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
-            : $this->_layout_strategy->layout_form();
673
-    }
674
-
675
-
676
-    /**
677
-     * enqueues JS and CSS for the form.
678
-     * It is preferred to call this before wp_enqueue_scripts so the
679
-     * scripts and styles can be put in the header, but if called later
680
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
-     * only be in the header; but in HTML5 its ok in the body.
682
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
-     *
685
-     * @return void
686
-     * @throws EE_Error
687
-     */
688
-    public function enqueue_js()
689
-    {
690
-        $this->_enqueue_and_localize_form_js();
691
-        foreach ($this->subsections() as $subsection) {
692
-            $subsection->enqueue_js();
693
-        }
694
-    }
695
-
696
-
697
-    /**
698
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
-     * the wp_enqueue_scripts hook.
701
-     * However, registering the form js and localizing it can happen when we
702
-     * actually output the form (which is preferred, seeing how teh form's fields
703
-     * could change until it's actually outputted)
704
-     *
705
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
-     *                                                    to be triggered automatically or not
707
-     * @return void
708
-     */
709
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
-    {
711
-        wp_register_script(
712
-            'ee_form_section_validation',
713
-            EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js',
714
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
-            EVENT_ESPRESSO_VERSION,
716
-            true
717
-        );
718
-        wp_localize_script(
719
-            'ee_form_section_validation',
720
-            'ee_form_section_validation_init',
721
-            array('init' => $init_form_validation_automatically ? '1' : '0')
722
-        );
723
-    }
724
-
725
-
726
-    /**
727
-     * gets the variables used by form_section_validation.js.
728
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
-     * but before the wordpress hook wp_loaded
730
-     *
731
-     * @throws EE_Error
732
-     */
733
-    public function _enqueue_and_localize_form_js()
734
-    {
735
-        $this->ensure_construct_finalized_called();
736
-        // actually, we don't want to localize just yet. There may be other forms on the page.
737
-        // so we need to add our form section data to a static variable accessible by all form sections
738
-        // and localize it just before the footer
739
-        $this->localize_validation_rules();
740
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
-    }
743
-
744
-
745
-    /**
746
-     * add our form section data to a static variable accessible by all form sections
747
-     *
748
-     * @param bool $return_for_subsection
749
-     * @return void
750
-     * @throws EE_Error
751
-     */
752
-    public function localize_validation_rules($return_for_subsection = false)
753
-    {
754
-        // we only want to localize vars ONCE for the entire form,
755
-        // so if the form section doesn't have a parent, then it must be the top dog
756
-        if ($return_for_subsection || ! $this->parent_section()) {
757
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
-                'form_section_id'  => $this->html_id(true),
759
-                'validation_rules' => $this->get_jquery_validation_rules(),
760
-                'other_data'       => $this->get_other_js_data(),
761
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
762
-            );
763
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
764
-        }
765
-    }
766
-
767
-
768
-    /**
769
-     * Gets an array of extra data that will be useful for client-side javascript.
770
-     * This is primarily data added by inputs and forms in addition to any
771
-     * scripts they might enqueue
772
-     *
773
-     * @param array $form_other_js_data
774
-     * @return array
775
-     * @throws EE_Error
776
-     */
777
-    public function get_other_js_data($form_other_js_data = array())
778
-    {
779
-        foreach ($this->subsections() as $subsection) {
780
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
-        }
782
-        return $form_other_js_data;
783
-    }
784
-
785
-
786
-    /**
787
-     * Gets a flat array of inputs for this form section and its subsections.
788
-     * Keys are their form names, and values are the inputs themselves
789
-     *
790
-     * @return EE_Form_Input_Base
791
-     * @throws EE_Error
792
-     */
793
-    public function inputs_in_subsections()
794
-    {
795
-        $inputs = array();
796
-        foreach ($this->subsections() as $subsection) {
797
-            if ($subsection instanceof EE_Form_Input_Base) {
798
-                $inputs[ $subsection->html_name() ] = $subsection;
799
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
800
-                $inputs += $subsection->inputs_in_subsections();
801
-            }
802
-        }
803
-        return $inputs;
804
-    }
805
-
806
-
807
-    /**
808
-     * Gets a flat array of all the validation errors.
809
-     * Keys are html names (because those should be unique)
810
-     * and values are a string of all their validation errors
811
-     *
812
-     * @return string[]
813
-     * @throws EE_Error
814
-     */
815
-    public function subsection_validation_errors_by_html_name()
816
-    {
817
-        $inputs = $this->inputs();
818
-        $errors = array();
819
-        foreach ($inputs as $form_input) {
820
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
-            }
823
-        }
824
-        return $errors;
825
-    }
826
-
827
-
828
-    /**
829
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
-     * Should be setup by each form during the _enqueues_and_localize_form_js
831
-     *
832
-     * @throws InvalidArgumentException
833
-     * @throws InvalidInterfaceException
834
-     * @throws InvalidDataTypeException
835
-     */
836
-    public static function localize_script_for_all_forms()
837
-    {
838
-        // allow inputs and stuff to hook in their JS and stuff here
839
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
843
-            : 'wp_default';
844
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
-        wp_enqueue_script('ee_form_section_validation');
846
-        wp_localize_script(
847
-            'ee_form_section_validation',
848
-            'ee_form_section_vars',
849
-            EE_Form_Section_Proper::$_js_localization
850
-        );
851
-    }
852
-
853
-
854
-    /**
855
-     * ensure_scripts_localized
856
-     *
857
-     * @throws EE_Error
858
-     */
859
-    public function ensure_scripts_localized()
860
-    {
861
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
862
-            $this->_enqueue_and_localize_form_js();
863
-        }
864
-    }
865
-
866
-
867
-    /**
868
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
869
-     * is that the key here should be the same as the custom validation rule put in the JS file
870
-     *
871
-     * @return array keys are custom validation rules, and values are internationalized strings
872
-     */
873
-    private static function _get_localized_error_messages()
874
-    {
875
-        return array(
876
-            'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
877
-            'regex'    => esc_html__('Please check your input', 'event_espresso'),
878
-        );
879
-    }
880
-
881
-
882
-    /**
883
-     * @return array
884
-     */
885
-    public static function js_localization()
886
-    {
887
-        return self::$_js_localization;
888
-    }
889
-
890
-
891
-    /**
892
-     * @return void
893
-     */
894
-    public static function reset_js_localization()
895
-    {
896
-        self::$_js_localization = array();
897
-    }
898
-
899
-
900
-    /**
901
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
-     * See parent function for more...
903
-     *
904
-     * @return array
905
-     * @throws EE_Error
906
-     */
907
-    public function get_jquery_validation_rules()
908
-    {
909
-        $jquery_validation_rules = array();
910
-        foreach ($this->get_validatable_subsections() as $subsection) {
911
-            $jquery_validation_rules = array_merge(
912
-                $jquery_validation_rules,
913
-                $subsection->get_jquery_validation_rules()
914
-            );
915
-        }
916
-        return $jquery_validation_rules;
917
-    }
918
-
919
-
920
-    /**
921
-     * Sanitizes all the data and sets the sanitized value of each field
922
-     *
923
-     * @param array $req_data like $_POST
924
-     * @return void
925
-     * @throws EE_Error
926
-     */
927
-    protected function _normalize($req_data)
928
-    {
929
-        $this->_received_submission = true;
930
-        $this->_validation_errors   = array();
931
-        foreach ($this->get_validatable_subsections() as $subsection) {
932
-            try {
933
-                $subsection->_normalize($req_data);
934
-            } catch (EE_Validation_Error $e) {
935
-                $subsection->add_validation_error($e);
936
-            }
937
-        }
938
-    }
939
-
940
-
941
-    /**
942
-     * Performs validation on this form section and its subsections.
943
-     * For each subsection,
944
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
945
-     * and passes it the subsection, then calls _validate on that subsection.
946
-     * If you need to perform validation on the form as a whole (considering multiple)
947
-     * you would be best to override this _validate method,
948
-     * calling parent::_validate() first.
949
-     *
950
-     * @throws EE_Error
951
-     */
952
-    protected function _validate()
953
-    {
954
-        // reset the cache of whether this form is valid or not- we're re-validating it now
955
-        $this->is_valid = null;
956
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
-            if (method_exists($this, '_validate_' . $subsection_name)) {
958
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
-            }
960
-            $subsection->_validate();
961
-        }
962
-    }
963
-
964
-
965
-    /**
966
-     * Gets all the validated inputs for the form section
967
-     *
968
-     * @return array
969
-     * @throws EE_Error
970
-     */
971
-    public function valid_data()
972
-    {
973
-        $inputs = array();
974
-        foreach ($this->subsections() as $subsection_name => $subsection) {
975
-            if ($subsection instanceof EE_Form_Section_Proper) {
976
-                $inputs[ $subsection_name ] = $subsection->valid_data();
977
-            } elseif ($subsection instanceof EE_Form_Input_Base) {
978
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
979
-            }
980
-        }
981
-        return $inputs;
982
-    }
983
-
984
-
985
-    /**
986
-     * Gets all the inputs on this form section
987
-     *
988
-     * @return EE_Form_Input_Base[]
989
-     * @throws EE_Error
990
-     */
991
-    public function inputs()
992
-    {
993
-        $inputs = array();
994
-        foreach ($this->subsections() as $subsection_name => $subsection) {
995
-            if ($subsection instanceof EE_Form_Input_Base) {
996
-                $inputs[ $subsection_name ] = $subsection;
997
-            }
998
-        }
999
-        return $inputs;
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * Gets all the subsections which are a proper form
1005
-     *
1006
-     * @return EE_Form_Section_Proper[]
1007
-     * @throws EE_Error
1008
-     */
1009
-    public function subforms()
1010
-    {
1011
-        $form_sections = array();
1012
-        foreach ($this->subsections() as $name => $obj) {
1013
-            if ($obj instanceof EE_Form_Section_Proper) {
1014
-                $form_sections[ $name ] = $obj;
1015
-            }
1016
-        }
1017
-        return $form_sections;
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
-     * Consider using inputs() or subforms()
1024
-     * if you only want form inputs or proper form sections.
1025
-     *
1026
-     * @param boolean $require_construction_to_be_finalized most client code should
1027
-     *                                                      leave this as TRUE so that the inputs will be properly
1028
-     *                                                      configured. However, some client code may be ok with
1029
-     *                                                      construction finalize being called later
1030
-     *                                                      (realizing that the subsections' html names might not be
1031
-     *                                                      set yet, etc.)
1032
-     * @return EE_Form_Section_Proper[]
1033
-     * @throws EE_Error
1034
-     */
1035
-    public function subsections($require_construction_to_be_finalized = true)
1036
-    {
1037
-        if ($require_construction_to_be_finalized) {
1038
-            $this->ensure_construct_finalized_called();
1039
-        }
1040
-        return $this->_subsections;
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * Returns whether this form has any subforms or inputs
1046
-     * @return bool
1047
-     */
1048
-    public function hasSubsections()
1049
-    {
1050
-        return ! empty($this->_subsections);
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * Returns a simple array where keys are input names, and values are their normalized
1056
-     * values. (Similar to calling get_input_value on inputs)
1057
-     *
1058
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
-     *                                        or just this forms' direct children inputs
1060
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
-     *                                        or allow multidimensional array
1062
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
-     *                                        with array keys being input names
1064
-     *                                        (regardless of whether they are from a subsection or not),
1065
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1066
-     *                                        where keys are always subsection names and values are either
1067
-     *                                        the input's normalized value, or an array like the top-level array
1068
-     * @throws EE_Error
1069
-     */
1070
-    public function input_values($include_subform_inputs = false, $flatten = false)
1071
-    {
1072
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
-     * is not necessarily the value we want to display to users. This creates an array
1080
-     * where keys are the input names, and values are their display values
1081
-     *
1082
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
-     *                                        or just this forms' direct children inputs
1084
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
-     *                                        or allow multidimensional array
1086
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
-     *                                        with array keys being input names
1088
-     *                                        (regardless of whether they are from a subsection or not),
1089
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1090
-     *                                        where keys are always subsection names and values are either
1091
-     *                                        the input's normalized value, or an array like the top-level array
1092
-     * @throws EE_Error
1093
-     */
1094
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
-    {
1096
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
-    }
1098
-
1099
-
1100
-    /**
1101
-     * Gets the input values from the form
1102
-     *
1103
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
-     *                                        or just the normalized value
1105
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
-     *                                        or just this forms' direct children inputs
1107
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
-     *                                        or allow multidimensional array
1109
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
-     *                                        input names (regardless of whether they are from a subsection or not),
1111
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1112
-     *                                        where keys are always subsection names and values are either
1113
-     *                                        the input's normalized value, or an array like the top-level array
1114
-     * @throws EE_Error
1115
-     */
1116
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
-    {
1118
-        $input_values = array();
1119
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1120
-            if ($subsection instanceof EE_Form_Input_Base) {
1121
-                $input_values[ $subsection_name ] = $pretty
1122
-                    ? $subsection->pretty_value()
1123
-                    : $subsection->normalized_value();
1124
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
-                $subform_input_values = $subsection->_input_values(
1126
-                    $pretty,
1127
-                    $include_subform_inputs,
1128
-                    $flatten
1129
-                );
1130
-                if ($flatten) {
1131
-                    $input_values = array_merge($input_values, $subform_input_values);
1132
-                } else {
1133
-                    $input_values[ $subsection_name ] = $subform_input_values;
1134
-                }
1135
-            }
1136
-        }
1137
-        return $input_values;
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * Gets the originally submitted input values from the form
1143
-     *
1144
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
-     *                                   or just this forms' direct children inputs
1146
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
-     *                                   with array keys being input names
1148
-     *                                   (regardless of whether they are from a subsection or not),
1149
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1150
-     *                                   where keys are always subsection names and values are either
1151
-     *                                   the input's normalized value, or an array like the top-level array
1152
-     * @throws EE_Error
1153
-     */
1154
-    public function submitted_values($include_subforms = false)
1155
-    {
1156
-        $submitted_values = array();
1157
-        foreach ($this->subsections() as $subsection) {
1158
-            if ($subsection instanceof EE_Form_Input_Base) {
1159
-                // is this input part of an array of inputs?
1160
-                if (strpos($subsection->html_name(), '[') !== false) {
1161
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
-                        explode(
1163
-                            '[',
1164
-                            str_replace(']', '', $subsection->html_name())
1165
-                        ),
1166
-                        $subsection->raw_value()
1167
-                    );
1168
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
-                } else {
1170
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
-                }
1172
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1174
-                $submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
-            }
1176
-        }
1177
-        return $submitted_values;
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * Indicates whether or not this form has received a submission yet
1183
-     * (ie, had receive_form_submission called on it yet)
1184
-     *
1185
-     * @return boolean
1186
-     * @throws EE_Error
1187
-     */
1188
-    public function has_received_submission()
1189
-    {
1190
-        $this->ensure_construct_finalized_called();
1191
-        return $this->_received_submission;
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * Equivalent to passing 'exclude' in the constructor's options array.
1197
-     * Removes the listed inputs from the form
1198
-     *
1199
-     * @param array $inputs_to_exclude values are the input names
1200
-     * @return void
1201
-     */
1202
-    public function exclude(array $inputs_to_exclude = array())
1203
-    {
1204
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
-            unset($this->_subsections[ $input_to_exclude_name ]);
1206
-        }
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
-     * @param array $inputs_to_hide
1213
-     * @throws EE_Error
1214
-     */
1215
-    public function hide(array $inputs_to_hide = array())
1216
-    {
1217
-        foreach ($inputs_to_hide as $input_to_hide) {
1218
-            $input = $this->get_input($input_to_hide);
1219
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
-        }
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * add_subsections
1226
-     * Adds the listed subsections to the form section.
1227
-     * If $subsection_name_to_target is provided,
1228
-     * then new subsections are added before or after that subsection,
1229
-     * otherwise to the start or end of the entire subsections array.
1230
-     *
1231
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
-     *                                                          where keys are their names
1233
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
-     *                                                          should be added before or after
1235
-     *                                                          IF $subsection_name_to_target is null,
1236
-     *                                                          then $new_subsections will be added to
1237
-     *                                                          the beginning or end of the entire subsections array
1238
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
-     *                                                          $subsection_name_to_target,
1240
-     *                                                          or if $subsection_name_to_target is null,
1241
-     *                                                          before or after entire subsections array
1242
-     * @return void
1243
-     * @throws EE_Error
1244
-     */
1245
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
-    {
1247
-        foreach ($new_subsections as $subsection_name => $subsection) {
1248
-            if (! $subsection instanceof EE_Form_Section_Base) {
1249
-                EE_Error::add_error(
1250
-                    sprintf(
1251
-                        esc_html__(
1252
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
-                            'event_espresso'
1254
-                        ),
1255
-                        get_class($subsection),
1256
-                        $subsection_name,
1257
-                        $this->name()
1258
-                    )
1259
-                );
1260
-                unset($new_subsections[ $subsection_name ]);
1261
-            }
1262
-        }
1263
-        $this->_subsections = EEH_Array::insert_into_array(
1264
-            $this->_subsections,
1265
-            $new_subsections,
1266
-            $subsection_name_to_target,
1267
-            $add_before
1268
-        );
1269
-        if ($this->_construction_finalized) {
1270
-            foreach ($this->_subsections as $name => $subsection) {
1271
-                $subsection->_construct_finalize($this, $name);
1272
-            }
1273
-        }
1274
-    }
1275
-
1276
-
1277
-    /**
1278
-     * @param string $subsection_name
1279
-     * @param bool   $recursive
1280
-     * @return bool
1281
-     */
1282
-    public function has_subsection($subsection_name, $recursive = false)
1283
-    {
1284
-        foreach ($this->_subsections as $name => $subsection) {
1285
-            if ($name === $subsection_name
1286
-                || (
1287
-                    $recursive
1288
-                    && $subsection instanceof EE_Form_Section_Proper
1289
-                    && $subsection->has_subsection($subsection_name, $recursive)
1290
-                )
1291
-            ) {
1292
-                return true;
1293
-            }
1294
-        }
1295
-        return false;
1296
-    }
1297
-
1298
-
1299
-
1300
-    /**
1301
-     * Just gets all validatable subsections to clean their sensitive data
1302
-     *
1303
-     * @throws EE_Error
1304
-     */
1305
-    public function clean_sensitive_data()
1306
-    {
1307
-        foreach ($this->get_validatable_subsections() as $subsection) {
1308
-            $subsection->clean_sensitive_data();
1309
-        }
1310
-    }
1311
-
1312
-
1313
-    /**
1314
-     * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
-     * @param string                           $form_submission_error_message
1316
-     * @param EE_Form_Section_Validatable $form_section unused
1317
-     * @throws EE_Error
1318
-     */
1319
-    public function set_submission_error_message(
1320
-        $form_submission_error_message = ''
1321
-    ) {
1322
-        $this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
-            ? $form_submission_error_message
1324
-            : $this->getAllValidationErrorsString();
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * Returns the cached error message. A default value is set for this during _validate(),
1330
-     * (called during receive_form_submission) but it can be explicitly set using
1331
-     * set_submission_error_message
1332
-     *
1333
-     * @return string
1334
-     */
1335
-    public function submission_error_message()
1336
-    {
1337
-        return $this->_form_submission_error_message;
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * Sets a message to display if the data submitted to the form was valid.
1343
-     * @param string $form_submission_success_message
1344
-     */
1345
-    public function set_submission_success_message($form_submission_success_message = '')
1346
-    {
1347
-        $this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
-            ? $form_submission_success_message
1349
-            : esc_html__('Form submitted successfully', 'event_espresso');
1350
-    }
1351
-
1352
-
1353
-    /**
1354
-     * Gets a message appropriate for display when the form is correctly submitted
1355
-     * @return string
1356
-     */
1357
-    public function submission_success_message()
1358
-    {
1359
-        return $this->_form_submission_success_message;
1360
-    }
1361
-
1362
-
1363
-    /**
1364
-     * Returns the prefix that should be used on child of this form section for
1365
-     * their html names. If this form section itself has a parent, prepends ITS
1366
-     * prefix onto this form section's prefix. Used primarily by
1367
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
-     *
1369
-     * @return string
1370
-     * @throws EE_Error
1371
-     */
1372
-    public function html_name_prefix()
1373
-    {
1374
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
-        }
1377
-        return $this->name();
1378
-    }
1379
-
1380
-
1381
-    /**
1382
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1383
-     * calls it (assumes there is no parent and that we want the name to be whatever
1384
-     * was set, which is probably nothing, or the classname)
1385
-     *
1386
-     * @return string
1387
-     * @throws EE_Error
1388
-     */
1389
-    public function name()
1390
-    {
1391
-        $this->ensure_construct_finalized_called();
1392
-        return parent::name();
1393
-    }
1394
-
1395
-
1396
-    /**
1397
-     * @return EE_Form_Section_Proper
1398
-     * @throws EE_Error
1399
-     */
1400
-    public function parent_section()
1401
-    {
1402
-        $this->ensure_construct_finalized_called();
1403
-        return parent::parent_section();
1404
-    }
1405
-
1406
-
1407
-    /**
1408
-     * make sure construction finalized was called, otherwise children might not be ready
1409
-     *
1410
-     * @return void
1411
-     * @throws EE_Error
1412
-     */
1413
-    public function ensure_construct_finalized_called()
1414
-    {
1415
-        if (! $this->_construction_finalized) {
1416
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1417
-        }
1418
-    }
1419
-
1420
-
1421
-    /**
1422
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1423
-     * are in teh form data. If any are found, returns true. Else false
1424
-     *
1425
-     * @param array $req_data
1426
-     * @return boolean
1427
-     * @throws EE_Error
1428
-     */
1429
-    public function form_data_present_in($req_data = null)
1430
-    {
1431
-        $req_data = $this->getCachedRequest($req_data);
1432
-        foreach ($this->subsections() as $subsection) {
1433
-            if ($subsection instanceof EE_Form_Input_Base) {
1434
-                if ($subsection->form_data_present_in($req_data)) {
1435
-                    return true;
1436
-                }
1437
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
-                if ($subsection->form_data_present_in($req_data)) {
1439
-                    return true;
1440
-                }
1441
-            }
1442
-        }
1443
-        return false;
1444
-    }
1445
-
1446
-
1447
-    /**
1448
-     * Gets validation errors for this form section and subsections
1449
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
-     * gets the validation errors for ALL subsection
1451
-     *
1452
-     * @return EE_Validation_Error[]
1453
-     * @throws EE_Error
1454
-     */
1455
-    public function get_validation_errors_accumulated()
1456
-    {
1457
-        $validation_errors = $this->get_validation_errors();
1458
-        foreach ($this->get_validatable_subsections() as $subsection) {
1459
-            if ($subsection instanceof EE_Form_Section_Proper) {
1460
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
-            } else {
1462
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
-            }
1464
-            if ($validation_errors_on_this_subsection) {
1465
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
-            }
1467
-        }
1468
-        return $validation_errors;
1469
-    }
1470
-
1471
-    /**
1472
-     * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
-     * This traverses the form section tree to generate this, but you probably want to instead use
1474
-     * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
-     *
1476
-     * @return string
1477
-     * @since 4.9.59.p
1478
-     */
1479
-    protected function getAllValidationErrorsString()
1480
-    {
1481
-        $submission_error_messages = array();
1482
-        // bad, bad, bad registrant
1483
-        foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
-            if ($validation_error instanceof EE_Validation_Error) {
1485
-                $form_section = $validation_error->get_form_section();
1486
-                if ($form_section instanceof EE_Form_Input_Base) {
1487
-                    $label = $validation_error->get_form_section()->html_label_text();
1488
-                } elseif ($form_section instanceof EE_Form_Section_Validatable) {
1489
-                    $label = $validation_error->get_form_section()->name();
1490
-                } else {
1491
-                    $label = esc_html__('Unknown', 'event_espresso');
1492
-                }
1493
-                $submission_error_messages[] = sprintf(
1494
-                    __('%s : %s', 'event_espresso'),
1495
-                    $label,
1496
-                    $validation_error->getMessage()
1497
-                );
1498
-            }
1499
-        }
1500
-        return implode('<br>', $submission_error_messages);
1501
-    }
1502
-
1503
-
1504
-    /**
1505
-     * This isn't just the name of an input, it's a path pointing to an input. The
1506
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
-     * dot-dot-slash (../) means to ascend into the parent section.
1508
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
-     * which will be returned.
1510
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
-     * Etc
1515
-     *
1516
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
-     * @return EE_Form_Section_Base
1518
-     * @throws EE_Error
1519
-     */
1520
-    public function find_section_from_path($form_section_path)
1521
-    {
1522
-        // check if we can find the input from purely going straight up the tree
1523
-        $input = parent::find_section_from_path($form_section_path);
1524
-        if ($input instanceof EE_Form_Section_Base) {
1525
-            return $input;
1526
-        }
1527
-        $next_slash_pos = strpos($form_section_path, '/');
1528
-        if ($next_slash_pos !== false) {
1529
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
-            $subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
-        } else {
1532
-            $child_section_name = $form_section_path;
1533
-            $subpath            = '';
1534
-        }
1535
-        $child_section = $this->get_subsection($child_section_name);
1536
-        if ($child_section instanceof EE_Form_Section_Base) {
1537
-            return $child_section->find_section_from_path($subpath);
1538
-        }
1539
-        return null;
1540
-    }
17
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
+
19
+	/**
20
+	 * Subsections
21
+	 *
22
+	 * @var EE_Form_Section_Validatable[]
23
+	 */
24
+	protected $_subsections = array();
25
+
26
+	/**
27
+	 * Strategy for laying out the form
28
+	 *
29
+	 * @var EE_Form_Section_Layout_Base
30
+	 */
31
+	protected $_layout_strategy;
32
+
33
+	/**
34
+	 * Whether or not this form has received and validated a form submission yet
35
+	 *
36
+	 * @var boolean
37
+	 */
38
+	protected $_received_submission = false;
39
+
40
+	/**
41
+	 * message displayed to users upon successful form submission
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_form_submission_success_message = '';
46
+
47
+	/**
48
+	 * message displayed to users upon unsuccessful form submission
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_form_submission_error_message = '';
53
+
54
+	/**
55
+	 * @var array like $_REQUEST
56
+	 */
57
+	protected $cached_request_data;
58
+
59
+	/**
60
+	 * Stores whether this form (and its sub-sections) were found to be valid or not.
61
+	 * Starts off as null, but once the form is validated, it set to either true or false
62
+	 * @var boolean|null
63
+	 */
64
+	protected $is_valid;
65
+
66
+	/**
67
+	 * Stores all the data that will localized for form validation
68
+	 *
69
+	 * @var array
70
+	 */
71
+	static protected $_js_localization = array();
72
+
73
+	/**
74
+	 * whether or not the form's localized validation JS vars have been set
75
+	 *
76
+	 * @type boolean
77
+	 */
78
+	static protected $_scripts_localized = false;
79
+
80
+
81
+	/**
82
+	 * when constructing a proper form section, calls _construct_finalize on children
83
+	 * so that they know who their parent is, and what name they've been given.
84
+	 *
85
+	 * @param array[] $options_array   {
86
+	 * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
+	 * @type          $include         string[] numerically-indexed where values are section names to be included,
88
+	 *                                 and in that order. This is handy if you want
89
+	 *                                 the subsections to be ordered differently than the default, and if you override
90
+	 *                                 which fields are shown
91
+	 * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
+	 *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
+	 *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
+	 *                                 items from that list of inclusions)
95
+	 * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
+	 *                                 } @see EE_Form_Section_Validatable::__construct()
97
+	 * @throws EE_Error
98
+	 */
99
+	public function __construct($options_array = array())
100
+	{
101
+		$options_array = (array) apply_filters(
102
+			'FHEE__EE_Form_Section_Proper___construct__options_array',
103
+			$options_array,
104
+			$this
105
+		);
106
+		// call parent first, as it may be setting the name
107
+		parent::__construct($options_array);
108
+		// if they've included subsections in the constructor, add them now
109
+		if (isset($options_array['include'])) {
110
+			// we are going to make sure we ONLY have those subsections to include
111
+			// AND we are going to make sure they're in that specified order
112
+			$reordered_subsections = array();
113
+			foreach ($options_array['include'] as $input_name) {
114
+				if (isset($this->_subsections[ $input_name ])) {
115
+					$reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
+				}
117
+			}
118
+			$this->_subsections = $reordered_subsections;
119
+		}
120
+		if (isset($options_array['exclude'])) {
121
+			$exclude            = $options_array['exclude'];
122
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
+		}
124
+		if (isset($options_array['layout_strategy'])) {
125
+			$this->_layout_strategy = $options_array['layout_strategy'];
126
+		}
127
+		if (! $this->_layout_strategy) {
128
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
+		}
130
+		$this->_layout_strategy->_construct_finalize($this);
131
+		// ok so we are definitely going to want the forms JS,
132
+		// so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
+			// ok so they've constructed this object after when they should have.
135
+			// just enqueue the generic form scripts and initialize the form immediately in the JS
136
+			EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
+		} else {
138
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
+		}
141
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
+		/**
143
+		 * Gives other plugins a chance to hook in before construct finalize is called.
144
+		 * The form probably doesn't yet have a parent form section.
145
+		 * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
+		 * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
+		 *
149
+		 * @since 4.9.32
150
+		 * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
+		 *                                              except maybe calling _construct_finalize has been done
152
+		 * @param array                  $options_array options passed into the constructor
153
+		 */
154
+		do_action(
155
+			'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
+			$this,
157
+			$options_array
158
+		);
159
+		if (isset($options_array['name'])) {
160
+			$this->_construct_finalize(null, $options_array['name']);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Finishes construction given the parent form section and this form section's name
167
+	 *
168
+	 * @param EE_Form_Section_Proper $parent_form_section
169
+	 * @param string                 $name
170
+	 * @throws EE_Error
171
+	 */
172
+	public function _construct_finalize($parent_form_section, $name)
173
+	{
174
+		parent::_construct_finalize($parent_form_section, $name);
175
+		$this->_set_default_name_if_empty();
176
+		$this->_set_default_html_id_if_empty();
177
+		foreach ($this->_subsections as $subsection_name => $subsection) {
178
+			if ($subsection instanceof EE_Form_Section_Base) {
179
+				$subsection->_construct_finalize($this, $subsection_name);
180
+			} else {
181
+				throw new EE_Error(
182
+					sprintf(
183
+						esc_html__(
184
+							'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
+							'event_espresso'
186
+						),
187
+						$subsection_name,
188
+						get_class($this),
189
+						$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
+					)
191
+				);
192
+			}
193
+		}
194
+		/**
195
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
+		 * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
199
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
+		 * ensured it has a name, HTML IDs, etc
201
+		 *
202
+		 * @param EE_Form_Section_Proper      $this
203
+		 * @param EE_Form_Section_Proper|null $parent_form_section
204
+		 * @param string                      $name
205
+		 */
206
+		do_action(
207
+			'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
+			$this,
209
+			$parent_form_section,
210
+			$name
211
+		);
212
+	}
213
+
214
+
215
+	/**
216
+	 * Gets the layout strategy for this form section
217
+	 *
218
+	 * @return EE_Form_Section_Layout_Base
219
+	 */
220
+	public function get_layout_strategy()
221
+	{
222
+		return $this->_layout_strategy;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets the HTML for a single input for this form section according
228
+	 * to the layout strategy
229
+	 *
230
+	 * @param EE_Form_Input_Base $input
231
+	 * @return string
232
+	 */
233
+	public function get_html_for_input($input)
234
+	{
235
+		return $this->_layout_strategy->layout_input($input);
236
+	}
237
+
238
+
239
+	/**
240
+	 * was_submitted - checks if form inputs are present in request data
241
+	 * Basically an alias for form_data_present_in() (which is used by both
242
+	 * proper form sections and form inputs)
243
+	 *
244
+	 * @param null $form_data
245
+	 * @return boolean
246
+	 * @throws EE_Error
247
+	 */
248
+	public function was_submitted($form_data = null)
249
+	{
250
+		return $this->form_data_present_in($form_data);
251
+	}
252
+
253
+	/**
254
+	 * Gets the cached request data; but if there is none, or $req_data was set with
255
+	 * something different, refresh the cache, and then return it
256
+	 * @param null $req_data
257
+	 * @return array
258
+	 */
259
+	protected function getCachedRequest($req_data = null)
260
+	{
261
+		if ($this->cached_request_data === null
262
+			|| (
263
+				$req_data !== null &&
264
+				$req_data !== $this->cached_request_data
265
+			)
266
+		) {
267
+			$req_data = apply_filters(
268
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
+				$req_data,
270
+				$this
271
+			);
272
+			if ($req_data === null) {
273
+				$req_data = array_merge($_GET, $_POST);
274
+			}
275
+			$req_data = apply_filters(
276
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
+				$req_data,
278
+				$this
279
+			);
280
+			$this->cached_request_data = (array) $req_data;
281
+		}
282
+		return $this->cached_request_data;
283
+	}
284
+
285
+
286
+	/**
287
+	 * After the form section is initially created, call this to sanitize the data in the submission
288
+	 * which relates to this form section, validate it, and set it as properties on the form.
289
+	 *
290
+	 * @param array|null $req_data should usually be $_POST (the default).
291
+	 *                             However, you CAN supply a different array.
292
+	 *                             Consider using set_defaults() instead however.
293
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
294
+	 *                             the inputs will have the correct name in the request data for this function
295
+	 *                             to find them and populate the form with them.
296
+	 *                             If you have a flat form (with only input subsections),
297
+	 *                             you can supply a flat array where keys
298
+	 *                             are the form input names and values are their values)
299
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
+	 *                             of course, to validate that data, and set errors on the invalid values.
301
+	 *                             But if the data has already been validated
302
+	 *                             (eg you validated the data then stored it in the DB)
303
+	 *                             you may want to skip this step.
304
+	 * @throws InvalidArgumentException
305
+	 * @throws InvalidInterfaceException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws EE_Error
308
+	 */
309
+	public function receive_form_submission($req_data = null, $validate = true)
310
+	{
311
+		$req_data = $this->getCachedRequest($req_data);
312
+		$this->_normalize($req_data);
313
+		if ($validate) {
314
+			$this->_validate();
315
+			// if it's invalid, we're going to want to re-display so remember what they submitted
316
+			if (! $this->is_valid()) {
317
+				$this->store_submitted_form_data_in_session();
318
+			}
319
+		}
320
+		if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
+			$this->set_submission_error_message();
322
+		}
323
+		do_action(
324
+			'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
+			$req_data,
326
+			$this,
327
+			$validate
328
+		);
329
+	}
330
+
331
+
332
+	/**
333
+	 * caches the originally submitted input values in the session
334
+	 * so that they can be used to repopulate the form if it failed validation
335
+	 *
336
+	 * @return boolean whether or not the data was successfully stored in the session
337
+	 * @throws InvalidArgumentException
338
+	 * @throws InvalidInterfaceException
339
+	 * @throws InvalidDataTypeException
340
+	 * @throws EE_Error
341
+	 */
342
+	protected function store_submitted_form_data_in_session()
343
+	{
344
+		return EE_Registry::instance()->SSN->set_session_data(
345
+			array(
346
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
+			)
348
+		);
349
+	}
350
+
351
+
352
+	/**
353
+	 * retrieves the originally submitted input values in the session
354
+	 * so that they can be used to repopulate the form if it failed validation
355
+	 *
356
+	 * @return array
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidInterfaceException
359
+	 * @throws InvalidDataTypeException
360
+	 */
361
+	protected function get_submitted_form_data_from_session()
362
+	{
363
+		$session = EE_Registry::instance()->SSN;
364
+		if ($session instanceof EE_Session) {
365
+			return $session->get_session_data(
366
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
+			);
368
+		}
369
+		return array();
370
+	}
371
+
372
+
373
+	/**
374
+	 * flushed the originally submitted input values from the session
375
+	 *
376
+	 * @return boolean whether or not the data was successfully removed from the session
377
+	 * @throws InvalidArgumentException
378
+	 * @throws InvalidInterfaceException
379
+	 * @throws InvalidDataTypeException
380
+	 */
381
+	public static function flush_submitted_form_data_from_session()
382
+	{
383
+		return EE_Registry::instance()->SSN->reset_data(
384
+			array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
+		);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Populates this form and its subsections with data from the session.
391
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
+	 * validation errors when displaying too)
393
+	 * Returns true if the form was populated from the session, false otherwise
394
+	 *
395
+	 * @return boolean
396
+	 * @throws InvalidArgumentException
397
+	 * @throws InvalidInterfaceException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws EE_Error
400
+	 */
401
+	public function populate_from_session()
402
+	{
403
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
404
+		if (empty($form_data_in_session)) {
405
+			return false;
406
+		}
407
+		$this->receive_form_submission($form_data_in_session);
408
+		add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session'));
409
+		if ($this->form_data_present_in($form_data_in_session)) {
410
+			return true;
411
+		}
412
+		return false;
413
+	}
414
+
415
+
416
+	/**
417
+	 * Populates the default data for the form, given an array where keys are
418
+	 * the input names, and values are their values (preferably normalized to be their
419
+	 * proper PHP types, not all strings... although that should be ok too).
420
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
421
+	 * the value being an array formatted in teh same way
422
+	 *
423
+	 * @param array $default_data
424
+	 * @throws EE_Error
425
+	 */
426
+	public function populate_defaults($default_data)
427
+	{
428
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
+			if (isset($default_data[ $subsection_name ])) {
430
+				if ($subsection instanceof EE_Form_Input_Base) {
431
+					$subsection->set_default($default_data[ $subsection_name ]);
432
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
433
+					$subsection->populate_defaults($default_data[ $subsection_name ]);
434
+				}
435
+			}
436
+		}
437
+	}
438
+
439
+
440
+	/**
441
+	 * returns true if subsection exists
442
+	 *
443
+	 * @param string $name
444
+	 * @return boolean
445
+	 */
446
+	public function subsection_exists($name)
447
+	{
448
+		return isset($this->_subsections[ $name ]) ? true : false;
449
+	}
450
+
451
+
452
+	/**
453
+	 * Gets the subsection specified by its name
454
+	 *
455
+	 * @param string  $name
456
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
+	 *                                                      so that the inputs will be properly configured.
458
+	 *                                                      However, some client code may be ok
459
+	 *                                                      with construction finalize being called later
460
+	 *                                                      (realizing that the subsections' html names
461
+	 *                                                      might not be set yet, etc.)
462
+	 * @return EE_Form_Section_Base
463
+	 * @throws EE_Error
464
+	 */
465
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
466
+	{
467
+		if ($require_construction_to_be_finalized) {
468
+			$this->ensure_construct_finalized_called();
469
+		}
470
+		return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
+	}
472
+
473
+
474
+	/**
475
+	 * Gets all the validatable subsections of this form section
476
+	 *
477
+	 * @return EE_Form_Section_Validatable[]
478
+	 * @throws EE_Error
479
+	 */
480
+	public function get_validatable_subsections()
481
+	{
482
+		$validatable_subsections = array();
483
+		foreach ($this->subsections() as $name => $obj) {
484
+			if ($obj instanceof EE_Form_Section_Validatable) {
485
+				$validatable_subsections[ $name ] = $obj;
486
+			}
487
+		}
488
+		return $validatable_subsections;
489
+	}
490
+
491
+
492
+	/**
493
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
+	 * throw an EE_Error.
495
+	 *
496
+	 * @param string  $name
497
+	 * @param boolean $require_construction_to_be_finalized most client code should
498
+	 *                                                      leave this as TRUE so that the inputs will be properly
499
+	 *                                                      configured. However, some client code may be ok with
500
+	 *                                                      construction finalize being called later
501
+	 *                                                      (realizing that the subsections' html names might not be
502
+	 *                                                      set yet, etc.)
503
+	 * @return EE_Form_Input_Base
504
+	 * @throws EE_Error
505
+	 */
506
+	public function get_input($name, $require_construction_to_be_finalized = true)
507
+	{
508
+		$subsection = $this->get_subsection(
509
+			$name,
510
+			$require_construction_to_be_finalized
511
+		);
512
+		if (! $subsection instanceof EE_Form_Input_Base) {
513
+			throw new EE_Error(
514
+				sprintf(
515
+					esc_html__(
516
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
+						'event_espresso'
518
+					),
519
+					$name,
520
+					get_class($this),
521
+					$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
+				)
523
+			);
524
+		}
525
+		return $subsection;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Like get_input(), gets the proper subsection of the form given the name,
531
+	 * otherwise throws an EE_Error
532
+	 *
533
+	 * @param string  $name
534
+	 * @param boolean $require_construction_to_be_finalized most client code should
535
+	 *                                                      leave this as TRUE so that the inputs will be properly
536
+	 *                                                      configured. However, some client code may be ok with
537
+	 *                                                      construction finalize being called later
538
+	 *                                                      (realizing that the subsections' html names might not be
539
+	 *                                                      set yet, etc.)
540
+	 * @return EE_Form_Section_Proper
541
+	 * @throws EE_Error
542
+	 */
543
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
+	{
545
+		$subsection = $this->get_subsection(
546
+			$name,
547
+			$require_construction_to_be_finalized
548
+		);
549
+		if (! $subsection instanceof EE_Form_Section_Proper) {
550
+			throw new EE_Error(
551
+				sprintf(
552
+					esc_html__(
553
+						"Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
+						'event_espresso'
555
+					),
556
+					$name,
557
+					get_class($this)
558
+				)
559
+			);
560
+		}
561
+		return $subsection;
562
+	}
563
+
564
+
565
+	/**
566
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
567
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
568
+	 *
569
+	 * @param string $name
570
+	 * @return mixed depending on the input's type and its normalization strategy
571
+	 * @throws EE_Error
572
+	 */
573
+	public function get_input_value($name)
574
+	{
575
+		$input = $this->get_input($name);
576
+		return $input->normalized_value();
577
+	}
578
+
579
+
580
+	/**
581
+	 * Checks if this form section itself is valid, and then checks its subsections
582
+	 *
583
+	 * @throws EE_Error
584
+	 * @return boolean
585
+	 */
586
+	public function is_valid()
587
+	{
588
+		if ($this->is_valid === null) {
589
+			if (! $this->has_received_submission()) {
590
+				throw new EE_Error(
591
+					sprintf(
592
+						esc_html__(
593
+							'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
+							'event_espresso'
595
+						)
596
+					)
597
+				);
598
+			}
599
+			if (! parent::is_valid()) {
600
+				$this->is_valid = false;
601
+			} else {
602
+				// ok so no general errors to this entire form section.
603
+				// so let's check the subsections, but only set errors if that hasn't been done yet
604
+				$this->is_valid = true;
605
+				foreach ($this->get_validatable_subsections() as $subsection) {
606
+					if (! $subsection->is_valid()) {
607
+						$this->is_valid = false;
608
+					}
609
+				}
610
+			}
611
+		}
612
+		return $this->is_valid;
613
+	}
614
+
615
+
616
+	/**
617
+	 * gets the default name of this form section if none is specified
618
+	 *
619
+	 * @return void
620
+	 */
621
+	protected function _set_default_name_if_empty()
622
+	{
623
+		if (! $this->_name) {
624
+			$classname    = get_class($this);
625
+			$default_name = str_replace('EE_', '', $classname);
626
+			$this->_name  = $default_name;
627
+		}
628
+	}
629
+
630
+
631
+	/**
632
+	 * Returns the HTML for the form, except for the form opening and closing tags
633
+	 * (as the form section doesn't know where you necessarily want to send the information to),
634
+	 * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
637
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
+	 * any CSS.
639
+	 *
640
+	 * @throws InvalidArgumentException
641
+	 * @throws InvalidInterfaceException
642
+	 * @throws InvalidDataTypeException
643
+	 * @throws EE_Error
644
+	 */
645
+	public function get_html_and_js()
646
+	{
647
+		$this->enqueue_js();
648
+		return $this->get_html();
649
+	}
650
+
651
+
652
+	/**
653
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
+	 *
655
+	 * @param bool $display_previously_submitted_data
656
+	 * @return string
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidInterfaceException
659
+	 * @throws InvalidDataTypeException
660
+	 * @throws EE_Error
661
+	 * @throws EE_Error
662
+	 * @throws EE_Error
663
+	 */
664
+	public function get_html($display_previously_submitted_data = true)
665
+	{
666
+		$this->ensure_construct_finalized_called();
667
+		if ($display_previously_submitted_data) {
668
+			$this->populate_from_session();
669
+		}
670
+		return $this->_form_html_filter
671
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
+			: $this->_layout_strategy->layout_form();
673
+	}
674
+
675
+
676
+	/**
677
+	 * enqueues JS and CSS for the form.
678
+	 * It is preferred to call this before wp_enqueue_scripts so the
679
+	 * scripts and styles can be put in the header, but if called later
680
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
+	 * only be in the header; but in HTML5 its ok in the body.
682
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
+	 *
685
+	 * @return void
686
+	 * @throws EE_Error
687
+	 */
688
+	public function enqueue_js()
689
+	{
690
+		$this->_enqueue_and_localize_form_js();
691
+		foreach ($this->subsections() as $subsection) {
692
+			$subsection->enqueue_js();
693
+		}
694
+	}
695
+
696
+
697
+	/**
698
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
+	 * the wp_enqueue_scripts hook.
701
+	 * However, registering the form js and localizing it can happen when we
702
+	 * actually output the form (which is preferred, seeing how teh form's fields
703
+	 * could change until it's actually outputted)
704
+	 *
705
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
+	 *                                                    to be triggered automatically or not
707
+	 * @return void
708
+	 */
709
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
+	{
711
+		wp_register_script(
712
+			'ee_form_section_validation',
713
+			EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js',
714
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
+			EVENT_ESPRESSO_VERSION,
716
+			true
717
+		);
718
+		wp_localize_script(
719
+			'ee_form_section_validation',
720
+			'ee_form_section_validation_init',
721
+			array('init' => $init_form_validation_automatically ? '1' : '0')
722
+		);
723
+	}
724
+
725
+
726
+	/**
727
+	 * gets the variables used by form_section_validation.js.
728
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
+	 * but before the wordpress hook wp_loaded
730
+	 *
731
+	 * @throws EE_Error
732
+	 */
733
+	public function _enqueue_and_localize_form_js()
734
+	{
735
+		$this->ensure_construct_finalized_called();
736
+		// actually, we don't want to localize just yet. There may be other forms on the page.
737
+		// so we need to add our form section data to a static variable accessible by all form sections
738
+		// and localize it just before the footer
739
+		$this->localize_validation_rules();
740
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
+	}
743
+
744
+
745
+	/**
746
+	 * add our form section data to a static variable accessible by all form sections
747
+	 *
748
+	 * @param bool $return_for_subsection
749
+	 * @return void
750
+	 * @throws EE_Error
751
+	 */
752
+	public function localize_validation_rules($return_for_subsection = false)
753
+	{
754
+		// we only want to localize vars ONCE for the entire form,
755
+		// so if the form section doesn't have a parent, then it must be the top dog
756
+		if ($return_for_subsection || ! $this->parent_section()) {
757
+			EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
+				'form_section_id'  => $this->html_id(true),
759
+				'validation_rules' => $this->get_jquery_validation_rules(),
760
+				'other_data'       => $this->get_other_js_data(),
761
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
762
+			);
763
+			EE_Form_Section_Proper::$_scripts_localized                                = true;
764
+		}
765
+	}
766
+
767
+
768
+	/**
769
+	 * Gets an array of extra data that will be useful for client-side javascript.
770
+	 * This is primarily data added by inputs and forms in addition to any
771
+	 * scripts they might enqueue
772
+	 *
773
+	 * @param array $form_other_js_data
774
+	 * @return array
775
+	 * @throws EE_Error
776
+	 */
777
+	public function get_other_js_data($form_other_js_data = array())
778
+	{
779
+		foreach ($this->subsections() as $subsection) {
780
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
+		}
782
+		return $form_other_js_data;
783
+	}
784
+
785
+
786
+	/**
787
+	 * Gets a flat array of inputs for this form section and its subsections.
788
+	 * Keys are their form names, and values are the inputs themselves
789
+	 *
790
+	 * @return EE_Form_Input_Base
791
+	 * @throws EE_Error
792
+	 */
793
+	public function inputs_in_subsections()
794
+	{
795
+		$inputs = array();
796
+		foreach ($this->subsections() as $subsection) {
797
+			if ($subsection instanceof EE_Form_Input_Base) {
798
+				$inputs[ $subsection->html_name() ] = $subsection;
799
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
800
+				$inputs += $subsection->inputs_in_subsections();
801
+			}
802
+		}
803
+		return $inputs;
804
+	}
805
+
806
+
807
+	/**
808
+	 * Gets a flat array of all the validation errors.
809
+	 * Keys are html names (because those should be unique)
810
+	 * and values are a string of all their validation errors
811
+	 *
812
+	 * @return string[]
813
+	 * @throws EE_Error
814
+	 */
815
+	public function subsection_validation_errors_by_html_name()
816
+	{
817
+		$inputs = $this->inputs();
818
+		$errors = array();
819
+		foreach ($inputs as $form_input) {
820
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
+				$errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
+			}
823
+		}
824
+		return $errors;
825
+	}
826
+
827
+
828
+	/**
829
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
831
+	 *
832
+	 * @throws InvalidArgumentException
833
+	 * @throws InvalidInterfaceException
834
+	 * @throws InvalidDataTypeException
835
+	 */
836
+	public static function localize_script_for_all_forms()
837
+	{
838
+		// allow inputs and stuff to hook in their JS and stuff here
839
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
+			? EE_Registry::instance()->CFG->registration->email_validation_level
843
+			: 'wp_default';
844
+		EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
+		wp_enqueue_script('ee_form_section_validation');
846
+		wp_localize_script(
847
+			'ee_form_section_validation',
848
+			'ee_form_section_vars',
849
+			EE_Form_Section_Proper::$_js_localization
850
+		);
851
+	}
852
+
853
+
854
+	/**
855
+	 * ensure_scripts_localized
856
+	 *
857
+	 * @throws EE_Error
858
+	 */
859
+	public function ensure_scripts_localized()
860
+	{
861
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
862
+			$this->_enqueue_and_localize_form_js();
863
+		}
864
+	}
865
+
866
+
867
+	/**
868
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
869
+	 * is that the key here should be the same as the custom validation rule put in the JS file
870
+	 *
871
+	 * @return array keys are custom validation rules, and values are internationalized strings
872
+	 */
873
+	private static function _get_localized_error_messages()
874
+	{
875
+		return array(
876
+			'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
877
+			'regex'    => esc_html__('Please check your input', 'event_espresso'),
878
+		);
879
+	}
880
+
881
+
882
+	/**
883
+	 * @return array
884
+	 */
885
+	public static function js_localization()
886
+	{
887
+		return self::$_js_localization;
888
+	}
889
+
890
+
891
+	/**
892
+	 * @return void
893
+	 */
894
+	public static function reset_js_localization()
895
+	{
896
+		self::$_js_localization = array();
897
+	}
898
+
899
+
900
+	/**
901
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
+	 * See parent function for more...
903
+	 *
904
+	 * @return array
905
+	 * @throws EE_Error
906
+	 */
907
+	public function get_jquery_validation_rules()
908
+	{
909
+		$jquery_validation_rules = array();
910
+		foreach ($this->get_validatable_subsections() as $subsection) {
911
+			$jquery_validation_rules = array_merge(
912
+				$jquery_validation_rules,
913
+				$subsection->get_jquery_validation_rules()
914
+			);
915
+		}
916
+		return $jquery_validation_rules;
917
+	}
918
+
919
+
920
+	/**
921
+	 * Sanitizes all the data and sets the sanitized value of each field
922
+	 *
923
+	 * @param array $req_data like $_POST
924
+	 * @return void
925
+	 * @throws EE_Error
926
+	 */
927
+	protected function _normalize($req_data)
928
+	{
929
+		$this->_received_submission = true;
930
+		$this->_validation_errors   = array();
931
+		foreach ($this->get_validatable_subsections() as $subsection) {
932
+			try {
933
+				$subsection->_normalize($req_data);
934
+			} catch (EE_Validation_Error $e) {
935
+				$subsection->add_validation_error($e);
936
+			}
937
+		}
938
+	}
939
+
940
+
941
+	/**
942
+	 * Performs validation on this form section and its subsections.
943
+	 * For each subsection,
944
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
945
+	 * and passes it the subsection, then calls _validate on that subsection.
946
+	 * If you need to perform validation on the form as a whole (considering multiple)
947
+	 * you would be best to override this _validate method,
948
+	 * calling parent::_validate() first.
949
+	 *
950
+	 * @throws EE_Error
951
+	 */
952
+	protected function _validate()
953
+	{
954
+		// reset the cache of whether this form is valid or not- we're re-validating it now
955
+		$this->is_valid = null;
956
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
+			if (method_exists($this, '_validate_' . $subsection_name)) {
958
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
+			}
960
+			$subsection->_validate();
961
+		}
962
+	}
963
+
964
+
965
+	/**
966
+	 * Gets all the validated inputs for the form section
967
+	 *
968
+	 * @return array
969
+	 * @throws EE_Error
970
+	 */
971
+	public function valid_data()
972
+	{
973
+		$inputs = array();
974
+		foreach ($this->subsections() as $subsection_name => $subsection) {
975
+			if ($subsection instanceof EE_Form_Section_Proper) {
976
+				$inputs[ $subsection_name ] = $subsection->valid_data();
977
+			} elseif ($subsection instanceof EE_Form_Input_Base) {
978
+				$inputs[ $subsection_name ] = $subsection->normalized_value();
979
+			}
980
+		}
981
+		return $inputs;
982
+	}
983
+
984
+
985
+	/**
986
+	 * Gets all the inputs on this form section
987
+	 *
988
+	 * @return EE_Form_Input_Base[]
989
+	 * @throws EE_Error
990
+	 */
991
+	public function inputs()
992
+	{
993
+		$inputs = array();
994
+		foreach ($this->subsections() as $subsection_name => $subsection) {
995
+			if ($subsection instanceof EE_Form_Input_Base) {
996
+				$inputs[ $subsection_name ] = $subsection;
997
+			}
998
+		}
999
+		return $inputs;
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * Gets all the subsections which are a proper form
1005
+	 *
1006
+	 * @return EE_Form_Section_Proper[]
1007
+	 * @throws EE_Error
1008
+	 */
1009
+	public function subforms()
1010
+	{
1011
+		$form_sections = array();
1012
+		foreach ($this->subsections() as $name => $obj) {
1013
+			if ($obj instanceof EE_Form_Section_Proper) {
1014
+				$form_sections[ $name ] = $obj;
1015
+			}
1016
+		}
1017
+		return $form_sections;
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
+	 * Consider using inputs() or subforms()
1024
+	 * if you only want form inputs or proper form sections.
1025
+	 *
1026
+	 * @param boolean $require_construction_to_be_finalized most client code should
1027
+	 *                                                      leave this as TRUE so that the inputs will be properly
1028
+	 *                                                      configured. However, some client code may be ok with
1029
+	 *                                                      construction finalize being called later
1030
+	 *                                                      (realizing that the subsections' html names might not be
1031
+	 *                                                      set yet, etc.)
1032
+	 * @return EE_Form_Section_Proper[]
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	public function subsections($require_construction_to_be_finalized = true)
1036
+	{
1037
+		if ($require_construction_to_be_finalized) {
1038
+			$this->ensure_construct_finalized_called();
1039
+		}
1040
+		return $this->_subsections;
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * Returns whether this form has any subforms or inputs
1046
+	 * @return bool
1047
+	 */
1048
+	public function hasSubsections()
1049
+	{
1050
+		return ! empty($this->_subsections);
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * Returns a simple array where keys are input names, and values are their normalized
1056
+	 * values. (Similar to calling get_input_value on inputs)
1057
+	 *
1058
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
+	 *                                        or just this forms' direct children inputs
1060
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
+	 *                                        or allow multidimensional array
1062
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
+	 *                                        with array keys being input names
1064
+	 *                                        (regardless of whether they are from a subsection or not),
1065
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1066
+	 *                                        where keys are always subsection names and values are either
1067
+	 *                                        the input's normalized value, or an array like the top-level array
1068
+	 * @throws EE_Error
1069
+	 */
1070
+	public function input_values($include_subform_inputs = false, $flatten = false)
1071
+	{
1072
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
+	 * is not necessarily the value we want to display to users. This creates an array
1080
+	 * where keys are the input names, and values are their display values
1081
+	 *
1082
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
+	 *                                        or just this forms' direct children inputs
1084
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
+	 *                                        or allow multidimensional array
1086
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
+	 *                                        with array keys being input names
1088
+	 *                                        (regardless of whether they are from a subsection or not),
1089
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1090
+	 *                                        where keys are always subsection names and values are either
1091
+	 *                                        the input's normalized value, or an array like the top-level array
1092
+	 * @throws EE_Error
1093
+	 */
1094
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
+	{
1096
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
+	}
1098
+
1099
+
1100
+	/**
1101
+	 * Gets the input values from the form
1102
+	 *
1103
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
+	 *                                        or just the normalized value
1105
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
+	 *                                        or just this forms' direct children inputs
1107
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
+	 *                                        or allow multidimensional array
1109
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
+	 *                                        input names (regardless of whether they are from a subsection or not),
1111
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1112
+	 *                                        where keys are always subsection names and values are either
1113
+	 *                                        the input's normalized value, or an array like the top-level array
1114
+	 * @throws EE_Error
1115
+	 */
1116
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
+	{
1118
+		$input_values = array();
1119
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1120
+			if ($subsection instanceof EE_Form_Input_Base) {
1121
+				$input_values[ $subsection_name ] = $pretty
1122
+					? $subsection->pretty_value()
1123
+					: $subsection->normalized_value();
1124
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
+				$subform_input_values = $subsection->_input_values(
1126
+					$pretty,
1127
+					$include_subform_inputs,
1128
+					$flatten
1129
+				);
1130
+				if ($flatten) {
1131
+					$input_values = array_merge($input_values, $subform_input_values);
1132
+				} else {
1133
+					$input_values[ $subsection_name ] = $subform_input_values;
1134
+				}
1135
+			}
1136
+		}
1137
+		return $input_values;
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * Gets the originally submitted input values from the form
1143
+	 *
1144
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
+	 *                                   or just this forms' direct children inputs
1146
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
+	 *                                   with array keys being input names
1148
+	 *                                   (regardless of whether they are from a subsection or not),
1149
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1150
+	 *                                   where keys are always subsection names and values are either
1151
+	 *                                   the input's normalized value, or an array like the top-level array
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	public function submitted_values($include_subforms = false)
1155
+	{
1156
+		$submitted_values = array();
1157
+		foreach ($this->subsections() as $subsection) {
1158
+			if ($subsection instanceof EE_Form_Input_Base) {
1159
+				// is this input part of an array of inputs?
1160
+				if (strpos($subsection->html_name(), '[') !== false) {
1161
+					$full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
+						explode(
1163
+							'[',
1164
+							str_replace(']', '', $subsection->html_name())
1165
+						),
1166
+						$subsection->raw_value()
1167
+					);
1168
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
+				} else {
1170
+					$submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
+				}
1172
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1174
+				$submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
+			}
1176
+		}
1177
+		return $submitted_values;
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * Indicates whether or not this form has received a submission yet
1183
+	 * (ie, had receive_form_submission called on it yet)
1184
+	 *
1185
+	 * @return boolean
1186
+	 * @throws EE_Error
1187
+	 */
1188
+	public function has_received_submission()
1189
+	{
1190
+		$this->ensure_construct_finalized_called();
1191
+		return $this->_received_submission;
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1197
+	 * Removes the listed inputs from the form
1198
+	 *
1199
+	 * @param array $inputs_to_exclude values are the input names
1200
+	 * @return void
1201
+	 */
1202
+	public function exclude(array $inputs_to_exclude = array())
1203
+	{
1204
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
+			unset($this->_subsections[ $input_to_exclude_name ]);
1206
+		}
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
+	 * @param array $inputs_to_hide
1213
+	 * @throws EE_Error
1214
+	 */
1215
+	public function hide(array $inputs_to_hide = array())
1216
+	{
1217
+		foreach ($inputs_to_hide as $input_to_hide) {
1218
+			$input = $this->get_input($input_to_hide);
1219
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
+		}
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * add_subsections
1226
+	 * Adds the listed subsections to the form section.
1227
+	 * If $subsection_name_to_target is provided,
1228
+	 * then new subsections are added before or after that subsection,
1229
+	 * otherwise to the start or end of the entire subsections array.
1230
+	 *
1231
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
+	 *                                                          where keys are their names
1233
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
+	 *                                                          should be added before or after
1235
+	 *                                                          IF $subsection_name_to_target is null,
1236
+	 *                                                          then $new_subsections will be added to
1237
+	 *                                                          the beginning or end of the entire subsections array
1238
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
+	 *                                                          $subsection_name_to_target,
1240
+	 *                                                          or if $subsection_name_to_target is null,
1241
+	 *                                                          before or after entire subsections array
1242
+	 * @return void
1243
+	 * @throws EE_Error
1244
+	 */
1245
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
+	{
1247
+		foreach ($new_subsections as $subsection_name => $subsection) {
1248
+			if (! $subsection instanceof EE_Form_Section_Base) {
1249
+				EE_Error::add_error(
1250
+					sprintf(
1251
+						esc_html__(
1252
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
+							'event_espresso'
1254
+						),
1255
+						get_class($subsection),
1256
+						$subsection_name,
1257
+						$this->name()
1258
+					)
1259
+				);
1260
+				unset($new_subsections[ $subsection_name ]);
1261
+			}
1262
+		}
1263
+		$this->_subsections = EEH_Array::insert_into_array(
1264
+			$this->_subsections,
1265
+			$new_subsections,
1266
+			$subsection_name_to_target,
1267
+			$add_before
1268
+		);
1269
+		if ($this->_construction_finalized) {
1270
+			foreach ($this->_subsections as $name => $subsection) {
1271
+				$subsection->_construct_finalize($this, $name);
1272
+			}
1273
+		}
1274
+	}
1275
+
1276
+
1277
+	/**
1278
+	 * @param string $subsection_name
1279
+	 * @param bool   $recursive
1280
+	 * @return bool
1281
+	 */
1282
+	public function has_subsection($subsection_name, $recursive = false)
1283
+	{
1284
+		foreach ($this->_subsections as $name => $subsection) {
1285
+			if ($name === $subsection_name
1286
+				|| (
1287
+					$recursive
1288
+					&& $subsection instanceof EE_Form_Section_Proper
1289
+					&& $subsection->has_subsection($subsection_name, $recursive)
1290
+				)
1291
+			) {
1292
+				return true;
1293
+			}
1294
+		}
1295
+		return false;
1296
+	}
1297
+
1298
+
1299
+
1300
+	/**
1301
+	 * Just gets all validatable subsections to clean their sensitive data
1302
+	 *
1303
+	 * @throws EE_Error
1304
+	 */
1305
+	public function clean_sensitive_data()
1306
+	{
1307
+		foreach ($this->get_validatable_subsections() as $subsection) {
1308
+			$subsection->clean_sensitive_data();
1309
+		}
1310
+	}
1311
+
1312
+
1313
+	/**
1314
+	 * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
+	 * @param string                           $form_submission_error_message
1316
+	 * @param EE_Form_Section_Validatable $form_section unused
1317
+	 * @throws EE_Error
1318
+	 */
1319
+	public function set_submission_error_message(
1320
+		$form_submission_error_message = ''
1321
+	) {
1322
+		$this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
+			? $form_submission_error_message
1324
+			: $this->getAllValidationErrorsString();
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * Returns the cached error message. A default value is set for this during _validate(),
1330
+	 * (called during receive_form_submission) but it can be explicitly set using
1331
+	 * set_submission_error_message
1332
+	 *
1333
+	 * @return string
1334
+	 */
1335
+	public function submission_error_message()
1336
+	{
1337
+		return $this->_form_submission_error_message;
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * Sets a message to display if the data submitted to the form was valid.
1343
+	 * @param string $form_submission_success_message
1344
+	 */
1345
+	public function set_submission_success_message($form_submission_success_message = '')
1346
+	{
1347
+		$this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
+			? $form_submission_success_message
1349
+			: esc_html__('Form submitted successfully', 'event_espresso');
1350
+	}
1351
+
1352
+
1353
+	/**
1354
+	 * Gets a message appropriate for display when the form is correctly submitted
1355
+	 * @return string
1356
+	 */
1357
+	public function submission_success_message()
1358
+	{
1359
+		return $this->_form_submission_success_message;
1360
+	}
1361
+
1362
+
1363
+	/**
1364
+	 * Returns the prefix that should be used on child of this form section for
1365
+	 * their html names. If this form section itself has a parent, prepends ITS
1366
+	 * prefix onto this form section's prefix. Used primarily by
1367
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
+	 *
1369
+	 * @return string
1370
+	 * @throws EE_Error
1371
+	 */
1372
+	public function html_name_prefix()
1373
+	{
1374
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
+		}
1377
+		return $this->name();
1378
+	}
1379
+
1380
+
1381
+	/**
1382
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1383
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1384
+	 * was set, which is probably nothing, or the classname)
1385
+	 *
1386
+	 * @return string
1387
+	 * @throws EE_Error
1388
+	 */
1389
+	public function name()
1390
+	{
1391
+		$this->ensure_construct_finalized_called();
1392
+		return parent::name();
1393
+	}
1394
+
1395
+
1396
+	/**
1397
+	 * @return EE_Form_Section_Proper
1398
+	 * @throws EE_Error
1399
+	 */
1400
+	public function parent_section()
1401
+	{
1402
+		$this->ensure_construct_finalized_called();
1403
+		return parent::parent_section();
1404
+	}
1405
+
1406
+
1407
+	/**
1408
+	 * make sure construction finalized was called, otherwise children might not be ready
1409
+	 *
1410
+	 * @return void
1411
+	 * @throws EE_Error
1412
+	 */
1413
+	public function ensure_construct_finalized_called()
1414
+	{
1415
+		if (! $this->_construction_finalized) {
1416
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1417
+		}
1418
+	}
1419
+
1420
+
1421
+	/**
1422
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1423
+	 * are in teh form data. If any are found, returns true. Else false
1424
+	 *
1425
+	 * @param array $req_data
1426
+	 * @return boolean
1427
+	 * @throws EE_Error
1428
+	 */
1429
+	public function form_data_present_in($req_data = null)
1430
+	{
1431
+		$req_data = $this->getCachedRequest($req_data);
1432
+		foreach ($this->subsections() as $subsection) {
1433
+			if ($subsection instanceof EE_Form_Input_Base) {
1434
+				if ($subsection->form_data_present_in($req_data)) {
1435
+					return true;
1436
+				}
1437
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
+				if ($subsection->form_data_present_in($req_data)) {
1439
+					return true;
1440
+				}
1441
+			}
1442
+		}
1443
+		return false;
1444
+	}
1445
+
1446
+
1447
+	/**
1448
+	 * Gets validation errors for this form section and subsections
1449
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
+	 * gets the validation errors for ALL subsection
1451
+	 *
1452
+	 * @return EE_Validation_Error[]
1453
+	 * @throws EE_Error
1454
+	 */
1455
+	public function get_validation_errors_accumulated()
1456
+	{
1457
+		$validation_errors = $this->get_validation_errors();
1458
+		foreach ($this->get_validatable_subsections() as $subsection) {
1459
+			if ($subsection instanceof EE_Form_Section_Proper) {
1460
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
+			} else {
1462
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
+			}
1464
+			if ($validation_errors_on_this_subsection) {
1465
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
+			}
1467
+		}
1468
+		return $validation_errors;
1469
+	}
1470
+
1471
+	/**
1472
+	 * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
+	 * This traverses the form section tree to generate this, but you probably want to instead use
1474
+	 * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
+	 *
1476
+	 * @return string
1477
+	 * @since 4.9.59.p
1478
+	 */
1479
+	protected function getAllValidationErrorsString()
1480
+	{
1481
+		$submission_error_messages = array();
1482
+		// bad, bad, bad registrant
1483
+		foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
+			if ($validation_error instanceof EE_Validation_Error) {
1485
+				$form_section = $validation_error->get_form_section();
1486
+				if ($form_section instanceof EE_Form_Input_Base) {
1487
+					$label = $validation_error->get_form_section()->html_label_text();
1488
+				} elseif ($form_section instanceof EE_Form_Section_Validatable) {
1489
+					$label = $validation_error->get_form_section()->name();
1490
+				} else {
1491
+					$label = esc_html__('Unknown', 'event_espresso');
1492
+				}
1493
+				$submission_error_messages[] = sprintf(
1494
+					__('%s : %s', 'event_espresso'),
1495
+					$label,
1496
+					$validation_error->getMessage()
1497
+				);
1498
+			}
1499
+		}
1500
+		return implode('<br>', $submission_error_messages);
1501
+	}
1502
+
1503
+
1504
+	/**
1505
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1506
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
+	 * dot-dot-slash (../) means to ascend into the parent section.
1508
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
+	 * which will be returned.
1510
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
+	 * Etc
1515
+	 *
1516
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
+	 * @return EE_Form_Section_Base
1518
+	 * @throws EE_Error
1519
+	 */
1520
+	public function find_section_from_path($form_section_path)
1521
+	{
1522
+		// check if we can find the input from purely going straight up the tree
1523
+		$input = parent::find_section_from_path($form_section_path);
1524
+		if ($input instanceof EE_Form_Section_Base) {
1525
+			return $input;
1526
+		}
1527
+		$next_slash_pos = strpos($form_section_path, '/');
1528
+		if ($next_slash_pos !== false) {
1529
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
+			$subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
+		} else {
1532
+			$child_section_name = $form_section_path;
1533
+			$subpath            = '';
1534
+		}
1535
+		$child_section = $this->get_subsection($child_section_name);
1536
+		if ($child_section instanceof EE_Form_Section_Base) {
1537
+			return $child_section->find_section_from_path($subpath);
1538
+		}
1539
+		return null;
1540
+	}
1541 1541
 }
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 2 patches
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
     public function __construct($routing = true)
33 33
     {
34 34
         parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
35
+        if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
36
+            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
37
+            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
38
+            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
39 39
         }
40 40
     }
41 41
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      */
46 46
     protected function _extend_page_config()
47 47
     {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
48
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
49 49
         $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50 50
             ? $this->_req_data['_REG_ID']
51 51
             : 0;
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
             // enqueue newsletter js
186 186
             wp_enqueue_script(
187 187
                 'ee-newsletter-trigger',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
188
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js',
189 189
                 array('ee-dialog'),
190 190
                 EVENT_ESPRESSO_VERSION,
191 191
                 true
192 192
             );
193 193
             wp_enqueue_style(
194 194
                 'ee-newsletter-trigger-css',
195
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
195
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css',
196 196
                 array(),
197 197
                 EVENT_ESPRESSO_VERSION
198 198
             );
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     {
214 214
         wp_register_script(
215 215
             'ee-reg-reports-js',
216
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
216
+            REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js',
217 217
             array('google-charts'),
218 218
             EVENT_ESPRESSO_VERSION,
219 219
             true
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
         $nonce_ref = 'get_newsletter_form_content_nonce';
300 300
         $this->_verify_nonce($nonce, $nonce_ref);
301 301
         // let's get the mtp for the incoming MTP_ ID
302
-        if (! isset($this->_req_data['GRP_ID'])) {
302
+        if ( ! isset($this->_req_data['GRP_ID'])) {
303 303
             EE_Error::add_error(
304 304
                 esc_html__(
305 305
                     'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
             $this->_return_json();
315 315
         }
316 316
         $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
317
-        if (! $MTPG instanceof EE_Message_Template_Group) {
317
+        if ( ! $MTPG instanceof EE_Message_Template_Group) {
318 318
             EE_Error::add_error(
319 319
                 sprintf(
320 320
                     esc_html__(
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
             $field = $MTP->get('MTP_template_field');
340 340
             if ($field === 'content') {
341 341
                 $content = $MTP->get('MTP_content');
342
-                if (! empty($content['newsletter_content'])) {
342
+                if ( ! empty($content['newsletter_content'])) {
343 343
                     $template_fields['newsletter_content'] = $content['newsletter_content'];
344 344
                 }
345 345
                 continue;
346 346
             }
347
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
347
+            $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
348 348
         }
349 349
         $this->_template_args['success'] = true;
350 350
         $this->_template_args['error'] = false;
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
      */
376 376
     public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
377 377
     {
378
-        if (! EE_Registry::instance()->CAP->current_user_can(
378
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
379 379
             'ee_send_message',
380 380
             'espresso_registrations_newsletter_selected_send'
381 381
         )
@@ -444,17 +444,17 @@  discard block
 block discarded – undo
444 444
                 $field_id = $field === '[NEWSLETTER_CONTENT]'
445 445
                     ? 'content'
446 446
                     : $field;
447
-                $field_id = 'batch-message-' . strtolower($field_id);
447
+                $field_id = 'batch-message-'.strtolower($field_id);
448 448
                 $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
449 449
                                           . $shortcode
450
-                                          . '" data-linked-input-id="' . $field_id . '">'
450
+                                          . '" data-linked-input-id="'.$field_id.'">'
451 451
                                           . $shortcode
452 452
                                           . '</span>';
453 453
             }
454
-            $codes[ $field ] = implode(', ', $available_shortcodes);
454
+            $codes[$field] = implode(', ', $available_shortcodes);
455 455
         }
456 456
         $shortcodes = $codes;
457
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
457
+        $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
458 458
         $form_template_args = array(
459 459
             'form_action'       => admin_url('admin.php?page=espresso_registrations'),
460 460
             'form_route'        => 'newsletter_selected_send',
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
      */
623 623
     protected function _registration_reports()
624 624
     {
625
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
625
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
626 626
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
627 627
             $template_path,
628 628
             $this->_reports_template_data,
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
             array_unshift($regs, $column_titles);
678 678
             // setup the date range.
679 679
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
680
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
680
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
681 681
             $ending_date = new DateTime("now", $DateTimeZone);
682 682
             $subtitle = sprintf(
683 683
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
                     '%sThere are currently no registration records in the last month for this report.%s',
698 698
                     'event_espresso'
699 699
                 ),
700
-                '<h2>' . $report_title . '</h2><p>',
700
+                '<h2>'.$report_title.'</h2><p>',
701 701
                 '</p>'
702 702
             ),
703 703
         );
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
             array_unshift($regs, $column_titles);
751 751
             // setup the date range.
752 752
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
753
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
753
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
754 754
             $ending_date = new DateTime("now", $DateTimeZone);
755 755
             $subtitle = sprintf(
756 756
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
                     '%sThere are currently no registration records in the last month for this report.%s',
771 771
                     'event_espresso'
772 772
                 ),
773
-                '<h2>' . $report_title . '</h2><p>',
773
+                '<h2>'.$report_title.'</h2><p>',
774 774
                 '</p>'
775 775
             ),
776 776
         );
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
         $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
797 797
         /** @var EE_Registration $registration */
798 798
         $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
799
-        if (! $registration instanceof EE_Registration) {
799
+        if ( ! $registration instanceof EE_Registration) {
800 800
             throw new EE_Error(
801 801
                 sprintf(
802 802
                     esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
         if ($datetime instanceof EE_Datetime) {
832 832
             $datetime_label = $datetime->get_dtt_display_name(true);
833 833
             $datetime_label .= ! empty($datetime_label)
834
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
834
+                ? ' ('.$datetime->get_dtt_display_name().')'
835 835
                 : $datetime->get_dtt_display_name();
836 836
         }
837 837
         $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
             )
846 846
             : '';
847 847
         $datetime_link = ! empty($datetime_link)
848
-            ? '<a href="' . $datetime_link . '">'
848
+            ? '<a href="'.$datetime_link.'">'
849 849
               . '<span id="checkin-dtt">'
850 850
               . $datetime_label
851 851
               . '</span></a>'
@@ -857,8 +857,8 @@  discard block
 block discarded – undo
857 857
             ? $attendee->get_admin_details_link()
858 858
             : '';
859 859
         $attendee_link = ! empty($attendee_link)
860
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
861
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
860
+            ? '<a href="'.$attendee->get_admin_details_link().'"'
861
+              . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">'
862 862
               . '<span id="checkin-attendee-name">'
863 863
               . $attendee_name
864 864
               . '</span></a>'
@@ -867,25 +867,25 @@  discard block
 block discarded – undo
867 867
             ? $registration->event()->get_admin_details_link()
868 868
             : '';
869 869
         $event_link = ! empty($event_link)
870
-            ? '<a href="' . $event_link . '"'
871
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
870
+            ? '<a href="'.$event_link.'"'
871
+              . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">'
872 872
               . '<span id="checkin-event-name">'
873 873
               . $registration->event_name()
874 874
               . '</span>'
875 875
               . '</a>'
876 876
             : '';
877 877
         $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
878
-            ? '<h2>' . sprintf(
878
+            ? '<h2>'.sprintf(
879 879
                 esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
880 880
                 $attendee_link,
881 881
                 $datetime_link,
882 882
                 $event_link
883
-            ) . '</h2>'
883
+            ).'</h2>'
884 884
             : '';
885 885
         $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
886
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
886
+            ? '<input type="hidden" name="_REG_ID" value="'.$reg_id.'">' : '';
887 887
         $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
888
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
888
+            ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
889 889
         $this->display_admin_list_table_page_with_no_sidebar();
890 890
     }
891 891
 
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
     public function toggle_checkin_status()
903 903
     {
904 904
         // first make sure we have the necessary data
905
-        if (! isset($this->_req_data['_regid'])) {
905
+        if ( ! isset($this->_req_data['_regid'])) {
906 906
             EE_Error::add_error(
907 907
                 esc_html__(
908 908
                     'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
         // beautiful! Made it this far so let's get the status.
925 925
         $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
926 926
         // setup new class to return via ajax
927
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
927
+        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses();
928 928
         $this->_template_args['success'] = true;
929 929
         $this->_return_json();
930 930
     }
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
         );
951 951
         $new_status = false;
952 952
         // bulk action check in toggle
953
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
953
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
954 954
             // cycle thru checkboxes
955 955
             while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
956 956
                 $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
@@ -1020,9 +1020,9 @@  discard block
 block discarded – undo
1020 1020
             '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1021 1021
         );
1022 1022
         $errors = 0;
1023
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1023
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1024 1024
             while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1025
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1025
+                if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1026 1026
                     $errors++;
1027 1027
                 }
1028 1028
             }
@@ -1068,8 +1068,8 @@  discard block
 block discarded – undo
1068 1068
             'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1069 1069
             '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1070 1070
         );
1071
-        if (! empty($this->_req_data['CHK_ID'])) {
1072
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1071
+        if ( ! empty($this->_req_data['CHK_ID'])) {
1072
+            if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1073 1073
                 EE_Error::add_error(
1074 1074
                     esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1075 1075
                     __FILE__,
@@ -1138,27 +1138,27 @@  discard block
 block discarded – undo
1138 1138
                 'desc'  => $checked_never->legendLabel(),
1139 1139
             ),
1140 1140
             'approved_status'  => array(
1141
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1141
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1142 1142
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1143 1143
             ),
1144 1144
             'cancelled_status' => array(
1145
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1145
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1146 1146
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1147 1147
             ),
1148 1148
             'declined_status'  => array(
1149
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1149
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1150 1150
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1151 1151
             ),
1152 1152
             'not_approved'     => array(
1153
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1153
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1154 1154
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1155 1155
             ),
1156 1156
             'pending_status'   => array(
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1157
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1158 1158
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1159 1159
             ),
1160 1160
             'wait_list'        => array(
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1161
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1162 1162
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1163 1163
             ),
1164 1164
         );
@@ -1167,10 +1167,10 @@  discard block
 block discarded – undo
1167 1167
         /** @var EE_Event $event */
1168 1168
         $event = EEM_Event::instance()->get_one_by_ID($event_id);
1169 1169
         $this->_template_args['before_list_table'] = $event instanceof EE_Event
1170
-            ? '<h2>' . sprintf(
1170
+            ? '<h2>'.sprintf(
1171 1171
                 esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1172 1172
                 EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1173
-            ) . '</h2>'
1173
+            ).'</h2>'
1174 1174
             : '';
1175 1175
         // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1176 1176
         // the event.
@@ -1188,12 +1188,12 @@  discard block
 block discarded – undo
1188 1188
             $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1189 1189
             $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1190 1190
             $this->_template_args['before_list_table'] .= $datetime->name();
1191
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1191
+            $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )';
1192 1192
             $this->_template_args['before_list_table'] .= '</span></h2>';
1193 1193
         }
1194 1194
         // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1195 1195
         // column represents
1196
-        if (! $datetime instanceof EE_Datetime) {
1196
+        if ( ! $datetime instanceof EE_Datetime) {
1197 1197
             $this->_template_args['before_list_table'] .= '<br><p class="description">'
1198 1198
                                                           . esc_html__(
1199 1199
                                                               'In this view, the check-in status represents the latest check-in record for the registration in that row.',
Please login to merge, or discard this patch.
Indentation   +1211 added lines, -1211 removed lines patch added patch discarded remove patch
@@ -16,1268 +16,1268 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * This is used to hold the reports template data which is setup early in the request.
21
-     *
22
-     * @type array
23
-     */
24
-    protected $_reports_template_data = array();
19
+	/**
20
+	 * This is used to hold the reports template data which is setup early in the request.
21
+	 *
22
+	 * @type array
23
+	 */
24
+	protected $_reports_template_data = array();
25 25
 
26 26
 
27
-    /**
28
-     * Extend_Registrations_Admin_Page constructor.
29
-     *
30
-     * @param bool $routing
31
-     */
32
-    public function __construct($routing = true)
33
-    {
34
-        parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
-        }
40
-    }
27
+	/**
28
+	 * Extend_Registrations_Admin_Page constructor.
29
+	 *
30
+	 * @param bool $routing
31
+	 */
32
+	public function __construct($routing = true)
33
+	{
34
+		parent::__construct($routing);
35
+		if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
+		}
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * Extending page configuration.
45
-     */
46
-    protected function _extend_page_config()
47
-    {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
-            ? $this->_req_data['_REG_ID']
51
-            : 0;
52
-        $new_page_routes = array(
53
-            'reports'                      => array(
54
-                'func'       => '_registration_reports',
55
-                'capability' => 'ee_read_registrations',
56
-            ),
57
-            'registration_checkins'        => array(
58
-                'func'       => '_registration_checkin_list_table',
59
-                'capability' => 'ee_read_checkins',
60
-            ),
61
-            'newsletter_selected_send'     => array(
62
-                'func'       => '_newsletter_selected_send',
63
-                'noheader'   => true,
64
-                'capability' => 'ee_send_message',
65
-            ),
66
-            'delete_checkin_rows'          => array(
67
-                'func'       => '_delete_checkin_rows',
68
-                'noheader'   => true,
69
-                'capability' => 'ee_delete_checkins',
70
-            ),
71
-            'delete_checkin_row'           => array(
72
-                'func'       => '_delete_checkin_row',
73
-                'noheader'   => true,
74
-                'capability' => 'ee_delete_checkin',
75
-                'obj_id'     => $reg_id,
76
-            ),
77
-            'toggle_checkin_status'        => array(
78
-                'func'       => '_toggle_checkin_status',
79
-                'noheader'   => true,
80
-                'capability' => 'ee_edit_checkin',
81
-                'obj_id'     => $reg_id,
82
-            ),
83
-            'toggle_checkin_status_bulk'   => array(
84
-                'func'       => '_toggle_checkin_status',
85
-                'noheader'   => true,
86
-                'capability' => 'ee_edit_checkins',
87
-            ),
88
-            'event_registrations'          => array(
89
-                'func'       => '_event_registrations_list_table',
90
-                'capability' => 'ee_read_checkins',
91
-            ),
92
-            'registrations_checkin_report' => array(
93
-                'func'       => '_registrations_checkin_report',
94
-                'noheader'   => true,
95
-                'capability' => 'ee_read_registrations',
96
-            ),
97
-        );
98
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
-        $new_page_config = array(
100
-            'reports'               => array(
101
-                'nav'           => array(
102
-                    'label' => esc_html__('Reports', 'event_espresso'),
103
-                    'order' => 30,
104
-                ),
105
-                'help_tabs'     => array(
106
-                    'registrations_reports_help_tab' => array(
107
-                        'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
-                        'filename' => 'registrations_reports',
109
-                    ),
110
-                ),
111
-                /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
112
-                'require_nonce' => false,
113
-            ),
114
-            'event_registrations'   => array(
115
-                'nav'           => array(
116
-                    'label'      => esc_html__('Event Check-In', 'event_espresso'),
117
-                    'order'      => 10,
118
-                    'persistent' => true,
119
-                ),
120
-                'help_tabs'     => array(
121
-                    'registrations_event_checkin_help_tab'                       => array(
122
-                        'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
123
-                        'filename' => 'registrations_event_checkin',
124
-                    ),
125
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
126
-                        'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
127
-                        'filename' => 'registrations_event_checkin_table_column_headings',
128
-                    ),
129
-                    'registrations_event_checkin_filters_help_tab'               => array(
130
-                        'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
131
-                        'filename' => 'registrations_event_checkin_filters',
132
-                    ),
133
-                    'registrations_event_checkin_views_help_tab'                 => array(
134
-                        'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
135
-                        'filename' => 'registrations_event_checkin_views',
136
-                    ),
137
-                    'registrations_event_checkin_other_help_tab'                 => array(
138
-                        'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
139
-                        'filename' => 'registrations_event_checkin_other',
140
-                    ),
141
-                ),
142
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
143
-                // 'help_tour'     => array('Event_Checkin_Help_Tour'),
144
-                'qtips'         => array('Registration_List_Table_Tips'),
145
-                'list_table'    => 'EE_Event_Registrations_List_Table',
146
-                'metaboxes'     => array(),
147
-                'require_nonce' => false,
148
-            ),
149
-            'registration_checkins' => array(
150
-                'nav'           => array(
151
-                    'label'      => esc_html__('Check-In Records', 'event_espresso'),
152
-                    'order'      => 15,
153
-                    'persistent' => false,
154
-                    'url'        => '',
155
-                ),
156
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
157
-                // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
158
-                'metaboxes'     => array(),
159
-                'require_nonce' => false,
160
-            ),
161
-        );
162
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
163
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
164
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
165
-    }
43
+	/**
44
+	 * Extending page configuration.
45
+	 */
46
+	protected function _extend_page_config()
47
+	{
48
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
+			? $this->_req_data['_REG_ID']
51
+			: 0;
52
+		$new_page_routes = array(
53
+			'reports'                      => array(
54
+				'func'       => '_registration_reports',
55
+				'capability' => 'ee_read_registrations',
56
+			),
57
+			'registration_checkins'        => array(
58
+				'func'       => '_registration_checkin_list_table',
59
+				'capability' => 'ee_read_checkins',
60
+			),
61
+			'newsletter_selected_send'     => array(
62
+				'func'       => '_newsletter_selected_send',
63
+				'noheader'   => true,
64
+				'capability' => 'ee_send_message',
65
+			),
66
+			'delete_checkin_rows'          => array(
67
+				'func'       => '_delete_checkin_rows',
68
+				'noheader'   => true,
69
+				'capability' => 'ee_delete_checkins',
70
+			),
71
+			'delete_checkin_row'           => array(
72
+				'func'       => '_delete_checkin_row',
73
+				'noheader'   => true,
74
+				'capability' => 'ee_delete_checkin',
75
+				'obj_id'     => $reg_id,
76
+			),
77
+			'toggle_checkin_status'        => array(
78
+				'func'       => '_toggle_checkin_status',
79
+				'noheader'   => true,
80
+				'capability' => 'ee_edit_checkin',
81
+				'obj_id'     => $reg_id,
82
+			),
83
+			'toggle_checkin_status_bulk'   => array(
84
+				'func'       => '_toggle_checkin_status',
85
+				'noheader'   => true,
86
+				'capability' => 'ee_edit_checkins',
87
+			),
88
+			'event_registrations'          => array(
89
+				'func'       => '_event_registrations_list_table',
90
+				'capability' => 'ee_read_checkins',
91
+			),
92
+			'registrations_checkin_report' => array(
93
+				'func'       => '_registrations_checkin_report',
94
+				'noheader'   => true,
95
+				'capability' => 'ee_read_registrations',
96
+			),
97
+		);
98
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
+		$new_page_config = array(
100
+			'reports'               => array(
101
+				'nav'           => array(
102
+					'label' => esc_html__('Reports', 'event_espresso'),
103
+					'order' => 30,
104
+				),
105
+				'help_tabs'     => array(
106
+					'registrations_reports_help_tab' => array(
107
+						'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
+						'filename' => 'registrations_reports',
109
+					),
110
+				),
111
+				/*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
112
+				'require_nonce' => false,
113
+			),
114
+			'event_registrations'   => array(
115
+				'nav'           => array(
116
+					'label'      => esc_html__('Event Check-In', 'event_espresso'),
117
+					'order'      => 10,
118
+					'persistent' => true,
119
+				),
120
+				'help_tabs'     => array(
121
+					'registrations_event_checkin_help_tab'                       => array(
122
+						'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
123
+						'filename' => 'registrations_event_checkin',
124
+					),
125
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
126
+						'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
127
+						'filename' => 'registrations_event_checkin_table_column_headings',
128
+					),
129
+					'registrations_event_checkin_filters_help_tab'               => array(
130
+						'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
131
+						'filename' => 'registrations_event_checkin_filters',
132
+					),
133
+					'registrations_event_checkin_views_help_tab'                 => array(
134
+						'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
135
+						'filename' => 'registrations_event_checkin_views',
136
+					),
137
+					'registrations_event_checkin_other_help_tab'                 => array(
138
+						'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
139
+						'filename' => 'registrations_event_checkin_other',
140
+					),
141
+				),
142
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
143
+				// 'help_tour'     => array('Event_Checkin_Help_Tour'),
144
+				'qtips'         => array('Registration_List_Table_Tips'),
145
+				'list_table'    => 'EE_Event_Registrations_List_Table',
146
+				'metaboxes'     => array(),
147
+				'require_nonce' => false,
148
+			),
149
+			'registration_checkins' => array(
150
+				'nav'           => array(
151
+					'label'      => esc_html__('Check-In Records', 'event_espresso'),
152
+					'order'      => 15,
153
+					'persistent' => false,
154
+					'url'        => '',
155
+				),
156
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
157
+				// 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
158
+				'metaboxes'     => array(),
159
+				'require_nonce' => false,
160
+			),
161
+		);
162
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
163
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
164
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
165
+	}
166 166
 
167 167
 
168
-    /**
169
-     * Ajax hooks for all routes in this page.
170
-     */
171
-    protected function _ajax_hooks()
172
-    {
173
-        parent::_ajax_hooks();
174
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
175
-    }
168
+	/**
169
+	 * Ajax hooks for all routes in this page.
170
+	 */
171
+	protected function _ajax_hooks()
172
+	{
173
+		parent::_ajax_hooks();
174
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
175
+	}
176 176
 
177 177
 
178
-    /**
179
-     * Global scripts for all routes in this page.
180
-     */
181
-    public function load_scripts_styles()
182
-    {
183
-        parent::load_scripts_styles();
184
-        // if newsletter message type is active then let's add filter and load js for it.
185
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
186
-            // enqueue newsletter js
187
-            wp_enqueue_script(
188
-                'ee-newsletter-trigger',
189
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
190
-                array('ee-dialog'),
191
-                EVENT_ESPRESSO_VERSION,
192
-                true
193
-            );
194
-            wp_enqueue_style(
195
-                'ee-newsletter-trigger-css',
196
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
197
-                array(),
198
-                EVENT_ESPRESSO_VERSION
199
-            );
200
-            // hook in buttons for newsletter message type trigger.
201
-            add_action(
202
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
203
-                array($this, 'add_newsletter_action_buttons'),
204
-                10
205
-            );
206
-        }
207
-    }
178
+	/**
179
+	 * Global scripts for all routes in this page.
180
+	 */
181
+	public function load_scripts_styles()
182
+	{
183
+		parent::load_scripts_styles();
184
+		// if newsletter message type is active then let's add filter and load js for it.
185
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
186
+			// enqueue newsletter js
187
+			wp_enqueue_script(
188
+				'ee-newsletter-trigger',
189
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
190
+				array('ee-dialog'),
191
+				EVENT_ESPRESSO_VERSION,
192
+				true
193
+			);
194
+			wp_enqueue_style(
195
+				'ee-newsletter-trigger-css',
196
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
197
+				array(),
198
+				EVENT_ESPRESSO_VERSION
199
+			);
200
+			// hook in buttons for newsletter message type trigger.
201
+			add_action(
202
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
203
+				array($this, 'add_newsletter_action_buttons'),
204
+				10
205
+			);
206
+		}
207
+	}
208 208
 
209 209
 
210
-    /**
211
-     * Scripts and styles for just the reports route.
212
-     */
213
-    public function load_scripts_styles_reports()
214
-    {
215
-        wp_register_script(
216
-            'ee-reg-reports-js',
217
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
218
-            array('google-charts'),
219
-            EVENT_ESPRESSO_VERSION,
220
-            true
221
-        );
222
-        wp_enqueue_script('ee-reg-reports-js');
223
-        $this->_registration_reports_js_setup();
224
-    }
210
+	/**
211
+	 * Scripts and styles for just the reports route.
212
+	 */
213
+	public function load_scripts_styles_reports()
214
+	{
215
+		wp_register_script(
216
+			'ee-reg-reports-js',
217
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
218
+			array('google-charts'),
219
+			EVENT_ESPRESSO_VERSION,
220
+			true
221
+		);
222
+		wp_enqueue_script('ee-reg-reports-js');
223
+		$this->_registration_reports_js_setup();
224
+	}
225 225
 
226 226
 
227
-    /**
228
-     * Register screen options for event_registrations route.
229
-     */
230
-    protected function _add_screen_options_event_registrations()
231
-    {
232
-        $this->_per_page_screen_option();
233
-    }
227
+	/**
228
+	 * Register screen options for event_registrations route.
229
+	 */
230
+	protected function _add_screen_options_event_registrations()
231
+	{
232
+		$this->_per_page_screen_option();
233
+	}
234 234
 
235 235
 
236
-    /**
237
-     * Register screen options for registration_checkins route
238
-     */
239
-    protected function _add_screen_options_registration_checkins()
240
-    {
241
-        $page_title = $this->_admin_page_title;
242
-        $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
243
-        $this->_per_page_screen_option();
244
-        $this->_admin_page_title = $page_title;
245
-    }
236
+	/**
237
+	 * Register screen options for registration_checkins route
238
+	 */
239
+	protected function _add_screen_options_registration_checkins()
240
+	{
241
+		$page_title = $this->_admin_page_title;
242
+		$this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
243
+		$this->_per_page_screen_option();
244
+		$this->_admin_page_title = $page_title;
245
+	}
246 246
 
247 247
 
248
-    /**
249
-     * Set views property for event_registrations route.
250
-     */
251
-    protected function _set_list_table_views_event_registrations()
252
-    {
253
-        $this->_views = array(
254
-            'all' => array(
255
-                'slug'        => 'all',
256
-                'label'       => esc_html__('All', 'event_espresso'),
257
-                'count'       => 0,
258
-                'bulk_action' => ! isset($this->_req_data['event_id'])
259
-                    ? array()
260
-                    : array(
261
-                        'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
262
-                    ),
263
-            ),
264
-        );
265
-    }
248
+	/**
249
+	 * Set views property for event_registrations route.
250
+	 */
251
+	protected function _set_list_table_views_event_registrations()
252
+	{
253
+		$this->_views = array(
254
+			'all' => array(
255
+				'slug'        => 'all',
256
+				'label'       => esc_html__('All', 'event_espresso'),
257
+				'count'       => 0,
258
+				'bulk_action' => ! isset($this->_req_data['event_id'])
259
+					? array()
260
+					: array(
261
+						'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
262
+					),
263
+			),
264
+		);
265
+	}
266 266
 
267 267
 
268
-    /**
269
-     * Set views property for registration_checkins route.
270
-     */
271
-    protected function _set_list_table_views_registration_checkins()
272
-    {
273
-        $this->_views = array(
274
-            'all' => array(
275
-                'slug'        => 'all',
276
-                'label'       => esc_html__('All', 'event_espresso'),
277
-                'count'       => 0,
278
-                'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
279
-            ),
280
-        );
281
-    }
268
+	/**
269
+	 * Set views property for registration_checkins route.
270
+	 */
271
+	protected function _set_list_table_views_registration_checkins()
272
+	{
273
+		$this->_views = array(
274
+			'all' => array(
275
+				'slug'        => 'all',
276
+				'label'       => esc_html__('All', 'event_espresso'),
277
+				'count'       => 0,
278
+				'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
279
+			),
280
+		);
281
+	}
282 282
 
283 283
 
284
-    /**
285
-     * callback for ajax action.
286
-     *
287
-     * @since 4.3.0
288
-     * @return void (JSON)
289
-     * @throws EE_Error
290
-     * @throws InvalidArgumentException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     */
294
-    public function get_newsletter_form_content()
295
-    {
296
-        // do a nonce check cause we're not coming in from an normal route here.
297
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
298
-            $this->_req_data['get_newsletter_form_content_nonce']
299
-        ) : '';
300
-        $nonce_ref = 'get_newsletter_form_content_nonce';
301
-        $this->_verify_nonce($nonce, $nonce_ref);
302
-        // let's get the mtp for the incoming MTP_ ID
303
-        if (! isset($this->_req_data['GRP_ID'])) {
304
-            EE_Error::add_error(
305
-                esc_html__(
306
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
307
-                    'event_espresso'
308
-                ),
309
-                __FILE__,
310
-                __FUNCTION__,
311
-                __LINE__
312
-            );
313
-            $this->_template_args['success'] = false;
314
-            $this->_template_args['error'] = true;
315
-            $this->_return_json();
316
-        }
317
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
318
-        if (! $MTPG instanceof EE_Message_Template_Group) {
319
-            EE_Error::add_error(
320
-                sprintf(
321
-                    esc_html__(
322
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
323
-                        'event_espresso'
324
-                    ),
325
-                    $this->_req_data['GRP_ID']
326
-                ),
327
-                __FILE__,
328
-                __FUNCTION__,
329
-                __LINE__
330
-            );
331
-            $this->_template_args['success'] = false;
332
-            $this->_template_args['error'] = true;
333
-            $this->_return_json();
334
-        }
335
-        $MTPs = $MTPG->context_templates();
336
-        $MTPs = $MTPs['attendee'];
337
-        $template_fields = array();
338
-        /** @var EE_Message_Template $MTP */
339
-        foreach ($MTPs as $MTP) {
340
-            $field = $MTP->get('MTP_template_field');
341
-            if ($field === 'content') {
342
-                $content = $MTP->get('MTP_content');
343
-                if (! empty($content['newsletter_content'])) {
344
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
345
-                }
346
-                continue;
347
-            }
348
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
349
-        }
350
-        $this->_template_args['success'] = true;
351
-        $this->_template_args['error'] = false;
352
-        $this->_template_args['data'] = array(
353
-            'batch_message_from'    => isset($template_fields['from'])
354
-                ? $template_fields['from']
355
-                : '',
356
-            'batch_message_subject' => isset($template_fields['subject'])
357
-                ? $template_fields['subject']
358
-                : '',
359
-            'batch_message_content' => isset($template_fields['newsletter_content'])
360
-                ? $template_fields['newsletter_content']
361
-                : '',
362
-        );
363
-        $this->_return_json();
364
-    }
284
+	/**
285
+	 * callback for ajax action.
286
+	 *
287
+	 * @since 4.3.0
288
+	 * @return void (JSON)
289
+	 * @throws EE_Error
290
+	 * @throws InvalidArgumentException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 */
294
+	public function get_newsletter_form_content()
295
+	{
296
+		// do a nonce check cause we're not coming in from an normal route here.
297
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
298
+			$this->_req_data['get_newsletter_form_content_nonce']
299
+		) : '';
300
+		$nonce_ref = 'get_newsletter_form_content_nonce';
301
+		$this->_verify_nonce($nonce, $nonce_ref);
302
+		// let's get the mtp for the incoming MTP_ ID
303
+		if (! isset($this->_req_data['GRP_ID'])) {
304
+			EE_Error::add_error(
305
+				esc_html__(
306
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
307
+					'event_espresso'
308
+				),
309
+				__FILE__,
310
+				__FUNCTION__,
311
+				__LINE__
312
+			);
313
+			$this->_template_args['success'] = false;
314
+			$this->_template_args['error'] = true;
315
+			$this->_return_json();
316
+		}
317
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
318
+		if (! $MTPG instanceof EE_Message_Template_Group) {
319
+			EE_Error::add_error(
320
+				sprintf(
321
+					esc_html__(
322
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
323
+						'event_espresso'
324
+					),
325
+					$this->_req_data['GRP_ID']
326
+				),
327
+				__FILE__,
328
+				__FUNCTION__,
329
+				__LINE__
330
+			);
331
+			$this->_template_args['success'] = false;
332
+			$this->_template_args['error'] = true;
333
+			$this->_return_json();
334
+		}
335
+		$MTPs = $MTPG->context_templates();
336
+		$MTPs = $MTPs['attendee'];
337
+		$template_fields = array();
338
+		/** @var EE_Message_Template $MTP */
339
+		foreach ($MTPs as $MTP) {
340
+			$field = $MTP->get('MTP_template_field');
341
+			if ($field === 'content') {
342
+				$content = $MTP->get('MTP_content');
343
+				if (! empty($content['newsletter_content'])) {
344
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
345
+				}
346
+				continue;
347
+			}
348
+			$template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
349
+		}
350
+		$this->_template_args['success'] = true;
351
+		$this->_template_args['error'] = false;
352
+		$this->_template_args['data'] = array(
353
+			'batch_message_from'    => isset($template_fields['from'])
354
+				? $template_fields['from']
355
+				: '',
356
+			'batch_message_subject' => isset($template_fields['subject'])
357
+				? $template_fields['subject']
358
+				: '',
359
+			'batch_message_content' => isset($template_fields['newsletter_content'])
360
+				? $template_fields['newsletter_content']
361
+				: '',
362
+		);
363
+		$this->_return_json();
364
+	}
365 365
 
366 366
 
367
-    /**
368
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
369
-     *
370
-     * @since 4.3.0
371
-     * @param EE_Admin_List_Table $list_table
372
-     * @return void
373
-     * @throws InvalidArgumentException
374
-     * @throws InvalidDataTypeException
375
-     * @throws InvalidInterfaceException
376
-     */
377
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
378
-    {
379
-        if (! EE_Registry::instance()->CAP->current_user_can(
380
-            'ee_send_message',
381
-            'espresso_registrations_newsletter_selected_send'
382
-        )
383
-        ) {
384
-            return;
385
-        }
386
-        $routes_to_add_to = array(
387
-            'contact_list',
388
-            'event_registrations',
389
-            'default',
390
-        );
391
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
392
-            if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
393
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
394
-            ) {
395
-                echo '';
396
-            } else {
397
-                $button_text = sprintf(
398
-                    esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
399
-                    '<span class="send-selected-newsletter-count">0</span>'
400
-                );
401
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
402
-                     . '<span class="dashicons dashicons-email "></span>'
403
-                     . $button_text
404
-                     . '</button>';
405
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
406
-            }
407
-        }
408
-    }
367
+	/**
368
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
369
+	 *
370
+	 * @since 4.3.0
371
+	 * @param EE_Admin_List_Table $list_table
372
+	 * @return void
373
+	 * @throws InvalidArgumentException
374
+	 * @throws InvalidDataTypeException
375
+	 * @throws InvalidInterfaceException
376
+	 */
377
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
378
+	{
379
+		if (! EE_Registry::instance()->CAP->current_user_can(
380
+			'ee_send_message',
381
+			'espresso_registrations_newsletter_selected_send'
382
+		)
383
+		) {
384
+			return;
385
+		}
386
+		$routes_to_add_to = array(
387
+			'contact_list',
388
+			'event_registrations',
389
+			'default',
390
+		);
391
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
392
+			if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
393
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
394
+			) {
395
+				echo '';
396
+			} else {
397
+				$button_text = sprintf(
398
+					esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
399
+					'<span class="send-selected-newsletter-count">0</span>'
400
+				);
401
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
402
+					 . '<span class="dashicons dashicons-email "></span>'
403
+					 . $button_text
404
+					 . '</button>';
405
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
406
+			}
407
+		}
408
+	}
409 409
 
410 410
 
411
-    /**
412
-     * @throws DomainException
413
-     * @throws EE_Error
414
-     * @throws InvalidArgumentException
415
-     * @throws InvalidDataTypeException
416
-     * @throws InvalidInterfaceException
417
-     */
418
-    public function newsletter_send_form_skeleton()
419
-    {
420
-        $list_table = $this->_list_table_object;
421
-        $codes = array();
422
-        // need to templates for the newsletter message type for the template selector.
423
-        $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
424
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
425
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
426
-        );
427
-        foreach ($mtps as $mtp) {
428
-            $name = $mtp->name();
429
-            $values[] = array(
430
-                'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
431
-                'id'   => $mtp->ID(),
432
-            );
433
-        }
434
-        // need to get a list of shortcodes that are available for the newsletter message type.
435
-        $shortcodes = EEH_MSG_Template::get_shortcodes(
436
-            'newsletter',
437
-            'email',
438
-            array(),
439
-            'attendee',
440
-            false
441
-        );
442
-        foreach ($shortcodes as $field => $shortcode_array) {
443
-            $available_shortcodes = array();
444
-            foreach ($shortcode_array as $shortcode => $shortcode_details) {
445
-                $field_id = $field === '[NEWSLETTER_CONTENT]'
446
-                    ? 'content'
447
-                    : $field;
448
-                $field_id = 'batch-message-' . strtolower($field_id);
449
-                $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
450
-                                          . $shortcode
451
-                                          . '" data-linked-input-id="' . $field_id . '">'
452
-                                          . $shortcode
453
-                                          . '</span>';
454
-            }
455
-            $codes[ $field ] = implode(', ', $available_shortcodes);
456
-        }
457
-        $shortcodes = $codes;
458
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
459
-        $form_template_args = array(
460
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
461
-            'form_route'        => 'newsletter_selected_send',
462
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
463
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
464
-            'redirect_back_to'  => $this->_req_action,
465
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
466
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
467
-            'shortcodes'        => $shortcodes,
468
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
469
-        );
470
-        EEH_Template::display_template($form_template, $form_template_args);
471
-    }
411
+	/**
412
+	 * @throws DomainException
413
+	 * @throws EE_Error
414
+	 * @throws InvalidArgumentException
415
+	 * @throws InvalidDataTypeException
416
+	 * @throws InvalidInterfaceException
417
+	 */
418
+	public function newsletter_send_form_skeleton()
419
+	{
420
+		$list_table = $this->_list_table_object;
421
+		$codes = array();
422
+		// need to templates for the newsletter message type for the template selector.
423
+		$values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
424
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
425
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
426
+		);
427
+		foreach ($mtps as $mtp) {
428
+			$name = $mtp->name();
429
+			$values[] = array(
430
+				'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
431
+				'id'   => $mtp->ID(),
432
+			);
433
+		}
434
+		// need to get a list of shortcodes that are available for the newsletter message type.
435
+		$shortcodes = EEH_MSG_Template::get_shortcodes(
436
+			'newsletter',
437
+			'email',
438
+			array(),
439
+			'attendee',
440
+			false
441
+		);
442
+		foreach ($shortcodes as $field => $shortcode_array) {
443
+			$available_shortcodes = array();
444
+			foreach ($shortcode_array as $shortcode => $shortcode_details) {
445
+				$field_id = $field === '[NEWSLETTER_CONTENT]'
446
+					? 'content'
447
+					: $field;
448
+				$field_id = 'batch-message-' . strtolower($field_id);
449
+				$available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
450
+										  . $shortcode
451
+										  . '" data-linked-input-id="' . $field_id . '">'
452
+										  . $shortcode
453
+										  . '</span>';
454
+			}
455
+			$codes[ $field ] = implode(', ', $available_shortcodes);
456
+		}
457
+		$shortcodes = $codes;
458
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
459
+		$form_template_args = array(
460
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
461
+			'form_route'        => 'newsletter_selected_send',
462
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
463
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
464
+			'redirect_back_to'  => $this->_req_action,
465
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
466
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
467
+			'shortcodes'        => $shortcodes,
468
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
469
+		);
470
+		EEH_Template::display_template($form_template, $form_template_args);
471
+	}
472 472
 
473 473
 
474
-    /**
475
-     * Handles sending selected registrations/contacts a newsletter.
476
-     *
477
-     * @since  4.3.0
478
-     * @return void
479
-     * @throws EE_Error
480
-     * @throws InvalidArgumentException
481
-     * @throws InvalidDataTypeException
482
-     * @throws InvalidInterfaceException
483
-     */
484
-    protected function _newsletter_selected_send()
485
-    {
486
-        $success = true;
487
-        // first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
488
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
489
-            EE_Error::add_error(
490
-                esc_html__(
491
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
492
-                    'event_espresso'
493
-                ),
494
-                __FILE__,
495
-                __FUNCTION__,
496
-                __LINE__
497
-            );
498
-            $success = false;
499
-        }
500
-        if ($success) {
501
-            // update Message template in case there are any changes
502
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
503
-                $this->_req_data['newsletter_mtp_selected']
504
-            );
505
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
506
-                ? $Message_Template_Group->context_templates()
507
-                : array();
508
-            if (empty($Message_Templates)) {
509
-                EE_Error::add_error(
510
-                    esc_html__(
511
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
512
-                        'event_espresso'
513
-                    ),
514
-                    __FILE__,
515
-                    __FUNCTION__,
516
-                    __LINE__
517
-                );
518
-            }
519
-            // let's just update the specific fields
520
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
521
-                if ($Message_Template instanceof EE_Message_Template) {
522
-                    $field = $Message_Template->get('MTP_template_field');
523
-                    $content = $Message_Template->get('MTP_content');
524
-                    $new_content = $content;
525
-                    switch ($field) {
526
-                        case 'from':
527
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
528
-                                ? $this->_req_data['batch_message']['from']
529
-                                : $content;
530
-                            break;
531
-                        case 'subject':
532
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
533
-                                ? $this->_req_data['batch_message']['subject']
534
-                                : $content;
535
-                            break;
536
-                        case 'content':
537
-                            $new_content = $content;
538
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
539
-                                ? $this->_req_data['batch_message']['content']
540
-                                : $content['newsletter_content'];
541
-                            break;
542
-                        default:
543
-                            // continue the foreach loop, we don't want to set $new_content nor save.
544
-                            continue 2;
545
-                    }
546
-                    $Message_Template->set('MTP_content', $new_content);
547
-                    $Message_Template->save();
548
-                }
549
-            }
550
-            // great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
551
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
552
-                ? $this->_req_data['batch_message']['id_type']
553
-                : 'registration';
554
-            // id_type will affect how we assemble the ids.
555
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
556
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
557
-                : array();
558
-            $registrations_used_for_contact_data = array();
559
-            // using switch because eventually we'll have other contexts that will be used for generating messages.
560
-            switch ($id_type) {
561
-                case 'registration':
562
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
563
-                        array(
564
-                            array(
565
-                                'REG_ID' => array('IN', $ids),
566
-                            ),
567
-                        )
568
-                    );
569
-                    break;
570
-                case 'contact':
571
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
572
-                                                                           ->get_latest_registration_for_each_of_given_contacts(
573
-                                                                               $ids
574
-                                                                           );
575
-                    break;
576
-            }
577
-            do_action_ref_array(
578
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
579
-                array(
580
-                    $registrations_used_for_contact_data,
581
-                    $Message_Template_Group->ID(),
582
-                )
583
-            );
584
-            // kept for backward compat, internally we no longer use this action.
585
-            // @deprecated 4.8.36.rc.002
586
-            $contacts = $id_type === 'registration'
587
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
588
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
589
-            do_action_ref_array(
590
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
591
-                array(
592
-                    $contacts,
593
-                    $Message_Template_Group->ID(),
594
-                )
595
-            );
596
-        }
597
-        $query_args = array(
598
-            'action' => ! empty($this->_req_data['redirect_back_to'])
599
-                ? $this->_req_data['redirect_back_to']
600
-                : 'default',
601
-        );
602
-        $this->_redirect_after_action(false, '', '', $query_args, true);
603
-    }
474
+	/**
475
+	 * Handles sending selected registrations/contacts a newsletter.
476
+	 *
477
+	 * @since  4.3.0
478
+	 * @return void
479
+	 * @throws EE_Error
480
+	 * @throws InvalidArgumentException
481
+	 * @throws InvalidDataTypeException
482
+	 * @throws InvalidInterfaceException
483
+	 */
484
+	protected function _newsletter_selected_send()
485
+	{
486
+		$success = true;
487
+		// first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
488
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
489
+			EE_Error::add_error(
490
+				esc_html__(
491
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
492
+					'event_espresso'
493
+				),
494
+				__FILE__,
495
+				__FUNCTION__,
496
+				__LINE__
497
+			);
498
+			$success = false;
499
+		}
500
+		if ($success) {
501
+			// update Message template in case there are any changes
502
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
503
+				$this->_req_data['newsletter_mtp_selected']
504
+			);
505
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
506
+				? $Message_Template_Group->context_templates()
507
+				: array();
508
+			if (empty($Message_Templates)) {
509
+				EE_Error::add_error(
510
+					esc_html__(
511
+						'Unable to retrieve message template fields from the db. Messages not sent.',
512
+						'event_espresso'
513
+					),
514
+					__FILE__,
515
+					__FUNCTION__,
516
+					__LINE__
517
+				);
518
+			}
519
+			// let's just update the specific fields
520
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
521
+				if ($Message_Template instanceof EE_Message_Template) {
522
+					$field = $Message_Template->get('MTP_template_field');
523
+					$content = $Message_Template->get('MTP_content');
524
+					$new_content = $content;
525
+					switch ($field) {
526
+						case 'from':
527
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
528
+								? $this->_req_data['batch_message']['from']
529
+								: $content;
530
+							break;
531
+						case 'subject':
532
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
533
+								? $this->_req_data['batch_message']['subject']
534
+								: $content;
535
+							break;
536
+						case 'content':
537
+							$new_content = $content;
538
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
539
+								? $this->_req_data['batch_message']['content']
540
+								: $content['newsletter_content'];
541
+							break;
542
+						default:
543
+							// continue the foreach loop, we don't want to set $new_content nor save.
544
+							continue 2;
545
+					}
546
+					$Message_Template->set('MTP_content', $new_content);
547
+					$Message_Template->save();
548
+				}
549
+			}
550
+			// great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
551
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
552
+				? $this->_req_data['batch_message']['id_type']
553
+				: 'registration';
554
+			// id_type will affect how we assemble the ids.
555
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
556
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
557
+				: array();
558
+			$registrations_used_for_contact_data = array();
559
+			// using switch because eventually we'll have other contexts that will be used for generating messages.
560
+			switch ($id_type) {
561
+				case 'registration':
562
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
563
+						array(
564
+							array(
565
+								'REG_ID' => array('IN', $ids),
566
+							),
567
+						)
568
+					);
569
+					break;
570
+				case 'contact':
571
+					$registrations_used_for_contact_data = EEM_Registration::instance()
572
+																		   ->get_latest_registration_for_each_of_given_contacts(
573
+																			   $ids
574
+																		   );
575
+					break;
576
+			}
577
+			do_action_ref_array(
578
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
579
+				array(
580
+					$registrations_used_for_contact_data,
581
+					$Message_Template_Group->ID(),
582
+				)
583
+			);
584
+			// kept for backward compat, internally we no longer use this action.
585
+			// @deprecated 4.8.36.rc.002
586
+			$contacts = $id_type === 'registration'
587
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
588
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
589
+			do_action_ref_array(
590
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
591
+				array(
592
+					$contacts,
593
+					$Message_Template_Group->ID(),
594
+				)
595
+			);
596
+		}
597
+		$query_args = array(
598
+			'action' => ! empty($this->_req_data['redirect_back_to'])
599
+				? $this->_req_data['redirect_back_to']
600
+				: 'default',
601
+		);
602
+		$this->_redirect_after_action(false, '', '', $query_args, true);
603
+	}
604 604
 
605 605
 
606
-    /**
607
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
608
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
609
-     */
610
-    protected function _registration_reports_js_setup()
611
-    {
612
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
613
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
614
-    }
606
+	/**
607
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
608
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
609
+	 */
610
+	protected function _registration_reports_js_setup()
611
+	{
612
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
613
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
614
+	}
615 615
 
616 616
 
617
-    /**
618
-     *        generates Business Reports regarding Registrations
619
-     *
620
-     * @access protected
621
-     * @return void
622
-     * @throws DomainException
623
-     */
624
-    protected function _registration_reports()
625
-    {
626
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
627
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
628
-            $template_path,
629
-            $this->_reports_template_data,
630
-            true
631
-        );
632
-        // the final template wrapper
633
-        $this->display_admin_page_with_no_sidebar();
634
-    }
617
+	/**
618
+	 *        generates Business Reports regarding Registrations
619
+	 *
620
+	 * @access protected
621
+	 * @return void
622
+	 * @throws DomainException
623
+	 */
624
+	protected function _registration_reports()
625
+	{
626
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
627
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
628
+			$template_path,
629
+			$this->_reports_template_data,
630
+			true
631
+		);
632
+		// the final template wrapper
633
+		$this->display_admin_page_with_no_sidebar();
634
+	}
635 635
 
636 636
 
637
-    /**
638
-     * Generates Business Report showing total registrations per day.
639
-     *
640
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
641
-     * @return string
642
-     * @throws EE_Error
643
-     * @throws InvalidArgumentException
644
-     * @throws InvalidDataTypeException
645
-     * @throws InvalidInterfaceException
646
-     */
647
-    private function _registrations_per_day_report($period = '-1 month')
648
-    {
649
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
650
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
651
-        $results = (array) $results;
652
-        $regs = array();
653
-        $subtitle = '';
654
-        if ($results) {
655
-            $column_titles = array();
656
-            $tracker = 0;
657
-            foreach ($results as $result) {
658
-                $report_column_values = array();
659
-                foreach ($result as $property_name => $property_value) {
660
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
661
-                        : (int) $property_value;
662
-                    $report_column_values[] = $property_value;
663
-                    if ($tracker === 0) {
664
-                        if ($property_name === 'Registration_REG_date') {
665
-                            $column_titles[] = esc_html__(
666
-                                'Date (only days with registrations are shown)',
667
-                                'event_espresso'
668
-                            );
669
-                        } else {
670
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
671
-                        }
672
-                    }
673
-                }
674
-                $tracker++;
675
-                $regs[] = $report_column_values;
676
-            }
677
-            // make sure the column_titles is pushed to the beginning of the array
678
-            array_unshift($regs, $column_titles);
679
-            // setup the date range.
680
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
681
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
682
-            $ending_date = new DateTime("now", $DateTimeZone);
683
-            $subtitle = sprintf(
684
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
685
-                $beginning_date->format('Y-m-d'),
686
-                $ending_date->format('Y-m-d')
687
-            );
688
-        }
689
-        $report_title = esc_html__('Total Registrations per Day', 'event_espresso');
690
-        $report_params = array(
691
-            'title'     => $report_title,
692
-            'subtitle'  => $subtitle,
693
-            'id'        => $report_ID,
694
-            'regs'      => $regs,
695
-            'noResults' => empty($regs),
696
-            'noRegsMsg' => sprintf(
697
-                esc_html__(
698
-                    '%sThere are currently no registration records in the last month for this report.%s',
699
-                    'event_espresso'
700
-                ),
701
-                '<h2>' . $report_title . '</h2><p>',
702
-                '</p>'
703
-            ),
704
-        );
705
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
706
-        return $report_ID;
707
-    }
637
+	/**
638
+	 * Generates Business Report showing total registrations per day.
639
+	 *
640
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
641
+	 * @return string
642
+	 * @throws EE_Error
643
+	 * @throws InvalidArgumentException
644
+	 * @throws InvalidDataTypeException
645
+	 * @throws InvalidInterfaceException
646
+	 */
647
+	private function _registrations_per_day_report($period = '-1 month')
648
+	{
649
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
650
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
651
+		$results = (array) $results;
652
+		$regs = array();
653
+		$subtitle = '';
654
+		if ($results) {
655
+			$column_titles = array();
656
+			$tracker = 0;
657
+			foreach ($results as $result) {
658
+				$report_column_values = array();
659
+				foreach ($result as $property_name => $property_value) {
660
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
661
+						: (int) $property_value;
662
+					$report_column_values[] = $property_value;
663
+					if ($tracker === 0) {
664
+						if ($property_name === 'Registration_REG_date') {
665
+							$column_titles[] = esc_html__(
666
+								'Date (only days with registrations are shown)',
667
+								'event_espresso'
668
+							);
669
+						} else {
670
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
671
+						}
672
+					}
673
+				}
674
+				$tracker++;
675
+				$regs[] = $report_column_values;
676
+			}
677
+			// make sure the column_titles is pushed to the beginning of the array
678
+			array_unshift($regs, $column_titles);
679
+			// setup the date range.
680
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
681
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
682
+			$ending_date = new DateTime("now", $DateTimeZone);
683
+			$subtitle = sprintf(
684
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
685
+				$beginning_date->format('Y-m-d'),
686
+				$ending_date->format('Y-m-d')
687
+			);
688
+		}
689
+		$report_title = esc_html__('Total Registrations per Day', 'event_espresso');
690
+		$report_params = array(
691
+			'title'     => $report_title,
692
+			'subtitle'  => $subtitle,
693
+			'id'        => $report_ID,
694
+			'regs'      => $regs,
695
+			'noResults' => empty($regs),
696
+			'noRegsMsg' => sprintf(
697
+				esc_html__(
698
+					'%sThere are currently no registration records in the last month for this report.%s',
699
+					'event_espresso'
700
+				),
701
+				'<h2>' . $report_title . '</h2><p>',
702
+				'</p>'
703
+			),
704
+		);
705
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
706
+		return $report_ID;
707
+	}
708 708
 
709 709
 
710
-    /**
711
-     * Generates Business Report showing total registrations per event.
712
-     *
713
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
714
-     * @return string
715
-     * @throws EE_Error
716
-     * @throws InvalidArgumentException
717
-     * @throws InvalidDataTypeException
718
-     * @throws InvalidInterfaceException
719
-     */
720
-    private function _registrations_per_event_report($period = '-1 month')
721
-    {
722
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
723
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
724
-        $results = (array) $results;
725
-        $regs = array();
726
-        $subtitle = '';
727
-        if ($results) {
728
-            $column_titles = array();
729
-            $tracker = 0;
730
-            foreach ($results as $result) {
731
-                $report_column_values = array();
732
-                foreach ($result as $property_name => $property_value) {
733
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
734
-                        $property_value,
735
-                        4,
736
-                        '...'
737
-                    ) : (int) $property_value;
738
-                    $report_column_values[] = $property_value;
739
-                    if ($tracker === 0) {
740
-                        if ($property_name === 'Registration_Event') {
741
-                            $column_titles[] = esc_html__('Event', 'event_espresso');
742
-                        } else {
743
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
744
-                        }
745
-                    }
746
-                }
747
-                $tracker++;
748
-                $regs[] = $report_column_values;
749
-            }
750
-            // make sure the column_titles is pushed to the beginning of the array
751
-            array_unshift($regs, $column_titles);
752
-            // setup the date range.
753
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
754
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
755
-            $ending_date = new DateTime("now", $DateTimeZone);
756
-            $subtitle = sprintf(
757
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
758
-                $beginning_date->format('Y-m-d'),
759
-                $ending_date->format('Y-m-d')
760
-            );
761
-        }
762
-        $report_title = esc_html__('Total Registrations per Event', 'event_espresso');
763
-        $report_params = array(
764
-            'title'     => $report_title,
765
-            'subtitle'  => $subtitle,
766
-            'id'        => $report_ID,
767
-            'regs'      => $regs,
768
-            'noResults' => empty($regs),
769
-            'noRegsMsg' => sprintf(
770
-                esc_html__(
771
-                    '%sThere are currently no registration records in the last month for this report.%s',
772
-                    'event_espresso'
773
-                ),
774
-                '<h2>' . $report_title . '</h2><p>',
775
-                '</p>'
776
-            ),
777
-        );
778
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
779
-        return $report_ID;
780
-    }
710
+	/**
711
+	 * Generates Business Report showing total registrations per event.
712
+	 *
713
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
714
+	 * @return string
715
+	 * @throws EE_Error
716
+	 * @throws InvalidArgumentException
717
+	 * @throws InvalidDataTypeException
718
+	 * @throws InvalidInterfaceException
719
+	 */
720
+	private function _registrations_per_event_report($period = '-1 month')
721
+	{
722
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
723
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
724
+		$results = (array) $results;
725
+		$regs = array();
726
+		$subtitle = '';
727
+		if ($results) {
728
+			$column_titles = array();
729
+			$tracker = 0;
730
+			foreach ($results as $result) {
731
+				$report_column_values = array();
732
+				foreach ($result as $property_name => $property_value) {
733
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
734
+						$property_value,
735
+						4,
736
+						'...'
737
+					) : (int) $property_value;
738
+					$report_column_values[] = $property_value;
739
+					if ($tracker === 0) {
740
+						if ($property_name === 'Registration_Event') {
741
+							$column_titles[] = esc_html__('Event', 'event_espresso');
742
+						} else {
743
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
744
+						}
745
+					}
746
+				}
747
+				$tracker++;
748
+				$regs[] = $report_column_values;
749
+			}
750
+			// make sure the column_titles is pushed to the beginning of the array
751
+			array_unshift($regs, $column_titles);
752
+			// setup the date range.
753
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
754
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
755
+			$ending_date = new DateTime("now", $DateTimeZone);
756
+			$subtitle = sprintf(
757
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
758
+				$beginning_date->format('Y-m-d'),
759
+				$ending_date->format('Y-m-d')
760
+			);
761
+		}
762
+		$report_title = esc_html__('Total Registrations per Event', 'event_espresso');
763
+		$report_params = array(
764
+			'title'     => $report_title,
765
+			'subtitle'  => $subtitle,
766
+			'id'        => $report_ID,
767
+			'regs'      => $regs,
768
+			'noResults' => empty($regs),
769
+			'noRegsMsg' => sprintf(
770
+				esc_html__(
771
+					'%sThere are currently no registration records in the last month for this report.%s',
772
+					'event_espresso'
773
+				),
774
+				'<h2>' . $report_title . '</h2><p>',
775
+				'</p>'
776
+			),
777
+		);
778
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
779
+		return $report_ID;
780
+	}
781 781
 
782 782
 
783
-    /**
784
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
785
-     *
786
-     * @access protected
787
-     * @return void
788
-     * @throws EE_Error
789
-     * @throws InvalidArgumentException
790
-     * @throws InvalidDataTypeException
791
-     * @throws InvalidInterfaceException
792
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
793
-     */
794
-    protected function _registration_checkin_list_table()
795
-    {
796
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
797
-        $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
798
-        /** @var EE_Registration $registration */
799
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
800
-        if (! $registration instanceof EE_Registration) {
801
-            throw new EE_Error(
802
-                sprintf(
803
-                    esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
804
-                    $reg_id
805
-                )
806
-            );
807
-        }
808
-        $attendee = $registration->attendee();
809
-        $this->_admin_page_title .= $this->get_action_link_or_button(
810
-            'new_registration',
811
-            'add-registrant',
812
-            array('event_id' => $registration->event_ID()),
813
-            'add-new-h2'
814
-        );
815
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
816
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
817
-        $legend_items = array(
818
-            'checkin'  => array(
819
-                'class' => $checked_in->cssClasses(),
820
-                'desc'  => $checked_in->legendLabel(),
821
-            ),
822
-            'checkout' => array(
823
-                'class' => $checked_out->cssClasses(),
824
-                'desc'  => $checked_out->legendLabel(),
825
-            ),
826
-        );
827
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
828
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
829
-        /** @var EE_Datetime $datetime */
830
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
831
-        $datetime_label = '';
832
-        if ($datetime instanceof EE_Datetime) {
833
-            $datetime_label = $datetime->get_dtt_display_name(true);
834
-            $datetime_label .= ! empty($datetime_label)
835
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
836
-                : $datetime->get_dtt_display_name();
837
-        }
838
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
839
-            ? EE_Admin_Page::add_query_args_and_nonce(
840
-                array(
841
-                    'action'   => 'event_registrations',
842
-                    'event_id' => $registration->event_ID(),
843
-                    'DTT_ID'   => $dtt_id,
844
-                ),
845
-                $this->_admin_base_url
846
-            )
847
-            : '';
848
-        $datetime_link = ! empty($datetime_link)
849
-            ? '<a href="' . $datetime_link . '">'
850
-              . '<span id="checkin-dtt">'
851
-              . $datetime_label
852
-              . '</span></a>'
853
-            : $datetime_label;
854
-        $attendee_name = $attendee instanceof EE_Attendee
855
-            ? $attendee->full_name()
856
-            : '';
857
-        $attendee_link = $attendee instanceof EE_Attendee
858
-            ? $attendee->get_admin_details_link()
859
-            : '';
860
-        $attendee_link = ! empty($attendee_link)
861
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
862
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
863
-              . '<span id="checkin-attendee-name">'
864
-              . $attendee_name
865
-              . '</span></a>'
866
-            : '';
867
-        $event_link = $registration->event() instanceof EE_Event
868
-            ? $registration->event()->get_admin_details_link()
869
-            : '';
870
-        $event_link = ! empty($event_link)
871
-            ? '<a href="' . $event_link . '"'
872
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
873
-              . '<span id="checkin-event-name">'
874
-              . $registration->event_name()
875
-              . '</span>'
876
-              . '</a>'
877
-            : '';
878
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
879
-            ? '<h2>' . sprintf(
880
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
881
-                $attendee_link,
882
-                $datetime_link,
883
-                $event_link
884
-            ) . '</h2>'
885
-            : '';
886
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
887
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
888
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
889
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
890
-        $this->display_admin_list_table_page_with_no_sidebar();
891
-    }
783
+	/**
784
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
785
+	 *
786
+	 * @access protected
787
+	 * @return void
788
+	 * @throws EE_Error
789
+	 * @throws InvalidArgumentException
790
+	 * @throws InvalidDataTypeException
791
+	 * @throws InvalidInterfaceException
792
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
793
+	 */
794
+	protected function _registration_checkin_list_table()
795
+	{
796
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
797
+		$reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
798
+		/** @var EE_Registration $registration */
799
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
800
+		if (! $registration instanceof EE_Registration) {
801
+			throw new EE_Error(
802
+				sprintf(
803
+					esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
804
+					$reg_id
805
+				)
806
+			);
807
+		}
808
+		$attendee = $registration->attendee();
809
+		$this->_admin_page_title .= $this->get_action_link_or_button(
810
+			'new_registration',
811
+			'add-registrant',
812
+			array('event_id' => $registration->event_ID()),
813
+			'add-new-h2'
814
+		);
815
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
816
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
817
+		$legend_items = array(
818
+			'checkin'  => array(
819
+				'class' => $checked_in->cssClasses(),
820
+				'desc'  => $checked_in->legendLabel(),
821
+			),
822
+			'checkout' => array(
823
+				'class' => $checked_out->cssClasses(),
824
+				'desc'  => $checked_out->legendLabel(),
825
+			),
826
+		);
827
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
828
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
829
+		/** @var EE_Datetime $datetime */
830
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
831
+		$datetime_label = '';
832
+		if ($datetime instanceof EE_Datetime) {
833
+			$datetime_label = $datetime->get_dtt_display_name(true);
834
+			$datetime_label .= ! empty($datetime_label)
835
+				? ' (' . $datetime->get_dtt_display_name() . ')'
836
+				: $datetime->get_dtt_display_name();
837
+		}
838
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
839
+			? EE_Admin_Page::add_query_args_and_nonce(
840
+				array(
841
+					'action'   => 'event_registrations',
842
+					'event_id' => $registration->event_ID(),
843
+					'DTT_ID'   => $dtt_id,
844
+				),
845
+				$this->_admin_base_url
846
+			)
847
+			: '';
848
+		$datetime_link = ! empty($datetime_link)
849
+			? '<a href="' . $datetime_link . '">'
850
+			  . '<span id="checkin-dtt">'
851
+			  . $datetime_label
852
+			  . '</span></a>'
853
+			: $datetime_label;
854
+		$attendee_name = $attendee instanceof EE_Attendee
855
+			? $attendee->full_name()
856
+			: '';
857
+		$attendee_link = $attendee instanceof EE_Attendee
858
+			? $attendee->get_admin_details_link()
859
+			: '';
860
+		$attendee_link = ! empty($attendee_link)
861
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
862
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
863
+			  . '<span id="checkin-attendee-name">'
864
+			  . $attendee_name
865
+			  . '</span></a>'
866
+			: '';
867
+		$event_link = $registration->event() instanceof EE_Event
868
+			? $registration->event()->get_admin_details_link()
869
+			: '';
870
+		$event_link = ! empty($event_link)
871
+			? '<a href="' . $event_link . '"'
872
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
873
+			  . '<span id="checkin-event-name">'
874
+			  . $registration->event_name()
875
+			  . '</span>'
876
+			  . '</a>'
877
+			: '';
878
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
879
+			? '<h2>' . sprintf(
880
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
881
+				$attendee_link,
882
+				$datetime_link,
883
+				$event_link
884
+			) . '</h2>'
885
+			: '';
886
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
887
+			? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
888
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
889
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
890
+		$this->display_admin_list_table_page_with_no_sidebar();
891
+	}
892 892
 
893 893
 
894
-    /**
895
-     * toggle the Check-in status for the given registration (coming from ajax)
896
-     *
897
-     * @return void (JSON)
898
-     * @throws EE_Error
899
-     * @throws InvalidArgumentException
900
-     * @throws InvalidDataTypeException
901
-     * @throws InvalidInterfaceException
902
-     */
903
-    public function toggle_checkin_status()
904
-    {
905
-        // first make sure we have the necessary data
906
-        if (! isset($this->_req_data['_regid'])) {
907
-            EE_Error::add_error(
908
-                esc_html__(
909
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
910
-                    'event_espresso'
911
-                ),
912
-                __FILE__,
913
-                __FUNCTION__,
914
-                __LINE__
915
-            );
916
-            $this->_template_args['success'] = false;
917
-            $this->_template_args['error'] = true;
918
-            $this->_return_json();
919
-        };
920
-        // do a nonce check cause we're not coming in from an normal route here.
921
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
922
-            : '';
923
-        $nonce_ref = 'checkin_nonce';
924
-        $this->_verify_nonce($nonce, $nonce_ref);
925
-        // beautiful! Made it this far so let's get the status.
926
-        $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
927
-        // setup new class to return via ajax
928
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
929
-        $this->_template_args['success'] = true;
930
-        $this->_return_json();
931
-    }
894
+	/**
895
+	 * toggle the Check-in status for the given registration (coming from ajax)
896
+	 *
897
+	 * @return void (JSON)
898
+	 * @throws EE_Error
899
+	 * @throws InvalidArgumentException
900
+	 * @throws InvalidDataTypeException
901
+	 * @throws InvalidInterfaceException
902
+	 */
903
+	public function toggle_checkin_status()
904
+	{
905
+		// first make sure we have the necessary data
906
+		if (! isset($this->_req_data['_regid'])) {
907
+			EE_Error::add_error(
908
+				esc_html__(
909
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
910
+					'event_espresso'
911
+				),
912
+				__FILE__,
913
+				__FUNCTION__,
914
+				__LINE__
915
+			);
916
+			$this->_template_args['success'] = false;
917
+			$this->_template_args['error'] = true;
918
+			$this->_return_json();
919
+		};
920
+		// do a nonce check cause we're not coming in from an normal route here.
921
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
922
+			: '';
923
+		$nonce_ref = 'checkin_nonce';
924
+		$this->_verify_nonce($nonce, $nonce_ref);
925
+		// beautiful! Made it this far so let's get the status.
926
+		$new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
927
+		// setup new class to return via ajax
928
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
929
+		$this->_template_args['success'] = true;
930
+		$this->_return_json();
931
+	}
932 932
 
933 933
 
934
-    /**
935
-     * handles toggling the checkin status for the registration,
936
-     *
937
-     * @access protected
938
-     * @return int|void
939
-     * @throws EE_Error
940
-     * @throws InvalidArgumentException
941
-     * @throws InvalidDataTypeException
942
-     * @throws InvalidInterfaceException
943
-     */
944
-    protected function _toggle_checkin_status()
945
-    {
946
-        // first let's get the query args out of the way for the redirect
947
-        $query_args = array(
948
-            'action'   => 'event_registrations',
949
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
950
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
951
-        );
952
-        $new_status = false;
953
-        // bulk action check in toggle
954
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
955
-            // cycle thru checkboxes
956
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
957
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
958
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
959
-            }
960
-        } elseif (isset($this->_req_data['_regid'])) {
961
-            // coming from ajax request
962
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
963
-            $query_args['DTT_ID'] = $DTT_ID;
964
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
965
-        } else {
966
-            EE_Error::add_error(
967
-                esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
968
-                __FILE__,
969
-                __FUNCTION__,
970
-                __LINE__
971
-            );
972
-        }
973
-        if (defined('DOING_AJAX')) {
974
-            return $new_status;
975
-        }
976
-        $this->_redirect_after_action(false, '', '', $query_args, true);
977
-    }
934
+	/**
935
+	 * handles toggling the checkin status for the registration,
936
+	 *
937
+	 * @access protected
938
+	 * @return int|void
939
+	 * @throws EE_Error
940
+	 * @throws InvalidArgumentException
941
+	 * @throws InvalidDataTypeException
942
+	 * @throws InvalidInterfaceException
943
+	 */
944
+	protected function _toggle_checkin_status()
945
+	{
946
+		// first let's get the query args out of the way for the redirect
947
+		$query_args = array(
948
+			'action'   => 'event_registrations',
949
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
950
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
951
+		);
952
+		$new_status = false;
953
+		// bulk action check in toggle
954
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
955
+			// cycle thru checkboxes
956
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
957
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
958
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
959
+			}
960
+		} elseif (isset($this->_req_data['_regid'])) {
961
+			// coming from ajax request
962
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
963
+			$query_args['DTT_ID'] = $DTT_ID;
964
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
965
+		} else {
966
+			EE_Error::add_error(
967
+				esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
968
+				__FILE__,
969
+				__FUNCTION__,
970
+				__LINE__
971
+			);
972
+		}
973
+		if (defined('DOING_AJAX')) {
974
+			return $new_status;
975
+		}
976
+		$this->_redirect_after_action(false, '', '', $query_args, true);
977
+	}
978 978
 
979 979
 
980
-    /**
981
-     * This is toggles a single Check-in for the given registration and datetime.
982
-     *
983
-     * @param  int $REG_ID The registration we're toggling
984
-     * @param  int $DTT_ID The datetime we're toggling
985
-     * @return int The new status toggled to.
986
-     * @throws EE_Error
987
-     * @throws InvalidArgumentException
988
-     * @throws InvalidDataTypeException
989
-     * @throws InvalidInterfaceException
990
-     */
991
-    private function _toggle_checkin($REG_ID, $DTT_ID)
992
-    {
993
-        /** @var EE_Registration $REG */
994
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
995
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
996
-        if ($new_status !== false) {
997
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
998
-        } else {
999
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
1000
-            $new_status = false;
1001
-        }
1002
-        return $new_status;
1003
-    }
980
+	/**
981
+	 * This is toggles a single Check-in for the given registration and datetime.
982
+	 *
983
+	 * @param  int $REG_ID The registration we're toggling
984
+	 * @param  int $DTT_ID The datetime we're toggling
985
+	 * @return int The new status toggled to.
986
+	 * @throws EE_Error
987
+	 * @throws InvalidArgumentException
988
+	 * @throws InvalidDataTypeException
989
+	 * @throws InvalidInterfaceException
990
+	 */
991
+	private function _toggle_checkin($REG_ID, $DTT_ID)
992
+	{
993
+		/** @var EE_Registration $REG */
994
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
995
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
996
+		if ($new_status !== false) {
997
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
998
+		} else {
999
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
1000
+			$new_status = false;
1001
+		}
1002
+		return $new_status;
1003
+	}
1004 1004
 
1005 1005
 
1006
-    /**
1007
-     * Takes care of deleting multiple EE_Checkin table rows
1008
-     *
1009
-     * @access protected
1010
-     * @return void
1011
-     * @throws EE_Error
1012
-     * @throws InvalidArgumentException
1013
-     * @throws InvalidDataTypeException
1014
-     * @throws InvalidInterfaceException
1015
-     */
1016
-    protected function _delete_checkin_rows()
1017
-    {
1018
-        $query_args = array(
1019
-            'action'  => 'registration_checkins',
1020
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1021
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1022
-        );
1023
-        $errors = 0;
1024
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1025
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1026
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1027
-                    $errors++;
1028
-                }
1029
-            }
1030
-        } else {
1031
-            EE_Error::add_error(
1032
-                esc_html__(
1033
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1034
-                    'event_espresso'
1035
-                ),
1036
-                __FILE__,
1037
-                __FUNCTION__,
1038
-                __LINE__
1039
-            );
1040
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1041
-        }
1042
-        if ($errors > 0) {
1043
-            EE_Error::add_error(
1044
-                sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1045
-                __FILE__,
1046
-                __FUNCTION__,
1047
-                __LINE__
1048
-            );
1049
-        } else {
1050
-            EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1051
-        }
1052
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1053
-    }
1006
+	/**
1007
+	 * Takes care of deleting multiple EE_Checkin table rows
1008
+	 *
1009
+	 * @access protected
1010
+	 * @return void
1011
+	 * @throws EE_Error
1012
+	 * @throws InvalidArgumentException
1013
+	 * @throws InvalidDataTypeException
1014
+	 * @throws InvalidInterfaceException
1015
+	 */
1016
+	protected function _delete_checkin_rows()
1017
+	{
1018
+		$query_args = array(
1019
+			'action'  => 'registration_checkins',
1020
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1021
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1022
+		);
1023
+		$errors = 0;
1024
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1025
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1026
+				if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1027
+					$errors++;
1028
+				}
1029
+			}
1030
+		} else {
1031
+			EE_Error::add_error(
1032
+				esc_html__(
1033
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1034
+					'event_espresso'
1035
+				),
1036
+				__FILE__,
1037
+				__FUNCTION__,
1038
+				__LINE__
1039
+			);
1040
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1041
+		}
1042
+		if ($errors > 0) {
1043
+			EE_Error::add_error(
1044
+				sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1045
+				__FILE__,
1046
+				__FUNCTION__,
1047
+				__LINE__
1048
+			);
1049
+		} else {
1050
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1051
+		}
1052
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1053
+	}
1054 1054
 
1055 1055
 
1056
-    /**
1057
-     * Deletes a single EE_Checkin row
1058
-     *
1059
-     * @return void
1060
-     * @throws EE_Error
1061
-     * @throws InvalidArgumentException
1062
-     * @throws InvalidDataTypeException
1063
-     * @throws InvalidInterfaceException
1064
-     */
1065
-    protected function _delete_checkin_row()
1066
-    {
1067
-        $query_args = array(
1068
-            'action'  => 'registration_checkins',
1069
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1070
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1071
-        );
1072
-        if (! empty($this->_req_data['CHK_ID'])) {
1073
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1074
-                EE_Error::add_error(
1075
-                    esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1076
-                    __FILE__,
1077
-                    __FUNCTION__,
1078
-                    __LINE__
1079
-                );
1080
-            } else {
1081
-                EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1082
-            }
1083
-        } else {
1084
-            EE_Error::add_error(
1085
-                esc_html__(
1086
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1087
-                    'event_espresso'
1088
-                ),
1089
-                __FILE__,
1090
-                __FUNCTION__,
1091
-                __LINE__
1092
-            );
1093
-        }
1094
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1095
-    }
1056
+	/**
1057
+	 * Deletes a single EE_Checkin row
1058
+	 *
1059
+	 * @return void
1060
+	 * @throws EE_Error
1061
+	 * @throws InvalidArgumentException
1062
+	 * @throws InvalidDataTypeException
1063
+	 * @throws InvalidInterfaceException
1064
+	 */
1065
+	protected function _delete_checkin_row()
1066
+	{
1067
+		$query_args = array(
1068
+			'action'  => 'registration_checkins',
1069
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1070
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1071
+		);
1072
+		if (! empty($this->_req_data['CHK_ID'])) {
1073
+			if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1074
+				EE_Error::add_error(
1075
+					esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1076
+					__FILE__,
1077
+					__FUNCTION__,
1078
+					__LINE__
1079
+				);
1080
+			} else {
1081
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1082
+			}
1083
+		} else {
1084
+			EE_Error::add_error(
1085
+				esc_html__(
1086
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1087
+					'event_espresso'
1088
+				),
1089
+				__FILE__,
1090
+				__FUNCTION__,
1091
+				__LINE__
1092
+			);
1093
+		}
1094
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1095
+	}
1096 1096
 
1097 1097
 
1098
-    /**
1099
-     *        generates HTML for the Event Registrations List Table
1100
-     *
1101
-     * @access protected
1102
-     * @return void
1103
-     * @throws EE_Error
1104
-     * @throws InvalidArgumentException
1105
-     * @throws InvalidDataTypeException
1106
-     * @throws InvalidInterfaceException
1107
-     */
1108
-    protected function _event_registrations_list_table()
1109
-    {
1110
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1111
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1112
-            ? $this->get_action_link_or_button(
1113
-                'new_registration',
1114
-                'add-registrant',
1115
-                array('event_id' => $this->_req_data['event_id']),
1116
-                'add-new-h2',
1117
-                '',
1118
-                false
1119
-            )
1120
-            : '';
1121
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1122
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1123
-        $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1124
-        $legend_items = array(
1125
-            'star-icon'        => array(
1126
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1127
-                'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1128
-            ),
1129
-            'checkin'          => array(
1130
-                'class' => $checked_in->cssClasses(),
1131
-                'desc'  => $checked_in->legendLabel(),
1132
-            ),
1133
-            'checkout'         => array(
1134
-                'class' => $checked_out->cssClasses(),
1135
-                'desc'  => $checked_out->legendLabel(),
1136
-            ),
1137
-            'nocheckinrecord'  => array(
1138
-                'class' => $checked_never->cssClasses(),
1139
-                'desc'  => $checked_never->legendLabel(),
1140
-            ),
1141
-            'approved_status'  => array(
1142
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1143
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1144
-            ),
1145
-            'cancelled_status' => array(
1146
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1147
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1148
-            ),
1149
-            'declined_status'  => array(
1150
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1151
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1152
-            ),
1153
-            'not_approved'     => array(
1154
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1155
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1156
-            ),
1157
-            'pending_status'   => array(
1158
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1159
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1160
-            ),
1161
-            'wait_list'        => array(
1162
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1163
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1164
-            ),
1165
-        );
1166
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1167
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1168
-        /** @var EE_Event $event */
1169
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1170
-        $this->_template_args['before_list_table'] = $event instanceof EE_Event
1171
-            ? '<h2>' . sprintf(
1172
-                esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1173
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1174
-            ) . '</h2>'
1175
-            : '';
1176
-        // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1177
-        // the event.
1178
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1179
-        $datetime = null;
1180
-        if ($event instanceof EE_Event) {
1181
-            $datetimes_on_event = $event->datetimes();
1182
-            if (count($datetimes_on_event) === 1) {
1183
-                $datetime = reset($datetimes_on_event);
1184
-            }
1185
-        }
1186
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1187
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1188
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1189
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1190
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1191
-            $this->_template_args['before_list_table'] .= $datetime->name();
1192
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1193
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1194
-        }
1195
-        // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1196
-        // column represents
1197
-        if (! $datetime instanceof EE_Datetime) {
1198
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1199
-                                                          . esc_html__(
1200
-                                                              'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1201
-                                                              'event_espresso'
1202
-                                                          )
1203
-                                                          . '</p>';
1204
-        }
1205
-        $this->display_admin_list_table_page_with_no_sidebar();
1206
-    }
1098
+	/**
1099
+	 *        generates HTML for the Event Registrations List Table
1100
+	 *
1101
+	 * @access protected
1102
+	 * @return void
1103
+	 * @throws EE_Error
1104
+	 * @throws InvalidArgumentException
1105
+	 * @throws InvalidDataTypeException
1106
+	 * @throws InvalidInterfaceException
1107
+	 */
1108
+	protected function _event_registrations_list_table()
1109
+	{
1110
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1111
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1112
+			? $this->get_action_link_or_button(
1113
+				'new_registration',
1114
+				'add-registrant',
1115
+				array('event_id' => $this->_req_data['event_id']),
1116
+				'add-new-h2',
1117
+				'',
1118
+				false
1119
+			)
1120
+			: '';
1121
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1122
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1123
+		$checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1124
+		$legend_items = array(
1125
+			'star-icon'        => array(
1126
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1127
+				'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1128
+			),
1129
+			'checkin'          => array(
1130
+				'class' => $checked_in->cssClasses(),
1131
+				'desc'  => $checked_in->legendLabel(),
1132
+			),
1133
+			'checkout'         => array(
1134
+				'class' => $checked_out->cssClasses(),
1135
+				'desc'  => $checked_out->legendLabel(),
1136
+			),
1137
+			'nocheckinrecord'  => array(
1138
+				'class' => $checked_never->cssClasses(),
1139
+				'desc'  => $checked_never->legendLabel(),
1140
+			),
1141
+			'approved_status'  => array(
1142
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1143
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1144
+			),
1145
+			'cancelled_status' => array(
1146
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1147
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1148
+			),
1149
+			'declined_status'  => array(
1150
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1151
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1152
+			),
1153
+			'not_approved'     => array(
1154
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1155
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1156
+			),
1157
+			'pending_status'   => array(
1158
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1159
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1160
+			),
1161
+			'wait_list'        => array(
1162
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1163
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1164
+			),
1165
+		);
1166
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1167
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1168
+		/** @var EE_Event $event */
1169
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1170
+		$this->_template_args['before_list_table'] = $event instanceof EE_Event
1171
+			? '<h2>' . sprintf(
1172
+				esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1173
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1174
+			) . '</h2>'
1175
+			: '';
1176
+		// need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1177
+		// the event.
1178
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1179
+		$datetime = null;
1180
+		if ($event instanceof EE_Event) {
1181
+			$datetimes_on_event = $event->datetimes();
1182
+			if (count($datetimes_on_event) === 1) {
1183
+				$datetime = reset($datetimes_on_event);
1184
+			}
1185
+		}
1186
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1187
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1188
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1189
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1190
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1191
+			$this->_template_args['before_list_table'] .= $datetime->name();
1192
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1193
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1194
+		}
1195
+		// if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1196
+		// column represents
1197
+		if (! $datetime instanceof EE_Datetime) {
1198
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1199
+														  . esc_html__(
1200
+															  'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1201
+															  'event_espresso'
1202
+														  )
1203
+														  . '</p>';
1204
+		}
1205
+		$this->display_admin_list_table_page_with_no_sidebar();
1206
+	}
1207 1207
 
1208
-    /**
1209
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1210
-     * conditions)
1211
-     *
1212
-     * @return void ends the request by a redirect or download
1213
-     */
1214
-    public function _registrations_checkin_report()
1215
-    {
1216
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1217
-    }
1208
+	/**
1209
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1210
+	 * conditions)
1211
+	 *
1212
+	 * @return void ends the request by a redirect or download
1213
+	 */
1214
+	public function _registrations_checkin_report()
1215
+	{
1216
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1217
+	}
1218 1218
 
1219
-    /**
1220
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1221
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1222
-     *
1223
-     * @param array $request
1224
-     * @param int   $per_page
1225
-     * @param bool  $count
1226
-     * @return array
1227
-     * @throws EE_Error
1228
-     */
1229
-    protected function _get_checkin_query_params_from_request(
1230
-        $request,
1231
-        $per_page = 10,
1232
-        $count = false
1233
-    ) {
1234
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1235
-        // unlike the regular registrations list table,
1236
-        $status_ids_array = apply_filters(
1237
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1238
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1239
-        );
1240
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1241
-        return $query_params;
1242
-    }
1219
+	/**
1220
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1221
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1222
+	 *
1223
+	 * @param array $request
1224
+	 * @param int   $per_page
1225
+	 * @param bool  $count
1226
+	 * @return array
1227
+	 * @throws EE_Error
1228
+	 */
1229
+	protected function _get_checkin_query_params_from_request(
1230
+		$request,
1231
+		$per_page = 10,
1232
+		$count = false
1233
+	) {
1234
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1235
+		// unlike the regular registrations list table,
1236
+		$status_ids_array = apply_filters(
1237
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1238
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1239
+		);
1240
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1241
+		return $query_params;
1242
+	}
1243 1243
 
1244 1244
 
1245
-    /**
1246
-     * Gets registrations for an event
1247
-     *
1248
-     * @param int    $per_page
1249
-     * @param bool   $count whether to return count or data.
1250
-     * @param bool   $trash
1251
-     * @param string $orderby
1252
-     * @return EE_Registration[]|int
1253
-     * @throws EE_Error
1254
-     * @throws InvalidArgumentException
1255
-     * @throws InvalidDataTypeException
1256
-     * @throws InvalidInterfaceException
1257
-     */
1258
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1259
-    {
1260
-        // normalize some request params that get setup by the parent `get_registrations` method.
1261
-        $request = $this->_req_data;
1262
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1263
-        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1264
-        if ($trash) {
1265
-            $request['status'] = 'trash';
1266
-        }
1267
-        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1268
-        /**
1269
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1270
-         *
1271
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1272
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1273
-         *                             or if you have the development copy of EE you can view this at the path:
1274
-         *                             /docs/G--Model-System/model-query-params.md
1275
-         */
1276
-        $query_params['group_by'] = '';
1245
+	/**
1246
+	 * Gets registrations for an event
1247
+	 *
1248
+	 * @param int    $per_page
1249
+	 * @param bool   $count whether to return count or data.
1250
+	 * @param bool   $trash
1251
+	 * @param string $orderby
1252
+	 * @return EE_Registration[]|int
1253
+	 * @throws EE_Error
1254
+	 * @throws InvalidArgumentException
1255
+	 * @throws InvalidDataTypeException
1256
+	 * @throws InvalidInterfaceException
1257
+	 */
1258
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1259
+	{
1260
+		// normalize some request params that get setup by the parent `get_registrations` method.
1261
+		$request = $this->_req_data;
1262
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1263
+		$request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1264
+		if ($trash) {
1265
+			$request['status'] = 'trash';
1266
+		}
1267
+		$query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1268
+		/**
1269
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1270
+		 *
1271
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1272
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1273
+		 *                             or if you have the development copy of EE you can view this at the path:
1274
+		 *                             /docs/G--Model-System/model-query-params.md
1275
+		 */
1276
+		$query_params['group_by'] = '';
1277 1277
 
1278
-        return $count
1279
-            ? EEM_Registration::instance()->count($query_params)
1280
-            /** @type EE_Registration[] */
1281
-            : EEM_Registration::instance()->get_all($query_params);
1282
-    }
1278
+		return $count
1279
+			? EEM_Registration::instance()->count($query_params)
1280
+			/** @type EE_Registration[] */
1281
+			: EEM_Registration::instance()->get_all($query_params);
1282
+	}
1283 1283
 }
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/ExecuteBatchDeletion.php 3 patches
Unused Use Statements   -8 removed lines patch added patch discarded remove patch
@@ -4,21 +4,13 @@
 block discarded – undo
4 4
 
5 5
 use EE_Change_Log;
6 6
 use EE_Registry;
7
-use EEM_Event;
8
-use EEM_Price;
9
-use EEM_Ticket;
10
-use EventEspresso\core\exceptions\InvalidClassException;
11
-use EventEspresso\core\exceptions\InvalidDataTypeException;
12
-use EventEspresso\core\exceptions\InvalidInterfaceException;
13 7
 use EventEspresso\core\exceptions\UnexpectedEntityException;
14
-use EventEspresso\core\services\loaders\LoaderFactory;
15 8
 use EventEspresso\core\services\orm\tree_traversal\NodeGroupDao;
16 9
 use EventEspresso\core\services\orm\tree_traversal\ModelObjNode;
17 10
 use EventEspressoBatchRequest\Helpers\BatchRequestException;
18 11
 use EventEspressoBatchRequest\Helpers\JobParameters;
19 12
 use EventEspressoBatchRequest\Helpers\JobStepResponse;
20 13
 use EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandler;
21
-use InvalidArgumentException;
22 14
 
23 15
 /**
24 16
  * Class EventDeletion
Please login to merge, or discard this patch.
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -32,158 +32,158 @@
 block discarded – undo
32 32
  */
33 33
 class ExecuteBatchDeletion extends JobHandler
34 34
 {
35
-    /**
36
-     * @var NodeGroupDao
37
-     */
38
-    protected $model_obj_node_group_persister;
39
-    public function __construct(NodeGroupDao $model_obj_node_group_persister)
40
-    {
41
-        $this->model_obj_node_group_persister = $model_obj_node_group_persister;
42
-    }
35
+	/**
36
+	 * @var NodeGroupDao
37
+	 */
38
+	protected $model_obj_node_group_persister;
39
+	public function __construct(NodeGroupDao $model_obj_node_group_persister)
40
+	{
41
+		$this->model_obj_node_group_persister = $model_obj_node_group_persister;
42
+	}
43 43
 
44 44
 
45
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
46
-    /**
47
-     *
48
-     * @param JobParameters $job_parameters
49
-     * @throws BatchRequestException
50
-     * @return JobStepResponse
51
-     */
52
-    public function create_job(JobParameters $job_parameters)
53
-    {
54
-        $deletion_job_code = $job_parameters->request_datum('deletion_job_code', null);
55
-        $roots = $this->model_obj_node_group_persister->getModelObjNodesInGroup($deletion_job_code);
56
-        if ($roots === null) {
57
-            throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso'));
58
-        }
59
-        $models_and_ids_to_delete = [];
60
-        foreach ($roots as $root) {
61
-            if (! $root instanceof ModelObjNode) {
62
-                throw new UnexpectedEntityException($root, 'ModelObjNode');
63
-            }
64
-            $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
65
-        }
66
-        $job_parameters->set_extra_data(
67
-            [
68
-                'models_and_ids_to_delete' => $models_and_ids_to_delete
69
-            ]
70
-        );
71
-        // Find the job's actual size.
72
-        $job_size = 0;
73
-        foreach ($models_and_ids_to_delete as $model_name => $ids) {
74
-            $job_size += count($ids);
75
-        }
76
-        $job_parameters->set_job_size($job_size);
77
-        return new JobStepResponse(
78
-            $job_parameters,
79
-            esc_html__('Beginning to delete items...', 'event_espresso')
80
-        );
81
-    }
45
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
46
+	/**
47
+	 *
48
+	 * @param JobParameters $job_parameters
49
+	 * @throws BatchRequestException
50
+	 * @return JobStepResponse
51
+	 */
52
+	public function create_job(JobParameters $job_parameters)
53
+	{
54
+		$deletion_job_code = $job_parameters->request_datum('deletion_job_code', null);
55
+		$roots = $this->model_obj_node_group_persister->getModelObjNodesInGroup($deletion_job_code);
56
+		if ($roots === null) {
57
+			throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso'));
58
+		}
59
+		$models_and_ids_to_delete = [];
60
+		foreach ($roots as $root) {
61
+			if (! $root instanceof ModelObjNode) {
62
+				throw new UnexpectedEntityException($root, 'ModelObjNode');
63
+			}
64
+			$models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
65
+		}
66
+		$job_parameters->set_extra_data(
67
+			[
68
+				'models_and_ids_to_delete' => $models_and_ids_to_delete
69
+			]
70
+		);
71
+		// Find the job's actual size.
72
+		$job_size = 0;
73
+		foreach ($models_and_ids_to_delete as $model_name => $ids) {
74
+			$job_size += count($ids);
75
+		}
76
+		$job_parameters->set_job_size($job_size);
77
+		return new JobStepResponse(
78
+			$job_parameters,
79
+			esc_html__('Beginning to delete items...', 'event_espresso')
80
+		);
81
+	}
82 82
 
83
-    /**
84
-     * Performs another step of the job
85
-     * @param JobParameters $job_parameters
86
-     * @param int $batch_size
87
-     * @return JobStepResponse
88
-     * @throws BatchRequestException
89
-     */
90
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
91
-    {
92
-        // We already have the items IDs. So deleting is really fast. Let's speed it up.
93
-        $batch_size *= 10;
94
-        $units_processed = 0;
95
-        $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []);
96
-        // Build a new list of everything leftover after this request's of deletions.
97
-        $models_and_ids_remaining = [];
98
-        foreach ($models_and_ids_to_delete as $model_name => $ids_to_delete) {
99
-            if ($units_processed < $batch_size) {
100
-                $model = EE_Registry::instance()->load_model($model_name);
101
-                $ids_to_delete_this_query = array_slice($ids_to_delete, 0, $batch_size - $units_processed, true);
102
-                if ($model->has_primary_key_field()) {
103
-                    $where_conditions = [
104
-                        $model->primary_key_name() => [
105
-                            'IN',
106
-                            $ids_to_delete_this_query
107
-                        ]
108
-                    ];
109
-                } else {
110
-                    $where_conditions = [
111
-                        'OR' => []
112
-                    ];
113
-                    foreach ($ids_to_delete_this_query as $index_primary_key_string) {
114
-                        $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string);
115
-                        $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values;
116
-                    }
117
-                }
118
-                // Deleting time!
119
-                // The model's deletion method reports every ROW deleted, and in the case of CPT models that will be
120
-                // two rows deleted for event CPT item. So don't rely on it for the count of items deleted.
121
-                $model->delete_permanently(
122
-                    [
123
-                        $where_conditions
124
-                    ],
125
-                    false
126
-                );
127
-                $units_processed += count($ids_to_delete_this_query);
128
-                $remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query);
129
-                // If there's any more from this model, we'll do them next time.
130
-                if (count($remaining_ids) > 0) {
131
-                    $models_and_ids_remaining[ $model_name ] = $remaining_ids;
132
-                }
133
-            } else {
134
-                $models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ];
135
-            }
136
-        }
137
-        $job_parameters->mark_processed($units_processed);
138
-        // All done deleting for this request. Is there anything to do next time?
139
-        if (empty($models_and_ids_remaining)) {
140
-            $job_parameters->set_status(JobParameters::status_complete);
141
-            return new JobStepResponse(
142
-                $job_parameters,
143
-                esc_html__('Deletion complete.', 'event_espresso')
144
-            );
145
-        }
146
-        $job_parameters->add_extra_data('models_and_ids_to_delete', $models_and_ids_remaining);
147
-        return new JobStepResponse(
148
-            $job_parameters,
149
-            sprintf(
150
-                esc_html__('Deleted %d items.', 'event_espresso'),
151
-                $units_processed
152
-            )
153
-        );
154
-    }
83
+	/**
84
+	 * Performs another step of the job
85
+	 * @param JobParameters $job_parameters
86
+	 * @param int $batch_size
87
+	 * @return JobStepResponse
88
+	 * @throws BatchRequestException
89
+	 */
90
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
91
+	{
92
+		// We already have the items IDs. So deleting is really fast. Let's speed it up.
93
+		$batch_size *= 10;
94
+		$units_processed = 0;
95
+		$models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []);
96
+		// Build a new list of everything leftover after this request's of deletions.
97
+		$models_and_ids_remaining = [];
98
+		foreach ($models_and_ids_to_delete as $model_name => $ids_to_delete) {
99
+			if ($units_processed < $batch_size) {
100
+				$model = EE_Registry::instance()->load_model($model_name);
101
+				$ids_to_delete_this_query = array_slice($ids_to_delete, 0, $batch_size - $units_processed, true);
102
+				if ($model->has_primary_key_field()) {
103
+					$where_conditions = [
104
+						$model->primary_key_name() => [
105
+							'IN',
106
+							$ids_to_delete_this_query
107
+						]
108
+					];
109
+				} else {
110
+					$where_conditions = [
111
+						'OR' => []
112
+					];
113
+					foreach ($ids_to_delete_this_query as $index_primary_key_string) {
114
+						$keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string);
115
+						$where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values;
116
+					}
117
+				}
118
+				// Deleting time!
119
+				// The model's deletion method reports every ROW deleted, and in the case of CPT models that will be
120
+				// two rows deleted for event CPT item. So don't rely on it for the count of items deleted.
121
+				$model->delete_permanently(
122
+					[
123
+						$where_conditions
124
+					],
125
+					false
126
+				);
127
+				$units_processed += count($ids_to_delete_this_query);
128
+				$remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query);
129
+				// If there's any more from this model, we'll do them next time.
130
+				if (count($remaining_ids) > 0) {
131
+					$models_and_ids_remaining[ $model_name ] = $remaining_ids;
132
+				}
133
+			} else {
134
+				$models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ];
135
+			}
136
+		}
137
+		$job_parameters->mark_processed($units_processed);
138
+		// All done deleting for this request. Is there anything to do next time?
139
+		if (empty($models_and_ids_remaining)) {
140
+			$job_parameters->set_status(JobParameters::status_complete);
141
+			return new JobStepResponse(
142
+				$job_parameters,
143
+				esc_html__('Deletion complete.', 'event_espresso')
144
+			);
145
+		}
146
+		$job_parameters->add_extra_data('models_and_ids_to_delete', $models_and_ids_remaining);
147
+		return new JobStepResponse(
148
+			$job_parameters,
149
+			sprintf(
150
+				esc_html__('Deleted %d items.', 'event_espresso'),
151
+				$units_processed
152
+			)
153
+		);
154
+	}
155 155
 
156
-    /**
157
-     * Performs any clean-up logic when we know the job is completed
158
-     * @param JobParameters $job_parameters
159
-     * @return JobStepResponse
160
-     */
161
-    public function cleanup_job(JobParameters $job_parameters)
162
-    {
163
-        $this->model_obj_node_group_persister->deleteModelObjNodesInGroup(
164
-            $job_parameters->request_datum('deletion_job_code')
165
-        );
166
-        // For backwards compatibility with how we used to delete events, make sure we still trigger the old action.
167
-        $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []);
168
-        foreach ($models_and_ids_to_delete['Event'] as $event_id) {
169
-            // Create a log entry so we know who and when this event was permanently deleted.
170
-            (EE_Change_Log::new_instance(
171
-                [
172
-                    'OBJ_ID' => $event_id,
173
-                    'OBJ_type' => 'Event',
174
-                    'LOG_message' => sprintf(
175
-                        esc_html__('Event %1$d permanently deleted using ExecuteBatchDeletion.', 'event_espresso'),
176
-                        $event_id
177
-                    )
178
-                ]
179
-            ))->save();
180
-            do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $event_id);
181
-        }
182
-        return new JobStepResponse(
183
-            $job_parameters,
184
-            esc_html__('All done', 'event_espresso')
185
-        );
186
-    }
156
+	/**
157
+	 * Performs any clean-up logic when we know the job is completed
158
+	 * @param JobParameters $job_parameters
159
+	 * @return JobStepResponse
160
+	 */
161
+	public function cleanup_job(JobParameters $job_parameters)
162
+	{
163
+		$this->model_obj_node_group_persister->deleteModelObjNodesInGroup(
164
+			$job_parameters->request_datum('deletion_job_code')
165
+		);
166
+		// For backwards compatibility with how we used to delete events, make sure we still trigger the old action.
167
+		$models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []);
168
+		foreach ($models_and_ids_to_delete['Event'] as $event_id) {
169
+			// Create a log entry so we know who and when this event was permanently deleted.
170
+			(EE_Change_Log::new_instance(
171
+				[
172
+					'OBJ_ID' => $event_id,
173
+					'OBJ_type' => 'Event',
174
+					'LOG_message' => sprintf(
175
+						esc_html__('Event %1$d permanently deleted using ExecuteBatchDeletion.', 'event_espresso'),
176
+						$event_id
177
+					)
178
+				]
179
+			))->save();
180
+			do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $event_id);
181
+		}
182
+		return new JobStepResponse(
183
+			$job_parameters,
184
+			esc_html__('All done', 'event_espresso')
185
+		);
186
+	}
187 187
 }
188 188
 // End of file EventDeletion.php
189 189
 // Location: EventEspressoBatchRequest\JobHandlers/EventDeletion.php
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         }
59 59
         $models_and_ids_to_delete = [];
60 60
         foreach ($roots as $root) {
61
-            if (! $root instanceof ModelObjNode) {
61
+            if ( ! $root instanceof ModelObjNode) {
62 62
                 throw new UnexpectedEntityException($root, 'ModelObjNode');
63 63
             }
64 64
             $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
                     ];
113 113
                     foreach ($ids_to_delete_this_query as $index_primary_key_string) {
114 114
                         $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string);
115
-                        $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values;
115
+                        $where_conditions['OR']['AND*'.$index_primary_key_string] = $keys_n_values;
116 116
                     }
117 117
                 }
118 118
                 // Deleting time!
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
                 $remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query);
129 129
                 // If there's any more from this model, we'll do them next time.
130 130
                 if (count($remaining_ids) > 0) {
131
-                    $models_and_ids_remaining[ $model_name ] = $remaining_ids;
131
+                    $models_and_ids_remaining[$model_name] = $remaining_ids;
132 132
                 }
133 133
             } else {
134
-                $models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ];
134
+                $models_and_ids_remaining[$model_name] = $models_and_ids_to_delete[$model_name];
135 135
             }
136 136
         }
137 137
         $job_parameters->mark_processed($units_processed);
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/NodeGroupDao.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -22,112 +22,112 @@
 block discarded – undo
22 22
  */
23 23
 class NodeGroupDao
24 24
 {
25
-    /**
26
-     * @since $VID:$
27
-     * @return mixed|void
28
-     */
29
-    public function generateGroupCode()
30
-    {
31
-        return wp_generate_password(6, false);
32
-    }
25
+	/**
26
+	 * @since $VID:$
27
+	 * @return mixed|void
28
+	 */
29
+	public function generateGroupCode()
30
+	{
31
+		return wp_generate_password(6, false);
32
+	}
33 33
 
34
-    /**
35
-     * Gets the string we put in front of the WP Option name used to store the jobs.
36
-     * @since $VID:$
37
-     * @return string
38
-     */
39
-    private function getOptionPrefix()
40
-    {
41
-        return 'ee_deletion_';
42
-    }
34
+	/**
35
+	 * Gets the string we put in front of the WP Option name used to store the jobs.
36
+	 * @since $VID:$
37
+	 * @return string
38
+	 */
39
+	private function getOptionPrefix()
40
+	{
41
+		return 'ee_deletion_';
42
+	}
43 43
 
44
-    /**
45
-     * @since $VID:$
46
-     * @param $code
47
-     * @return ModelObjNode[]
48
-     * @throws UnexpectedEntityException
49
-     */
50
-    public function getModelObjNodesInGroup($code)
51
-    {
52
-        if (! $code) {
53
-            throw new Exception(esc_html__('We aren’t sure which job you are performing. Please press back in your browser and try again.', 'event_espresso'));
54
-        }
55
-        $deletion_data = get_option($this->getOptionPrefix() . $code, []);
56
-        foreach ($deletion_data as $root) {
57
-            if (! $root instanceof ModelObjNode) {
58
-                throw new UnexpectedEntityException($root, 'ModelObjNode');
59
-            }
60
-        }
61
-        return $deletion_data;
62
-    }
44
+	/**
45
+	 * @since $VID:$
46
+	 * @param $code
47
+	 * @return ModelObjNode[]
48
+	 * @throws UnexpectedEntityException
49
+	 */
50
+	public function getModelObjNodesInGroup($code)
51
+	{
52
+		if (! $code) {
53
+			throw new Exception(esc_html__('We aren’t sure which job you are performing. Please press back in your browser and try again.', 'event_espresso'));
54
+		}
55
+		$deletion_data = get_option($this->getOptionPrefix() . $code, []);
56
+		foreach ($deletion_data as $root) {
57
+			if (! $root instanceof ModelObjNode) {
58
+				throw new UnexpectedEntityException($root, 'ModelObjNode');
59
+			}
60
+		}
61
+		return $deletion_data;
62
+	}
63 63
 
64
-    /**
65
-     * Gets an array indicating what database rows are contained in the job.
66
-     * Each top-level key is a model name, and its value is an array of IDs.
67
-     * @since $VID:$
68
-     * @param ModelObjNode[] $model_obj_nodes
69
-     * @return array
70
-     * @throws EE_Error
71
-     * @throws InvalidDataTypeException
72
-     * @throws InvalidInterfaceException
73
-     * @throws InvalidArgumentException
74
-     * @throws ReflectionException
75
-     */
76
-    public function getModelsAndIdsContainedIn($model_obj_nodes)
77
-    {
78
-        $models_and_ids_to_delete = [];
79
-        foreach ($model_obj_nodes as $root) {
80
-            $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
81
-        }
82
-        return $models_and_ids_to_delete;
83
-    }
64
+	/**
65
+	 * Gets an array indicating what database rows are contained in the job.
66
+	 * Each top-level key is a model name, and its value is an array of IDs.
67
+	 * @since $VID:$
68
+	 * @param ModelObjNode[] $model_obj_nodes
69
+	 * @return array
70
+	 * @throws EE_Error
71
+	 * @throws InvalidDataTypeException
72
+	 * @throws InvalidInterfaceException
73
+	 * @throws InvalidArgumentException
74
+	 * @throws ReflectionException
75
+	 */
76
+	public function getModelsAndIdsContainedIn($model_obj_nodes)
77
+	{
78
+		$models_and_ids_to_delete = [];
79
+		foreach ($model_obj_nodes as $root) {
80
+			$models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
81
+		}
82
+		return $models_and_ids_to_delete;
83
+	}
84 84
 
85
-    /**
86
-     * Gets an array indicating what database rows are contained in the job.
87
-     * Each top-level key is a model name, and its value is an array of IDs.
88
-     * @since $VID:$
89
-     * @param string $code
90
-     * @return array
91
-     * @throws EE_Error
92
-     * @throws InvalidArgumentException
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidInterfaceException
95
-     * @throws ReflectionException
96
-     * @throws UnexpectedEntityException
97
-     */
98
-    public function getModelsAndIdsFromGroup($code)
99
-    {
100
-        $model_obj_nodes = $this->getModelObjNodesInGroup($code);
101
-        return $this->getModelsAndIdsContainedIn($model_obj_nodes);
102
-    }
85
+	/**
86
+	 * Gets an array indicating what database rows are contained in the job.
87
+	 * Each top-level key is a model name, and its value is an array of IDs.
88
+	 * @since $VID:$
89
+	 * @param string $code
90
+	 * @return array
91
+	 * @throws EE_Error
92
+	 * @throws InvalidArgumentException
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidInterfaceException
95
+	 * @throws ReflectionException
96
+	 * @throws UnexpectedEntityException
97
+	 */
98
+	public function getModelsAndIdsFromGroup($code)
99
+	{
100
+		$model_obj_nodes = $this->getModelObjNodesInGroup($code);
101
+		return $this->getModelsAndIdsContainedIn($model_obj_nodes);
102
+	}
103 103
 
104
-    /**
105
-     * Persists the ModelObjNodes for future requests, using the code for reference.
106
-     * @since $VID:$
107
-     * @param ModelObjNode[] $model_obj_nodes
108
-     * @param string $code
109
-     * @return bool
110
-     */
111
-    public function persistModelObjNodesGroup($model_obj_nodes, $code)
112
-    {
113
-        return add_option(
114
-            $this->getOptionPrefix() . $code,
115
-            $model_obj_nodes,
116
-            null,
117
-            'no'
118
-        );
119
-    }
104
+	/**
105
+	 * Persists the ModelObjNodes for future requests, using the code for reference.
106
+	 * @since $VID:$
107
+	 * @param ModelObjNode[] $model_obj_nodes
108
+	 * @param string $code
109
+	 * @return bool
110
+	 */
111
+	public function persistModelObjNodesGroup($model_obj_nodes, $code)
112
+	{
113
+		return add_option(
114
+			$this->getOptionPrefix() . $code,
115
+			$model_obj_nodes,
116
+			null,
117
+			'no'
118
+		);
119
+	}
120 120
 
121
-    /**
122
-     * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though.
123
-     * @since $VID:$
124
-     * @param $code
125
-     * @return bool
126
-     */
127
-    public function deleteModelObjNodesInGroup($code)
128
-    {
129
-        return delete_option($this->getOptionPrefix() . $code);
130
-    }
121
+	/**
122
+	 * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though.
123
+	 * @since $VID:$
124
+	 * @param $code
125
+	 * @return bool
126
+	 */
127
+	public function deleteModelObjNodesInGroup($code)
128
+	{
129
+		return delete_option($this->getOptionPrefix() . $code);
130
+	}
131 131
 }
132 132
 // End of file NodeGroupDao.php
133 133
 // Location: EventEspresso\core\services\orm\tree_traversal/NodeGroupDao.php
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function getModelObjNodesInGroup($code)
51 51
     {
52
-        if (! $code) {
52
+        if ( ! $code) {
53 53
             throw new Exception(esc_html__('We aren’t sure which job you are performing. Please press back in your browser and try again.', 'event_espresso'));
54 54
         }
55
-        $deletion_data = get_option($this->getOptionPrefix() . $code, []);
55
+        $deletion_data = get_option($this->getOptionPrefix().$code, []);
56 56
         foreach ($deletion_data as $root) {
57
-            if (! $root instanceof ModelObjNode) {
57
+            if ( ! $root instanceof ModelObjNode) {
58 58
                 throw new UnexpectedEntityException($root, 'ModelObjNode');
59 59
             }
60 60
         }
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
     public function persistModelObjNodesGroup($model_obj_nodes, $code)
112 112
     {
113 113
         return add_option(
114
-            $this->getOptionPrefix() . $code,
114
+            $this->getOptionPrefix().$code,
115 115
             $model_obj_nodes,
116 116
             null,
117 117
             'no'
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      */
127 127
     public function deleteModelObjNodesInGroup($code)
128 128
     {
129
-        return delete_option($this->getOptionPrefix() . $code);
129
+        return delete_option($this->getOptionPrefix().$code);
130 130
     }
131 131
 }
132 132
 // End of file NodeGroupDao.php
Please login to merge, or discard this patch.
core/domain/services/admin/events/data/ConfirmDeletion.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -30,86 +30,86 @@
 block discarded – undo
30 30
  */
31 31
 class ConfirmDeletion
32 32
 {
33
-    /**
34
-     * @var NodeGroupDao
35
-     */
36
-    private $dao;
33
+	/**
34
+	 * @var NodeGroupDao
35
+	 */
36
+	private $dao;
37 37
 
38
-    /**
39
-     * ConfirmDeletion constructor.
40
-     * @param NodeGroupDao $dao
41
-     */
42
-    public function __construct(
43
-        NodeGroupDao $dao
44
-    ) {
38
+	/**
39
+	 * ConfirmDeletion constructor.
40
+	 * @param NodeGroupDao $dao
41
+	 */
42
+	public function __construct(
43
+		NodeGroupDao $dao
44
+	) {
45 45
 
46
-        $this->dao = $dao;
47
-    }
46
+		$this->dao = $dao;
47
+	}
48 48
 
49
-    /**
50
-     * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion
51
-     * preview page.
52
-     * @since $VID:$
53
-     * @param $request_data
54
-     * @param $admin_base_url
55
-     * @throws EE_Error
56
-     * @throws InvalidArgumentException
57
-     * @throws InvalidDataTypeException
58
-     * @throws InvalidInterfaceException
59
-     * @throws ReflectionException
60
-     * @throws UnexpectedEntityException
61
-     */
62
-    public function handle($request_data, $admin_base_url)
63
-    {
64
-        $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
65
-        $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
66
-        $form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']);
67
-        // Initialize the form from the request, and check if its valid.
68
-        $form->receive_form_submission($request_data);
69
-        if ($form->is_valid()) {
70
-            // Redirect the user to the deletion batch job.
71
-            EEH_URL::safeRedirectAndExit(
72
-                EE_Admin_Page::add_query_args_and_nonce(
73
-                    array(
74
-                        'page' => 'espresso_batch',
75
-                        'batch' => EED_Batch::batch_job,
76
-                        'deletion_job_code' => $deletion_job_code,
77
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'),
78
-                        'return_url' => urlencode(
79
-                            add_query_arg(
80
-                                [
81
-                                    'status' => 'trash'
82
-                                ],
83
-                                EVENTS_ADMIN_URL
84
-                            )
85
-                        )
86
-                    ),
87
-                    admin_url()
88
-                )
89
-            );
90
-        }
91
-        // Dont' use $form->submission_error_message() because it adds the form input's label in front
92
-        // of each validation error which ends up looking quite confusing.
93
-        $validation_errors = $form->get_validation_errors_accumulated();
94
-        foreach ($validation_errors as $validation_error) {
95
-            EE_Error::add_error(
96
-                $validation_error->getMessage(),
97
-                __FILE__,
98
-                __FUNCTION__,
99
-                __LINE__
100
-            );
101
-        }
49
+	/**
50
+	 * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion
51
+	 * preview page.
52
+	 * @since $VID:$
53
+	 * @param $request_data
54
+	 * @param $admin_base_url
55
+	 * @throws EE_Error
56
+	 * @throws InvalidArgumentException
57
+	 * @throws InvalidDataTypeException
58
+	 * @throws InvalidInterfaceException
59
+	 * @throws ReflectionException
60
+	 * @throws UnexpectedEntityException
61
+	 */
62
+	public function handle($request_data, $admin_base_url)
63
+	{
64
+		$deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : '';
65
+		$models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code);
66
+		$form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']);
67
+		// Initialize the form from the request, and check if its valid.
68
+		$form->receive_form_submission($request_data);
69
+		if ($form->is_valid()) {
70
+			// Redirect the user to the deletion batch job.
71
+			EEH_URL::safeRedirectAndExit(
72
+				EE_Admin_Page::add_query_args_and_nonce(
73
+					array(
74
+						'page' => 'espresso_batch',
75
+						'batch' => EED_Batch::batch_job,
76
+						'deletion_job_code' => $deletion_job_code,
77
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'),
78
+						'return_url' => urlencode(
79
+							add_query_arg(
80
+								[
81
+									'status' => 'trash'
82
+								],
83
+								EVENTS_ADMIN_URL
84
+							)
85
+						)
86
+					),
87
+					admin_url()
88
+				)
89
+			);
90
+		}
91
+		// Dont' use $form->submission_error_message() because it adds the form input's label in front
92
+		// of each validation error which ends up looking quite confusing.
93
+		$validation_errors = $form->get_validation_errors_accumulated();
94
+		foreach ($validation_errors as $validation_error) {
95
+			EE_Error::add_error(
96
+				$validation_error->getMessage(),
97
+				__FILE__,
98
+				__FUNCTION__,
99
+				__LINE__
100
+			);
101
+		}
102 102
 
103
-        EEH_URL::safeRedirectAndExit(
104
-            EE_Admin_Page::add_query_args_and_nonce(
105
-                [
106
-                    'action' => 'preview_deletion',
107
-                    'deletion_job_code' => $deletion_job_code
108
-                ],
109
-                $admin_base_url
110
-            )
111
-        );
112
-    }
103
+		EEH_URL::safeRedirectAndExit(
104
+			EE_Admin_Page::add_query_args_and_nonce(
105
+				[
106
+					'action' => 'preview_deletion',
107
+					'deletion_job_code' => $deletion_job_code
108
+				],
109
+				$admin_base_url
110
+			)
111
+		);
112
+	}
113 113
 }
114 114
 // End of file ConfirmDeletion.php
115 115
 // Location: EventEspresso\core\domain\services\admin\events\data/ConfirmDeletion.php
Please login to merge, or discard this patch.