Completed
Branch master (993271)
by
unknown
02:12
created
core/services/request/sanitizers/AllowedTags.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@
 block discarded – undo
129 129
         $allowed_post_tags = wp_kses_allowed_html('post');
130 130
         $allowed_tags = [];
131 131
         foreach (AllowedTags::$tags as $tag) {
132
-            $allowed_tags[ $tag ] = AllowedTags::$attributes;
132
+            $allowed_tags[$tag] = AllowedTags::$attributes;
133 133
         }
134 134
         AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags);
135 135
     }
Please login to merge, or discard this patch.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -13,225 +13,225 @@
 block discarded – undo
13 13
 class AllowedTags
14 14
 {
15 15
 
16
-    /**
17
-     * @var array[]
18
-     */
19
-    private static $attributes = [
20
-        'accept-charset'    => 1,
21
-        'action'            => 1,
22
-        'alt'               => 1,
23
-        'allow'             => 1,
24
-        'allowfullscreen'   => 1,
25
-        'align'             => 1,
26
-        'aria-*'            => 1,
27
-        'autocomplete'      => 1,
28
-        'checked'           => 1,
29
-        'class'             => 1,
30
-        'cols'              => 1,
31
-        'content'           => 1,
32
-        'data-*'            => 1,
33
-        'dir'               => 1,
34
-        'disabled'          => 1,
35
-        'enctype'           => 1,
36
-        'for'               => 1,
37
-        'frameborder'       => 1,
38
-        'height'            => 1,
39
-        'href'              => 1,
40
-        'id'                => 1,
41
-        'itemprop'          => 1,
42
-        'itemscope'         => 1,
43
-        'itemtype'          => 1,
44
-        'label'             => 1,
45
-        'lang'              => 1,
46
-        'max'               => 1,
47
-        'method'            => 1,
48
-        'min'               => 1,
49
-        'multiple'          => 1,
50
-        'name'              => 1,
51
-        'novalidate'        => 1,
52
-        'placeholder'       => 1,
53
-        'readonly'          => 1,
54
-        'rel'               => 1,
55
-        'required'          => 1,
56
-        'rows'              => 1,
57
-        'selected'          => 1,
58
-        'src'               => 1,
59
-        'style'             => 1,
60
-        'step'              => 1,
61
-        'tabindex'          => 1,
62
-        'target'            => 1,
63
-        'title'             => 1,
64
-        'type'              => 1,
65
-        'value'             => 1,
66
-        'width'             => 1,
67
-    ];
68
-
69
-
70
-    /**
71
-     * @var array
72
-     */
73
-    private static $tags = [
74
-        'a',
75
-        'abbr',
76
-        'b',
77
-        'br',
78
-        'code',
79
-        'div',
80
-        'em',
81
-        'h1',
82
-        'h2',
83
-        'h3',
84
-        'h4',
85
-        'h5',
86
-        'h6',
87
-        'hr',
88
-        'i',
89
-        'img',
90
-        'li',
91
-        'ol',
92
-        'p',
93
-        'pre',
94
-        'small',
95
-        'span',
96
-        'strong',
97
-        'table',
98
-        'td',
99
-        'tr',
100
-        'ul',
101
-    ];
102
-
103
-
104
-    /**
105
-     * @var array
106
-     */
107
-    private static $allowed_tags;
108
-
109
-
110
-    /**
111
-     * @var array
112
-     */
113
-    private static $allowed_with_embed_tags;
114
-
115
-
116
-    /**
117
-     * @var array
118
-     */
119
-    private static $allowed_with_form_tags;
120
-
121
-
122
-    /**
123
-     * @var array
124
-     */
125
-    private static $allowed_with_script_and_style_tags;
126
-
127
-
128
-    /**
129
-     * merges additional tags and attributes into the WP post tags
130
-     */
131
-    private static function initializeAllowedTags()
132
-    {
133
-        $allowed_post_tags = wp_kses_allowed_html('post');
134
-        $allowed_tags = [];
135
-        foreach (AllowedTags::$tags as $tag) {
136
-            $allowed_tags[ $tag ] = AllowedTags::$attributes;
137
-        }
138
-        AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags);
139
-    }
140
-
141
-
142
-    /**
143
-     * merges embed tags and attributes into the EE all tags
144
-     */
145
-    private static function initializeWithEmbedTags()
146
-    {
147
-        $all_tags = AllowedTags::getAllowedTags();
148
-        $embed_tags = [
149
-            'iframe' => AllowedTags::$attributes
150
-        ];
151
-        AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags);
152
-    }
153
-
154
-
155
-    /**
156
-     * merges form tags and attributes into the EE all tags
157
-     */
158
-    private static function initializeWithFormTags()
159
-    {
160
-        $all_tags = AllowedTags::getAllowedTags();
161
-        $form_tags = [
162
-            'form' => AllowedTags::$attributes,
163
-            'label' => AllowedTags::$attributes,
164
-            'input' => AllowedTags::$attributes,
165
-            'select' => AllowedTags::$attributes,
166
-            'option' => AllowedTags::$attributes,
167
-            'optgroup' => AllowedTags::$attributes,
168
-            'textarea' => AllowedTags::$attributes,
169
-            'button' => AllowedTags::$attributes,
170
-            'fieldset' => AllowedTags::$attributes,
171
-            'output' => AllowedTags::$attributes,
172
-        ];
173
-        AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags);
174
-    }
175
-
176
-
177
-    /**
178
-     * merges form script and style tags and attributes into the EE all tags
179
-     */
180
-    private static function initializeWithScriptAndStyleTags()
181
-    {
182
-        $all_tags = AllowedTags::getAllowedTags();
183
-        $script_and_style_tags = [
184
-            'script' => AllowedTags::$attributes,
185
-            'style' => AllowedTags::$attributes,
186
-        ];
187
-        AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags);
188
-    }
189
-
190
-
191
-    /**
192
-     * @return array[]
193
-     */
194
-    public static function getAllowedTags()
195
-    {
196
-        if (empty(AllowedTags::$allowed_tags)) {
197
-            AllowedTags::initializeAllowedTags();
198
-        }
199
-        return AllowedTags::$allowed_tags;
200
-    }
201
-
202
-
203
-    /**
204
-     * @return array[]
205
-     */
206
-    public static function getWithEmbedTags()
207
-    {
208
-        if (empty(AllowedTags::$allowed_with_embed_tags)) {
209
-            AllowedTags::initializeWithEmbedTags();
210
-        }
211
-        return AllowedTags::$allowed_with_embed_tags;
212
-    }
213
-
214
-
215
-    /**
216
-     * @return array[]
217
-     */
218
-    public static function getWithFormTags()
219
-    {
220
-        if (empty(AllowedTags::$allowed_with_form_tags)) {
221
-            AllowedTags::initializeWithFormTags();
222
-        }
223
-        return AllowedTags::$allowed_with_form_tags;
224
-    }
225
-
226
-
227
-    /**
228
-     * @return array[]
229
-     */
230
-    public static function getWithScriptAndStyleTags()
231
-    {
232
-        if (empty(AllowedTags::$allowed_with_script_and_style_tags)) {
233
-            AllowedTags::initializeWithScriptAndStyleTags();
234
-        }
235
-        return AllowedTags::$allowed_with_script_and_style_tags;
236
-    }
16
+	/**
17
+	 * @var array[]
18
+	 */
19
+	private static $attributes = [
20
+		'accept-charset'    => 1,
21
+		'action'            => 1,
22
+		'alt'               => 1,
23
+		'allow'             => 1,
24
+		'allowfullscreen'   => 1,
25
+		'align'             => 1,
26
+		'aria-*'            => 1,
27
+		'autocomplete'      => 1,
28
+		'checked'           => 1,
29
+		'class'             => 1,
30
+		'cols'              => 1,
31
+		'content'           => 1,
32
+		'data-*'            => 1,
33
+		'dir'               => 1,
34
+		'disabled'          => 1,
35
+		'enctype'           => 1,
36
+		'for'               => 1,
37
+		'frameborder'       => 1,
38
+		'height'            => 1,
39
+		'href'              => 1,
40
+		'id'                => 1,
41
+		'itemprop'          => 1,
42
+		'itemscope'         => 1,
43
+		'itemtype'          => 1,
44
+		'label'             => 1,
45
+		'lang'              => 1,
46
+		'max'               => 1,
47
+		'method'            => 1,
48
+		'min'               => 1,
49
+		'multiple'          => 1,
50
+		'name'              => 1,
51
+		'novalidate'        => 1,
52
+		'placeholder'       => 1,
53
+		'readonly'          => 1,
54
+		'rel'               => 1,
55
+		'required'          => 1,
56
+		'rows'              => 1,
57
+		'selected'          => 1,
58
+		'src'               => 1,
59
+		'style'             => 1,
60
+		'step'              => 1,
61
+		'tabindex'          => 1,
62
+		'target'            => 1,
63
+		'title'             => 1,
64
+		'type'              => 1,
65
+		'value'             => 1,
66
+		'width'             => 1,
67
+	];
68
+
69
+
70
+	/**
71
+	 * @var array
72
+	 */
73
+	private static $tags = [
74
+		'a',
75
+		'abbr',
76
+		'b',
77
+		'br',
78
+		'code',
79
+		'div',
80
+		'em',
81
+		'h1',
82
+		'h2',
83
+		'h3',
84
+		'h4',
85
+		'h5',
86
+		'h6',
87
+		'hr',
88
+		'i',
89
+		'img',
90
+		'li',
91
+		'ol',
92
+		'p',
93
+		'pre',
94
+		'small',
95
+		'span',
96
+		'strong',
97
+		'table',
98
+		'td',
99
+		'tr',
100
+		'ul',
101
+	];
102
+
103
+
104
+	/**
105
+	 * @var array
106
+	 */
107
+	private static $allowed_tags;
108
+
109
+
110
+	/**
111
+	 * @var array
112
+	 */
113
+	private static $allowed_with_embed_tags;
114
+
115
+
116
+	/**
117
+	 * @var array
118
+	 */
119
+	private static $allowed_with_form_tags;
120
+
121
+
122
+	/**
123
+	 * @var array
124
+	 */
125
+	private static $allowed_with_script_and_style_tags;
126
+
127
+
128
+	/**
129
+	 * merges additional tags and attributes into the WP post tags
130
+	 */
131
+	private static function initializeAllowedTags()
132
+	{
133
+		$allowed_post_tags = wp_kses_allowed_html('post');
134
+		$allowed_tags = [];
135
+		foreach (AllowedTags::$tags as $tag) {
136
+			$allowed_tags[ $tag ] = AllowedTags::$attributes;
137
+		}
138
+		AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags);
139
+	}
140
+
141
+
142
+	/**
143
+	 * merges embed tags and attributes into the EE all tags
144
+	 */
145
+	private static function initializeWithEmbedTags()
146
+	{
147
+		$all_tags = AllowedTags::getAllowedTags();
148
+		$embed_tags = [
149
+			'iframe' => AllowedTags::$attributes
150
+		];
151
+		AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags);
152
+	}
153
+
154
+
155
+	/**
156
+	 * merges form tags and attributes into the EE all tags
157
+	 */
158
+	private static function initializeWithFormTags()
159
+	{
160
+		$all_tags = AllowedTags::getAllowedTags();
161
+		$form_tags = [
162
+			'form' => AllowedTags::$attributes,
163
+			'label' => AllowedTags::$attributes,
164
+			'input' => AllowedTags::$attributes,
165
+			'select' => AllowedTags::$attributes,
166
+			'option' => AllowedTags::$attributes,
167
+			'optgroup' => AllowedTags::$attributes,
168
+			'textarea' => AllowedTags::$attributes,
169
+			'button' => AllowedTags::$attributes,
170
+			'fieldset' => AllowedTags::$attributes,
171
+			'output' => AllowedTags::$attributes,
172
+		];
173
+		AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags);
174
+	}
175
+
176
+
177
+	/**
178
+	 * merges form script and style tags and attributes into the EE all tags
179
+	 */
180
+	private static function initializeWithScriptAndStyleTags()
181
+	{
182
+		$all_tags = AllowedTags::getAllowedTags();
183
+		$script_and_style_tags = [
184
+			'script' => AllowedTags::$attributes,
185
+			'style' => AllowedTags::$attributes,
186
+		];
187
+		AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags);
188
+	}
189
+
190
+
191
+	/**
192
+	 * @return array[]
193
+	 */
194
+	public static function getAllowedTags()
195
+	{
196
+		if (empty(AllowedTags::$allowed_tags)) {
197
+			AllowedTags::initializeAllowedTags();
198
+		}
199
+		return AllowedTags::$allowed_tags;
200
+	}
201
+
202
+
203
+	/**
204
+	 * @return array[]
205
+	 */
206
+	public static function getWithEmbedTags()
207
+	{
208
+		if (empty(AllowedTags::$allowed_with_embed_tags)) {
209
+			AllowedTags::initializeWithEmbedTags();
210
+		}
211
+		return AllowedTags::$allowed_with_embed_tags;
212
+	}
213
+
214
+
215
+	/**
216
+	 * @return array[]
217
+	 */
218
+	public static function getWithFormTags()
219
+	{
220
+		if (empty(AllowedTags::$allowed_with_form_tags)) {
221
+			AllowedTags::initializeWithFormTags();
222
+		}
223
+		return AllowedTags::$allowed_with_form_tags;
224
+	}
225
+
226
+
227
+	/**
228
+	 * @return array[]
229
+	 */
230
+	public static function getWithScriptAndStyleTags()
231
+	{
232
+		if (empty(AllowedTags::$allowed_with_script_and_style_tags)) {
233
+			AllowedTags::initializeWithScriptAndStyleTags();
234
+		}
235
+		return AllowedTags::$allowed_with_script_and_style_tags;
236
+	}
237 237
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2796 added lines, -2796 removed lines patch added patch discarded remove patch
@@ -16,2803 +16,2803 @@
 block discarded – undo
16 16
 class Events_Admin_Page extends EE_Admin_Page_CPT
17 17
 {
18 18
 
19
-    /**
20
-     * This will hold the event object for event_details screen.
19
+	/**
20
+	 * This will hold the event object for event_details screen.
21
+	 *
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+	/**
44
+	 * @var EE_Event
45
+	 */
46
+	protected $_cpt_model_obj = false;
47
+
48
+
49
+	/**
50
+	 * @var NodeGroupDao
51
+	 */
52
+	protected $model_obj_node_group_persister;
53
+
54
+
55
+	/**
56
+	 * Initialize page props for this admin page group.
57
+	 */
58
+	protected function _init_page_props()
59
+	{
60
+		$this->page_slug        = EVENTS_PG_SLUG;
61
+		$this->page_label       = EVENTS_LABEL;
62
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
63
+		$this->_admin_base_path = EVENTS_ADMIN;
64
+		$this->_cpt_model_names = [
65
+			'create_new' => 'EEM_Event',
66
+			'edit'       => 'EEM_Event',
67
+		];
68
+		$this->_cpt_edit_routes = [
69
+			'espresso_events' => 'edit',
70
+		];
71
+		add_action(
72
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
+			[$this, 'verify_event_edit'],
74
+			10,
75
+			2
76
+		);
77
+	}
78
+
79
+
80
+	/**
81
+	 * Sets the ajax hooks used for this admin page group.
82
+	 */
83
+	protected function _ajax_hooks()
84
+	{
85
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
+	}
87
+
88
+
89
+	/**
90
+	 * Sets the page properties for this admin page group.
91
+	 */
92
+	protected function _define_page_props()
93
+	{
94
+		$this->_admin_page_title = EVENTS_LABEL;
95
+		$this->_labels           = [
96
+			'buttons'      => [
97
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
98
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
+			],
104
+			'editor_title' => [
105
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
+			],
107
+			'publishbox'   => [
108
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
110
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
+			],
114
+		];
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets the page routes property for this admin page group.
120
+	 */
121
+	protected function _set_page_routes()
122
+	{
123
+		// load formatter helper
124
+		// load field generator helper
125
+		// is there a evt_id in the request?
126
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
+
129
+		$this->_page_routes = [
130
+			'default'                       => [
131
+				'func'       => '_events_overview_list_table',
132
+				'capability' => 'ee_read_events',
133
+			],
134
+			'create_new'                    => [
135
+				'func'       => '_create_new_cpt_item',
136
+				'capability' => 'ee_edit_events',
137
+			],
138
+			'edit'                          => [
139
+				'func'       => '_edit_cpt_item',
140
+				'capability' => 'ee_edit_event',
141
+				'obj_id'     => $EVT_ID,
142
+			],
143
+			'copy_event'                    => [
144
+				'func'       => '_copy_events',
145
+				'capability' => 'ee_edit_event',
146
+				'obj_id'     => $EVT_ID,
147
+				'noheader'   => true,
148
+			],
149
+			'trash_event'                   => [
150
+				'func'       => '_trash_or_restore_event',
151
+				'args'       => ['event_status' => 'trash'],
152
+				'capability' => 'ee_delete_event',
153
+				'obj_id'     => $EVT_ID,
154
+				'noheader'   => true,
155
+			],
156
+			'trash_events'                  => [
157
+				'func'       => '_trash_or_restore_events',
158
+				'args'       => ['event_status' => 'trash'],
159
+				'capability' => 'ee_delete_events',
160
+				'noheader'   => true,
161
+			],
162
+			'restore_event'                 => [
163
+				'func'       => '_trash_or_restore_event',
164
+				'args'       => ['event_status' => 'draft'],
165
+				'capability' => 'ee_delete_event',
166
+				'obj_id'     => $EVT_ID,
167
+				'noheader'   => true,
168
+			],
169
+			'restore_events'                => [
170
+				'func'       => '_trash_or_restore_events',
171
+				'args'       => ['event_status' => 'draft'],
172
+				'capability' => 'ee_delete_events',
173
+				'noheader'   => true,
174
+			],
175
+			'delete_event'                  => [
176
+				'func'       => '_delete_event',
177
+				'capability' => 'ee_delete_event',
178
+				'obj_id'     => $EVT_ID,
179
+				'noheader'   => true,
180
+			],
181
+			'delete_events'                 => [
182
+				'func'       => '_delete_events',
183
+				'capability' => 'ee_delete_events',
184
+				'noheader'   => true,
185
+			],
186
+			'view_report'                   => [
187
+				'func'       => '_view_report',
188
+				'capability' => 'ee_edit_events',
189
+			],
190
+			'default_event_settings'        => [
191
+				'func'       => '_default_event_settings',
192
+				'capability' => 'manage_options',
193
+			],
194
+			'update_default_event_settings' => [
195
+				'func'       => '_update_default_event_settings',
196
+				'capability' => 'manage_options',
197
+				'noheader'   => true,
198
+			],
199
+			'template_settings'             => [
200
+				'func'       => '_template_settings',
201
+				'capability' => 'manage_options',
202
+			],
203
+			// event category tab related
204
+			'add_category'                  => [
205
+				'func'       => '_category_details',
206
+				'capability' => 'ee_edit_event_category',
207
+				'args'       => ['add'],
208
+			],
209
+			'edit_category'                 => [
210
+				'func'       => '_category_details',
211
+				'capability' => 'ee_edit_event_category',
212
+				'args'       => ['edit'],
213
+			],
214
+			'delete_categories'             => [
215
+				'func'       => '_delete_categories',
216
+				'capability' => 'ee_delete_event_category',
217
+				'noheader'   => true,
218
+			],
219
+			'delete_category'               => [
220
+				'func'       => '_delete_categories',
221
+				'capability' => 'ee_delete_event_category',
222
+				'noheader'   => true,
223
+			],
224
+			'insert_category'               => [
225
+				'func'       => '_insert_or_update_category',
226
+				'args'       => ['new_category' => true],
227
+				'capability' => 'ee_edit_event_category',
228
+				'noheader'   => true,
229
+			],
230
+			'update_category'               => [
231
+				'func'       => '_insert_or_update_category',
232
+				'args'       => ['new_category' => false],
233
+				'capability' => 'ee_edit_event_category',
234
+				'noheader'   => true,
235
+			],
236
+			'category_list'                 => [
237
+				'func'       => '_category_list_table',
238
+				'capability' => 'ee_manage_event_categories',
239
+			],
240
+			'preview_deletion'              => [
241
+				'func'       => 'previewDeletion',
242
+				'capability' => 'ee_delete_events',
243
+			],
244
+			'confirm_deletion'              => [
245
+				'func'       => 'confirmDeletion',
246
+				'capability' => 'ee_delete_events',
247
+				'noheader'   => true,
248
+			],
249
+		];
250
+	}
251
+
252
+
253
+	/**
254
+	 * Set the _page_config property for this admin page group.
255
+	 */
256
+	protected function _set_page_config()
257
+	{
258
+		$post_id            = $this->request->getRequestParam('post', 0, 'int');
259
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
+		$this->_page_config = [
261
+			'default'                => [
262
+				'nav'           => [
263
+					'label' => esc_html__('Overview', 'event_espresso'),
264
+					'order' => 10,
265
+				],
266
+				'list_table'    => 'Events_Admin_List_Table',
267
+				'help_tabs'     => [
268
+					'events_overview_help_tab'                       => [
269
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
270
+						'filename' => 'events_overview',
271
+					],
272
+					'events_overview_table_column_headings_help_tab' => [
273
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
+						'filename' => 'events_overview_table_column_headings',
275
+					],
276
+					'events_overview_filters_help_tab'               => [
277
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
+						'filename' => 'events_overview_filters',
279
+					],
280
+					'events_overview_view_help_tab'                  => [
281
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
+						'filename' => 'events_overview_views',
283
+					],
284
+					'events_overview_other_help_tab'                 => [
285
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
+						'filename' => 'events_overview_other',
287
+					],
288
+				],
289
+				'qtips'         => [
290
+					'EE_Event_List_Table_Tips',
291
+				],
292
+				'require_nonce' => false,
293
+			],
294
+			'create_new'             => [
295
+				'nav'           => [
296
+					'label'      => esc_html__('Add Event', 'event_espresso'),
297
+					'order'      => 5,
298
+					'persistent' => false,
299
+				],
300
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
301
+				'help_tabs'     => [
302
+					'event_editor_help_tab'                            => [
303
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
304
+						'filename' => 'event_editor',
305
+					],
306
+					'event_editor_title_richtexteditor_help_tab'       => [
307
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
308
+						'filename' => 'event_editor_title_richtexteditor',
309
+					],
310
+					'event_editor_venue_details_help_tab'              => [
311
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
312
+						'filename' => 'event_editor_venue_details',
313
+					],
314
+					'event_editor_event_datetimes_help_tab'            => [
315
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
316
+						'filename' => 'event_editor_event_datetimes',
317
+					],
318
+					'event_editor_event_tickets_help_tab'              => [
319
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
320
+						'filename' => 'event_editor_event_tickets',
321
+					],
322
+					'event_editor_event_registration_options_help_tab' => [
323
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
324
+						'filename' => 'event_editor_event_registration_options',
325
+					],
326
+					'event_editor_tags_categories_help_tab'            => [
327
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
328
+						'filename' => 'event_editor_tags_categories',
329
+					],
330
+					'event_editor_questions_registrants_help_tab'      => [
331
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
332
+						'filename' => 'event_editor_questions_registrants',
333
+					],
334
+					'event_editor_save_new_event_help_tab'             => [
335
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
336
+						'filename' => 'event_editor_save_new_event',
337
+					],
338
+					'event_editor_other_help_tab'                      => [
339
+						'title'    => esc_html__('Event Other', 'event_espresso'),
340
+						'filename' => 'event_editor_other',
341
+					],
342
+				],
343
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
344
+				'require_nonce' => false,
345
+			],
346
+			'edit'                   => [
347
+				'nav'           => [
348
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
349
+					'order'      => 5,
350
+					'persistent' => false,
351
+					'url'        => $post_id
352
+						? EE_Admin_Page::add_query_args_and_nonce(
353
+							['post' => $post_id, 'action' => 'edit'],
354
+							$this->_current_page_view_url
355
+						)
356
+						: $this->_admin_base_url,
357
+				],
358
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
359
+				'help_tabs'     => [
360
+					'event_editor_help_tab'                            => [
361
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
362
+						'filename' => 'event_editor',
363
+					],
364
+					'event_editor_title_richtexteditor_help_tab'       => [
365
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
366
+						'filename' => 'event_editor_title_richtexteditor',
367
+					],
368
+					'event_editor_venue_details_help_tab'              => [
369
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
370
+						'filename' => 'event_editor_venue_details',
371
+					],
372
+					'event_editor_event_datetimes_help_tab'            => [
373
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
374
+						'filename' => 'event_editor_event_datetimes',
375
+					],
376
+					'event_editor_event_tickets_help_tab'              => [
377
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
378
+						'filename' => 'event_editor_event_tickets',
379
+					],
380
+					'event_editor_event_registration_options_help_tab' => [
381
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
382
+						'filename' => 'event_editor_event_registration_options',
383
+					],
384
+					'event_editor_tags_categories_help_tab'            => [
385
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
386
+						'filename' => 'event_editor_tags_categories',
387
+					],
388
+					'event_editor_questions_registrants_help_tab'      => [
389
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
390
+						'filename' => 'event_editor_questions_registrants',
391
+					],
392
+					'event_editor_save_new_event_help_tab'             => [
393
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
394
+						'filename' => 'event_editor_save_new_event',
395
+					],
396
+					'event_editor_other_help_tab'                      => [
397
+						'title'    => esc_html__('Event Other', 'event_espresso'),
398
+						'filename' => 'event_editor_other',
399
+					],
400
+				],
401
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
402
+				'require_nonce' => false,
403
+			],
404
+			'default_event_settings' => [
405
+				'nav'           => [
406
+					'label' => esc_html__('Default Settings', 'event_espresso'),
407
+					'order' => 40,
408
+				],
409
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
410
+				'labels'        => [
411
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
412
+				],
413
+				'help_tabs'     => [
414
+					'default_settings_help_tab'        => [
415
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
416
+						'filename' => 'events_default_settings',
417
+					],
418
+					'default_settings_status_help_tab' => [
419
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
420
+						'filename' => 'events_default_settings_status',
421
+					],
422
+					'default_maximum_tickets_help_tab' => [
423
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
424
+						'filename' => 'events_default_settings_max_tickets',
425
+					],
426
+				],
427
+				'require_nonce' => false,
428
+			],
429
+			// template settings
430
+			'template_settings'      => [
431
+				'nav'           => [
432
+					'label' => esc_html__('Templates', 'event_espresso'),
433
+					'order' => 30,
434
+				],
435
+				'metaboxes'     => $this->_default_espresso_metaboxes,
436
+				'help_tabs'     => [
437
+					'general_settings_templates_help_tab' => [
438
+						'title'    => esc_html__('Templates', 'event_espresso'),
439
+						'filename' => 'general_settings_templates',
440
+					],
441
+				],
442
+				'require_nonce' => false,
443
+			],
444
+			// event category stuff
445
+			'add_category'           => [
446
+				'nav'           => [
447
+					'label'      => esc_html__('Add Category', 'event_espresso'),
448
+					'order'      => 15,
449
+					'persistent' => false,
450
+				],
451
+				'help_tabs'     => [
452
+					'add_category_help_tab' => [
453
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
454
+						'filename' => 'events_add_category',
455
+					],
456
+				],
457
+				'metaboxes'     => ['_publish_post_box'],
458
+				'require_nonce' => false,
459
+			],
460
+			'edit_category'          => [
461
+				'nav'           => [
462
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
463
+					'order'      => 15,
464
+					'persistent' => false,
465
+					'url'        => $EVT_CAT_ID
466
+						? add_query_arg(
467
+							['EVT_CAT_ID' => $EVT_CAT_ID],
468
+							$this->_current_page_view_url
469
+						)
470
+						: $this->_admin_base_url,
471
+				],
472
+				'help_tabs'     => [
473
+					'edit_category_help_tab' => [
474
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
475
+						'filename' => 'events_edit_category',
476
+					],
477
+				],
478
+				'metaboxes'     => ['_publish_post_box'],
479
+				'require_nonce' => false,
480
+			],
481
+			'category_list'          => [
482
+				'nav'           => [
483
+					'label' => esc_html__('Categories', 'event_espresso'),
484
+					'order' => 20,
485
+				],
486
+				'list_table'    => 'Event_Categories_Admin_List_Table',
487
+				'help_tabs'     => [
488
+					'events_categories_help_tab'                       => [
489
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
490
+						'filename' => 'events_categories',
491
+					],
492
+					'events_categories_table_column_headings_help_tab' => [
493
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
494
+						'filename' => 'events_categories_table_column_headings',
495
+					],
496
+					'events_categories_view_help_tab'                  => [
497
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
498
+						'filename' => 'events_categories_views',
499
+					],
500
+					'events_categories_other_help_tab'                 => [
501
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
502
+						'filename' => 'events_categories_other',
503
+					],
504
+				],
505
+				'metaboxes'     => $this->_default_espresso_metaboxes,
506
+				'require_nonce' => false,
507
+			],
508
+			'preview_deletion'       => [
509
+				'nav'           => [
510
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
511
+					'order'      => 15,
512
+					'persistent' => false,
513
+					'url'        => '',
514
+				],
515
+				'require_nonce' => false,
516
+			],
517
+		];
518
+	}
519
+
520
+
521
+	/**
522
+	 * Used to register any global screen options if necessary for every route in this admin page group.
523
+	 */
524
+	protected function _add_screen_options()
525
+	{
526
+	}
527
+
528
+
529
+	/**
530
+	 * Implementing the screen options for the 'default' route.
531
+	 */
532
+	protected function _add_screen_options_default()
533
+	{
534
+		$this->_per_page_screen_option();
535
+	}
536
+
537
+
538
+	/**
539
+	 * Implementing screen options for the category list route.
540
+	 */
541
+	protected function _add_screen_options_category_list()
542
+	{
543
+		$page_title              = $this->_admin_page_title;
544
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
545
+		$this->_per_page_screen_option();
546
+		$this->_admin_page_title = $page_title;
547
+	}
548
+
549
+
550
+	/**
551
+	 * Used to register any global feature pointers for the admin page group.
552
+	 */
553
+	protected function _add_feature_pointers()
554
+	{
555
+	}
556
+
557
+
558
+	/**
559
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
560
+	 */
561
+	public function load_scripts_styles()
562
+	{
563
+		wp_register_style(
564
+			'events-admin-css',
565
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
566
+			[],
567
+			EVENT_ESPRESSO_VERSION
568
+		);
569
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
570
+		wp_enqueue_style('events-admin-css');
571
+		wp_enqueue_style('ee-cat-admin');
572
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
573
+		// registers for all views
574
+		// scripts
575
+		wp_register_script(
576
+			'event_editor_js',
577
+			EVENTS_ASSETS_URL . 'event_editor.js',
578
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
579
+			EVENT_ESPRESSO_VERSION,
580
+			true
581
+		);
582
+	}
583
+
584
+
585
+	/**
586
+	 * Enqueuing scripts and styles specific to this view
587
+	 */
588
+	public function load_scripts_styles_create_new()
589
+	{
590
+		$this->load_scripts_styles_edit();
591
+	}
592
+
593
+
594
+	/**
595
+	 * Enqueuing scripts and styles specific to this view
596
+	 */
597
+	public function load_scripts_styles_edit()
598
+	{
599
+		// styles
600
+		wp_enqueue_style('espresso-ui-theme');
601
+		wp_register_style(
602
+			'event-editor-css',
603
+			EVENTS_ASSETS_URL . 'event-editor.css',
604
+			['ee-admin-css'],
605
+			EVENT_ESPRESSO_VERSION
606
+		);
607
+		wp_enqueue_style('event-editor-css');
608
+		// scripts
609
+		wp_register_script(
610
+			'event-datetime-metabox',
611
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
612
+			['event_editor_js', 'ee-datepicker'],
613
+			EVENT_ESPRESSO_VERSION
614
+		);
615
+		wp_enqueue_script('event-datetime-metabox');
616
+	}
617
+
618
+
619
+	/**
620
+	 * Populating the _views property for the category list table view.
621
+	 */
622
+	protected function _set_list_table_views_category_list()
623
+	{
624
+		$this->_views = [
625
+			'all' => [
626
+				'slug'        => 'all',
627
+				'label'       => esc_html__('All', 'event_espresso'),
628
+				'count'       => 0,
629
+				'bulk_action' => [
630
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
631
+				],
632
+			],
633
+		];
634
+	}
635
+
636
+
637
+	/**
638
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
639
+	 */
640
+	public function admin_init()
641
+	{
642
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
643
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
644
+			'event_espresso'
645
+		);
646
+	}
647
+
648
+
649
+	/**
650
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
651
+	 * group.
652
+	 */
653
+	public function admin_notices()
654
+	{
655
+	}
656
+
657
+
658
+	/**
659
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
660
+	 * this admin page group.
661
+	 */
662
+	public function admin_footer_scripts()
663
+	{
664
+	}
665
+
666
+
667
+	/**
668
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
669
+	 * warning (via EE_Error::add_error());
670
+	 *
671
+	 * @param EE_Event $event Event object
672
+	 * @param string   $req_type
673
+	 * @return void
674
+	 * @throws EE_Error
675
+	 * @throws ReflectionException
676
+	 */
677
+	public function verify_event_edit($event = null, $req_type = '')
678
+	{
679
+		// don't need to do this when processing
680
+		if (! empty($req_type)) {
681
+			return;
682
+		}
683
+		// no event?
684
+		if (empty($event)) {
685
+			// set event
686
+			$event = $this->_cpt_model_obj;
687
+		}
688
+		// STILL no event?
689
+		if (! $event instanceof EE_Event) {
690
+			return;
691
+		}
692
+		$orig_status = $event->status();
693
+		// first check if event is active.
694
+		if (
695
+			$orig_status === EEM_Event::cancelled
696
+			|| $orig_status === EEM_Event::postponed
697
+			|| $event->is_expired()
698
+			|| $event->is_inactive()
699
+		) {
700
+			return;
701
+		}
702
+		// made it here so it IS active... next check that any of the tickets are sold.
703
+		if ($event->is_sold_out(true)) {
704
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
705
+				EE_Error::add_attention(
706
+					sprintf(
707
+						esc_html__(
708
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
709
+							'event_espresso'
710
+						),
711
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
712
+					)
713
+				);
714
+			}
715
+			return;
716
+		} elseif ($orig_status === EEM_Event::sold_out) {
717
+			EE_Error::add_attention(
718
+				sprintf(
719
+					esc_html__(
720
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
721
+						'event_espresso'
722
+					),
723
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
724
+				)
725
+			);
726
+		}
727
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
728
+		if (! $event->tickets_on_sale()) {
729
+			return;
730
+		}
731
+		// made it here so show warning
732
+		$this->_edit_event_warning();
733
+	}
734
+
735
+
736
+	/**
737
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
738
+	 * When needed, hook this into a EE_Error::add_error() notice.
739
+	 *
740
+	 * @access protected
741
+	 * @return void
742
+	 */
743
+	protected function _edit_event_warning()
744
+	{
745
+		// we don't want to add warnings during these requests
746
+		if ($this->request->getRequestParam('action') === 'editpost') {
747
+			return;
748
+		}
749
+		EE_Error::add_attention(
750
+			sprintf(
751
+				esc_html__(
752
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
753
+					'event_espresso'
754
+				),
755
+				'<a class="espresso-help-tab-lnk">',
756
+				'</a>'
757
+			)
758
+		);
759
+	}
760
+
761
+
762
+	/**
763
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
764
+	 * Otherwise, do the normal logic
765
+	 *
766
+	 * @return void
767
+	 * @throws EE_Error
768
+	 */
769
+	protected function _create_new_cpt_item()
770
+	{
771
+		$has_timezone_string = get_option('timezone_string');
772
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
773
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
774
+			EE_Error::add_attention(
775
+				sprintf(
776
+					esc_html__(
777
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
778
+						'event_espresso'
779
+					),
780
+					'<br>',
781
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
782
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
783
+					. '</select>',
784
+					'<button class="button button-secondary timezone-submit">',
785
+					'</button><span class="spinner"></span>'
786
+				),
787
+				__FILE__,
788
+				__FUNCTION__,
789
+				__LINE__
790
+			);
791
+		}
792
+		parent::_create_new_cpt_item();
793
+	}
794
+
795
+
796
+	/**
797
+	 * Sets the _views property for the default route in this admin page group.
798
+	 */
799
+	protected function _set_list_table_views_default()
800
+	{
801
+		$this->_views = [
802
+			'all'   => [
803
+				'slug'        => 'all',
804
+				'label'       => esc_html__('View All Events', 'event_espresso'),
805
+				'count'       => 0,
806
+				'bulk_action' => [
807
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
808
+				],
809
+			],
810
+			'draft' => [
811
+				'slug'        => 'draft',
812
+				'label'       => esc_html__('Draft', 'event_espresso'),
813
+				'count'       => 0,
814
+				'bulk_action' => [
815
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
816
+				],
817
+			],
818
+		];
819
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
820
+			$this->_views['trash'] = [
821
+				'slug'        => 'trash',
822
+				'label'       => esc_html__('Trash', 'event_espresso'),
823
+				'count'       => 0,
824
+				'bulk_action' => [
825
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
826
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
827
+				],
828
+			];
829
+		}
830
+	}
831
+
832
+
833
+	/**
834
+	 * Provides the legend item array for the default list table view.
835
+	 *
836
+	 * @return array
837
+	 * @throws EE_Error
838
+	 * @throws EE_Error
839
+	 */
840
+	protected function _event_legend_items()
841
+	{
842
+		$items    = [
843
+			'view_details'   => [
844
+				'class' => 'dashicons dashicons-search',
845
+				'desc'  => esc_html__('View Event', 'event_espresso'),
846
+			],
847
+			'edit_event'     => [
848
+				'class' => 'ee-icon ee-icon-calendar-edit',
849
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
850
+			],
851
+			'view_attendees' => [
852
+				'class' => 'dashicons dashicons-groups',
853
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
854
+			],
855
+		];
856
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
857
+		$statuses = [
858
+			'sold_out_status'  => [
859
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
860
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
861
+			],
862
+			'active_status'    => [
863
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
864
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
865
+			],
866
+			'upcoming_status'  => [
867
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
868
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
869
+			],
870
+			'postponed_status' => [
871
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
872
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
873
+			],
874
+			'cancelled_status' => [
875
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
876
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
877
+			],
878
+			'expired_status'   => [
879
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
880
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
881
+			],
882
+			'inactive_status'  => [
883
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
884
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
885
+			],
886
+		];
887
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
888
+		return array_merge($items, $statuses);
889
+	}
890
+
891
+
892
+	/**
893
+	 * @return EEM_Event
894
+	 * @throws EE_Error
895
+	 * @throws ReflectionException
896
+	 */
897
+	private function _event_model()
898
+	{
899
+		if (! $this->_event_model instanceof EEM_Event) {
900
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
901
+		}
902
+		return $this->_event_model;
903
+	}
904
+
905
+
906
+	/**
907
+	 * Adds extra buttons to the WP CPT permalink field row.
908
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
909
+	 *
910
+	 * @param string $return    the current html
911
+	 * @param int    $id        the post id for the page
912
+	 * @param string $new_title What the title is
913
+	 * @param string $new_slug  what the slug is
914
+	 * @return string            The new html string for the permalink area
915
+	 */
916
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
917
+	{
918
+		// make sure this is only when editing
919
+		if (! empty($id)) {
920
+			$post   = get_post($id);
921
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
922
+					   . esc_html__('Shortcode', 'event_espresso')
923
+					   . '</a> ';
924
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
925
+					   . $post->ID
926
+					   . ']">';
927
+		}
928
+		return $return;
929
+	}
930
+
931
+
932
+	/**
933
+	 * _events_overview_list_table
934
+	 * This contains the logic for showing the events_overview list
935
+	 *
936
+	 * @access protected
937
+	 * @return void
938
+	 * @throws EE_Error
939
+	 */
940
+	protected function _events_overview_list_table()
941
+	{
942
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
943
+		$this->_template_args['after_list_table']                           =
944
+			! empty($this->_template_args['after_list_table'])
945
+				? (array) $this->_template_args['after_list_table']
946
+				: [];
947
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
948
+			. EEH_Template::get_button_or_link(
949
+				get_post_type_archive_link('espresso_events'),
950
+				esc_html__("View Event Archive Page", "event_espresso"),
951
+				'button'
952
+			);
953
+		$this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
954
+			$this->_event_legend_items()
955
+		);
956
+		$this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
957
+			'create_new',
958
+			'add',
959
+			[],
960
+			'add-new-h2'
961
+		);
962
+		$this->display_admin_list_table_page_with_no_sidebar();
963
+	}
964
+
965
+
966
+	/**
967
+	 * this allows for extra misc actions in the default WP publish box
968
+	 *
969
+	 * @return void
970
+	 * @throws EE_Error
971
+	 * @throws ReflectionException
972
+	 */
973
+	public function extra_misc_actions_publish_box()
974
+	{
975
+		$this->_generate_publish_box_extra_content();
976
+	}
977
+
978
+
979
+	/**
980
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
981
+	 * saved.
982
+	 * Typically you would use this to save any additional data.
983
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
984
+	 * ALSO very important.  When a post transitions from scheduled to published,
985
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
986
+	 * other meta saves. So MAKE sure that you handle this accordingly.
987
+	 *
988
+	 * @access protected
989
+	 * @abstract
990
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
991
+	 * @param WP_Post $post    The post object of the cpt that was saved.
992
+	 * @return void
993
+	 * @throws EE_Error
994
+	 * @throws ReflectionException
995
+	 */
996
+	protected function _insert_update_cpt_item($post_id, $post)
997
+	{
998
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
999
+			// get out we're not processing an event save.
1000
+			return;
1001
+		}
1002
+
1003
+		$event_values = [
1004
+			'EVT_display_desc'                => $this->request->getRequestParam('display_desc', false, 'bool'),
1005
+			'EVT_display_ticket_selector'     => $this->request->getRequestParam(
1006
+				'display_ticket_selector',
1007
+				false,
1008
+				'bool'
1009
+			),
1010
+			'EVT_additional_limit'            => min(
1011
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1012
+				$this->request->getRequestParam('additional_limit', null, 'int')
1013
+			),
1014
+			'EVT_default_registration_status' => $this->request->getRequestParam(
1015
+				'EVT_default_registration_status',
1016
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1017
+			),
1018
+
1019
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1020
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1021
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1022
+			'EVT_external_URL'    => $this->request->getRequestParam('externalURL'),
1023
+			'EVT_phone'           => $this->request->getRequestParam('event_phone'),
1024
+		];
1025
+		// update event
1026
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1027
+		// get event_object for other metaboxes...
1028
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1029
+		// i have to setup where conditions to override the filters in the model
1030
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1031
+		$event = $this->_event_model()->get_one(
1032
+			[
1033
+				[
1034
+					$this->_event_model()->primary_key_name() => $post_id,
1035
+					'OR'                                      => [
1036
+						'status'   => $post->post_status,
1037
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1038
+						// but the returned object here has a status of "publish", so use the original post status as well
1039
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1040
+					],
1041
+				],
1042
+			]
1043
+		);
1044
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1045
+		$event_update_callbacks = apply_filters(
1046
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1047
+			[
1048
+				[$this, '_default_venue_update'],
1049
+				[$this, '_default_tickets_update'],
1050
+			]
1051
+		);
1052
+		$att_success            = true;
1053
+		foreach ($event_update_callbacks as $e_callback) {
1054
+			$_success = is_callable($e_callback)
1055
+				? call_user_func($e_callback, $event, $this->request->requestParams())
1056
+				: false;
1057
+			// if ANY of these updates fail then we want the appropriate global error message
1058
+			$att_success = ! $att_success ? $att_success : $_success;
1059
+		}
1060
+		// any errors?
1061
+		if ($success && false === $att_success) {
1062
+			EE_Error::add_error(
1063
+				esc_html__(
1064
+					'Event Details saved successfully but something went wrong with saving attachments.',
1065
+					'event_espresso'
1066
+				),
1067
+				__FILE__,
1068
+				__FUNCTION__,
1069
+				__LINE__
1070
+			);
1071
+		} elseif ($success === false) {
1072
+			EE_Error::add_error(
1073
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1074
+				__FILE__,
1075
+				__FUNCTION__,
1076
+				__LINE__
1077
+			);
1078
+		}
1079
+	}
1080
+
1081
+
1082
+	/**
1083
+	 * @param int $post_id
1084
+	 * @param int $revision_id
1085
+	 * @throws EE_Error
1086
+	 * @throws EE_Error
1087
+	 * @throws ReflectionException
1088
+	 * @see parent::restore_item()
1089
+	 */
1090
+	protected function _restore_cpt_item($post_id, $revision_id)
1091
+	{
1092
+		// copy existing event meta to new post
1093
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1094
+		if ($post_evt instanceof EE_Event) {
1095
+			// meta revision restore
1096
+			$post_evt->restore_revision($revision_id);
1097
+			// related objs restore
1098
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1099
+		}
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * Attach the venue to the Event
1105
+	 *
1106
+	 * @param EE_Event $event Event Object to add the venue to
1107
+	 * @param array    $data  The request data from the form
1108
+	 * @return bool           Success or fail.
1109
+	 * @throws EE_Error
1110
+	 * @throws ReflectionException
1111
+	 */
1112
+	protected function _default_venue_update(EE_Event $event, $data)
1113
+	{
1114
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1115
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1116
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1117
+		// very important.  If we don't have a venue name...
1118
+		// then we'll get out because not necessary to create empty venue
1119
+		if (empty($data['venue_title'])) {
1120
+			return false;
1121
+		}
1122
+		$venue_array = [
1123
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1124
+			'VNU_name'            => $data['venue_title'],
1125
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1126
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1127
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1128
+				? $data['venue_short_description']
1129
+				: null,
1130
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1131
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1132
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1133
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1134
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1135
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1136
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1137
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1138
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1139
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1140
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1141
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1142
+			'status'              => 'publish',
1143
+		];
1144
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1145
+		if (! empty($venue_id)) {
1146
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1147
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1148
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1149
+			$event->_add_relation_to($venue_id, 'Venue');
1150
+			return $rows_affected > 0;
1151
+		}
1152
+		// we insert the venue
1153
+		$venue_id = $venue_model->insert($venue_array);
1154
+		$event->_add_relation_to($venue_id, 'Venue');
1155
+		return ! empty($venue_id);
1156
+		// when we have the ancestor come in it's already been handled by the revision save.
1157
+	}
1158
+
1159
+
1160
+	/**
1161
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1162
+	 *
1163
+	 * @param EE_Event $event The Event object we're attaching data to
1164
+	 * @param array    $data  The request data from the form
1165
+	 * @return array
1166
+	 * @throws EE_Error
1167
+	 * @throws ReflectionException
1168
+	 * @throws Exception
1169
+	 */
1170
+	protected function _default_tickets_update(EE_Event $event, $data)
1171
+	{
1172
+		$datetime       = null;
1173
+		$saved_tickets  = [];
1174
+		$event_timezone = $event->get_timezone();
1175
+		$date_formats   = ['Y-m-d', 'h:i a'];
1176
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1177
+			// trim all values to ensure any excess whitespace is removed.
1178
+			$datetime_data                = array_map('trim', $datetime_data);
1179
+			$datetime_data['DTT_EVT_end'] =
1180
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1181
+					? $datetime_data['DTT_EVT_end']
1182
+					: $datetime_data['DTT_EVT_start'];
1183
+			$datetime_values              = [
1184
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1185
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1186
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1187
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1188
+				'DTT_order'     => $row,
1189
+			];
1190
+			// if we have an id then let's get existing object first and then set the new values.
1191
+			//  Otherwise we instantiate a new object for save.
1192
+			if (! empty($datetime_data['DTT_ID'])) {
1193
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1194
+				if (! $datetime instanceof EE_Datetime) {
1195
+					throw new RuntimeException(
1196
+						sprintf(
1197
+							esc_html__(
1198
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1199
+								'event_espresso'
1200
+							),
1201
+							$datetime_data['DTT_ID']
1202
+						)
1203
+					);
1204
+				}
1205
+				$datetime->set_date_format($date_formats[0]);
1206
+				$datetime->set_time_format($date_formats[1]);
1207
+				foreach ($datetime_values as $field => $value) {
1208
+					$datetime->set($field, $value);
1209
+				}
1210
+			} else {
1211
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1212
+			}
1213
+			if (! $datetime instanceof EE_Datetime) {
1214
+				throw new RuntimeException(
1215
+					sprintf(
1216
+						esc_html__(
1217
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1218
+							'event_espresso'
1219
+						),
1220
+						print_r($datetime_values, true)
1221
+					)
1222
+				);
1223
+			}
1224
+			// before going any further make sure our dates are setup correctly
1225
+			// so that the end date is always equal or greater than the start date.
1226
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1227
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1228
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1229
+			}
1230
+			$datetime->save();
1231
+			$event->_add_relation_to($datetime, 'Datetime');
1232
+		}
1233
+		// no datetimes get deleted so we don't do any of that logic here.
1234
+		// update tickets next
1235
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1236
+
1237
+		// set up some default start and end dates in case those are not present in the incoming data
1238
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1239
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1240
+		// use the start date of the first datetime for the end date
1241
+		$first_datetime   = $event->first_datetime();
1242
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1243
+
1244
+		// now process the incoming data
1245
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1246
+			$update_prices = false;
1247
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1248
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1249
+				: 0;
1250
+			// trim inputs to ensure any excess whitespace is removed.
1251
+			$ticket_data   = array_map('trim', $ticket_data);
1252
+			$ticket_values = [
1253
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1254
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1255
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1256
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1257
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1258
+					? $ticket_data['TKT_start_date']
1259
+					: $default_start_date,
1260
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1261
+					? $ticket_data['TKT_end_date']
1262
+					: $default_end_date,
1263
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1264
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1265
+					? $ticket_data['TKT_qty']
1266
+					: EE_INF,
1267
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1268
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1269
+					? $ticket_data['TKT_uses']
1270
+					: EE_INF,
1271
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1272
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1273
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1274
+				'TKT_price'       => $ticket_price,
1275
+				'TKT_row'         => $row,
1276
+			];
1277
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1278
+			// which means in turn that the prices will become new prices as well.
1279
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1280
+				$ticket_values['TKT_ID']         = 0;
1281
+				$ticket_values['TKT_is_default'] = 0;
1282
+				$update_prices                   = true;
1283
+			}
1284
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1285
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1286
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1287
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1288
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1289
+			if (! empty($ticket_data['TKT_ID'])) {
1290
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1291
+				if (! $existing_ticket instanceof EE_Ticket) {
1292
+					throw new RuntimeException(
1293
+						sprintf(
1294
+							esc_html__(
1295
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1296
+								'event_espresso'
1297
+							),
1298
+							$ticket_data['TKT_ID']
1299
+						)
1300
+					);
1301
+				}
1302
+				$ticket_sold = $existing_ticket->count_related(
1303
+					'Registration',
1304
+					[
1305
+						[
1306
+							'STS_ID' => [
1307
+								'NOT IN',
1308
+								[EEM_Registration::status_id_incomplete],
1309
+							],
1310
+						],
1311
+					]
1312
+				) > 0;
1313
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1314
+				// if they are different then we create a new ticket (if $ticket_sold)
1315
+				// if they aren't different then we go ahead and modify existing ticket.
1316
+				$create_new_ticket = $ticket_sold
1317
+									 && $ticket_price !== $existing_ticket->price()
1318
+									 && ! $existing_ticket->deleted();
1319
+				$existing_ticket->set_date_format($date_formats[0]);
1320
+				$existing_ticket->set_time_format($date_formats[1]);
1321
+				// set new values
1322
+				foreach ($ticket_values as $field => $value) {
1323
+					if ($field == 'TKT_qty') {
1324
+						$existing_ticket->set_qty($value);
1325
+					} elseif ($field == 'TKT_price') {
1326
+						$existing_ticket->set('TKT_price', $ticket_price);
1327
+					} else {
1328
+						$existing_ticket->set($field, $value);
1329
+					}
1330
+				}
1331
+				$ticket = $existing_ticket;
1332
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1333
+				//  Otherwise we have to create a new ticket.
1334
+				if ($create_new_ticket) {
1335
+					// archive the old ticket first
1336
+					$existing_ticket->set('TKT_deleted', 1);
1337
+					$existing_ticket->save();
1338
+					// make sure this ticket is still recorded in our $saved_tickets
1339
+					// so we don't run it through the regular trash routine.
1340
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1341
+					// create new ticket that's a copy of the existing except,
1342
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1343
+					$new_ticket = clone $existing_ticket;
1344
+					$new_ticket->set('TKT_ID', 0);
1345
+					$new_ticket->set('TKT_deleted', 0);
1346
+					$new_ticket->set('TKT_sold', 0);
1347
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1348
+					$update_prices = true;
1349
+					$ticket        = $new_ticket;
1350
+				}
1351
+			} else {
1352
+				// no TKT_id so a new ticket
1353
+				$ticket_values['TKT_price'] = $ticket_price;
1354
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1355
+				$update_prices              = true;
1356
+			}
1357
+			if (! $ticket instanceof EE_Ticket) {
1358
+				throw new RuntimeException(
1359
+					sprintf(
1360
+						esc_html__(
1361
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1362
+							'event_espresso'
1363
+						),
1364
+						print_r($ticket_values, true)
1365
+					)
1366
+				);
1367
+			}
1368
+			// cap ticket qty by datetime reg limits
1369
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1370
+			// update ticket.
1371
+			$ticket->save();
1372
+			// before going any further make sure our dates are setup correctly
1373
+			// so that the end date is always equal or greater than the start date.
1374
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1375
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1376
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1377
+				$ticket->save();
1378
+			}
1379
+			// initially let's add the ticket to the datetime
1380
+			$datetime->_add_relation_to($ticket, 'Ticket');
1381
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1382
+			// add prices to ticket
1383
+			$prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1384
+				? $data['edit_prices'][ $row ]
1385
+				: [];
1386
+			$this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1387
+		}
1388
+		// however now we need to handle permanently deleting tickets via the ui.
1389
+		// Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1390
+		// However, it does allow for deleting tickets that have no tickets sold,
1391
+		// in which case we want to get rid of permanently because there is no need to save in db.
1392
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets;
1393
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1394
+		foreach ($tickets_removed as $id) {
1395
+			$id = absint($id);
1396
+			// get the ticket for this id
1397
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1398
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1399
+				continue;
1400
+			}
1401
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1402
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1403
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1404
+			foreach ($related_datetimes as $related_datetime) {
1405
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1406
+			}
1407
+			// need to do the same for prices (except these prices can also be deleted because again,
1408
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1409
+			$ticket_to_remove->delete_related_permanently('Price');
1410
+			// finally let's delete this ticket
1411
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1412
+			$ticket_to_remove->delete_permanently();
1413
+		}
1414
+		return [$datetime, $saved_tickets];
1415
+	}
1416
+
1417
+
1418
+	/**
1419
+	 * This attaches a list of given prices to a ticket.
1420
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1421
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1422
+	 * price info and prices are automatically "archived" via the ticket.
1423
+	 *
1424
+	 * @access  private
1425
+	 * @param array     $prices_data Array of prices from the form.
1426
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1427
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1428
+	 * @return  void
1429
+	 * @throws EE_Error
1430
+	 * @throws ReflectionException
1431
+	 */
1432
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1433
+	{
1434
+		$timezone = $ticket->get_timezone();
1435
+		foreach ($prices_data as $row => $price_data) {
1436
+			$price_values = [
1437
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1438
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1439
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1440
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1441
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1442
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1443
+				'PRC_order'      => $row,
1444
+			];
1445
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1446
+				$price_values['PRC_ID'] = 0;
1447
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1448
+			} else {
1449
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1450
+				// update this price with new values
1451
+				foreach ($price_values as $field => $new_price) {
1452
+					$price->set($field, $new_price);
1453
+				}
1454
+			}
1455
+			if (! $price instanceof EE_Price) {
1456
+				throw new RuntimeException(
1457
+					sprintf(
1458
+						esc_html__(
1459
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1460
+							'event_espresso'
1461
+						),
1462
+						print_r($price_values, true)
1463
+					)
1464
+				);
1465
+			}
1466
+			$price->save();
1467
+			$ticket->_add_relation_to($price, 'Price');
1468
+		}
1469
+	}
1470
+
1471
+
1472
+	/**
1473
+	 * Add in our autosave ajax handlers
1474
+	 *
1475
+	 */
1476
+	protected function _ee_autosave_create_new()
1477
+	{
1478
+	}
1479
+
1480
+
1481
+	/**
1482
+	 * More autosave handlers.
1483
+	 */
1484
+	protected function _ee_autosave_edit()
1485
+	{
1486
+		// TEMPORARILY EXITING CAUSE THIS IS A TODO
1487
+	}
1488
+
1489
+
1490
+	/**
1491
+	 * @throws EE_Error
1492
+	 * @throws ReflectionException
1493
+	 */
1494
+	private function _generate_publish_box_extra_content()
1495
+	{
1496
+		// load formatter helper
1497
+		// args for getting related registrations
1498
+		$approved_query_args        = [
1499
+			[
1500
+				'REG_deleted' => 0,
1501
+				'STS_ID'      => EEM_Registration::status_id_approved,
1502
+			],
1503
+		];
1504
+		$not_approved_query_args    = [
1505
+			[
1506
+				'REG_deleted' => 0,
1507
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1508
+			],
1509
+		];
1510
+		$pending_payment_query_args = [
1511
+			[
1512
+				'REG_deleted' => 0,
1513
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1514
+			],
1515
+		];
1516
+		// publish box
1517
+		$publish_box_extra_args = [
1518
+			'view_approved_reg_url'        => add_query_arg(
1519
+				[
1520
+					'action'      => 'default',
1521
+					'event_id'    => $this->_cpt_model_obj->ID(),
1522
+					'_reg_status' => EEM_Registration::status_id_approved,
1523
+				],
1524
+				REG_ADMIN_URL
1525
+			),
1526
+			'view_not_approved_reg_url'    => add_query_arg(
1527
+				[
1528
+					'action'      => 'default',
1529
+					'event_id'    => $this->_cpt_model_obj->ID(),
1530
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1531
+				],
1532
+				REG_ADMIN_URL
1533
+			),
1534
+			'view_pending_payment_reg_url' => add_query_arg(
1535
+				[
1536
+					'action'      => 'default',
1537
+					'event_id'    => $this->_cpt_model_obj->ID(),
1538
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1539
+				],
1540
+				REG_ADMIN_URL
1541
+			),
1542
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1543
+				'Registration',
1544
+				$approved_query_args
1545
+			),
1546
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1547
+				'Registration',
1548
+				$not_approved_query_args
1549
+			),
1550
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1551
+				'Registration',
1552
+				$pending_payment_query_args
1553
+			),
1554
+			'misc_pub_section_class'       => apply_filters(
1555
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1556
+				'misc-pub-section'
1557
+			),
1558
+		];
1559
+		ob_start();
1560
+		do_action(
1561
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1562
+			$this->_cpt_model_obj
1563
+		);
1564
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1565
+		// load template
1566
+		EEH_Template::display_template(
1567
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1568
+			$publish_box_extra_args
1569
+		);
1570
+	}
1571
+
1572
+
1573
+	/**
1574
+	 * @return EE_Event
1575
+	 */
1576
+	public function get_event_object()
1577
+	{
1578
+		return $this->_cpt_model_obj;
1579
+	}
1580
+
1581
+
1582
+
1583
+
1584
+	/** METABOXES * */
1585
+	/**
1586
+	 * _register_event_editor_meta_boxes
1587
+	 * add all metaboxes related to the event_editor
1588
+	 *
1589
+	 * @return void
1590
+	 * @throws EE_Error
1591
+	 * @throws ReflectionException
1592
+	 */
1593
+	protected function _register_event_editor_meta_boxes()
1594
+	{
1595
+		$this->verify_cpt_object();
1596
+		add_meta_box(
1597
+			'espresso_event_editor_tickets',
1598
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1599
+			[$this, 'ticket_metabox'],
1600
+			$this->page_slug,
1601
+			'normal',
1602
+			'high'
1603
+		);
1604
+		add_meta_box(
1605
+			'espresso_event_editor_event_options',
1606
+			esc_html__('Event Registration Options', 'event_espresso'),
1607
+			[$this, 'registration_options_meta_box'],
1608
+			$this->page_slug,
1609
+			'side'
1610
+		);
1611
+		// NOTE: if you're looking for other metaboxes in here,
1612
+		// where a metabox has a related management page in the admin
1613
+		// you will find it setup in the related management page's "_Hooks" file.
1614
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1615
+	}
1616
+
1617
+
1618
+	/**
1619
+	 * @throws DomainException
1620
+	 * @throws EE_Error
1621
+	 * @throws ReflectionException
1622
+	 */
1623
+	public function ticket_metabox()
1624
+	{
1625
+		$existing_datetime_ids = $existing_ticket_ids = [];
1626
+		// defaults for template args
1627
+		$template_args = [
1628
+			'existing_datetime_ids'    => '',
1629
+			'event_datetime_help_link' => '',
1630
+			'ticket_options_help_link' => '',
1631
+			'time'                     => null,
1632
+			'ticket_rows'              => '',
1633
+			'existing_ticket_ids'      => '',
1634
+			'total_ticket_rows'        => 1,
1635
+			'ticket_js_structure'      => '',
1636
+			'trash_icon'               => 'ee-lock-icon',
1637
+			'disabled'                 => '',
1638
+		];
1639
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1640
+		/**
1641
+		 * 1. Start with retrieving Datetimes
1642
+		 * 2. Fore each datetime get related tickets
1643
+		 * 3. For each ticket get related prices
1644
+		 */
1645
+		$times          = EEM_Datetime::instance()->get_all_event_dates($event_id);
1646
+		$first_datetime = reset($times);
1647
+		// do we get related tickets?
1648
+		if (
1649
+			$first_datetime instanceof EE_Datetime
1650
+			&& $first_datetime->ID() !== 0
1651
+		) {
1652
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1653
+			$template_args['time']   = $first_datetime;
1654
+			$related_tickets         = $first_datetime->tickets(
1655
+				[
1656
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1657
+					'default_where_conditions' => 'none',
1658
+				]
1659
+			);
1660
+			if (! empty($related_tickets)) {
1661
+				$template_args['total_ticket_rows'] = count($related_tickets);
1662
+				$row                                = 0;
1663
+				foreach ($related_tickets as $ticket) {
1664
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1665
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1666
+					$row++;
1667
+				}
1668
+			} else {
1669
+				$template_args['total_ticket_rows'] = 1;
1670
+				/** @type EE_Ticket $ticket */
1671
+				$ticket                       = EEM_Ticket::instance()->create_default_object();
1672
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1673
+			}
1674
+		} else {
1675
+			$template_args['time']        = $times[0];
1676
+			$tickets                      = EEM_Ticket::instance()->get_all_default_tickets();
1677
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1678
+			// NOTE: we're just sending the first default row
1679
+			// (decaf can't manage default tickets so this should be sufficient);
1680
+		}
1681
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1682
+			'event_editor_event_datetimes_help_tab'
1683
+		);
1684
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1685
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1686
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1687
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1688
+			EEM_Ticket::instance()->create_default_object(),
1689
+			true
1690
+		);
1691
+		$template                                  = apply_filters(
1692
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1693
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1694
+		);
1695
+		EEH_Template::display_template($template, $template_args);
1696
+	}
1697
+
1698
+
1699
+	/**
1700
+	 * Setup an individual ticket form for the decaf event editor page
1701
+	 *
1702
+	 * @access private
1703
+	 * @param EE_Ticket $ticket   the ticket object
1704
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1705
+	 * @param int       $row
1706
+	 * @return string generated html for the ticket row.
1707
+	 * @throws EE_Error
1708
+	 * @throws ReflectionException
1709
+	 */
1710
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1711
+	{
1712
+		$template_args = [
1713
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1714
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1715
+				: '',
1716
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1717
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1718
+			'TKT_name'            => $ticket->get('TKT_name'),
1719
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1720
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1721
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1722
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1723
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1724
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1725
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1726
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1727
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1728
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1729
+				: ' disabled=disabled',
1730
+		];
1731
+		$price         = $ticket->ID() !== 0
1732
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1733
+			: null;
1734
+		$price         = $price instanceof EE_Price
1735
+			? $price
1736
+			: EEM_Price::instance()->create_default_object();
1737
+		$price_args    = [
1738
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1739
+			'PRC_amount'            => $price->get('PRC_amount'),
1740
+			'PRT_ID'                => $price->get('PRT_ID'),
1741
+			'PRC_ID'                => $price->get('PRC_ID'),
1742
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1743
+		];
1744
+		// make sure we have default start and end dates if skeleton
1745
+		// handle rows that should NOT be empty
1746
+		if (empty($template_args['TKT_start_date'])) {
1747
+			// if empty then the start date will be now.
1748
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1749
+		}
1750
+		if (empty($template_args['TKT_end_date'])) {
1751
+			// get the earliest datetime (if present);
1752
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1753
+				? $this->_cpt_model_obj->get_first_related(
1754
+					'Datetime',
1755
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1756
+				)
1757
+				: null;
1758
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1759
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1760
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1761
+		}
1762
+		$template_args = array_merge($template_args, $price_args);
1763
+		$template      = apply_filters(
1764
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1765
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1766
+			$ticket
1767
+		);
1768
+		return EEH_Template::display_template($template, $template_args, true);
1769
+	}
1770
+
1771
+
1772
+	/**
1773
+	 * @throws EE_Error
1774
+	 * @throws ReflectionException
1775
+	 */
1776
+	public function registration_options_meta_box()
1777
+	{
1778
+		$yes_no_values             = [
1779
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1780
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1781
+		];
1782
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1783
+			[
1784
+				EEM_Registration::status_id_cancelled,
1785
+				EEM_Registration::status_id_declined,
1786
+				EEM_Registration::status_id_incomplete,
1787
+			],
1788
+			true
1789
+		);
1790
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1791
+		$template_args['_event']                          = $this->_cpt_model_obj;
1792
+		$template_args['event']                           = $this->_cpt_model_obj;
1793
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1794
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1795
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1796
+			'default_reg_status',
1797
+			$default_reg_status_values,
1798
+			$this->_cpt_model_obj->default_registration_status()
1799
+		);
1800
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1801
+			'display_desc',
1802
+			$yes_no_values,
1803
+			$this->_cpt_model_obj->display_description()
1804
+		);
1805
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1806
+			'display_ticket_selector',
1807
+			$yes_no_values,
1808
+			$this->_cpt_model_obj->display_ticket_selector(),
1809
+			'',
1810
+			'',
1811
+			false
1812
+		);
1813
+		$template_args['additional_registration_options'] = apply_filters(
1814
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1815
+			'',
1816
+			$template_args,
1817
+			$yes_no_values,
1818
+			$default_reg_status_values
1819
+		);
1820
+		EEH_Template::display_template(
1821
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1822
+			$template_args
1823
+		);
1824
+	}
1825
+
1826
+
1827
+	/**
1828
+	 * _get_events()
1829
+	 * This method simply returns all the events (for the given _view and paging)
1830
+	 *
1831
+	 * @access public
1832
+	 * @param int  $per_page     count of items per page (20 default);
1833
+	 * @param int  $current_page what is the current page being viewed.
1834
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1835
+	 *                           If FALSE then we return an array of event objects
1836
+	 *                           that match the given _view and paging parameters.
1837
+	 * @return array|int         an array of event objects or a count of them.
1838
+	 * @throws Exception
1839
+	 */
1840
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1841
+	{
1842
+		$EEM_Event   = $this->_event_model();
1843
+		$offset      = ($current_page - 1) * $per_page;
1844
+		$limit       = $count ? null : $offset . ',' . $per_page;
1845
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1846
+		$order       = $this->request->getRequestParam('order', 'DESC');
1847
+		$month_range = $this->request->getRequestParam('month_range');
1848
+		if ($month_range) {
1849
+			$pieces = explode(' ', $month_range, 3);
1850
+			// simulate the FIRST day of the month, that fixes issues for months like February
1851
+			// where PHP doesn't know what to assume for date.
1852
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1853
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1854
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1855
+		}
1856
+		$where  = [];
1857
+		$status = $this->request->getRequestParam('status');
1858
+		// determine what post_status our condition will have for the query.
1859
+		switch ($status) {
1860
+			case 'month':
1861
+			case 'today':
1862
+			case null:
1863
+			case 'all':
1864
+				break;
1865
+			case 'draft':
1866
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1867
+				break;
1868
+			default:
1869
+				$where['status'] = $status;
1870
+		}
1871
+		// categories? The default for all categories is -1
1872
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1873
+		if ($category !== -1) {
1874
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1875
+			$where['Term_Taxonomy.term_id']  = $category;
1876
+		}
1877
+		// date where conditions
1878
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1879
+		if ($month_range) {
1880
+			$DateTime = new DateTime(
1881
+				$year_r . '-' . $month_r . '-01 00:00:00',
1882
+				new DateTimeZone('UTC')
1883
+			);
1884
+			$start    = $DateTime->getTimestamp();
1885
+			// set the datetime to be the end of the month
1886
+			$DateTime->setDate(
1887
+				$year_r,
1888
+				$month_r,
1889
+				$DateTime->format('t')
1890
+			)->setTime(23, 59, 59);
1891
+			$end                             = $DateTime->getTimestamp();
1892
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1893
+		} elseif ($status === 'today') {
1894
+			$DateTime                        =
1895
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1896
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1897
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1898
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1899
+		} elseif ($status === 'month') {
1900
+			$now                             = date('Y-m-01');
1901
+			$DateTime                        =
1902
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1903
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1904
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1905
+														->setTime(23, 59, 59)
1906
+														->format(implode(' ', $start_formats));
1907
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1908
+		}
1909
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1910
+			$where['EVT_wp_user'] = get_current_user_id();
1911
+		} else {
1912
+			if (! isset($where['status'])) {
1913
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1914
+					$where['OR'] = [
1915
+						'status*restrict_private' => ['!=', 'private'],
1916
+						'AND'                     => [
1917
+							'status*inclusive' => ['=', 'private'],
1918
+							'EVT_wp_user'      => get_current_user_id(),
1919
+						],
1920
+					];
1921
+				}
1922
+			}
1923
+		}
1924
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1925
+		if (
1926
+			$wp_user
1927
+			&& $wp_user !== get_current_user_id()
1928
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1929
+		) {
1930
+			$where['EVT_wp_user'] = $wp_user;
1931
+		}
1932
+		// search query handling
1933
+		$search_term = $this->request->getRequestParam('s');
1934
+		if ($search_term) {
1935
+			$search_term = '%' . $search_term . '%';
1936
+			$where['OR'] = [
1937
+				'EVT_name'       => ['LIKE', $search_term],
1938
+				'EVT_desc'       => ['LIKE', $search_term],
1939
+				'EVT_short_desc' => ['LIKE', $search_term],
1940
+			];
1941
+		}
1942
+		// filter events by venue.
1943
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
1944
+		if ($venue) {
1945
+			$where['Venue.VNU_ID'] = $venue;
1946
+		}
1947
+		$request_params = $this->request->requestParams();
1948
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
1949
+		$query_params   = apply_filters(
1950
+			'FHEE__Events_Admin_Page__get_events__query_params',
1951
+			[
1952
+				$where,
1953
+				'limit'    => $limit,
1954
+				'order_by' => $orderby,
1955
+				'order'    => $order,
1956
+				'group_by' => 'EVT_ID',
1957
+			],
1958
+			$request_params
1959
+		);
1960
+
1961
+		// let's first check if we have special requests coming in.
1962
+		$active_status = $this->request->getRequestParam('active_status');
1963
+		if ($active_status) {
1964
+			switch ($active_status) {
1965
+				case 'upcoming':
1966
+					return $EEM_Event->get_upcoming_events($query_params, $count);
1967
+				case 'expired':
1968
+					return $EEM_Event->get_expired_events($query_params, $count);
1969
+				case 'active':
1970
+					return $EEM_Event->get_active_events($query_params, $count);
1971
+				case 'inactive':
1972
+					return $EEM_Event->get_inactive_events($query_params, $count);
1973
+			}
1974
+		}
1975
+
1976
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
1977
+	}
1978
+
1979
+
1980
+	/**
1981
+	 * handling for WordPress CPT actions (trash, restore, delete)
1982
+	 *
1983
+	 * @param string $post_id
1984
+	 * @throws EE_Error
1985
+	 * @throws ReflectionException
1986
+	 */
1987
+	public function trash_cpt_item($post_id)
1988
+	{
1989
+		$this->request->setRequestParam('EVT_ID', $post_id);
1990
+		$this->_trash_or_restore_event('trash', false);
1991
+	}
1992
+
1993
+
1994
+	/**
1995
+	 * @param string $post_id
1996
+	 * @throws EE_Error
1997
+	 * @throws ReflectionException
1998
+	 */
1999
+	public function restore_cpt_item($post_id)
2000
+	{
2001
+		$this->request->setRequestParam('EVT_ID', $post_id);
2002
+		$this->_trash_or_restore_event('draft', false);
2003
+	}
2004
+
2005
+
2006
+	/**
2007
+	 * @param string $post_id
2008
+	 * @throws EE_Error
2009
+	 * @throws EE_Error
2010
+	 */
2011
+	public function delete_cpt_item($post_id)
2012
+	{
2013
+		throw new EE_Error(
2014
+			esc_html__(
2015
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2016
+				'event_espresso'
2017
+			)
2018
+		);
2019
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2020
+		// $this->_delete_event();
2021
+	}
2022
+
2023
+
2024
+	/**
2025
+	 * _trash_or_restore_event
2026
+	 *
2027
+	 * @access protected
2028
+	 * @param string $event_status
2029
+	 * @param bool   $redirect_after
2030
+	 * @throws EE_Error
2031
+	 * @throws EE_Error
2032
+	 * @throws ReflectionException
2033
+	 */
2034
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2035
+	{
2036
+		// determine the event id and set to array.
2037
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2038
+		// loop thru events
2039
+		if ($EVT_ID) {
2040
+			// clean status
2041
+			$event_status = sanitize_key($event_status);
2042
+			// grab status
2043
+			if (! empty($event_status)) {
2044
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2045
+			} else {
2046
+				$success = false;
2047
+				$msg     = esc_html__(
2048
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2049
+					'event_espresso'
2050
+				);
2051
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2052
+			}
2053
+		} else {
2054
+			$success = false;
2055
+			$msg     = esc_html__(
2056
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2057
+				'event_espresso'
2058
+			);
2059
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2060
+		}
2061
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2062
+		if ($redirect_after) {
2063
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2064
+		}
2065
+	}
2066
+
2067
+
2068
+	/**
2069
+	 * _trash_or_restore_events
2070
+	 *
2071
+	 * @access protected
2072
+	 * @param string $event_status
2073
+	 * @return void
2074
+	 * @throws EE_Error
2075
+	 * @throws EE_Error
2076
+	 * @throws ReflectionException
2077
+	 */
2078
+	protected function _trash_or_restore_events($event_status = 'trash')
2079
+	{
2080
+		// clean status
2081
+		$event_status = sanitize_key($event_status);
2082
+		// grab status
2083
+		if (! empty($event_status)) {
2084
+			$success = true;
2085
+			// determine the event id and set to array.
2086
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2087
+			// loop thru events
2088
+			foreach ($EVT_IDs as $EVT_ID) {
2089
+				if ($EVT_ID = absint($EVT_ID)) {
2090
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2091
+					$success = $results !== false ? $success : false;
2092
+				} else {
2093
+					$msg = sprintf(
2094
+						esc_html__(
2095
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2096
+							'event_espresso'
2097
+						),
2098
+						$EVT_ID
2099
+					);
2100
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2101
+					$success = false;
2102
+				}
2103
+			}
2104
+		} else {
2105
+			$success = false;
2106
+			$msg     = esc_html__(
2107
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2108
+				'event_espresso'
2109
+			);
2110
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2111
+		}
2112
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2113
+		$success = $success ? 2 : false;
2114
+		$action  = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2115
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2116
+	}
2117
+
2118
+
2119
+	/**
2120
+	 * @param int    $EVT_ID
2121
+	 * @param string $event_status
2122
+	 * @return bool
2123
+	 * @throws EE_Error
2124
+	 * @throws ReflectionException
2125
+	 */
2126
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2127
+	{
2128
+		// grab event id
2129
+		if (! $EVT_ID) {
2130
+			$msg = esc_html__(
2131
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2132
+				'event_espresso'
2133
+			);
2134
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2135
+			return false;
2136
+		}
2137
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2138
+		// clean status
2139
+		$event_status = sanitize_key($event_status);
2140
+		// grab status
2141
+		if (empty($event_status)) {
2142
+			$msg = esc_html__(
2143
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2144
+				'event_espresso'
2145
+			);
2146
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2147
+			return false;
2148
+		}
2149
+		// was event trashed or restored ?
2150
+		switch ($event_status) {
2151
+			case 'draft':
2152
+				$action = 'restored from the trash';
2153
+				$hook   = 'AHEE_event_restored_from_trash';
2154
+				break;
2155
+			case 'trash':
2156
+				$action = 'moved to the trash';
2157
+				$hook   = 'AHEE_event_moved_to_trash';
2158
+				break;
2159
+			default:
2160
+				$action = 'updated';
2161
+				$hook   = false;
2162
+		}
2163
+		// use class to change status
2164
+		$this->_cpt_model_obj->set_status($event_status);
2165
+		$success = $this->_cpt_model_obj->save();
2166
+		if (! $success) {
2167
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2168
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2169
+			return false;
2170
+		}
2171
+		if ($hook) {
2172
+			do_action($hook);
2173
+		}
2174
+		return true;
2175
+	}
2176
+
2177
+
2178
+	/**
2179
+	 * @param array $event_ids
2180
+	 * @return array
2181
+	 * @since   4.10.23.p
2182
+	 */
2183
+	private function cleanEventIds(array $event_ids)
2184
+	{
2185
+		return array_map('absint', $event_ids);
2186
+	}
2187
+
2188
+
2189
+	/**
2190
+	 * @return array
2191
+	 * @since   4.10.23.p
2192
+	 */
2193
+	private function getEventIdsFromRequest()
2194
+	{
2195
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2196
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2197
+		} else {
2198
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2199
+		}
2200
+	}
2201
+
2202
+
2203
+	/**
2204
+	 * @param bool $preview_delete
2205
+	 * @throws EE_Error
2206
+	 */
2207
+	protected function _delete_event($preview_delete = true)
2208
+	{
2209
+		$this->_delete_events($preview_delete);
2210
+	}
2211
+
2212
+
2213
+	/**
2214
+	 * Gets the tree traversal batch persister.
2215
+	 *
2216
+	 * @return NodeGroupDao
2217
+	 * @throws InvalidArgumentException
2218
+	 * @throws InvalidDataTypeException
2219
+	 * @throws InvalidInterfaceException
2220
+	 * @since 4.10.12.p
2221
+	 */
2222
+	protected function getModelObjNodeGroupPersister()
2223
+	{
2224
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2225
+			$this->model_obj_node_group_persister =
2226
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2227
+		}
2228
+		return $this->model_obj_node_group_persister;
2229
+	}
2230
+
2231
+
2232
+	/**
2233
+	 * @param bool $preview_delete
2234
+	 * @return void
2235
+	 * @throws EE_Error
2236
+	 */
2237
+	protected function _delete_events($preview_delete = true)
2238
+	{
2239
+		$event_ids = $this->getEventIdsFromRequest();
2240
+		if ($preview_delete) {
2241
+			$this->generateDeletionPreview($event_ids);
2242
+		} else {
2243
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2244
+		}
2245
+	}
2246
+
2247
+
2248
+	/**
2249
+	 * @param array $event_ids
2250
+	 */
2251
+	protected function generateDeletionPreview(array $event_ids)
2252
+	{
2253
+		$event_ids = $this->cleanEventIds($event_ids);
2254
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2255
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2256
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2257
+			[
2258
+				'action'            => 'preview_deletion',
2259
+				'deletion_job_code' => $deletion_job_code,
2260
+			],
2261
+			$this->_admin_base_url
2262
+		);
2263
+		EEH_URL::safeRedirectAndExit(
2264
+			EE_Admin_Page::add_query_args_and_nonce(
2265
+				[
2266
+					'page'              => 'espresso_batch',
2267
+					'batch'             => EED_Batch::batch_job,
2268
+					'EVT_IDs'           => $event_ids,
2269
+					'deletion_job_code' => $deletion_job_code,
2270
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2271
+					'return_url'        => urlencode($return_url),
2272
+				],
2273
+				admin_url()
2274
+			)
2275
+		);
2276
+	}
2277
+
2278
+
2279
+	/**
2280
+	 * Checks for a POST submission
2281
+	 *
2282
+	 * @since 4.10.12.p
2283
+	 */
2284
+	protected function confirmDeletion()
2285
+	{
2286
+		$deletion_redirect_logic =
2287
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2288
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2289
+	}
2290
+
2291
+
2292
+	/**
2293
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2294
+	 *
2295
+	 * @throws EE_Error
2296
+	 * @since 4.10.12.p
2297
+	 */
2298
+	protected function previewDeletion()
2299
+	{
2300
+		$preview_deletion_logic =
2301
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2302
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2303
+		$this->display_admin_page_with_no_sidebar();
2304
+	}
2305
+
2306
+
2307
+	/**
2308
+	 * get total number of events
2309
+	 *
2310
+	 * @access public
2311
+	 * @return int
2312
+	 * @throws EE_Error
2313
+	 * @throws EE_Error
2314
+	 */
2315
+	public function total_events()
2316
+	{
2317
+		return EEM_Event::instance()->count(
2318
+			['caps' => 'read_admin'],
2319
+			'EVT_ID',
2320
+			true
2321
+		);
2322
+	}
2323
+
2324
+
2325
+	/**
2326
+	 * get total number of draft events
2327
+	 *
2328
+	 * @access public
2329
+	 * @return int
2330
+	 * @throws EE_Error
2331
+	 * @throws EE_Error
2332
+	 */
2333
+	public function total_events_draft()
2334
+	{
2335
+		return EEM_Event::instance()->count(
2336
+			[
2337
+				['status' => ['IN', ['draft', 'auto-draft']]],
2338
+				'caps' => 'read_admin',
2339
+			],
2340
+			'EVT_ID',
2341
+			true
2342
+		);
2343
+	}
2344
+
2345
+
2346
+	/**
2347
+	 * get total number of trashed events
2348
+	 *
2349
+	 * @access public
2350
+	 * @return int
2351
+	 * @throws EE_Error
2352
+	 * @throws EE_Error
2353
+	 */
2354
+	public function total_trashed_events()
2355
+	{
2356
+		return EEM_Event::instance()->count(
2357
+			[
2358
+				['status' => 'trash'],
2359
+				'caps' => 'read_admin',
2360
+			],
2361
+			'EVT_ID',
2362
+			true
2363
+		);
2364
+	}
2365
+
2366
+
2367
+	/**
2368
+	 *    _default_event_settings
2369
+	 *    This generates the Default Settings Tab
2370
+	 *
2371
+	 * @return void
2372
+	 * @throws EE_Error
2373
+	 */
2374
+	protected function _default_event_settings()
2375
+	{
2376
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2377
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2378
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2379
+		$this->display_admin_page_with_sidebar();
2380
+	}
2381
+
2382
+
2383
+	/**
2384
+	 * Return the form for event settings.
2385
+	 *
2386
+	 * @return EE_Form_Section_Proper
2387
+	 * @throws EE_Error
2388
+	 */
2389
+	protected function _default_event_settings_form()
2390
+	{
2391
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2392
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2393
+		// exclude
2394
+			[
2395
+				EEM_Registration::status_id_cancelled,
2396
+				EEM_Registration::status_id_declined,
2397
+				EEM_Registration::status_id_incomplete,
2398
+				EEM_Registration::status_id_wait_list,
2399
+			],
2400
+			true
2401
+		);
2402
+		return new EE_Form_Section_Proper(
2403
+			[
2404
+				'name'            => 'update_default_event_settings',
2405
+				'html_id'         => 'update_default_event_settings',
2406
+				'html_class'      => 'form-table',
2407
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2408
+				'subsections'     => apply_filters(
2409
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2410
+					[
2411
+						'default_reg_status'  => new EE_Select_Input(
2412
+							$registration_stati_for_selection,
2413
+							[
2414
+								'default'         => isset($registration_config->default_STS_ID)
2415
+													 && array_key_exists(
2416
+														 $registration_config->default_STS_ID,
2417
+														 $registration_stati_for_selection
2418
+													 )
2419
+									? sanitize_text_field($registration_config->default_STS_ID)
2420
+									: EEM_Registration::status_id_pending_payment,
2421
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2422
+													 . EEH_Template::get_help_tab_link(
2423
+														 'default_settings_status_help_tab'
2424
+													 ),
2425
+								'html_help_text'  => esc_html__(
2426
+									'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.',
2427
+									'event_espresso'
2428
+								),
2429
+							]
2430
+						),
2431
+						'default_max_tickets' => new EE_Integer_Input(
2432
+							[
2433
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2434
+									? $registration_config->default_maximum_number_of_tickets
2435
+									: EEM_Event::get_default_additional_limit(),
2436
+								'html_label_text' => esc_html__(
2437
+									'Default Maximum Tickets Allowed Per Order:',
2438
+									'event_espresso'
2439
+								)
2440
+								. EEH_Template::get_help_tab_link(
2441
+									'default_maximum_tickets_help_tab"'
2442
+								),
2443
+								'html_help_text'  => esc_html__(
2444
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2445
+									'event_espresso'
2446
+								),
2447
+							]
2448
+						),
2449
+					]
2450
+				),
2451
+			]
2452
+		);
2453
+	}
2454
+
2455
+
2456
+	/**
2457
+	 * _update_default_event_settings
2458
+	 *
2459
+	 * @access protected
2460
+	 * @return void
2461
+	 * @throws EE_Error
2462
+	 */
2463
+	protected function _update_default_event_settings()
2464
+	{
2465
+		$registration_config = EE_Registry::instance()->CFG->registration;
2466
+		$form                = $this->_default_event_settings_form();
2467
+		if ($form->was_submitted()) {
2468
+			$form->receive_form_submission();
2469
+			if ($form->is_valid()) {
2470
+				$valid_data = $form->valid_data();
2471
+				if (isset($valid_data['default_reg_status'])) {
2472
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2473
+				}
2474
+				if (isset($valid_data['default_max_tickets'])) {
2475
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2476
+				}
2477
+				// update because data was valid!
2478
+				EE_Registry::instance()->CFG->update_espresso_config();
2479
+				EE_Error::overwrite_success();
2480
+				EE_Error::add_success(
2481
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2482
+				);
2483
+			}
2484
+		}
2485
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2486
+	}
2487
+
2488
+
2489
+	/*************        Templates        *************
21 2490
      *
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $_cpt_model_obj = false;
47
-
48
-
49
-    /**
50
-     * @var NodeGroupDao
51
-     */
52
-    protected $model_obj_node_group_persister;
53
-
54
-
55
-    /**
56
-     * Initialize page props for this admin page group.
57
-     */
58
-    protected function _init_page_props()
59
-    {
60
-        $this->page_slug        = EVENTS_PG_SLUG;
61
-        $this->page_label       = EVENTS_LABEL;
62
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
63
-        $this->_admin_base_path = EVENTS_ADMIN;
64
-        $this->_cpt_model_names = [
65
-            'create_new' => 'EEM_Event',
66
-            'edit'       => 'EEM_Event',
67
-        ];
68
-        $this->_cpt_edit_routes = [
69
-            'espresso_events' => 'edit',
70
-        ];
71
-        add_action(
72
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
-            [$this, 'verify_event_edit'],
74
-            10,
75
-            2
76
-        );
77
-    }
78
-
79
-
80
-    /**
81
-     * Sets the ajax hooks used for this admin page group.
82
-     */
83
-    protected function _ajax_hooks()
84
-    {
85
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
-    }
87
-
88
-
89
-    /**
90
-     * Sets the page properties for this admin page group.
91
-     */
92
-    protected function _define_page_props()
93
-    {
94
-        $this->_admin_page_title = EVENTS_LABEL;
95
-        $this->_labels           = [
96
-            'buttons'      => [
97
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
98
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
-            ],
104
-            'editor_title' => [
105
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
-            ],
107
-            'publishbox'   => [
108
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
110
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
-            ],
114
-        ];
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets the page routes property for this admin page group.
120
-     */
121
-    protected function _set_page_routes()
122
-    {
123
-        // load formatter helper
124
-        // load field generator helper
125
-        // is there a evt_id in the request?
126
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
-
129
-        $this->_page_routes = [
130
-            'default'                       => [
131
-                'func'       => '_events_overview_list_table',
132
-                'capability' => 'ee_read_events',
133
-            ],
134
-            'create_new'                    => [
135
-                'func'       => '_create_new_cpt_item',
136
-                'capability' => 'ee_edit_events',
137
-            ],
138
-            'edit'                          => [
139
-                'func'       => '_edit_cpt_item',
140
-                'capability' => 'ee_edit_event',
141
-                'obj_id'     => $EVT_ID,
142
-            ],
143
-            'copy_event'                    => [
144
-                'func'       => '_copy_events',
145
-                'capability' => 'ee_edit_event',
146
-                'obj_id'     => $EVT_ID,
147
-                'noheader'   => true,
148
-            ],
149
-            'trash_event'                   => [
150
-                'func'       => '_trash_or_restore_event',
151
-                'args'       => ['event_status' => 'trash'],
152
-                'capability' => 'ee_delete_event',
153
-                'obj_id'     => $EVT_ID,
154
-                'noheader'   => true,
155
-            ],
156
-            'trash_events'                  => [
157
-                'func'       => '_trash_or_restore_events',
158
-                'args'       => ['event_status' => 'trash'],
159
-                'capability' => 'ee_delete_events',
160
-                'noheader'   => true,
161
-            ],
162
-            'restore_event'                 => [
163
-                'func'       => '_trash_or_restore_event',
164
-                'args'       => ['event_status' => 'draft'],
165
-                'capability' => 'ee_delete_event',
166
-                'obj_id'     => $EVT_ID,
167
-                'noheader'   => true,
168
-            ],
169
-            'restore_events'                => [
170
-                'func'       => '_trash_or_restore_events',
171
-                'args'       => ['event_status' => 'draft'],
172
-                'capability' => 'ee_delete_events',
173
-                'noheader'   => true,
174
-            ],
175
-            'delete_event'                  => [
176
-                'func'       => '_delete_event',
177
-                'capability' => 'ee_delete_event',
178
-                'obj_id'     => $EVT_ID,
179
-                'noheader'   => true,
180
-            ],
181
-            'delete_events'                 => [
182
-                'func'       => '_delete_events',
183
-                'capability' => 'ee_delete_events',
184
-                'noheader'   => true,
185
-            ],
186
-            'view_report'                   => [
187
-                'func'       => '_view_report',
188
-                'capability' => 'ee_edit_events',
189
-            ],
190
-            'default_event_settings'        => [
191
-                'func'       => '_default_event_settings',
192
-                'capability' => 'manage_options',
193
-            ],
194
-            'update_default_event_settings' => [
195
-                'func'       => '_update_default_event_settings',
196
-                'capability' => 'manage_options',
197
-                'noheader'   => true,
198
-            ],
199
-            'template_settings'             => [
200
-                'func'       => '_template_settings',
201
-                'capability' => 'manage_options',
202
-            ],
203
-            // event category tab related
204
-            'add_category'                  => [
205
-                'func'       => '_category_details',
206
-                'capability' => 'ee_edit_event_category',
207
-                'args'       => ['add'],
208
-            ],
209
-            'edit_category'                 => [
210
-                'func'       => '_category_details',
211
-                'capability' => 'ee_edit_event_category',
212
-                'args'       => ['edit'],
213
-            ],
214
-            'delete_categories'             => [
215
-                'func'       => '_delete_categories',
216
-                'capability' => 'ee_delete_event_category',
217
-                'noheader'   => true,
218
-            ],
219
-            'delete_category'               => [
220
-                'func'       => '_delete_categories',
221
-                'capability' => 'ee_delete_event_category',
222
-                'noheader'   => true,
223
-            ],
224
-            'insert_category'               => [
225
-                'func'       => '_insert_or_update_category',
226
-                'args'       => ['new_category' => true],
227
-                'capability' => 'ee_edit_event_category',
228
-                'noheader'   => true,
229
-            ],
230
-            'update_category'               => [
231
-                'func'       => '_insert_or_update_category',
232
-                'args'       => ['new_category' => false],
233
-                'capability' => 'ee_edit_event_category',
234
-                'noheader'   => true,
235
-            ],
236
-            'category_list'                 => [
237
-                'func'       => '_category_list_table',
238
-                'capability' => 'ee_manage_event_categories',
239
-            ],
240
-            'preview_deletion'              => [
241
-                'func'       => 'previewDeletion',
242
-                'capability' => 'ee_delete_events',
243
-            ],
244
-            'confirm_deletion'              => [
245
-                'func'       => 'confirmDeletion',
246
-                'capability' => 'ee_delete_events',
247
-                'noheader'   => true,
248
-            ],
249
-        ];
250
-    }
251
-
252
-
253
-    /**
254
-     * Set the _page_config property for this admin page group.
255
-     */
256
-    protected function _set_page_config()
257
-    {
258
-        $post_id            = $this->request->getRequestParam('post', 0, 'int');
259
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
-        $this->_page_config = [
261
-            'default'                => [
262
-                'nav'           => [
263
-                    'label' => esc_html__('Overview', 'event_espresso'),
264
-                    'order' => 10,
265
-                ],
266
-                'list_table'    => 'Events_Admin_List_Table',
267
-                'help_tabs'     => [
268
-                    'events_overview_help_tab'                       => [
269
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
270
-                        'filename' => 'events_overview',
271
-                    ],
272
-                    'events_overview_table_column_headings_help_tab' => [
273
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
-                        'filename' => 'events_overview_table_column_headings',
275
-                    ],
276
-                    'events_overview_filters_help_tab'               => [
277
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
-                        'filename' => 'events_overview_filters',
279
-                    ],
280
-                    'events_overview_view_help_tab'                  => [
281
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
-                        'filename' => 'events_overview_views',
283
-                    ],
284
-                    'events_overview_other_help_tab'                 => [
285
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
-                        'filename' => 'events_overview_other',
287
-                    ],
288
-                ],
289
-                'qtips'         => [
290
-                    'EE_Event_List_Table_Tips',
291
-                ],
292
-                'require_nonce' => false,
293
-            ],
294
-            'create_new'             => [
295
-                'nav'           => [
296
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
297
-                    'order'      => 5,
298
-                    'persistent' => false,
299
-                ],
300
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
301
-                'help_tabs'     => [
302
-                    'event_editor_help_tab'                            => [
303
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
304
-                        'filename' => 'event_editor',
305
-                    ],
306
-                    'event_editor_title_richtexteditor_help_tab'       => [
307
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
308
-                        'filename' => 'event_editor_title_richtexteditor',
309
-                    ],
310
-                    'event_editor_venue_details_help_tab'              => [
311
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
312
-                        'filename' => 'event_editor_venue_details',
313
-                    ],
314
-                    'event_editor_event_datetimes_help_tab'            => [
315
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
316
-                        'filename' => 'event_editor_event_datetimes',
317
-                    ],
318
-                    'event_editor_event_tickets_help_tab'              => [
319
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
320
-                        'filename' => 'event_editor_event_tickets',
321
-                    ],
322
-                    'event_editor_event_registration_options_help_tab' => [
323
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
324
-                        'filename' => 'event_editor_event_registration_options',
325
-                    ],
326
-                    'event_editor_tags_categories_help_tab'            => [
327
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
328
-                        'filename' => 'event_editor_tags_categories',
329
-                    ],
330
-                    'event_editor_questions_registrants_help_tab'      => [
331
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
332
-                        'filename' => 'event_editor_questions_registrants',
333
-                    ],
334
-                    'event_editor_save_new_event_help_tab'             => [
335
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
336
-                        'filename' => 'event_editor_save_new_event',
337
-                    ],
338
-                    'event_editor_other_help_tab'                      => [
339
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
340
-                        'filename' => 'event_editor_other',
341
-                    ],
342
-                ],
343
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
344
-                'require_nonce' => false,
345
-            ],
346
-            'edit'                   => [
347
-                'nav'           => [
348
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
349
-                    'order'      => 5,
350
-                    'persistent' => false,
351
-                    'url'        => $post_id
352
-                        ? EE_Admin_Page::add_query_args_and_nonce(
353
-                            ['post' => $post_id, 'action' => 'edit'],
354
-                            $this->_current_page_view_url
355
-                        )
356
-                        : $this->_admin_base_url,
357
-                ],
358
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
359
-                'help_tabs'     => [
360
-                    'event_editor_help_tab'                            => [
361
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
362
-                        'filename' => 'event_editor',
363
-                    ],
364
-                    'event_editor_title_richtexteditor_help_tab'       => [
365
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
366
-                        'filename' => 'event_editor_title_richtexteditor',
367
-                    ],
368
-                    'event_editor_venue_details_help_tab'              => [
369
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
370
-                        'filename' => 'event_editor_venue_details',
371
-                    ],
372
-                    'event_editor_event_datetimes_help_tab'            => [
373
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
374
-                        'filename' => 'event_editor_event_datetimes',
375
-                    ],
376
-                    'event_editor_event_tickets_help_tab'              => [
377
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
378
-                        'filename' => 'event_editor_event_tickets',
379
-                    ],
380
-                    'event_editor_event_registration_options_help_tab' => [
381
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
382
-                        'filename' => 'event_editor_event_registration_options',
383
-                    ],
384
-                    'event_editor_tags_categories_help_tab'            => [
385
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
386
-                        'filename' => 'event_editor_tags_categories',
387
-                    ],
388
-                    'event_editor_questions_registrants_help_tab'      => [
389
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
390
-                        'filename' => 'event_editor_questions_registrants',
391
-                    ],
392
-                    'event_editor_save_new_event_help_tab'             => [
393
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
394
-                        'filename' => 'event_editor_save_new_event',
395
-                    ],
396
-                    'event_editor_other_help_tab'                      => [
397
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
398
-                        'filename' => 'event_editor_other',
399
-                    ],
400
-                ],
401
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
402
-                'require_nonce' => false,
403
-            ],
404
-            'default_event_settings' => [
405
-                'nav'           => [
406
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
407
-                    'order' => 40,
408
-                ],
409
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
410
-                'labels'        => [
411
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
412
-                ],
413
-                'help_tabs'     => [
414
-                    'default_settings_help_tab'        => [
415
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
416
-                        'filename' => 'events_default_settings',
417
-                    ],
418
-                    'default_settings_status_help_tab' => [
419
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
420
-                        'filename' => 'events_default_settings_status',
421
-                    ],
422
-                    'default_maximum_tickets_help_tab' => [
423
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
424
-                        'filename' => 'events_default_settings_max_tickets',
425
-                    ],
426
-                ],
427
-                'require_nonce' => false,
428
-            ],
429
-            // template settings
430
-            'template_settings'      => [
431
-                'nav'           => [
432
-                    'label' => esc_html__('Templates', 'event_espresso'),
433
-                    'order' => 30,
434
-                ],
435
-                'metaboxes'     => $this->_default_espresso_metaboxes,
436
-                'help_tabs'     => [
437
-                    'general_settings_templates_help_tab' => [
438
-                        'title'    => esc_html__('Templates', 'event_espresso'),
439
-                        'filename' => 'general_settings_templates',
440
-                    ],
441
-                ],
442
-                'require_nonce' => false,
443
-            ],
444
-            // event category stuff
445
-            'add_category'           => [
446
-                'nav'           => [
447
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
448
-                    'order'      => 15,
449
-                    'persistent' => false,
450
-                ],
451
-                'help_tabs'     => [
452
-                    'add_category_help_tab' => [
453
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
454
-                        'filename' => 'events_add_category',
455
-                    ],
456
-                ],
457
-                'metaboxes'     => ['_publish_post_box'],
458
-                'require_nonce' => false,
459
-            ],
460
-            'edit_category'          => [
461
-                'nav'           => [
462
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
463
-                    'order'      => 15,
464
-                    'persistent' => false,
465
-                    'url'        => $EVT_CAT_ID
466
-                        ? add_query_arg(
467
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
468
-                            $this->_current_page_view_url
469
-                        )
470
-                        : $this->_admin_base_url,
471
-                ],
472
-                'help_tabs'     => [
473
-                    'edit_category_help_tab' => [
474
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
475
-                        'filename' => 'events_edit_category',
476
-                    ],
477
-                ],
478
-                'metaboxes'     => ['_publish_post_box'],
479
-                'require_nonce' => false,
480
-            ],
481
-            'category_list'          => [
482
-                'nav'           => [
483
-                    'label' => esc_html__('Categories', 'event_espresso'),
484
-                    'order' => 20,
485
-                ],
486
-                'list_table'    => 'Event_Categories_Admin_List_Table',
487
-                'help_tabs'     => [
488
-                    'events_categories_help_tab'                       => [
489
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
490
-                        'filename' => 'events_categories',
491
-                    ],
492
-                    'events_categories_table_column_headings_help_tab' => [
493
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
494
-                        'filename' => 'events_categories_table_column_headings',
495
-                    ],
496
-                    'events_categories_view_help_tab'                  => [
497
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
498
-                        'filename' => 'events_categories_views',
499
-                    ],
500
-                    'events_categories_other_help_tab'                 => [
501
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
502
-                        'filename' => 'events_categories_other',
503
-                    ],
504
-                ],
505
-                'metaboxes'     => $this->_default_espresso_metaboxes,
506
-                'require_nonce' => false,
507
-            ],
508
-            'preview_deletion'       => [
509
-                'nav'           => [
510
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
511
-                    'order'      => 15,
512
-                    'persistent' => false,
513
-                    'url'        => '',
514
-                ],
515
-                'require_nonce' => false,
516
-            ],
517
-        ];
518
-    }
519
-
520
-
521
-    /**
522
-     * Used to register any global screen options if necessary for every route in this admin page group.
523
-     */
524
-    protected function _add_screen_options()
525
-    {
526
-    }
527
-
528
-
529
-    /**
530
-     * Implementing the screen options for the 'default' route.
531
-     */
532
-    protected function _add_screen_options_default()
533
-    {
534
-        $this->_per_page_screen_option();
535
-    }
536
-
537
-
538
-    /**
539
-     * Implementing screen options for the category list route.
540
-     */
541
-    protected function _add_screen_options_category_list()
542
-    {
543
-        $page_title              = $this->_admin_page_title;
544
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
545
-        $this->_per_page_screen_option();
546
-        $this->_admin_page_title = $page_title;
547
-    }
548
-
549
-
550
-    /**
551
-     * Used to register any global feature pointers for the admin page group.
552
-     */
553
-    protected function _add_feature_pointers()
554
-    {
555
-    }
556
-
557
-
558
-    /**
559
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
560
-     */
561
-    public function load_scripts_styles()
562
-    {
563
-        wp_register_style(
564
-            'events-admin-css',
565
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
566
-            [],
567
-            EVENT_ESPRESSO_VERSION
568
-        );
569
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
570
-        wp_enqueue_style('events-admin-css');
571
-        wp_enqueue_style('ee-cat-admin');
572
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
573
-        // registers for all views
574
-        // scripts
575
-        wp_register_script(
576
-            'event_editor_js',
577
-            EVENTS_ASSETS_URL . 'event_editor.js',
578
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
579
-            EVENT_ESPRESSO_VERSION,
580
-            true
581
-        );
582
-    }
583
-
584
-
585
-    /**
586
-     * Enqueuing scripts and styles specific to this view
587
-     */
588
-    public function load_scripts_styles_create_new()
589
-    {
590
-        $this->load_scripts_styles_edit();
591
-    }
592
-
593
-
594
-    /**
595
-     * Enqueuing scripts and styles specific to this view
596
-     */
597
-    public function load_scripts_styles_edit()
598
-    {
599
-        // styles
600
-        wp_enqueue_style('espresso-ui-theme');
601
-        wp_register_style(
602
-            'event-editor-css',
603
-            EVENTS_ASSETS_URL . 'event-editor.css',
604
-            ['ee-admin-css'],
605
-            EVENT_ESPRESSO_VERSION
606
-        );
607
-        wp_enqueue_style('event-editor-css');
608
-        // scripts
609
-        wp_register_script(
610
-            'event-datetime-metabox',
611
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
612
-            ['event_editor_js', 'ee-datepicker'],
613
-            EVENT_ESPRESSO_VERSION
614
-        );
615
-        wp_enqueue_script('event-datetime-metabox');
616
-    }
617
-
618
-
619
-    /**
620
-     * Populating the _views property for the category list table view.
621
-     */
622
-    protected function _set_list_table_views_category_list()
623
-    {
624
-        $this->_views = [
625
-            'all' => [
626
-                'slug'        => 'all',
627
-                'label'       => esc_html__('All', 'event_espresso'),
628
-                'count'       => 0,
629
-                'bulk_action' => [
630
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
631
-                ],
632
-            ],
633
-        ];
634
-    }
635
-
636
-
637
-    /**
638
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
639
-     */
640
-    public function admin_init()
641
-    {
642
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
643
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
644
-            'event_espresso'
645
-        );
646
-    }
647
-
648
-
649
-    /**
650
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
651
-     * group.
652
-     */
653
-    public function admin_notices()
654
-    {
655
-    }
656
-
657
-
658
-    /**
659
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
660
-     * this admin page group.
661
-     */
662
-    public function admin_footer_scripts()
663
-    {
664
-    }
665
-
666
-
667
-    /**
668
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
669
-     * warning (via EE_Error::add_error());
670
-     *
671
-     * @param EE_Event $event Event object
672
-     * @param string   $req_type
673
-     * @return void
674
-     * @throws EE_Error
675
-     * @throws ReflectionException
676
-     */
677
-    public function verify_event_edit($event = null, $req_type = '')
678
-    {
679
-        // don't need to do this when processing
680
-        if (! empty($req_type)) {
681
-            return;
682
-        }
683
-        // no event?
684
-        if (empty($event)) {
685
-            // set event
686
-            $event = $this->_cpt_model_obj;
687
-        }
688
-        // STILL no event?
689
-        if (! $event instanceof EE_Event) {
690
-            return;
691
-        }
692
-        $orig_status = $event->status();
693
-        // first check if event is active.
694
-        if (
695
-            $orig_status === EEM_Event::cancelled
696
-            || $orig_status === EEM_Event::postponed
697
-            || $event->is_expired()
698
-            || $event->is_inactive()
699
-        ) {
700
-            return;
701
-        }
702
-        // made it here so it IS active... next check that any of the tickets are sold.
703
-        if ($event->is_sold_out(true)) {
704
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
705
-                EE_Error::add_attention(
706
-                    sprintf(
707
-                        esc_html__(
708
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
709
-                            'event_espresso'
710
-                        ),
711
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
712
-                    )
713
-                );
714
-            }
715
-            return;
716
-        } elseif ($orig_status === EEM_Event::sold_out) {
717
-            EE_Error::add_attention(
718
-                sprintf(
719
-                    esc_html__(
720
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
721
-                        'event_espresso'
722
-                    ),
723
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
724
-                )
725
-            );
726
-        }
727
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
728
-        if (! $event->tickets_on_sale()) {
729
-            return;
730
-        }
731
-        // made it here so show warning
732
-        $this->_edit_event_warning();
733
-    }
734
-
735
-
736
-    /**
737
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
738
-     * When needed, hook this into a EE_Error::add_error() notice.
739
-     *
740
-     * @access protected
741
-     * @return void
742
-     */
743
-    protected function _edit_event_warning()
744
-    {
745
-        // we don't want to add warnings during these requests
746
-        if ($this->request->getRequestParam('action') === 'editpost') {
747
-            return;
748
-        }
749
-        EE_Error::add_attention(
750
-            sprintf(
751
-                esc_html__(
752
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
753
-                    'event_espresso'
754
-                ),
755
-                '<a class="espresso-help-tab-lnk">',
756
-                '</a>'
757
-            )
758
-        );
759
-    }
760
-
761
-
762
-    /**
763
-     * When a user is creating a new event, notify them if they haven't set their timezone.
764
-     * Otherwise, do the normal logic
765
-     *
766
-     * @return void
767
-     * @throws EE_Error
768
-     */
769
-    protected function _create_new_cpt_item()
770
-    {
771
-        $has_timezone_string = get_option('timezone_string');
772
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
773
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
774
-            EE_Error::add_attention(
775
-                sprintf(
776
-                    esc_html__(
777
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
778
-                        'event_espresso'
779
-                    ),
780
-                    '<br>',
781
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
782
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
783
-                    . '</select>',
784
-                    '<button class="button button-secondary timezone-submit">',
785
-                    '</button><span class="spinner"></span>'
786
-                ),
787
-                __FILE__,
788
-                __FUNCTION__,
789
-                __LINE__
790
-            );
791
-        }
792
-        parent::_create_new_cpt_item();
793
-    }
794
-
795
-
796
-    /**
797
-     * Sets the _views property for the default route in this admin page group.
798
-     */
799
-    protected function _set_list_table_views_default()
800
-    {
801
-        $this->_views = [
802
-            'all'   => [
803
-                'slug'        => 'all',
804
-                'label'       => esc_html__('View All Events', 'event_espresso'),
805
-                'count'       => 0,
806
-                'bulk_action' => [
807
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
808
-                ],
809
-            ],
810
-            'draft' => [
811
-                'slug'        => 'draft',
812
-                'label'       => esc_html__('Draft', 'event_espresso'),
813
-                'count'       => 0,
814
-                'bulk_action' => [
815
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
816
-                ],
817
-            ],
818
-        ];
819
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
820
-            $this->_views['trash'] = [
821
-                'slug'        => 'trash',
822
-                'label'       => esc_html__('Trash', 'event_espresso'),
823
-                'count'       => 0,
824
-                'bulk_action' => [
825
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
826
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
827
-                ],
828
-            ];
829
-        }
830
-    }
831
-
832
-
833
-    /**
834
-     * Provides the legend item array for the default list table view.
835
-     *
836
-     * @return array
837
-     * @throws EE_Error
838
-     * @throws EE_Error
839
-     */
840
-    protected function _event_legend_items()
841
-    {
842
-        $items    = [
843
-            'view_details'   => [
844
-                'class' => 'dashicons dashicons-search',
845
-                'desc'  => esc_html__('View Event', 'event_espresso'),
846
-            ],
847
-            'edit_event'     => [
848
-                'class' => 'ee-icon ee-icon-calendar-edit',
849
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
850
-            ],
851
-            'view_attendees' => [
852
-                'class' => 'dashicons dashicons-groups',
853
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
854
-            ],
855
-        ];
856
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
857
-        $statuses = [
858
-            'sold_out_status'  => [
859
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
860
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
861
-            ],
862
-            'active_status'    => [
863
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
864
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
865
-            ],
866
-            'upcoming_status'  => [
867
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
868
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
869
-            ],
870
-            'postponed_status' => [
871
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
872
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
873
-            ],
874
-            'cancelled_status' => [
875
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
876
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
877
-            ],
878
-            'expired_status'   => [
879
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
880
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
881
-            ],
882
-            'inactive_status'  => [
883
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
884
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
885
-            ],
886
-        ];
887
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
888
-        return array_merge($items, $statuses);
889
-    }
890
-
891
-
892
-    /**
893
-     * @return EEM_Event
894
-     * @throws EE_Error
895
-     * @throws ReflectionException
896
-     */
897
-    private function _event_model()
898
-    {
899
-        if (! $this->_event_model instanceof EEM_Event) {
900
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
901
-        }
902
-        return $this->_event_model;
903
-    }
904
-
905
-
906
-    /**
907
-     * Adds extra buttons to the WP CPT permalink field row.
908
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
909
-     *
910
-     * @param string $return    the current html
911
-     * @param int    $id        the post id for the page
912
-     * @param string $new_title What the title is
913
-     * @param string $new_slug  what the slug is
914
-     * @return string            The new html string for the permalink area
915
-     */
916
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
917
-    {
918
-        // make sure this is only when editing
919
-        if (! empty($id)) {
920
-            $post   = get_post($id);
921
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
922
-                       . esc_html__('Shortcode', 'event_espresso')
923
-                       . '</a> ';
924
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
925
-                       . $post->ID
926
-                       . ']">';
927
-        }
928
-        return $return;
929
-    }
930
-
931
-
932
-    /**
933
-     * _events_overview_list_table
934
-     * This contains the logic for showing the events_overview list
935
-     *
936
-     * @access protected
937
-     * @return void
938
-     * @throws EE_Error
939
-     */
940
-    protected function _events_overview_list_table()
941
-    {
942
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
943
-        $this->_template_args['after_list_table']                           =
944
-            ! empty($this->_template_args['after_list_table'])
945
-                ? (array) $this->_template_args['after_list_table']
946
-                : [];
947
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
948
-            . EEH_Template::get_button_or_link(
949
-                get_post_type_archive_link('espresso_events'),
950
-                esc_html__("View Event Archive Page", "event_espresso"),
951
-                'button'
952
-            );
953
-        $this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
954
-            $this->_event_legend_items()
955
-        );
956
-        $this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
957
-            'create_new',
958
-            'add',
959
-            [],
960
-            'add-new-h2'
961
-        );
962
-        $this->display_admin_list_table_page_with_no_sidebar();
963
-    }
964
-
965
-
966
-    /**
967
-     * this allows for extra misc actions in the default WP publish box
968
-     *
969
-     * @return void
970
-     * @throws EE_Error
971
-     * @throws ReflectionException
972
-     */
973
-    public function extra_misc_actions_publish_box()
974
-    {
975
-        $this->_generate_publish_box_extra_content();
976
-    }
977
-
978
-
979
-    /**
980
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
981
-     * saved.
982
-     * Typically you would use this to save any additional data.
983
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
984
-     * ALSO very important.  When a post transitions from scheduled to published,
985
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
986
-     * other meta saves. So MAKE sure that you handle this accordingly.
987
-     *
988
-     * @access protected
989
-     * @abstract
990
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
991
-     * @param WP_Post $post    The post object of the cpt that was saved.
992
-     * @return void
993
-     * @throws EE_Error
994
-     * @throws ReflectionException
995
-     */
996
-    protected function _insert_update_cpt_item($post_id, $post)
997
-    {
998
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
999
-            // get out we're not processing an event save.
1000
-            return;
1001
-        }
1002
-
1003
-        $event_values = [
1004
-            'EVT_display_desc'                => $this->request->getRequestParam('display_desc', false, 'bool'),
1005
-            'EVT_display_ticket_selector'     => $this->request->getRequestParam(
1006
-                'display_ticket_selector',
1007
-                false,
1008
-                'bool'
1009
-            ),
1010
-            'EVT_additional_limit'            => min(
1011
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1012
-                $this->request->getRequestParam('additional_limit', null, 'int')
1013
-            ),
1014
-            'EVT_default_registration_status' => $this->request->getRequestParam(
1015
-                'EVT_default_registration_status',
1016
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1017
-            ),
1018
-
1019
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1020
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1021
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1022
-            'EVT_external_URL'    => $this->request->getRequestParam('externalURL'),
1023
-            'EVT_phone'           => $this->request->getRequestParam('event_phone'),
1024
-        ];
1025
-        // update event
1026
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1027
-        // get event_object for other metaboxes...
1028
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1029
-        // i have to setup where conditions to override the filters in the model
1030
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1031
-        $event = $this->_event_model()->get_one(
1032
-            [
1033
-                [
1034
-                    $this->_event_model()->primary_key_name() => $post_id,
1035
-                    'OR'                                      => [
1036
-                        'status'   => $post->post_status,
1037
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1038
-                        // but the returned object here has a status of "publish", so use the original post status as well
1039
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1040
-                    ],
1041
-                ],
1042
-            ]
1043
-        );
1044
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1045
-        $event_update_callbacks = apply_filters(
1046
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1047
-            [
1048
-                [$this, '_default_venue_update'],
1049
-                [$this, '_default_tickets_update'],
1050
-            ]
1051
-        );
1052
-        $att_success            = true;
1053
-        foreach ($event_update_callbacks as $e_callback) {
1054
-            $_success = is_callable($e_callback)
1055
-                ? call_user_func($e_callback, $event, $this->request->requestParams())
1056
-                : false;
1057
-            // if ANY of these updates fail then we want the appropriate global error message
1058
-            $att_success = ! $att_success ? $att_success : $_success;
1059
-        }
1060
-        // any errors?
1061
-        if ($success && false === $att_success) {
1062
-            EE_Error::add_error(
1063
-                esc_html__(
1064
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1065
-                    'event_espresso'
1066
-                ),
1067
-                __FILE__,
1068
-                __FUNCTION__,
1069
-                __LINE__
1070
-            );
1071
-        } elseif ($success === false) {
1072
-            EE_Error::add_error(
1073
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1074
-                __FILE__,
1075
-                __FUNCTION__,
1076
-                __LINE__
1077
-            );
1078
-        }
1079
-    }
1080
-
1081
-
1082
-    /**
1083
-     * @param int $post_id
1084
-     * @param int $revision_id
1085
-     * @throws EE_Error
1086
-     * @throws EE_Error
1087
-     * @throws ReflectionException
1088
-     * @see parent::restore_item()
1089
-     */
1090
-    protected function _restore_cpt_item($post_id, $revision_id)
1091
-    {
1092
-        // copy existing event meta to new post
1093
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1094
-        if ($post_evt instanceof EE_Event) {
1095
-            // meta revision restore
1096
-            $post_evt->restore_revision($revision_id);
1097
-            // related objs restore
1098
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1099
-        }
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * Attach the venue to the Event
1105
-     *
1106
-     * @param EE_Event $event Event Object to add the venue to
1107
-     * @param array    $data  The request data from the form
1108
-     * @return bool           Success or fail.
1109
-     * @throws EE_Error
1110
-     * @throws ReflectionException
1111
-     */
1112
-    protected function _default_venue_update(EE_Event $event, $data)
1113
-    {
1114
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1115
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1116
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1117
-        // very important.  If we don't have a venue name...
1118
-        // then we'll get out because not necessary to create empty venue
1119
-        if (empty($data['venue_title'])) {
1120
-            return false;
1121
-        }
1122
-        $venue_array = [
1123
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1124
-            'VNU_name'            => $data['venue_title'],
1125
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1126
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1127
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1128
-                ? $data['venue_short_description']
1129
-                : null,
1130
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1131
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1132
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1133
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1134
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1135
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1136
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1137
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1138
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1139
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1140
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1141
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1142
-            'status'              => 'publish',
1143
-        ];
1144
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1145
-        if (! empty($venue_id)) {
1146
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1147
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1148
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1149
-            $event->_add_relation_to($venue_id, 'Venue');
1150
-            return $rows_affected > 0;
1151
-        }
1152
-        // we insert the venue
1153
-        $venue_id = $venue_model->insert($venue_array);
1154
-        $event->_add_relation_to($venue_id, 'Venue');
1155
-        return ! empty($venue_id);
1156
-        // when we have the ancestor come in it's already been handled by the revision save.
1157
-    }
1158
-
1159
-
1160
-    /**
1161
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1162
-     *
1163
-     * @param EE_Event $event The Event object we're attaching data to
1164
-     * @param array    $data  The request data from the form
1165
-     * @return array
1166
-     * @throws EE_Error
1167
-     * @throws ReflectionException
1168
-     * @throws Exception
1169
-     */
1170
-    protected function _default_tickets_update(EE_Event $event, $data)
1171
-    {
1172
-        $datetime       = null;
1173
-        $saved_tickets  = [];
1174
-        $event_timezone = $event->get_timezone();
1175
-        $date_formats   = ['Y-m-d', 'h:i a'];
1176
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1177
-            // trim all values to ensure any excess whitespace is removed.
1178
-            $datetime_data                = array_map('trim', $datetime_data);
1179
-            $datetime_data['DTT_EVT_end'] =
1180
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1181
-                    ? $datetime_data['DTT_EVT_end']
1182
-                    : $datetime_data['DTT_EVT_start'];
1183
-            $datetime_values              = [
1184
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1185
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1186
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1187
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1188
-                'DTT_order'     => $row,
1189
-            ];
1190
-            // if we have an id then let's get existing object first and then set the new values.
1191
-            //  Otherwise we instantiate a new object for save.
1192
-            if (! empty($datetime_data['DTT_ID'])) {
1193
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1194
-                if (! $datetime instanceof EE_Datetime) {
1195
-                    throw new RuntimeException(
1196
-                        sprintf(
1197
-                            esc_html__(
1198
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1199
-                                'event_espresso'
1200
-                            ),
1201
-                            $datetime_data['DTT_ID']
1202
-                        )
1203
-                    );
1204
-                }
1205
-                $datetime->set_date_format($date_formats[0]);
1206
-                $datetime->set_time_format($date_formats[1]);
1207
-                foreach ($datetime_values as $field => $value) {
1208
-                    $datetime->set($field, $value);
1209
-                }
1210
-            } else {
1211
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1212
-            }
1213
-            if (! $datetime instanceof EE_Datetime) {
1214
-                throw new RuntimeException(
1215
-                    sprintf(
1216
-                        esc_html__(
1217
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1218
-                            'event_espresso'
1219
-                        ),
1220
-                        print_r($datetime_values, true)
1221
-                    )
1222
-                );
1223
-            }
1224
-            // before going any further make sure our dates are setup correctly
1225
-            // so that the end date is always equal or greater than the start date.
1226
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1227
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1228
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1229
-            }
1230
-            $datetime->save();
1231
-            $event->_add_relation_to($datetime, 'Datetime');
1232
-        }
1233
-        // no datetimes get deleted so we don't do any of that logic here.
1234
-        // update tickets next
1235
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1236
-
1237
-        // set up some default start and end dates in case those are not present in the incoming data
1238
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1239
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1240
-        // use the start date of the first datetime for the end date
1241
-        $first_datetime   = $event->first_datetime();
1242
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1243
-
1244
-        // now process the incoming data
1245
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1246
-            $update_prices = false;
1247
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1248
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1249
-                : 0;
1250
-            // trim inputs to ensure any excess whitespace is removed.
1251
-            $ticket_data   = array_map('trim', $ticket_data);
1252
-            $ticket_values = [
1253
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1254
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1255
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1256
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1257
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1258
-                    ? $ticket_data['TKT_start_date']
1259
-                    : $default_start_date,
1260
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1261
-                    ? $ticket_data['TKT_end_date']
1262
-                    : $default_end_date,
1263
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1264
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1265
-                    ? $ticket_data['TKT_qty']
1266
-                    : EE_INF,
1267
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1268
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1269
-                    ? $ticket_data['TKT_uses']
1270
-                    : EE_INF,
1271
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1272
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1273
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1274
-                'TKT_price'       => $ticket_price,
1275
-                'TKT_row'         => $row,
1276
-            ];
1277
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1278
-            // which means in turn that the prices will become new prices as well.
1279
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1280
-                $ticket_values['TKT_ID']         = 0;
1281
-                $ticket_values['TKT_is_default'] = 0;
1282
-                $update_prices                   = true;
1283
-            }
1284
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1285
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1286
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1287
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1288
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1289
-            if (! empty($ticket_data['TKT_ID'])) {
1290
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1291
-                if (! $existing_ticket instanceof EE_Ticket) {
1292
-                    throw new RuntimeException(
1293
-                        sprintf(
1294
-                            esc_html__(
1295
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1296
-                                'event_espresso'
1297
-                            ),
1298
-                            $ticket_data['TKT_ID']
1299
-                        )
1300
-                    );
1301
-                }
1302
-                $ticket_sold = $existing_ticket->count_related(
1303
-                    'Registration',
1304
-                    [
1305
-                        [
1306
-                            'STS_ID' => [
1307
-                                'NOT IN',
1308
-                                [EEM_Registration::status_id_incomplete],
1309
-                            ],
1310
-                        ],
1311
-                    ]
1312
-                ) > 0;
1313
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1314
-                // if they are different then we create a new ticket (if $ticket_sold)
1315
-                // if they aren't different then we go ahead and modify existing ticket.
1316
-                $create_new_ticket = $ticket_sold
1317
-                                     && $ticket_price !== $existing_ticket->price()
1318
-                                     && ! $existing_ticket->deleted();
1319
-                $existing_ticket->set_date_format($date_formats[0]);
1320
-                $existing_ticket->set_time_format($date_formats[1]);
1321
-                // set new values
1322
-                foreach ($ticket_values as $field => $value) {
1323
-                    if ($field == 'TKT_qty') {
1324
-                        $existing_ticket->set_qty($value);
1325
-                    } elseif ($field == 'TKT_price') {
1326
-                        $existing_ticket->set('TKT_price', $ticket_price);
1327
-                    } else {
1328
-                        $existing_ticket->set($field, $value);
1329
-                    }
1330
-                }
1331
-                $ticket = $existing_ticket;
1332
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1333
-                //  Otherwise we have to create a new ticket.
1334
-                if ($create_new_ticket) {
1335
-                    // archive the old ticket first
1336
-                    $existing_ticket->set('TKT_deleted', 1);
1337
-                    $existing_ticket->save();
1338
-                    // make sure this ticket is still recorded in our $saved_tickets
1339
-                    // so we don't run it through the regular trash routine.
1340
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1341
-                    // create new ticket that's a copy of the existing except,
1342
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1343
-                    $new_ticket = clone $existing_ticket;
1344
-                    $new_ticket->set('TKT_ID', 0);
1345
-                    $new_ticket->set('TKT_deleted', 0);
1346
-                    $new_ticket->set('TKT_sold', 0);
1347
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1348
-                    $update_prices = true;
1349
-                    $ticket        = $new_ticket;
1350
-                }
1351
-            } else {
1352
-                // no TKT_id so a new ticket
1353
-                $ticket_values['TKT_price'] = $ticket_price;
1354
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1355
-                $update_prices              = true;
1356
-            }
1357
-            if (! $ticket instanceof EE_Ticket) {
1358
-                throw new RuntimeException(
1359
-                    sprintf(
1360
-                        esc_html__(
1361
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1362
-                            'event_espresso'
1363
-                        ),
1364
-                        print_r($ticket_values, true)
1365
-                    )
1366
-                );
1367
-            }
1368
-            // cap ticket qty by datetime reg limits
1369
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1370
-            // update ticket.
1371
-            $ticket->save();
1372
-            // before going any further make sure our dates are setup correctly
1373
-            // so that the end date is always equal or greater than the start date.
1374
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1375
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1376
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1377
-                $ticket->save();
1378
-            }
1379
-            // initially let's add the ticket to the datetime
1380
-            $datetime->_add_relation_to($ticket, 'Ticket');
1381
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1382
-            // add prices to ticket
1383
-            $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1384
-                ? $data['edit_prices'][ $row ]
1385
-                : [];
1386
-            $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1387
-        }
1388
-        // however now we need to handle permanently deleting tickets via the ui.
1389
-        // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1390
-        // However, it does allow for deleting tickets that have no tickets sold,
1391
-        // in which case we want to get rid of permanently because there is no need to save in db.
1392
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets;
1393
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1394
-        foreach ($tickets_removed as $id) {
1395
-            $id = absint($id);
1396
-            // get the ticket for this id
1397
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1398
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1399
-                continue;
1400
-            }
1401
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1402
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1403
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1404
-            foreach ($related_datetimes as $related_datetime) {
1405
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1406
-            }
1407
-            // need to do the same for prices (except these prices can also be deleted because again,
1408
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1409
-            $ticket_to_remove->delete_related_permanently('Price');
1410
-            // finally let's delete this ticket
1411
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1412
-            $ticket_to_remove->delete_permanently();
1413
-        }
1414
-        return [$datetime, $saved_tickets];
1415
-    }
1416
-
1417
-
1418
-    /**
1419
-     * This attaches a list of given prices to a ticket.
1420
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1421
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1422
-     * price info and prices are automatically "archived" via the ticket.
1423
-     *
1424
-     * @access  private
1425
-     * @param array     $prices_data Array of prices from the form.
1426
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1427
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1428
-     * @return  void
1429
-     * @throws EE_Error
1430
-     * @throws ReflectionException
1431
-     */
1432
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1433
-    {
1434
-        $timezone = $ticket->get_timezone();
1435
-        foreach ($prices_data as $row => $price_data) {
1436
-            $price_values = [
1437
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1438
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1439
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1440
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1441
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1442
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1443
-                'PRC_order'      => $row,
1444
-            ];
1445
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1446
-                $price_values['PRC_ID'] = 0;
1447
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1448
-            } else {
1449
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1450
-                // update this price with new values
1451
-                foreach ($price_values as $field => $new_price) {
1452
-                    $price->set($field, $new_price);
1453
-                }
1454
-            }
1455
-            if (! $price instanceof EE_Price) {
1456
-                throw new RuntimeException(
1457
-                    sprintf(
1458
-                        esc_html__(
1459
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1460
-                            'event_espresso'
1461
-                        ),
1462
-                        print_r($price_values, true)
1463
-                    )
1464
-                );
1465
-            }
1466
-            $price->save();
1467
-            $ticket->_add_relation_to($price, 'Price');
1468
-        }
1469
-    }
1470
-
1471
-
1472
-    /**
1473
-     * Add in our autosave ajax handlers
1474
-     *
1475
-     */
1476
-    protected function _ee_autosave_create_new()
1477
-    {
1478
-    }
1479
-
1480
-
1481
-    /**
1482
-     * More autosave handlers.
1483
-     */
1484
-    protected function _ee_autosave_edit()
1485
-    {
1486
-        // TEMPORARILY EXITING CAUSE THIS IS A TODO
1487
-    }
1488
-
1489
-
1490
-    /**
1491
-     * @throws EE_Error
1492
-     * @throws ReflectionException
1493
-     */
1494
-    private function _generate_publish_box_extra_content()
1495
-    {
1496
-        // load formatter helper
1497
-        // args for getting related registrations
1498
-        $approved_query_args        = [
1499
-            [
1500
-                'REG_deleted' => 0,
1501
-                'STS_ID'      => EEM_Registration::status_id_approved,
1502
-            ],
1503
-        ];
1504
-        $not_approved_query_args    = [
1505
-            [
1506
-                'REG_deleted' => 0,
1507
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1508
-            ],
1509
-        ];
1510
-        $pending_payment_query_args = [
1511
-            [
1512
-                'REG_deleted' => 0,
1513
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1514
-            ],
1515
-        ];
1516
-        // publish box
1517
-        $publish_box_extra_args = [
1518
-            'view_approved_reg_url'        => add_query_arg(
1519
-                [
1520
-                    'action'      => 'default',
1521
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1522
-                    '_reg_status' => EEM_Registration::status_id_approved,
1523
-                ],
1524
-                REG_ADMIN_URL
1525
-            ),
1526
-            'view_not_approved_reg_url'    => add_query_arg(
1527
-                [
1528
-                    'action'      => 'default',
1529
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1530
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1531
-                ],
1532
-                REG_ADMIN_URL
1533
-            ),
1534
-            'view_pending_payment_reg_url' => add_query_arg(
1535
-                [
1536
-                    'action'      => 'default',
1537
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1538
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1539
-                ],
1540
-                REG_ADMIN_URL
1541
-            ),
1542
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1543
-                'Registration',
1544
-                $approved_query_args
1545
-            ),
1546
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1547
-                'Registration',
1548
-                $not_approved_query_args
1549
-            ),
1550
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1551
-                'Registration',
1552
-                $pending_payment_query_args
1553
-            ),
1554
-            'misc_pub_section_class'       => apply_filters(
1555
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1556
-                'misc-pub-section'
1557
-            ),
1558
-        ];
1559
-        ob_start();
1560
-        do_action(
1561
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1562
-            $this->_cpt_model_obj
1563
-        );
1564
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1565
-        // load template
1566
-        EEH_Template::display_template(
1567
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1568
-            $publish_box_extra_args
1569
-        );
1570
-    }
1571
-
1572
-
1573
-    /**
1574
-     * @return EE_Event
1575
-     */
1576
-    public function get_event_object()
1577
-    {
1578
-        return $this->_cpt_model_obj;
1579
-    }
1580
-
1581
-
1582
-
1583
-
1584
-    /** METABOXES * */
1585
-    /**
1586
-     * _register_event_editor_meta_boxes
1587
-     * add all metaboxes related to the event_editor
1588
-     *
1589
-     * @return void
1590
-     * @throws EE_Error
1591
-     * @throws ReflectionException
1592
-     */
1593
-    protected function _register_event_editor_meta_boxes()
1594
-    {
1595
-        $this->verify_cpt_object();
1596
-        add_meta_box(
1597
-            'espresso_event_editor_tickets',
1598
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1599
-            [$this, 'ticket_metabox'],
1600
-            $this->page_slug,
1601
-            'normal',
1602
-            'high'
1603
-        );
1604
-        add_meta_box(
1605
-            'espresso_event_editor_event_options',
1606
-            esc_html__('Event Registration Options', 'event_espresso'),
1607
-            [$this, 'registration_options_meta_box'],
1608
-            $this->page_slug,
1609
-            'side'
1610
-        );
1611
-        // NOTE: if you're looking for other metaboxes in here,
1612
-        // where a metabox has a related management page in the admin
1613
-        // you will find it setup in the related management page's "_Hooks" file.
1614
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1615
-    }
1616
-
1617
-
1618
-    /**
1619
-     * @throws DomainException
1620
-     * @throws EE_Error
1621
-     * @throws ReflectionException
1622
-     */
1623
-    public function ticket_metabox()
1624
-    {
1625
-        $existing_datetime_ids = $existing_ticket_ids = [];
1626
-        // defaults for template args
1627
-        $template_args = [
1628
-            'existing_datetime_ids'    => '',
1629
-            'event_datetime_help_link' => '',
1630
-            'ticket_options_help_link' => '',
1631
-            'time'                     => null,
1632
-            'ticket_rows'              => '',
1633
-            'existing_ticket_ids'      => '',
1634
-            'total_ticket_rows'        => 1,
1635
-            'ticket_js_structure'      => '',
1636
-            'trash_icon'               => 'ee-lock-icon',
1637
-            'disabled'                 => '',
1638
-        ];
1639
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1640
-        /**
1641
-         * 1. Start with retrieving Datetimes
1642
-         * 2. Fore each datetime get related tickets
1643
-         * 3. For each ticket get related prices
1644
-         */
1645
-        $times          = EEM_Datetime::instance()->get_all_event_dates($event_id);
1646
-        $first_datetime = reset($times);
1647
-        // do we get related tickets?
1648
-        if (
1649
-            $first_datetime instanceof EE_Datetime
1650
-            && $first_datetime->ID() !== 0
1651
-        ) {
1652
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1653
-            $template_args['time']   = $first_datetime;
1654
-            $related_tickets         = $first_datetime->tickets(
1655
-                [
1656
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1657
-                    'default_where_conditions' => 'none',
1658
-                ]
1659
-            );
1660
-            if (! empty($related_tickets)) {
1661
-                $template_args['total_ticket_rows'] = count($related_tickets);
1662
-                $row                                = 0;
1663
-                foreach ($related_tickets as $ticket) {
1664
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1665
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1666
-                    $row++;
1667
-                }
1668
-            } else {
1669
-                $template_args['total_ticket_rows'] = 1;
1670
-                /** @type EE_Ticket $ticket */
1671
-                $ticket                       = EEM_Ticket::instance()->create_default_object();
1672
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1673
-            }
1674
-        } else {
1675
-            $template_args['time']        = $times[0];
1676
-            $tickets                      = EEM_Ticket::instance()->get_all_default_tickets();
1677
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1678
-            // NOTE: we're just sending the first default row
1679
-            // (decaf can't manage default tickets so this should be sufficient);
1680
-        }
1681
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1682
-            'event_editor_event_datetimes_help_tab'
1683
-        );
1684
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1685
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1686
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1687
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1688
-            EEM_Ticket::instance()->create_default_object(),
1689
-            true
1690
-        );
1691
-        $template                                  = apply_filters(
1692
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1693
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1694
-        );
1695
-        EEH_Template::display_template($template, $template_args);
1696
-    }
1697
-
1698
-
1699
-    /**
1700
-     * Setup an individual ticket form for the decaf event editor page
1701
-     *
1702
-     * @access private
1703
-     * @param EE_Ticket $ticket   the ticket object
1704
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1705
-     * @param int       $row
1706
-     * @return string generated html for the ticket row.
1707
-     * @throws EE_Error
1708
-     * @throws ReflectionException
1709
-     */
1710
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1711
-    {
1712
-        $template_args = [
1713
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1714
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1715
-                : '',
1716
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1717
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1718
-            'TKT_name'            => $ticket->get('TKT_name'),
1719
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1720
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1721
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1722
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1723
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1724
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1725
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1726
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1727
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1728
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1729
-                : ' disabled=disabled',
1730
-        ];
1731
-        $price         = $ticket->ID() !== 0
1732
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1733
-            : null;
1734
-        $price         = $price instanceof EE_Price
1735
-            ? $price
1736
-            : EEM_Price::instance()->create_default_object();
1737
-        $price_args    = [
1738
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1739
-            'PRC_amount'            => $price->get('PRC_amount'),
1740
-            'PRT_ID'                => $price->get('PRT_ID'),
1741
-            'PRC_ID'                => $price->get('PRC_ID'),
1742
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1743
-        ];
1744
-        // make sure we have default start and end dates if skeleton
1745
-        // handle rows that should NOT be empty
1746
-        if (empty($template_args['TKT_start_date'])) {
1747
-            // if empty then the start date will be now.
1748
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1749
-        }
1750
-        if (empty($template_args['TKT_end_date'])) {
1751
-            // get the earliest datetime (if present);
1752
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1753
-                ? $this->_cpt_model_obj->get_first_related(
1754
-                    'Datetime',
1755
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1756
-                )
1757
-                : null;
1758
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1759
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1760
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1761
-        }
1762
-        $template_args = array_merge($template_args, $price_args);
1763
-        $template      = apply_filters(
1764
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1765
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1766
-            $ticket
1767
-        );
1768
-        return EEH_Template::display_template($template, $template_args, true);
1769
-    }
1770
-
1771
-
1772
-    /**
1773
-     * @throws EE_Error
1774
-     * @throws ReflectionException
1775
-     */
1776
-    public function registration_options_meta_box()
1777
-    {
1778
-        $yes_no_values             = [
1779
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1780
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1781
-        ];
1782
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1783
-            [
1784
-                EEM_Registration::status_id_cancelled,
1785
-                EEM_Registration::status_id_declined,
1786
-                EEM_Registration::status_id_incomplete,
1787
-            ],
1788
-            true
1789
-        );
1790
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1791
-        $template_args['_event']                          = $this->_cpt_model_obj;
1792
-        $template_args['event']                           = $this->_cpt_model_obj;
1793
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1794
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1795
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1796
-            'default_reg_status',
1797
-            $default_reg_status_values,
1798
-            $this->_cpt_model_obj->default_registration_status()
1799
-        );
1800
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1801
-            'display_desc',
1802
-            $yes_no_values,
1803
-            $this->_cpt_model_obj->display_description()
1804
-        );
1805
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1806
-            'display_ticket_selector',
1807
-            $yes_no_values,
1808
-            $this->_cpt_model_obj->display_ticket_selector(),
1809
-            '',
1810
-            '',
1811
-            false
1812
-        );
1813
-        $template_args['additional_registration_options'] = apply_filters(
1814
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1815
-            '',
1816
-            $template_args,
1817
-            $yes_no_values,
1818
-            $default_reg_status_values
1819
-        );
1820
-        EEH_Template::display_template(
1821
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1822
-            $template_args
1823
-        );
1824
-    }
1825
-
1826
-
1827
-    /**
1828
-     * _get_events()
1829
-     * This method simply returns all the events (for the given _view and paging)
1830
-     *
1831
-     * @access public
1832
-     * @param int  $per_page     count of items per page (20 default);
1833
-     * @param int  $current_page what is the current page being viewed.
1834
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1835
-     *                           If FALSE then we return an array of event objects
1836
-     *                           that match the given _view and paging parameters.
1837
-     * @return array|int         an array of event objects or a count of them.
1838
-     * @throws Exception
1839
-     */
1840
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1841
-    {
1842
-        $EEM_Event   = $this->_event_model();
1843
-        $offset      = ($current_page - 1) * $per_page;
1844
-        $limit       = $count ? null : $offset . ',' . $per_page;
1845
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1846
-        $order       = $this->request->getRequestParam('order', 'DESC');
1847
-        $month_range = $this->request->getRequestParam('month_range');
1848
-        if ($month_range) {
1849
-            $pieces = explode(' ', $month_range, 3);
1850
-            // simulate the FIRST day of the month, that fixes issues for months like February
1851
-            // where PHP doesn't know what to assume for date.
1852
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1853
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1854
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1855
-        }
1856
-        $where  = [];
1857
-        $status = $this->request->getRequestParam('status');
1858
-        // determine what post_status our condition will have for the query.
1859
-        switch ($status) {
1860
-            case 'month':
1861
-            case 'today':
1862
-            case null:
1863
-            case 'all':
1864
-                break;
1865
-            case 'draft':
1866
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1867
-                break;
1868
-            default:
1869
-                $where['status'] = $status;
1870
-        }
1871
-        // categories? The default for all categories is -1
1872
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1873
-        if ($category !== -1) {
1874
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1875
-            $where['Term_Taxonomy.term_id']  = $category;
1876
-        }
1877
-        // date where conditions
1878
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1879
-        if ($month_range) {
1880
-            $DateTime = new DateTime(
1881
-                $year_r . '-' . $month_r . '-01 00:00:00',
1882
-                new DateTimeZone('UTC')
1883
-            );
1884
-            $start    = $DateTime->getTimestamp();
1885
-            // set the datetime to be the end of the month
1886
-            $DateTime->setDate(
1887
-                $year_r,
1888
-                $month_r,
1889
-                $DateTime->format('t')
1890
-            )->setTime(23, 59, 59);
1891
-            $end                             = $DateTime->getTimestamp();
1892
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1893
-        } elseif ($status === 'today') {
1894
-            $DateTime                        =
1895
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1896
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1897
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1898
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1899
-        } elseif ($status === 'month') {
1900
-            $now                             = date('Y-m-01');
1901
-            $DateTime                        =
1902
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1903
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1904
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1905
-                                                        ->setTime(23, 59, 59)
1906
-                                                        ->format(implode(' ', $start_formats));
1907
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1908
-        }
1909
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1910
-            $where['EVT_wp_user'] = get_current_user_id();
1911
-        } else {
1912
-            if (! isset($where['status'])) {
1913
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1914
-                    $where['OR'] = [
1915
-                        'status*restrict_private' => ['!=', 'private'],
1916
-                        'AND'                     => [
1917
-                            'status*inclusive' => ['=', 'private'],
1918
-                            'EVT_wp_user'      => get_current_user_id(),
1919
-                        ],
1920
-                    ];
1921
-                }
1922
-            }
1923
-        }
1924
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1925
-        if (
1926
-            $wp_user
1927
-            && $wp_user !== get_current_user_id()
1928
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1929
-        ) {
1930
-            $where['EVT_wp_user'] = $wp_user;
1931
-        }
1932
-        // search query handling
1933
-        $search_term = $this->request->getRequestParam('s');
1934
-        if ($search_term) {
1935
-            $search_term = '%' . $search_term . '%';
1936
-            $where['OR'] = [
1937
-                'EVT_name'       => ['LIKE', $search_term],
1938
-                'EVT_desc'       => ['LIKE', $search_term],
1939
-                'EVT_short_desc' => ['LIKE', $search_term],
1940
-            ];
1941
-        }
1942
-        // filter events by venue.
1943
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
1944
-        if ($venue) {
1945
-            $where['Venue.VNU_ID'] = $venue;
1946
-        }
1947
-        $request_params = $this->request->requestParams();
1948
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
1949
-        $query_params   = apply_filters(
1950
-            'FHEE__Events_Admin_Page__get_events__query_params',
1951
-            [
1952
-                $where,
1953
-                'limit'    => $limit,
1954
-                'order_by' => $orderby,
1955
-                'order'    => $order,
1956
-                'group_by' => 'EVT_ID',
1957
-            ],
1958
-            $request_params
1959
-        );
1960
-
1961
-        // let's first check if we have special requests coming in.
1962
-        $active_status = $this->request->getRequestParam('active_status');
1963
-        if ($active_status) {
1964
-            switch ($active_status) {
1965
-                case 'upcoming':
1966
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
1967
-                case 'expired':
1968
-                    return $EEM_Event->get_expired_events($query_params, $count);
1969
-                case 'active':
1970
-                    return $EEM_Event->get_active_events($query_params, $count);
1971
-                case 'inactive':
1972
-                    return $EEM_Event->get_inactive_events($query_params, $count);
1973
-            }
1974
-        }
1975
-
1976
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
1977
-    }
1978
-
1979
-
1980
-    /**
1981
-     * handling for WordPress CPT actions (trash, restore, delete)
1982
-     *
1983
-     * @param string $post_id
1984
-     * @throws EE_Error
1985
-     * @throws ReflectionException
1986
-     */
1987
-    public function trash_cpt_item($post_id)
1988
-    {
1989
-        $this->request->setRequestParam('EVT_ID', $post_id);
1990
-        $this->_trash_or_restore_event('trash', false);
1991
-    }
1992
-
1993
-
1994
-    /**
1995
-     * @param string $post_id
1996
-     * @throws EE_Error
1997
-     * @throws ReflectionException
1998
-     */
1999
-    public function restore_cpt_item($post_id)
2000
-    {
2001
-        $this->request->setRequestParam('EVT_ID', $post_id);
2002
-        $this->_trash_or_restore_event('draft', false);
2003
-    }
2004
-
2005
-
2006
-    /**
2007
-     * @param string $post_id
2008
-     * @throws EE_Error
2009
-     * @throws EE_Error
2010
-     */
2011
-    public function delete_cpt_item($post_id)
2012
-    {
2013
-        throw new EE_Error(
2014
-            esc_html__(
2015
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2016
-                'event_espresso'
2017
-            )
2018
-        );
2019
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2020
-        // $this->_delete_event();
2021
-    }
2022
-
2023
-
2024
-    /**
2025
-     * _trash_or_restore_event
2026
-     *
2027
-     * @access protected
2028
-     * @param string $event_status
2029
-     * @param bool   $redirect_after
2030
-     * @throws EE_Error
2031
-     * @throws EE_Error
2032
-     * @throws ReflectionException
2033
-     */
2034
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2035
-    {
2036
-        // determine the event id and set to array.
2037
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2038
-        // loop thru events
2039
-        if ($EVT_ID) {
2040
-            // clean status
2041
-            $event_status = sanitize_key($event_status);
2042
-            // grab status
2043
-            if (! empty($event_status)) {
2044
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2045
-            } else {
2046
-                $success = false;
2047
-                $msg     = esc_html__(
2048
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2049
-                    'event_espresso'
2050
-                );
2051
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2052
-            }
2053
-        } else {
2054
-            $success = false;
2055
-            $msg     = esc_html__(
2056
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2057
-                'event_espresso'
2058
-            );
2059
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2060
-        }
2061
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2062
-        if ($redirect_after) {
2063
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2064
-        }
2065
-    }
2066
-
2067
-
2068
-    /**
2069
-     * _trash_or_restore_events
2070
-     *
2071
-     * @access protected
2072
-     * @param string $event_status
2073
-     * @return void
2074
-     * @throws EE_Error
2075
-     * @throws EE_Error
2076
-     * @throws ReflectionException
2077
-     */
2078
-    protected function _trash_or_restore_events($event_status = 'trash')
2079
-    {
2080
-        // clean status
2081
-        $event_status = sanitize_key($event_status);
2082
-        // grab status
2083
-        if (! empty($event_status)) {
2084
-            $success = true;
2085
-            // determine the event id and set to array.
2086
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2087
-            // loop thru events
2088
-            foreach ($EVT_IDs as $EVT_ID) {
2089
-                if ($EVT_ID = absint($EVT_ID)) {
2090
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2091
-                    $success = $results !== false ? $success : false;
2092
-                } else {
2093
-                    $msg = sprintf(
2094
-                        esc_html__(
2095
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2096
-                            'event_espresso'
2097
-                        ),
2098
-                        $EVT_ID
2099
-                    );
2100
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2101
-                    $success = false;
2102
-                }
2103
-            }
2104
-        } else {
2105
-            $success = false;
2106
-            $msg     = esc_html__(
2107
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2108
-                'event_espresso'
2109
-            );
2110
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2111
-        }
2112
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2113
-        $success = $success ? 2 : false;
2114
-        $action  = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2115
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2116
-    }
2117
-
2118
-
2119
-    /**
2120
-     * @param int    $EVT_ID
2121
-     * @param string $event_status
2122
-     * @return bool
2123
-     * @throws EE_Error
2124
-     * @throws ReflectionException
2125
-     */
2126
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2127
-    {
2128
-        // grab event id
2129
-        if (! $EVT_ID) {
2130
-            $msg = esc_html__(
2131
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2132
-                'event_espresso'
2133
-            );
2134
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2135
-            return false;
2136
-        }
2137
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2138
-        // clean status
2139
-        $event_status = sanitize_key($event_status);
2140
-        // grab status
2141
-        if (empty($event_status)) {
2142
-            $msg = esc_html__(
2143
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2144
-                'event_espresso'
2145
-            );
2146
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2147
-            return false;
2148
-        }
2149
-        // was event trashed or restored ?
2150
-        switch ($event_status) {
2151
-            case 'draft':
2152
-                $action = 'restored from the trash';
2153
-                $hook   = 'AHEE_event_restored_from_trash';
2154
-                break;
2155
-            case 'trash':
2156
-                $action = 'moved to the trash';
2157
-                $hook   = 'AHEE_event_moved_to_trash';
2158
-                break;
2159
-            default:
2160
-                $action = 'updated';
2161
-                $hook   = false;
2162
-        }
2163
-        // use class to change status
2164
-        $this->_cpt_model_obj->set_status($event_status);
2165
-        $success = $this->_cpt_model_obj->save();
2166
-        if (! $success) {
2167
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2168
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2169
-            return false;
2170
-        }
2171
-        if ($hook) {
2172
-            do_action($hook);
2173
-        }
2174
-        return true;
2175
-    }
2176
-
2177
-
2178
-    /**
2179
-     * @param array $event_ids
2180
-     * @return array
2181
-     * @since   4.10.23.p
2182
-     */
2183
-    private function cleanEventIds(array $event_ids)
2184
-    {
2185
-        return array_map('absint', $event_ids);
2186
-    }
2187
-
2188
-
2189
-    /**
2190
-     * @return array
2191
-     * @since   4.10.23.p
2192
-     */
2193
-    private function getEventIdsFromRequest()
2194
-    {
2195
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2196
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2197
-        } else {
2198
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2199
-        }
2200
-    }
2201
-
2202
-
2203
-    /**
2204
-     * @param bool $preview_delete
2205
-     * @throws EE_Error
2206
-     */
2207
-    protected function _delete_event($preview_delete = true)
2208
-    {
2209
-        $this->_delete_events($preview_delete);
2210
-    }
2211
-
2212
-
2213
-    /**
2214
-     * Gets the tree traversal batch persister.
2215
-     *
2216
-     * @return NodeGroupDao
2217
-     * @throws InvalidArgumentException
2218
-     * @throws InvalidDataTypeException
2219
-     * @throws InvalidInterfaceException
2220
-     * @since 4.10.12.p
2221
-     */
2222
-    protected function getModelObjNodeGroupPersister()
2223
-    {
2224
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2225
-            $this->model_obj_node_group_persister =
2226
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2227
-        }
2228
-        return $this->model_obj_node_group_persister;
2229
-    }
2230
-
2231
-
2232
-    /**
2233
-     * @param bool $preview_delete
2234
-     * @return void
2235
-     * @throws EE_Error
2236
-     */
2237
-    protected function _delete_events($preview_delete = true)
2238
-    {
2239
-        $event_ids = $this->getEventIdsFromRequest();
2240
-        if ($preview_delete) {
2241
-            $this->generateDeletionPreview($event_ids);
2242
-        } else {
2243
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2244
-        }
2245
-    }
2246
-
2247
-
2248
-    /**
2249
-     * @param array $event_ids
2250
-     */
2251
-    protected function generateDeletionPreview(array $event_ids)
2252
-    {
2253
-        $event_ids = $this->cleanEventIds($event_ids);
2254
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2255
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2256
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2257
-            [
2258
-                'action'            => 'preview_deletion',
2259
-                'deletion_job_code' => $deletion_job_code,
2260
-            ],
2261
-            $this->_admin_base_url
2262
-        );
2263
-        EEH_URL::safeRedirectAndExit(
2264
-            EE_Admin_Page::add_query_args_and_nonce(
2265
-                [
2266
-                    'page'              => 'espresso_batch',
2267
-                    'batch'             => EED_Batch::batch_job,
2268
-                    'EVT_IDs'           => $event_ids,
2269
-                    'deletion_job_code' => $deletion_job_code,
2270
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2271
-                    'return_url'        => urlencode($return_url),
2272
-                ],
2273
-                admin_url()
2274
-            )
2275
-        );
2276
-    }
2277
-
2278
-
2279
-    /**
2280
-     * Checks for a POST submission
2281
-     *
2282
-     * @since 4.10.12.p
2283
-     */
2284
-    protected function confirmDeletion()
2285
-    {
2286
-        $deletion_redirect_logic =
2287
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2288
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2289
-    }
2290
-
2291
-
2292
-    /**
2293
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2294
-     *
2295
-     * @throws EE_Error
2296
-     * @since 4.10.12.p
2297
-     */
2298
-    protected function previewDeletion()
2299
-    {
2300
-        $preview_deletion_logic =
2301
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2302
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2303
-        $this->display_admin_page_with_no_sidebar();
2304
-    }
2305
-
2306
-
2307
-    /**
2308
-     * get total number of events
2309
-     *
2310
-     * @access public
2311
-     * @return int
2312
-     * @throws EE_Error
2313
-     * @throws EE_Error
2314
-     */
2315
-    public function total_events()
2316
-    {
2317
-        return EEM_Event::instance()->count(
2318
-            ['caps' => 'read_admin'],
2319
-            'EVT_ID',
2320
-            true
2321
-        );
2322
-    }
2323
-
2324
-
2325
-    /**
2326
-     * get total number of draft events
2327
-     *
2328
-     * @access public
2329
-     * @return int
2330
-     * @throws EE_Error
2331
-     * @throws EE_Error
2332
-     */
2333
-    public function total_events_draft()
2334
-    {
2335
-        return EEM_Event::instance()->count(
2336
-            [
2337
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2338
-                'caps' => 'read_admin',
2339
-            ],
2340
-            'EVT_ID',
2341
-            true
2342
-        );
2343
-    }
2344
-
2345
-
2346
-    /**
2347
-     * get total number of trashed events
2348
-     *
2349
-     * @access public
2350
-     * @return int
2351
-     * @throws EE_Error
2352
-     * @throws EE_Error
2353
-     */
2354
-    public function total_trashed_events()
2355
-    {
2356
-        return EEM_Event::instance()->count(
2357
-            [
2358
-                ['status' => 'trash'],
2359
-                'caps' => 'read_admin',
2360
-            ],
2361
-            'EVT_ID',
2362
-            true
2363
-        );
2364
-    }
2365
-
2366
-
2367
-    /**
2368
-     *    _default_event_settings
2369
-     *    This generates the Default Settings Tab
2370
-     *
2371
-     * @return void
2372
-     * @throws EE_Error
2373
-     */
2374
-    protected function _default_event_settings()
2375
-    {
2376
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2377
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2378
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2379
-        $this->display_admin_page_with_sidebar();
2380
-    }
2381
-
2382
-
2383
-    /**
2384
-     * Return the form for event settings.
2385
-     *
2386
-     * @return EE_Form_Section_Proper
2387
-     * @throws EE_Error
2388
-     */
2389
-    protected function _default_event_settings_form()
2390
-    {
2391
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2392
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2393
-        // exclude
2394
-            [
2395
-                EEM_Registration::status_id_cancelled,
2396
-                EEM_Registration::status_id_declined,
2397
-                EEM_Registration::status_id_incomplete,
2398
-                EEM_Registration::status_id_wait_list,
2399
-            ],
2400
-            true
2401
-        );
2402
-        return new EE_Form_Section_Proper(
2403
-            [
2404
-                'name'            => 'update_default_event_settings',
2405
-                'html_id'         => 'update_default_event_settings',
2406
-                'html_class'      => 'form-table',
2407
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2408
-                'subsections'     => apply_filters(
2409
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2410
-                    [
2411
-                        'default_reg_status'  => new EE_Select_Input(
2412
-                            $registration_stati_for_selection,
2413
-                            [
2414
-                                'default'         => isset($registration_config->default_STS_ID)
2415
-                                                     && array_key_exists(
2416
-                                                         $registration_config->default_STS_ID,
2417
-                                                         $registration_stati_for_selection
2418
-                                                     )
2419
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2420
-                                    : EEM_Registration::status_id_pending_payment,
2421
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2422
-                                                     . EEH_Template::get_help_tab_link(
2423
-                                                         'default_settings_status_help_tab'
2424
-                                                     ),
2425
-                                'html_help_text'  => esc_html__(
2426
-                                    '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.',
2427
-                                    'event_espresso'
2428
-                                ),
2429
-                            ]
2430
-                        ),
2431
-                        'default_max_tickets' => new EE_Integer_Input(
2432
-                            [
2433
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2434
-                                    ? $registration_config->default_maximum_number_of_tickets
2435
-                                    : EEM_Event::get_default_additional_limit(),
2436
-                                'html_label_text' => esc_html__(
2437
-                                    'Default Maximum Tickets Allowed Per Order:',
2438
-                                    'event_espresso'
2439
-                                )
2440
-                                . EEH_Template::get_help_tab_link(
2441
-                                    'default_maximum_tickets_help_tab"'
2442
-                                ),
2443
-                                'html_help_text'  => esc_html__(
2444
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2445
-                                    'event_espresso'
2446
-                                ),
2447
-                            ]
2448
-                        ),
2449
-                    ]
2450
-                ),
2451
-            ]
2452
-        );
2453
-    }
2454
-
2455
-
2456
-    /**
2457
-     * _update_default_event_settings
2458
-     *
2459
-     * @access protected
2460
-     * @return void
2461
-     * @throws EE_Error
2462
-     */
2463
-    protected function _update_default_event_settings()
2464
-    {
2465
-        $registration_config = EE_Registry::instance()->CFG->registration;
2466
-        $form                = $this->_default_event_settings_form();
2467
-        if ($form->was_submitted()) {
2468
-            $form->receive_form_submission();
2469
-            if ($form->is_valid()) {
2470
-                $valid_data = $form->valid_data();
2471
-                if (isset($valid_data['default_reg_status'])) {
2472
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2473
-                }
2474
-                if (isset($valid_data['default_max_tickets'])) {
2475
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2476
-                }
2477
-                // update because data was valid!
2478
-                EE_Registry::instance()->CFG->update_espresso_config();
2479
-                EE_Error::overwrite_success();
2480
-                EE_Error::add_success(
2481
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2482
-                );
2483
-            }
2484
-        }
2485
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2486
-    }
2487
-
2488
-
2489
-    /*************        Templates        *************
2490
-     *
2491
-     * @throws EE_Error
2492
-     */
2493
-    protected function _template_settings()
2494
-    {
2495
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2496
-        $this->_template_args['preview_img']  = '<img src="'
2497
-                                                . EVENTS_ASSETS_URL
2498
-                                                . '/images/'
2499
-                                                . 'caffeinated_template_features.jpg" alt="'
2500
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2501
-                                                . '" />';
2502
-        $this->_template_args['preview_text'] = '<strong>'
2503
-                                                . esc_html__(
2504
-                                                    '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.',
2505
-                                                    'event_espresso'
2506
-                                                ) . '</strong>';
2507
-        $this->display_admin_caf_preview_page('template_settings_tab');
2508
-    }
2509
-
2510
-
2511
-    /** Event Category Stuff **/
2512
-    /**
2513
-     * set the _category property with the category object for the loaded page.
2514
-     *
2515
-     * @access private
2516
-     * @return void
2517
-     */
2518
-    private function _set_category_object()
2519
-    {
2520
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2521
-            return;
2522
-        } //already have the category object so get out.
2523
-        // set default category object
2524
-        $this->_set_empty_category_object();
2525
-        // only set if we've got an id
2526
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2527
-        if (! $category_ID) {
2528
-            return;
2529
-        }
2530
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2531
-        if (! empty($term)) {
2532
-            $this->_category->category_name       = $term->name;
2533
-            $this->_category->category_identifier = $term->slug;
2534
-            $this->_category->category_desc       = $term->description;
2535
-            $this->_category->id                  = $term->term_id;
2536
-            $this->_category->parent              = $term->parent;
2537
-        }
2538
-    }
2539
-
2540
-
2541
-    /**
2542
-     * Clears out category properties.
2543
-     */
2544
-    private function _set_empty_category_object()
2545
-    {
2546
-        $this->_category                = new stdClass();
2547
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2548
-        $this->_category->id            = $this->_category->parent = 0;
2549
-    }
2550
-
2551
-
2552
-    /**
2553
-     * @throws EE_Error
2554
-     */
2555
-    protected function _category_list_table()
2556
-    {
2557
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2558
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2559
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2560
-            'add_category',
2561
-            'add_category',
2562
-            [],
2563
-            'add-new-h2'
2564
-        );
2565
-        $this->display_admin_list_table_page_with_sidebar();
2566
-    }
2567
-
2568
-
2569
-    /**
2570
-     * Output category details view.
2571
-     *
2572
-     * @throws EE_Error
2573
-     * @throws EE_Error
2574
-     */
2575
-    protected function _category_details($view)
2576
-    {
2577
-        // load formatter helper
2578
-        // load field generator helper
2579
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2580
-        $this->_set_add_edit_form_tags($route);
2581
-        $this->_set_category_object();
2582
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2583
-        $delete_action = 'delete_category';
2584
-        // custom redirect
2585
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2586
-            ['action' => 'category_list'],
2587
-            $this->_admin_base_url
2588
-        );
2589
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2590
-        // take care of contents
2591
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2592
-        $this->display_admin_page_with_sidebar();
2593
-    }
2594
-
2595
-
2596
-    /**
2597
-     * Output category details content.
2598
-     */
2599
-    protected function _category_details_content()
2600
-    {
2601
-        $editor_args['category_desc'] = [
2602
-            'type'          => 'wp_editor',
2603
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2604
-            'class'         => 'my_editor_custom',
2605
-            'wpeditor_args' => ['media_buttons' => false],
2606
-        ];
2607
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2608
-        $all_terms                    = get_terms(
2609
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2610
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2611
-        );
2612
-        // setup category select for term parents.
2613
-        $category_select_values[] = [
2614
-            'text' => esc_html__('No Parent', 'event_espresso'),
2615
-            'id'   => 0,
2616
-        ];
2617
-        foreach ($all_terms as $term) {
2618
-            $category_select_values[] = [
2619
-                'text' => $term->name,
2620
-                'id'   => $term->term_id,
2621
-            ];
2622
-        }
2623
-        $category_select = EEH_Form_Fields::select_input(
2624
-            'category_parent',
2625
-            $category_select_values,
2626
-            $this->_category->parent
2627
-        );
2628
-        $template_args   = [
2629
-            'category'                 => $this->_category,
2630
-            'category_select'          => $category_select,
2631
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2632
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2633
-            'disable'                  => '',
2634
-            'disabled_message'         => false,
2635
-        ];
2636
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2637
-        return EEH_Template::display_template($template, $template_args, true);
2638
-    }
2639
-
2640
-
2641
-    /**
2642
-     * Handles deleting categories.
2643
-     *
2644
-     * @throws EE_Error
2645
-     */
2646
-    protected function _delete_categories()
2647
-    {
2648
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2649
-        foreach ($category_IDs as $category_ID) {
2650
-            $this->_delete_category($category_ID);
2651
-        }
2652
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2653
-        $query_args = [
2654
-            'action' => 'category_list',
2655
-        ];
2656
-        $this->_redirect_after_action(0, '', '', $query_args);
2657
-    }
2658
-
2659
-
2660
-    /**
2661
-     * Handles deleting specific category.
2662
-     *
2663
-     * @param int $cat_id
2664
-     */
2665
-    protected function _delete_category($cat_id)
2666
-    {
2667
-        $cat_id = absint($cat_id);
2668
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2669
-    }
2670
-
2671
-
2672
-    /**
2673
-     * Handles triggering the update or insertion of a new category.
2674
-     *
2675
-     * @param bool $new_category true means we're triggering the insert of a new category.
2676
-     * @throws EE_Error
2677
-     * @throws EE_Error
2678
-     */
2679
-    protected function _insert_or_update_category($new_category)
2680
-    {
2681
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2682
-        $success = 0; // we already have a success message so lets not send another.
2683
-        if ($cat_id) {
2684
-            $query_args = [
2685
-                'action'     => 'edit_category',
2686
-                'EVT_CAT_ID' => $cat_id,
2687
-            ];
2688
-        } else {
2689
-            $query_args = ['action' => 'add_category'];
2690
-        }
2691
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2692
-    }
2693
-
2694
-
2695
-    /**
2696
-     * Inserts or updates category
2697
-     *
2698
-     * @param bool $update (true indicates we're updating a category).
2699
-     * @return bool|mixed|string
2700
-     */
2701
-    private function _insert_category($update = false)
2702
-    {
2703
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2704
-        $category_name       = $this->request->getRequestParam('category_name', '');
2705
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2706
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2707
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2708
-
2709
-        if (empty($category_name)) {
2710
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2711
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2712
-            return false;
2713
-        }
2714
-        $term_args = [
2715
-            'name'        => $category_name,
2716
-            'description' => $category_desc,
2717
-            'parent'      => $category_parent,
2718
-        ];
2719
-        // was the category_identifier input disabled?
2720
-        if ($category_identifier) {
2721
-            $term_args['slug'] = $category_identifier;
2722
-        }
2723
-        $insert_ids = $update
2724
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2725
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2726
-        if (! is_array($insert_ids)) {
2727
-            $msg = esc_html__(
2728
-                'An error occurred and the category has not been saved to the database.',
2729
-                'event_espresso'
2730
-            );
2731
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2732
-        } else {
2733
-            $category_ID = $insert_ids['term_id'];
2734
-            $msg         =
2735
-                sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2736
-            EE_Error::add_success($msg);
2737
-        }
2738
-        return $category_ID;
2739
-    }
2740
-
2741
-
2742
-    /**
2743
-     * Gets categories or count of categories matching the arguments in the request.
2744
-     *
2745
-     * @param int  $per_page
2746
-     * @param int  $current_page
2747
-     * @param bool $count
2748
-     * @return EE_Term_Taxonomy[]|int
2749
-     * @throws EE_Error
2750
-     * @throws EE_Error
2751
-     */
2752
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2753
-    {
2754
-        // testing term stuff
2755
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2756
-        $order       = $this->request->getRequestParam('order', 'DESC');
2757
-        $limit       = ($current_page - 1) * $per_page;
2758
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2759
-        $search_term = $this->request->getRequestParam('s');
2760
-        if ($search_term) {
2761
-            $search_term = '%' . $search_term . '%';
2762
-            $where['OR'] = [
2763
-                'Term.name'   => ['LIKE', $search_term],
2764
-                'description' => ['LIKE', $search_term],
2765
-            ];
2766
-        }
2767
-        $query_params = [
2768
-            $where,
2769
-            'order_by'   => [$orderby => $order],
2770
-            'limit'      => $limit . ',' . $per_page,
2771
-            'force_join' => ['Term'],
2772
-        ];
2773
-        return $count
2774
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2775
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2776
-    }
2777
-
2778
-    /* end category stuff */
2779
-    /**************/
2780
-
2781
-
2782
-    /**
2783
-     * Callback for the `ee_save_timezone_setting` ajax action.
2784
-     *
2785
-     * @throws EE_Error
2786
-     */
2787
-    public function saveTimezoneString()
2788
-    {
2789
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2790
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2791
-            EE_Error::add_error(
2792
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2793
-                __FILE__,
2794
-                __FUNCTION__,
2795
-                __LINE__
2796
-            );
2797
-            $this->_template_args['error'] = true;
2798
-            $this->_return_json();
2799
-        }
2800
-
2801
-        update_option('timezone_string', $timezone_string);
2802
-        EE_Error::add_success(
2803
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2804
-        );
2805
-        $this->_template_args['success'] = true;
2806
-        $this->_return_json(true, ['action' => 'create_new']);
2807
-    }
2808
-
2809
-
2810
-    /**
2811 2491
      * @throws EE_Error
2812
-     * @deprecated 4.10.25.p
2813 2492
      */
2814
-    public function save_timezonestring_setting()
2815
-    {
2816
-        $this->saveTimezoneString();
2817
-    }
2493
+	protected function _template_settings()
2494
+	{
2495
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2496
+		$this->_template_args['preview_img']  = '<img src="'
2497
+												. EVENTS_ASSETS_URL
2498
+												. '/images/'
2499
+												. 'caffeinated_template_features.jpg" alt="'
2500
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2501
+												. '" />';
2502
+		$this->_template_args['preview_text'] = '<strong>'
2503
+												. esc_html__(
2504
+													'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.',
2505
+													'event_espresso'
2506
+												) . '</strong>';
2507
+		$this->display_admin_caf_preview_page('template_settings_tab');
2508
+	}
2509
+
2510
+
2511
+	/** Event Category Stuff **/
2512
+	/**
2513
+	 * set the _category property with the category object for the loaded page.
2514
+	 *
2515
+	 * @access private
2516
+	 * @return void
2517
+	 */
2518
+	private function _set_category_object()
2519
+	{
2520
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2521
+			return;
2522
+		} //already have the category object so get out.
2523
+		// set default category object
2524
+		$this->_set_empty_category_object();
2525
+		// only set if we've got an id
2526
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2527
+		if (! $category_ID) {
2528
+			return;
2529
+		}
2530
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2531
+		if (! empty($term)) {
2532
+			$this->_category->category_name       = $term->name;
2533
+			$this->_category->category_identifier = $term->slug;
2534
+			$this->_category->category_desc       = $term->description;
2535
+			$this->_category->id                  = $term->term_id;
2536
+			$this->_category->parent              = $term->parent;
2537
+		}
2538
+	}
2539
+
2540
+
2541
+	/**
2542
+	 * Clears out category properties.
2543
+	 */
2544
+	private function _set_empty_category_object()
2545
+	{
2546
+		$this->_category                = new stdClass();
2547
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2548
+		$this->_category->id            = $this->_category->parent = 0;
2549
+	}
2550
+
2551
+
2552
+	/**
2553
+	 * @throws EE_Error
2554
+	 */
2555
+	protected function _category_list_table()
2556
+	{
2557
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2558
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2559
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2560
+			'add_category',
2561
+			'add_category',
2562
+			[],
2563
+			'add-new-h2'
2564
+		);
2565
+		$this->display_admin_list_table_page_with_sidebar();
2566
+	}
2567
+
2568
+
2569
+	/**
2570
+	 * Output category details view.
2571
+	 *
2572
+	 * @throws EE_Error
2573
+	 * @throws EE_Error
2574
+	 */
2575
+	protected function _category_details($view)
2576
+	{
2577
+		// load formatter helper
2578
+		// load field generator helper
2579
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2580
+		$this->_set_add_edit_form_tags($route);
2581
+		$this->_set_category_object();
2582
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2583
+		$delete_action = 'delete_category';
2584
+		// custom redirect
2585
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2586
+			['action' => 'category_list'],
2587
+			$this->_admin_base_url
2588
+		);
2589
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2590
+		// take care of contents
2591
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2592
+		$this->display_admin_page_with_sidebar();
2593
+	}
2594
+
2595
+
2596
+	/**
2597
+	 * Output category details content.
2598
+	 */
2599
+	protected function _category_details_content()
2600
+	{
2601
+		$editor_args['category_desc'] = [
2602
+			'type'          => 'wp_editor',
2603
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2604
+			'class'         => 'my_editor_custom',
2605
+			'wpeditor_args' => ['media_buttons' => false],
2606
+		];
2607
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2608
+		$all_terms                    = get_terms(
2609
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2610
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2611
+		);
2612
+		// setup category select for term parents.
2613
+		$category_select_values[] = [
2614
+			'text' => esc_html__('No Parent', 'event_espresso'),
2615
+			'id'   => 0,
2616
+		];
2617
+		foreach ($all_terms as $term) {
2618
+			$category_select_values[] = [
2619
+				'text' => $term->name,
2620
+				'id'   => $term->term_id,
2621
+			];
2622
+		}
2623
+		$category_select = EEH_Form_Fields::select_input(
2624
+			'category_parent',
2625
+			$category_select_values,
2626
+			$this->_category->parent
2627
+		);
2628
+		$template_args   = [
2629
+			'category'                 => $this->_category,
2630
+			'category_select'          => $category_select,
2631
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2632
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2633
+			'disable'                  => '',
2634
+			'disabled_message'         => false,
2635
+		];
2636
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2637
+		return EEH_Template::display_template($template, $template_args, true);
2638
+	}
2639
+
2640
+
2641
+	/**
2642
+	 * Handles deleting categories.
2643
+	 *
2644
+	 * @throws EE_Error
2645
+	 */
2646
+	protected function _delete_categories()
2647
+	{
2648
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2649
+		foreach ($category_IDs as $category_ID) {
2650
+			$this->_delete_category($category_ID);
2651
+		}
2652
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2653
+		$query_args = [
2654
+			'action' => 'category_list',
2655
+		];
2656
+		$this->_redirect_after_action(0, '', '', $query_args);
2657
+	}
2658
+
2659
+
2660
+	/**
2661
+	 * Handles deleting specific category.
2662
+	 *
2663
+	 * @param int $cat_id
2664
+	 */
2665
+	protected function _delete_category($cat_id)
2666
+	{
2667
+		$cat_id = absint($cat_id);
2668
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2669
+	}
2670
+
2671
+
2672
+	/**
2673
+	 * Handles triggering the update or insertion of a new category.
2674
+	 *
2675
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2676
+	 * @throws EE_Error
2677
+	 * @throws EE_Error
2678
+	 */
2679
+	protected function _insert_or_update_category($new_category)
2680
+	{
2681
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2682
+		$success = 0; // we already have a success message so lets not send another.
2683
+		if ($cat_id) {
2684
+			$query_args = [
2685
+				'action'     => 'edit_category',
2686
+				'EVT_CAT_ID' => $cat_id,
2687
+			];
2688
+		} else {
2689
+			$query_args = ['action' => 'add_category'];
2690
+		}
2691
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2692
+	}
2693
+
2694
+
2695
+	/**
2696
+	 * Inserts or updates category
2697
+	 *
2698
+	 * @param bool $update (true indicates we're updating a category).
2699
+	 * @return bool|mixed|string
2700
+	 */
2701
+	private function _insert_category($update = false)
2702
+	{
2703
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2704
+		$category_name       = $this->request->getRequestParam('category_name', '');
2705
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2706
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2707
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2708
+
2709
+		if (empty($category_name)) {
2710
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2711
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2712
+			return false;
2713
+		}
2714
+		$term_args = [
2715
+			'name'        => $category_name,
2716
+			'description' => $category_desc,
2717
+			'parent'      => $category_parent,
2718
+		];
2719
+		// was the category_identifier input disabled?
2720
+		if ($category_identifier) {
2721
+			$term_args['slug'] = $category_identifier;
2722
+		}
2723
+		$insert_ids = $update
2724
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2725
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2726
+		if (! is_array($insert_ids)) {
2727
+			$msg = esc_html__(
2728
+				'An error occurred and the category has not been saved to the database.',
2729
+				'event_espresso'
2730
+			);
2731
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2732
+		} else {
2733
+			$category_ID = $insert_ids['term_id'];
2734
+			$msg         =
2735
+				sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2736
+			EE_Error::add_success($msg);
2737
+		}
2738
+		return $category_ID;
2739
+	}
2740
+
2741
+
2742
+	/**
2743
+	 * Gets categories or count of categories matching the arguments in the request.
2744
+	 *
2745
+	 * @param int  $per_page
2746
+	 * @param int  $current_page
2747
+	 * @param bool $count
2748
+	 * @return EE_Term_Taxonomy[]|int
2749
+	 * @throws EE_Error
2750
+	 * @throws EE_Error
2751
+	 */
2752
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2753
+	{
2754
+		// testing term stuff
2755
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2756
+		$order       = $this->request->getRequestParam('order', 'DESC');
2757
+		$limit       = ($current_page - 1) * $per_page;
2758
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2759
+		$search_term = $this->request->getRequestParam('s');
2760
+		if ($search_term) {
2761
+			$search_term = '%' . $search_term . '%';
2762
+			$where['OR'] = [
2763
+				'Term.name'   => ['LIKE', $search_term],
2764
+				'description' => ['LIKE', $search_term],
2765
+			];
2766
+		}
2767
+		$query_params = [
2768
+			$where,
2769
+			'order_by'   => [$orderby => $order],
2770
+			'limit'      => $limit . ',' . $per_page,
2771
+			'force_join' => ['Term'],
2772
+		];
2773
+		return $count
2774
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2775
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2776
+	}
2777
+
2778
+	/* end category stuff */
2779
+	/**************/
2780
+
2781
+
2782
+	/**
2783
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2784
+	 *
2785
+	 * @throws EE_Error
2786
+	 */
2787
+	public function saveTimezoneString()
2788
+	{
2789
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2790
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2791
+			EE_Error::add_error(
2792
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2793
+				__FILE__,
2794
+				__FUNCTION__,
2795
+				__LINE__
2796
+			);
2797
+			$this->_template_args['error'] = true;
2798
+			$this->_return_json();
2799
+		}
2800
+
2801
+		update_option('timezone_string', $timezone_string);
2802
+		EE_Error::add_success(
2803
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2804
+		);
2805
+		$this->_template_args['success'] = true;
2806
+		$this->_return_json(true, ['action' => 'create_new']);
2807
+	}
2808
+
2809
+
2810
+	/**
2811
+	 * @throws EE_Error
2812
+	 * @deprecated 4.10.25.p
2813
+	 */
2814
+	public function save_timezonestring_setting()
2815
+	{
2816
+		$this->saveTimezoneString();
2817
+	}
2818 2818
 }
Please login to merge, or discard this patch.