Completed
Branch FET/consistent-reg-admin-page-... (c5d240)
by
unknown
26:13 queued 17:48
created
admin_pages/messages/EE_Message_List_Table.class.php 2 patches
Indentation   +430 added lines, -430 removed lines patch added patch discarded remove patch
@@ -12,434 +12,434 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * @return Messages_Admin_Page
17
-     */
18
-    public function get_admin_page()
19
-    {
20
-        return $this->_admin_page;
21
-    }
22
-
23
-
24
-    protected function _setup_data()
25
-    {
26
-        $this->_data = $this->_get_messages($this->_per_page, $this->_view);
27
-        $this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true);
28
-    }
29
-
30
-
31
-    protected function _set_properties()
32
-    {
33
-        $this->_wp_list_args = array(
34
-            'singular' => __('Message', 'event_espresso'),
35
-            'plural'   => __('Messages', 'event_espresso'),
36
-            'ajax'     => true,
37
-            'screen'   => $this->get_admin_page()->get_current_screen()->id,
38
-        );
39
-
40
-        $this->_columns = array(
41
-            'cb'           => '<input type="checkbox" />',
42
-            'to'           => __('To', 'event_espresso'),
43
-            'from'         => __('From', 'event_espresso'),
44
-            'messenger'    => __('Messenger', 'event_espresso'),
45
-            'message_type' => __('Message Type', 'event_espresso'),
46
-            'context'      => __('Context', 'event_espresso'),
47
-            'modified'     => __('Modified', 'event_espresso'),
48
-            'action'       => __('Actions', 'event_espresso'),
49
-            'msg_id'       => __('ID', 'event_espresso'),
50
-        );
51
-
52
-        $this->_sortable_columns = array(
53
-            'modified'     => array('MSG_modified' => true),
54
-            'message_type' => array('MSG_message_type' => false),
55
-            'messenger'    => array('MSG_messenger' => false),
56
-            'to'           => array('MSG_to' => false),
57
-            'from'         => array('MSG_from' => false),
58
-            'context'      => array('MSG_context' => false),
59
-            'msg_id'       => array('MSG_ID', false),
60
-        );
61
-
62
-        $this->_primary_column = 'to';
63
-
64
-        $this->_hidden_columns = array(
65
-            'msg_id',
66
-        );
67
-    }
68
-
69
-
70
-    /**
71
-     * This simply sets up the row class for the table rows.
72
-     * Allows for easier overriding of child methods for setting up sorting.
73
-     *
74
-     * @param  object $item the current item
75
-     * @return string
76
-     */
77
-    protected function _get_row_class($item)
78
-    {
79
-        $class = parent::_get_row_class($item);
80
-        // add status class
81
-        $class .= ' ee-status-strip msg-status-' . $item->STS_ID();
82
-        if ($this->_has_checkbox_column) {
83
-            $class .= ' has-checkbox-column';
84
-        }
85
-        return $class;
86
-    }
87
-
88
-
89
-    /**
90
-     * _get_table_filters
91
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
92
-     * get's shown in the table.
93
-     *
94
-     * @abstract
95
-     * @access protected
96
-     * @return string
97
-     * @throws \EE_Error
98
-     */
99
-    protected function _get_table_filters()
100
-    {
101
-        $filters = array();
102
-
103
-        // get select_inputs
104
-        $select_inputs = array(
105
-            $this->_get_messengers_dropdown_filter(),
106
-            $this->_get_message_types_dropdown_filter(),
107
-            $this->_get_contexts_for_message_types_dropdown_filter(),
108
-        );
109
-
110
-        // set filters to select inputs if they aren't empty
111
-        foreach ($select_inputs as $select_input) {
112
-            if ($select_input) {
113
-                $filters[] = $select_input;
114
-            }
115
-        }
116
-        return $filters;
117
-    }
118
-
119
-
120
-    protected function _add_view_counts()
121
-    {
122
-        foreach ($this->_views as $view => $args) {
123
-            $this->_views[ $view ]['count'] = $this->_get_messages($this->_per_page, $view, true, true);
124
-        }
125
-    }
126
-
127
-
128
-    /**
129
-     * @param EE_Message $message
130
-     * @return string   checkbox
131
-     * @throws \EE_Error
132
-     */
133
-    public function column_cb($message)
134
-    {
135
-        return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID());
136
-    }
137
-
138
-
139
-    /**
140
-     * @param EE_Message $message
141
-     * @return string
142
-     * @throws \EE_Error
143
-     */
144
-    public function column_msg_id(EE_Message $message)
145
-    {
146
-        return $message->ID();
147
-    }
148
-
149
-
150
-    /**
151
-     * @param EE_Message $message
152
-     * @return string    The recipient of the message
153
-     * @throws \EE_Error
154
-     */
155
-    public function column_to(EE_Message $message)
156
-    {
157
-        EE_Registry::instance()->load_helper('URL');
158
-        $actions = array();
159
-        $actions['delete'] = '<a href="'
160
-                             . EEH_URL::add_query_args_and_nonce(
161
-                                 array(
162
-                                    'page'   => 'espresso_messages',
163
-                                    'action' => 'delete_ee_message',
164
-                                    'MSG_ID' => $message->ID(),
165
-                                 ),
166
-                                 admin_url('admin.php')
167
-                             )
168
-                             . '">' . __('Delete', 'event_espresso') . '</a>';
169
-        return esc_html($message->to()) . $this->row_actions($actions);
170
-    }
171
-
172
-
173
-    /**
174
-     * @param EE_Message $message
175
-     * @return string   The sender of the message
176
-     */
177
-    public function column_from(EE_Message $message)
178
-    {
179
-        return esc_html($message->from());
180
-    }
181
-
182
-
183
-    /**
184
-     * @param EE_Message $message
185
-     * @return string  The messenger used to send the message.
186
-     */
187
-    public function column_messenger(EE_Message $message)
188
-    {
189
-        return ucwords($message->messenger_label());
190
-    }
191
-
192
-
193
-    /**
194
-     * @param EE_Message $message
195
-     * @return string  The message type used to generate the message.
196
-     */
197
-    public function column_message_type(EE_Message $message)
198
-    {
199
-        return ucwords($message->message_type_label());
200
-    }
201
-
202
-
203
-    /**
204
-     * @param EE_Message $message
205
-     * @return string  The context the message was generated for.
206
-     */
207
-    public function column_context(EE_Message $message)
208
-    {
209
-        return $message->context_label();
210
-    }
211
-
212
-
213
-    /**
214
-     * @param EE_Message $message
215
-     * @return string    The timestamp when this message was last modified.
216
-     */
217
-    public function column_modified(EE_Message $message)
218
-    {
219
-        return $message->modified();
220
-    }
221
-
222
-
223
-    /**
224
-     * @param EE_Message $message
225
-     * @return string   Actions that can be done on the current message.
226
-     */
227
-    public function column_action(EE_Message $message)
228
-    {
229
-        EE_Registry::instance()->load_helper('MSG_Template');
230
-        $action_links = array(
231
-            'view'                => EEH_MSG_Template::get_message_action_link('view', $message),
232
-            'error'               => EEH_MSG_Template::get_message_action_link('error', $message),
233
-            'generate_now'        => EEH_MSG_Template::get_message_action_link('generate_now', $message),
234
-            'send_now'            => EEH_MSG_Template::get_message_action_link('send_now', $message),
235
-            'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message),
236
-            'view_transaction'    => EEH_MSG_Template::get_message_action_link('view_transaction', $message),
237
-        );
238
-        $content = '';
239
-        switch ($message->STS_ID()) {
240
-            case EEM_Message::status_sent:
241
-                $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction'];
242
-                break;
243
-            case EEM_Message::status_resend:
244
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
245
-                break;
246
-            case EEM_Message::status_retry:
247
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction'];
248
-                break;
249
-            case EEM_Message::status_failed:
250
-            case EEM_Message::status_debug_only:
251
-                $content = $action_links['error'] . $action_links['view_transaction'];
252
-                break;
253
-            case EEM_Message::status_idle:
254
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
255
-                break;
256
-            case EEM_Message::status_incomplete:
257
-                $content = $action_links['generate_now'] . $action_links['view_transaction'];
258
-                break;
259
-        }
260
-        return $content;
261
-    }
262
-
263
-
264
-    /**
265
-     * Retrieve the EE_Message objects for the list table.
266
-     *
267
-     * @param int    $perpage The number of items per page
268
-     * @param string $view    The view items are being retrieved for
269
-     * @param bool   $count   Whether to just return a count or not.
270
-     * @param bool   $all     Disregard any paging info (no limit on data returned).
271
-     * @return int|EE_Message[]
272
-     * @throws \EE_Error
273
-     */
274
-    protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false)
275
-    {
276
-
277
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
278
-            ? $this->_req_data['paged']
279
-            : 1;
280
-
281
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
282
-            ? $this->_req_data['perpage']
283
-            : $perpage;
284
-
285
-        $offset = ($current_page - 1) * $per_page;
286
-        $limit = $all || $count ? null : array($offset, $per_page);
287
-        $query_params = array(
288
-            'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'],
289
-            'order'    => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'],
290
-            'limit'    => $limit,
291
-        );
292
-
293
-        /**
294
-         * Any filters coming in from other routes?
295
-         */
296
-        if (isset($this->_req_data['filterby'])) {
297
-            $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params());
298
-            if (! $count) {
299
-                $query_params['group_by'] = 'MSG_ID';
300
-            }
301
-        }
302
-
303
-        // view conditionals
304
-        if ($view !== 'all' && $count && $all) {
305
-            $query_params[0]['AND*view_conditional'] = array(
306
-                'STS_ID' => strtoupper($view),
307
-            );
308
-        }
309
-
310
-        if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') {
311
-            $query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed
312
-                ? array(
313
-                    'STS_ID' => array(
314
-                        'IN',
315
-                        array(EEM_Message::status_failed, EEM_Message::status_messenger_executing),
316
-                    ),
317
-                )
318
-                : array('STS_ID' => strtoupper($this->_req_data['status']));
319
-        }
320
-
321
-        if (! $all && ! empty($this->_req_data['s'])) {
322
-            $search_string = '%' . $this->_req_data['s'] . '%';
323
-            $query_params[0]['OR'] = array(
324
-                'MSG_to'      => array('LIKE', $search_string),
325
-                'MSG_from'    => array('LIKE', $search_string),
326
-                'MSG_subject' => array('LIKE', $search_string),
327
-                'MSG_content' => array('LIKE', $search_string),
328
-            );
329
-        }
330
-
331
-        // account for debug only status.  We don't show Messages with the EEM_Message::status_debug_only to clients when
332
-        // the messages system is in debug mode.
333
-        // Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only
334
-        // messages in the database.
335
-        if (! EEM_Message::debug()) {
336
-            $query_params[0]['AND*debug_only_conditional'] = array(
337
-                'STS_ID' => array('!=', EEM_Message::status_debug_only),
338
-            );
339
-        }
340
-
341
-        // account for filters
342
-        if (! $all
343
-            && isset($this->_req_data['ee_messenger_filter_by'])
344
-            && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected'
345
-        ) {
346
-            $query_params[0]['AND*messenger_filter'] = array(
347
-                'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'],
348
-            );
349
-        }
350
-        if (! $all
351
-            && ! empty($this->_req_data['ee_message_type_filter_by'])
352
-            && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected'
353
-        ) {
354
-            $query_params[0]['AND*message_type_filter'] = array(
355
-                'MSG_message_type' => $this->_req_data['ee_message_type_filter_by'],
356
-            );
357
-        }
358
-
359
-        if (! $all
360
-            && ! empty($this->_req_data['ee_context_filter_by'])
361
-            && $this->_req_data['ee_context_filter_by'] !== 'none_selected'
362
-        ) {
363
-            $query_params[0]['AND*context_filter'] = array(
364
-                'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])),
365
-            );
366
-        }
367
-
368
-        return $count
369
-            /** @type int */
370
-            ? EEM_Message::instance()->count($query_params, null, true)
371
-            /** @type EE_Message[] */
372
-            : EEM_Message::instance()->get_all($query_params);
373
-    }
374
-
375
-
376
-    /**
377
-     * Generate dropdown filter select input for messengers.
378
-     *
379
-     * @return string
380
-     */
381
-    protected function _get_messengers_dropdown_filter()
382
-    {
383
-        $messenger_options = array();
384
-        $active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
385
-
386
-        // setup array of messenger options
387
-        foreach ($active_messages_grouped_by_messenger as $active_message) {
388
-            if ($active_message instanceof EE_Message) {
389
-                $messenger_options[ $active_message->messenger() ] = ucwords($active_message->messenger_label());
390
-            }
391
-        }
392
-        return $this->get_admin_page()->get_messengers_select_input($messenger_options);
393
-    }
394
-
395
-
396
-    /**
397
-     * Generate dropdown filter select input for message types
398
-     *
399
-     * @return string
400
-     */
401
-    protected function _get_message_types_dropdown_filter()
402
-    {
403
-        $message_type_options = array();
404
-        $active_messages_grouped_by_message_type = EEM_Message::instance()->get_all(
405
-            array('group_by' => 'MSG_message_type')
406
-        );
407
-
408
-        // setup array of message type options
409
-        foreach ($active_messages_grouped_by_message_type as $active_message) {
410
-            if ($active_message instanceof EE_Message) {
411
-                $message_type_options[ $active_message->message_type() ] = ucwords(
412
-                    $active_message->message_type_label()
413
-                );
414
-            }
415
-        }
416
-        return $this->get_admin_page()->get_message_types_select_input($message_type_options);
417
-    }
418
-
419
-
420
-    /**
421
-     * Generate dropdown filter select input for message type contexts
422
-     *
423
-     * @return string
424
-     */
425
-    protected function _get_contexts_for_message_types_dropdown_filter()
426
-    {
427
-        $context_options = array();
428
-        $active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
429
-
430
-        // setup array of context options
431
-        foreach ($active_messages_grouped_by_context as $active_message) {
432
-            if ($active_message instanceof EE_Message) {
433
-                $message_type = $active_message->message_type_object();
434
-                if ($message_type instanceof EE_message_type) {
435
-                    foreach ($message_type->get_contexts() as $context => $context_details) {
436
-                        if (isset($context_details['label'])) {
437
-                            $context_options[ $context ] = $context_details['label'];
438
-                        }
439
-                    }
440
-                }
441
-            }
442
-        }
443
-        return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options);
444
-    }
15
+	/**
16
+	 * @return Messages_Admin_Page
17
+	 */
18
+	public function get_admin_page()
19
+	{
20
+		return $this->_admin_page;
21
+	}
22
+
23
+
24
+	protected function _setup_data()
25
+	{
26
+		$this->_data = $this->_get_messages($this->_per_page, $this->_view);
27
+		$this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true);
28
+	}
29
+
30
+
31
+	protected function _set_properties()
32
+	{
33
+		$this->_wp_list_args = array(
34
+			'singular' => __('Message', 'event_espresso'),
35
+			'plural'   => __('Messages', 'event_espresso'),
36
+			'ajax'     => true,
37
+			'screen'   => $this->get_admin_page()->get_current_screen()->id,
38
+		);
39
+
40
+		$this->_columns = array(
41
+			'cb'           => '<input type="checkbox" />',
42
+			'to'           => __('To', 'event_espresso'),
43
+			'from'         => __('From', 'event_espresso'),
44
+			'messenger'    => __('Messenger', 'event_espresso'),
45
+			'message_type' => __('Message Type', 'event_espresso'),
46
+			'context'      => __('Context', 'event_espresso'),
47
+			'modified'     => __('Modified', 'event_espresso'),
48
+			'action'       => __('Actions', 'event_espresso'),
49
+			'msg_id'       => __('ID', 'event_espresso'),
50
+		);
51
+
52
+		$this->_sortable_columns = array(
53
+			'modified'     => array('MSG_modified' => true),
54
+			'message_type' => array('MSG_message_type' => false),
55
+			'messenger'    => array('MSG_messenger' => false),
56
+			'to'           => array('MSG_to' => false),
57
+			'from'         => array('MSG_from' => false),
58
+			'context'      => array('MSG_context' => false),
59
+			'msg_id'       => array('MSG_ID', false),
60
+		);
61
+
62
+		$this->_primary_column = 'to';
63
+
64
+		$this->_hidden_columns = array(
65
+			'msg_id',
66
+		);
67
+	}
68
+
69
+
70
+	/**
71
+	 * This simply sets up the row class for the table rows.
72
+	 * Allows for easier overriding of child methods for setting up sorting.
73
+	 *
74
+	 * @param  object $item the current item
75
+	 * @return string
76
+	 */
77
+	protected function _get_row_class($item)
78
+	{
79
+		$class = parent::_get_row_class($item);
80
+		// add status class
81
+		$class .= ' ee-status-strip msg-status-' . $item->STS_ID();
82
+		if ($this->_has_checkbox_column) {
83
+			$class .= ' has-checkbox-column';
84
+		}
85
+		return $class;
86
+	}
87
+
88
+
89
+	/**
90
+	 * _get_table_filters
91
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
92
+	 * get's shown in the table.
93
+	 *
94
+	 * @abstract
95
+	 * @access protected
96
+	 * @return string
97
+	 * @throws \EE_Error
98
+	 */
99
+	protected function _get_table_filters()
100
+	{
101
+		$filters = array();
102
+
103
+		// get select_inputs
104
+		$select_inputs = array(
105
+			$this->_get_messengers_dropdown_filter(),
106
+			$this->_get_message_types_dropdown_filter(),
107
+			$this->_get_contexts_for_message_types_dropdown_filter(),
108
+		);
109
+
110
+		// set filters to select inputs if they aren't empty
111
+		foreach ($select_inputs as $select_input) {
112
+			if ($select_input) {
113
+				$filters[] = $select_input;
114
+			}
115
+		}
116
+		return $filters;
117
+	}
118
+
119
+
120
+	protected function _add_view_counts()
121
+	{
122
+		foreach ($this->_views as $view => $args) {
123
+			$this->_views[ $view ]['count'] = $this->_get_messages($this->_per_page, $view, true, true);
124
+		}
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param EE_Message $message
130
+	 * @return string   checkbox
131
+	 * @throws \EE_Error
132
+	 */
133
+	public function column_cb($message)
134
+	{
135
+		return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID());
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param EE_Message $message
141
+	 * @return string
142
+	 * @throws \EE_Error
143
+	 */
144
+	public function column_msg_id(EE_Message $message)
145
+	{
146
+		return $message->ID();
147
+	}
148
+
149
+
150
+	/**
151
+	 * @param EE_Message $message
152
+	 * @return string    The recipient of the message
153
+	 * @throws \EE_Error
154
+	 */
155
+	public function column_to(EE_Message $message)
156
+	{
157
+		EE_Registry::instance()->load_helper('URL');
158
+		$actions = array();
159
+		$actions['delete'] = '<a href="'
160
+							 . EEH_URL::add_query_args_and_nonce(
161
+								 array(
162
+									'page'   => 'espresso_messages',
163
+									'action' => 'delete_ee_message',
164
+									'MSG_ID' => $message->ID(),
165
+								 ),
166
+								 admin_url('admin.php')
167
+							 )
168
+							 . '">' . __('Delete', 'event_espresso') . '</a>';
169
+		return esc_html($message->to()) . $this->row_actions($actions);
170
+	}
171
+
172
+
173
+	/**
174
+	 * @param EE_Message $message
175
+	 * @return string   The sender of the message
176
+	 */
177
+	public function column_from(EE_Message $message)
178
+	{
179
+		return esc_html($message->from());
180
+	}
181
+
182
+
183
+	/**
184
+	 * @param EE_Message $message
185
+	 * @return string  The messenger used to send the message.
186
+	 */
187
+	public function column_messenger(EE_Message $message)
188
+	{
189
+		return ucwords($message->messenger_label());
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param EE_Message $message
195
+	 * @return string  The message type used to generate the message.
196
+	 */
197
+	public function column_message_type(EE_Message $message)
198
+	{
199
+		return ucwords($message->message_type_label());
200
+	}
201
+
202
+
203
+	/**
204
+	 * @param EE_Message $message
205
+	 * @return string  The context the message was generated for.
206
+	 */
207
+	public function column_context(EE_Message $message)
208
+	{
209
+		return $message->context_label();
210
+	}
211
+
212
+
213
+	/**
214
+	 * @param EE_Message $message
215
+	 * @return string    The timestamp when this message was last modified.
216
+	 */
217
+	public function column_modified(EE_Message $message)
218
+	{
219
+		return $message->modified();
220
+	}
221
+
222
+
223
+	/**
224
+	 * @param EE_Message $message
225
+	 * @return string   Actions that can be done on the current message.
226
+	 */
227
+	public function column_action(EE_Message $message)
228
+	{
229
+		EE_Registry::instance()->load_helper('MSG_Template');
230
+		$action_links = array(
231
+			'view'                => EEH_MSG_Template::get_message_action_link('view', $message),
232
+			'error'               => EEH_MSG_Template::get_message_action_link('error', $message),
233
+			'generate_now'        => EEH_MSG_Template::get_message_action_link('generate_now', $message),
234
+			'send_now'            => EEH_MSG_Template::get_message_action_link('send_now', $message),
235
+			'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message),
236
+			'view_transaction'    => EEH_MSG_Template::get_message_action_link('view_transaction', $message),
237
+		);
238
+		$content = '';
239
+		switch ($message->STS_ID()) {
240
+			case EEM_Message::status_sent:
241
+				$content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction'];
242
+				break;
243
+			case EEM_Message::status_resend:
244
+				$content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
245
+				break;
246
+			case EEM_Message::status_retry:
247
+				$content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction'];
248
+				break;
249
+			case EEM_Message::status_failed:
250
+			case EEM_Message::status_debug_only:
251
+				$content = $action_links['error'] . $action_links['view_transaction'];
252
+				break;
253
+			case EEM_Message::status_idle:
254
+				$content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
255
+				break;
256
+			case EEM_Message::status_incomplete:
257
+				$content = $action_links['generate_now'] . $action_links['view_transaction'];
258
+				break;
259
+		}
260
+		return $content;
261
+	}
262
+
263
+
264
+	/**
265
+	 * Retrieve the EE_Message objects for the list table.
266
+	 *
267
+	 * @param int    $perpage The number of items per page
268
+	 * @param string $view    The view items are being retrieved for
269
+	 * @param bool   $count   Whether to just return a count or not.
270
+	 * @param bool   $all     Disregard any paging info (no limit on data returned).
271
+	 * @return int|EE_Message[]
272
+	 * @throws \EE_Error
273
+	 */
274
+	protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false)
275
+	{
276
+
277
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
278
+			? $this->_req_data['paged']
279
+			: 1;
280
+
281
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
282
+			? $this->_req_data['perpage']
283
+			: $perpage;
284
+
285
+		$offset = ($current_page - 1) * $per_page;
286
+		$limit = $all || $count ? null : array($offset, $per_page);
287
+		$query_params = array(
288
+			'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'],
289
+			'order'    => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'],
290
+			'limit'    => $limit,
291
+		);
292
+
293
+		/**
294
+		 * Any filters coming in from other routes?
295
+		 */
296
+		if (isset($this->_req_data['filterby'])) {
297
+			$query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params());
298
+			if (! $count) {
299
+				$query_params['group_by'] = 'MSG_ID';
300
+			}
301
+		}
302
+
303
+		// view conditionals
304
+		if ($view !== 'all' && $count && $all) {
305
+			$query_params[0]['AND*view_conditional'] = array(
306
+				'STS_ID' => strtoupper($view),
307
+			);
308
+		}
309
+
310
+		if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') {
311
+			$query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed
312
+				? array(
313
+					'STS_ID' => array(
314
+						'IN',
315
+						array(EEM_Message::status_failed, EEM_Message::status_messenger_executing),
316
+					),
317
+				)
318
+				: array('STS_ID' => strtoupper($this->_req_data['status']));
319
+		}
320
+
321
+		if (! $all && ! empty($this->_req_data['s'])) {
322
+			$search_string = '%' . $this->_req_data['s'] . '%';
323
+			$query_params[0]['OR'] = array(
324
+				'MSG_to'      => array('LIKE', $search_string),
325
+				'MSG_from'    => array('LIKE', $search_string),
326
+				'MSG_subject' => array('LIKE', $search_string),
327
+				'MSG_content' => array('LIKE', $search_string),
328
+			);
329
+		}
330
+
331
+		// account for debug only status.  We don't show Messages with the EEM_Message::status_debug_only to clients when
332
+		// the messages system is in debug mode.
333
+		// Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only
334
+		// messages in the database.
335
+		if (! EEM_Message::debug()) {
336
+			$query_params[0]['AND*debug_only_conditional'] = array(
337
+				'STS_ID' => array('!=', EEM_Message::status_debug_only),
338
+			);
339
+		}
340
+
341
+		// account for filters
342
+		if (! $all
343
+			&& isset($this->_req_data['ee_messenger_filter_by'])
344
+			&& $this->_req_data['ee_messenger_filter_by'] !== 'none_selected'
345
+		) {
346
+			$query_params[0]['AND*messenger_filter'] = array(
347
+				'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'],
348
+			);
349
+		}
350
+		if (! $all
351
+			&& ! empty($this->_req_data['ee_message_type_filter_by'])
352
+			&& $this->_req_data['ee_message_type_filter_by'] !== 'none_selected'
353
+		) {
354
+			$query_params[0]['AND*message_type_filter'] = array(
355
+				'MSG_message_type' => $this->_req_data['ee_message_type_filter_by'],
356
+			);
357
+		}
358
+
359
+		if (! $all
360
+			&& ! empty($this->_req_data['ee_context_filter_by'])
361
+			&& $this->_req_data['ee_context_filter_by'] !== 'none_selected'
362
+		) {
363
+			$query_params[0]['AND*context_filter'] = array(
364
+				'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])),
365
+			);
366
+		}
367
+
368
+		return $count
369
+			/** @type int */
370
+			? EEM_Message::instance()->count($query_params, null, true)
371
+			/** @type EE_Message[] */
372
+			: EEM_Message::instance()->get_all($query_params);
373
+	}
374
+
375
+
376
+	/**
377
+	 * Generate dropdown filter select input for messengers.
378
+	 *
379
+	 * @return string
380
+	 */
381
+	protected function _get_messengers_dropdown_filter()
382
+	{
383
+		$messenger_options = array();
384
+		$active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
385
+
386
+		// setup array of messenger options
387
+		foreach ($active_messages_grouped_by_messenger as $active_message) {
388
+			if ($active_message instanceof EE_Message) {
389
+				$messenger_options[ $active_message->messenger() ] = ucwords($active_message->messenger_label());
390
+			}
391
+		}
392
+		return $this->get_admin_page()->get_messengers_select_input($messenger_options);
393
+	}
394
+
395
+
396
+	/**
397
+	 * Generate dropdown filter select input for message types
398
+	 *
399
+	 * @return string
400
+	 */
401
+	protected function _get_message_types_dropdown_filter()
402
+	{
403
+		$message_type_options = array();
404
+		$active_messages_grouped_by_message_type = EEM_Message::instance()->get_all(
405
+			array('group_by' => 'MSG_message_type')
406
+		);
407
+
408
+		// setup array of message type options
409
+		foreach ($active_messages_grouped_by_message_type as $active_message) {
410
+			if ($active_message instanceof EE_Message) {
411
+				$message_type_options[ $active_message->message_type() ] = ucwords(
412
+					$active_message->message_type_label()
413
+				);
414
+			}
415
+		}
416
+		return $this->get_admin_page()->get_message_types_select_input($message_type_options);
417
+	}
418
+
419
+
420
+	/**
421
+	 * Generate dropdown filter select input for message type contexts
422
+	 *
423
+	 * @return string
424
+	 */
425
+	protected function _get_contexts_for_message_types_dropdown_filter()
426
+	{
427
+		$context_options = array();
428
+		$active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
429
+
430
+		// setup array of context options
431
+		foreach ($active_messages_grouped_by_context as $active_message) {
432
+			if ($active_message instanceof EE_Message) {
433
+				$message_type = $active_message->message_type_object();
434
+				if ($message_type instanceof EE_message_type) {
435
+					foreach ($message_type->get_contexts() as $context => $context_details) {
436
+						if (isset($context_details['label'])) {
437
+							$context_options[ $context ] = $context_details['label'];
438
+						}
439
+					}
440
+				}
441
+			}
442
+		}
443
+		return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options);
444
+	}
445 445
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     {
79 79
         $class = parent::_get_row_class($item);
80 80
         // add status class
81
-        $class .= ' ee-status-strip msg-status-' . $item->STS_ID();
81
+        $class .= ' ee-status-strip msg-status-'.$item->STS_ID();
82 82
         if ($this->_has_checkbox_column) {
83 83
             $class .= ' has-checkbox-column';
84 84
         }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     protected function _add_view_counts()
121 121
     {
122 122
         foreach ($this->_views as $view => $args) {
123
-            $this->_views[ $view ]['count'] = $this->_get_messages($this->_per_page, $view, true, true);
123
+            $this->_views[$view]['count'] = $this->_get_messages($this->_per_page, $view, true, true);
124 124
         }
125 125
     }
126 126
 
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
                                  ),
166 166
                                  admin_url('admin.php')
167 167
                              )
168
-                             . '">' . __('Delete', 'event_espresso') . '</a>';
169
-        return esc_html($message->to()) . $this->row_actions($actions);
168
+                             . '">'.__('Delete', 'event_espresso').'</a>';
169
+        return esc_html($message->to()).$this->row_actions($actions);
170 170
     }
171 171
 
172 172
 
@@ -238,23 +238,23 @@  discard block
 block discarded – undo
238 238
         $content = '';
239 239
         switch ($message->STS_ID()) {
240 240
             case EEM_Message::status_sent:
241
-                $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction'];
241
+                $content = $action_links['view'].$action_links['queue_for_resending'].$action_links['view_transaction'];
242 242
                 break;
243 243
             case EEM_Message::status_resend:
244
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
244
+                $content = $action_links['view'].$action_links['send_now'].$action_links['view_transaction'];
245 245
                 break;
246 246
             case EEM_Message::status_retry:
247
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction'];
247
+                $content = $action_links['view'].$action_links['send_now'].$action_links['error'].$action_links['view_transaction'];
248 248
                 break;
249 249
             case EEM_Message::status_failed:
250 250
             case EEM_Message::status_debug_only:
251
-                $content = $action_links['error'] . $action_links['view_transaction'];
251
+                $content = $action_links['error'].$action_links['view_transaction'];
252 252
                 break;
253 253
             case EEM_Message::status_idle:
254
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
254
+                $content = $action_links['view'].$action_links['send_now'].$action_links['view_transaction'];
255 255
                 break;
256 256
             case EEM_Message::status_incomplete:
257
-                $content = $action_links['generate_now'] . $action_links['view_transaction'];
257
+                $content = $action_links['generate_now'].$action_links['view_transaction'];
258 258
                 break;
259 259
         }
260 260
         return $content;
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
          */
296 296
         if (isset($this->_req_data['filterby'])) {
297 297
             $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params());
298
-            if (! $count) {
298
+            if ( ! $count) {
299 299
                 $query_params['group_by'] = 'MSG_ID';
300 300
             }
301 301
         }
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
             );
308 308
         }
309 309
 
310
-        if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') {
310
+        if ( ! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') {
311 311
             $query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed
312 312
                 ? array(
313 313
                     'STS_ID' => array(
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
                 : array('STS_ID' => strtoupper($this->_req_data['status']));
319 319
         }
320 320
 
321
-        if (! $all && ! empty($this->_req_data['s'])) {
322
-            $search_string = '%' . $this->_req_data['s'] . '%';
321
+        if ( ! $all && ! empty($this->_req_data['s'])) {
322
+            $search_string = '%'.$this->_req_data['s'].'%';
323 323
             $query_params[0]['OR'] = array(
324 324
                 'MSG_to'      => array('LIKE', $search_string),
325 325
                 'MSG_from'    => array('LIKE', $search_string),
@@ -332,14 +332,14 @@  discard block
 block discarded – undo
332 332
         // the messages system is in debug mode.
333 333
         // Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only
334 334
         // messages in the database.
335
-        if (! EEM_Message::debug()) {
335
+        if ( ! EEM_Message::debug()) {
336 336
             $query_params[0]['AND*debug_only_conditional'] = array(
337 337
                 'STS_ID' => array('!=', EEM_Message::status_debug_only),
338 338
             );
339 339
         }
340 340
 
341 341
         // account for filters
342
-        if (! $all
342
+        if ( ! $all
343 343
             && isset($this->_req_data['ee_messenger_filter_by'])
344 344
             && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected'
345 345
         ) {
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
                 'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'],
348 348
             );
349 349
         }
350
-        if (! $all
350
+        if ( ! $all
351 351
             && ! empty($this->_req_data['ee_message_type_filter_by'])
352 352
             && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected'
353 353
         ) {
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
             );
357 357
         }
358 358
 
359
-        if (! $all
359
+        if ( ! $all
360 360
             && ! empty($this->_req_data['ee_context_filter_by'])
361 361
             && $this->_req_data['ee_context_filter_by'] !== 'none_selected'
362 362
         ) {
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
         // setup array of messenger options
387 387
         foreach ($active_messages_grouped_by_messenger as $active_message) {
388 388
             if ($active_message instanceof EE_Message) {
389
-                $messenger_options[ $active_message->messenger() ] = ucwords($active_message->messenger_label());
389
+                $messenger_options[$active_message->messenger()] = ucwords($active_message->messenger_label());
390 390
             }
391 391
         }
392 392
         return $this->get_admin_page()->get_messengers_select_input($messenger_options);
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
         // setup array of message type options
409 409
         foreach ($active_messages_grouped_by_message_type as $active_message) {
410 410
             if ($active_message instanceof EE_Message) {
411
-                $message_type_options[ $active_message->message_type() ] = ucwords(
411
+                $message_type_options[$active_message->message_type()] = ucwords(
412 412
                     $active_message->message_type_label()
413 413
                 );
414 414
             }
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
                 if ($message_type instanceof EE_message_type) {
435 435
                     foreach ($message_type->get_contexts() as $context => $context_details) {
436 436
                         if (isset($context_details['label'])) {
437
-                            $context_options[ $context ] = $context_details['label'];
437
+                            $context_options[$context] = $context_details['label'];
438 438
                         }
439 439
                     }
440 440
                 }
Please login to merge, or discard this patch.
admin_pages/venues/Venues_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1006,7 +1006,7 @@
 block discarded – undo
1006 1006
      * @access  private
1007 1007
      * @param  int    $VNU_ID
1008 1008
      * @param  string $venue_status
1009
-     * @return void
1009
+     * @return boolean
1010 1010
      */
1011 1011
     private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1012 1012
     {
Please login to merge, or discard this patch.
Indentation   +1512 added lines, -1512 removed lines patch added patch discarded remove patch
@@ -17,1518 +17,1518 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * _venue
22
-     * This will hold the venue object for venue_details screen.
23
-     *
24
-     * @access protected
25
-     * @var object
26
-     */
27
-    protected $_venue;
28
-
29
-
30
-    /**
31
-     * This will hold the category object for category_details screen.
32
-     *
33
-     * @var object
34
-     */
35
-    protected $_category;
36
-
37
-
38
-    /**
39
-     * This property will hold the venue model instance
40
-     *
41
-     * @var object
42
-     */
43
-    protected $_venue_model;
44
-
45
-
46
-    protected function _init_page_props()
47
-    {
48
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
49
-        $this->page_slug = EE_VENUES_PG_SLUG;
50
-        $this->_admin_base_url = EE_VENUES_ADMIN_URL;
51
-        $this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
52
-        $this->page_label = __('Event Venues', 'event_espresso');
53
-        $this->_cpt_model_names = array(
54
-            'create_new' => 'EEM_Venue',
55
-            'edit'       => 'EEM_Venue',
56
-        );
57
-        $this->_cpt_edit_routes = array(
58
-            'espresso_venues' => 'edit',
59
-        );
60
-        $this->_venue_model = EEM_Venue::instance();
61
-    }
62
-
63
-
64
-    protected function _ajax_hooks()
65
-    {
66
-        // todo: all hooks for ee_venues ajax goes in here.
67
-    }
68
-
69
-
70
-    protected function _define_page_props()
71
-    {
72
-        $this->_admin_page_title = $this->page_label;
73
-        $this->_labels = array(
74
-            'buttons'      => array(
75
-                'add'             => __('Add New Venue', 'event_espresso'),
76
-                'edit'            => __('Edit Venue', 'event_espresso'),
77
-                'delete'          => __('Delete Venue', 'event_espresso'),
78
-                'add_category'    => __('Add New Category', 'event_espresso'),
79
-                'edit_category'   => __('Edit Category', 'event_espresso'),
80
-                'delete_category' => __('Delete Category', 'event_espresso'),
81
-            ),
82
-            'editor_title' => array(
83
-                'espresso_venues' => __('Enter Venue name here', 'event_espresso'),
84
-            ),
85
-            'publishbox'   => array(
86
-                'create_new'          => __('Save New Venue', 'event_espresso'),
87
-                'edit'                => __('Update Venue', 'event_espresso'),
88
-                'add_category'        => __('Save New Category', 'event_espresso'),
89
-                'edit_category'       => __('Update Category', 'event_espresso'),
90
-                'google_map_settings' => __('Update Settings', 'event_espresso'),
91
-            ),
92
-        );
93
-    }
94
-
95
-
96
-    protected function _set_page_routes()
97
-    {
98
-
99
-        // load formatter helper
100
-        // load field generator helper
101
-
102
-        // is there a vnu_id in the request?
103
-        $vnu_id = ! empty($this->_req_data['VNU_ID']) && ! is_array($this->_req_data['VNU_ID'])
104
-            ? $this->_req_data['VNU_ID'] : 0;
105
-        $vnu_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $vnu_id;
106
-
107
-        $this->_page_routes = array(
108
-            'default'                    => array(
109
-                'func'       => '_overview_list_table',
110
-                'capability' => 'ee_read_venues',
111
-            ),
112
-            'create_new'                 => array(
113
-                'func'       => '_create_new_cpt_item',
114
-                'capability' => 'ee_edit_venues',
115
-            ),
116
-            'edit'                       => array(
117
-                'func'       => '_edit_cpt_item',
118
-                'capability' => 'ee_edit_venue',
119
-                'obj_id'     => $vnu_id,
120
-            ),
121
-            'trash_venue'                => array(
122
-                'func'       => '_trash_or_restore_venue',
123
-                'args'       => array('venue_status' => 'trash'),
124
-                'noheader'   => true,
125
-                'capability' => 'ee_delete_venue',
126
-                'obj_id'     => $vnu_id,
127
-            ),
128
-            'trash_venues'               => array(
129
-                'func'       => '_trash_or_restore_venues',
130
-                'args'       => array('venue_status' => 'trash'),
131
-                'noheader'   => true,
132
-                'capability' => 'ee_delete_venues',
133
-            ),
134
-            'restore_venue'              => array(
135
-                'func'       => '_trash_or_restore_venue',
136
-                'args'       => array('venue_status' => 'draft'),
137
-                'noheader'   => true,
138
-                'capability' => 'ee_delete_venue',
139
-                'obj_id'     => $vnu_id,
140
-            ),
141
-            'restore_venues'             => array(
142
-                'func'       => '_trash_or_restore_venues',
143
-                'args'       => array('venue_status' => 'draft'),
144
-                'noheader'   => true,
145
-                'capability' => 'ee_delete_venues',
146
-            ),
147
-            'delete_venues'              => array(
148
-                'func'       => '_delete_venues',
149
-                'noheader'   => true,
150
-                'capability' => 'ee_delete_venues',
151
-            ),
152
-            'delete_venue'               => array(
153
-                'func'       => '_delete_venue',
154
-                'noheader'   => true,
155
-                'capability' => 'ee_delete_venue',
156
-                'obj_id'     => $vnu_id,
157
-            ),
158
-            // settings related
159
-            'google_map_settings'        => array(
160
-                'func'       => '_google_map_settings',
161
-                'capability' => 'manage_options',
162
-            ),
163
-            'update_google_map_settings' => array(
164
-                'func'       => '_update_google_map_settings',
165
-                'capability' => 'manage_options',
166
-                'noheader'   => true,
167
-            ),
168
-            // venue category tab related
169
-            'add_category'               => array(
170
-                'func'       => '_category_details',
171
-                'args'       => array('add'),
172
-                'capability' => 'ee_edit_venue_category',
173
-            ),
174
-            'edit_category'              => array(
175
-                'func'       => '_category_details',
176
-                'args'       => array('edit'),
177
-                'capability' => 'ee_edit_venue_category',
178
-            ),
179
-            'delete_categories'          => array(
180
-                'func'       => '_delete_categories',
181
-                'noheader'   => true,
182
-                'capability' => 'ee_delete_venue_category',
183
-            ),
184
-
185
-            'delete_category' => array(
186
-                'func'       => '_delete_categories',
187
-                'noheader'   => true,
188
-                'capability' => 'ee_delete_venue_category',
189
-            ),
190
-
191
-            'insert_category' => array(
192
-                'func'       => '_insert_or_update_category',
193
-                'args'       => array('new_category' => true),
194
-                'noheader'   => true,
195
-                'capability' => 'ee_edit_venue_category',
196
-            ),
197
-
198
-            'update_category'   => array(
199
-                'func'       => '_insert_or_update_category',
200
-                'args'       => array('new_category' => false),
201
-                'noheader'   => true,
202
-                'capability' => 'ee_edit_venue_category',
203
-            ),
204
-            'export_categories' => array(
205
-                'func'       => '_categories_export',
206
-                'noheader'   => true,
207
-                'capability' => 'export',
208
-            ),
209
-            'import_categories' => array(
210
-                'func'       => '_import_categories',
211
-                'capability' => 'import',
212
-            ),
213
-            'category_list'     => array(
214
-                'func'       => '_category_list_table',
215
-                'capability' => 'ee_manage_venue_categories',
216
-            ),
217
-        );
218
-    }
219
-
220
-
221
-    protected function _set_page_config()
222
-    {
223
-        $this->_page_config = array(
224
-            'default'             => array(
225
-                'nav'           => array(
226
-                    'label' => __('Overview', 'event_espresso'),
227
-                    'order' => 10,
228
-                ),
229
-                'list_table'    => 'Venues_Admin_List_Table',
230
-                'help_tabs'     => array(
231
-                    'venues_overview_help_tab'                           => array(
232
-                        'title'    => __('Venues Overview', 'event_espresso'),
233
-                        'filename' => 'venues_overview',
234
-                    ),
235
-                    'venues_overview_table_column_headings_help_tab'     => array(
236
-                        'title'    => __('Venues Overview Table Column Headings', 'event_espresso'),
237
-                        'filename' => 'venues_overview_table_column_headings',
238
-                    ),
239
-                    'venues_overview_views_bulk_actions_search_help_tab' => array(
240
-                        'title'    => __('Venues Overview Views & Bulk Actions & Search', 'event_espresso'),
241
-                        'filename' => 'venues_overview_views_bulk_actions_search',
242
-                    ),
243
-                ),
244
-                'help_tour'     => array('Venues_Overview_Help_Tour'),
245
-                'metaboxes'     => array('_espresso_news_post_box', '_espresso_links_post_box'),
246
-                'require_nonce' => false,
247
-            ),
248
-            'create_new'          => array(
249
-                'nav'           => array(
250
-                    'label'      => __('Add Venue', 'event_espresso'),
251
-                    'order'      => 5,
252
-                    'persistent' => false,
253
-                ),
254
-                'help_tabs'     => array(
255
-                    'venues_editor_help_tab'                                               => array(
256
-                        'title'    => __('Venue Editor', 'event_espresso'),
257
-                        'filename' => 'venues_editor',
258
-                    ),
259
-                    'venues_editor_title_richtexteditor_help_tab'                          => array(
260
-                        'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
261
-                        'filename' => 'venues_editor_title_richtexteditor',
262
-                    ),
263
-                    'venues_editor_tags_categories_help_tab'                               => array(
264
-                        'title'    => __('Venue Tags & Categories', 'event_espresso'),
265
-                        'filename' => 'venues_editor_tags_categories',
266
-                    ),
267
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
268
-                        'title'    => __(
269
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
270
-                            'event_espresso'
271
-                        ),
272
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
273
-                    ),
274
-                    'venues_editor_save_new_venue_help_tab'                                => array(
275
-                        'title'    => __('Save New Venue', 'event_espresso'),
276
-                        'filename' => 'venues_editor_save_new_venue',
277
-                    ),
278
-                    'venues_editor_other_help_tab'                                         => array(
279
-                        'title'    => __('Venue Editor Other', 'event_espresso'),
280
-                        'filename' => 'venues_editor_other',
281
-                    ),
282
-                ),
283
-                'help_tour'     => array('Venues_Add_Venue_Help_Tour'),
284
-                'metaboxes'     => array('_venue_editor_metaboxes'),
285
-                'require_nonce' => false,
286
-            ),
287
-            'edit'                => array(
288
-                'nav'           => array(
289
-                    'label'      => __('Edit Venue', 'event_espresso'),
290
-                    'order'      => 5,
291
-                    'persistent' => false,
292
-                    'url'        => isset($this->_req_data['post']) ? add_query_arg(
293
-                        array('post' => $this->_req_data['post']),
294
-                        $this->_current_page_view_url
295
-                    ) : $this->_admin_base_url,
296
-                ),
297
-                'help_tabs'     => array(
298
-                    'venues_editor_help_tab'                                               => array(
299
-                        'title'    => __('Venue Editor', 'event_espresso'),
300
-                        'filename' => 'venues_editor',
301
-                    ),
302
-                    'venues_editor_title_richtexteditor_help_tab'                          => array(
303
-                        'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
304
-                        'filename' => 'venues_editor_title_richtexteditor',
305
-                    ),
306
-                    'venues_editor_tags_categories_help_tab'                               => array(
307
-                        'title'    => __('Venue Tags & Categories', 'event_espresso'),
308
-                        'filename' => 'venues_editor_tags_categories',
309
-                    ),
310
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
311
-                        'title'    => __(
312
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
313
-                            'event_espresso'
314
-                        ),
315
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
316
-                    ),
317
-                    'venues_editor_save_new_venue_help_tab'                                => array(
318
-                        'title'    => __('Save New Venue', 'event_espresso'),
319
-                        'filename' => 'venues_editor_save_new_venue',
320
-                    ),
321
-                    'venues_editor_other_help_tab'                                         => array(
322
-                        'title'    => __('Venue Editor Other', 'event_espresso'),
323
-                        'filename' => 'venues_editor_other',
324
-                    ),
325
-                ),
326
-                /*'help_tour' => array( 'Venues_Edit_Venue_Help_Tour' ),*/
327
-                'metaboxes'     => array('_venue_editor_metaboxes'),
328
-                'require_nonce' => false,
329
-            ),
330
-            'google_map_settings' => array(
331
-                'nav'           => array(
332
-                    'label' => esc_html__('Google Maps', 'event_espresso'),
333
-                    'order' => 40,
334
-                ),
335
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
336
-                'help_tabs'     => array(
337
-                    'general_settings_google_maps_help_tab' => array(
338
-                        'title'    => __('Google Maps', 'event_espresso'),
339
-                        'filename' => 'general_settings_google_maps',
340
-                    ),
341
-                ),
342
-                'help_tour'     => array('Google_Maps_Help_Tour'),
343
-                'require_nonce' => false,
344
-            ),
345
-            // venue category stuff
346
-            'add_category'        => array(
347
-                'nav'           => array(
348
-                    'label'      => __('Add Category', 'event_espresso'),
349
-                    'order'      => 15,
350
-                    'persistent' => false,
351
-                ),
352
-                'metaboxes'     => array('_publish_post_box'),
353
-                'help_tabs'     => array(
354
-                    'venues_add_category_help_tab' => array(
355
-                        'title'    => __('Add New Venue Category', 'event_espresso'),
356
-                        'filename' => 'venues_add_category',
357
-                    ),
358
-                ),
359
-                'help_tour'     => array('Venues_Add_Category_Help_Tour'),
360
-                'require_nonce' => false,
361
-            ),
362
-            'edit_category'       => array(
363
-                'nav'           => array(
364
-                    'label'      => __('Edit Category', 'event_espresso'),
365
-                    'order'      => 15,
366
-                    'persistent' => false,
367
-                    'url'        => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(
368
-                        array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
369
-                        $this->_current_page_view_url
370
-                    ) : $this->_admin_base_url,
371
-                ),
372
-                'metaboxes'     => array('_publish_post_box'),
373
-                'help_tabs'     => array(
374
-                    'venues_edit_category_help_tab' => array(
375
-                        'title'    => __('Edit Venue Category', 'event_espresso'),
376
-                        'filename' => 'venues_edit_category',
377
-                    ),
378
-                ),
379
-                /*'help_tour' => array( 'Venues_Edit_Category_Help_Tour' ),*/
380
-                'require_nonce' => false,
381
-            ),
382
-            'category_list'       => array(
383
-                'nav'           => array(
384
-                    'label' => __('Categories', 'event_espresso'),
385
-                    'order' => 20,
386
-                ),
387
-                'list_table'    => 'Venue_Categories_Admin_List_Table',
388
-                'help_tabs'     => array(
389
-                    'venues_categories_help_tab'                       => array(
390
-                        'title'    => __('Venue Categories', 'event_espresso'),
391
-                        'filename' => 'venues_categories',
392
-                    ),
393
-                    'venues_categories_table_column_headings_help_tab' => array(
394
-                        'title'    => __('Venue Categories Table Column Headings', 'event_espresso'),
395
-                        'filename' => 'venues_categories_table_column_headings',
396
-                    ),
397
-                    'venues_categories_views_help_tab'                 => array(
398
-                        'title'    => __('Venue Categories Views', 'event_espresso'),
399
-                        'filename' => 'venues_categories_views',
400
-                    ),
401
-                    'venues_categories_other_help_tab'                 => array(
402
-                        'title'    => __('Venue Categories Other', 'event_espresso'),
403
-                        'filename' => 'venues_categories_other',
404
-                    ),
405
-                ),
406
-                'help_tour'     => array('Venues_Categories_Help_Tour'),
407
-                'metaboxes'     => $this->_default_espresso_metaboxes,
408
-                'require_nonce' => false,
409
-            ),
410
-        );
411
-    }
412
-
413
-
414
-    protected function _add_screen_options()
415
-    {
416
-        // todo
417
-    }
418
-
419
-
420
-    protected function _add_screen_options_default()
421
-    {
422
-        $this->_per_page_screen_option();
423
-    }
424
-
425
-
426
-    protected function _add_screen_options_category_list()
427
-    {
428
-        $page_title = $this->_admin_page_title;
429
-        $this->_admin_page_title = __('Venue Categories', 'event_espresso');
430
-        $this->_per_page_screen_option();
431
-        $this->_admin_page_title = $page_title;
432
-    }
433
-
434
-
435
-    // none of the below group are currently used for Event Venues
436
-    protected function _add_feature_pointers()
437
-    {
438
-    }
439
-
440
-    public function admin_init()
441
-    {
442
-    }
443
-
444
-    public function admin_notices()
445
-    {
446
-    }
447
-
448
-    public function admin_footer_scripts()
449
-    {
450
-    }
451
-
452
-
453
-    public function load_scripts_styles_create_new()
454
-    {
455
-        $this->load_scripts_styles_edit();
456
-    }
457
-
458
-
459
-    public function load_scripts_styles()
460
-    {
461
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
462
-        wp_enqueue_style('ee-cat-admin');
463
-    }
464
-
465
-
466
-    public function load_scripts_styles_add_category()
467
-    {
468
-        $this->load_scripts_styles_edit_category();
469
-    }
470
-
471
-
472
-    public function load_scripts_styles_edit_category()
473
-    {
474
-    }
475
-
476
-
477
-    public function load_scripts_styles_edit()
478
-    {
479
-        // styles
480
-        wp_enqueue_style('espresso-ui-theme');
481
-        wp_register_style(
482
-            'espresso_venues',
483
-            EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
484
-            array(),
485
-            EVENT_ESPRESSO_VERSION
486
-        );
487
-        wp_enqueue_style('espresso_venues');
488
-    }
489
-
490
-
491
-    protected function _set_list_table_views_default()
492
-    {
493
-        $this->_views = array(
494
-            'all' => array(
495
-                'slug'        => 'all',
496
-                'label'       => __('View All Venues', 'event_espresso'),
497
-                'count'       => 0,
498
-                'bulk_action' => array(),
499
-            ),
500
-        );
501
-
502
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
503
-            $this->_views['all']['bulk_action'] = array(
504
-                'trash_venues' => __('Move to Trash', 'event_espresso'),
505
-            );
506
-            $this->_views['trash'] = array(
507
-                'slug'        => 'trash',
508
-                'label'       => __('Trash', 'event_espresso'),
509
-                'count'       => 0,
510
-                'bulk_action' => array(
511
-                    'restore_venues' => __('Restore from Trash', 'event_espresso'),
512
-                    'delete_venues'  => __('Delete', 'event_espresso'),
513
-                ),
514
-            );
515
-        }
516
-    }
517
-
518
-
519
-    protected function _set_list_table_views_category_list()
520
-    {
521
-        $this->_views = array(
522
-            'all' => array(
523
-                'slug'        => 'all',
524
-                'label'       => __('All', 'event_espresso'),
525
-                'count'       => 0,
526
-                'bulk_action' => array(
527
-                    'delete_categories' => __('Delete Permanently', 'event_espresso'),
528
-                ),
529
-            ),
530
-        );
531
-    }
532
-
533
-
534
-    protected function _overview_list_table()
535
-    {
536
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
537
-        $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
538
-            get_post_type_archive_link('espresso_venues'),
539
-            __("View Venue Archive Page", "event_espresso"),
540
-            'button'
541
-        );
542
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2');
543
-        $this->_search_btn_label = __('Venues', 'event_espresso');
544
-        $this->display_admin_list_table_page_with_sidebar();
545
-    }
546
-
547
-
548
-    public function extra_misc_actions_publish_box()
549
-    {
550
-        $extra_rows = array(
551
-            'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
552
-            'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
553
-            'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
554
-        );
555
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
556
-        EEH_Template::display_template($template, $extra_rows);
557
-    }
558
-
559
-
560
-    /*************        Google Maps        *************/
561
-
562
-
563
-    protected function _google_map_settings()
564
-    {
565
-
566
-
567
-        $this->_template_args['values'] = $this->_yes_no_values;
568
-        $default_map_settings = new stdClass();
569
-        $default_map_settings->use_google_maps = true;
570
-        $default_map_settings->google_map_api_key = '';
571
-        // for event details pages (reg page)
572
-        $default_map_settings->event_details_map_width = 585;            // ee_map_width_single
573
-        $default_map_settings->event_details_map_height = 362;            // ee_map_height_single
574
-        $default_map_settings->event_details_map_zoom = 14;            // ee_map_zoom_single
575
-        $default_map_settings->event_details_display_nav = true;            // ee_map_nav_display_single
576
-        $default_map_settings->event_details_nav_size = false;            // ee_map_nav_size_single
577
-        $default_map_settings->event_details_control_type = 'default';        // ee_map_type_control_single
578
-        $default_map_settings->event_details_map_align = 'center';            // ee_map_align_single
579
-        // for event list pages
580
-        $default_map_settings->event_list_map_width = 300;            // ee_map_width
581
-        $default_map_settings->event_list_map_height = 185;        // ee_map_height
582
-        $default_map_settings->event_list_map_zoom = 12;            // ee_map_zoom
583
-        $default_map_settings->event_list_display_nav = false;        // ee_map_nav_display
584
-        $default_map_settings->event_list_nav_size = true;            // ee_map_nav_size
585
-        $default_map_settings->event_list_control_type = 'dropdown';        // ee_map_type_control
586
-        $default_map_settings->event_list_map_align = 'center';            // ee_map_align
587
-
588
-        $this->_template_args['map_settings'] =
589
-            isset(EE_Registry::instance()->CFG->map_settings)
590
-            && ! empty(EE_Registry::instance()->CFG->map_settings)
591
-                ? (object) array_merge(
592
-                    (array) $default_map_settings,
593
-                    (array) EE_Registry::instance()->CFG->map_settings
594
-                )
595
-                : $default_map_settings;
596
-
597
-        $this->_set_add_edit_form_tags('update_google_map_settings');
598
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
599
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
600
-            EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
601
-            $this->_template_args,
602
-            true
603
-        );
604
-        $this->display_admin_page_with_sidebar();
605
-    }
606
-
607
-    protected function _update_google_map_settings()
608
-    {
609
-
610
-        EE_Registry::instance()->CFG->map_settings->use_google_maps =
611
-            isset($this->_req_data['use_google_maps'])
612
-                ? absint($this->_req_data['use_google_maps'])
613
-                : EE_Registry::instance()->CFG->map_settings->use_google_maps;
614
-
615
-        EE_Registry::instance()->CFG->map_settings->google_map_api_key =
616
-            isset($this->_req_data['google_map_api_key'])
617
-                ? sanitize_text_field($this->_req_data['google_map_api_key'])
618
-                : EE_Registry::instance()->CFG->map_settings->google_map_api_key;
619
-
620
-        EE_Registry::instance()->CFG->map_settings->event_details_map_width =
621
-            isset($this->_req_data['event_details_map_width'])
622
-                ? absint($this->_req_data['event_details_map_width'])
623
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_width;
624
-
625
-        EE_Registry::instance()->CFG->map_settings->event_details_map_height =
626
-            isset($this->_req_data['event_details_map_height'])
627
-                ? absint($this->_req_data['event_details_map_height'])
628
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_height;
629
-
630
-        EE_Registry::instance()->CFG->map_settings->event_details_map_zoom =
631
-            isset($this->_req_data['event_details_map_zoom'])
632
-                ? absint($this->_req_data['event_details_map_zoom'])
633
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_zoom;
634
-
635
-        EE_Registry::instance()->CFG->map_settings->event_details_display_nav =
636
-            isset($this->_req_data['event_details_display_nav'])
637
-                ? absint($this->_req_data['event_details_display_nav'])
638
-                : EE_Registry::instance()->CFG->map_settings->event_details_display_nav;
639
-
640
-        EE_Registry::instance()->CFG->map_settings->event_details_nav_size =
641
-            isset($this->_req_data['event_details_nav_size'])
642
-                ? absint($this->_req_data['event_details_nav_size'])
643
-                : EE_Registry::instance()->CFG->map_settings->event_details_nav_size;
644
-
645
-        EE_Registry::instance()->CFG->map_settings->event_details_control_type =
646
-            isset($this->_req_data['event_details_control_type'])
647
-                ? sanitize_text_field($this->_req_data['event_details_control_type'])
648
-                : EE_Registry::instance()->CFG->map_settings->event_details_control_type;
649
-
650
-        EE_Registry::instance()->CFG->map_settings->event_details_map_align =
651
-            isset($this->_req_data['event_details_map_align'])
652
-                ? sanitize_text_field($this->_req_data['event_details_map_align'])
653
-                : EE_Registry::instance()->CFG->map_settings->event_details_map_align;
654
-
655
-        EE_Registry::instance()->CFG->map_settings->event_list_map_width =
656
-            isset($this->_req_data['event_list_map_width'])
657
-                ? absint($this->_req_data['event_list_map_width'])
658
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_width;
659
-
660
-        EE_Registry::instance()->CFG->map_settings->event_list_map_height =
661
-            isset($this->_req_data['event_list_map_height'])
662
-                ? absint($this->_req_data['event_list_map_height'])
663
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_height;
664
-
665
-        EE_Registry::instance()->CFG->map_settings->event_list_map_zoom =
666
-            isset($this->_req_data['event_list_map_zoom'])
667
-                ? absint($this->_req_data['event_list_map_zoom'])
668
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_zoom;
669
-
670
-        EE_Registry::instance()->CFG->map_settings->event_list_display_nav =
671
-            isset($this->_req_data['event_list_display_nav'])
672
-                ? absint($this->_req_data['event_list_display_nav'])
673
-                : EE_Registry::instance()->CFG->map_settings->event_list_display_nav;
674
-
675
-        EE_Registry::instance()->CFG->map_settings->event_list_nav_size =
676
-            isset($this->_req_data['event_list_nav_size'])
677
-                ? absint($this->_req_data['event_list_nav_size'])
678
-                : EE_Registry::instance()->CFG->map_settings->event_list_nav_size;
679
-
680
-        EE_Registry::instance()->CFG->map_settings->event_list_control_type =
681
-            isset($this->_req_data['event_list_control_type'])
682
-                ? sanitize_text_field($this->_req_data['event_list_control_type'])
683
-                : EE_Registry::instance()->CFG->map_settings->event_list_control_type;
684
-
685
-        EE_Registry::instance()->CFG->map_settings->event_list_map_align =
686
-            isset($this->_req_data['event_list_map_align'])
687
-                ? sanitize_text_field($this->_req_data['event_list_map_align'])
688
-                : EE_Registry::instance()->CFG->map_settings->event_list_map_align;
689
-
690
-        EE_Registry::instance()->CFG->map_settings = apply_filters(
691
-            'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
692
-            EE_Registry::instance()->CFG->map_settings
693
-        );
694
-
695
-        $what = 'Google Map Settings';
696
-        $success = $this->_update_espresso_configuration(
697
-            $what,
698
-            EE_Registry::instance()->CFG->map_settings,
699
-            __FILE__,
700
-            __FUNCTION__,
701
-            __LINE__
702
-        );
703
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'google_map_settings'));
704
-    }
705
-
706
-
707
-    protected function _venue_editor_metaboxes()
708
-    {
709
-        $this->verify_cpt_object();
710
-
711
-        add_meta_box(
712
-            'espresso_venue_address_options',
713
-            __('Physical Location', 'event_espresso'),
714
-            array($this, 'venue_address_metabox'),
715
-            $this->page_slug,
716
-            'side',
717
-            'default'
718
-        );
719
-        add_meta_box(
720
-            'espresso_venue_gmap_options',
721
-            __('Google Map', 'event_espresso'),
722
-            array($this, 'venue_gmap_metabox'),
723
-            $this->page_slug,
724
-            'side',
725
-            'default'
726
-        );
727
-        add_meta_box(
728
-            'espresso_venue_virtual_loc_options',
729
-            __('Virtual Location', 'event_espresso'),
730
-            array($this, 'venue_virtual_loc_metabox'),
731
-            $this->page_slug,
732
-            'side',
733
-            'default'
734
-        );
735
-    }
736
-
737
-
738
-    public function venue_gmap_metabox()
739
-    {
740
-        $template_args = array(
741
-            'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
742
-                'vnu_enable_for_gmap',
743
-                $this->get_yes_no_values(),
744
-                $this->_cpt_model_obj->enable_for_gmap()
745
-            ),
746
-            'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
747
-        );
748
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
749
-        EEH_Template::display_template($template, $template_args);
750
-    }
751
-
752
-
753
-    public function venue_address_metabox()
754
-    {
755
-
756
-        $template_args['_venue'] = $this->_cpt_model_obj;
757
-
758
-        $template_args['states_dropdown'] = EEH_Form_Fields::generate_form_input(
759
-            $QFI = new EE_Question_Form_Input(
760
-                EE_Question::new_instance(
761
-                    array('QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state')
762
-                ),
763
-                EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->state_ID())),
764
-                array(
765
-                    'input_name'     => 'sta_id',
766
-                    'input_id'       => 'sta_id',
767
-                    'input_class'    => '',
768
-                    'input_prefix'   => '',
769
-                    'append_qstn_id' => false,
770
-                )
771
-            )
772
-        );
773
-        $template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
774
-            $QFI = new EE_Question_Form_Input(
775
-                EE_Question::new_instance(
776
-                    array('QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country')
777
-                ),
778
-                EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->country_ID())),
779
-                array(
780
-                    'input_name'     => 'cnt_iso',
781
-                    'input_id'       => 'cnt_iso',
782
-                    'input_class'    => '',
783
-                    'input_prefix'   => '',
784
-                    'append_qstn_id' => false,
785
-                )
786
-            )
787
-        );
788
-
789
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
790
-        EEH_Template::display_template($template, $template_args);
791
-    }
792
-
793
-
794
-    public function venue_virtual_loc_metabox()
795
-    {
796
-        $template_args = array(
797
-            '_venue' => $this->_cpt_model_obj,
798
-        );
799
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
800
-        EEH_Template::display_template($template, $template_args);
801
-    }
802
-
803
-
804
-    protected function _restore_cpt_item($post_id, $revision_id)
805
-    {
806
-        $venue_obj = $this->_venue_model->get_one_by_ID($post_id);
807
-
808
-        // meta revision restore
809
-        $venue_obj->restore_revision($revision_id);
810
-    }
811
-
812
-
813
-    /**
814
-     * Handles updates for venue cpts
815
-     *
816
-     * @param  int    $post_id ID of Venue CPT
817
-     * @param  object $post    Post object (with "blessed" WP properties)
818
-     * @return void
819
-     */
820
-    protected function _insert_update_cpt_item($post_id, $post)
821
-    {
822
-
823
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
824
-            return;// get out we're not processing the saving of venues.
825
-        }
826
-
827
-        $wheres = array($this->_venue_model->primary_key_name() => $post_id);
828
-
829
-        $venue_values = array(
830
-            'VNU_address'         => ! empty($this->_req_data['vnu_address']) ? $this->_req_data['vnu_address'] : null,
831
-            'VNU_address2'        => ! empty($this->_req_data['vnu_address2']) ? $this->_req_data['vnu_address2']
832
-                : null,
833
-            'VNU_city'            => ! empty($this->_req_data['vnu_city']) ? $this->_req_data['vnu_city'] : null,
834
-            'STA_ID'              => ! empty($this->_req_data['sta_id']) ? $this->_req_data['sta_id'] : null,
835
-            'CNT_ISO'             => ! empty($this->_req_data['cnt_iso']) ? $this->_req_data['cnt_iso'] : null,
836
-            'VNU_zip'             => ! empty($this->_req_data['vnu_zip']) ? $this->_req_data['vnu_zip'] : null,
837
-            'VNU_phone'           => ! empty($this->_req_data['vnu_phone']) ? $this->_req_data['vnu_phone'] : null,
838
-            'VNU_capacity'        => ! empty($this->_req_data['vnu_capacity']) ? str_replace(
839
-                ',',
840
-                '',
841
-                $this->_req_data['vnu_capacity']
842
-            ) : EE_INF,
843
-            'VNU_url'             => ! empty($this->_req_data['vnu_url']) ? $this->_req_data['vnu_url'] : null,
844
-            'VNU_virtual_phone'   => ! empty($this->_req_data['vnu_virtual_phone'])
845
-                ? $this->_req_data['vnu_virtual_phone'] : null,
846
-            'VNU_virtual_url'     => ! empty($this->_req_data['vnu_virtual_url']) ? $this->_req_data['vnu_virtual_url']
847
-                : null,
848
-            'VNU_enable_for_gmap' => ! empty($this->_req_data['vnu_enable_for_gmap']) ? true : false,
849
-            'VNU_google_map_link' => ! empty($this->_req_data['vnu_google_map_link'])
850
-                ? $this->_req_data['vnu_google_map_link'] : null,
851
-        );
852
-
853
-        // update venue
854
-        $success = $this->_venue_model->update($venue_values, array($wheres));
855
-
856
-        // get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
857
-        $get_one_where = array($this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status);
858
-        $venue = $this->_venue_model->get_one(array($get_one_where));
859
-
860
-        // notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use.  So this is just here for addons to more easily hook into venue saves.
861
-        $venue_update_callbacks = apply_filters(
862
-            'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
863
-            array()
864
-        );
865
-
866
-        $att_success = true;
867
-
868
-        foreach ($venue_update_callbacks as $v_callback) {
869
-            $_succ = call_user_func_array($v_callback, array($venue, $this->_req_data));
870
-            $att_success = ! $att_success ? $att_success
871
-                : $_succ; // if ANY of these updates fail then we want the appropriate global error message
872
-        }
873
-
874
-        // any errors?
875
-        if ($success && ! $att_success) {
876
-            EE_Error::add_error(
877
-                __(
878
-                    'Venue Details saved successfully but something went wrong with saving attachments.',
879
-                    'event_espresso'
880
-                ),
881
-                __FILE__,
882
-                __FUNCTION__,
883
-                __LINE__
884
-            );
885
-        } elseif ($success === false) {
886
-            EE_Error::add_error(
887
-                __('Venue Details did not save successfully.', 'event_espresso'),
888
-                __FILE__,
889
-                __FUNCTION__,
890
-                __LINE__
891
-            );
892
-        }
893
-    }
894
-
895
-
896
-    public function trash_cpt_item($post_id)
897
-    {
898
-        $this->_req_data['VNU_ID'] = $post_id;
899
-        $this->_trash_or_restore_venue('trash', false);
900
-    }
901
-
902
-
903
-    public function restore_cpt_item($post_id)
904
-    {
905
-        $this->_req_data['VNU_ID'] = $post_id;
906
-        $this->_trash_or_restore_venue('draft', false);
907
-    }
908
-
909
-
910
-    public function delete_cpt_item($post_id)
911
-    {
912
-        $this->_req_data['VNU_ID'] = $post_id;
913
-        $this->_delete_venue(false);
914
-    }
915
-
916
-
917
-    public function get_venue_object()
918
-    {
919
-        return $this->_cpt_model_obj;
920
-    }
921
-
922
-
923
-    protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
924
-    {
925
-        $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : false;
926
-
927
-        // loop thru venues
928
-        if ($VNU_ID) {
929
-            // clean status
930
-            $venue_status = sanitize_key($venue_status);
931
-            // grab status
932
-            if (! empty($venue_status)) {
933
-                $success = $this->_change_venue_status($VNU_ID, $venue_status);
934
-            } else {
935
-                $success = false;
936
-                $msg = __(
937
-                    'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
938
-                    'event_espresso'
939
-                );
940
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
941
-            }
942
-        } else {
943
-            $success = false;
944
-            $msg = __(
945
-                'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
946
-                'event_espresso'
947
-            );
948
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
949
-        }
950
-        $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
951
-
952
-        if ($redirect_after) {
953
-            $this->_redirect_after_action($success, 'Venue', $action, array('action' => 'default'));
954
-        }
955
-    }
956
-
957
-
958
-    protected function _trash_or_restore_venues($venue_status = 'trash')
959
-    {
960
-        // clean status
961
-        $venue_status = sanitize_key($venue_status);
962
-        // grab status
963
-        if (! empty($venue_status)) {
964
-            $success = true;
965
-            // determine the event id and set to array.
966
-            $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
967
-            // loop thru events
968
-            foreach ($VNU_IDs as $VNU_ID) {
969
-                if ($VNU_ID = absint($VNU_ID)) {
970
-                    $results = $this->_change_venue_status($VNU_ID, $venue_status);
971
-                    $success = $results !== false ? $success : false;
972
-                } else {
973
-                    $msg = sprintf(
974
-                        __(
975
-                            'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
976
-                            'event_espresso'
977
-                        ),
978
-                        $VNU_ID
979
-                    );
980
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
981
-                    $success = false;
982
-                }
983
-            }
984
-        } else {
985
-            $success = false;
986
-            $msg = __(
987
-                'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
988
-                'event_espresso'
989
-            );
990
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
991
-        }
992
-        // in order to force a pluralized result message we need to send back a success status greater than 1
993
-        $success = $success ? 2 : false;
994
-        $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
995
-        $this->_redirect_after_action($success, 'Venues', $action, array('action' => 'default'));
996
-    }
997
-
998
-
999
-    /**
1000
-     * _trash_or_restore_venues
1001
-     *
1002
-     * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1003
-     * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1004
-     * accepting a certain number of params.
1005
-     *
1006
-     * @access  private
1007
-     * @param  int    $VNU_ID
1008
-     * @param  string $venue_status
1009
-     * @return void
1010
-     */
1011
-    private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1012
-    {
1013
-        // grab venue id
1014
-        if (! $VNU_ID) {
1015
-            $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1016
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1017
-            return false;
1018
-        }
1019
-
1020
-        $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1021
-
1022
-        // clean status
1023
-        $venue_status = sanitize_key($venue_status);
1024
-        // grab status
1025
-        if (! $venue_status) {
1026
-            $msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso');
1027
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1028
-            return false;
1029
-        }
1030
-
1031
-        // was event trashed or restored ?
1032
-        switch ($venue_status) {
1033
-            case 'draft':
1034
-                $action = 'restored from the trash';
1035
-                $hook = 'AHEE_venue_restored_from_trash';
1036
-                break;
1037
-            case 'trash':
1038
-                $action = 'moved to the trash';
1039
-                $hook = 'AHEE_venue_moved_to_trash';
1040
-                break;
1041
-            default:
1042
-                $action = 'updated';
1043
-                $hook = false;
1044
-        }
1045
-        // use class to change status
1046
-        $this->_cpt_model_obj->set_status($venue_status);
1047
-        $success = $this->_cpt_model_obj->save();
1048
-
1049
-        if ($success === false) {
1050
-            $msg = sprintf(__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1051
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1052
-            return false;
1053
-        }
1054
-        if ($hook) {
1055
-            do_action($hook);
1056
-        }
1057
-        return true;
1058
-    }
1059
-
1060
-
1061
-    /**
1062
-     * @param  bool $redirect_after
1063
-     * @return void
1064
-     */
1065
-    protected function _delete_venue($redirect_after = true)
1066
-    {
1067
-        // determine the venue id and set to array.
1068
-        $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : null;
1069
-        $VNU_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $VNU_ID;
1070
-
1071
-
1072
-        // loop thru venues
1073
-        if ($VNU_ID) {
1074
-            $success = $this->_delete_or_trash_venue($VNU_ID);
1075
-        } else {
1076
-            $success = false;
1077
-            $msg = __(
1078
-                'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1079
-                'event_espresso'
1080
-            );
1081
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1082
-        }
1083
-        if ($redirect_after) {
1084
-            $this->_redirect_after_action($success, 'Venue', 'deleted', array('action' => 'default'));
1085
-        }
1086
-    }
1087
-
1088
-
1089
-    protected function _delete_venues()
1090
-    {
1091
-        $success = true;
1092
-        // determine the event id and set to array.
1093
-        $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
1094
-        // loop thru events
1095
-        foreach ($VNU_IDs as $VNU_ID) {
1096
-            if ($VNU_ID = absint($VNU_ID)) {
1097
-                $results = $this->_delete_or_trash_venue($VNU_ID);
1098
-                $success = $results !== false ? $success : false;
1099
-            } else {
1100
-                $success = false;
1101
-                $msg = __(
1102
-                    'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1103
-                    'event_espresso'
1104
-                );
1105
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1106
-            }
1107
-        }
1108
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1109
-        $success = $success ? 2 : false;
1110
-        $this->_redirect_after_action(
1111
-            $success,
1112
-            __('Venues', 'event_espresso'),
1113
-            __('deleted', 'event_espresso'),
1114
-            array('action' => 'default')
1115
-        );
1116
-    }
1117
-
1118
-
1119
-    // todo: put in parent
1120
-    private function _delete_or_trash_venue($VNU_ID = false)
1121
-    {
1122
-        // grab event id
1123
-        if (! $VNU_ID = absint($VNU_ID)) {
1124
-            $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1125
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1126
-            return false;
1127
-        }
1128
-
1129
-
1130
-        $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1131
-        // first need to remove all term relationships
1132
-        $venue->_remove_relations('Term_Taxonomy');
1133
-        $success = $venue->delete_permanently();
1134
-        // did it all go as planned ?
1135
-        if ($success) {
1136
-            $msg = sprintf(__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1137
-            EE_Error::add_success($msg);
1138
-        } else {
1139
-            $msg = sprintf(__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'), $VNU_ID);
1140
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1141
-            return false;
1142
-        }
1143
-        do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1144
-        return true;
1145
-    }
1146
-
1147
-
1148
-
1149
-
1150
-    /***********/
1151
-    /* QUERIES */
1152
-
1153
-
1154
-    public function get_venues($per_page = 10, $count = false)
1155
-    {
1156
-
1157
-        $_orderby = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1158
-
1159
-        switch ($_orderby) {
1160
-            case 'id':
1161
-                $orderby = 'VNU_ID';
1162
-                break;
1163
-
1164
-            case 'capacity':
1165
-                $orderby = 'VNU_capacity';
1166
-                break;
1167
-
1168
-            case 'city':
1169
-                $orderby = 'VNU_city';
1170
-                break;
1171
-
1172
-            default:
1173
-                $orderby = 'VNU_name';
1174
-        }
1175
-
1176
-
1177
-        $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1178
-            : 'ASC';
1179
-
1180
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1181
-            ? $this->_req_data['paged'] : 1;
1182
-        $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
1183
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1184
-            ? $this->_req_data['perpage'] : $per_page;
1185
-
1186
-
1187
-        $offset = ($current_page - 1) * $per_page;
1188
-        $limit = array($offset, $per_page);
1189
-
1190
-        $category = isset($this->_req_data['category']) && $this->_req_data['category'] > 0
1191
-            ? $this->_req_data['category'] : null;
1192
-        $where = array();
1193
-
1194
-        // only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1195
-        if (isset($this->_req_data['status']) && $this->_req_data['status'] != 'all') {
1196
-            $where['status'] = $this->_req_data['status'];
1197
-        }
1198
-
1199
-        if (isset($this->_req_data['venue_status'])) {
1200
-            $where['status'] = $this->_req_data['venue_status'];
1201
-        }
1202
-
1203
-
1204
-        if ($category) {
1205
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1206
-            $where['Term_Taxonomy.term_id'] = $category;
1207
-        }
1208
-
1209
-
1210
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1211
-            $where['VNU_wp_user'] = get_current_user_id();
1212
-        } else {
1213
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1214
-                $where['OR'] = array(
1215
-                    'status*restrict_private' => array('!=', 'private'),
1216
-                    'AND'                     => array(
1217
-                        'status*inclusive' => array('=', 'private'),
1218
-                        'VNU_wp_user'      => get_current_user_id(),
1219
-                    ),
1220
-                );
1221
-            }
1222
-        }
1223
-
1224
-
1225
-        if (isset($this->_req_data['s'])) {
1226
-            $sstr = '%' . $this->_req_data['s'] . '%';
1227
-            $where['OR'] = array(
1228
-                'VNU_name'               => array('LIKE', $sstr),
1229
-                'VNU_desc'               => array('LIKE', $sstr),
1230
-                'VNU_short_desc'         => array('LIKE', $sstr),
1231
-                'VNU_address'            => array('LIKE', $sstr),
1232
-                'VNU_address2'           => array('LIKE', $sstr),
1233
-                'VNU_city'               => array('LIKE', $sstr),
1234
-                'VNU_zip'                => array('LIKE', $sstr),
1235
-                'VNU_phone'              => array('LIKE', $sstr),
1236
-                'VNU_url'                => array('LIKE', $sstr),
1237
-                'VNU_virtual_phone'      => array('LIKE', $sstr),
1238
-                'VNU_virtual_url'        => array('LIKE', $sstr),
1239
-                'VNU_google_map_link'    => array('LIKE', $sstr),
1240
-                'Event.EVT_name'         => array('LIKE', $sstr),
1241
-                'Event.EVT_desc'         => array('LIKE', $sstr),
1242
-                'Event.EVT_phone'        => array('LIKE', $sstr),
1243
-                'Event.EVT_external_URL' => array('LIKE', $sstr),
1244
-            );
1245
-        }
20
+	/**
21
+	 * _venue
22
+	 * This will hold the venue object for venue_details screen.
23
+	 *
24
+	 * @access protected
25
+	 * @var object
26
+	 */
27
+	protected $_venue;
28
+
29
+
30
+	/**
31
+	 * This will hold the category object for category_details screen.
32
+	 *
33
+	 * @var object
34
+	 */
35
+	protected $_category;
36
+
37
+
38
+	/**
39
+	 * This property will hold the venue model instance
40
+	 *
41
+	 * @var object
42
+	 */
43
+	protected $_venue_model;
44
+
45
+
46
+	protected function _init_page_props()
47
+	{
48
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
49
+		$this->page_slug = EE_VENUES_PG_SLUG;
50
+		$this->_admin_base_url = EE_VENUES_ADMIN_URL;
51
+		$this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
52
+		$this->page_label = __('Event Venues', 'event_espresso');
53
+		$this->_cpt_model_names = array(
54
+			'create_new' => 'EEM_Venue',
55
+			'edit'       => 'EEM_Venue',
56
+		);
57
+		$this->_cpt_edit_routes = array(
58
+			'espresso_venues' => 'edit',
59
+		);
60
+		$this->_venue_model = EEM_Venue::instance();
61
+	}
62
+
63
+
64
+	protected function _ajax_hooks()
65
+	{
66
+		// todo: all hooks for ee_venues ajax goes in here.
67
+	}
68
+
69
+
70
+	protected function _define_page_props()
71
+	{
72
+		$this->_admin_page_title = $this->page_label;
73
+		$this->_labels = array(
74
+			'buttons'      => array(
75
+				'add'             => __('Add New Venue', 'event_espresso'),
76
+				'edit'            => __('Edit Venue', 'event_espresso'),
77
+				'delete'          => __('Delete Venue', 'event_espresso'),
78
+				'add_category'    => __('Add New Category', 'event_espresso'),
79
+				'edit_category'   => __('Edit Category', 'event_espresso'),
80
+				'delete_category' => __('Delete Category', 'event_espresso'),
81
+			),
82
+			'editor_title' => array(
83
+				'espresso_venues' => __('Enter Venue name here', 'event_espresso'),
84
+			),
85
+			'publishbox'   => array(
86
+				'create_new'          => __('Save New Venue', 'event_espresso'),
87
+				'edit'                => __('Update Venue', 'event_espresso'),
88
+				'add_category'        => __('Save New Category', 'event_espresso'),
89
+				'edit_category'       => __('Update Category', 'event_espresso'),
90
+				'google_map_settings' => __('Update Settings', 'event_espresso'),
91
+			),
92
+		);
93
+	}
94
+
95
+
96
+	protected function _set_page_routes()
97
+	{
98
+
99
+		// load formatter helper
100
+		// load field generator helper
101
+
102
+		// is there a vnu_id in the request?
103
+		$vnu_id = ! empty($this->_req_data['VNU_ID']) && ! is_array($this->_req_data['VNU_ID'])
104
+			? $this->_req_data['VNU_ID'] : 0;
105
+		$vnu_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $vnu_id;
106
+
107
+		$this->_page_routes = array(
108
+			'default'                    => array(
109
+				'func'       => '_overview_list_table',
110
+				'capability' => 'ee_read_venues',
111
+			),
112
+			'create_new'                 => array(
113
+				'func'       => '_create_new_cpt_item',
114
+				'capability' => 'ee_edit_venues',
115
+			),
116
+			'edit'                       => array(
117
+				'func'       => '_edit_cpt_item',
118
+				'capability' => 'ee_edit_venue',
119
+				'obj_id'     => $vnu_id,
120
+			),
121
+			'trash_venue'                => array(
122
+				'func'       => '_trash_or_restore_venue',
123
+				'args'       => array('venue_status' => 'trash'),
124
+				'noheader'   => true,
125
+				'capability' => 'ee_delete_venue',
126
+				'obj_id'     => $vnu_id,
127
+			),
128
+			'trash_venues'               => array(
129
+				'func'       => '_trash_or_restore_venues',
130
+				'args'       => array('venue_status' => 'trash'),
131
+				'noheader'   => true,
132
+				'capability' => 'ee_delete_venues',
133
+			),
134
+			'restore_venue'              => array(
135
+				'func'       => '_trash_or_restore_venue',
136
+				'args'       => array('venue_status' => 'draft'),
137
+				'noheader'   => true,
138
+				'capability' => 'ee_delete_venue',
139
+				'obj_id'     => $vnu_id,
140
+			),
141
+			'restore_venues'             => array(
142
+				'func'       => '_trash_or_restore_venues',
143
+				'args'       => array('venue_status' => 'draft'),
144
+				'noheader'   => true,
145
+				'capability' => 'ee_delete_venues',
146
+			),
147
+			'delete_venues'              => array(
148
+				'func'       => '_delete_venues',
149
+				'noheader'   => true,
150
+				'capability' => 'ee_delete_venues',
151
+			),
152
+			'delete_venue'               => array(
153
+				'func'       => '_delete_venue',
154
+				'noheader'   => true,
155
+				'capability' => 'ee_delete_venue',
156
+				'obj_id'     => $vnu_id,
157
+			),
158
+			// settings related
159
+			'google_map_settings'        => array(
160
+				'func'       => '_google_map_settings',
161
+				'capability' => 'manage_options',
162
+			),
163
+			'update_google_map_settings' => array(
164
+				'func'       => '_update_google_map_settings',
165
+				'capability' => 'manage_options',
166
+				'noheader'   => true,
167
+			),
168
+			// venue category tab related
169
+			'add_category'               => array(
170
+				'func'       => '_category_details',
171
+				'args'       => array('add'),
172
+				'capability' => 'ee_edit_venue_category',
173
+			),
174
+			'edit_category'              => array(
175
+				'func'       => '_category_details',
176
+				'args'       => array('edit'),
177
+				'capability' => 'ee_edit_venue_category',
178
+			),
179
+			'delete_categories'          => array(
180
+				'func'       => '_delete_categories',
181
+				'noheader'   => true,
182
+				'capability' => 'ee_delete_venue_category',
183
+			),
184
+
185
+			'delete_category' => array(
186
+				'func'       => '_delete_categories',
187
+				'noheader'   => true,
188
+				'capability' => 'ee_delete_venue_category',
189
+			),
190
+
191
+			'insert_category' => array(
192
+				'func'       => '_insert_or_update_category',
193
+				'args'       => array('new_category' => true),
194
+				'noheader'   => true,
195
+				'capability' => 'ee_edit_venue_category',
196
+			),
197
+
198
+			'update_category'   => array(
199
+				'func'       => '_insert_or_update_category',
200
+				'args'       => array('new_category' => false),
201
+				'noheader'   => true,
202
+				'capability' => 'ee_edit_venue_category',
203
+			),
204
+			'export_categories' => array(
205
+				'func'       => '_categories_export',
206
+				'noheader'   => true,
207
+				'capability' => 'export',
208
+			),
209
+			'import_categories' => array(
210
+				'func'       => '_import_categories',
211
+				'capability' => 'import',
212
+			),
213
+			'category_list'     => array(
214
+				'func'       => '_category_list_table',
215
+				'capability' => 'ee_manage_venue_categories',
216
+			),
217
+		);
218
+	}
219
+
220
+
221
+	protected function _set_page_config()
222
+	{
223
+		$this->_page_config = array(
224
+			'default'             => array(
225
+				'nav'           => array(
226
+					'label' => __('Overview', 'event_espresso'),
227
+					'order' => 10,
228
+				),
229
+				'list_table'    => 'Venues_Admin_List_Table',
230
+				'help_tabs'     => array(
231
+					'venues_overview_help_tab'                           => array(
232
+						'title'    => __('Venues Overview', 'event_espresso'),
233
+						'filename' => 'venues_overview',
234
+					),
235
+					'venues_overview_table_column_headings_help_tab'     => array(
236
+						'title'    => __('Venues Overview Table Column Headings', 'event_espresso'),
237
+						'filename' => 'venues_overview_table_column_headings',
238
+					),
239
+					'venues_overview_views_bulk_actions_search_help_tab' => array(
240
+						'title'    => __('Venues Overview Views & Bulk Actions & Search', 'event_espresso'),
241
+						'filename' => 'venues_overview_views_bulk_actions_search',
242
+					),
243
+				),
244
+				'help_tour'     => array('Venues_Overview_Help_Tour'),
245
+				'metaboxes'     => array('_espresso_news_post_box', '_espresso_links_post_box'),
246
+				'require_nonce' => false,
247
+			),
248
+			'create_new'          => array(
249
+				'nav'           => array(
250
+					'label'      => __('Add Venue', 'event_espresso'),
251
+					'order'      => 5,
252
+					'persistent' => false,
253
+				),
254
+				'help_tabs'     => array(
255
+					'venues_editor_help_tab'                                               => array(
256
+						'title'    => __('Venue Editor', 'event_espresso'),
257
+						'filename' => 'venues_editor',
258
+					),
259
+					'venues_editor_title_richtexteditor_help_tab'                          => array(
260
+						'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
261
+						'filename' => 'venues_editor_title_richtexteditor',
262
+					),
263
+					'venues_editor_tags_categories_help_tab'                               => array(
264
+						'title'    => __('Venue Tags & Categories', 'event_espresso'),
265
+						'filename' => 'venues_editor_tags_categories',
266
+					),
267
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
268
+						'title'    => __(
269
+							'Venue Editor Physical Location & Google Map & Virtual Location',
270
+							'event_espresso'
271
+						),
272
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
273
+					),
274
+					'venues_editor_save_new_venue_help_tab'                                => array(
275
+						'title'    => __('Save New Venue', 'event_espresso'),
276
+						'filename' => 'venues_editor_save_new_venue',
277
+					),
278
+					'venues_editor_other_help_tab'                                         => array(
279
+						'title'    => __('Venue Editor Other', 'event_espresso'),
280
+						'filename' => 'venues_editor_other',
281
+					),
282
+				),
283
+				'help_tour'     => array('Venues_Add_Venue_Help_Tour'),
284
+				'metaboxes'     => array('_venue_editor_metaboxes'),
285
+				'require_nonce' => false,
286
+			),
287
+			'edit'                => array(
288
+				'nav'           => array(
289
+					'label'      => __('Edit Venue', 'event_espresso'),
290
+					'order'      => 5,
291
+					'persistent' => false,
292
+					'url'        => isset($this->_req_data['post']) ? add_query_arg(
293
+						array('post' => $this->_req_data['post']),
294
+						$this->_current_page_view_url
295
+					) : $this->_admin_base_url,
296
+				),
297
+				'help_tabs'     => array(
298
+					'venues_editor_help_tab'                                               => array(
299
+						'title'    => __('Venue Editor', 'event_espresso'),
300
+						'filename' => 'venues_editor',
301
+					),
302
+					'venues_editor_title_richtexteditor_help_tab'                          => array(
303
+						'title'    => __('Venue Title & Rich Text Editor', 'event_espresso'),
304
+						'filename' => 'venues_editor_title_richtexteditor',
305
+					),
306
+					'venues_editor_tags_categories_help_tab'                               => array(
307
+						'title'    => __('Venue Tags & Categories', 'event_espresso'),
308
+						'filename' => 'venues_editor_tags_categories',
309
+					),
310
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => array(
311
+						'title'    => __(
312
+							'Venue Editor Physical Location & Google Map & Virtual Location',
313
+							'event_espresso'
314
+						),
315
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
316
+					),
317
+					'venues_editor_save_new_venue_help_tab'                                => array(
318
+						'title'    => __('Save New Venue', 'event_espresso'),
319
+						'filename' => 'venues_editor_save_new_venue',
320
+					),
321
+					'venues_editor_other_help_tab'                                         => array(
322
+						'title'    => __('Venue Editor Other', 'event_espresso'),
323
+						'filename' => 'venues_editor_other',
324
+					),
325
+				),
326
+				/*'help_tour' => array( 'Venues_Edit_Venue_Help_Tour' ),*/
327
+				'metaboxes'     => array('_venue_editor_metaboxes'),
328
+				'require_nonce' => false,
329
+			),
330
+			'google_map_settings' => array(
331
+				'nav'           => array(
332
+					'label' => esc_html__('Google Maps', 'event_espresso'),
333
+					'order' => 40,
334
+				),
335
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
336
+				'help_tabs'     => array(
337
+					'general_settings_google_maps_help_tab' => array(
338
+						'title'    => __('Google Maps', 'event_espresso'),
339
+						'filename' => 'general_settings_google_maps',
340
+					),
341
+				),
342
+				'help_tour'     => array('Google_Maps_Help_Tour'),
343
+				'require_nonce' => false,
344
+			),
345
+			// venue category stuff
346
+			'add_category'        => array(
347
+				'nav'           => array(
348
+					'label'      => __('Add Category', 'event_espresso'),
349
+					'order'      => 15,
350
+					'persistent' => false,
351
+				),
352
+				'metaboxes'     => array('_publish_post_box'),
353
+				'help_tabs'     => array(
354
+					'venues_add_category_help_tab' => array(
355
+						'title'    => __('Add New Venue Category', 'event_espresso'),
356
+						'filename' => 'venues_add_category',
357
+					),
358
+				),
359
+				'help_tour'     => array('Venues_Add_Category_Help_Tour'),
360
+				'require_nonce' => false,
361
+			),
362
+			'edit_category'       => array(
363
+				'nav'           => array(
364
+					'label'      => __('Edit Category', 'event_espresso'),
365
+					'order'      => 15,
366
+					'persistent' => false,
367
+					'url'        => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(
368
+						array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
369
+						$this->_current_page_view_url
370
+					) : $this->_admin_base_url,
371
+				),
372
+				'metaboxes'     => array('_publish_post_box'),
373
+				'help_tabs'     => array(
374
+					'venues_edit_category_help_tab' => array(
375
+						'title'    => __('Edit Venue Category', 'event_espresso'),
376
+						'filename' => 'venues_edit_category',
377
+					),
378
+				),
379
+				/*'help_tour' => array( 'Venues_Edit_Category_Help_Tour' ),*/
380
+				'require_nonce' => false,
381
+			),
382
+			'category_list'       => array(
383
+				'nav'           => array(
384
+					'label' => __('Categories', 'event_espresso'),
385
+					'order' => 20,
386
+				),
387
+				'list_table'    => 'Venue_Categories_Admin_List_Table',
388
+				'help_tabs'     => array(
389
+					'venues_categories_help_tab'                       => array(
390
+						'title'    => __('Venue Categories', 'event_espresso'),
391
+						'filename' => 'venues_categories',
392
+					),
393
+					'venues_categories_table_column_headings_help_tab' => array(
394
+						'title'    => __('Venue Categories Table Column Headings', 'event_espresso'),
395
+						'filename' => 'venues_categories_table_column_headings',
396
+					),
397
+					'venues_categories_views_help_tab'                 => array(
398
+						'title'    => __('Venue Categories Views', 'event_espresso'),
399
+						'filename' => 'venues_categories_views',
400
+					),
401
+					'venues_categories_other_help_tab'                 => array(
402
+						'title'    => __('Venue Categories Other', 'event_espresso'),
403
+						'filename' => 'venues_categories_other',
404
+					),
405
+				),
406
+				'help_tour'     => array('Venues_Categories_Help_Tour'),
407
+				'metaboxes'     => $this->_default_espresso_metaboxes,
408
+				'require_nonce' => false,
409
+			),
410
+		);
411
+	}
412
+
413
+
414
+	protected function _add_screen_options()
415
+	{
416
+		// todo
417
+	}
418
+
419
+
420
+	protected function _add_screen_options_default()
421
+	{
422
+		$this->_per_page_screen_option();
423
+	}
424
+
425
+
426
+	protected function _add_screen_options_category_list()
427
+	{
428
+		$page_title = $this->_admin_page_title;
429
+		$this->_admin_page_title = __('Venue Categories', 'event_espresso');
430
+		$this->_per_page_screen_option();
431
+		$this->_admin_page_title = $page_title;
432
+	}
433
+
434
+
435
+	// none of the below group are currently used for Event Venues
436
+	protected function _add_feature_pointers()
437
+	{
438
+	}
439
+
440
+	public function admin_init()
441
+	{
442
+	}
443
+
444
+	public function admin_notices()
445
+	{
446
+	}
447
+
448
+	public function admin_footer_scripts()
449
+	{
450
+	}
451
+
452
+
453
+	public function load_scripts_styles_create_new()
454
+	{
455
+		$this->load_scripts_styles_edit();
456
+	}
457
+
458
+
459
+	public function load_scripts_styles()
460
+	{
461
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
462
+		wp_enqueue_style('ee-cat-admin');
463
+	}
464
+
465
+
466
+	public function load_scripts_styles_add_category()
467
+	{
468
+		$this->load_scripts_styles_edit_category();
469
+	}
470
+
471
+
472
+	public function load_scripts_styles_edit_category()
473
+	{
474
+	}
475
+
476
+
477
+	public function load_scripts_styles_edit()
478
+	{
479
+		// styles
480
+		wp_enqueue_style('espresso-ui-theme');
481
+		wp_register_style(
482
+			'espresso_venues',
483
+			EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
484
+			array(),
485
+			EVENT_ESPRESSO_VERSION
486
+		);
487
+		wp_enqueue_style('espresso_venues');
488
+	}
489
+
490
+
491
+	protected function _set_list_table_views_default()
492
+	{
493
+		$this->_views = array(
494
+			'all' => array(
495
+				'slug'        => 'all',
496
+				'label'       => __('View All Venues', 'event_espresso'),
497
+				'count'       => 0,
498
+				'bulk_action' => array(),
499
+			),
500
+		);
501
+
502
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
503
+			$this->_views['all']['bulk_action'] = array(
504
+				'trash_venues' => __('Move to Trash', 'event_espresso'),
505
+			);
506
+			$this->_views['trash'] = array(
507
+				'slug'        => 'trash',
508
+				'label'       => __('Trash', 'event_espresso'),
509
+				'count'       => 0,
510
+				'bulk_action' => array(
511
+					'restore_venues' => __('Restore from Trash', 'event_espresso'),
512
+					'delete_venues'  => __('Delete', 'event_espresso'),
513
+				),
514
+			);
515
+		}
516
+	}
517
+
518
+
519
+	protected function _set_list_table_views_category_list()
520
+	{
521
+		$this->_views = array(
522
+			'all' => array(
523
+				'slug'        => 'all',
524
+				'label'       => __('All', 'event_espresso'),
525
+				'count'       => 0,
526
+				'bulk_action' => array(
527
+					'delete_categories' => __('Delete Permanently', 'event_espresso'),
528
+				),
529
+			),
530
+		);
531
+	}
532
+
533
+
534
+	protected function _overview_list_table()
535
+	{
536
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
537
+		$this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
538
+			get_post_type_archive_link('espresso_venues'),
539
+			__("View Venue Archive Page", "event_espresso"),
540
+			'button'
541
+		);
542
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2');
543
+		$this->_search_btn_label = __('Venues', 'event_espresso');
544
+		$this->display_admin_list_table_page_with_sidebar();
545
+	}
546
+
547
+
548
+	public function extra_misc_actions_publish_box()
549
+	{
550
+		$extra_rows = array(
551
+			'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
552
+			'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
553
+			'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
554
+		);
555
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
556
+		EEH_Template::display_template($template, $extra_rows);
557
+	}
558
+
559
+
560
+	/*************        Google Maps        *************/
561
+
562
+
563
+	protected function _google_map_settings()
564
+	{
565
+
566
+
567
+		$this->_template_args['values'] = $this->_yes_no_values;
568
+		$default_map_settings = new stdClass();
569
+		$default_map_settings->use_google_maps = true;
570
+		$default_map_settings->google_map_api_key = '';
571
+		// for event details pages (reg page)
572
+		$default_map_settings->event_details_map_width = 585;            // ee_map_width_single
573
+		$default_map_settings->event_details_map_height = 362;            // ee_map_height_single
574
+		$default_map_settings->event_details_map_zoom = 14;            // ee_map_zoom_single
575
+		$default_map_settings->event_details_display_nav = true;            // ee_map_nav_display_single
576
+		$default_map_settings->event_details_nav_size = false;            // ee_map_nav_size_single
577
+		$default_map_settings->event_details_control_type = 'default';        // ee_map_type_control_single
578
+		$default_map_settings->event_details_map_align = 'center';            // ee_map_align_single
579
+		// for event list pages
580
+		$default_map_settings->event_list_map_width = 300;            // ee_map_width
581
+		$default_map_settings->event_list_map_height = 185;        // ee_map_height
582
+		$default_map_settings->event_list_map_zoom = 12;            // ee_map_zoom
583
+		$default_map_settings->event_list_display_nav = false;        // ee_map_nav_display
584
+		$default_map_settings->event_list_nav_size = true;            // ee_map_nav_size
585
+		$default_map_settings->event_list_control_type = 'dropdown';        // ee_map_type_control
586
+		$default_map_settings->event_list_map_align = 'center';            // ee_map_align
587
+
588
+		$this->_template_args['map_settings'] =
589
+			isset(EE_Registry::instance()->CFG->map_settings)
590
+			&& ! empty(EE_Registry::instance()->CFG->map_settings)
591
+				? (object) array_merge(
592
+					(array) $default_map_settings,
593
+					(array) EE_Registry::instance()->CFG->map_settings
594
+				)
595
+				: $default_map_settings;
596
+
597
+		$this->_set_add_edit_form_tags('update_google_map_settings');
598
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
599
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
600
+			EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
601
+			$this->_template_args,
602
+			true
603
+		);
604
+		$this->display_admin_page_with_sidebar();
605
+	}
606
+
607
+	protected function _update_google_map_settings()
608
+	{
609
+
610
+		EE_Registry::instance()->CFG->map_settings->use_google_maps =
611
+			isset($this->_req_data['use_google_maps'])
612
+				? absint($this->_req_data['use_google_maps'])
613
+				: EE_Registry::instance()->CFG->map_settings->use_google_maps;
614
+
615
+		EE_Registry::instance()->CFG->map_settings->google_map_api_key =
616
+			isset($this->_req_data['google_map_api_key'])
617
+				? sanitize_text_field($this->_req_data['google_map_api_key'])
618
+				: EE_Registry::instance()->CFG->map_settings->google_map_api_key;
619
+
620
+		EE_Registry::instance()->CFG->map_settings->event_details_map_width =
621
+			isset($this->_req_data['event_details_map_width'])
622
+				? absint($this->_req_data['event_details_map_width'])
623
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_width;
624
+
625
+		EE_Registry::instance()->CFG->map_settings->event_details_map_height =
626
+			isset($this->_req_data['event_details_map_height'])
627
+				? absint($this->_req_data['event_details_map_height'])
628
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_height;
629
+
630
+		EE_Registry::instance()->CFG->map_settings->event_details_map_zoom =
631
+			isset($this->_req_data['event_details_map_zoom'])
632
+				? absint($this->_req_data['event_details_map_zoom'])
633
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_zoom;
634
+
635
+		EE_Registry::instance()->CFG->map_settings->event_details_display_nav =
636
+			isset($this->_req_data['event_details_display_nav'])
637
+				? absint($this->_req_data['event_details_display_nav'])
638
+				: EE_Registry::instance()->CFG->map_settings->event_details_display_nav;
639
+
640
+		EE_Registry::instance()->CFG->map_settings->event_details_nav_size =
641
+			isset($this->_req_data['event_details_nav_size'])
642
+				? absint($this->_req_data['event_details_nav_size'])
643
+				: EE_Registry::instance()->CFG->map_settings->event_details_nav_size;
644
+
645
+		EE_Registry::instance()->CFG->map_settings->event_details_control_type =
646
+			isset($this->_req_data['event_details_control_type'])
647
+				? sanitize_text_field($this->_req_data['event_details_control_type'])
648
+				: EE_Registry::instance()->CFG->map_settings->event_details_control_type;
649
+
650
+		EE_Registry::instance()->CFG->map_settings->event_details_map_align =
651
+			isset($this->_req_data['event_details_map_align'])
652
+				? sanitize_text_field($this->_req_data['event_details_map_align'])
653
+				: EE_Registry::instance()->CFG->map_settings->event_details_map_align;
654
+
655
+		EE_Registry::instance()->CFG->map_settings->event_list_map_width =
656
+			isset($this->_req_data['event_list_map_width'])
657
+				? absint($this->_req_data['event_list_map_width'])
658
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_width;
659
+
660
+		EE_Registry::instance()->CFG->map_settings->event_list_map_height =
661
+			isset($this->_req_data['event_list_map_height'])
662
+				? absint($this->_req_data['event_list_map_height'])
663
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_height;
664
+
665
+		EE_Registry::instance()->CFG->map_settings->event_list_map_zoom =
666
+			isset($this->_req_data['event_list_map_zoom'])
667
+				? absint($this->_req_data['event_list_map_zoom'])
668
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_zoom;
669
+
670
+		EE_Registry::instance()->CFG->map_settings->event_list_display_nav =
671
+			isset($this->_req_data['event_list_display_nav'])
672
+				? absint($this->_req_data['event_list_display_nav'])
673
+				: EE_Registry::instance()->CFG->map_settings->event_list_display_nav;
674
+
675
+		EE_Registry::instance()->CFG->map_settings->event_list_nav_size =
676
+			isset($this->_req_data['event_list_nav_size'])
677
+				? absint($this->_req_data['event_list_nav_size'])
678
+				: EE_Registry::instance()->CFG->map_settings->event_list_nav_size;
679
+
680
+		EE_Registry::instance()->CFG->map_settings->event_list_control_type =
681
+			isset($this->_req_data['event_list_control_type'])
682
+				? sanitize_text_field($this->_req_data['event_list_control_type'])
683
+				: EE_Registry::instance()->CFG->map_settings->event_list_control_type;
684
+
685
+		EE_Registry::instance()->CFG->map_settings->event_list_map_align =
686
+			isset($this->_req_data['event_list_map_align'])
687
+				? sanitize_text_field($this->_req_data['event_list_map_align'])
688
+				: EE_Registry::instance()->CFG->map_settings->event_list_map_align;
689
+
690
+		EE_Registry::instance()->CFG->map_settings = apply_filters(
691
+			'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
692
+			EE_Registry::instance()->CFG->map_settings
693
+		);
694
+
695
+		$what = 'Google Map Settings';
696
+		$success = $this->_update_espresso_configuration(
697
+			$what,
698
+			EE_Registry::instance()->CFG->map_settings,
699
+			__FILE__,
700
+			__FUNCTION__,
701
+			__LINE__
702
+		);
703
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'google_map_settings'));
704
+	}
705
+
706
+
707
+	protected function _venue_editor_metaboxes()
708
+	{
709
+		$this->verify_cpt_object();
710
+
711
+		add_meta_box(
712
+			'espresso_venue_address_options',
713
+			__('Physical Location', 'event_espresso'),
714
+			array($this, 'venue_address_metabox'),
715
+			$this->page_slug,
716
+			'side',
717
+			'default'
718
+		);
719
+		add_meta_box(
720
+			'espresso_venue_gmap_options',
721
+			__('Google Map', 'event_espresso'),
722
+			array($this, 'venue_gmap_metabox'),
723
+			$this->page_slug,
724
+			'side',
725
+			'default'
726
+		);
727
+		add_meta_box(
728
+			'espresso_venue_virtual_loc_options',
729
+			__('Virtual Location', 'event_espresso'),
730
+			array($this, 'venue_virtual_loc_metabox'),
731
+			$this->page_slug,
732
+			'side',
733
+			'default'
734
+		);
735
+	}
736
+
737
+
738
+	public function venue_gmap_metabox()
739
+	{
740
+		$template_args = array(
741
+			'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
742
+				'vnu_enable_for_gmap',
743
+				$this->get_yes_no_values(),
744
+				$this->_cpt_model_obj->enable_for_gmap()
745
+			),
746
+			'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
747
+		);
748
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
749
+		EEH_Template::display_template($template, $template_args);
750
+	}
751
+
752
+
753
+	public function venue_address_metabox()
754
+	{
755
+
756
+		$template_args['_venue'] = $this->_cpt_model_obj;
757
+
758
+		$template_args['states_dropdown'] = EEH_Form_Fields::generate_form_input(
759
+			$QFI = new EE_Question_Form_Input(
760
+				EE_Question::new_instance(
761
+					array('QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state')
762
+				),
763
+				EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->state_ID())),
764
+				array(
765
+					'input_name'     => 'sta_id',
766
+					'input_id'       => 'sta_id',
767
+					'input_class'    => '',
768
+					'input_prefix'   => '',
769
+					'append_qstn_id' => false,
770
+				)
771
+			)
772
+		);
773
+		$template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
774
+			$QFI = new EE_Question_Form_Input(
775
+				EE_Question::new_instance(
776
+					array('QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country')
777
+				),
778
+				EE_Answer::new_instance(array('ANS_value' => $this->_cpt_model_obj->country_ID())),
779
+				array(
780
+					'input_name'     => 'cnt_iso',
781
+					'input_id'       => 'cnt_iso',
782
+					'input_class'    => '',
783
+					'input_prefix'   => '',
784
+					'append_qstn_id' => false,
785
+				)
786
+			)
787
+		);
788
+
789
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
790
+		EEH_Template::display_template($template, $template_args);
791
+	}
792
+
793
+
794
+	public function venue_virtual_loc_metabox()
795
+	{
796
+		$template_args = array(
797
+			'_venue' => $this->_cpt_model_obj,
798
+		);
799
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
800
+		EEH_Template::display_template($template, $template_args);
801
+	}
802
+
803
+
804
+	protected function _restore_cpt_item($post_id, $revision_id)
805
+	{
806
+		$venue_obj = $this->_venue_model->get_one_by_ID($post_id);
807
+
808
+		// meta revision restore
809
+		$venue_obj->restore_revision($revision_id);
810
+	}
811
+
812
+
813
+	/**
814
+	 * Handles updates for venue cpts
815
+	 *
816
+	 * @param  int    $post_id ID of Venue CPT
817
+	 * @param  object $post    Post object (with "blessed" WP properties)
818
+	 * @return void
819
+	 */
820
+	protected function _insert_update_cpt_item($post_id, $post)
821
+	{
822
+
823
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
824
+			return;// get out we're not processing the saving of venues.
825
+		}
826
+
827
+		$wheres = array($this->_venue_model->primary_key_name() => $post_id);
828
+
829
+		$venue_values = array(
830
+			'VNU_address'         => ! empty($this->_req_data['vnu_address']) ? $this->_req_data['vnu_address'] : null,
831
+			'VNU_address2'        => ! empty($this->_req_data['vnu_address2']) ? $this->_req_data['vnu_address2']
832
+				: null,
833
+			'VNU_city'            => ! empty($this->_req_data['vnu_city']) ? $this->_req_data['vnu_city'] : null,
834
+			'STA_ID'              => ! empty($this->_req_data['sta_id']) ? $this->_req_data['sta_id'] : null,
835
+			'CNT_ISO'             => ! empty($this->_req_data['cnt_iso']) ? $this->_req_data['cnt_iso'] : null,
836
+			'VNU_zip'             => ! empty($this->_req_data['vnu_zip']) ? $this->_req_data['vnu_zip'] : null,
837
+			'VNU_phone'           => ! empty($this->_req_data['vnu_phone']) ? $this->_req_data['vnu_phone'] : null,
838
+			'VNU_capacity'        => ! empty($this->_req_data['vnu_capacity']) ? str_replace(
839
+				',',
840
+				'',
841
+				$this->_req_data['vnu_capacity']
842
+			) : EE_INF,
843
+			'VNU_url'             => ! empty($this->_req_data['vnu_url']) ? $this->_req_data['vnu_url'] : null,
844
+			'VNU_virtual_phone'   => ! empty($this->_req_data['vnu_virtual_phone'])
845
+				? $this->_req_data['vnu_virtual_phone'] : null,
846
+			'VNU_virtual_url'     => ! empty($this->_req_data['vnu_virtual_url']) ? $this->_req_data['vnu_virtual_url']
847
+				: null,
848
+			'VNU_enable_for_gmap' => ! empty($this->_req_data['vnu_enable_for_gmap']) ? true : false,
849
+			'VNU_google_map_link' => ! empty($this->_req_data['vnu_google_map_link'])
850
+				? $this->_req_data['vnu_google_map_link'] : null,
851
+		);
852
+
853
+		// update venue
854
+		$success = $this->_venue_model->update($venue_values, array($wheres));
855
+
856
+		// get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
857
+		$get_one_where = array($this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status);
858
+		$venue = $this->_venue_model->get_one(array($get_one_where));
859
+
860
+		// notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use.  So this is just here for addons to more easily hook into venue saves.
861
+		$venue_update_callbacks = apply_filters(
862
+			'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
863
+			array()
864
+		);
865
+
866
+		$att_success = true;
867
+
868
+		foreach ($venue_update_callbacks as $v_callback) {
869
+			$_succ = call_user_func_array($v_callback, array($venue, $this->_req_data));
870
+			$att_success = ! $att_success ? $att_success
871
+				: $_succ; // if ANY of these updates fail then we want the appropriate global error message
872
+		}
873
+
874
+		// any errors?
875
+		if ($success && ! $att_success) {
876
+			EE_Error::add_error(
877
+				__(
878
+					'Venue Details saved successfully but something went wrong with saving attachments.',
879
+					'event_espresso'
880
+				),
881
+				__FILE__,
882
+				__FUNCTION__,
883
+				__LINE__
884
+			);
885
+		} elseif ($success === false) {
886
+			EE_Error::add_error(
887
+				__('Venue Details did not save successfully.', 'event_espresso'),
888
+				__FILE__,
889
+				__FUNCTION__,
890
+				__LINE__
891
+			);
892
+		}
893
+	}
894
+
895
+
896
+	public function trash_cpt_item($post_id)
897
+	{
898
+		$this->_req_data['VNU_ID'] = $post_id;
899
+		$this->_trash_or_restore_venue('trash', false);
900
+	}
901
+
902
+
903
+	public function restore_cpt_item($post_id)
904
+	{
905
+		$this->_req_data['VNU_ID'] = $post_id;
906
+		$this->_trash_or_restore_venue('draft', false);
907
+	}
908
+
909
+
910
+	public function delete_cpt_item($post_id)
911
+	{
912
+		$this->_req_data['VNU_ID'] = $post_id;
913
+		$this->_delete_venue(false);
914
+	}
915
+
916
+
917
+	public function get_venue_object()
918
+	{
919
+		return $this->_cpt_model_obj;
920
+	}
921
+
922
+
923
+	protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
924
+	{
925
+		$VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : false;
926
+
927
+		// loop thru venues
928
+		if ($VNU_ID) {
929
+			// clean status
930
+			$venue_status = sanitize_key($venue_status);
931
+			// grab status
932
+			if (! empty($venue_status)) {
933
+				$success = $this->_change_venue_status($VNU_ID, $venue_status);
934
+			} else {
935
+				$success = false;
936
+				$msg = __(
937
+					'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
938
+					'event_espresso'
939
+				);
940
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
941
+			}
942
+		} else {
943
+			$success = false;
944
+			$msg = __(
945
+				'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
946
+				'event_espresso'
947
+			);
948
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
949
+		}
950
+		$action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
951
+
952
+		if ($redirect_after) {
953
+			$this->_redirect_after_action($success, 'Venue', $action, array('action' => 'default'));
954
+		}
955
+	}
956
+
957
+
958
+	protected function _trash_or_restore_venues($venue_status = 'trash')
959
+	{
960
+		// clean status
961
+		$venue_status = sanitize_key($venue_status);
962
+		// grab status
963
+		if (! empty($venue_status)) {
964
+			$success = true;
965
+			// determine the event id and set to array.
966
+			$VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
967
+			// loop thru events
968
+			foreach ($VNU_IDs as $VNU_ID) {
969
+				if ($VNU_ID = absint($VNU_ID)) {
970
+					$results = $this->_change_venue_status($VNU_ID, $venue_status);
971
+					$success = $results !== false ? $success : false;
972
+				} else {
973
+					$msg = sprintf(
974
+						__(
975
+							'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
976
+							'event_espresso'
977
+						),
978
+						$VNU_ID
979
+					);
980
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
981
+					$success = false;
982
+				}
983
+			}
984
+		} else {
985
+			$success = false;
986
+			$msg = __(
987
+				'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
988
+				'event_espresso'
989
+			);
990
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
991
+		}
992
+		// in order to force a pluralized result message we need to send back a success status greater than 1
993
+		$success = $success ? 2 : false;
994
+		$action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
995
+		$this->_redirect_after_action($success, 'Venues', $action, array('action' => 'default'));
996
+	}
997
+
998
+
999
+	/**
1000
+	 * _trash_or_restore_venues
1001
+	 *
1002
+	 * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1003
+	 * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1004
+	 * accepting a certain number of params.
1005
+	 *
1006
+	 * @access  private
1007
+	 * @param  int    $VNU_ID
1008
+	 * @param  string $venue_status
1009
+	 * @return void
1010
+	 */
1011
+	private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1012
+	{
1013
+		// grab venue id
1014
+		if (! $VNU_ID) {
1015
+			$msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1016
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1017
+			return false;
1018
+		}
1019
+
1020
+		$this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1021
+
1022
+		// clean status
1023
+		$venue_status = sanitize_key($venue_status);
1024
+		// grab status
1025
+		if (! $venue_status) {
1026
+			$msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso');
1027
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1028
+			return false;
1029
+		}
1030
+
1031
+		// was event trashed or restored ?
1032
+		switch ($venue_status) {
1033
+			case 'draft':
1034
+				$action = 'restored from the trash';
1035
+				$hook = 'AHEE_venue_restored_from_trash';
1036
+				break;
1037
+			case 'trash':
1038
+				$action = 'moved to the trash';
1039
+				$hook = 'AHEE_venue_moved_to_trash';
1040
+				break;
1041
+			default:
1042
+				$action = 'updated';
1043
+				$hook = false;
1044
+		}
1045
+		// use class to change status
1046
+		$this->_cpt_model_obj->set_status($venue_status);
1047
+		$success = $this->_cpt_model_obj->save();
1048
+
1049
+		if ($success === false) {
1050
+			$msg = sprintf(__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1051
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1052
+			return false;
1053
+		}
1054
+		if ($hook) {
1055
+			do_action($hook);
1056
+		}
1057
+		return true;
1058
+	}
1059
+
1060
+
1061
+	/**
1062
+	 * @param  bool $redirect_after
1063
+	 * @return void
1064
+	 */
1065
+	protected function _delete_venue($redirect_after = true)
1066
+	{
1067
+		// determine the venue id and set to array.
1068
+		$VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : null;
1069
+		$VNU_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $VNU_ID;
1070
+
1071
+
1072
+		// loop thru venues
1073
+		if ($VNU_ID) {
1074
+			$success = $this->_delete_or_trash_venue($VNU_ID);
1075
+		} else {
1076
+			$success = false;
1077
+			$msg = __(
1078
+				'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1079
+				'event_espresso'
1080
+			);
1081
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1082
+		}
1083
+		if ($redirect_after) {
1084
+			$this->_redirect_after_action($success, 'Venue', 'deleted', array('action' => 'default'));
1085
+		}
1086
+	}
1087
+
1088
+
1089
+	protected function _delete_venues()
1090
+	{
1091
+		$success = true;
1092
+		// determine the event id and set to array.
1093
+		$VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
1094
+		// loop thru events
1095
+		foreach ($VNU_IDs as $VNU_ID) {
1096
+			if ($VNU_ID = absint($VNU_ID)) {
1097
+				$results = $this->_delete_or_trash_venue($VNU_ID);
1098
+				$success = $results !== false ? $success : false;
1099
+			} else {
1100
+				$success = false;
1101
+				$msg = __(
1102
+					'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1103
+					'event_espresso'
1104
+				);
1105
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1106
+			}
1107
+		}
1108
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1109
+		$success = $success ? 2 : false;
1110
+		$this->_redirect_after_action(
1111
+			$success,
1112
+			__('Venues', 'event_espresso'),
1113
+			__('deleted', 'event_espresso'),
1114
+			array('action' => 'default')
1115
+		);
1116
+	}
1117
+
1118
+
1119
+	// todo: put in parent
1120
+	private function _delete_or_trash_venue($VNU_ID = false)
1121
+	{
1122
+		// grab event id
1123
+		if (! $VNU_ID = absint($VNU_ID)) {
1124
+			$msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1125
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1126
+			return false;
1127
+		}
1128
+
1129
+
1130
+		$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1131
+		// first need to remove all term relationships
1132
+		$venue->_remove_relations('Term_Taxonomy');
1133
+		$success = $venue->delete_permanently();
1134
+		// did it all go as planned ?
1135
+		if ($success) {
1136
+			$msg = sprintf(__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1137
+			EE_Error::add_success($msg);
1138
+		} else {
1139
+			$msg = sprintf(__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'), $VNU_ID);
1140
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1141
+			return false;
1142
+		}
1143
+		do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1144
+		return true;
1145
+	}
1146
+
1147
+
1148
+
1149
+
1150
+	/***********/
1151
+	/* QUERIES */
1152
+
1153
+
1154
+	public function get_venues($per_page = 10, $count = false)
1155
+	{
1156
+
1157
+		$_orderby = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1158
+
1159
+		switch ($_orderby) {
1160
+			case 'id':
1161
+				$orderby = 'VNU_ID';
1162
+				break;
1163
+
1164
+			case 'capacity':
1165
+				$orderby = 'VNU_capacity';
1166
+				break;
1167
+
1168
+			case 'city':
1169
+				$orderby = 'VNU_city';
1170
+				break;
1171
+
1172
+			default:
1173
+				$orderby = 'VNU_name';
1174
+		}
1175
+
1176
+
1177
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1178
+			: 'ASC';
1179
+
1180
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1181
+			? $this->_req_data['paged'] : 1;
1182
+		$per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
1183
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1184
+			? $this->_req_data['perpage'] : $per_page;
1185
+
1186
+
1187
+		$offset = ($current_page - 1) * $per_page;
1188
+		$limit = array($offset, $per_page);
1189
+
1190
+		$category = isset($this->_req_data['category']) && $this->_req_data['category'] > 0
1191
+			? $this->_req_data['category'] : null;
1192
+		$where = array();
1193
+
1194
+		// only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1195
+		if (isset($this->_req_data['status']) && $this->_req_data['status'] != 'all') {
1196
+			$where['status'] = $this->_req_data['status'];
1197
+		}
1198
+
1199
+		if (isset($this->_req_data['venue_status'])) {
1200
+			$where['status'] = $this->_req_data['venue_status'];
1201
+		}
1202
+
1203
+
1204
+		if ($category) {
1205
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1206
+			$where['Term_Taxonomy.term_id'] = $category;
1207
+		}
1208
+
1209
+
1210
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1211
+			$where['VNU_wp_user'] = get_current_user_id();
1212
+		} else {
1213
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1214
+				$where['OR'] = array(
1215
+					'status*restrict_private' => array('!=', 'private'),
1216
+					'AND'                     => array(
1217
+						'status*inclusive' => array('=', 'private'),
1218
+						'VNU_wp_user'      => get_current_user_id(),
1219
+					),
1220
+				);
1221
+			}
1222
+		}
1223
+
1224
+
1225
+		if (isset($this->_req_data['s'])) {
1226
+			$sstr = '%' . $this->_req_data['s'] . '%';
1227
+			$where['OR'] = array(
1228
+				'VNU_name'               => array('LIKE', $sstr),
1229
+				'VNU_desc'               => array('LIKE', $sstr),
1230
+				'VNU_short_desc'         => array('LIKE', $sstr),
1231
+				'VNU_address'            => array('LIKE', $sstr),
1232
+				'VNU_address2'           => array('LIKE', $sstr),
1233
+				'VNU_city'               => array('LIKE', $sstr),
1234
+				'VNU_zip'                => array('LIKE', $sstr),
1235
+				'VNU_phone'              => array('LIKE', $sstr),
1236
+				'VNU_url'                => array('LIKE', $sstr),
1237
+				'VNU_virtual_phone'      => array('LIKE', $sstr),
1238
+				'VNU_virtual_url'        => array('LIKE', $sstr),
1239
+				'VNU_google_map_link'    => array('LIKE', $sstr),
1240
+				'Event.EVT_name'         => array('LIKE', $sstr),
1241
+				'Event.EVT_desc'         => array('LIKE', $sstr),
1242
+				'Event.EVT_phone'        => array('LIKE', $sstr),
1243
+				'Event.EVT_external_URL' => array('LIKE', $sstr),
1244
+			);
1245
+		}
1246 1246
 
1247 1247
 
1248
-        $venues = $count
1249
-            ? $this->_venue_model->count(array($where), 'VNU_ID')
1250
-            : $this->_venue_model->get_all(
1251
-                array($where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort)
1252
-            );
1253
-
1254
-        return $venues;
1255
-    }
1256
-
1257
-
1258
-
1259
-
1260
-    /** Venue Category Stuff **/
1261
-
1262
-    /**
1263
-     * set the _category property with the category object for the loaded page.
1264
-     *
1265
-     * @access private
1266
-     * @return void
1267
-     */
1268
-    private function _set_category_object()
1269
-    {
1270
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
1271
-            return;
1272
-        } // already have the category object so get out.
1273
-
1274
-        // set default category object
1275
-        $this->_set_empty_category_object();
1276
-
1277
-        // only set if we've got an id
1278
-        if (! isset($this->_req_data['VEN_CAT_ID'])) {
1279
-            return;
1280
-        }
1281
-
1282
-        $category_id = absint($this->_req_data['VEN_CAT_ID']);
1283
-        $term = get_term($category_id, 'espresso_venue_categories');
1284
-
1285
-
1286
-        if (! empty($term)) {
1287
-            $this->_category->category_name = $term->name;
1288
-            $this->_category->category_identifier = $term->slug;
1289
-            $this->_category->category_desc = $term->description;
1290
-            $this->_category->id = $term->term_id;
1291
-            $this->_category->parent = $term->parent;
1292
-        }
1293
-    }
1294
-
1295
-
1296
-    private function _set_empty_category_object()
1297
-    {
1298
-        $this->_category = new stdClass();
1299
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1300
-        $this->_category->id = $this->_category->parent = 0;
1301
-    }
1302
-
1303
-
1304
-    protected function _category_list_table()
1305
-    {
1306
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1307
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1308
-            'add_category',
1309
-            'add_category',
1310
-            array(),
1311
-            'add-new-h2'
1312
-        );
1313
-        $this->_search_btn_label = __('Venue Categories', 'event_espresso');
1314
-        $this->display_admin_list_table_page_with_sidebar();
1315
-    }
1316
-
1317
-
1318
-    protected function _category_details($view)
1319
-    {
1320
-
1321
-        // load formatter helper
1322
-        // load field generator helper
1323
-
1324
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
1325
-        $this->_set_add_edit_form_tags($route);
1326
-
1327
-        $this->_set_category_object();
1328
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
1329
-
1330
-        $delete_action = 'delete_category';
1331
-
1332
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'category_list'), $this->_admin_base_url);
1333
-
1334
-        $this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1335
-
1336
-        // take care of contents
1337
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
1338
-        $this->display_admin_page_with_sidebar();
1339
-    }
1340
-
1341
-
1342
-    protected function _category_details_content()
1343
-    {
1344
-        $editor_args['category_desc'] = array(
1345
-            'type'          => 'wp_editor',
1346
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1347
-            'class'         => 'my_editor_custom',
1348
-            'wpeditor_args' => array('media_buttons' => false),
1349
-        );
1350
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
1351
-
1352
-        $all_terms = get_terms(
1353
-            array('espresso_venue_categories'),
1354
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
1355
-        );
1356
-
1357
-        // setup category select for term parents.
1358
-        $category_select_values[] = array(
1359
-            'text' => __('No Parent', 'event_espresso'),
1360
-            'id'   => 0,
1361
-        );
1362
-        foreach ($all_terms as $term) {
1363
-            $category_select_values[] = array(
1364
-                'text' => $term->name,
1365
-                'id'   => $term->term_id,
1366
-            );
1367
-        }
1368
-
1369
-        $category_select = EEH_Form_Fields::select_input(
1370
-            'category_parent',
1371
-            $category_select_values,
1372
-            $this->_category->parent
1373
-        );
1374
-        $template_args = array(
1375
-            'category'                 => $this->_category,
1376
-            'category_select'          => $category_select,
1377
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1378
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1379
-            'disable'                  => '',
1380
-            'disabled_message'         => false,
1381
-        );
1382
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1383
-        return EEH_Template::display_template($template, $template_args, true);
1384
-    }
1385
-
1386
-
1387
-    protected function _delete_categories()
1388
-    {
1389
-        $cat_ids = isset($this->_req_data['VEN_CAT_ID']) ? (array) $this->_req_data['VEN_CAT_ID']
1390
-            : (array) $this->_req_data['category_id'];
1391
-
1392
-        foreach ($cat_ids as $cat_id) {
1393
-            $this->_delete_category($cat_id);
1394
-        }
1395
-
1396
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
1397
-        $query_args = array(
1398
-            'action' => 'category_list',
1399
-        );
1400
-        $this->_redirect_after_action(0, '', '', $query_args);
1401
-    }
1402
-
1403
-
1404
-    protected function _delete_category($cat_id)
1405
-    {
1406
-        $cat_id = absint($cat_id);
1407
-        wp_delete_term($cat_id, 'espresso_venue_categories');
1408
-    }
1409
-
1410
-
1411
-    protected function _insert_or_update_category($new_category)
1412
-    {
1413
-
1414
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1415
-        $success = 0; // we already have a success message so lets not send another.
1416
-        if ($cat_id) {
1417
-            $query_args = array(
1418
-                'action'     => 'edit_category',
1419
-                'VEN_CAT_ID' => $cat_id,
1420
-            );
1421
-        } else {
1422
-            $query_args = array('action' => 'add_category');
1423
-        }
1424
-        $this->_redirect_after_action($success, '', '', $query_args, true);
1425
-    }
1426
-
1427
-
1428
-    private function _insert_category($update = false)
1429
-    {
1430
-        $cat_id = $update ? $this->_req_data['VEN_CAT_ID'] : '';
1431
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
1432
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
1433
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
1434
-
1435
-        if (empty($category_name)) {
1436
-            $msg = __('You must add a name for the category.', 'event_espresso');
1437
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1438
-            return false;
1439
-        }
1440
-
1441
-
1442
-        $term_args = array(
1443
-            'name'        => $category_name,
1444
-            'description' => $category_desc,
1445
-            'parent'      => $category_parent,
1446
-        );
1447
-
1448
-        $insert_ids = $update
1449
-            ? wp_update_term($cat_id, 'espresso_venue_categories', $term_args)
1450
-            : wp_insert_term(
1451
-                $category_name,
1452
-                'espresso_venue_categories',
1453
-                $term_args
1454
-            );
1455
-
1456
-        if (! is_array($insert_ids)) {
1457
-            $msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso');
1458
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1459
-        } else {
1460
-            $cat_id = $insert_ids['term_id'];
1461
-            $msg = sprintf(__('The category %s was successfully created', 'event_espresso'), $category_name);
1462
-            EE_Error::add_success($msg);
1463
-        }
1464
-
1465
-        return $cat_id;
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     * TODO handle category exports()
1471
-     *
1472
-     * @return file export
1473
-     */
1474
-    protected function _categories_export()
1475
-    {
1476
-
1477
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
1478
-        $new_request_args = array(
1479
-            'export'       => 'report',
1480
-            'action'       => 'categories',
1481
-            'category_ids' => $this->_req_data['VEN_CAT_ID'],
1482
-        );
1483
-
1484
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
1485
-
1486
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1487
-            require_once(EE_CLASSES . 'EE_Export.class.php');
1488
-            $EE_Export = EE_Export::instance($this->_req_data);
1489
-            $EE_Export->export();
1490
-        }
1491
-    }
1492
-
1493
-
1494
-    protected function _import_categories()
1495
-    {
1496
-
1497
-        require_once(EE_CLASSES . 'EE_Import.class.php');
1498
-        EE_Import::instance()->import();
1499
-    }
1500
-
1501
-
1502
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
1503
-    {
1504
-
1505
-        // testing term stuff
1506
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
1507
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1508
-        $limit = ($current_page - 1) * $per_page;
1509
-        $where = array('taxonomy' => 'espresso_venue_categories');
1510
-        if (isset($this->_req_data['s'])) {
1511
-            $sstr = '%' . $this->_req_data['s'] . '%';
1512
-            $where['OR'] = array(
1513
-                'Term.name'   => array('LIKE', $sstr),
1514
-                'description' => array('LIKE', $sstr),
1515
-            );
1516
-        }
1517
-
1518
-        $query_params = array(
1519
-            $where,
1520
-            'order_by'   => array($orderby => $order),
1521
-            'limit'      => $limit . ',' . $per_page,
1522
-            'force_join' => array('Term'),
1523
-        );
1524
-
1525
-        $categories = $count ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1526
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
1527
-
1528
-        return $categories;
1529
-    }
1530
-
1531
-
1532
-    /* end category stuff */
1533
-    /**************/
1248
+		$venues = $count
1249
+			? $this->_venue_model->count(array($where), 'VNU_ID')
1250
+			: $this->_venue_model->get_all(
1251
+				array($where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort)
1252
+			);
1253
+
1254
+		return $venues;
1255
+	}
1256
+
1257
+
1258
+
1259
+
1260
+	/** Venue Category Stuff **/
1261
+
1262
+	/**
1263
+	 * set the _category property with the category object for the loaded page.
1264
+	 *
1265
+	 * @access private
1266
+	 * @return void
1267
+	 */
1268
+	private function _set_category_object()
1269
+	{
1270
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
1271
+			return;
1272
+		} // already have the category object so get out.
1273
+
1274
+		// set default category object
1275
+		$this->_set_empty_category_object();
1276
+
1277
+		// only set if we've got an id
1278
+		if (! isset($this->_req_data['VEN_CAT_ID'])) {
1279
+			return;
1280
+		}
1281
+
1282
+		$category_id = absint($this->_req_data['VEN_CAT_ID']);
1283
+		$term = get_term($category_id, 'espresso_venue_categories');
1284
+
1285
+
1286
+		if (! empty($term)) {
1287
+			$this->_category->category_name = $term->name;
1288
+			$this->_category->category_identifier = $term->slug;
1289
+			$this->_category->category_desc = $term->description;
1290
+			$this->_category->id = $term->term_id;
1291
+			$this->_category->parent = $term->parent;
1292
+		}
1293
+	}
1294
+
1295
+
1296
+	private function _set_empty_category_object()
1297
+	{
1298
+		$this->_category = new stdClass();
1299
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1300
+		$this->_category->id = $this->_category->parent = 0;
1301
+	}
1302
+
1303
+
1304
+	protected function _category_list_table()
1305
+	{
1306
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1307
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1308
+			'add_category',
1309
+			'add_category',
1310
+			array(),
1311
+			'add-new-h2'
1312
+		);
1313
+		$this->_search_btn_label = __('Venue Categories', 'event_espresso');
1314
+		$this->display_admin_list_table_page_with_sidebar();
1315
+	}
1316
+
1317
+
1318
+	protected function _category_details($view)
1319
+	{
1320
+
1321
+		// load formatter helper
1322
+		// load field generator helper
1323
+
1324
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
1325
+		$this->_set_add_edit_form_tags($route);
1326
+
1327
+		$this->_set_category_object();
1328
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
1329
+
1330
+		$delete_action = 'delete_category';
1331
+
1332
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'category_list'), $this->_admin_base_url);
1333
+
1334
+		$this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1335
+
1336
+		// take care of contents
1337
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
1338
+		$this->display_admin_page_with_sidebar();
1339
+	}
1340
+
1341
+
1342
+	protected function _category_details_content()
1343
+	{
1344
+		$editor_args['category_desc'] = array(
1345
+			'type'          => 'wp_editor',
1346
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1347
+			'class'         => 'my_editor_custom',
1348
+			'wpeditor_args' => array('media_buttons' => false),
1349
+		);
1350
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
1351
+
1352
+		$all_terms = get_terms(
1353
+			array('espresso_venue_categories'),
1354
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
1355
+		);
1356
+
1357
+		// setup category select for term parents.
1358
+		$category_select_values[] = array(
1359
+			'text' => __('No Parent', 'event_espresso'),
1360
+			'id'   => 0,
1361
+		);
1362
+		foreach ($all_terms as $term) {
1363
+			$category_select_values[] = array(
1364
+				'text' => $term->name,
1365
+				'id'   => $term->term_id,
1366
+			);
1367
+		}
1368
+
1369
+		$category_select = EEH_Form_Fields::select_input(
1370
+			'category_parent',
1371
+			$category_select_values,
1372
+			$this->_category->parent
1373
+		);
1374
+		$template_args = array(
1375
+			'category'                 => $this->_category,
1376
+			'category_select'          => $category_select,
1377
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1378
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1379
+			'disable'                  => '',
1380
+			'disabled_message'         => false,
1381
+		);
1382
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1383
+		return EEH_Template::display_template($template, $template_args, true);
1384
+	}
1385
+
1386
+
1387
+	protected function _delete_categories()
1388
+	{
1389
+		$cat_ids = isset($this->_req_data['VEN_CAT_ID']) ? (array) $this->_req_data['VEN_CAT_ID']
1390
+			: (array) $this->_req_data['category_id'];
1391
+
1392
+		foreach ($cat_ids as $cat_id) {
1393
+			$this->_delete_category($cat_id);
1394
+		}
1395
+
1396
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
1397
+		$query_args = array(
1398
+			'action' => 'category_list',
1399
+		);
1400
+		$this->_redirect_after_action(0, '', '', $query_args);
1401
+	}
1402
+
1403
+
1404
+	protected function _delete_category($cat_id)
1405
+	{
1406
+		$cat_id = absint($cat_id);
1407
+		wp_delete_term($cat_id, 'espresso_venue_categories');
1408
+	}
1409
+
1410
+
1411
+	protected function _insert_or_update_category($new_category)
1412
+	{
1413
+
1414
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1415
+		$success = 0; // we already have a success message so lets not send another.
1416
+		if ($cat_id) {
1417
+			$query_args = array(
1418
+				'action'     => 'edit_category',
1419
+				'VEN_CAT_ID' => $cat_id,
1420
+			);
1421
+		} else {
1422
+			$query_args = array('action' => 'add_category');
1423
+		}
1424
+		$this->_redirect_after_action($success, '', '', $query_args, true);
1425
+	}
1426
+
1427
+
1428
+	private function _insert_category($update = false)
1429
+	{
1430
+		$cat_id = $update ? $this->_req_data['VEN_CAT_ID'] : '';
1431
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
1432
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
1433
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
1434
+
1435
+		if (empty($category_name)) {
1436
+			$msg = __('You must add a name for the category.', 'event_espresso');
1437
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1438
+			return false;
1439
+		}
1440
+
1441
+
1442
+		$term_args = array(
1443
+			'name'        => $category_name,
1444
+			'description' => $category_desc,
1445
+			'parent'      => $category_parent,
1446
+		);
1447
+
1448
+		$insert_ids = $update
1449
+			? wp_update_term($cat_id, 'espresso_venue_categories', $term_args)
1450
+			: wp_insert_term(
1451
+				$category_name,
1452
+				'espresso_venue_categories',
1453
+				$term_args
1454
+			);
1455
+
1456
+		if (! is_array($insert_ids)) {
1457
+			$msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso');
1458
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1459
+		} else {
1460
+			$cat_id = $insert_ids['term_id'];
1461
+			$msg = sprintf(__('The category %s was successfully created', 'event_espresso'), $category_name);
1462
+			EE_Error::add_success($msg);
1463
+		}
1464
+
1465
+		return $cat_id;
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 * TODO handle category exports()
1471
+	 *
1472
+	 * @return file export
1473
+	 */
1474
+	protected function _categories_export()
1475
+	{
1476
+
1477
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
1478
+		$new_request_args = array(
1479
+			'export'       => 'report',
1480
+			'action'       => 'categories',
1481
+			'category_ids' => $this->_req_data['VEN_CAT_ID'],
1482
+		);
1483
+
1484
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
1485
+
1486
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1487
+			require_once(EE_CLASSES . 'EE_Export.class.php');
1488
+			$EE_Export = EE_Export::instance($this->_req_data);
1489
+			$EE_Export->export();
1490
+		}
1491
+	}
1492
+
1493
+
1494
+	protected function _import_categories()
1495
+	{
1496
+
1497
+		require_once(EE_CLASSES . 'EE_Import.class.php');
1498
+		EE_Import::instance()->import();
1499
+	}
1500
+
1501
+
1502
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
1503
+	{
1504
+
1505
+		// testing term stuff
1506
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
1507
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1508
+		$limit = ($current_page - 1) * $per_page;
1509
+		$where = array('taxonomy' => 'espresso_venue_categories');
1510
+		if (isset($this->_req_data['s'])) {
1511
+			$sstr = '%' . $this->_req_data['s'] . '%';
1512
+			$where['OR'] = array(
1513
+				'Term.name'   => array('LIKE', $sstr),
1514
+				'description' => array('LIKE', $sstr),
1515
+			);
1516
+		}
1517
+
1518
+		$query_params = array(
1519
+			$where,
1520
+			'order_by'   => array($orderby => $order),
1521
+			'limit'      => $limit . ',' . $per_page,
1522
+			'force_join' => array('Term'),
1523
+		);
1524
+
1525
+		$categories = $count ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1526
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
1527
+
1528
+		return $categories;
1529
+	}
1530
+
1531
+
1532
+	/* end category stuff */
1533
+	/**************/
1534 1534
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 
46 46
     protected function _init_page_props()
47 47
     {
48
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
48
+        require_once(EE_MODELS.'EEM_Venue.model.php');
49 49
         $this->page_slug = EE_VENUES_PG_SLUG;
50 50
         $this->_admin_base_url = EE_VENUES_ADMIN_URL;
51
-        $this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
51
+        $this->_admin_base_path = EE_ADMIN_PAGES.'venues';
52 52
         $this->page_label = __('Event Venues', 'event_espresso');
53 53
         $this->_cpt_model_names = array(
54 54
             'create_new' => 'EEM_Venue',
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 
459 459
     public function load_scripts_styles()
460 460
     {
461
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
461
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
462 462
         wp_enqueue_style('ee-cat-admin');
463 463
     }
464 464
 
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
         wp_enqueue_style('espresso-ui-theme');
481 481
         wp_register_style(
482 482
             'espresso_venues',
483
-            EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
483
+            EE_VENUES_ASSETS_URL.'ee-venues-admin.css',
484 484
             array(),
485 485
             EVENT_ESPRESSO_VERSION
486 486
         );
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
             __("View Venue Archive Page", "event_espresso"),
540 540
             'button'
541 541
         );
542
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2');
542
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2');
543 543
         $this->_search_btn_label = __('Venues', 'event_espresso');
544 544
         $this->display_admin_list_table_page_with_sidebar();
545 545
     }
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
             'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
553 553
             'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
554 554
         );
555
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
555
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_publish_box_extras.template.php';
556 556
         EEH_Template::display_template($template, $extra_rows);
557 557
     }
558 558
 
@@ -569,21 +569,21 @@  discard block
 block discarded – undo
569 569
         $default_map_settings->use_google_maps = true;
570 570
         $default_map_settings->google_map_api_key = '';
571 571
         // for event details pages (reg page)
572
-        $default_map_settings->event_details_map_width = 585;            // ee_map_width_single
573
-        $default_map_settings->event_details_map_height = 362;            // ee_map_height_single
574
-        $default_map_settings->event_details_map_zoom = 14;            // ee_map_zoom_single
575
-        $default_map_settings->event_details_display_nav = true;            // ee_map_nav_display_single
576
-        $default_map_settings->event_details_nav_size = false;            // ee_map_nav_size_single
577
-        $default_map_settings->event_details_control_type = 'default';        // ee_map_type_control_single
578
-        $default_map_settings->event_details_map_align = 'center';            // ee_map_align_single
572
+        $default_map_settings->event_details_map_width = 585; // ee_map_width_single
573
+        $default_map_settings->event_details_map_height = 362; // ee_map_height_single
574
+        $default_map_settings->event_details_map_zoom = 14; // ee_map_zoom_single
575
+        $default_map_settings->event_details_display_nav = true; // ee_map_nav_display_single
576
+        $default_map_settings->event_details_nav_size = false; // ee_map_nav_size_single
577
+        $default_map_settings->event_details_control_type = 'default'; // ee_map_type_control_single
578
+        $default_map_settings->event_details_map_align = 'center'; // ee_map_align_single
579 579
         // for event list pages
580
-        $default_map_settings->event_list_map_width = 300;            // ee_map_width
581
-        $default_map_settings->event_list_map_height = 185;        // ee_map_height
582
-        $default_map_settings->event_list_map_zoom = 12;            // ee_map_zoom
583
-        $default_map_settings->event_list_display_nav = false;        // ee_map_nav_display
584
-        $default_map_settings->event_list_nav_size = true;            // ee_map_nav_size
585
-        $default_map_settings->event_list_control_type = 'dropdown';        // ee_map_type_control
586
-        $default_map_settings->event_list_map_align = 'center';            // ee_map_align
580
+        $default_map_settings->event_list_map_width = 300; // ee_map_width
581
+        $default_map_settings->event_list_map_height = 185; // ee_map_height
582
+        $default_map_settings->event_list_map_zoom = 12; // ee_map_zoom
583
+        $default_map_settings->event_list_display_nav = false; // ee_map_nav_display
584
+        $default_map_settings->event_list_nav_size = true; // ee_map_nav_size
585
+        $default_map_settings->event_list_control_type = 'dropdown'; // ee_map_type_control
586
+        $default_map_settings->event_list_map_align = 'center'; // ee_map_align
587 587
 
588 588
         $this->_template_args['map_settings'] =
589 589
             isset(EE_Registry::instance()->CFG->map_settings)
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
         $this->_set_add_edit_form_tags('update_google_map_settings');
598 598
         $this->_set_publish_post_box_vars(null, false, false, null, false);
599 599
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
600
-            EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
600
+            EE_VENUES_TEMPLATE_PATH.'google_map.template.php',
601 601
             $this->_template_args,
602 602
             true
603 603
         );
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
             ),
746 746
             'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
747 747
         );
748
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
748
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_gmap_metabox_content.template.php';
749 749
         EEH_Template::display_template($template, $template_args);
750 750
     }
751 751
 
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
             )
787 787
         );
788 788
 
789
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
789
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_address_metabox_content.template.php';
790 790
         EEH_Template::display_template($template, $template_args);
791 791
     }
792 792
 
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
         $template_args = array(
797 797
             '_venue' => $this->_cpt_model_obj,
798 798
         );
799
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
799
+        $template = EE_VENUES_TEMPLATE_PATH.'venue_virtual_location_metabox_content.template.php';
800 800
         EEH_Template::display_template($template, $template_args);
801 801
     }
802 802
 
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
     {
822 822
 
823 823
         if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
824
-            return;// get out we're not processing the saving of venues.
824
+            return; // get out we're not processing the saving of venues.
825 825
         }
826 826
 
827 827
         $wheres = array($this->_venue_model->primary_key_name() => $post_id);
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
             // clean status
930 930
             $venue_status = sanitize_key($venue_status);
931 931
             // grab status
932
-            if (! empty($venue_status)) {
932
+            if ( ! empty($venue_status)) {
933 933
                 $success = $this->_change_venue_status($VNU_ID, $venue_status);
934 934
             } else {
935 935
                 $success = false;
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
         // clean status
961 961
         $venue_status = sanitize_key($venue_status);
962 962
         // grab status
963
-        if (! empty($venue_status)) {
963
+        if ( ! empty($venue_status)) {
964 964
             $success = true;
965 965
             // determine the event id and set to array.
966 966
             $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array();
@@ -1011,7 +1011,7 @@  discard block
 block discarded – undo
1011 1011
     private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1012 1012
     {
1013 1013
         // grab venue id
1014
-        if (! $VNU_ID) {
1014
+        if ( ! $VNU_ID) {
1015 1015
             $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1016 1016
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1017 1017
             return false;
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
         // clean status
1023 1023
         $venue_status = sanitize_key($venue_status);
1024 1024
         // grab status
1025
-        if (! $venue_status) {
1025
+        if ( ! $venue_status) {
1026 1026
             $msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso');
1027 1027
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1028 1028
             return false;
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
     private function _delete_or_trash_venue($VNU_ID = false)
1121 1121
     {
1122 1122
         // grab event id
1123
-        if (! $VNU_ID = absint($VNU_ID)) {
1123
+        if ( ! $VNU_ID = absint($VNU_ID)) {
1124 1124
             $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1125 1125
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1126 1126
             return false;
@@ -1207,10 +1207,10 @@  discard block
 block discarded – undo
1207 1207
         }
1208 1208
 
1209 1209
 
1210
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1210
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1211 1211
             $where['VNU_wp_user'] = get_current_user_id();
1212 1212
         } else {
1213
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1213
+            if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1214 1214
                 $where['OR'] = array(
1215 1215
                     'status*restrict_private' => array('!=', 'private'),
1216 1216
                     'AND'                     => array(
@@ -1223,7 +1223,7 @@  discard block
 block discarded – undo
1223 1223
 
1224 1224
 
1225 1225
         if (isset($this->_req_data['s'])) {
1226
-            $sstr = '%' . $this->_req_data['s'] . '%';
1226
+            $sstr = '%'.$this->_req_data['s'].'%';
1227 1227
             $where['OR'] = array(
1228 1228
                 'VNU_name'               => array('LIKE', $sstr),
1229 1229
                 'VNU_desc'               => array('LIKE', $sstr),
@@ -1275,7 +1275,7 @@  discard block
 block discarded – undo
1275 1275
         $this->_set_empty_category_object();
1276 1276
 
1277 1277
         // only set if we've got an id
1278
-        if (! isset($this->_req_data['VEN_CAT_ID'])) {
1278
+        if ( ! isset($this->_req_data['VEN_CAT_ID'])) {
1279 1279
             return;
1280 1280
         }
1281 1281
 
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
         $term = get_term($category_id, 'espresso_venue_categories');
1284 1284
 
1285 1285
 
1286
-        if (! empty($term)) {
1286
+        if ( ! empty($term)) {
1287 1287
             $this->_category->category_name = $term->name;
1288 1288
             $this->_category->category_identifier = $term->slug;
1289 1289
             $this->_category->category_desc = $term->description;
@@ -1304,7 +1304,7 @@  discard block
 block discarded – undo
1304 1304
     protected function _category_list_table()
1305 1305
     {
1306 1306
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1307
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1307
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1308 1308
             'add_category',
1309 1309
             'add_category',
1310 1310
             array(),
@@ -1379,7 +1379,7 @@  discard block
 block discarded – undo
1379 1379
             'disable'                  => '',
1380 1380
             'disabled_message'         => false,
1381 1381
         );
1382
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1382
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
1383 1383
         return EEH_Template::display_template($template, $template_args, true);
1384 1384
     }
1385 1385
 
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
                 $term_args
1454 1454
             );
1455 1455
 
1456
-        if (! is_array($insert_ids)) {
1456
+        if ( ! is_array($insert_ids)) {
1457 1457
             $msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso');
1458 1458
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1459 1459
         } else {
@@ -1483,8 +1483,8 @@  discard block
 block discarded – undo
1483 1483
 
1484 1484
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
1485 1485
 
1486
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1487
-            require_once(EE_CLASSES . 'EE_Export.class.php');
1486
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
1487
+            require_once(EE_CLASSES.'EE_Export.class.php');
1488 1488
             $EE_Export = EE_Export::instance($this->_req_data);
1489 1489
             $EE_Export->export();
1490 1490
         }
@@ -1494,7 +1494,7 @@  discard block
 block discarded – undo
1494 1494
     protected function _import_categories()
1495 1495
     {
1496 1496
 
1497
-        require_once(EE_CLASSES . 'EE_Import.class.php');
1497
+        require_once(EE_CLASSES.'EE_Import.class.php');
1498 1498
         EE_Import::instance()->import();
1499 1499
     }
1500 1500
 
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
         $limit = ($current_page - 1) * $per_page;
1509 1509
         $where = array('taxonomy' => 'espresso_venue_categories');
1510 1510
         if (isset($this->_req_data['s'])) {
1511
-            $sstr = '%' . $this->_req_data['s'] . '%';
1511
+            $sstr = '%'.$this->_req_data['s'].'%';
1512 1512
             $where['OR'] = array(
1513 1513
                 'Term.name'   => array('LIKE', $sstr),
1514 1514
                 'description' => array('LIKE', $sstr),
@@ -1518,7 +1518,7 @@  discard block
 block discarded – undo
1518 1518
         $query_params = array(
1519 1519
             $where,
1520 1520
             'order_by'   => array($orderby => $order),
1521
-            'limit'      => $limit . ',' . $per_page,
1521
+            'limit'      => $limit.','.$per_page,
1522 1522
             'force_join' => array('Term'),
1523 1523
         );
1524 1524
 
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      *
343 343
      * @param $template
344 344
      * @param $template_args
345
-     * @return mixed
345
+     * @return string
346 346
      * @throws DomainException
347 347
      */
348 348
     public function add_additional_datetime_button($template, $template_args)
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
      *
361 361
      * @param $template
362 362
      * @param $template_args
363
-     * @return mixed
363
+     * @return string
364 364
      * @throws DomainException
365 365
      */
366 366
     public function add_datetime_clone_button($template, $template_args)
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
      *
379 379
      * @param $template
380 380
      * @param $template_args
381
-     * @return mixed
381
+     * @return string
382 382
      * @throws DomainException
383 383
      */
384 384
     public function datetime_timezones_template($template, $template_args)
Please login to merge, or discard this patch.
Indentation   +1253 added lines, -1253 removed lines patch added patch discarded remove patch
@@ -16,1257 +16,1257 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Extend_Events_Admin_Page constructor.
21
-     *
22
-     * @param bool $routing
23
-     */
24
-    public function __construct($routing = true)
25
-    {
26
-        parent::__construct($routing);
27
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
-        }
32
-    }
33
-
34
-
35
-    /**
36
-     * Sets routes.
37
-     */
38
-    protected function _extend_page_config()
39
-    {
40
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
41
-        // is there a evt_id in the request?
42
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
43
-            ? $this->_req_data['EVT_ID']
44
-            : 0;
45
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
46
-        // tkt_id?
47
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
48
-            ? $this->_req_data['TKT_ID']
49
-            : 0;
50
-        $new_page_routes = array(
51
-            'duplicate_event'          => array(
52
-                'func'       => '_duplicate_event',
53
-                'capability' => 'ee_edit_event',
54
-                'obj_id'     => $evt_id,
55
-                'noheader'   => true,
56
-            ),
57
-            'ticket_list_table'        => array(
58
-                'func'       => '_tickets_overview_list_table',
59
-                'capability' => 'ee_read_default_tickets',
60
-            ),
61
-            'trash_ticket'             => array(
62
-                'func'       => '_trash_or_restore_ticket',
63
-                'capability' => 'ee_delete_default_ticket',
64
-                'obj_id'     => $tkt_id,
65
-                'noheader'   => true,
66
-                'args'       => array('trash' => true),
67
-            ),
68
-            'trash_tickets'            => array(
69
-                'func'       => '_trash_or_restore_ticket',
70
-                'capability' => 'ee_delete_default_tickets',
71
-                'noheader'   => true,
72
-                'args'       => array('trash' => true),
73
-            ),
74
-            'restore_ticket'           => array(
75
-                'func'       => '_trash_or_restore_ticket',
76
-                'capability' => 'ee_delete_default_ticket',
77
-                'obj_id'     => $tkt_id,
78
-                'noheader'   => true,
79
-            ),
80
-            'restore_tickets'          => array(
81
-                'func'       => '_trash_or_restore_ticket',
82
-                'capability' => 'ee_delete_default_tickets',
83
-                'noheader'   => true,
84
-            ),
85
-            'delete_ticket'            => array(
86
-                'func'       => '_delete_ticket',
87
-                'capability' => 'ee_delete_default_ticket',
88
-                'obj_id'     => $tkt_id,
89
-                'noheader'   => true,
90
-            ),
91
-            'delete_tickets'           => array(
92
-                'func'       => '_delete_ticket',
93
-                'capability' => 'ee_delete_default_tickets',
94
-                'noheader'   => true,
95
-            ),
96
-            'import_page'              => array(
97
-                'func'       => '_import_page',
98
-                'capability' => 'import',
99
-            ),
100
-            'import'                   => array(
101
-                'func'       => '_import_events',
102
-                'capability' => 'import',
103
-                'noheader'   => true,
104
-            ),
105
-            'import_events'            => array(
106
-                'func'       => '_import_events',
107
-                'capability' => 'import',
108
-                'noheader'   => true,
109
-            ),
110
-            'export_events'            => array(
111
-                'func'       => '_events_export',
112
-                'capability' => 'export',
113
-                'noheader'   => true,
114
-            ),
115
-            'export_categories'        => array(
116
-                'func'       => '_categories_export',
117
-                'capability' => 'export',
118
-                'noheader'   => true,
119
-            ),
120
-            'sample_export_file'       => array(
121
-                'func'       => '_sample_export_file',
122
-                'capability' => 'export',
123
-                'noheader'   => true,
124
-            ),
125
-            'update_template_settings' => array(
126
-                'func'       => '_update_template_settings',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ),
130
-        );
131
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
132
-        // partial route/config override
133
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
134
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
135
-        $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
136
-        $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
137
-        $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
138
-        $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
139
-        // add tickets tab but only if there are more than one default ticket!
140
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
141
-            array(array('TKT_is_default' => 1)),
142
-            'TKT_ID',
143
-            true
144
-        );
145
-        if ($tkt_count > 1) {
146
-            $new_page_config = array(
147
-                'ticket_list_table' => array(
148
-                    'nav'           => array(
149
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
150
-                        'order' => 60,
151
-                    ),
152
-                    'list_table'    => 'Tickets_List_Table',
153
-                    'require_nonce' => false,
154
-                ),
155
-            );
156
-        }
157
-        // template settings
158
-        $new_page_config['template_settings'] = array(
159
-            'nav'           => array(
160
-                'label' => esc_html__('Templates', 'event_espresso'),
161
-                'order' => 30,
162
-            ),
163
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
164
-            'help_tabs'     => array(
165
-                'general_settings_templates_help_tab' => array(
166
-                    'title'    => esc_html__('Templates', 'event_espresso'),
167
-                    'filename' => 'general_settings_templates',
168
-                ),
169
-            ),
170
-            'help_tour'     => array('Templates_Help_Tour'),
171
-            'require_nonce' => false,
172
-        );
173
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
174
-        // add filters and actions
175
-        // modifying _views
176
-        add_filter(
177
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
178
-            array($this, 'add_additional_datetime_button'),
179
-            10,
180
-            2
181
-        );
182
-        add_filter(
183
-            'FHEE_event_datetime_metabox_clone_button_template',
184
-            array($this, 'add_datetime_clone_button'),
185
-            10,
186
-            2
187
-        );
188
-        add_filter(
189
-            'FHEE_event_datetime_metabox_timezones_template',
190
-            array($this, 'datetime_timezones_template'),
191
-            10,
192
-            2
193
-        );
194
-        // filters for event list table
195
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
196
-        add_filter(
197
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
198
-            array($this, 'extra_list_table_actions'),
199
-            10,
200
-            2
201
-        );
202
-        // legend item
203
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
204
-        add_action('admin_init', array($this, 'admin_init'));
205
-    }
206
-
207
-
208
-    /**
209
-     * admin_init
210
-     */
211
-    public function admin_init()
212
-    {
213
-        EE_Registry::$i18n_js_strings = array_merge(
214
-            EE_Registry::$i18n_js_strings,
215
-            array(
216
-                'image_confirm'          => esc_html__(
217
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
218
-                    'event_espresso'
219
-                ),
220
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
221
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
222
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
223
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
224
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
225
-            )
226
-        );
227
-    }
228
-
229
-
230
-    /**
231
-     * Add per page screen options to the default ticket list table view.
232
-     */
233
-    protected function _add_screen_options_ticket_list_table()
234
-    {
235
-        $this->_per_page_screen_option();
236
-    }
237
-
238
-
239
-    /**
240
-     * @param string $return
241
-     * @param int    $id
242
-     * @param string $new_title
243
-     * @param string $new_slug
244
-     * @return string
245
-     */
246
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
247
-    {
248
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
249
-        // make sure this is only when editing
250
-        if (! empty($id)) {
251
-            $href = EE_Admin_Page::add_query_args_and_nonce(
252
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
253
-                $this->_admin_base_url
254
-            );
255
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
256
-            $return .= '<a href="'
257
-                       . $href
258
-                       . '" title="'
259
-                       . $title
260
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
261
-                       . $title
262
-                       . '</a>';
263
-        }
264
-        return $return;
265
-    }
266
-
267
-
268
-    /**
269
-     * Set the list table views for the default ticket list table view.
270
-     */
271
-    public function _set_list_table_views_ticket_list_table()
272
-    {
273
-        $this->_views = array(
274
-            'all'     => array(
275
-                'slug'        => 'all',
276
-                'label'       => esc_html__('All', 'event_espresso'),
277
-                'count'       => 0,
278
-                'bulk_action' => array(
279
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
280
-                ),
281
-            ),
282
-            'trashed' => array(
283
-                'slug'        => 'trashed',
284
-                'label'       => esc_html__('Trash', 'event_espresso'),
285
-                'count'       => 0,
286
-                'bulk_action' => array(
287
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
288
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
289
-                ),
290
-            ),
291
-        );
292
-    }
293
-
294
-
295
-    /**
296
-     * Enqueue scripts and styles for the event editor.
297
-     */
298
-    public function load_scripts_styles_edit()
299
-    {
300
-        wp_register_script(
301
-            'ee-event-editor-heartbeat',
302
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
303
-            array('ee_admin_js', 'heartbeat'),
304
-            EVENT_ESPRESSO_VERSION,
305
-            true
306
-        );
307
-        wp_enqueue_script('ee-accounting');
308
-        // styles
309
-        wp_enqueue_style('espresso-ui-theme');
310
-        wp_enqueue_script('event_editor_js');
311
-        wp_enqueue_script('ee-event-editor-heartbeat');
312
-    }
313
-
314
-
315
-    /**
316
-     * Returns template for the additional datetime.
317
-     *
318
-     * @param $template
319
-     * @param $template_args
320
-     * @return mixed
321
-     * @throws DomainException
322
-     */
323
-    public function add_additional_datetime_button($template, $template_args)
324
-    {
325
-        return EEH_Template::display_template(
326
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
327
-            $template_args,
328
-            true
329
-        );
330
-    }
331
-
332
-
333
-    /**
334
-     * Returns the template for cloning a datetime.
335
-     *
336
-     * @param $template
337
-     * @param $template_args
338
-     * @return mixed
339
-     * @throws DomainException
340
-     */
341
-    public function add_datetime_clone_button($template, $template_args)
342
-    {
343
-        return EEH_Template::display_template(
344
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
345
-            $template_args,
346
-            true
347
-        );
348
-    }
349
-
350
-
351
-    /**
352
-     * Returns the template for datetime timezones.
353
-     *
354
-     * @param $template
355
-     * @param $template_args
356
-     * @return mixed
357
-     * @throws DomainException
358
-     */
359
-    public function datetime_timezones_template($template, $template_args)
360
-    {
361
-        return EEH_Template::display_template(
362
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
363
-            $template_args,
364
-            true
365
-        );
366
-    }
367
-
368
-
369
-    /**
370
-     * Sets the views for the default list table view.
371
-     */
372
-    protected function _set_list_table_views_default()
373
-    {
374
-        parent::_set_list_table_views_default();
375
-        $new_views = array(
376
-            'today' => array(
377
-                'slug'        => 'today',
378
-                'label'       => esc_html__('Today', 'event_espresso'),
379
-                'count'       => $this->total_events_today(),
380
-                'bulk_action' => array(
381
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
382
-                ),
383
-            ),
384
-            'month' => array(
385
-                'slug'        => 'month',
386
-                'label'       => esc_html__('This Month', 'event_espresso'),
387
-                'count'       => $this->total_events_this_month(),
388
-                'bulk_action' => array(
389
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
390
-                ),
391
-            ),
392
-        );
393
-        $this->_views = array_merge($this->_views, $new_views);
394
-    }
395
-
396
-
397
-    /**
398
-     * Returns the extra action links for the default list table view.
399
-     *
400
-     * @param array     $action_links
401
-     * @param \EE_Event $event
402
-     * @return array
403
-     * @throws EE_Error
404
-     */
405
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
406
-    {
407
-        if (EE_Registry::instance()->CAP->current_user_can(
408
-            'ee_read_registrations',
409
-            'espresso_registrations_reports',
410
-            $event->ID()
411
-        )
412
-        ) {
413
-            $reports_query_args = array(
414
-                'action' => 'reports',
415
-                'EVT_ID' => $event->ID(),
416
-            );
417
-            $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
418
-            $action_links[] = '<a href="'
419
-                              . $reports_link
420
-                              . '" title="'
421
-                              . esc_attr__('View Report', 'event_espresso')
422
-                              . '"><div class="dashicons dashicons-chart-bar"></div></a>'
423
-                              . "\n\t";
424
-        }
425
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
426
-            EE_Registry::instance()->load_helper('MSG_Template');
427
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
428
-                'see_notifications_for',
429
-                null,
430
-                array('EVT_ID' => $event->ID())
431
-            );
432
-        }
433
-        return $action_links;
434
-    }
435
-
436
-
437
-    /**
438
-     * @param $items
439
-     * @return mixed
440
-     */
441
-    public function additional_legend_items($items)
442
-    {
443
-        if (EE_Registry::instance()->CAP->current_user_can(
444
-            'ee_read_registrations',
445
-            'espresso_registrations_reports'
446
-        )
447
-        ) {
448
-            $items['reports'] = array(
449
-                'class' => 'dashicons dashicons-chart-bar',
450
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
451
-            );
452
-        }
453
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
454
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
455
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
456
-                $items['view_related_messages'] = array(
457
-                    'class' => $related_for_icon['css_class'],
458
-                    'desc'  => $related_for_icon['label'],
459
-                );
460
-            }
461
-        }
462
-        return $items;
463
-    }
464
-
465
-
466
-    /**
467
-     * This is the callback method for the duplicate event route
468
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
469
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
470
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
471
-     * After duplication the redirect is to the new event edit page.
472
-     *
473
-     * @return void
474
-     * @access protected
475
-     * @throws EE_Error If EE_Event is not available with given ID
476
-     */
477
-    protected function _duplicate_event()
478
-    {
479
-        // first make sure the ID for the event is in the request.
480
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
481
-        if (! isset($this->_req_data['EVT_ID'])) {
482
-            EE_Error::add_error(
483
-                esc_html__(
484
-                    'In order to duplicate an event an Event ID is required.  None was given.',
485
-                    'event_espresso'
486
-                ),
487
-                __FILE__,
488
-                __FUNCTION__,
489
-                __LINE__
490
-            );
491
-            $this->_redirect_after_action(false, '', '', array(), true);
492
-            return;
493
-        }
494
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
495
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
496
-        if (! $orig_event instanceof EE_Event) {
497
-            throw new EE_Error(
498
-                sprintf(
499
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
500
-                    $this->_req_data['EVT_ID']
501
-                )
502
-            );
503
-        }
504
-        // k now let's clone the $orig_event before getting relations
505
-        $new_event = clone $orig_event;
506
-        // original datetimes
507
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
508
-        // other original relations
509
-        $orig_ven = $orig_event->get_many_related('Venue');
510
-        // reset the ID and modify other details to make it clear this is a dupe
511
-        $new_event->set('EVT_ID', 0);
512
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
513
-        $new_event->set('EVT_name', $new_name);
514
-        $new_event->set(
515
-            'EVT_slug',
516
-            wp_unique_post_slug(
517
-                sanitize_title($orig_event->name()),
518
-                0,
519
-                'publish',
520
-                'espresso_events',
521
-                0
522
-            )
523
-        );
524
-        $new_event->set('status', 'draft');
525
-        // duplicate discussion settings
526
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
527
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
528
-        // save the new event
529
-        $new_event->save();
530
-        // venues
531
-        foreach ($orig_ven as $ven) {
532
-            $new_event->_add_relation_to($ven, 'Venue');
533
-        }
534
-        $new_event->save();
535
-        // now we need to get the question group relations and handle that
536
-        // first primary question groups
537
-        $orig_primary_qgs = $orig_event->get_many_related(
538
-            'Question_Group',
539
-            array(array('Event_Question_Group.EQG_primary' => 1))
540
-        );
541
-        if (! empty($orig_primary_qgs)) {
542
-            foreach ($orig_primary_qgs as $id => $obj) {
543
-                if ($obj instanceof EE_Question_Group) {
544
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
545
-                }
546
-            }
547
-        }
548
-        // next additional attendee question groups
549
-        $orig_additional_qgs = $orig_event->get_many_related(
550
-            'Question_Group',
551
-            array(array('Event_Question_Group.EQG_primary' => 0))
552
-        );
553
-        if (! empty($orig_additional_qgs)) {
554
-            foreach ($orig_additional_qgs as $id => $obj) {
555
-                if ($obj instanceof EE_Question_Group) {
556
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
557
-                }
558
-            }
559
-        }
560
-
561
-        $new_event->save();
562
-
563
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
564
-        $cloned_tickets = array();
565
-        foreach ($orig_datetimes as $orig_dtt) {
566
-            if (! $orig_dtt instanceof EE_Datetime) {
567
-                continue;
568
-            }
569
-            $new_dtt = clone $orig_dtt;
570
-            $orig_tkts = $orig_dtt->tickets();
571
-            // save new dtt then add to event
572
-            $new_dtt->set('DTT_ID', 0);
573
-            $new_dtt->set('DTT_sold', 0);
574
-            $new_dtt->set_reserved(0);
575
-            $new_dtt->save();
576
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
577
-            $new_event->save();
578
-            // now let's get the ticket relations setup.
579
-            foreach ((array) $orig_tkts as $orig_tkt) {
580
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
581
-                if (! $orig_tkt instanceof EE_Ticket) {
582
-                    continue;
583
-                }
584
-                // is this ticket archived?  If it is then let's skip
585
-                if ($orig_tkt->get('TKT_deleted')) {
586
-                    continue;
587
-                }
588
-                // does this original ticket already exist in the clone_tickets cache?
589
-                //  If so we'll just use the new ticket from it.
590
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
591
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
592
-                } else {
593
-                    $new_tkt = clone $orig_tkt;
594
-                    // get relations on the $orig_tkt that we need to setup.
595
-                    $orig_prices = $orig_tkt->prices();
596
-                    $new_tkt->set('TKT_ID', 0);
597
-                    $new_tkt->set('TKT_sold', 0);
598
-                    $new_tkt->set('TKT_reserved', 0);
599
-                    $new_tkt->save(); // make sure new ticket has ID.
600
-                    // price relations on new ticket need to be setup.
601
-                    foreach ($orig_prices as $orig_price) {
602
-                        $new_price = clone $orig_price;
603
-                        $new_price->set('PRC_ID', 0);
604
-                        $new_price->save();
605
-                        $new_tkt->_add_relation_to($new_price, 'Price');
606
-                        $new_tkt->save();
607
-                    }
608
-
609
-                    do_action(
610
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
611
-                        $orig_tkt,
612
-                        $new_tkt,
613
-                        $orig_prices,
614
-                        $orig_event,
615
-                        $orig_dtt,
616
-                        $new_dtt
617
-                    );
618
-                }
619
-                // k now we can add the new ticket as a relation to the new datetime
620
-                // and make sure its added to our cached $cloned_tickets array
621
-                // for use with later datetimes that have the same ticket.
622
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
623
-                $new_dtt->save();
624
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
625
-            }
626
-        }
627
-        // clone taxonomy information
628
-        $taxonomies_to_clone_with = apply_filters(
629
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
630
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
631
-        );
632
-        // get terms for original event (notice)
633
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
634
-        // loop through terms and add them to new event.
635
-        foreach ($orig_terms as $term) {
636
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
637
-        }
638
-
639
-        // duplicate other core WP_Post items for this event.
640
-        // post thumbnail (feature image).
641
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
642
-        if ($feature_image_id) {
643
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
644
-        }
645
-
646
-        // duplicate page_template setting
647
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
648
-        if ($page_template) {
649
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
650
-        }
651
-
652
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
653
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
654
-        if ($new_event->ID()) {
655
-            $redirect_args = array(
656
-                'post'   => $new_event->ID(),
657
-                'action' => 'edit',
658
-            );
659
-            EE_Error::add_success(
660
-                esc_html__(
661
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
662
-                    'event_espresso'
663
-                )
664
-            );
665
-        } else {
666
-            $redirect_args = array(
667
-                'action' => 'default',
668
-            );
669
-            EE_Error::add_error(
670
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
671
-                __FILE__,
672
-                __FUNCTION__,
673
-                __LINE__
674
-            );
675
-        }
676
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
677
-    }
678
-
679
-
680
-    /**
681
-     * Generates output for the import page.
682
-     *
683
-     * @throws DomainException
684
-     */
685
-    protected function _import_page()
686
-    {
687
-        $title = esc_html__('Import', 'event_espresso');
688
-        $intro = esc_html__(
689
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
690
-            'event_espresso'
691
-        );
692
-        $form_url = EVENTS_ADMIN_URL;
693
-        $action = 'import_events';
694
-        $type = 'csv';
695
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
696
-            $title,
697
-            $intro,
698
-            $form_url,
699
-            $action,
700
-            $type
701
-        );
702
-        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
703
-            array('action' => 'sample_export_file'),
704
-            $this->_admin_base_url
705
-        );
706
-        $content = EEH_Template::display_template(
707
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
708
-            $this->_template_args,
709
-            true
710
-        );
711
-        $this->_template_args['admin_page_content'] = $content;
712
-        $this->display_admin_page_with_sidebar();
713
-    }
714
-
715
-
716
-    /**
717
-     * _import_events
718
-     * This handles displaying the screen and running imports for importing events.
719
-     *
720
-     * @return void
721
-     */
722
-    protected function _import_events()
723
-    {
724
-        require_once(EE_CLASSES . 'EE_Import.class.php');
725
-        $success = EE_Import::instance()->import();
726
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
727
-    }
728
-
729
-
730
-    /**
731
-     * _events_export
732
-     * Will export all (or just the given event) to a Excel compatible file.
733
-     *
734
-     * @access protected
735
-     * @return void
736
-     */
737
-    protected function _events_export()
738
-    {
739
-        if (isset($this->_req_data['EVT_ID'])) {
740
-            $event_ids = $this->_req_data['EVT_ID'];
741
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
742
-            $event_ids = $this->_req_data['EVT_IDs'];
743
-        } else {
744
-            $event_ids = null;
745
-        }
746
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
747
-        $new_request_args = array(
748
-            'export' => 'report',
749
-            'action' => 'all_event_data',
750
-            'EVT_ID' => $event_ids,
751
-        );
752
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
753
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
754
-            require_once(EE_CLASSES . 'EE_Export.class.php');
755
-            $EE_Export = EE_Export::instance($this->_req_data);
756
-            $EE_Export->export();
757
-        }
758
-    }
759
-
760
-
761
-    /**
762
-     * handle category exports()
763
-     *
764
-     * @return void
765
-     */
766
-    protected function _categories_export()
767
-    {
768
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
769
-        $new_request_args = array(
770
-            'export'       => 'report',
771
-            'action'       => 'categories',
772
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
773
-        );
774
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
775
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
776
-            require_once(EE_CLASSES . 'EE_Export.class.php');
777
-            $EE_Export = EE_Export::instance($this->_req_data);
778
-            $EE_Export->export();
779
-        }
780
-    }
781
-
782
-
783
-    /**
784
-     * Creates a sample CSV file for importing
785
-     */
786
-    protected function _sample_export_file()
787
-    {
788
-        // require_once(EE_CLASSES . 'EE_Export.class.php');
789
-        EE_Export::instance()->export_sample();
790
-    }
791
-
792
-
793
-    /*************        Template Settings        *************/
794
-    /**
795
-     * Generates template settings page output
796
-     *
797
-     * @throws DomainException
798
-     * @throws EE_Error
799
-     */
800
-    protected function _template_settings()
801
-    {
802
-        $this->_template_args['values'] = $this->_yes_no_values;
803
-        /**
804
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
805
-         * from General_Settings_Admin_Page to here.
806
-         */
807
-        $this->_template_args = apply_filters(
808
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
809
-            $this->_template_args
810
-        );
811
-        $this->_set_add_edit_form_tags('update_template_settings');
812
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
813
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
814
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
815
-            $this->_template_args,
816
-            true
817
-        );
818
-        $this->display_admin_page_with_sidebar();
819
-    }
820
-
821
-
822
-    /**
823
-     * Handler for updating template settings.
824
-     *
825
-     * @throws InvalidInterfaceException
826
-     * @throws InvalidDataTypeException
827
-     * @throws InvalidArgumentException
828
-     */
829
-    protected function _update_template_settings()
830
-    {
831
-        /**
832
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
833
-         * from General_Settings_Admin_Page to here.
834
-         */
835
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
836
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
837
-            EE_Registry::instance()->CFG->template_settings,
838
-            $this->_req_data
839
-        );
840
-        // update custom post type slugs and detect if we need to flush rewrite rules
841
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
842
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
843
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
844
-            : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
845
-        $what = 'Template Settings';
846
-        $success = $this->_update_espresso_configuration(
847
-            $what,
848
-            EE_Registry::instance()->CFG->template_settings,
849
-            __FILE__,
850
-            __FUNCTION__,
851
-            __LINE__
852
-        );
853
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
854
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
855
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
856
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
857
-            );
858
-            $rewrite_rules->flush();
859
-        }
860
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
861
-    }
862
-
863
-
864
-    /**
865
-     * _premium_event_editor_meta_boxes
866
-     * add all metaboxes related to the event_editor
867
-     *
868
-     * @access protected
869
-     * @return void
870
-     * @throws EE_Error
871
-     */
872
-    protected function _premium_event_editor_meta_boxes()
873
-    {
874
-        $this->verify_cpt_object();
875
-        add_meta_box(
876
-            'espresso_event_editor_event_options',
877
-            esc_html__('Event Registration Options', 'event_espresso'),
878
-            array($this, 'registration_options_meta_box'),
879
-            $this->page_slug,
880
-            'side',
881
-            'core'
882
-        );
883
-    }
884
-
885
-
886
-    /**
887
-     * override caf metabox
888
-     *
889
-     * @return void
890
-     * @throws DomainException
891
-     */
892
-    public function registration_options_meta_box()
893
-    {
894
-        $yes_no_values = array(
895
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
896
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
897
-        );
898
-        $default_reg_status_values = EEM_Registration::reg_status_array(
899
-            array(
900
-                EEM_Registration::status_id_cancelled,
901
-                EEM_Registration::status_id_declined,
902
-                EEM_Registration::status_id_incomplete,
903
-                EEM_Registration::status_id_wait_list,
904
-            ),
905
-            true
906
-        );
907
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
908
-        $template_args['_event'] = $this->_cpt_model_obj;
909
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
910
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
911
-            'default_reg_status',
912
-            $default_reg_status_values,
913
-            $this->_cpt_model_obj->default_registration_status()
914
-        );
915
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
916
-            'display_desc',
917
-            $yes_no_values,
918
-            $this->_cpt_model_obj->display_description()
919
-        );
920
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
921
-            'display_ticket_selector',
922
-            $yes_no_values,
923
-            $this->_cpt_model_obj->display_ticket_selector(),
924
-            '',
925
-            '',
926
-            false
927
-        );
928
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
929
-            'EVT_default_registration_status',
930
-            $default_reg_status_values,
931
-            $this->_cpt_model_obj->default_registration_status()
932
-        );
933
-        $template_args['additional_registration_options'] = apply_filters(
934
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
935
-            '',
936
-            $template_args,
937
-            $yes_no_values,
938
-            $default_reg_status_values
939
-        );
940
-        EEH_Template::display_template(
941
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
942
-            $template_args
943
-        );
944
-    }
945
-
946
-
947
-
948
-    /**
949
-     * wp_list_table_mods for caf
950
-     * ============================
951
-     */
952
-    /**
953
-     * hook into list table filters and provide filters for caffeinated list table
954
-     *
955
-     * @param  array $old_filters    any existing filters present
956
-     * @param  array $list_table_obj the list table object
957
-     * @return array                  new filters
958
-     */
959
-    public function list_table_filters($old_filters, $list_table_obj)
960
-    {
961
-        $filters = array();
962
-        // first month/year filters
963
-        $filters[] = $this->espresso_event_months_dropdown();
964
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
965
-        // active status dropdown
966
-        if ($status !== 'draft') {
967
-            $filters[] = $this->active_status_dropdown(
968
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
969
-            );
970
-        }
971
-        // category filter
972
-        $filters[] = $this->category_dropdown();
973
-        return array_merge($old_filters, $filters);
974
-    }
975
-
976
-
977
-    /**
978
-     * espresso_event_months_dropdown
979
-     *
980
-     * @access public
981
-     * @return string                dropdown listing month/year selections for events.
982
-     */
983
-    public function espresso_event_months_dropdown()
984
-    {
985
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
986
-        // Note we need to include any other filters that are set!
987
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
988
-        // categories?
989
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
990
-            ? $this->_req_data['EVT_CAT']
991
-            : null;
992
-        // active status?
993
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
994
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
995
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
996
-    }
997
-
998
-
999
-    /**
1000
-     * returns a list of "active" statuses on the event
1001
-     *
1002
-     * @param  string $current_value whatever the current active status is
1003
-     * @return string
1004
-     */
1005
-    public function active_status_dropdown($current_value = '')
1006
-    {
1007
-        $select_name = 'active_status';
1008
-        $values = array(
1009
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1010
-            'active'   => esc_html__('Active', 'event_espresso'),
1011
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1012
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1013
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1014
-        );
1015
-        $id = 'id="espresso-active-status-dropdown-filter"';
1016
-        $class = 'wide';
1017
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * output a dropdown of the categories for the category filter on the event admin list table
1023
-     *
1024
-     * @access  public
1025
-     * @return string html
1026
-     */
1027
-    public function category_dropdown()
1028
-    {
1029
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1030
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1031
-    }
1032
-
1033
-
1034
-    /**
1035
-     * get total number of events today
1036
-     *
1037
-     * @access public
1038
-     * @return int
1039
-     * @throws EE_Error
1040
-     */
1041
-    public function total_events_today()
1042
-    {
1043
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1044
-            'DTT_EVT_start',
1045
-            date('Y-m-d') . ' 00:00:00',
1046
-            'Y-m-d H:i:s',
1047
-            'UTC'
1048
-        );
1049
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1050
-            'DTT_EVT_start',
1051
-            date('Y-m-d') . ' 23:59:59',
1052
-            'Y-m-d H:i:s',
1053
-            'UTC'
1054
-        );
1055
-        $where = array(
1056
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1057
-        );
1058
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1059
-        return $count;
1060
-    }
1061
-
1062
-
1063
-    /**
1064
-     * get total number of events this month
1065
-     *
1066
-     * @access public
1067
-     * @return int
1068
-     * @throws EE_Error
1069
-     */
1070
-    public function total_events_this_month()
1071
-    {
1072
-        // Dates
1073
-        $this_year_r = date('Y');
1074
-        $this_month_r = date('m');
1075
-        $days_this_month = date('t');
1076
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1077
-            'DTT_EVT_start',
1078
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1079
-            'Y-m-d H:i:s',
1080
-            'UTC'
1081
-        );
1082
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1083
-            'DTT_EVT_start',
1084
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1085
-            'Y-m-d H:i:s',
1086
-            'UTC'
1087
-        );
1088
-        $where = array(
1089
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1090
-        );
1091
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1092
-        return $count;
1093
-    }
1094
-
1095
-
1096
-    /** DEFAULT TICKETS STUFF **/
1097
-
1098
-    /**
1099
-     * Output default tickets list table view.
1100
-     */
1101
-    public function _tickets_overview_list_table()
1102
-    {
1103
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1104
-        $this->display_admin_list_table_page_with_no_sidebar();
1105
-    }
1106
-
1107
-
1108
-    /**
1109
-     * @param int  $per_page
1110
-     * @param bool $count
1111
-     * @param bool $trashed
1112
-     * @return \EE_Soft_Delete_Base_Class[]|int
1113
-     */
1114
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1115
-    {
1116
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1117
-        $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1118
-        switch ($orderby) {
1119
-            case 'TKT_name':
1120
-                $orderby = array('TKT_name' => $order);
1121
-                break;
1122
-            case 'TKT_price':
1123
-                $orderby = array('TKT_price' => $order);
1124
-                break;
1125
-            case 'TKT_uses':
1126
-                $orderby = array('TKT_uses' => $order);
1127
-                break;
1128
-            case 'TKT_min':
1129
-                $orderby = array('TKT_min' => $order);
1130
-                break;
1131
-            case 'TKT_max':
1132
-                $orderby = array('TKT_max' => $order);
1133
-                break;
1134
-            case 'TKT_qty':
1135
-                $orderby = array('TKT_qty' => $order);
1136
-                break;
1137
-        }
1138
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1139
-            ? $this->_req_data['paged']
1140
-            : 1;
1141
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1142
-            ? $this->_req_data['perpage']
1143
-            : $per_page;
1144
-        $_where = array(
1145
-            'TKT_is_default' => 1,
1146
-            'TKT_deleted'    => $trashed,
1147
-        );
1148
-        $offset = ($current_page - 1) * $per_page;
1149
-        $limit = array($offset, $per_page);
1150
-        if (isset($this->_req_data['s'])) {
1151
-            $sstr = '%' . $this->_req_data['s'] . '%';
1152
-            $_where['OR'] = array(
1153
-                'TKT_name'        => array('LIKE', $sstr),
1154
-                'TKT_description' => array('LIKE', $sstr),
1155
-            );
1156
-        }
1157
-        $query_params = array(
1158
-            $_where,
1159
-            'order_by' => $orderby,
1160
-            'limit'    => $limit,
1161
-            'group_by' => 'TKT_ID',
1162
-        );
1163
-        if ($count) {
1164
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1165
-        } else {
1166
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1167
-        }
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     * @param bool $trash
1173
-     * @throws EE_Error
1174
-     */
1175
-    protected function _trash_or_restore_ticket($trash = false)
1176
-    {
1177
-        $success = 1;
1178
-        $TKT = EEM_Ticket::instance();
1179
-        // checkboxes?
1180
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1181
-            // if array has more than one element then success message should be plural
1182
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1183
-            // cycle thru the boxes
1184
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1185
-                if ($trash) {
1186
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1187
-                        $success = 0;
1188
-                    }
1189
-                } else {
1190
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1191
-                        $success = 0;
1192
-                    }
1193
-                }
1194
-            }
1195
-        } else {
1196
-            // grab single id and trash
1197
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1198
-            if ($trash) {
1199
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1200
-                    $success = 0;
1201
-                }
1202
-            } else {
1203
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1204
-                    $success = 0;
1205
-                }
1206
-            }
1207
-        }
1208
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1209
-        $query_args = array(
1210
-            'action' => 'ticket_list_table',
1211
-            'status' => $trash ? '' : 'trashed',
1212
-        );
1213
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     * Handles trashing default ticket.
1219
-     */
1220
-    protected function _delete_ticket()
1221
-    {
1222
-        $success = 1;
1223
-        // checkboxes?
1224
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1225
-            // if array has more than one element then success message should be plural
1226
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1227
-            // cycle thru the boxes
1228
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1229
-                // delete
1230
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1231
-                    $success = 0;
1232
-                }
1233
-            }
1234
-        } else {
1235
-            // grab single id and trash
1236
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1237
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1238
-                $success = 0;
1239
-            }
1240
-        }
1241
-        $action_desc = 'deleted';
1242
-        $query_args = array(
1243
-            'action' => 'ticket_list_table',
1244
-            'status' => 'trashed',
1245
-        );
1246
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1247
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1248
-            array(array('TKT_is_default' => 1)),
1249
-            'TKT_ID',
1250
-            true
1251
-        )
1252
-        ) {
1253
-            $query_args = array();
1254
-        }
1255
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1256
-    }
1257
-
1258
-
1259
-    /**
1260
-     * @param int $TKT_ID
1261
-     * @return bool|int
1262
-     * @throws EE_Error
1263
-     */
1264
-    protected function _delete_the_ticket($TKT_ID)
1265
-    {
1266
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1267
-        $tkt->_remove_relations('Datetime');
1268
-        // delete all related prices first
1269
-        $tkt->delete_related_permanently('Price');
1270
-        return $tkt->delete_permanently();
1271
-    }
19
+	/**
20
+	 * Extend_Events_Admin_Page constructor.
21
+	 *
22
+	 * @param bool $routing
23
+	 */
24
+	public function __construct($routing = true)
25
+	{
26
+		parent::__construct($routing);
27
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
+		}
32
+	}
33
+
34
+
35
+	/**
36
+	 * Sets routes.
37
+	 */
38
+	protected function _extend_page_config()
39
+	{
40
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
41
+		// is there a evt_id in the request?
42
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
43
+			? $this->_req_data['EVT_ID']
44
+			: 0;
45
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
46
+		// tkt_id?
47
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
48
+			? $this->_req_data['TKT_ID']
49
+			: 0;
50
+		$new_page_routes = array(
51
+			'duplicate_event'          => array(
52
+				'func'       => '_duplicate_event',
53
+				'capability' => 'ee_edit_event',
54
+				'obj_id'     => $evt_id,
55
+				'noheader'   => true,
56
+			),
57
+			'ticket_list_table'        => array(
58
+				'func'       => '_tickets_overview_list_table',
59
+				'capability' => 'ee_read_default_tickets',
60
+			),
61
+			'trash_ticket'             => array(
62
+				'func'       => '_trash_or_restore_ticket',
63
+				'capability' => 'ee_delete_default_ticket',
64
+				'obj_id'     => $tkt_id,
65
+				'noheader'   => true,
66
+				'args'       => array('trash' => true),
67
+			),
68
+			'trash_tickets'            => array(
69
+				'func'       => '_trash_or_restore_ticket',
70
+				'capability' => 'ee_delete_default_tickets',
71
+				'noheader'   => true,
72
+				'args'       => array('trash' => true),
73
+			),
74
+			'restore_ticket'           => array(
75
+				'func'       => '_trash_or_restore_ticket',
76
+				'capability' => 'ee_delete_default_ticket',
77
+				'obj_id'     => $tkt_id,
78
+				'noheader'   => true,
79
+			),
80
+			'restore_tickets'          => array(
81
+				'func'       => '_trash_or_restore_ticket',
82
+				'capability' => 'ee_delete_default_tickets',
83
+				'noheader'   => true,
84
+			),
85
+			'delete_ticket'            => array(
86
+				'func'       => '_delete_ticket',
87
+				'capability' => 'ee_delete_default_ticket',
88
+				'obj_id'     => $tkt_id,
89
+				'noheader'   => true,
90
+			),
91
+			'delete_tickets'           => array(
92
+				'func'       => '_delete_ticket',
93
+				'capability' => 'ee_delete_default_tickets',
94
+				'noheader'   => true,
95
+			),
96
+			'import_page'              => array(
97
+				'func'       => '_import_page',
98
+				'capability' => 'import',
99
+			),
100
+			'import'                   => array(
101
+				'func'       => '_import_events',
102
+				'capability' => 'import',
103
+				'noheader'   => true,
104
+			),
105
+			'import_events'            => array(
106
+				'func'       => '_import_events',
107
+				'capability' => 'import',
108
+				'noheader'   => true,
109
+			),
110
+			'export_events'            => array(
111
+				'func'       => '_events_export',
112
+				'capability' => 'export',
113
+				'noheader'   => true,
114
+			),
115
+			'export_categories'        => array(
116
+				'func'       => '_categories_export',
117
+				'capability' => 'export',
118
+				'noheader'   => true,
119
+			),
120
+			'sample_export_file'       => array(
121
+				'func'       => '_sample_export_file',
122
+				'capability' => 'export',
123
+				'noheader'   => true,
124
+			),
125
+			'update_template_settings' => array(
126
+				'func'       => '_update_template_settings',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			),
130
+		);
131
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
132
+		// partial route/config override
133
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
134
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
135
+		$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
136
+		$this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
137
+		$this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
138
+		$this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
139
+		// add tickets tab but only if there are more than one default ticket!
140
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
141
+			array(array('TKT_is_default' => 1)),
142
+			'TKT_ID',
143
+			true
144
+		);
145
+		if ($tkt_count > 1) {
146
+			$new_page_config = array(
147
+				'ticket_list_table' => array(
148
+					'nav'           => array(
149
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
150
+						'order' => 60,
151
+					),
152
+					'list_table'    => 'Tickets_List_Table',
153
+					'require_nonce' => false,
154
+				),
155
+			);
156
+		}
157
+		// template settings
158
+		$new_page_config['template_settings'] = array(
159
+			'nav'           => array(
160
+				'label' => esc_html__('Templates', 'event_espresso'),
161
+				'order' => 30,
162
+			),
163
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
164
+			'help_tabs'     => array(
165
+				'general_settings_templates_help_tab' => array(
166
+					'title'    => esc_html__('Templates', 'event_espresso'),
167
+					'filename' => 'general_settings_templates',
168
+				),
169
+			),
170
+			'help_tour'     => array('Templates_Help_Tour'),
171
+			'require_nonce' => false,
172
+		);
173
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
174
+		// add filters and actions
175
+		// modifying _views
176
+		add_filter(
177
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
178
+			array($this, 'add_additional_datetime_button'),
179
+			10,
180
+			2
181
+		);
182
+		add_filter(
183
+			'FHEE_event_datetime_metabox_clone_button_template',
184
+			array($this, 'add_datetime_clone_button'),
185
+			10,
186
+			2
187
+		);
188
+		add_filter(
189
+			'FHEE_event_datetime_metabox_timezones_template',
190
+			array($this, 'datetime_timezones_template'),
191
+			10,
192
+			2
193
+		);
194
+		// filters for event list table
195
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
196
+		add_filter(
197
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
198
+			array($this, 'extra_list_table_actions'),
199
+			10,
200
+			2
201
+		);
202
+		// legend item
203
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
204
+		add_action('admin_init', array($this, 'admin_init'));
205
+	}
206
+
207
+
208
+	/**
209
+	 * admin_init
210
+	 */
211
+	public function admin_init()
212
+	{
213
+		EE_Registry::$i18n_js_strings = array_merge(
214
+			EE_Registry::$i18n_js_strings,
215
+			array(
216
+				'image_confirm'          => esc_html__(
217
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
218
+					'event_espresso'
219
+				),
220
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
221
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
222
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
223
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
224
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
225
+			)
226
+		);
227
+	}
228
+
229
+
230
+	/**
231
+	 * Add per page screen options to the default ticket list table view.
232
+	 */
233
+	protected function _add_screen_options_ticket_list_table()
234
+	{
235
+		$this->_per_page_screen_option();
236
+	}
237
+
238
+
239
+	/**
240
+	 * @param string $return
241
+	 * @param int    $id
242
+	 * @param string $new_title
243
+	 * @param string $new_slug
244
+	 * @return string
245
+	 */
246
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
247
+	{
248
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
249
+		// make sure this is only when editing
250
+		if (! empty($id)) {
251
+			$href = EE_Admin_Page::add_query_args_and_nonce(
252
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
253
+				$this->_admin_base_url
254
+			);
255
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
256
+			$return .= '<a href="'
257
+					   . $href
258
+					   . '" title="'
259
+					   . $title
260
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
261
+					   . $title
262
+					   . '</a>';
263
+		}
264
+		return $return;
265
+	}
266
+
267
+
268
+	/**
269
+	 * Set the list table views for the default ticket list table view.
270
+	 */
271
+	public function _set_list_table_views_ticket_list_table()
272
+	{
273
+		$this->_views = array(
274
+			'all'     => array(
275
+				'slug'        => 'all',
276
+				'label'       => esc_html__('All', 'event_espresso'),
277
+				'count'       => 0,
278
+				'bulk_action' => array(
279
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
280
+				),
281
+			),
282
+			'trashed' => array(
283
+				'slug'        => 'trashed',
284
+				'label'       => esc_html__('Trash', 'event_espresso'),
285
+				'count'       => 0,
286
+				'bulk_action' => array(
287
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
288
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
289
+				),
290
+			),
291
+		);
292
+	}
293
+
294
+
295
+	/**
296
+	 * Enqueue scripts and styles for the event editor.
297
+	 */
298
+	public function load_scripts_styles_edit()
299
+	{
300
+		wp_register_script(
301
+			'ee-event-editor-heartbeat',
302
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
303
+			array('ee_admin_js', 'heartbeat'),
304
+			EVENT_ESPRESSO_VERSION,
305
+			true
306
+		);
307
+		wp_enqueue_script('ee-accounting');
308
+		// styles
309
+		wp_enqueue_style('espresso-ui-theme');
310
+		wp_enqueue_script('event_editor_js');
311
+		wp_enqueue_script('ee-event-editor-heartbeat');
312
+	}
313
+
314
+
315
+	/**
316
+	 * Returns template for the additional datetime.
317
+	 *
318
+	 * @param $template
319
+	 * @param $template_args
320
+	 * @return mixed
321
+	 * @throws DomainException
322
+	 */
323
+	public function add_additional_datetime_button($template, $template_args)
324
+	{
325
+		return EEH_Template::display_template(
326
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
327
+			$template_args,
328
+			true
329
+		);
330
+	}
331
+
332
+
333
+	/**
334
+	 * Returns the template for cloning a datetime.
335
+	 *
336
+	 * @param $template
337
+	 * @param $template_args
338
+	 * @return mixed
339
+	 * @throws DomainException
340
+	 */
341
+	public function add_datetime_clone_button($template, $template_args)
342
+	{
343
+		return EEH_Template::display_template(
344
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
345
+			$template_args,
346
+			true
347
+		);
348
+	}
349
+
350
+
351
+	/**
352
+	 * Returns the template for datetime timezones.
353
+	 *
354
+	 * @param $template
355
+	 * @param $template_args
356
+	 * @return mixed
357
+	 * @throws DomainException
358
+	 */
359
+	public function datetime_timezones_template($template, $template_args)
360
+	{
361
+		return EEH_Template::display_template(
362
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
363
+			$template_args,
364
+			true
365
+		);
366
+	}
367
+
368
+
369
+	/**
370
+	 * Sets the views for the default list table view.
371
+	 */
372
+	protected function _set_list_table_views_default()
373
+	{
374
+		parent::_set_list_table_views_default();
375
+		$new_views = array(
376
+			'today' => array(
377
+				'slug'        => 'today',
378
+				'label'       => esc_html__('Today', 'event_espresso'),
379
+				'count'       => $this->total_events_today(),
380
+				'bulk_action' => array(
381
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
382
+				),
383
+			),
384
+			'month' => array(
385
+				'slug'        => 'month',
386
+				'label'       => esc_html__('This Month', 'event_espresso'),
387
+				'count'       => $this->total_events_this_month(),
388
+				'bulk_action' => array(
389
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
390
+				),
391
+			),
392
+		);
393
+		$this->_views = array_merge($this->_views, $new_views);
394
+	}
395
+
396
+
397
+	/**
398
+	 * Returns the extra action links for the default list table view.
399
+	 *
400
+	 * @param array     $action_links
401
+	 * @param \EE_Event $event
402
+	 * @return array
403
+	 * @throws EE_Error
404
+	 */
405
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
406
+	{
407
+		if (EE_Registry::instance()->CAP->current_user_can(
408
+			'ee_read_registrations',
409
+			'espresso_registrations_reports',
410
+			$event->ID()
411
+		)
412
+		) {
413
+			$reports_query_args = array(
414
+				'action' => 'reports',
415
+				'EVT_ID' => $event->ID(),
416
+			);
417
+			$reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
418
+			$action_links[] = '<a href="'
419
+							  . $reports_link
420
+							  . '" title="'
421
+							  . esc_attr__('View Report', 'event_espresso')
422
+							  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
423
+							  . "\n\t";
424
+		}
425
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
426
+			EE_Registry::instance()->load_helper('MSG_Template');
427
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
428
+				'see_notifications_for',
429
+				null,
430
+				array('EVT_ID' => $event->ID())
431
+			);
432
+		}
433
+		return $action_links;
434
+	}
435
+
436
+
437
+	/**
438
+	 * @param $items
439
+	 * @return mixed
440
+	 */
441
+	public function additional_legend_items($items)
442
+	{
443
+		if (EE_Registry::instance()->CAP->current_user_can(
444
+			'ee_read_registrations',
445
+			'espresso_registrations_reports'
446
+		)
447
+		) {
448
+			$items['reports'] = array(
449
+				'class' => 'dashicons dashicons-chart-bar',
450
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
451
+			);
452
+		}
453
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
454
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
455
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
456
+				$items['view_related_messages'] = array(
457
+					'class' => $related_for_icon['css_class'],
458
+					'desc'  => $related_for_icon['label'],
459
+				);
460
+			}
461
+		}
462
+		return $items;
463
+	}
464
+
465
+
466
+	/**
467
+	 * This is the callback method for the duplicate event route
468
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
469
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
470
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
471
+	 * After duplication the redirect is to the new event edit page.
472
+	 *
473
+	 * @return void
474
+	 * @access protected
475
+	 * @throws EE_Error If EE_Event is not available with given ID
476
+	 */
477
+	protected function _duplicate_event()
478
+	{
479
+		// first make sure the ID for the event is in the request.
480
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
481
+		if (! isset($this->_req_data['EVT_ID'])) {
482
+			EE_Error::add_error(
483
+				esc_html__(
484
+					'In order to duplicate an event an Event ID is required.  None was given.',
485
+					'event_espresso'
486
+				),
487
+				__FILE__,
488
+				__FUNCTION__,
489
+				__LINE__
490
+			);
491
+			$this->_redirect_after_action(false, '', '', array(), true);
492
+			return;
493
+		}
494
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
495
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
496
+		if (! $orig_event instanceof EE_Event) {
497
+			throw new EE_Error(
498
+				sprintf(
499
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
500
+					$this->_req_data['EVT_ID']
501
+				)
502
+			);
503
+		}
504
+		// k now let's clone the $orig_event before getting relations
505
+		$new_event = clone $orig_event;
506
+		// original datetimes
507
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
508
+		// other original relations
509
+		$orig_ven = $orig_event->get_many_related('Venue');
510
+		// reset the ID and modify other details to make it clear this is a dupe
511
+		$new_event->set('EVT_ID', 0);
512
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
513
+		$new_event->set('EVT_name', $new_name);
514
+		$new_event->set(
515
+			'EVT_slug',
516
+			wp_unique_post_slug(
517
+				sanitize_title($orig_event->name()),
518
+				0,
519
+				'publish',
520
+				'espresso_events',
521
+				0
522
+			)
523
+		);
524
+		$new_event->set('status', 'draft');
525
+		// duplicate discussion settings
526
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
527
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
528
+		// save the new event
529
+		$new_event->save();
530
+		// venues
531
+		foreach ($orig_ven as $ven) {
532
+			$new_event->_add_relation_to($ven, 'Venue');
533
+		}
534
+		$new_event->save();
535
+		// now we need to get the question group relations and handle that
536
+		// first primary question groups
537
+		$orig_primary_qgs = $orig_event->get_many_related(
538
+			'Question_Group',
539
+			array(array('Event_Question_Group.EQG_primary' => 1))
540
+		);
541
+		if (! empty($orig_primary_qgs)) {
542
+			foreach ($orig_primary_qgs as $id => $obj) {
543
+				if ($obj instanceof EE_Question_Group) {
544
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
545
+				}
546
+			}
547
+		}
548
+		// next additional attendee question groups
549
+		$orig_additional_qgs = $orig_event->get_many_related(
550
+			'Question_Group',
551
+			array(array('Event_Question_Group.EQG_primary' => 0))
552
+		);
553
+		if (! empty($orig_additional_qgs)) {
554
+			foreach ($orig_additional_qgs as $id => $obj) {
555
+				if ($obj instanceof EE_Question_Group) {
556
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
557
+				}
558
+			}
559
+		}
560
+
561
+		$new_event->save();
562
+
563
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
564
+		$cloned_tickets = array();
565
+		foreach ($orig_datetimes as $orig_dtt) {
566
+			if (! $orig_dtt instanceof EE_Datetime) {
567
+				continue;
568
+			}
569
+			$new_dtt = clone $orig_dtt;
570
+			$orig_tkts = $orig_dtt->tickets();
571
+			// save new dtt then add to event
572
+			$new_dtt->set('DTT_ID', 0);
573
+			$new_dtt->set('DTT_sold', 0);
574
+			$new_dtt->set_reserved(0);
575
+			$new_dtt->save();
576
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
577
+			$new_event->save();
578
+			// now let's get the ticket relations setup.
579
+			foreach ((array) $orig_tkts as $orig_tkt) {
580
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
581
+				if (! $orig_tkt instanceof EE_Ticket) {
582
+					continue;
583
+				}
584
+				// is this ticket archived?  If it is then let's skip
585
+				if ($orig_tkt->get('TKT_deleted')) {
586
+					continue;
587
+				}
588
+				// does this original ticket already exist in the clone_tickets cache?
589
+				//  If so we'll just use the new ticket from it.
590
+				if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
591
+					$new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
592
+				} else {
593
+					$new_tkt = clone $orig_tkt;
594
+					// get relations on the $orig_tkt that we need to setup.
595
+					$orig_prices = $orig_tkt->prices();
596
+					$new_tkt->set('TKT_ID', 0);
597
+					$new_tkt->set('TKT_sold', 0);
598
+					$new_tkt->set('TKT_reserved', 0);
599
+					$new_tkt->save(); // make sure new ticket has ID.
600
+					// price relations on new ticket need to be setup.
601
+					foreach ($orig_prices as $orig_price) {
602
+						$new_price = clone $orig_price;
603
+						$new_price->set('PRC_ID', 0);
604
+						$new_price->save();
605
+						$new_tkt->_add_relation_to($new_price, 'Price');
606
+						$new_tkt->save();
607
+					}
608
+
609
+					do_action(
610
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
611
+						$orig_tkt,
612
+						$new_tkt,
613
+						$orig_prices,
614
+						$orig_event,
615
+						$orig_dtt,
616
+						$new_dtt
617
+					);
618
+				}
619
+				// k now we can add the new ticket as a relation to the new datetime
620
+				// and make sure its added to our cached $cloned_tickets array
621
+				// for use with later datetimes that have the same ticket.
622
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
623
+				$new_dtt->save();
624
+				$cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
625
+			}
626
+		}
627
+		// clone taxonomy information
628
+		$taxonomies_to_clone_with = apply_filters(
629
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
630
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
631
+		);
632
+		// get terms for original event (notice)
633
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
634
+		// loop through terms and add them to new event.
635
+		foreach ($orig_terms as $term) {
636
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
637
+		}
638
+
639
+		// duplicate other core WP_Post items for this event.
640
+		// post thumbnail (feature image).
641
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
642
+		if ($feature_image_id) {
643
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
644
+		}
645
+
646
+		// duplicate page_template setting
647
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
648
+		if ($page_template) {
649
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
650
+		}
651
+
652
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
653
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
654
+		if ($new_event->ID()) {
655
+			$redirect_args = array(
656
+				'post'   => $new_event->ID(),
657
+				'action' => 'edit',
658
+			);
659
+			EE_Error::add_success(
660
+				esc_html__(
661
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
662
+					'event_espresso'
663
+				)
664
+			);
665
+		} else {
666
+			$redirect_args = array(
667
+				'action' => 'default',
668
+			);
669
+			EE_Error::add_error(
670
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
671
+				__FILE__,
672
+				__FUNCTION__,
673
+				__LINE__
674
+			);
675
+		}
676
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
677
+	}
678
+
679
+
680
+	/**
681
+	 * Generates output for the import page.
682
+	 *
683
+	 * @throws DomainException
684
+	 */
685
+	protected function _import_page()
686
+	{
687
+		$title = esc_html__('Import', 'event_espresso');
688
+		$intro = esc_html__(
689
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
690
+			'event_espresso'
691
+		);
692
+		$form_url = EVENTS_ADMIN_URL;
693
+		$action = 'import_events';
694
+		$type = 'csv';
695
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
696
+			$title,
697
+			$intro,
698
+			$form_url,
699
+			$action,
700
+			$type
701
+		);
702
+		$this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
703
+			array('action' => 'sample_export_file'),
704
+			$this->_admin_base_url
705
+		);
706
+		$content = EEH_Template::display_template(
707
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
708
+			$this->_template_args,
709
+			true
710
+		);
711
+		$this->_template_args['admin_page_content'] = $content;
712
+		$this->display_admin_page_with_sidebar();
713
+	}
714
+
715
+
716
+	/**
717
+	 * _import_events
718
+	 * This handles displaying the screen and running imports for importing events.
719
+	 *
720
+	 * @return void
721
+	 */
722
+	protected function _import_events()
723
+	{
724
+		require_once(EE_CLASSES . 'EE_Import.class.php');
725
+		$success = EE_Import::instance()->import();
726
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
727
+	}
728
+
729
+
730
+	/**
731
+	 * _events_export
732
+	 * Will export all (or just the given event) to a Excel compatible file.
733
+	 *
734
+	 * @access protected
735
+	 * @return void
736
+	 */
737
+	protected function _events_export()
738
+	{
739
+		if (isset($this->_req_data['EVT_ID'])) {
740
+			$event_ids = $this->_req_data['EVT_ID'];
741
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
742
+			$event_ids = $this->_req_data['EVT_IDs'];
743
+		} else {
744
+			$event_ids = null;
745
+		}
746
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
747
+		$new_request_args = array(
748
+			'export' => 'report',
749
+			'action' => 'all_event_data',
750
+			'EVT_ID' => $event_ids,
751
+		);
752
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
753
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
754
+			require_once(EE_CLASSES . 'EE_Export.class.php');
755
+			$EE_Export = EE_Export::instance($this->_req_data);
756
+			$EE_Export->export();
757
+		}
758
+	}
759
+
760
+
761
+	/**
762
+	 * handle category exports()
763
+	 *
764
+	 * @return void
765
+	 */
766
+	protected function _categories_export()
767
+	{
768
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
769
+		$new_request_args = array(
770
+			'export'       => 'report',
771
+			'action'       => 'categories',
772
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
773
+		);
774
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
775
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
776
+			require_once(EE_CLASSES . 'EE_Export.class.php');
777
+			$EE_Export = EE_Export::instance($this->_req_data);
778
+			$EE_Export->export();
779
+		}
780
+	}
781
+
782
+
783
+	/**
784
+	 * Creates a sample CSV file for importing
785
+	 */
786
+	protected function _sample_export_file()
787
+	{
788
+		// require_once(EE_CLASSES . 'EE_Export.class.php');
789
+		EE_Export::instance()->export_sample();
790
+	}
791
+
792
+
793
+	/*************        Template Settings        *************/
794
+	/**
795
+	 * Generates template settings page output
796
+	 *
797
+	 * @throws DomainException
798
+	 * @throws EE_Error
799
+	 */
800
+	protected function _template_settings()
801
+	{
802
+		$this->_template_args['values'] = $this->_yes_no_values;
803
+		/**
804
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
805
+		 * from General_Settings_Admin_Page to here.
806
+		 */
807
+		$this->_template_args = apply_filters(
808
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
809
+			$this->_template_args
810
+		);
811
+		$this->_set_add_edit_form_tags('update_template_settings');
812
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
813
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
814
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
815
+			$this->_template_args,
816
+			true
817
+		);
818
+		$this->display_admin_page_with_sidebar();
819
+	}
820
+
821
+
822
+	/**
823
+	 * Handler for updating template settings.
824
+	 *
825
+	 * @throws InvalidInterfaceException
826
+	 * @throws InvalidDataTypeException
827
+	 * @throws InvalidArgumentException
828
+	 */
829
+	protected function _update_template_settings()
830
+	{
831
+		/**
832
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
833
+		 * from General_Settings_Admin_Page to here.
834
+		 */
835
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
836
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
837
+			EE_Registry::instance()->CFG->template_settings,
838
+			$this->_req_data
839
+		);
840
+		// update custom post type slugs and detect if we need to flush rewrite rules
841
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
842
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
843
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
844
+			: EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
845
+		$what = 'Template Settings';
846
+		$success = $this->_update_espresso_configuration(
847
+			$what,
848
+			EE_Registry::instance()->CFG->template_settings,
849
+			__FILE__,
850
+			__FUNCTION__,
851
+			__LINE__
852
+		);
853
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
854
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
855
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
856
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
857
+			);
858
+			$rewrite_rules->flush();
859
+		}
860
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
861
+	}
862
+
863
+
864
+	/**
865
+	 * _premium_event_editor_meta_boxes
866
+	 * add all metaboxes related to the event_editor
867
+	 *
868
+	 * @access protected
869
+	 * @return void
870
+	 * @throws EE_Error
871
+	 */
872
+	protected function _premium_event_editor_meta_boxes()
873
+	{
874
+		$this->verify_cpt_object();
875
+		add_meta_box(
876
+			'espresso_event_editor_event_options',
877
+			esc_html__('Event Registration Options', 'event_espresso'),
878
+			array($this, 'registration_options_meta_box'),
879
+			$this->page_slug,
880
+			'side',
881
+			'core'
882
+		);
883
+	}
884
+
885
+
886
+	/**
887
+	 * override caf metabox
888
+	 *
889
+	 * @return void
890
+	 * @throws DomainException
891
+	 */
892
+	public function registration_options_meta_box()
893
+	{
894
+		$yes_no_values = array(
895
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
896
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
897
+		);
898
+		$default_reg_status_values = EEM_Registration::reg_status_array(
899
+			array(
900
+				EEM_Registration::status_id_cancelled,
901
+				EEM_Registration::status_id_declined,
902
+				EEM_Registration::status_id_incomplete,
903
+				EEM_Registration::status_id_wait_list,
904
+			),
905
+			true
906
+		);
907
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
908
+		$template_args['_event'] = $this->_cpt_model_obj;
909
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
910
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
911
+			'default_reg_status',
912
+			$default_reg_status_values,
913
+			$this->_cpt_model_obj->default_registration_status()
914
+		);
915
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
916
+			'display_desc',
917
+			$yes_no_values,
918
+			$this->_cpt_model_obj->display_description()
919
+		);
920
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
921
+			'display_ticket_selector',
922
+			$yes_no_values,
923
+			$this->_cpt_model_obj->display_ticket_selector(),
924
+			'',
925
+			'',
926
+			false
927
+		);
928
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
929
+			'EVT_default_registration_status',
930
+			$default_reg_status_values,
931
+			$this->_cpt_model_obj->default_registration_status()
932
+		);
933
+		$template_args['additional_registration_options'] = apply_filters(
934
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
935
+			'',
936
+			$template_args,
937
+			$yes_no_values,
938
+			$default_reg_status_values
939
+		);
940
+		EEH_Template::display_template(
941
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
942
+			$template_args
943
+		);
944
+	}
945
+
946
+
947
+
948
+	/**
949
+	 * wp_list_table_mods for caf
950
+	 * ============================
951
+	 */
952
+	/**
953
+	 * hook into list table filters and provide filters for caffeinated list table
954
+	 *
955
+	 * @param  array $old_filters    any existing filters present
956
+	 * @param  array $list_table_obj the list table object
957
+	 * @return array                  new filters
958
+	 */
959
+	public function list_table_filters($old_filters, $list_table_obj)
960
+	{
961
+		$filters = array();
962
+		// first month/year filters
963
+		$filters[] = $this->espresso_event_months_dropdown();
964
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
965
+		// active status dropdown
966
+		if ($status !== 'draft') {
967
+			$filters[] = $this->active_status_dropdown(
968
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
969
+			);
970
+		}
971
+		// category filter
972
+		$filters[] = $this->category_dropdown();
973
+		return array_merge($old_filters, $filters);
974
+	}
975
+
976
+
977
+	/**
978
+	 * espresso_event_months_dropdown
979
+	 *
980
+	 * @access public
981
+	 * @return string                dropdown listing month/year selections for events.
982
+	 */
983
+	public function espresso_event_months_dropdown()
984
+	{
985
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
986
+		// Note we need to include any other filters that are set!
987
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
988
+		// categories?
989
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
990
+			? $this->_req_data['EVT_CAT']
991
+			: null;
992
+		// active status?
993
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
994
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
995
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
996
+	}
997
+
998
+
999
+	/**
1000
+	 * returns a list of "active" statuses on the event
1001
+	 *
1002
+	 * @param  string $current_value whatever the current active status is
1003
+	 * @return string
1004
+	 */
1005
+	public function active_status_dropdown($current_value = '')
1006
+	{
1007
+		$select_name = 'active_status';
1008
+		$values = array(
1009
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1010
+			'active'   => esc_html__('Active', 'event_espresso'),
1011
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1012
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1013
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1014
+		);
1015
+		$id = 'id="espresso-active-status-dropdown-filter"';
1016
+		$class = 'wide';
1017
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * output a dropdown of the categories for the category filter on the event admin list table
1023
+	 *
1024
+	 * @access  public
1025
+	 * @return string html
1026
+	 */
1027
+	public function category_dropdown()
1028
+	{
1029
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1030
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1031
+	}
1032
+
1033
+
1034
+	/**
1035
+	 * get total number of events today
1036
+	 *
1037
+	 * @access public
1038
+	 * @return int
1039
+	 * @throws EE_Error
1040
+	 */
1041
+	public function total_events_today()
1042
+	{
1043
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1044
+			'DTT_EVT_start',
1045
+			date('Y-m-d') . ' 00:00:00',
1046
+			'Y-m-d H:i:s',
1047
+			'UTC'
1048
+		);
1049
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1050
+			'DTT_EVT_start',
1051
+			date('Y-m-d') . ' 23:59:59',
1052
+			'Y-m-d H:i:s',
1053
+			'UTC'
1054
+		);
1055
+		$where = array(
1056
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1057
+		);
1058
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1059
+		return $count;
1060
+	}
1061
+
1062
+
1063
+	/**
1064
+	 * get total number of events this month
1065
+	 *
1066
+	 * @access public
1067
+	 * @return int
1068
+	 * @throws EE_Error
1069
+	 */
1070
+	public function total_events_this_month()
1071
+	{
1072
+		// Dates
1073
+		$this_year_r = date('Y');
1074
+		$this_month_r = date('m');
1075
+		$days_this_month = date('t');
1076
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1077
+			'DTT_EVT_start',
1078
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1079
+			'Y-m-d H:i:s',
1080
+			'UTC'
1081
+		);
1082
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1083
+			'DTT_EVT_start',
1084
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1085
+			'Y-m-d H:i:s',
1086
+			'UTC'
1087
+		);
1088
+		$where = array(
1089
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1090
+		);
1091
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1092
+		return $count;
1093
+	}
1094
+
1095
+
1096
+	/** DEFAULT TICKETS STUFF **/
1097
+
1098
+	/**
1099
+	 * Output default tickets list table view.
1100
+	 */
1101
+	public function _tickets_overview_list_table()
1102
+	{
1103
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1104
+		$this->display_admin_list_table_page_with_no_sidebar();
1105
+	}
1106
+
1107
+
1108
+	/**
1109
+	 * @param int  $per_page
1110
+	 * @param bool $count
1111
+	 * @param bool $trashed
1112
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1113
+	 */
1114
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1115
+	{
1116
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1117
+		$order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1118
+		switch ($orderby) {
1119
+			case 'TKT_name':
1120
+				$orderby = array('TKT_name' => $order);
1121
+				break;
1122
+			case 'TKT_price':
1123
+				$orderby = array('TKT_price' => $order);
1124
+				break;
1125
+			case 'TKT_uses':
1126
+				$orderby = array('TKT_uses' => $order);
1127
+				break;
1128
+			case 'TKT_min':
1129
+				$orderby = array('TKT_min' => $order);
1130
+				break;
1131
+			case 'TKT_max':
1132
+				$orderby = array('TKT_max' => $order);
1133
+				break;
1134
+			case 'TKT_qty':
1135
+				$orderby = array('TKT_qty' => $order);
1136
+				break;
1137
+		}
1138
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1139
+			? $this->_req_data['paged']
1140
+			: 1;
1141
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1142
+			? $this->_req_data['perpage']
1143
+			: $per_page;
1144
+		$_where = array(
1145
+			'TKT_is_default' => 1,
1146
+			'TKT_deleted'    => $trashed,
1147
+		);
1148
+		$offset = ($current_page - 1) * $per_page;
1149
+		$limit = array($offset, $per_page);
1150
+		if (isset($this->_req_data['s'])) {
1151
+			$sstr = '%' . $this->_req_data['s'] . '%';
1152
+			$_where['OR'] = array(
1153
+				'TKT_name'        => array('LIKE', $sstr),
1154
+				'TKT_description' => array('LIKE', $sstr),
1155
+			);
1156
+		}
1157
+		$query_params = array(
1158
+			$_where,
1159
+			'order_by' => $orderby,
1160
+			'limit'    => $limit,
1161
+			'group_by' => 'TKT_ID',
1162
+		);
1163
+		if ($count) {
1164
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1165
+		} else {
1166
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1167
+		}
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 * @param bool $trash
1173
+	 * @throws EE_Error
1174
+	 */
1175
+	protected function _trash_or_restore_ticket($trash = false)
1176
+	{
1177
+		$success = 1;
1178
+		$TKT = EEM_Ticket::instance();
1179
+		// checkboxes?
1180
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1181
+			// if array has more than one element then success message should be plural
1182
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1183
+			// cycle thru the boxes
1184
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1185
+				if ($trash) {
1186
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1187
+						$success = 0;
1188
+					}
1189
+				} else {
1190
+					if (! $TKT->restore_by_ID($TKT_ID)) {
1191
+						$success = 0;
1192
+					}
1193
+				}
1194
+			}
1195
+		} else {
1196
+			// grab single id and trash
1197
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1198
+			if ($trash) {
1199
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1200
+					$success = 0;
1201
+				}
1202
+			} else {
1203
+				if (! $TKT->restore_by_ID($TKT_ID)) {
1204
+					$success = 0;
1205
+				}
1206
+			}
1207
+		}
1208
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1209
+		$query_args = array(
1210
+			'action' => 'ticket_list_table',
1211
+			'status' => $trash ? '' : 'trashed',
1212
+		);
1213
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 * Handles trashing default ticket.
1219
+	 */
1220
+	protected function _delete_ticket()
1221
+	{
1222
+		$success = 1;
1223
+		// checkboxes?
1224
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1225
+			// if array has more than one element then success message should be plural
1226
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1227
+			// cycle thru the boxes
1228
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1229
+				// delete
1230
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1231
+					$success = 0;
1232
+				}
1233
+			}
1234
+		} else {
1235
+			// grab single id and trash
1236
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1237
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1238
+				$success = 0;
1239
+			}
1240
+		}
1241
+		$action_desc = 'deleted';
1242
+		$query_args = array(
1243
+			'action' => 'ticket_list_table',
1244
+			'status' => 'trashed',
1245
+		);
1246
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1247
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1248
+			array(array('TKT_is_default' => 1)),
1249
+			'TKT_ID',
1250
+			true
1251
+		)
1252
+		) {
1253
+			$query_args = array();
1254
+		}
1255
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1256
+	}
1257
+
1258
+
1259
+	/**
1260
+	 * @param int $TKT_ID
1261
+	 * @return bool|int
1262
+	 * @throws EE_Error
1263
+	 */
1264
+	protected function _delete_the_ticket($TKT_ID)
1265
+	{
1266
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1267
+		$tkt->_remove_relations('Datetime');
1268
+		// delete all related prices first
1269
+		$tkt->delete_related_permanently('Price');
1270
+		return $tkt->delete_permanently();
1271
+	}
1272 1272
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
     public function __construct($routing = true)
25 25
     {
26 26
         parent::__construct($routing);
27
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
27
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
29
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
30
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
31 31
         }
32 32
     }
33 33
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     protected function _extend_page_config()
39 39
     {
40
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
40
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
41 41
         // is there a evt_id in the request?
42 42
         $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
43 43
             ? $this->_req_data['EVT_ID']
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     {
248 248
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
249 249
         // make sure this is only when editing
250
-        if (! empty($id)) {
250
+        if ( ! empty($id)) {
251 251
             $href = EE_Admin_Page::add_query_args_and_nonce(
252 252
                 array('action' => 'duplicate_event', 'EVT_ID' => $id),
253 253
                 $this->_admin_base_url
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     {
300 300
         wp_register_script(
301 301
             'ee-event-editor-heartbeat',
302
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
302
+            EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
303 303
             array('ee_admin_js', 'heartbeat'),
304 304
             EVENT_ESPRESSO_VERSION,
305 305
             true
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
     public function add_additional_datetime_button($template, $template_args)
324 324
     {
325 325
         return EEH_Template::display_template(
326
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
326
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
327 327
             $template_args,
328 328
             true
329 329
         );
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
     public function add_datetime_clone_button($template, $template_args)
342 342
     {
343 343
         return EEH_Template::display_template(
344
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
344
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
345 345
             $template_args,
346 346
             true
347 347
         );
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
     public function datetime_timezones_template($template, $template_args)
360 360
     {
361 361
         return EEH_Template::display_template(
362
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
362
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
363 363
             $template_args,
364 364
             true
365 365
         );
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
     {
479 479
         // first make sure the ID for the event is in the request.
480 480
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
481
-        if (! isset($this->_req_data['EVT_ID'])) {
481
+        if ( ! isset($this->_req_data['EVT_ID'])) {
482 482
             EE_Error::add_error(
483 483
                 esc_html__(
484 484
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
         }
494 494
         // k we've got EVT_ID so let's use that to get the event we'll duplicate
495 495
         $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
496
-        if (! $orig_event instanceof EE_Event) {
496
+        if ( ! $orig_event instanceof EE_Event) {
497 497
             throw new EE_Error(
498 498
                 sprintf(
499 499
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
         $orig_ven = $orig_event->get_many_related('Venue');
510 510
         // reset the ID and modify other details to make it clear this is a dupe
511 511
         $new_event->set('EVT_ID', 0);
512
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
512
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
513 513
         $new_event->set('EVT_name', $new_name);
514 514
         $new_event->set(
515 515
             'EVT_slug',
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
             'Question_Group',
539 539
             array(array('Event_Question_Group.EQG_primary' => 1))
540 540
         );
541
-        if (! empty($orig_primary_qgs)) {
541
+        if ( ! empty($orig_primary_qgs)) {
542 542
             foreach ($orig_primary_qgs as $id => $obj) {
543 543
                 if ($obj instanceof EE_Question_Group) {
544 544
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
             'Question_Group',
551 551
             array(array('Event_Question_Group.EQG_primary' => 0))
552 552
         );
553
-        if (! empty($orig_additional_qgs)) {
553
+        if ( ! empty($orig_additional_qgs)) {
554 554
             foreach ($orig_additional_qgs as $id => $obj) {
555 555
                 if ($obj instanceof EE_Question_Group) {
556 556
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
         // k now that we have the new event saved we can loop through the datetimes and start adding relations.
564 564
         $cloned_tickets = array();
565 565
         foreach ($orig_datetimes as $orig_dtt) {
566
-            if (! $orig_dtt instanceof EE_Datetime) {
566
+            if ( ! $orig_dtt instanceof EE_Datetime) {
567 567
                 continue;
568 568
             }
569 569
             $new_dtt = clone $orig_dtt;
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
             // now let's get the ticket relations setup.
579 579
             foreach ((array) $orig_tkts as $orig_tkt) {
580 580
                 // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
581
-                if (! $orig_tkt instanceof EE_Ticket) {
581
+                if ( ! $orig_tkt instanceof EE_Ticket) {
582 582
                     continue;
583 583
                 }
584 584
                 // is this ticket archived?  If it is then let's skip
@@ -587,8 +587,8 @@  discard block
 block discarded – undo
587 587
                 }
588 588
                 // does this original ticket already exist in the clone_tickets cache?
589 589
                 //  If so we'll just use the new ticket from it.
590
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
591
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
590
+                if (isset($cloned_tickets[$orig_tkt->ID()])) {
591
+                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
592 592
                 } else {
593 593
                     $new_tkt = clone $orig_tkt;
594 594
                     // get relations on the $orig_tkt that we need to setup.
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
                 // for use with later datetimes that have the same ticket.
622 622
                 $new_dtt->_add_relation_to($new_tkt, 'Ticket');
623 623
                 $new_dtt->save();
624
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
624
+                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
625 625
             }
626 626
         }
627 627
         // clone taxonomy information
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
             $this->_admin_base_url
705 705
         );
706 706
         $content = EEH_Template::display_template(
707
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
707
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
708 708
             $this->_template_args,
709 709
             true
710 710
         );
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
      */
722 722
     protected function _import_events()
723 723
     {
724
-        require_once(EE_CLASSES . 'EE_Import.class.php');
724
+        require_once(EE_CLASSES.'EE_Import.class.php');
725 725
         $success = EE_Import::instance()->import();
726 726
         $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
727 727
     }
@@ -750,8 +750,8 @@  discard block
 block discarded – undo
750 750
             'EVT_ID' => $event_ids,
751 751
         );
752 752
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
753
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
754
-            require_once(EE_CLASSES . 'EE_Export.class.php');
753
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
754
+            require_once(EE_CLASSES.'EE_Export.class.php');
755 755
             $EE_Export = EE_Export::instance($this->_req_data);
756 756
             $EE_Export->export();
757 757
         }
@@ -772,8 +772,8 @@  discard block
 block discarded – undo
772 772
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
773 773
         );
774 774
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
775
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
776
-            require_once(EE_CLASSES . 'EE_Export.class.php');
775
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
776
+            require_once(EE_CLASSES.'EE_Export.class.php');
777 777
             $EE_Export = EE_Export::instance($this->_req_data);
778 778
             $EE_Export->export();
779 779
         }
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
         $this->_set_add_edit_form_tags('update_template_settings');
812 812
         $this->_set_publish_post_box_vars(null, false, false, null, false);
813 813
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
814
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
814
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
815 815
             $this->_template_args,
816 816
             true
817 817
         );
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
             $default_reg_status_values
939 939
         );
940 940
         EEH_Template::display_template(
941
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
941
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
942 942
             $template_args
943 943
         );
944 944
     }
@@ -1042,13 +1042,13 @@  discard block
 block discarded – undo
1042 1042
     {
1043 1043
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1044 1044
             'DTT_EVT_start',
1045
-            date('Y-m-d') . ' 00:00:00',
1045
+            date('Y-m-d').' 00:00:00',
1046 1046
             'Y-m-d H:i:s',
1047 1047
             'UTC'
1048 1048
         );
1049 1049
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1050 1050
             'DTT_EVT_start',
1051
-            date('Y-m-d') . ' 23:59:59',
1051
+            date('Y-m-d').' 23:59:59',
1052 1052
             'Y-m-d H:i:s',
1053 1053
             'UTC'
1054 1054
         );
@@ -1075,13 +1075,13 @@  discard block
 block discarded – undo
1075 1075
         $days_this_month = date('t');
1076 1076
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1077 1077
             'DTT_EVT_start',
1078
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1078
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1079 1079
             'Y-m-d H:i:s',
1080 1080
             'UTC'
1081 1081
         );
1082 1082
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1083 1083
             'DTT_EVT_start',
1084
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1084
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1085 1085
             'Y-m-d H:i:s',
1086 1086
             'UTC'
1087 1087
         );
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
         $offset = ($current_page - 1) * $per_page;
1149 1149
         $limit = array($offset, $per_page);
1150 1150
         if (isset($this->_req_data['s'])) {
1151
-            $sstr = '%' . $this->_req_data['s'] . '%';
1151
+            $sstr = '%'.$this->_req_data['s'].'%';
1152 1152
             $_where['OR'] = array(
1153 1153
                 'TKT_name'        => array('LIKE', $sstr),
1154 1154
                 'TKT_description' => array('LIKE', $sstr),
@@ -1177,17 +1177,17 @@  discard block
 block discarded – undo
1177 1177
         $success = 1;
1178 1178
         $TKT = EEM_Ticket::instance();
1179 1179
         // checkboxes?
1180
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1180
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1181 1181
             // if array has more than one element then success message should be plural
1182 1182
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1183 1183
             // cycle thru the boxes
1184 1184
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1185 1185
                 if ($trash) {
1186
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1186
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1187 1187
                         $success = 0;
1188 1188
                     }
1189 1189
                 } else {
1190
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1190
+                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1191 1191
                         $success = 0;
1192 1192
                     }
1193 1193
                 }
@@ -1196,11 +1196,11 @@  discard block
 block discarded – undo
1196 1196
             // grab single id and trash
1197 1197
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1198 1198
             if ($trash) {
1199
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1199
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1200 1200
                     $success = 0;
1201 1201
                 }
1202 1202
             } else {
1203
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1203
+                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1204 1204
                     $success = 0;
1205 1205
                 }
1206 1206
             }
@@ -1221,20 +1221,20 @@  discard block
 block discarded – undo
1221 1221
     {
1222 1222
         $success = 1;
1223 1223
         // checkboxes?
1224
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1224
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1225 1225
             // if array has more than one element then success message should be plural
1226 1226
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1227 1227
             // cycle thru the boxes
1228 1228
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1229 1229
                 // delete
1230
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1230
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1231 1231
                     $success = 0;
1232 1232
                 }
1233 1233
             }
1234 1234
         } else {
1235 1235
             // grab single id and trash
1236 1236
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1237
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1237
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1238 1238
                 $success = 0;
1239 1239
             }
1240 1240
         }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Loader.core.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice;
4
-use EventEspresso\core\exceptions\InvalidDataTypeException;
5 4
 
6 5
 /**
7 6
  * Event Espresso
Please login to merge, or discard this patch.
Indentation   +674 added lines, -674 removed lines patch added patch discarded remove patch
@@ -24,678 +24,678 @@
 block discarded – undo
24 24
 class EE_Admin_Page_Loader
25 25
 {
26 26
 
27
-    /**
28
-     * _installed_pages
29
-     * objects for page_init objects detected and loaded
30
-     *
31
-     * @access private
32
-     * @var \EE_Admin_Page_Init[]
33
-     */
34
-    private $_installed_pages = array();
35
-
36
-
37
-    /**
38
-     * this is used to hold the registry of menu slugs for all the installed admin pages
39
-     *
40
-     * @var array
41
-     */
42
-    private $_menu_slugs = array();
43
-
44
-
45
-    /**
46
-     * _caffeinated_extends
47
-     * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
48
-     * pieces needed to do so).  This property is defined in the _set_caffeinated method.
49
-     *
50
-     * @var array
51
-     */
52
-    private $_caffeinated_extends = array();
53
-
54
-
55
-    /**
56
-     * _current_caf_extend_slug
57
-     * This property is used for holding the page slug that is required for referencing the correct
58
-     * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
59
-     *
60
-     * @var array
61
-     */
62
-    private $_current_caf_extend_slug;
63
-
64
-    /**
65
-     * _prepped_menu_maps
66
-     * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
67
-     *
68
-     * @since  4.4.0
69
-     * @var EE_Admin_Page_Menu_Map[]
70
-     */
71
-    private $_prepped_menu_maps = array();
72
-
73
-
74
-    /**
75
-     * _admin_menu_groups
76
-     * array that holds the group headings and details for
77
-     *
78
-     * @access private
79
-     * @var array
80
-     */
81
-    private $_admin_menu_groups = array();
82
-
83
-
84
-    /**
85
-     * This property will hold the hook file for setting up the filter that does all the connections between admin
86
-     * pages.
87
-     *
88
-     * @var string
89
-     */
90
-    public $hook_file;
91
-
92
-
93
-    /**
94
-     * constructor
95
-     *
96
-     * @access public
97
-     * @return \EE_Admin_Page_Loader
98
-     */
99
-    public function __construct()
100
-    {
101
-        // load menu_map classes
102
-        EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core');
103
-        // define the default "groups" for the admin_pages
104
-        $this->_set_menu_groups();
105
-
106
-        // let's do a scan and see what installed pages we have
107
-        $this->_get_installed_pages();
108
-        // set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
109
-        add_action('admin_menu', array($this, 'set_menus'));
110
-        add_action('network_admin_menu', array($this, 'set_network_menus'));
111
-    }
112
-
113
-
114
-    /**
115
-     * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
116
-     * files in the caffeinated folder.
117
-     *
118
-     * @access private
119
-     * @return void
120
-     */
121
-    private function _define_caffeinated_constants()
122
-    {
123
-        if (! defined('EE_CORE_CAF_ADMIN')) {
124
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
125
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
126
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
127
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
128
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
129
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
130
-        }
131
-    }
132
-
133
-
134
-    /**
135
-     * _set_menu_groups
136
-     * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
137
-     *
138
-     * @access private
139
-     * @return void
140
-     */
141
-    private function _set_menu_groups()
142
-    {
143
-
144
-        // set array of EE_Admin_Page_Menu_Group objects
145
-        $groups = array(
146
-            'main'       => new EE_Admin_Page_Menu_Group(
147
-                array(
148
-                    'menu_label'   => __('Main', 'event_espresso'),
149
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
150
-                    'menu_slug'    => 'main',
151
-                    'capability'   => 'ee_read_ee',
152
-                    'menu_order'   => 0,
153
-                    'parent_slug'  => 'espresso_events',
154
-                )
155
-            ),
156
-            'management' => new EE_Admin_Page_Menu_Group(
157
-                array(
158
-                    'menu_label'   => __('Management', 'event_espresso'),
159
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
160
-                    'menu_slug'    => 'management',
161
-                    'capability'   => 'ee_read_ee',
162
-                    'menu_order'   => 10,
163
-                    'parent_slug'  => 'espresso_events',
164
-                )
165
-            ),
166
-            'settings'   => new EE_Admin_Page_Menu_Group(
167
-                array(
168
-                    'menu_label'   => __('Settings', 'event_espresso'),
169
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
170
-                    'menu_slug'    => 'settings',
171
-                    'capability'   => 'ee_read_ee',
172
-                    'menu_order'   => 30,
173
-                    'parent_slug'  => 'espresso_events',
174
-                )
175
-            ),
176
-            'templates'  => new EE_Admin_Page_Menu_Group(
177
-                array(
178
-                    'menu_label'   => __('Templates', 'event_espresso'),
179
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
180
-                    'menu_slug'    => 'templates',
181
-                    'capability'   => 'ee_read_ee',
182
-                    'menu_order'   => 40,
183
-                    'parent_slug'  => 'espresso_events',
184
-                )
185
-            ),
186
-            'extras'     => new EE_Admin_Page_Menu_Group(
187
-                array(
188
-                    'menu_label'              => __('Extras', 'event_espresso'),
189
-                    'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
190
-                    'menu_slug'               => 'extras',
191
-                    'capability'              => 'ee_read_ee',
192
-                    'menu_order'              => 50,
193
-                    'parent_slug'             => 'espresso_events',
194
-                    'maintenance_mode_parent' => 'espresso_maintenance_settings',
195
-                )
196
-            ),
197
-            'tools'      => new EE_Admin_Page_Menu_Group(
198
-                array(
199
-                    'menu_label'   => __("Tools", "event_espresso"),
200
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
201
-                    'menu_slug'    => 'tools',
202
-                    'capability'   => 'ee_read_ee',
203
-                    'menu_order'   => 60,
204
-                    'parent_slug'  => 'espresso_events',
205
-                )
206
-            ),
207
-            'addons'     => new EE_Admin_Page_Menu_Group(
208
-                array(
209
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
210
-                    'menu_label'   => __('Add-ons', 'event_espresso'),
211
-                    'menu_slug'    => 'addons',
212
-                    'capability'   => 'ee_read_ee',
213
-                    'menu_order'   => 20,
214
-                    'parent_slug'  => 'espresso_events',
215
-                )
216
-            ),
217
-        );
218
-        $this->_admin_menu_groups = apply_filters(
219
-            'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
220
-            $groups
221
-        );
222
-    }
223
-
224
-
225
-    /**
226
-     * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
227
-     * slug.  The other utility with this function is it validates that all the groups are instances of
228
-     * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
229
-     *
230
-     * @since  4.4.0
231
-     * @throws \EE_Error
232
-     * @return EE_Admin_Page_Menu_Group[]
233
-     */
234
-    private function _rearrange_menu_groups()
235
-    {
236
-        $groups = array();
237
-        // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
238
-        usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
239
-        foreach ($this->_admin_menu_groups as $group) {
240
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
241
-                throw new EE_Error(
242
-                    sprintf(
243
-                        __(
244
-                            'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
245
-                            'event_espresso'
246
-                        ),
247
-                        print_r($group, true)
248
-                    )
249
-                );
250
-            }
251
-            $groups[ $group->menu_slug ] = $group;
252
-        }
253
-        return $groups;
254
-    }
255
-
256
-
257
-    /**
258
-     * _get_installed_pages
259
-     * This just gets the list of installed EE_Admin_pages.
260
-     *
261
-     * @access private
262
-     * @throws EE_Error
263
-     * @return void
264
-     */
265
-    private function _get_installed_pages()
266
-    {
267
-        $installed_refs = array();
268
-        $exclude = array('assets', 'templates');
269
-        // grab everything in the  admin core directory
270
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
271
-        if ($admin_screens) {
272
-            foreach ($admin_screens as $admin_screen) {
273
-                // files and anything in the exclude array need not apply
274
-                if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
275
-                    // these folders represent the different EE admin pages
276
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
277
-                }
278
-            }
279
-        }
280
-        if (empty($installed_refs)) {
281
-            $error_msg[] = __(
282
-                'There are no EE_Admin pages detected, it looks like EE did not install properly',
283
-                'event_espresso'
284
-            );
285
-            $error_msg[] = $error_msg[0] . "\r\n"
286
-                           . sprintf(
287
-                               __(
288
-                                   'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
289
-                                   'event_espresso'
290
-                               ),
291
-                               EE_ADMIN_PAGES
292
-                           );
293
-            throw new EE_Error(implode('||', $error_msg));
294
-        }
295
-        // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
296
-        $installed_refs = $this->_set_caffeinated($installed_refs);
297
-        // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
298
-        $installed_refs = apply_filters(
299
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
300
-            $installed_refs
301
-        );
302
-        $this->_caffeinated_extends = apply_filters(
303
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
304
-            $this->_caffeinated_extends
305
-        );
306
-        // loop through admin pages and setup the $_installed_pages array.
307
-        $hooks_ref = array();
308
-        foreach ($installed_refs as $page => $path) {
309
-            // set autoloaders for our admin page classes based on included path information
310
-            EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
311
-            // build list of installed pages
312
-            $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
313
-            // verify returned object
314
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
315
-                if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
316
-                    continue;
317
-                }
318
-                // skip if in full maintenance mode and maintenance_mode_parent is set
319
-                $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
320
-                if (empty($maintenance_mode_parent)
321
-                    && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
322
-                ) {
323
-                    unset($installed_refs[ $page ]);
324
-                    continue;
325
-                }
326
-                $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
327
-                $this->_menu_slugs[ $menu_slug ] = $page;
328
-                // flag for register hooks on extended pages b/c extended pages use the default INIT.
329
-                $extend = false;
330
-                // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
331
-                if (isset($this->_caffeinated_extends[ $page ])) {
332
-                    $this->_current_caf_extend_slug = $page;
333
-                    $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
334
-                    $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
335
-                    $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
336
-                    add_filter(
337
-                        "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
338
-                        function ($path_to_file) use ($caf_path) {
339
-                            return $caf_path;
340
-                        }
341
-                    );
342
-                    add_filter(
343
-                        "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
344
-                        function ($admin_page) use ($caf_admin_page) {
345
-                            return $caf_admin_page;
346
-                        }
347
-                    );
348
-                    $extend = true;
349
-                }
350
-                // let's do the registered hooks
351
-                $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
352
-                $hooks_ref = array_merge($hooks_ref, $extended_hooks);
353
-            }
354
-        }
355
-        // the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
356
-        // first make sure we've got unique values
357
-        $hooks_ref = array_unique($hooks_ref);
358
-        // now let's loop and require!
359
-        foreach ($hooks_ref as $path) {
360
-            require_once($path);
361
-        }
362
-        // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
363
-        global $ee_menu_slugs;
364
-        $ee_menu_slugs = $this->_menu_slugs;
365
-        // we need to loop again to run any early code
366
-        foreach ($installed_refs as $page => $path) {
367
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
368
-                $this->_installed_pages[ $page ]->do_initial_loads();
369
-            }
370
-        }
371
-        do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
372
-    }
373
-
374
-
375
-    /**
376
-     * get_admin_page_object
377
-     *
378
-     * @param string $page_slug
379
-     * @return EE_Admin_Page
380
-     */
381
-    public function get_admin_page_object($page_slug = '')
382
-    {
383
-        if (isset($this->_installed_pages[ $page_slug ])) {
384
-            return $this->_installed_pages[ $page_slug ]->loaded_page_object();
385
-        }
386
-        return null;
387
-    }
388
-
389
-
390
-    /**
391
-     * _get_classname_for_admin_page
392
-     * generates an "Admin Page" class based on the directory  name
393
-     *
394
-     * @param $dir_name
395
-     * @return string
396
-     */
397
-    private function _get_classname_for_admin_page($dir_name = '')
398
-    {
399
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
400
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
401
-    }
402
-
403
-
404
-    /**
405
-     * _get_classname_for_admin_init_page
406
-     * generates an "Admin Page Init" class based on the directory  name
407
-     *
408
-     * @param $dir_name
409
-     * @return string
410
-     */
411
-    private function _get_classname_for_admin_init_page($dir_name = '')
412
-    {
413
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
414
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
415
-    }
416
-
417
-
418
-    /**
419
-     * _load_admin_page
420
-     * Loads and instantiates page_init object for a single EE_admin page.
421
-     *
422
-     * @param  string $page page_reference
423
-     * @param string  $path
424
-     * @throws EE_Error
425
-     * @return object|bool  return page object if valid, bool false if not.
426
-     */
427
-    private function _load_admin_page($page = '', $path = '')
428
-    {
429
-        $class_name = $this->_get_classname_for_admin_init_page($page);
430
-        EE_Registry::instance()->load_file($path, $class_name, 'core');
431
-        if (! class_exists($class_name)) {
432
-            $inner_error_msg = '<br />'
433
-                               . sprintf(
434
-                                   esc_html__(
435
-                                       'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
436
-                                       'event_espresso'
437
-                                   ),
438
-                                   '<strong>' . $class_name . '</strong>'
439
-                               );
440
-            $error_msg[] = sprintf(
441
-                __('Something went wrong with loading the %s admin page.', 'event_espresso'),
442
-                $page
443
-            );
444
-            $error_msg[] = $error_msg[0]
445
-                           . "\r\n"
446
-                           . sprintf(
447
-                               esc_html__(
448
-                                   'There is no Init class in place for the %s admin page.',
449
-                                   'event_espresso'
450
-                               ),
451
-                               $page
452
-                           )
453
-                           . $inner_error_msg;
454
-            throw new EE_Error(implode('||', $error_msg));
455
-        }
456
-        $a = new ReflectionClass($class_name);
457
-        return $a->newInstance();
458
-    }
459
-
460
-
461
-    /**
462
-     * set_menus
463
-     * This method sets up the menus for EE Admin Pages
464
-     *
465
-     * @access private
466
-     * @return void
467
-     */
468
-    public function set_menus()
469
-    {
470
-        // prep the menu pages (sort, group.)
471
-        $this->_prep_pages();
472
-        foreach ($this->_prepped_menu_maps as $menu_map) {
473
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
474
-                $menu_map->add_menu_page(false);
475
-            }
476
-        }
477
-    }
478
-
479
-
480
-    /**
481
-     * set_network_menus
482
-     * This method sets up the menus for network EE Admin Pages.
483
-     * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
484
-     * are only added to the menu map if they are intended for the admin menu
485
-     *
486
-     * @return void
487
-     */
488
-    public function set_network_menus()
489
-    {
490
-        $this->_prep_pages();
491
-        foreach ($this->_prepped_menu_maps as $menu_map) {
492
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
493
-                $menu_map->add_menu_page(true);
494
-            }
495
-        }
496
-    }
497
-
498
-
499
-    /**
500
-     * _prep_pages
501
-     * sets the _prepped_menu_maps property
502
-     *
503
-     * @access private
504
-     * @throws EE_Error
505
-     * @return void
506
-     */
507
-    private function _prep_pages()
508
-    {
509
-        $pages_array = array();
510
-        // rearrange _admin_menu_groups to be indexed by group slug.
511
-        $menu_groups = $this->_rearrange_menu_groups();
512
-        foreach ($this->_installed_pages as $page) {
513
-            if ($page instanceof EE_Admin_page_Init) {
514
-                $page_map = $page->get_menu_map();
515
-                // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
516
-                if (is_array($page_map) || empty($page_map)) {
517
-                    new PersistentAdminNotice(
518
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
519
-                        sprintf(
520
-                            __(
521
-                                'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
522
-                                'event_espresso'
523
-                            ),
524
-                            $page->label
525
-                        )
526
-                    );
527
-                    continue;
528
-                }
529
-                // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
530
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
531
-                    throw new EE_Error(
532
-                        sprintf(
533
-                            __(
534
-                                'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
535
-                                'event_espresso'
536
-                            ),
537
-                            $page->label,
538
-                            $page_map
539
-                        )
540
-                    );
541
-                }
542
-                // use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
543
-                if (empty($page_map->maintenance_mode_parent)
544
-                    && EE_Maintenance_Mode::instance()->level()
545
-                       == EE_Maintenance_Mode::level_2_complete_maintenance) {
546
-                    continue;
547
-                }
548
-                // assign to group (remember $page_map has the admin page stored in it).
549
-                $pages_array[ $page_map->menu_group ][] = $page_map;
550
-            }
551
-        }
552
-        if (empty($pages_array)) {
553
-            throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
554
-        }
555
-        // let's sort the groups, make sure it's a valid group, add header (if to show).
556
-        foreach ($pages_array as $group => $menu_maps) {
557
-            // valid_group?
558
-            if (! array_key_exists($group, $menu_groups)) {
559
-                continue;
560
-            }
561
-            // sort pages.
562
-            usort($menu_maps, array($this, '_sort_menu_maps'));
563
-            // prepend header
564
-            array_unshift($menu_maps, $menu_groups[ $group ]);
565
-            // reset $pages_array with prepped data
566
-            $pages_array[ $group ] = $menu_maps;
567
-        }
568
-        // now let's setup the _prepped_menu_maps property
569
-        foreach ($menu_groups as $group => $group_objs) {
570
-            if (isset($pages_array[ $group ])) {
571
-                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]);
572
-            }
573
-        }/**/
574
-    }
575
-
576
-
577
-    /**
578
-     * This method is the "workhorse" for detecting and setting up caffeinated functionality.
579
-     * In this method there are three checks being done:
580
-     * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
581
-     * array) etc.  (new page sets are found in caffeinated/new/{page})
582
-     * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
583
-     * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
584
-     * Extend_Events_Admin_Page extends Events_Admin_Page.
585
-     * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
586
-     * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
587
-     * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
588
-     * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
589
-     * admin_pages)
590
-     *
591
-     * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
592
-     *                              loaded.
593
-     * @return array
594
-     */
595
-    private function _set_caffeinated($installed_refs)
596
-    {
597
-
598
-        // first let's check if there IS a caffeinated folder. If there is not then lets get out.
599
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
600
-            return $installed_refs;
601
-        }
602
-        $this->_define_caffeinated_constants();
603
-        $exclude = array('tickets');
604
-        // okay let's setup an "New" pages first (we'll return installed refs later)
605
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
606
-        if ($new_admin_screens) {
607
-            foreach ($new_admin_screens as $admin_screen) {
608
-                // files and anything in the exclude array need not apply
609
-                if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
610
-                    // these folders represent the different NEW EE admin pages
611
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
612
-                    // set autoloaders for our admin page classes based on included path information
613
-                    EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
614
-                }
615
-            }
616
-        }
617
-        // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
618
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
619
-        if ($extends) {
620
-            foreach ($extends as $extend) {
621
-                if (is_dir($extend)) {
622
-                    $extend_ref = basename($extend);
623
-                    // now let's make sure there is a file that matches the expected format
624
-                    $filename = str_replace(
625
-                        ' ',
626
-                        '_',
627
-                        ucwords(
628
-                            str_replace(
629
-                                '_',
630
-                                ' ',
631
-                                $extend_ref
632
-                            )
633
-                        )
634
-                    );
635
-                    $filename = 'Extend_' . $filename . '_Admin_Page';
636
-                    $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
637
-                        array('\\', '/'),
638
-                        DS,
639
-                        EE_CORE_CAF_ADMIN
640
-                        . 'extend'
641
-                        . DS
642
-                        . $extend_ref
643
-                        . DS
644
-                        . $filename
645
-                        . '.core.php'
646
-                    );
647
-                    $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
648
-                    // set autoloaders for our admin page classes based on included path information
649
-                    EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
650
-                }
651
-            }
652
-        }
653
-        // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
654
-        $ee_admin_hooks = array();
655
-        $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
656
-        if ($hooks) {
657
-            foreach ($hooks as $hook) {
658
-                if (is_readable($hook)) {
659
-                    require_once $hook;
660
-                    $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
661
-                    $classname = str_replace('.class.php', '', $classname);
662
-                    if (class_exists($classname)) {
663
-                        $a = new ReflectionClass($classname);
664
-                        $ee_admin_hooks[] = $a->newInstance();
665
-                    }
666
-                }
667
-            }
668
-        }/**/
669
-        $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
670
-        return $installed_refs;
671
-    }
672
-
673
-
674
-    /**
675
-     * Utility method for sorting the _menu_maps (callback for usort php function)
676
-     *
677
-     * @since  4.4.0
678
-     * @param  EE_Admin_Page_Menu_Map $a menu_map object
679
-     * @param  EE_Admin_Page_Menu_Map $b being compared to
680
-     * @return int    sort order
681
-     */
682
-    private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
683
-    {
684
-        if ($a->menu_order == $b->menu_order) {
685
-            return 0;
686
-        }
687
-        return ($a->menu_order < $b->menu_order) ? -1 : 1;
688
-    }
689
-
690
-
691
-    /**
692
-     * _default_header_link
693
-     * This is just a dummy method to use with header submenu items
694
-     *
695
-     * @return bool false
696
-     */
697
-    public function _default_header_link()
698
-    {
699
-        return false;
700
-    }
27
+	/**
28
+	 * _installed_pages
29
+	 * objects for page_init objects detected and loaded
30
+	 *
31
+	 * @access private
32
+	 * @var \EE_Admin_Page_Init[]
33
+	 */
34
+	private $_installed_pages = array();
35
+
36
+
37
+	/**
38
+	 * this is used to hold the registry of menu slugs for all the installed admin pages
39
+	 *
40
+	 * @var array
41
+	 */
42
+	private $_menu_slugs = array();
43
+
44
+
45
+	/**
46
+	 * _caffeinated_extends
47
+	 * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
48
+	 * pieces needed to do so).  This property is defined in the _set_caffeinated method.
49
+	 *
50
+	 * @var array
51
+	 */
52
+	private $_caffeinated_extends = array();
53
+
54
+
55
+	/**
56
+	 * _current_caf_extend_slug
57
+	 * This property is used for holding the page slug that is required for referencing the correct
58
+	 * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
59
+	 *
60
+	 * @var array
61
+	 */
62
+	private $_current_caf_extend_slug;
63
+
64
+	/**
65
+	 * _prepped_menu_maps
66
+	 * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
67
+	 *
68
+	 * @since  4.4.0
69
+	 * @var EE_Admin_Page_Menu_Map[]
70
+	 */
71
+	private $_prepped_menu_maps = array();
72
+
73
+
74
+	/**
75
+	 * _admin_menu_groups
76
+	 * array that holds the group headings and details for
77
+	 *
78
+	 * @access private
79
+	 * @var array
80
+	 */
81
+	private $_admin_menu_groups = array();
82
+
83
+
84
+	/**
85
+	 * This property will hold the hook file for setting up the filter that does all the connections between admin
86
+	 * pages.
87
+	 *
88
+	 * @var string
89
+	 */
90
+	public $hook_file;
91
+
92
+
93
+	/**
94
+	 * constructor
95
+	 *
96
+	 * @access public
97
+	 * @return \EE_Admin_Page_Loader
98
+	 */
99
+	public function __construct()
100
+	{
101
+		// load menu_map classes
102
+		EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core');
103
+		// define the default "groups" for the admin_pages
104
+		$this->_set_menu_groups();
105
+
106
+		// let's do a scan and see what installed pages we have
107
+		$this->_get_installed_pages();
108
+		// set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
109
+		add_action('admin_menu', array($this, 'set_menus'));
110
+		add_action('network_admin_menu', array($this, 'set_network_menus'));
111
+	}
112
+
113
+
114
+	/**
115
+	 * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
116
+	 * files in the caffeinated folder.
117
+	 *
118
+	 * @access private
119
+	 * @return void
120
+	 */
121
+	private function _define_caffeinated_constants()
122
+	{
123
+		if (! defined('EE_CORE_CAF_ADMIN')) {
124
+			define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
125
+			define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
126
+			define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
127
+			define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
128
+			define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
129
+			define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
130
+		}
131
+	}
132
+
133
+
134
+	/**
135
+	 * _set_menu_groups
136
+	 * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
137
+	 *
138
+	 * @access private
139
+	 * @return void
140
+	 */
141
+	private function _set_menu_groups()
142
+	{
143
+
144
+		// set array of EE_Admin_Page_Menu_Group objects
145
+		$groups = array(
146
+			'main'       => new EE_Admin_Page_Menu_Group(
147
+				array(
148
+					'menu_label'   => __('Main', 'event_espresso'),
149
+					'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
150
+					'menu_slug'    => 'main',
151
+					'capability'   => 'ee_read_ee',
152
+					'menu_order'   => 0,
153
+					'parent_slug'  => 'espresso_events',
154
+				)
155
+			),
156
+			'management' => new EE_Admin_Page_Menu_Group(
157
+				array(
158
+					'menu_label'   => __('Management', 'event_espresso'),
159
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
160
+					'menu_slug'    => 'management',
161
+					'capability'   => 'ee_read_ee',
162
+					'menu_order'   => 10,
163
+					'parent_slug'  => 'espresso_events',
164
+				)
165
+			),
166
+			'settings'   => new EE_Admin_Page_Menu_Group(
167
+				array(
168
+					'menu_label'   => __('Settings', 'event_espresso'),
169
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
170
+					'menu_slug'    => 'settings',
171
+					'capability'   => 'ee_read_ee',
172
+					'menu_order'   => 30,
173
+					'parent_slug'  => 'espresso_events',
174
+				)
175
+			),
176
+			'templates'  => new EE_Admin_Page_Menu_Group(
177
+				array(
178
+					'menu_label'   => __('Templates', 'event_espresso'),
179
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
180
+					'menu_slug'    => 'templates',
181
+					'capability'   => 'ee_read_ee',
182
+					'menu_order'   => 40,
183
+					'parent_slug'  => 'espresso_events',
184
+				)
185
+			),
186
+			'extras'     => new EE_Admin_Page_Menu_Group(
187
+				array(
188
+					'menu_label'              => __('Extras', 'event_espresso'),
189
+					'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
190
+					'menu_slug'               => 'extras',
191
+					'capability'              => 'ee_read_ee',
192
+					'menu_order'              => 50,
193
+					'parent_slug'             => 'espresso_events',
194
+					'maintenance_mode_parent' => 'espresso_maintenance_settings',
195
+				)
196
+			),
197
+			'tools'      => new EE_Admin_Page_Menu_Group(
198
+				array(
199
+					'menu_label'   => __("Tools", "event_espresso"),
200
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
201
+					'menu_slug'    => 'tools',
202
+					'capability'   => 'ee_read_ee',
203
+					'menu_order'   => 60,
204
+					'parent_slug'  => 'espresso_events',
205
+				)
206
+			),
207
+			'addons'     => new EE_Admin_Page_Menu_Group(
208
+				array(
209
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
210
+					'menu_label'   => __('Add-ons', 'event_espresso'),
211
+					'menu_slug'    => 'addons',
212
+					'capability'   => 'ee_read_ee',
213
+					'menu_order'   => 20,
214
+					'parent_slug'  => 'espresso_events',
215
+				)
216
+			),
217
+		);
218
+		$this->_admin_menu_groups = apply_filters(
219
+			'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
220
+			$groups
221
+		);
222
+	}
223
+
224
+
225
+	/**
226
+	 * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
227
+	 * slug.  The other utility with this function is it validates that all the groups are instances of
228
+	 * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
229
+	 *
230
+	 * @since  4.4.0
231
+	 * @throws \EE_Error
232
+	 * @return EE_Admin_Page_Menu_Group[]
233
+	 */
234
+	private function _rearrange_menu_groups()
235
+	{
236
+		$groups = array();
237
+		// first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
238
+		usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
239
+		foreach ($this->_admin_menu_groups as $group) {
240
+			if (! $group instanceof EE_Admin_Page_Menu_Group) {
241
+				throw new EE_Error(
242
+					sprintf(
243
+						__(
244
+							'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
245
+							'event_espresso'
246
+						),
247
+						print_r($group, true)
248
+					)
249
+				);
250
+			}
251
+			$groups[ $group->menu_slug ] = $group;
252
+		}
253
+		return $groups;
254
+	}
255
+
256
+
257
+	/**
258
+	 * _get_installed_pages
259
+	 * This just gets the list of installed EE_Admin_pages.
260
+	 *
261
+	 * @access private
262
+	 * @throws EE_Error
263
+	 * @return void
264
+	 */
265
+	private function _get_installed_pages()
266
+	{
267
+		$installed_refs = array();
268
+		$exclude = array('assets', 'templates');
269
+		// grab everything in the  admin core directory
270
+		$admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
271
+		if ($admin_screens) {
272
+			foreach ($admin_screens as $admin_screen) {
273
+				// files and anything in the exclude array need not apply
274
+				if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
275
+					// these folders represent the different EE admin pages
276
+					$installed_refs[ basename($admin_screen) ] = $admin_screen;
277
+				}
278
+			}
279
+		}
280
+		if (empty($installed_refs)) {
281
+			$error_msg[] = __(
282
+				'There are no EE_Admin pages detected, it looks like EE did not install properly',
283
+				'event_espresso'
284
+			);
285
+			$error_msg[] = $error_msg[0] . "\r\n"
286
+						   . sprintf(
287
+							   __(
288
+								   'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
289
+								   'event_espresso'
290
+							   ),
291
+							   EE_ADMIN_PAGES
292
+						   );
293
+			throw new EE_Error(implode('||', $error_msg));
294
+		}
295
+		// this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
296
+		$installed_refs = $this->_set_caffeinated($installed_refs);
297
+		// allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
298
+		$installed_refs = apply_filters(
299
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
300
+			$installed_refs
301
+		);
302
+		$this->_caffeinated_extends = apply_filters(
303
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
304
+			$this->_caffeinated_extends
305
+		);
306
+		// loop through admin pages and setup the $_installed_pages array.
307
+		$hooks_ref = array();
308
+		foreach ($installed_refs as $page => $path) {
309
+			// set autoloaders for our admin page classes based on included path information
310
+			EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
311
+			// build list of installed pages
312
+			$this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
313
+			// verify returned object
314
+			if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
315
+				if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
316
+					continue;
317
+				}
318
+				// skip if in full maintenance mode and maintenance_mode_parent is set
319
+				$maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
320
+				if (empty($maintenance_mode_parent)
321
+					&& EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
322
+				) {
323
+					unset($installed_refs[ $page ]);
324
+					continue;
325
+				}
326
+				$menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
327
+				$this->_menu_slugs[ $menu_slug ] = $page;
328
+				// flag for register hooks on extended pages b/c extended pages use the default INIT.
329
+				$extend = false;
330
+				// now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
331
+				if (isset($this->_caffeinated_extends[ $page ])) {
332
+					$this->_current_caf_extend_slug = $page;
333
+					$admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
334
+					$caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
335
+					$caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
336
+					add_filter(
337
+						"FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
338
+						function ($path_to_file) use ($caf_path) {
339
+							return $caf_path;
340
+						}
341
+					);
342
+					add_filter(
343
+						"FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
344
+						function ($admin_page) use ($caf_admin_page) {
345
+							return $caf_admin_page;
346
+						}
347
+					);
348
+					$extend = true;
349
+				}
350
+				// let's do the registered hooks
351
+				$extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
352
+				$hooks_ref = array_merge($hooks_ref, $extended_hooks);
353
+			}
354
+		}
355
+		// the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
356
+		// first make sure we've got unique values
357
+		$hooks_ref = array_unique($hooks_ref);
358
+		// now let's loop and require!
359
+		foreach ($hooks_ref as $path) {
360
+			require_once($path);
361
+		}
362
+		// make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
363
+		global $ee_menu_slugs;
364
+		$ee_menu_slugs = $this->_menu_slugs;
365
+		// we need to loop again to run any early code
366
+		foreach ($installed_refs as $page => $path) {
367
+			if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
368
+				$this->_installed_pages[ $page ]->do_initial_loads();
369
+			}
370
+		}
371
+		do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
372
+	}
373
+
374
+
375
+	/**
376
+	 * get_admin_page_object
377
+	 *
378
+	 * @param string $page_slug
379
+	 * @return EE_Admin_Page
380
+	 */
381
+	public function get_admin_page_object($page_slug = '')
382
+	{
383
+		if (isset($this->_installed_pages[ $page_slug ])) {
384
+			return $this->_installed_pages[ $page_slug ]->loaded_page_object();
385
+		}
386
+		return null;
387
+	}
388
+
389
+
390
+	/**
391
+	 * _get_classname_for_admin_page
392
+	 * generates an "Admin Page" class based on the directory  name
393
+	 *
394
+	 * @param $dir_name
395
+	 * @return string
396
+	 */
397
+	private function _get_classname_for_admin_page($dir_name = '')
398
+	{
399
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
400
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
401
+	}
402
+
403
+
404
+	/**
405
+	 * _get_classname_for_admin_init_page
406
+	 * generates an "Admin Page Init" class based on the directory  name
407
+	 *
408
+	 * @param $dir_name
409
+	 * @return string
410
+	 */
411
+	private function _get_classname_for_admin_init_page($dir_name = '')
412
+	{
413
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
414
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
415
+	}
416
+
417
+
418
+	/**
419
+	 * _load_admin_page
420
+	 * Loads and instantiates page_init object for a single EE_admin page.
421
+	 *
422
+	 * @param  string $page page_reference
423
+	 * @param string  $path
424
+	 * @throws EE_Error
425
+	 * @return object|bool  return page object if valid, bool false if not.
426
+	 */
427
+	private function _load_admin_page($page = '', $path = '')
428
+	{
429
+		$class_name = $this->_get_classname_for_admin_init_page($page);
430
+		EE_Registry::instance()->load_file($path, $class_name, 'core');
431
+		if (! class_exists($class_name)) {
432
+			$inner_error_msg = '<br />'
433
+							   . sprintf(
434
+								   esc_html__(
435
+									   'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
436
+									   'event_espresso'
437
+								   ),
438
+								   '<strong>' . $class_name . '</strong>'
439
+							   );
440
+			$error_msg[] = sprintf(
441
+				__('Something went wrong with loading the %s admin page.', 'event_espresso'),
442
+				$page
443
+			);
444
+			$error_msg[] = $error_msg[0]
445
+						   . "\r\n"
446
+						   . sprintf(
447
+							   esc_html__(
448
+								   'There is no Init class in place for the %s admin page.',
449
+								   'event_espresso'
450
+							   ),
451
+							   $page
452
+						   )
453
+						   . $inner_error_msg;
454
+			throw new EE_Error(implode('||', $error_msg));
455
+		}
456
+		$a = new ReflectionClass($class_name);
457
+		return $a->newInstance();
458
+	}
459
+
460
+
461
+	/**
462
+	 * set_menus
463
+	 * This method sets up the menus for EE Admin Pages
464
+	 *
465
+	 * @access private
466
+	 * @return void
467
+	 */
468
+	public function set_menus()
469
+	{
470
+		// prep the menu pages (sort, group.)
471
+		$this->_prep_pages();
472
+		foreach ($this->_prepped_menu_maps as $menu_map) {
473
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
474
+				$menu_map->add_menu_page(false);
475
+			}
476
+		}
477
+	}
478
+
479
+
480
+	/**
481
+	 * set_network_menus
482
+	 * This method sets up the menus for network EE Admin Pages.
483
+	 * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
484
+	 * are only added to the menu map if they are intended for the admin menu
485
+	 *
486
+	 * @return void
487
+	 */
488
+	public function set_network_menus()
489
+	{
490
+		$this->_prep_pages();
491
+		foreach ($this->_prepped_menu_maps as $menu_map) {
492
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
493
+				$menu_map->add_menu_page(true);
494
+			}
495
+		}
496
+	}
497
+
498
+
499
+	/**
500
+	 * _prep_pages
501
+	 * sets the _prepped_menu_maps property
502
+	 *
503
+	 * @access private
504
+	 * @throws EE_Error
505
+	 * @return void
506
+	 */
507
+	private function _prep_pages()
508
+	{
509
+		$pages_array = array();
510
+		// rearrange _admin_menu_groups to be indexed by group slug.
511
+		$menu_groups = $this->_rearrange_menu_groups();
512
+		foreach ($this->_installed_pages as $page) {
513
+			if ($page instanceof EE_Admin_page_Init) {
514
+				$page_map = $page->get_menu_map();
515
+				// if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
516
+				if (is_array($page_map) || empty($page_map)) {
517
+					new PersistentAdminNotice(
518
+						'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
519
+						sprintf(
520
+							__(
521
+								'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
522
+								'event_espresso'
523
+							),
524
+							$page->label
525
+						)
526
+					);
527
+					continue;
528
+				}
529
+				// if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
530
+				if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
531
+					throw new EE_Error(
532
+						sprintf(
533
+							__(
534
+								'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
535
+								'event_espresso'
536
+							),
537
+							$page->label,
538
+							$page_map
539
+						)
540
+					);
541
+				}
542
+				// use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
543
+				if (empty($page_map->maintenance_mode_parent)
544
+					&& EE_Maintenance_Mode::instance()->level()
545
+					   == EE_Maintenance_Mode::level_2_complete_maintenance) {
546
+					continue;
547
+				}
548
+				// assign to group (remember $page_map has the admin page stored in it).
549
+				$pages_array[ $page_map->menu_group ][] = $page_map;
550
+			}
551
+		}
552
+		if (empty($pages_array)) {
553
+			throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
554
+		}
555
+		// let's sort the groups, make sure it's a valid group, add header (if to show).
556
+		foreach ($pages_array as $group => $menu_maps) {
557
+			// valid_group?
558
+			if (! array_key_exists($group, $menu_groups)) {
559
+				continue;
560
+			}
561
+			// sort pages.
562
+			usort($menu_maps, array($this, '_sort_menu_maps'));
563
+			// prepend header
564
+			array_unshift($menu_maps, $menu_groups[ $group ]);
565
+			// reset $pages_array with prepped data
566
+			$pages_array[ $group ] = $menu_maps;
567
+		}
568
+		// now let's setup the _prepped_menu_maps property
569
+		foreach ($menu_groups as $group => $group_objs) {
570
+			if (isset($pages_array[ $group ])) {
571
+				$this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]);
572
+			}
573
+		}/**/
574
+	}
575
+
576
+
577
+	/**
578
+	 * This method is the "workhorse" for detecting and setting up caffeinated functionality.
579
+	 * In this method there are three checks being done:
580
+	 * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
581
+	 * array) etc.  (new page sets are found in caffeinated/new/{page})
582
+	 * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
583
+	 * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
584
+	 * Extend_Events_Admin_Page extends Events_Admin_Page.
585
+	 * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
586
+	 * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
587
+	 * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
588
+	 * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
589
+	 * admin_pages)
590
+	 *
591
+	 * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
592
+	 *                              loaded.
593
+	 * @return array
594
+	 */
595
+	private function _set_caffeinated($installed_refs)
596
+	{
597
+
598
+		// first let's check if there IS a caffeinated folder. If there is not then lets get out.
599
+		if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
600
+			return $installed_refs;
601
+		}
602
+		$this->_define_caffeinated_constants();
603
+		$exclude = array('tickets');
604
+		// okay let's setup an "New" pages first (we'll return installed refs later)
605
+		$new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
606
+		if ($new_admin_screens) {
607
+			foreach ($new_admin_screens as $admin_screen) {
608
+				// files and anything in the exclude array need not apply
609
+				if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
610
+					// these folders represent the different NEW EE admin pages
611
+					$installed_refs[ basename($admin_screen) ] = $admin_screen;
612
+					// set autoloaders for our admin page classes based on included path information
613
+					EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
614
+				}
615
+			}
616
+		}
617
+		// let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
618
+		$extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
619
+		if ($extends) {
620
+			foreach ($extends as $extend) {
621
+				if (is_dir($extend)) {
622
+					$extend_ref = basename($extend);
623
+					// now let's make sure there is a file that matches the expected format
624
+					$filename = str_replace(
625
+						' ',
626
+						'_',
627
+						ucwords(
628
+							str_replace(
629
+								'_',
630
+								' ',
631
+								$extend_ref
632
+							)
633
+						)
634
+					);
635
+					$filename = 'Extend_' . $filename . '_Admin_Page';
636
+					$this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
637
+						array('\\', '/'),
638
+						DS,
639
+						EE_CORE_CAF_ADMIN
640
+						. 'extend'
641
+						. DS
642
+						. $extend_ref
643
+						. DS
644
+						. $filename
645
+						. '.core.php'
646
+					);
647
+					$this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
648
+					// set autoloaders for our admin page classes based on included path information
649
+					EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
650
+				}
651
+			}
652
+		}
653
+		// let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
654
+		$ee_admin_hooks = array();
655
+		$hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
656
+		if ($hooks) {
657
+			foreach ($hooks as $hook) {
658
+				if (is_readable($hook)) {
659
+					require_once $hook;
660
+					$classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
661
+					$classname = str_replace('.class.php', '', $classname);
662
+					if (class_exists($classname)) {
663
+						$a = new ReflectionClass($classname);
664
+						$ee_admin_hooks[] = $a->newInstance();
665
+					}
666
+				}
667
+			}
668
+		}/**/
669
+		$ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
670
+		return $installed_refs;
671
+	}
672
+
673
+
674
+	/**
675
+	 * Utility method for sorting the _menu_maps (callback for usort php function)
676
+	 *
677
+	 * @since  4.4.0
678
+	 * @param  EE_Admin_Page_Menu_Map $a menu_map object
679
+	 * @param  EE_Admin_Page_Menu_Map $b being compared to
680
+	 * @return int    sort order
681
+	 */
682
+	private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
683
+	{
684
+		if ($a->menu_order == $b->menu_order) {
685
+			return 0;
686
+		}
687
+		return ($a->menu_order < $b->menu_order) ? -1 : 1;
688
+	}
689
+
690
+
691
+	/**
692
+	 * _default_header_link
693
+	 * This is just a dummy method to use with header submenu items
694
+	 *
695
+	 * @return bool false
696
+	 */
697
+	public function _default_header_link()
698
+	{
699
+		return false;
700
+	}
701 701
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
      */
121 121
     private function _define_caffeinated_constants()
122 122
     {
123
-        if (! defined('EE_CORE_CAF_ADMIN')) {
124
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
125
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
126
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
127
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
128
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
129
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
123
+        if ( ! defined('EE_CORE_CAF_ADMIN')) {
124
+            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/');
125
+            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/');
126
+            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/');
127
+            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/');
128
+            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/');
129
+            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/');
130 130
         }
131 131
     }
132 132
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
238 238
         usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
239 239
         foreach ($this->_admin_menu_groups as $group) {
240
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
240
+            if ( ! $group instanceof EE_Admin_Page_Menu_Group) {
241 241
                 throw new EE_Error(
242 242
                     sprintf(
243 243
                         __(
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
                     )
249 249
                 );
250 250
             }
251
-            $groups[ $group->menu_slug ] = $group;
251
+            $groups[$group->menu_slug] = $group;
252 252
         }
253 253
         return $groups;
254 254
     }
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
         $installed_refs = array();
268 268
         $exclude = array('assets', 'templates');
269 269
         // grab everything in the  admin core directory
270
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
270
+        $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR);
271 271
         if ($admin_screens) {
272 272
             foreach ($admin_screens as $admin_screen) {
273 273
                 // files and anything in the exclude array need not apply
274 274
                 if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
275 275
                     // these folders represent the different EE admin pages
276
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
276
+                    $installed_refs[basename($admin_screen)] = $admin_screen;
277 277
                 }
278 278
             }
279 279
         }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                 'There are no EE_Admin pages detected, it looks like EE did not install properly',
283 283
                 'event_espresso'
284 284
             );
285
-            $error_msg[] = $error_msg[0] . "\r\n"
285
+            $error_msg[] = $error_msg[0]."\r\n"
286 286
                            . sprintf(
287 287
                                __(
288 288
                                    'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
@@ -309,46 +309,46 @@  discard block
 block discarded – undo
309 309
             // set autoloaders for our admin page classes based on included path information
310 310
             EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
311 311
             // build list of installed pages
312
-            $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
312
+            $this->_installed_pages[$page] = $this->_load_admin_page($page, $path);
313 313
             // verify returned object
314
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
315
-                if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
314
+            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
315
+                if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
316 316
                     continue;
317 317
                 }
318 318
                 // skip if in full maintenance mode and maintenance_mode_parent is set
319
-                $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
319
+                $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent;
320 320
                 if (empty($maintenance_mode_parent)
321 321
                     && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
322 322
                 ) {
323
-                    unset($installed_refs[ $page ]);
323
+                    unset($installed_refs[$page]);
324 324
                     continue;
325 325
                 }
326
-                $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
327
-                $this->_menu_slugs[ $menu_slug ] = $page;
326
+                $menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug;
327
+                $this->_menu_slugs[$menu_slug] = $page;
328 328
                 // flag for register hooks on extended pages b/c extended pages use the default INIT.
329 329
                 $extend = false;
330 330
                 // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
331
-                if (isset($this->_caffeinated_extends[ $page ])) {
331
+                if (isset($this->_caffeinated_extends[$page])) {
332 332
                     $this->_current_caf_extend_slug = $page;
333
-                    $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
334
-                    $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
335
-                    $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
333
+                    $admin_page_name = $this->_installed_pages[$page]->get_admin_page_name();
334
+                    $caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path'];
335
+                    $caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page'];
336 336
                     add_filter(
337 337
                         "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
338
-                        function ($path_to_file) use ($caf_path) {
338
+                        function($path_to_file) use ($caf_path) {
339 339
                             return $caf_path;
340 340
                         }
341 341
                     );
342 342
                     add_filter(
343 343
                         "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
344
-                        function ($admin_page) use ($caf_admin_page) {
344
+                        function($admin_page) use ($caf_admin_page) {
345 345
                             return $caf_admin_page;
346 346
                         }
347 347
                     );
348 348
                     $extend = true;
349 349
                 }
350 350
                 // let's do the registered hooks
351
-                $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
351
+                $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend);
352 352
                 $hooks_ref = array_merge($hooks_ref, $extended_hooks);
353 353
             }
354 354
         }
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
         $ee_menu_slugs = $this->_menu_slugs;
365 365
         // we need to loop again to run any early code
366 366
         foreach ($installed_refs as $page => $path) {
367
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
368
-                $this->_installed_pages[ $page ]->do_initial_loads();
367
+            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
368
+                $this->_installed_pages[$page]->do_initial_loads();
369 369
             }
370 370
         }
371 371
         do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
      */
381 381
     public function get_admin_page_object($page_slug = '')
382 382
     {
383
-        if (isset($this->_installed_pages[ $page_slug ])) {
384
-            return $this->_installed_pages[ $page_slug ]->loaded_page_object();
383
+        if (isset($this->_installed_pages[$page_slug])) {
384
+            return $this->_installed_pages[$page_slug]->loaded_page_object();
385 385
         }
386 386
         return null;
387 387
     }
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
     private function _get_classname_for_admin_page($dir_name = '')
398 398
     {
399 399
         $class_name = str_replace('_', ' ', strtolower($dir_name));
400
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
400
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page';
401 401
     }
402 402
 
403 403
 
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
     private function _get_classname_for_admin_init_page($dir_name = '')
412 412
     {
413 413
         $class_name = str_replace('_', ' ', strtolower($dir_name));
414
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
414
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init';
415 415
     }
416 416
 
417 417
 
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
     {
429 429
         $class_name = $this->_get_classname_for_admin_init_page($page);
430 430
         EE_Registry::instance()->load_file($path, $class_name, 'core');
431
-        if (! class_exists($class_name)) {
431
+        if ( ! class_exists($class_name)) {
432 432
             $inner_error_msg = '<br />'
433 433
                                . sprintf(
434 434
                                    esc_html__(
435 435
                                        'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
436 436
                                        'event_espresso'
437 437
                                    ),
438
-                                   '<strong>' . $class_name . '</strong>'
438
+                                   '<strong>'.$class_name.'</strong>'
439 439
                                );
440 440
             $error_msg[] = sprintf(
441 441
                 __('Something went wrong with loading the %s admin page.', 'event_espresso'),
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
                 // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
516 516
                 if (is_array($page_map) || empty($page_map)) {
517 517
                     new PersistentAdminNotice(
518
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
518
+                        'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION,
519 519
                         sprintf(
520 520
                             __(
521 521
                                 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
                     continue;
528 528
                 }
529 529
                 // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
530
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
530
+                if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) {
531 531
                     throw new EE_Error(
532 532
                         sprintf(
533 533
                             __(
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
                     continue;
547 547
                 }
548 548
                 // assign to group (remember $page_map has the admin page stored in it).
549
-                $pages_array[ $page_map->menu_group ][] = $page_map;
549
+                $pages_array[$page_map->menu_group][] = $page_map;
550 550
             }
551 551
         }
552 552
         if (empty($pages_array)) {
@@ -555,20 +555,20 @@  discard block
 block discarded – undo
555 555
         // let's sort the groups, make sure it's a valid group, add header (if to show).
556 556
         foreach ($pages_array as $group => $menu_maps) {
557 557
             // valid_group?
558
-            if (! array_key_exists($group, $menu_groups)) {
558
+            if ( ! array_key_exists($group, $menu_groups)) {
559 559
                 continue;
560 560
             }
561 561
             // sort pages.
562 562
             usort($menu_maps, array($this, '_sort_menu_maps'));
563 563
             // prepend header
564
-            array_unshift($menu_maps, $menu_groups[ $group ]);
564
+            array_unshift($menu_maps, $menu_groups[$group]);
565 565
             // reset $pages_array with prepped data
566
-            $pages_array[ $group ] = $menu_maps;
566
+            $pages_array[$group] = $menu_maps;
567 567
         }
568 568
         // now let's setup the _prepped_menu_maps property
569 569
         foreach ($menu_groups as $group => $group_objs) {
570
-            if (isset($pages_array[ $group ])) {
571
-                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]);
570
+            if (isset($pages_array[$group])) {
571
+                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]);
572 572
             }
573 573
         }/**/
574 574
     }
@@ -596,26 +596,26 @@  discard block
 block discarded – undo
596 596
     {
597 597
 
598 598
         // first let's check if there IS a caffeinated folder. If there is not then lets get out.
599
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
599
+        if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated'.DS.'admin') || (defined('EE_DECAF') && EE_DECAF)) {
600 600
             return $installed_refs;
601 601
         }
602 602
         $this->_define_caffeinated_constants();
603 603
         $exclude = array('tickets');
604 604
         // okay let's setup an "New" pages first (we'll return installed refs later)
605
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
605
+        $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR);
606 606
         if ($new_admin_screens) {
607 607
             foreach ($new_admin_screens as $admin_screen) {
608 608
                 // files and anything in the exclude array need not apply
609 609
                 if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
610 610
                     // these folders represent the different NEW EE admin pages
611
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
611
+                    $installed_refs[basename($admin_screen)] = $admin_screen;
612 612
                     // set autoloaders for our admin page classes based on included path information
613 613
                     EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
614 614
                 }
615 615
             }
616 616
         }
617 617
         // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
618
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
618
+        $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR);
619 619
         if ($extends) {
620 620
             foreach ($extends as $extend) {
621 621
                 if (is_dir($extend)) {
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
                             )
633 633
                         )
634 634
                     );
635
-                    $filename = 'Extend_' . $filename . '_Admin_Page';
636
-                    $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
635
+                    $filename = 'Extend_'.$filename.'_Admin_Page';
636
+                    $this->_caffeinated_extends[$extend_ref]['path'] = str_replace(
637 637
                         array('\\', '/'),
638 638
                         DS,
639 639
                         EE_CORE_CAF_ADMIN
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
                         . $filename
645 645
                         . '.core.php'
646 646
                     );
647
-                    $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
647
+                    $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename;
648 648
                     // set autoloaders for our admin page classes based on included path information
649 649
                     EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
650 650
                 }
@@ -652,12 +652,12 @@  discard block
 block discarded – undo
652 652
         }
653 653
         // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
654 654
         $ee_admin_hooks = array();
655
-        $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
655
+        $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php');
656 656
         if ($hooks) {
657 657
             foreach ($hooks as $hook) {
658 658
                 if (is_readable($hook)) {
659 659
                     require_once $hook;
660
-                    $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
660
+                    $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook);
661 661
                     $classname = str_replace('.class.php', '', $classname);
662 662
                     if (class_exists($classname)) {
663 663
                         $a = new ReflectionClass($classname);
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Menu_Map.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@
 block discarded – undo
124 124
      *
125 125
      * @param  array $menu_args           An array of arguments used to setup the menu
126 126
      *                                    properties on construct.
127
-     * @param  array $required            An array of keys that should be in the $menu_args, this
127
+     * @param  string[] $required            An array of keys that should be in the $menu_args, this
128 128
      *                                    is used to validate that the items that should be defined
129 129
      *                                    are present.
130 130
      * @return void
Please login to merge, or discard this patch.
Indentation   +357 added lines, -357 removed lines patch added patch discarded remove patch
@@ -11,257 +11,257 @@  discard block
 block discarded – undo
11 11
 {
12 12
 
13 13
 
14
-    /**
15
-     * The title for the menu page. (the page the menu links to)
16
-     *
17
-     * @since  4.4.0
18
-     * @var string
19
-     */
20
-    public $title;
21
-
22
-
23
-    /**
24
-     * The label for the menu item. (What shows up in the actual menu).
25
-     *
26
-     * @since 4.4.0
27
-     * @var string
28
-     */
29
-    public $menu_label;
30
-
31
-
32
-    /**
33
-     * What menu item is the parent of this menu item.
34
-     *
35
-     * @since 4.4.0
36
-     * @var string
37
-     */
38
-    public $parent_slug;
39
-
40
-
41
-    /**
42
-     * What capability is required to access this page.
43
-     *
44
-     * @since 4.4.0
45
-     * @var string
46
-     */
47
-    public $capability = 'administrator';
48
-
49
-
50
-    /**
51
-     * What slug should be used to reference this menu item.
52
-     *
53
-     * @since 4.4.0
54
-     * @var string
55
-     */
56
-    public $menu_slug;
57
-
58
-
59
-    /**
60
-     * The callback for displaying the page that the menu references.
61
-     *
62
-     * @since 4.4.0
63
-     * @var string
64
-     */
65
-    public $menu_callback;
66
-
67
-
68
-    /**
69
-     * The EE_Admin_Page_Init attached to this map.
70
-     *
71
-     * @var EE_Admin_Page_Init
72
-     */
73
-    public $admin_init_page;
74
-
75
-
76
-    /**
77
-     * The EE specific group this menu item belongs in (group slug).
78
-     *
79
-     * @since 4.4.0
80
-     * @var string
81
-     */
82
-    public $menu_group;
83
-
84
-
85
-    /**
86
-     * What order this item should be in the menu.
87
-     *
88
-     * @since 4.4.0
89
-     * @var int
90
-     */
91
-    public $menu_order;
92
-
93
-
94
-    const NONE = 0;
95
-    const BLOG_ADMIN_ONLY = 1;
96
-    const BLOG_AND_NETWORK_ADMIN = 2;
97
-    const NETWORK_ADMIN_ONLY = 3;
98
-
99
-
100
-    /**
101
-     * Whether this item is displayed in the menu or not.
102
-     * Sometimes an EE Admin Page needs to register itself but is not accessible via the WordPress
103
-     * admin menu.
104
-     *
105
-     * @since 4.4.0
106
-     * @var int
107
-     */
108
-    public $show_on_menu = self::BLOG_ADMIN_ONLY;
109
-
110
-
111
-    /**
112
-     * Menu maps can define a parent slug that gets used instead of the main parent slug for the menu when
113
-     * EE_Maintenance_Mode::level_2_complete_maintenance is active.
114
-     *
115
-     * @var bool
116
-     */
117
-    public $maintenance_mode_parent = '';
118
-
119
-
120
-    /**
121
-     * Constructor.
122
-     *
123
-     * @since 4.4.0
124
-     *
125
-     * @param  array $menu_args           An array of arguments used to setup the menu
126
-     *                                    properties on construct.
127
-     * @param  array $required            An array of keys that should be in the $menu_args, this
128
-     *                                    is used to validate that the items that should be defined
129
-     *                                    are present.
130
-     * @return void
131
-     */
132
-    public function __construct($menu_args, $required)
133
-    {
134
-        // filter all args before processing so plugins can manipulate various settings for menus.
135
-        $menu_args = apply_filters(
136
-            'FHEE__EE_Admin_Page_Menu_Map__construct__menu_args',
137
-            $menu_args,
138
-            $required,
139
-            get_class($this)
140
-        );
141
-
142
-
143
-        // verify that required keys are present in the incoming array.
144
-        $missing = array_diff((array) $required, array_keys((array) $menu_args));
145
-
146
-        if (! empty($missing)) {
147
-            throw new EE_Error(
148
-                sprintf(
149
-                    __(
150
-                        '%s is missing some expected keys in the argument array.  The following keys are missing: %s',
151
-                        'event_espresso'
152
-                    ),
153
-                    get_class($this),
154
-                    implode(', ', $missing)
155
-                )
156
-            );
157
-        }
158
-
159
-        // made it here okay, so let's set the properties!
160
-        foreach ($menu_args as $prop => $value) {
161
-            switch ($prop) {
162
-                case 'show_on_menu':
163
-                    $value = (int) $value;
164
-                    break;
165
-                case 'admin_init_page':
166
-                    if (in_array('admin_init_page', $required) && ! $value instanceof EE_Admin_Page_Init) {
167
-                        throw new EE_Error(
168
-                            sprintf(
169
-                                __(
170
-                                    'The value for the "admin_init_page" argument must be an instance of an EE_Admin_Page_Init object.  Instead %s was given as the value.',
171
-                                    'event_espresso'
172
-                                ),
173
-                                print_r($value, true)
174
-                            )
175
-                        );
176
-                    }
177
-                    break;
178
-                case 'menu_callback':
179
-                    break;
180
-
181
-                default:
182
-                    $value = (string) $value;
183
-                    break;
184
-            }
185
-            if (! EEH_Class_Tools::has_property($this, $prop)) {
186
-                throw new EE_Error(
187
-                    sprintf(
188
-                        __(
189
-                            'The $menu_args coming into %s has a index key (%s) representing a property that is not defined by the class.  Perhaps there is a typo?',
190
-                            'event_espresso'
191
-                        ),
192
-                        get_class($this),
193
-                        $prop
194
-                    )
195
-                );
196
-            }
197
-            $this->{$prop} = $value;
198
-        }
199
-
200
-        // filter capabilities (both static and dynamic)
201
-        $this->capability = apply_filters('FHEE_management_capability', $this->capability, null);
202
-        $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null);
203
-
204
-        // Might need to change parent slug depending on maintenance mode.
205
-        if (! empty($this->maintenance_mode_parent)
206
-            && EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
207
-        ) {
208
-            $this->parent_slug = $this->maintenance_mode_parent;
209
-        }
210
-
211
-        // if empty menu_callback let's set default (but only if we have admin page init object)
212
-        if (empty($this->menu_callback) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
213
-            $this->menu_callback = array($this->admin_init_page, 'initialize_admin_page');
214
-        }
215
-    }
216
-
217
-
218
-    /**
219
-     * This method should define how the menu page gets added for this particular item
220
-     * and go ahead and define it.  Note that child classes MUST also return the result of
221
-     * the function used to register the WordPress admin page (the wp_page_slug string)
222
-     *
223
-     * @since  4.4.0
224
-     * @return string wp_page_slug.
225
-     */
226
-    abstract protected function _add_menu_page();
227
-
228
-
229
-    /**
230
-     * Called by client code to use this menu map for registering a WordPress admin page
231
-     *
232
-     * @param boolean $network_admin whether this is being added to the network admin page or not
233
-     * @since  4.4.0
234
-     */
235
-    public function add_menu_page($network_admin = false)
236
-    {
237
-
238
-        $show_on_menu_int = (int) $this->show_on_menu;
239
-        if (($network_admin
240
-             && in_array(
241
-                 $show_on_menu_int,
242
-                 array(self::BLOG_AND_NETWORK_ADMIN, self::NETWORK_ADMIN_ONLY),
243
-                 true
244
-             ))
245
-            ||
246
-            (! $network_admin
247
-             && in_array(
248
-                 $show_on_menu_int,
249
-                 array(self::BLOG_AND_NETWORK_ADMIN, self::BLOG_ADMIN_ONLY),
250
-                 true
251
-             ))) {
252
-            $wp_page_slug = $this->_add_menu_page();
253
-        } else {
254
-            $wp_page_slug = '';
255
-        }
256
-
257
-        if (! empty($wp_page_slug) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
258
-            try {
259
-                $this->admin_init_page->set_page_dependencies($wp_page_slug);
260
-            } catch (EE_Error $e) {
261
-                $e->get_error();
262
-            }
263
-        }
264
-    }
14
+	/**
15
+	 * The title for the menu page. (the page the menu links to)
16
+	 *
17
+	 * @since  4.4.0
18
+	 * @var string
19
+	 */
20
+	public $title;
21
+
22
+
23
+	/**
24
+	 * The label for the menu item. (What shows up in the actual menu).
25
+	 *
26
+	 * @since 4.4.0
27
+	 * @var string
28
+	 */
29
+	public $menu_label;
30
+
31
+
32
+	/**
33
+	 * What menu item is the parent of this menu item.
34
+	 *
35
+	 * @since 4.4.0
36
+	 * @var string
37
+	 */
38
+	public $parent_slug;
39
+
40
+
41
+	/**
42
+	 * What capability is required to access this page.
43
+	 *
44
+	 * @since 4.4.0
45
+	 * @var string
46
+	 */
47
+	public $capability = 'administrator';
48
+
49
+
50
+	/**
51
+	 * What slug should be used to reference this menu item.
52
+	 *
53
+	 * @since 4.4.0
54
+	 * @var string
55
+	 */
56
+	public $menu_slug;
57
+
58
+
59
+	/**
60
+	 * The callback for displaying the page that the menu references.
61
+	 *
62
+	 * @since 4.4.0
63
+	 * @var string
64
+	 */
65
+	public $menu_callback;
66
+
67
+
68
+	/**
69
+	 * The EE_Admin_Page_Init attached to this map.
70
+	 *
71
+	 * @var EE_Admin_Page_Init
72
+	 */
73
+	public $admin_init_page;
74
+
75
+
76
+	/**
77
+	 * The EE specific group this menu item belongs in (group slug).
78
+	 *
79
+	 * @since 4.4.0
80
+	 * @var string
81
+	 */
82
+	public $menu_group;
83
+
84
+
85
+	/**
86
+	 * What order this item should be in the menu.
87
+	 *
88
+	 * @since 4.4.0
89
+	 * @var int
90
+	 */
91
+	public $menu_order;
92
+
93
+
94
+	const NONE = 0;
95
+	const BLOG_ADMIN_ONLY = 1;
96
+	const BLOG_AND_NETWORK_ADMIN = 2;
97
+	const NETWORK_ADMIN_ONLY = 3;
98
+
99
+
100
+	/**
101
+	 * Whether this item is displayed in the menu or not.
102
+	 * Sometimes an EE Admin Page needs to register itself but is not accessible via the WordPress
103
+	 * admin menu.
104
+	 *
105
+	 * @since 4.4.0
106
+	 * @var int
107
+	 */
108
+	public $show_on_menu = self::BLOG_ADMIN_ONLY;
109
+
110
+
111
+	/**
112
+	 * Menu maps can define a parent slug that gets used instead of the main parent slug for the menu when
113
+	 * EE_Maintenance_Mode::level_2_complete_maintenance is active.
114
+	 *
115
+	 * @var bool
116
+	 */
117
+	public $maintenance_mode_parent = '';
118
+
119
+
120
+	/**
121
+	 * Constructor.
122
+	 *
123
+	 * @since 4.4.0
124
+	 *
125
+	 * @param  array $menu_args           An array of arguments used to setup the menu
126
+	 *                                    properties on construct.
127
+	 * @param  array $required            An array of keys that should be in the $menu_args, this
128
+	 *                                    is used to validate that the items that should be defined
129
+	 *                                    are present.
130
+	 * @return void
131
+	 */
132
+	public function __construct($menu_args, $required)
133
+	{
134
+		// filter all args before processing so plugins can manipulate various settings for menus.
135
+		$menu_args = apply_filters(
136
+			'FHEE__EE_Admin_Page_Menu_Map__construct__menu_args',
137
+			$menu_args,
138
+			$required,
139
+			get_class($this)
140
+		);
141
+
142
+
143
+		// verify that required keys are present in the incoming array.
144
+		$missing = array_diff((array) $required, array_keys((array) $menu_args));
145
+
146
+		if (! empty($missing)) {
147
+			throw new EE_Error(
148
+				sprintf(
149
+					__(
150
+						'%s is missing some expected keys in the argument array.  The following keys are missing: %s',
151
+						'event_espresso'
152
+					),
153
+					get_class($this),
154
+					implode(', ', $missing)
155
+				)
156
+			);
157
+		}
158
+
159
+		// made it here okay, so let's set the properties!
160
+		foreach ($menu_args as $prop => $value) {
161
+			switch ($prop) {
162
+				case 'show_on_menu':
163
+					$value = (int) $value;
164
+					break;
165
+				case 'admin_init_page':
166
+					if (in_array('admin_init_page', $required) && ! $value instanceof EE_Admin_Page_Init) {
167
+						throw new EE_Error(
168
+							sprintf(
169
+								__(
170
+									'The value for the "admin_init_page" argument must be an instance of an EE_Admin_Page_Init object.  Instead %s was given as the value.',
171
+									'event_espresso'
172
+								),
173
+								print_r($value, true)
174
+							)
175
+						);
176
+					}
177
+					break;
178
+				case 'menu_callback':
179
+					break;
180
+
181
+				default:
182
+					$value = (string) $value;
183
+					break;
184
+			}
185
+			if (! EEH_Class_Tools::has_property($this, $prop)) {
186
+				throw new EE_Error(
187
+					sprintf(
188
+						__(
189
+							'The $menu_args coming into %s has a index key (%s) representing a property that is not defined by the class.  Perhaps there is a typo?',
190
+							'event_espresso'
191
+						),
192
+						get_class($this),
193
+						$prop
194
+					)
195
+				);
196
+			}
197
+			$this->{$prop} = $value;
198
+		}
199
+
200
+		// filter capabilities (both static and dynamic)
201
+		$this->capability = apply_filters('FHEE_management_capability', $this->capability, null);
202
+		$this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null);
203
+
204
+		// Might need to change parent slug depending on maintenance mode.
205
+		if (! empty($this->maintenance_mode_parent)
206
+			&& EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
207
+		) {
208
+			$this->parent_slug = $this->maintenance_mode_parent;
209
+		}
210
+
211
+		// if empty menu_callback let's set default (but only if we have admin page init object)
212
+		if (empty($this->menu_callback) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
213
+			$this->menu_callback = array($this->admin_init_page, 'initialize_admin_page');
214
+		}
215
+	}
216
+
217
+
218
+	/**
219
+	 * This method should define how the menu page gets added for this particular item
220
+	 * and go ahead and define it.  Note that child classes MUST also return the result of
221
+	 * the function used to register the WordPress admin page (the wp_page_slug string)
222
+	 *
223
+	 * @since  4.4.0
224
+	 * @return string wp_page_slug.
225
+	 */
226
+	abstract protected function _add_menu_page();
227
+
228
+
229
+	/**
230
+	 * Called by client code to use this menu map for registering a WordPress admin page
231
+	 *
232
+	 * @param boolean $network_admin whether this is being added to the network admin page or not
233
+	 * @since  4.4.0
234
+	 */
235
+	public function add_menu_page($network_admin = false)
236
+	{
237
+
238
+		$show_on_menu_int = (int) $this->show_on_menu;
239
+		if (($network_admin
240
+			 && in_array(
241
+				 $show_on_menu_int,
242
+				 array(self::BLOG_AND_NETWORK_ADMIN, self::NETWORK_ADMIN_ONLY),
243
+				 true
244
+			 ))
245
+			||
246
+			(! $network_admin
247
+			 && in_array(
248
+				 $show_on_menu_int,
249
+				 array(self::BLOG_AND_NETWORK_ADMIN, self::BLOG_ADMIN_ONLY),
250
+				 true
251
+			 ))) {
252
+			$wp_page_slug = $this->_add_menu_page();
253
+		} else {
254
+			$wp_page_slug = '';
255
+		}
256
+
257
+		if (! empty($wp_page_slug) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
258
+			try {
259
+				$this->admin_init_page->set_page_dependencies($wp_page_slug);
260
+			} catch (EE_Error $e) {
261
+				$e->get_error();
262
+			}
263
+		}
264
+	}
265 265
 }
266 266
 
267 267
 
@@ -275,75 +275,75 @@  discard block
 block discarded – undo
275 275
 class EE_Admin_Page_Main_Menu extends EE_Admin_Page_Menu_Map
276 276
 {
277 277
 
278
-    /**
279
-     * If included int incoming params, then this class will also register a Sub Menue Admin page with a different
280
-     * subtitle than the main menu item.
281
-     *
282
-     * @since 4.4.0
283
-     *
284
-     * @var string
285
-     */
286
-    public $subtitle;
287
-
288
-    /**
289
-     * The page to a icon used for this menu.
290
-     *
291
-     * @since  4.4.0
292
-     * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
293
-     *        for what can be set for this property.
294
-     * @var string
295
-     */
296
-    public $icon_url;
297
-
298
-
299
-    /**
300
-     * What position in the main menu order for the WP admin menu this menu item
301
-     * should show.
302
-     *
303
-     * @since  4.4.0
304
-     * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
305
-     *        for what can be set for this property.
306
-     * @var integer
307
-     */
308
-    public $position;
309
-
310
-
311
-    public function __construct($menu_args)
312
-    {
313
-        $required = array('menu_label', 'parent_slug', 'menu_slug', 'menu_group', 'menu_order', 'admin_init_page');
314
-
315
-        parent::__construct($menu_args, $required);
316
-
317
-        $this->position = ! empty($this->position) ? (int) $this->position : $this->position;
318
-    }
319
-
320
-
321
-    /**
322
-     * Uses the proper WP utility for registering a menu page for the main WP pages.
323
-     */
324
-    protected function _add_menu_page()
325
-    {
326
-        $main = add_menu_page(
327
-            $this->title,
328
-            $this->menu_label,
329
-            $this->capability,
330
-            $this->parent_slug,
331
-            $this->menu_callback,
332
-            $this->icon_url,
333
-            $this->position
334
-        );
335
-        if (! empty($this->subtitle)) {
336
-            add_submenu_page(
337
-                $this->parent_slug,
338
-                $this->subtitle,
339
-                $this->subtitle,
340
-                $this->capability,
341
-                $this->menu_slug,
342
-                $this->menu_callback
343
-            );
344
-        }
345
-        return $main;
346
-    }
278
+	/**
279
+	 * If included int incoming params, then this class will also register a Sub Menue Admin page with a different
280
+	 * subtitle than the main menu item.
281
+	 *
282
+	 * @since 4.4.0
283
+	 *
284
+	 * @var string
285
+	 */
286
+	public $subtitle;
287
+
288
+	/**
289
+	 * The page to a icon used for this menu.
290
+	 *
291
+	 * @since  4.4.0
292
+	 * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
293
+	 *        for what can be set for this property.
294
+	 * @var string
295
+	 */
296
+	public $icon_url;
297
+
298
+
299
+	/**
300
+	 * What position in the main menu order for the WP admin menu this menu item
301
+	 * should show.
302
+	 *
303
+	 * @since  4.4.0
304
+	 * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
305
+	 *        for what can be set for this property.
306
+	 * @var integer
307
+	 */
308
+	public $position;
309
+
310
+
311
+	public function __construct($menu_args)
312
+	{
313
+		$required = array('menu_label', 'parent_slug', 'menu_slug', 'menu_group', 'menu_order', 'admin_init_page');
314
+
315
+		parent::__construct($menu_args, $required);
316
+
317
+		$this->position = ! empty($this->position) ? (int) $this->position : $this->position;
318
+	}
319
+
320
+
321
+	/**
322
+	 * Uses the proper WP utility for registering a menu page for the main WP pages.
323
+	 */
324
+	protected function _add_menu_page()
325
+	{
326
+		$main = add_menu_page(
327
+			$this->title,
328
+			$this->menu_label,
329
+			$this->capability,
330
+			$this->parent_slug,
331
+			$this->menu_callback,
332
+			$this->icon_url,
333
+			$this->position
334
+		);
335
+		if (! empty($this->subtitle)) {
336
+			add_submenu_page(
337
+				$this->parent_slug,
338
+				$this->subtitle,
339
+				$this->subtitle,
340
+				$this->capability,
341
+				$this->menu_slug,
342
+				$this->menu_callback
343
+			);
344
+		}
345
+		return $main;
346
+	}
347 347
 } //end EE_Admin_Page_Main_Menu
348 348
 
349 349
 
@@ -357,23 +357,23 @@  discard block
 block discarded – undo
357 357
 class EE_Admin_Page_Sub_Menu extends EE_Admin_Page_Main_Menu
358 358
 {
359 359
 
360
-    public function __construct($menu_args)
361
-    {
362
-        parent::__construct($menu_args);
363
-    }
364
-
365
-
366
-    protected function _add_menu_page()
367
-    {
368
-        return add_submenu_page(
369
-            $this->parent_slug,
370
-            $this->title,
371
-            $this->menu_label,
372
-            $this->capability,
373
-            $this->menu_slug,
374
-            $this->menu_callback
375
-        );
376
-    }
360
+	public function __construct($menu_args)
361
+	{
362
+		parent::__construct($menu_args);
363
+	}
364
+
365
+
366
+	protected function _add_menu_page()
367
+	{
368
+		return add_submenu_page(
369
+			$this->parent_slug,
370
+			$this->title,
371
+			$this->menu_label,
372
+			$this->capability,
373
+			$this->menu_slug,
374
+			$this->menu_callback
375
+		);
376
+	}
377 377
 }
378 378
 
379 379
 
@@ -392,28 +392,28 @@  discard block
 block discarded – undo
392 392
 {
393 393
 
394 394
 
395
-    public function __construct($menu_args = array())
396
-    {
397
-        $required = array('menu_label', 'menu_slug', 'menu_order', 'parent_slug');
398
-        parent::__construct($menu_args, $required);
399
-    }
395
+	public function __construct($menu_args = array())
396
+	{
397
+		$required = array('menu_label', 'menu_slug', 'menu_order', 'parent_slug');
398
+		parent::__construct($menu_args, $required);
399
+	}
400 400
 
401 401
 
402
-    protected function _add_menu_page()
403
-    {
404
-        return add_submenu_page(
405
-            $this->parent_slug,
406
-            $this->menu_label,
407
-            $this->_group_link(),
408
-            $this->capability,
409
-            $this->menu_slug,
410
-            '__return_false'
411
-        );
412
-    }
402
+	protected function _add_menu_page()
403
+	{
404
+		return add_submenu_page(
405
+			$this->parent_slug,
406
+			$this->menu_label,
407
+			$this->_group_link(),
408
+			$this->capability,
409
+			$this->menu_slug,
410
+			'__return_false'
411
+		);
412
+	}
413 413
 
414 414
 
415
-    private function _group_link()
416
-    {
417
-        return '<span class="ee_menu_group"  onclick="return false;">' . $this->menu_label . '</span>';
418
-    }
415
+	private function _group_link()
416
+	{
417
+		return '<span class="ee_menu_group"  onclick="return false;">' . $this->menu_label . '</span>';
418
+	}
419 419
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
         // verify that required keys are present in the incoming array.
144 144
         $missing = array_diff((array) $required, array_keys((array) $menu_args));
145 145
 
146
-        if (! empty($missing)) {
146
+        if ( ! empty($missing)) {
147 147
             throw new EE_Error(
148 148
                 sprintf(
149 149
                     __(
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
                     $value = (string) $value;
183 183
                     break;
184 184
             }
185
-            if (! EEH_Class_Tools::has_property($this, $prop)) {
185
+            if ( ! EEH_Class_Tools::has_property($this, $prop)) {
186 186
                 throw new EE_Error(
187 187
                     sprintf(
188 188
                         __(
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
 
200 200
         // filter capabilities (both static and dynamic)
201 201
         $this->capability = apply_filters('FHEE_management_capability', $this->capability, null);
202
-        $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null);
202
+        $this->capability = apply_filters('FHEE_'.$this->menu_slug.'_capability', $this->capability, null);
203 203
 
204 204
         // Might need to change parent slug depending on maintenance mode.
205
-        if (! empty($this->maintenance_mode_parent)
205
+        if ( ! empty($this->maintenance_mode_parent)
206 206
             && EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
207 207
         ) {
208 208
             $this->parent_slug = $this->maintenance_mode_parent;
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
                  true
244 244
              ))
245 245
             ||
246
-            (! $network_admin
246
+            ( ! $network_admin
247 247
              && in_array(
248 248
                  $show_on_menu_int,
249 249
                  array(self::BLOG_AND_NETWORK_ADMIN, self::BLOG_ADMIN_ONLY),
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             $wp_page_slug = '';
255 255
         }
256 256
 
257
-        if (! empty($wp_page_slug) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
257
+        if ( ! empty($wp_page_slug) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
258 258
             try {
259 259
                 $this->admin_init_page->set_page_dependencies($wp_page_slug);
260 260
             } catch (EE_Error $e) {
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
             $this->icon_url,
333 333
             $this->position
334 334
         );
335
-        if (! empty($this->subtitle)) {
335
+        if ( ! empty($this->subtitle)) {
336 336
             add_submenu_page(
337 337
                 $this->parent_slug,
338 338
                 $this->subtitle,
@@ -414,6 +414,6 @@  discard block
 block discarded – undo
414 414
 
415 415
     private function _group_link()
416 416
     {
417
-        return '<span class="ee_menu_group"  onclick="return false;">' . $this->menu_label . '</span>';
417
+        return '<span class="ee_menu_group"  onclick="return false;">'.$this->menu_label.'</span>';
418 418
     }
419 419
 }
Please login to merge, or discard this patch.
core/admin/EE_Help_Tour.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@
 block discarded – undo
96 96
      *
97 97
      * @access public
98 98
      * @param boolean $caf used to indicate if this tour is happening on caf install or not.
99
-     * @return void
99
+     * @return EE_Help_Tour
100 100
      */
101 101
     public function __construct($caf = false)
102 102
     {
Please login to merge, or discard this patch.
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -15,268 +15,268 @@
 block discarded – undo
15 15
 abstract class EE_Help_Tour extends EE_Base
16 16
 {
17 17
 
18
-    /**
19
-     * This is the label for the tour. It is used when regenerating restart buttons for the tour. Set this in the
20
-     * constructor of the child class.
21
-     *
22
-     * @access protected
23
-     * @var string
24
-     */
25
-    protected $_label = '';
26
-
27
-
28
-    /**
29
-     * This is the slug for the tour.  It should be unique from all tours and is used for starting a tour and setting
30
-     * cookies for the tour. Set this in the constructor of the child class.
31
-     *
32
-     * @access protected
33
-     * @var string
34
-     */
35
-    protected $_slug = '';
36
-
37
-
38
-    /**
39
-     * This will contain the formatted array for the stops that gets used by EE_Admin_Page->_add_help_tour() for
40
-     * setting up a tour on a given page. format for array is: array(
41
-     *        0 => array(
42
-     *            'id' => 'id_element', //if attached to an css id for an element then use this param. id's will take
43
-     *            precendence even if you also set class.
44
-     *            'class' => 'class_element', //if attached to a css class for an element anchoring the stop then use
45
-     *            this param. The first element for that class is the anchor. If the class or the id are empty then the
46
-     *            stop will be a modal on the page anchored to the main body.
47
-     *            'custom_class' => 'some_custom_class', //optional custom class to add for this stop.
48
-     *            'button_text' => 'custom text for button', //optional
49
-     *            'content' => 'The content for the stop', //required
50
-     *            'pause_after' => false, //indicate if you want the tour to pause after this stop and it will get
51
-     *            added to the pauseAfter global option array setup for the joyride instance. This is only applicable
52
-     *            when this tour has been set to run on timer.
53
-     *            'options' => array(
54
-     *                //override any of the global options set via the help_tour "option_callback" for the joyride
55
-     *                instance on this specific stop.
56
-     *                )
57
-     *            )
58
-     *        );
59
-     *
60
-     * @access protected
61
-     * @var array
62
-     */
63
-    protected $_stops = array();
64
-
65
-
66
-    /**
67
-     * This contains any stop specific options for the tour.
68
-     * defaults are set but child classes can override.
69
-     *
70
-     * @access protected
71
-     * @var array
72
-     */
73
-    protected $_options = array();
74
-
75
-
76
-    /**
77
-     * holds anything found in the $_REQUEST object (however we override any _gets with _post data).
78
-     *
79
-     * @access protected
80
-     * @var array
81
-     */
82
-    protected $_req_data = array();
83
-
84
-
85
-    /**
86
-     * a flag that is set on init for whether this help_tour is happening on a caf install or not.
87
-     *
88
-     * @var boolean
89
-     */
90
-    protected $_is_caf = false;
91
-
92
-
93
-    /**
94
-     * _constructor
95
-     * initialized the tour object and sets up important properties required to setup the tour.
96
-     *
97
-     * @access public
98
-     * @param boolean $caf used to indicate if this tour is happening on caf install or not.
99
-     * @return void
100
-     */
101
-    public function __construct($caf = false)
102
-    {
103
-        $this->_is_caf = $caf;
104
-        $this->_req_data = array_merge($_GET, $_POST);
105
-        $this->_set_tour_properties();
106
-        $this->_set_tour_stops();
107
-        $this->_set_tour_options();
108
-
109
-        // make sure the last tour stop has "end tour" for its button
110
-        $end = array_pop($this->_stops);
111
-        $end['button_text'] = __('End Tour', 'event_espresso');
112
-        // add back to stops
113
-        $this->_stops[] = $end;
114
-    }
115
-
116
-
117
-    /**
118
-     * required method that has the sole purpose of setting up the tour $_label and $_slug properties
119
-     *
120
-     * @abstract
121
-     * @access protected
122
-     * @return void
123
-     */
124
-    abstract protected function _set_tour_properties();
125
-
126
-
127
-    /**
128
-     * required method that's sole purpose is to setup the $_stops property
129
-     *
130
-     * @abstract
131
-     * @access protected
132
-     * @return void
133
-     */
134
-    abstract protected function _set_tour_stops();
135
-
136
-
137
-    /**
138
-     * The method can optionally be overridden by child classes to set the _options array if there are any default
139
-     * options the child wishes to override for a this tour. See property definition for more info
140
-     *
141
-     * @access protected
142
-     * @return void
143
-     */
144
-    protected function _set_tour_options($options = array())
145
-    {
146
-        $defaults = array(
147
-            'tipLocation'           => 'bottom',
148
-            // 'top', 'bottom', 'right', 'left' in relation to parent
149
-            'nubPosition'           => 'auto',
150
-            // override on a per tooltip bases. can be "auto", "right", "top", "bottom", "left"
151
-            'tipAdjustmentY'        => 0,
152
-            // allow for adjustment of tip
153
-            'tipAdjustmentX'        => 0,
154
-            // allow for adjustment of tip
155
-            'scroll'                => true,
156
-            // whether to scrollTo the next step or not
157
-            'scrollSpeed'           => 300,
158
-            // Page scrolling speed in ms
159
-            'timer'                 => 0,
160
-            // 0 = off, all other numbers = time(ms)
161
-            'autoStart'             => true,
162
-            // true or false - false tour starts when restart called
163
-            'startTimerOnClick'     => true,
164
-            // true/false to start timer on first click
165
-            'nextButton'            => true,
166
-            // true/false for next button visibility
167
-            'button_text'           => __('Next', 'event_espresso'),
168
-            'tipAnimation'          => 'fade',
169
-            // 'pop' or 'fade' in each tip
170
-            'pauseAfter'            => array(),
171
-            // array of indexes where to pause the tour after
172
-            'tipAnimationFadeSpeed' => 300,
173
-            // if 'fade'- speed in ms of transition
174
-            'cookieMonster'         => true,
175
-            // true/false for whether cookies are used
176
-            'cookieName'            => $this->get_slug(),
177
-            // choose your own cookie name (setup will add the prefix for the specific page joyride)
178
-            'cookieDomain'          => false,
179
-            // set to false or yoursite.com
180
-            // 'tipContainer' => 'body',            // Where the tip be attached if not inline
181
-            'modal'                 => false,
182
-            // Whether to cover page with modal during the tour
183
-            'expose'                => false,
184
-            // Whether to expose the elements at each step in the tour (requires modal:true),
185
-            'postExposeCallback'    => 'EEHelpTour.postExposeCallback',
186
-            // A method to call after an element has been exposed
187
-            'preRideCallback'       => 'EEHelpTour_preRideCallback',
188
-            // A method to call before the tour starts (passed index, tip, and cloned exposed element)
189
-            'postRideCallback'      => 'EEHelpTour_postRideCallback',
190
-            // a method to call once the tour closes.  This will correspond to the name of a js method that will have to be defined in loaded js.
191
-            'preStepCallback'       => 'EEHelpTour_preStepCallback',
192
-            // A method to call before each step
193
-            'postStepCallback'      => 'EEHelpTour_postStepCallback',
194
-            // A method to call after each step (remember this will correspond with a js method that you will have to define in a js file BEFORE ee-help-tour.js loads, if the default methods do not exist, then ee-help-tour.js just substitues empty functions $.noop)/**/
195
-        );
196
-
197
-        $options = ! empty($options) && is_array($options) ? array_merge($defaults, $options) : $defaults;
198
-        $this->_options = $options;
199
-    }
200
-
201
-
202
-    /**
203
-     * getter functions to return all the properties for the tour.
204
-     */
205
-
206
-
207
-    /**
208
-     * get_slug
209
-     *
210
-     * @return string slug for the tour
211
-     */
212
-    public function get_slug()
213
-    {
214
-        if (empty($this->_slug)) {
215
-            throw new EE_Error(
216
-                sprintf(
217
-                    __(
218
-                        'There is no slug set for the help tour class (%s). Make sure that the $_slug property is set in the class constructor',
219
-                        'event_espresso'
220
-                    ),
221
-                    get_class($this)
222
-                )
223
-            );
224
-        }
225
-        return $this->_slug;
226
-    }
227
-
228
-
229
-    /**
230
-     * get_label
231
-     *
232
-     * @return string
233
-     */
234
-    public function get_label()
235
-    {
236
-        if (empty($this->_label)) {
237
-            throw new EE_Error(
238
-                sprintf(
239
-                    __(
240
-                        'There is no label set for the help tour class (%s). Make sure that the $_label property is set in the class constructor',
241
-                        'event_espresso'
242
-                    ),
243
-                    get_class($this)
244
-                )
245
-            );
246
-        }
247
-        return $this->_label;
248
-    }
249
-
250
-
251
-    /**
252
-     * get_stops
253
-     *
254
-     * @return array
255
-     */
256
-    public function get_stops()
257
-    {
258
-        foreach ($this->_stops as $ind => $stop) {
259
-            if (! isset($stop['button_text'])) {
260
-                $this->_stops[ $ind ]['button_text'] = $this->_options['button_text'];
261
-            }
262
-        }
263
-        return $this->_stops;
264
-    }
265
-
266
-
267
-    /**
268
-     * get options
269
-     *
270
-     * @return array
271
-     */
272
-    public function get_options()
273
-    {
274
-        // let's make sure there are not pauses set
275
-        foreach ($this->_stops as $ind => $stop) {
276
-            if (isset($stop['pause_after']) && $stop['pause_after']) {
277
-                $this->_options['pauseAfter'][] = $ind;
278
-            }
279
-        }
280
-        return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this);
281
-    }
18
+	/**
19
+	 * This is the label for the tour. It is used when regenerating restart buttons for the tour. Set this in the
20
+	 * constructor of the child class.
21
+	 *
22
+	 * @access protected
23
+	 * @var string
24
+	 */
25
+	protected $_label = '';
26
+
27
+
28
+	/**
29
+	 * This is the slug for the tour.  It should be unique from all tours and is used for starting a tour and setting
30
+	 * cookies for the tour. Set this in the constructor of the child class.
31
+	 *
32
+	 * @access protected
33
+	 * @var string
34
+	 */
35
+	protected $_slug = '';
36
+
37
+
38
+	/**
39
+	 * This will contain the formatted array for the stops that gets used by EE_Admin_Page->_add_help_tour() for
40
+	 * setting up a tour on a given page. format for array is: array(
41
+	 *        0 => array(
42
+	 *            'id' => 'id_element', //if attached to an css id for an element then use this param. id's will take
43
+	 *            precendence even if you also set class.
44
+	 *            'class' => 'class_element', //if attached to a css class for an element anchoring the stop then use
45
+	 *            this param. The first element for that class is the anchor. If the class or the id are empty then the
46
+	 *            stop will be a modal on the page anchored to the main body.
47
+	 *            'custom_class' => 'some_custom_class', //optional custom class to add for this stop.
48
+	 *            'button_text' => 'custom text for button', //optional
49
+	 *            'content' => 'The content for the stop', //required
50
+	 *            'pause_after' => false, //indicate if you want the tour to pause after this stop and it will get
51
+	 *            added to the pauseAfter global option array setup for the joyride instance. This is only applicable
52
+	 *            when this tour has been set to run on timer.
53
+	 *            'options' => array(
54
+	 *                //override any of the global options set via the help_tour "option_callback" for the joyride
55
+	 *                instance on this specific stop.
56
+	 *                )
57
+	 *            )
58
+	 *        );
59
+	 *
60
+	 * @access protected
61
+	 * @var array
62
+	 */
63
+	protected $_stops = array();
64
+
65
+
66
+	/**
67
+	 * This contains any stop specific options for the tour.
68
+	 * defaults are set but child classes can override.
69
+	 *
70
+	 * @access protected
71
+	 * @var array
72
+	 */
73
+	protected $_options = array();
74
+
75
+
76
+	/**
77
+	 * holds anything found in the $_REQUEST object (however we override any _gets with _post data).
78
+	 *
79
+	 * @access protected
80
+	 * @var array
81
+	 */
82
+	protected $_req_data = array();
83
+
84
+
85
+	/**
86
+	 * a flag that is set on init for whether this help_tour is happening on a caf install or not.
87
+	 *
88
+	 * @var boolean
89
+	 */
90
+	protected $_is_caf = false;
91
+
92
+
93
+	/**
94
+	 * _constructor
95
+	 * initialized the tour object and sets up important properties required to setup the tour.
96
+	 *
97
+	 * @access public
98
+	 * @param boolean $caf used to indicate if this tour is happening on caf install or not.
99
+	 * @return void
100
+	 */
101
+	public function __construct($caf = false)
102
+	{
103
+		$this->_is_caf = $caf;
104
+		$this->_req_data = array_merge($_GET, $_POST);
105
+		$this->_set_tour_properties();
106
+		$this->_set_tour_stops();
107
+		$this->_set_tour_options();
108
+
109
+		// make sure the last tour stop has "end tour" for its button
110
+		$end = array_pop($this->_stops);
111
+		$end['button_text'] = __('End Tour', 'event_espresso');
112
+		// add back to stops
113
+		$this->_stops[] = $end;
114
+	}
115
+
116
+
117
+	/**
118
+	 * required method that has the sole purpose of setting up the tour $_label and $_slug properties
119
+	 *
120
+	 * @abstract
121
+	 * @access protected
122
+	 * @return void
123
+	 */
124
+	abstract protected function _set_tour_properties();
125
+
126
+
127
+	/**
128
+	 * required method that's sole purpose is to setup the $_stops property
129
+	 *
130
+	 * @abstract
131
+	 * @access protected
132
+	 * @return void
133
+	 */
134
+	abstract protected function _set_tour_stops();
135
+
136
+
137
+	/**
138
+	 * The method can optionally be overridden by child classes to set the _options array if there are any default
139
+	 * options the child wishes to override for a this tour. See property definition for more info
140
+	 *
141
+	 * @access protected
142
+	 * @return void
143
+	 */
144
+	protected function _set_tour_options($options = array())
145
+	{
146
+		$defaults = array(
147
+			'tipLocation'           => 'bottom',
148
+			// 'top', 'bottom', 'right', 'left' in relation to parent
149
+			'nubPosition'           => 'auto',
150
+			// override on a per tooltip bases. can be "auto", "right", "top", "bottom", "left"
151
+			'tipAdjustmentY'        => 0,
152
+			// allow for adjustment of tip
153
+			'tipAdjustmentX'        => 0,
154
+			// allow for adjustment of tip
155
+			'scroll'                => true,
156
+			// whether to scrollTo the next step or not
157
+			'scrollSpeed'           => 300,
158
+			// Page scrolling speed in ms
159
+			'timer'                 => 0,
160
+			// 0 = off, all other numbers = time(ms)
161
+			'autoStart'             => true,
162
+			// true or false - false tour starts when restart called
163
+			'startTimerOnClick'     => true,
164
+			// true/false to start timer on first click
165
+			'nextButton'            => true,
166
+			// true/false for next button visibility
167
+			'button_text'           => __('Next', 'event_espresso'),
168
+			'tipAnimation'          => 'fade',
169
+			// 'pop' or 'fade' in each tip
170
+			'pauseAfter'            => array(),
171
+			// array of indexes where to pause the tour after
172
+			'tipAnimationFadeSpeed' => 300,
173
+			// if 'fade'- speed in ms of transition
174
+			'cookieMonster'         => true,
175
+			// true/false for whether cookies are used
176
+			'cookieName'            => $this->get_slug(),
177
+			// choose your own cookie name (setup will add the prefix for the specific page joyride)
178
+			'cookieDomain'          => false,
179
+			// set to false or yoursite.com
180
+			// 'tipContainer' => 'body',            // Where the tip be attached if not inline
181
+			'modal'                 => false,
182
+			// Whether to cover page with modal during the tour
183
+			'expose'                => false,
184
+			// Whether to expose the elements at each step in the tour (requires modal:true),
185
+			'postExposeCallback'    => 'EEHelpTour.postExposeCallback',
186
+			// A method to call after an element has been exposed
187
+			'preRideCallback'       => 'EEHelpTour_preRideCallback',
188
+			// A method to call before the tour starts (passed index, tip, and cloned exposed element)
189
+			'postRideCallback'      => 'EEHelpTour_postRideCallback',
190
+			// a method to call once the tour closes.  This will correspond to the name of a js method that will have to be defined in loaded js.
191
+			'preStepCallback'       => 'EEHelpTour_preStepCallback',
192
+			// A method to call before each step
193
+			'postStepCallback'      => 'EEHelpTour_postStepCallback',
194
+			// A method to call after each step (remember this will correspond with a js method that you will have to define in a js file BEFORE ee-help-tour.js loads, if the default methods do not exist, then ee-help-tour.js just substitues empty functions $.noop)/**/
195
+		);
196
+
197
+		$options = ! empty($options) && is_array($options) ? array_merge($defaults, $options) : $defaults;
198
+		$this->_options = $options;
199
+	}
200
+
201
+
202
+	/**
203
+	 * getter functions to return all the properties for the tour.
204
+	 */
205
+
206
+
207
+	/**
208
+	 * get_slug
209
+	 *
210
+	 * @return string slug for the tour
211
+	 */
212
+	public function get_slug()
213
+	{
214
+		if (empty($this->_slug)) {
215
+			throw new EE_Error(
216
+				sprintf(
217
+					__(
218
+						'There is no slug set for the help tour class (%s). Make sure that the $_slug property is set in the class constructor',
219
+						'event_espresso'
220
+					),
221
+					get_class($this)
222
+				)
223
+			);
224
+		}
225
+		return $this->_slug;
226
+	}
227
+
228
+
229
+	/**
230
+	 * get_label
231
+	 *
232
+	 * @return string
233
+	 */
234
+	public function get_label()
235
+	{
236
+		if (empty($this->_label)) {
237
+			throw new EE_Error(
238
+				sprintf(
239
+					__(
240
+						'There is no label set for the help tour class (%s). Make sure that the $_label property is set in the class constructor',
241
+						'event_espresso'
242
+					),
243
+					get_class($this)
244
+				)
245
+			);
246
+		}
247
+		return $this->_label;
248
+	}
249
+
250
+
251
+	/**
252
+	 * get_stops
253
+	 *
254
+	 * @return array
255
+	 */
256
+	public function get_stops()
257
+	{
258
+		foreach ($this->_stops as $ind => $stop) {
259
+			if (! isset($stop['button_text'])) {
260
+				$this->_stops[ $ind ]['button_text'] = $this->_options['button_text'];
261
+			}
262
+		}
263
+		return $this->_stops;
264
+	}
265
+
266
+
267
+	/**
268
+	 * get options
269
+	 *
270
+	 * @return array
271
+	 */
272
+	public function get_options()
273
+	{
274
+		// let's make sure there are not pauses set
275
+		foreach ($this->_stops as $ind => $stop) {
276
+			if (isset($stop['pause_after']) && $stop['pause_after']) {
277
+				$this->_options['pauseAfter'][] = $ind;
278
+			}
279
+		}
280
+		return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this);
281
+	}
282 282
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
     public function get_stops()
257 257
     {
258 258
         foreach ($this->_stops as $ind => $stop) {
259
-            if (! isset($stop['button_text'])) {
260
-                $this->_stops[ $ind ]['button_text'] = $this->_options['button_text'];
259
+            if ( ! isset($stop['button_text'])) {
260
+                $this->_stops[$ind]['button_text'] = $this->_options['button_text'];
261 261
             }
262 262
         }
263 263
         return $this->_stops;
@@ -277,6 +277,6 @@  discard block
 block discarded – undo
277 277
                 $this->_options['pauseAfter'][] = $ind;
278 278
             }
279 279
         }
280
-        return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this);
280
+        return apply_filters('FHEE__'.get_class($this).'__get_options', $this->_options, $this);
281 281
     }
282 282
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_answers.dmsstage.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,6 @@
 block discarded – undo
62 62
     /**
63 63
      * Creates a 4.1 price base type
64 64
      * @global type $wpdb
65
-     * @param array $old_price
66 65
      * @param int $new_reg_id
67 66
      * @return int
68 67
      */
Please login to merge, or discard this patch.
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -32,86 +32,86 @@
 block discarded – undo
32 32
 
33 33
 class EE_DMS_4_1_0_answers extends EE_Data_Migration_Script_Stage_Table
34 34
 {
35
-    private $_new_answer_table;
36
-    private $_new_question_table;
37
-    public function __construct()
38
-    {
39
-        global $wpdb;
40
-        $this->_pretty_name = __("Answers", "event_espresso");
41
-        $this->_old_table = $wpdb->prefix."events_answer";
42
-        // join to attendee and then join to events table
43
-        $this->_extra_where_sql = ' AS ans 
35
+	private $_new_answer_table;
36
+	private $_new_question_table;
37
+	public function __construct()
38
+	{
39
+		global $wpdb;
40
+		$this->_pretty_name = __("Answers", "event_espresso");
41
+		$this->_old_table = $wpdb->prefix."events_answer";
42
+		// join to attendee and then join to events table
43
+		$this->_extra_where_sql = ' AS ans 
44 44
             INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id
45 45
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id 
46 46
             WHERE e.event_status !="D"';
47
-        $this->_new_answer_table = $wpdb->prefix."esp_answer";
48
-        $this->_new_question_table = $wpdb->prefix."esp_question";
49
-        parent::__construct();
50
-    }
51
-    protected function _migrate_old_row($old_row)
52
-    {
53
-        // get the new REGs for the old answer
54
-        global $wpdb;
55
-        $old_attendee_table = $wpdb->prefix."events_attendee";
56
-        $new_reg_table = $wpdb->prefix."esp_registration";
57
-        $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
58
-        if (! $regs) {
59
-            $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
60
-            return false;
61
-        }
62
-        // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee)
63
-        foreach ($regs as $new_reg_id) {
64
-            $new_answer_id = $this->_insert_new_answer($old_row, $new_reg_id);
65
-        }
66
-    }
67
-    /**
68
-     * Creates a 4.1 price base type
69
-     * @global type $wpdb
70
-     * @param array $old_price
71
-     * @param int $new_reg_id
72
-     * @return int
73
-     */
74
-    private function _insert_new_answer($old_answer, $new_reg_id)
75
-    {
76
-        global $wpdb;
77
-        $old_question_table = $wpdb->prefix."events_question";
78
-        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
47
+		$this->_new_answer_table = $wpdb->prefix."esp_answer";
48
+		$this->_new_question_table = $wpdb->prefix."esp_question";
49
+		parent::__construct();
50
+	}
51
+	protected function _migrate_old_row($old_row)
52
+	{
53
+		// get the new REGs for the old answer
54
+		global $wpdb;
55
+		$old_attendee_table = $wpdb->prefix."events_attendee";
56
+		$new_reg_table = $wpdb->prefix."esp_registration";
57
+		$regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
58
+		if (! $regs) {
59
+			$this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
60
+			return false;
61
+		}
62
+		// as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee)
63
+		foreach ($regs as $new_reg_id) {
64
+			$new_answer_id = $this->_insert_new_answer($old_row, $new_reg_id);
65
+		}
66
+	}
67
+	/**
68
+	 * Creates a 4.1 price base type
69
+	 * @global type $wpdb
70
+	 * @param array $old_price
71
+	 * @param int $new_reg_id
72
+	 * @return int
73
+	 */
74
+	private function _insert_new_answer($old_answer, $new_reg_id)
75
+	{
76
+		global $wpdb;
77
+		$old_question_table = $wpdb->prefix."events_question";
78
+		$new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
79 79
 
80
-        $question_type = $this->_get_question_type($new_question_id);
81
-        if (in_array($question_type, array('MULTIPLE'))) {
82
-            $ans_value = serialize(explode(",", stripslashes($old_answer['answer'])));
83
-        } else {
84
-            $ans_value = stripslashes($old_answer['answer']);
85
-        }
86
-        $cols_n_values = array(
87
-            'REG_ID'=>$new_reg_id,
88
-            'QST_ID'=>$new_question_id,
89
-            'ANS_value'=>$ans_value
90
-        );
91
-        $datatypes = array(
92
-            '%d',// REG_ID
93
-            '%d',// QST_ID
94
-            '%s',// ANS_value
95
-        );
96
-        $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
97
-        if (! $success) {
98
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
99
-            return 0;
100
-        }
101
-        $new_id = $wpdb->insert_id;
102
-        return $new_id;
103
-    }
80
+		$question_type = $this->_get_question_type($new_question_id);
81
+		if (in_array($question_type, array('MULTIPLE'))) {
82
+			$ans_value = serialize(explode(",", stripslashes($old_answer['answer'])));
83
+		} else {
84
+			$ans_value = stripslashes($old_answer['answer']);
85
+		}
86
+		$cols_n_values = array(
87
+			'REG_ID'=>$new_reg_id,
88
+			'QST_ID'=>$new_question_id,
89
+			'ANS_value'=>$ans_value
90
+		);
91
+		$datatypes = array(
92
+			'%d',// REG_ID
93
+			'%d',// QST_ID
94
+			'%s',// ANS_value
95
+		);
96
+		$success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
97
+		if (! $success) {
98
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
99
+			return 0;
100
+		}
101
+		$new_id = $wpdb->insert_id;
102
+		return $new_id;
103
+	}
104 104
 
105
-    /**
106
-     * Gets the question's type
107
-     * @global type $wpdb
108
-     * @param type $question_id
109
-     * @return string
110
-     */
111
-    private function _get_question_type($question_id)
112
-    {
113
-        global $wpdb;
114
-        $type = $wpdb->get_var($wpdb->prepare("SELECT QST_type FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", $question_id));
115
-        return $type;
116
-    }
105
+	/**
106
+	 * Gets the question's type
107
+	 * @global type $wpdb
108
+	 * @param type $question_id
109
+	 * @return string
110
+	 */
111
+	private function _get_question_type($question_id)
112
+	{
113
+		global $wpdb;
114
+		$type = $wpdb->get_var($wpdb->prepare("SELECT QST_type FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", $question_id));
115
+		return $type;
116
+	}
117 117
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
         $this->_old_table = $wpdb->prefix."events_answer";
42 42
         // join to attendee and then join to events table
43 43
         $this->_extra_where_sql = ' AS ans 
44
-            INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id
45
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id 
44
+            INNER JOIN ' . $wpdb->prefix.'events_attendee AS att ON ans.attendee_id = att.id
45
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id = e.id 
46 46
             WHERE e.event_status !="D"';
47 47
         $this->_new_answer_table = $wpdb->prefix."esp_answer";
48 48
         $this->_new_question_table = $wpdb->prefix."esp_question";
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
         $old_attendee_table = $wpdb->prefix."events_attendee";
56 56
         $new_reg_table = $wpdb->prefix."esp_registration";
57 57
         $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
58
-        if (! $regs) {
58
+        if ( ! $regs) {
59 59
             $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
60 60
             return false;
61 61
         }
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
             'ANS_value'=>$ans_value
90 90
         );
91 91
         $datatypes = array(
92
-            '%d',// REG_ID
93
-            '%d',// QST_ID
94
-            '%s',// ANS_value
92
+            '%d', // REG_ID
93
+            '%d', // QST_ID
94
+            '%s', // ANS_value
95 95
         );
96 96
         $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
97
-        if (! $success) {
97
+        if ( ! $success) {
98 98
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
99 99
             return 0;
100 100
         }
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_attendees.dmsstage.php 3 patches
Doc Comments   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
      * that they WILL be added (because the attendees stage runs nearly last during
580 580
      * the migration script)
581 581
      * @param type $new_ticket_id
582
-     * @param type $sold
583
-     * @param type $STS_ID
582
+     * @param string $STS_ID
583
+     * @param integer $quantity_sold
584 584
      * @return boolean whether they were successfully updated or not
585 585
      */
586 586
     protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
@@ -777,6 +777,10 @@  discard block
 block discarded – undo
777 777
         }
778 778
         return $count;
779 779
     }
780
+
781
+    /**
782
+     * @param integer $new_txn_id
783
+     */
780 784
     private function _insert_new_payment($old_attendee, $new_txn_id)
781 785
     {
782 786
         global $wpdb;
Please login to merge, or discard this patch.
Indentation   +598 added lines, -602 removed lines patch added patch discarded remove patch
@@ -53,10 +53,6 @@  discard block
 block discarded – undo
53 53
 ENGINE=InnoDB
54 54
 AUTO_INCREMENT=3
55 55
 ;
56
-
57
-
58
-
59
-
60 56
  * 4.1 Attendee tables and fields:
61 57
  * $this->_tables = array(
62 58
             'Attendee_CPT'=> new EE_Primary_Table('posts', 'ID'),
@@ -186,634 +182,634 @@  discard block
 block discarded – undo
186 182
  */
187 183
 class EE_DMS_4_1_0_attendees extends EE_Data_Migration_Script_Stage_Table
188 184
 {
189
-    private $_new_attendee_cpt_table;
190
-    private $_new_attendee_meta_table;
191
-    private $_new_reg_table;
192
-    private $_new_transaction_table;
193
-    private $_new_payment_table;
194
-    private $_new_line_table;
195
-    private $_old_mer_table;
196
-    private $_new_ticket_table;
197
-    private $_new_ticket_datetime_table;
198
-    private $_new_datetime_table;
199
-    private $_new_datetime_ticket_table;
200
-    private $_new_price_table;
201
-    private $_new_ticket_price_table;
202
-    /**
203
-     * Rememebrs whether or not the mer table exists
204
-     * @var boolean
205
-     */
206
-    private $_mer_tables_exist = null;
207
-    public function __construct()
208
-    {
209
-        global $wpdb;
210
-        $this->_pretty_name = __("Attendees", "event_espresso");
211
-        $this->_old_table = $wpdb->prefix."events_attendee";
212
-        $this->_extra_where_sql = 'AS att
185
+	private $_new_attendee_cpt_table;
186
+	private $_new_attendee_meta_table;
187
+	private $_new_reg_table;
188
+	private $_new_transaction_table;
189
+	private $_new_payment_table;
190
+	private $_new_line_table;
191
+	private $_old_mer_table;
192
+	private $_new_ticket_table;
193
+	private $_new_ticket_datetime_table;
194
+	private $_new_datetime_table;
195
+	private $_new_datetime_ticket_table;
196
+	private $_new_price_table;
197
+	private $_new_ticket_price_table;
198
+	/**
199
+	 * Rememebrs whether or not the mer table exists
200
+	 * @var boolean
201
+	 */
202
+	private $_mer_tables_exist = null;
203
+	public function __construct()
204
+	{
205
+		global $wpdb;
206
+		$this->_pretty_name = __("Attendees", "event_espresso");
207
+		$this->_old_table = $wpdb->prefix."events_attendee";
208
+		$this->_extra_where_sql = 'AS att
213 209
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
214 210
             WHERE e.event_status!="D"';
215
-        $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group";
216
-        $this->_new_attendee_cpt_table = $wpdb->posts;
217
-        $this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta";
218
-        $this->_new_reg_table = $wpdb->prefix."esp_registration";
219
-        $this->_new_transaction_table = $wpdb->prefix."esp_transaction";
220
-        $this->_new_payment_table = $wpdb->prefix."esp_payment";
221
-        $this->_new_line_table = $wpdb->prefix."esp_line_item";
222
-        $this->_new_ticket_table = $wpdb->prefix."esp_ticket";
223
-        $this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket";
224
-        $this->_new_datetime_table = $wpdb->prefix."esp_datetime";
225
-        $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
226
-        $this->_new_price_table = $wpdb->prefix."esp_price";
227
-        $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
228
-        parent::__construct();
229
-    }
211
+		$this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group";
212
+		$this->_new_attendee_cpt_table = $wpdb->posts;
213
+		$this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta";
214
+		$this->_new_reg_table = $wpdb->prefix."esp_registration";
215
+		$this->_new_transaction_table = $wpdb->prefix."esp_transaction";
216
+		$this->_new_payment_table = $wpdb->prefix."esp_payment";
217
+		$this->_new_line_table = $wpdb->prefix."esp_line_item";
218
+		$this->_new_ticket_table = $wpdb->prefix."esp_ticket";
219
+		$this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket";
220
+		$this->_new_datetime_table = $wpdb->prefix."esp_datetime";
221
+		$this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
222
+		$this->_new_price_table = $wpdb->prefix."esp_price";
223
+		$this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
224
+		parent::__construct();
225
+	}
230 226
 
231
-    protected function _migrate_old_row($old_row)
232
-    {
233
-        // first check if there's already a new attendee with similar characteristics
234
-        $new_att_id = $this->_find_attendee_cpt_matching($old_row);
235
-        if (! $new_att_id) {
236
-            $new_att_id = $this->_insert_new_attendee_cpt($old_row);
237
-            if (! $new_att_id) {
238
-                // if we couldnt even make an attendee, abandon all hope
239
-                return false;
240
-            }
241
-            $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id);
242
-            if ($new_att_meta_id) {
243
-                $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id);
244
-            }
245
-        }
246
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
227
+	protected function _migrate_old_row($old_row)
228
+	{
229
+		// first check if there's already a new attendee with similar characteristics
230
+		$new_att_id = $this->_find_attendee_cpt_matching($old_row);
231
+		if (! $new_att_id) {
232
+			$new_att_id = $this->_insert_new_attendee_cpt($old_row);
233
+			if (! $new_att_id) {
234
+				// if we couldnt even make an attendee, abandon all hope
235
+				return false;
236
+			}
237
+			$new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id);
238
+			if ($new_att_meta_id) {
239
+				$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id);
240
+			}
241
+		}
242
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
247 243
 
248
-        $txn_id = $this->_insert_new_transaction($old_row);
249
-        if (! $txn_id) {
250
-            // if we couldnt make the transaction, also abandon all hope
251
-            return false;
252
-        }
253
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id);
254
-        $pay_id = $this->_insert_new_payment($old_row, $txn_id);
255
-        if ($pay_id) {
256
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id);
257
-        }
244
+		$txn_id = $this->_insert_new_transaction($old_row);
245
+		if (! $txn_id) {
246
+			// if we couldnt make the transaction, also abandon all hope
247
+			return false;
248
+		}
249
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id);
250
+		$pay_id = $this->_insert_new_payment($old_row, $txn_id);
251
+		if ($pay_id) {
252
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id);
253
+		}
258 254
 
259 255
 
260
-        // even if there was no payment, we can go ahead with adding the reg
261
-        $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id);
262
-        if ($new_regs) {
263
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs);
264
-        }
265
-    }
266
-    /**
267
-     * Checks if there's already an attendee CPT in the db that has the same
268
-     * first and last name, and email. If so, returns its ID as an int.
269
-     * @global type $wpdb
270
-     * @param array $old_attendee
271
-     * @return int
272
-     */
273
-    private function _find_attendee_cpt_matching($old_attendee)
274
-    {
275
-        global $wpdb;
276
-        $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_new_attendee_cpt_table." AS cpt INNER JOIN ".$this->_new_attendee_meta_table." AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email']));
277
-        return intval($existing_attendee_id);
278
-    }
279
-    private function _insert_new_attendee_cpt($old_attendee)
280
-    {
281
-        global $wpdb;
282
-        $cols_n_values = array(
283
-            'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name
284
-            'post_content'=>'',// ATT_bio
285
-            'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug
286
-            'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
287
-            'post_excerpt'=>'',// ATT_short_bio
288
-            'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
289
-            'post_author'=>0,// ATT_author
290
-            'post_parent'=>0,// ATT_parent
291
-            'post_type'=>'espresso_attendees',// post_type
292
-            'post_status'=>'publish'// status
293
-        );
294
-        $datatypes = array(
295
-            '%s',// ATT_full_name
296
-            '%s',// ATT_bio
297
-            '%s',// ATT_slug
298
-            '%s',// ATT_created
299
-            '%s',// ATT_short_bio
300
-            '%s',// ATT_modified
301
-            '%d',// ATT_author
302
-            '%d',// ATT_parent
303
-            '%s',// post_type
304
-            '%s',// status
305
-        );
306
-        $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
307
-        if (! $success) {
308
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
309
-            return 0;
310
-        }
311
-        $new_id = $wpdb->insert_id;
312
-        return $new_id;
313
-    }
256
+		// even if there was no payment, we can go ahead with adding the reg
257
+		$new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id);
258
+		if ($new_regs) {
259
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs);
260
+		}
261
+	}
262
+	/**
263
+	 * Checks if there's already an attendee CPT in the db that has the same
264
+	 * first and last name, and email. If so, returns its ID as an int.
265
+	 * @global type $wpdb
266
+	 * @param array $old_attendee
267
+	 * @return int
268
+	 */
269
+	private function _find_attendee_cpt_matching($old_attendee)
270
+	{
271
+		global $wpdb;
272
+		$existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_new_attendee_cpt_table." AS cpt INNER JOIN ".$this->_new_attendee_meta_table." AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email']));
273
+		return intval($existing_attendee_id);
274
+	}
275
+	private function _insert_new_attendee_cpt($old_attendee)
276
+	{
277
+		global $wpdb;
278
+		$cols_n_values = array(
279
+			'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name
280
+			'post_content'=>'',// ATT_bio
281
+			'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug
282
+			'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
283
+			'post_excerpt'=>'',// ATT_short_bio
284
+			'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
285
+			'post_author'=>0,// ATT_author
286
+			'post_parent'=>0,// ATT_parent
287
+			'post_type'=>'espresso_attendees',// post_type
288
+			'post_status'=>'publish'// status
289
+		);
290
+		$datatypes = array(
291
+			'%s',// ATT_full_name
292
+			'%s',// ATT_bio
293
+			'%s',// ATT_slug
294
+			'%s',// ATT_created
295
+			'%s',// ATT_short_bio
296
+			'%s',// ATT_modified
297
+			'%d',// ATT_author
298
+			'%d',// ATT_parent
299
+			'%s',// post_type
300
+			'%s',// status
301
+		);
302
+		$success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
303
+		if (! $success) {
304
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
305
+			return 0;
306
+		}
307
+		$new_id = $wpdb->insert_id;
308
+		return $new_id;
309
+	}
314 310
 
315
-    private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id)
316
-    {
317
-        global $wpdb;
318
-        // get the state and country ids from the old row
319
-        try {
320
-            $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id']));
321
-            $new_country_iso = $new_country['CNT_ISO'];
322
-        } catch (EE_Error $exception) {
323
-            $new_country_iso = $this->get_migration_script()->get_default_country_iso();
324
-        }
325
-        try {
326
-            $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso);
327
-            $new_state_id = $new_state['STA_ID'];
328
-        } catch (EE_Error $exception) {
329
-            $new_state_id = 0;
330
-        }
331
-        $cols_n_values = array(
332
-            'ATT_ID'=>$new_attendee_cpt_id,
333
-            'ATT_fname'=>stripslashes($old_attendee['fname']),
334
-            'ATT_lname'=>stripslashes($old_attendee['lname']),
335
-            'ATT_address'=>stripslashes($old_attendee['address']),
336
-            'ATT_address2'=>stripslashes($old_attendee['address2']),
337
-            'ATT_city'=>stripslashes($old_attendee['city']),
338
-            'STA_ID'=>$new_state_id,
339
-            'CNT_ISO'=>$new_country_iso,
340
-            'ATT_zip'=>stripslashes($old_attendee['zip']),
341
-            'ATT_email'=>stripslashes($old_attendee['email']),
342
-            'ATT_phone'=>stripslashes($old_attendee['phone']),
343
-        );
344
-        $datatypes = array(
345
-            '%d',// ATT_ID
346
-            '%s',// ATT_fname
347
-            '%s',// ATT_lname
348
-            '%s',// ATT_address
349
-            '%s',// ATT_address2
350
-            '%s',// ATT_city
351
-            '%d',// STA_ID
352
-            '%s',// CNT_ISO
353
-            '%s',// ATT_zip
354
-            '%s',// ATT_email
355
-            '%s',// ATT_phone
356
-        );
357
-        $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
358
-        if (! $success) {
359
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes));
360
-            return 0;
361
-        }
362
-        $new_id = $wpdb->insert_id;
363
-        return $new_id;
364
-    }
311
+	private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id)
312
+	{
313
+		global $wpdb;
314
+		// get the state and country ids from the old row
315
+		try {
316
+			$new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id']));
317
+			$new_country_iso = $new_country['CNT_ISO'];
318
+		} catch (EE_Error $exception) {
319
+			$new_country_iso = $this->get_migration_script()->get_default_country_iso();
320
+		}
321
+		try {
322
+			$new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso);
323
+			$new_state_id = $new_state['STA_ID'];
324
+		} catch (EE_Error $exception) {
325
+			$new_state_id = 0;
326
+		}
327
+		$cols_n_values = array(
328
+			'ATT_ID'=>$new_attendee_cpt_id,
329
+			'ATT_fname'=>stripslashes($old_attendee['fname']),
330
+			'ATT_lname'=>stripslashes($old_attendee['lname']),
331
+			'ATT_address'=>stripslashes($old_attendee['address']),
332
+			'ATT_address2'=>stripslashes($old_attendee['address2']),
333
+			'ATT_city'=>stripslashes($old_attendee['city']),
334
+			'STA_ID'=>$new_state_id,
335
+			'CNT_ISO'=>$new_country_iso,
336
+			'ATT_zip'=>stripslashes($old_attendee['zip']),
337
+			'ATT_email'=>stripslashes($old_attendee['email']),
338
+			'ATT_phone'=>stripslashes($old_attendee['phone']),
339
+		);
340
+		$datatypes = array(
341
+			'%d',// ATT_ID
342
+			'%s',// ATT_fname
343
+			'%s',// ATT_lname
344
+			'%s',// ATT_address
345
+			'%s',// ATT_address2
346
+			'%s',// ATT_city
347
+			'%d',// STA_ID
348
+			'%s',// CNT_ISO
349
+			'%s',// ATT_zip
350
+			'%s',// ATT_email
351
+			'%s',// ATT_phone
352
+		);
353
+		$success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
354
+		if (! $success) {
355
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes));
356
+			return 0;
357
+		}
358
+		$new_id = $wpdb->insert_id;
359
+		return $new_id;
360
+	}
365 361
 
366
-    /**
367
-     * Note: we don't necessarily create a new transaction for each attendee row.
368
-     * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that
369
-     * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id
370
-     * @global type $wpdb
371
-     * @param type $old_attendee
372
-     * @return int new transaction id
373
-     */
374
-    private function _insert_new_transaction($old_attendee)
375
-    {
376
-        global $wpdb;
362
+	/**
363
+	 * Note: we don't necessarily create a new transaction for each attendee row.
364
+	 * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that
365
+	 * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id
366
+	 * @global type $wpdb
367
+	 * @param type $old_attendee
368
+	 * @return int new transaction id
369
+	 */
370
+	private function _insert_new_transaction($old_attendee)
371
+	{
372
+		global $wpdb;
377 373
 
378
-        // first: let's check for an existing transaction for this old attendee
379
-        if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn
380
-            $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
381
-        } else { // non-primary attendee, so find its primary attendee's transaction
382
-            $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id']));
383
-            if (! $primary_attendee_old_id) {
384
-                $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
385
-                $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
386
-            }
387
-            $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
388
-            if (! $txn_id) {
389
-                $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id));
390
-                $txn_id = 0;
391
-            }
392
-        }
393
-        // if there isn't yet a transaction row for this, create one
394
-        // (so even if it was a non-primary attendee with no EE3 primary attendee,
395
-        // it ought to have SOME transaction, so we'll make one)
396
-        if (! $txn_id) {
397
-            // maps 3.1 payment stati onto 4.1 transaction stati
398
-            $txn_status_mapping = array(
399
-                'Completed'=>'TCM',
400
-                'Pending'=>'TIN',
401
-                'Payment Declined'=>'TIN',
402
-                'Incomplete'=>'TIN',
403
-                'Not Completed'=>'TIN',
404
-                'Cancelled'=>'TIN',
405
-                'Declined'=>'TIN'
406
-            );
407
-            $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
408
-            $cols_n_values = array(
409
-                'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
410
-                'TXN_total'=>floatval($old_attendee['total_cost']),
411
-                'TXN_paid'=>floatval($old_attendee['amount_pd']),
412
-                'STS_ID'=>$STS_ID,
413
-                'TXN_hash_salt'=>$old_attendee['hashSalt']
414
-            );
415
-            $datatypes = array(
416
-                '%s',// TXN_timestamp
417
-                '%f',// TXN_total
418
-                '%f',// TXN_paid
419
-                '%s',// STS_ID
420
-                '%s',// TXN_hash_salt
421
-            );
422
-            $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
423
-            if (! $success) {
424
-                $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes));
425
-                return 0;
426
-            }
427
-            $txn_id = $wpdb->insert_id;
428
-        }
374
+		// first: let's check for an existing transaction for this old attendee
375
+		if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn
376
+			$txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
377
+		} else { // non-primary attendee, so find its primary attendee's transaction
378
+			$primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id']));
379
+			if (! $primary_attendee_old_id) {
380
+				$primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
381
+				$primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
382
+			}
383
+			$txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
384
+			if (! $txn_id) {
385
+				$this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id));
386
+				$txn_id = 0;
387
+			}
388
+		}
389
+		// if there isn't yet a transaction row for this, create one
390
+		// (so even if it was a non-primary attendee with no EE3 primary attendee,
391
+		// it ought to have SOME transaction, so we'll make one)
392
+		if (! $txn_id) {
393
+			// maps 3.1 payment stati onto 4.1 transaction stati
394
+			$txn_status_mapping = array(
395
+				'Completed'=>'TCM',
396
+				'Pending'=>'TIN',
397
+				'Payment Declined'=>'TIN',
398
+				'Incomplete'=>'TIN',
399
+				'Not Completed'=>'TIN',
400
+				'Cancelled'=>'TIN',
401
+				'Declined'=>'TIN'
402
+			);
403
+			$STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
404
+			$cols_n_values = array(
405
+				'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
406
+				'TXN_total'=>floatval($old_attendee['total_cost']),
407
+				'TXN_paid'=>floatval($old_attendee['amount_pd']),
408
+				'STS_ID'=>$STS_ID,
409
+				'TXN_hash_salt'=>$old_attendee['hashSalt']
410
+			);
411
+			$datatypes = array(
412
+				'%s',// TXN_timestamp
413
+				'%f',// TXN_total
414
+				'%f',// TXN_paid
415
+				'%s',// STS_ID
416
+				'%s',// TXN_hash_salt
417
+			);
418
+			$success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
419
+			if (! $success) {
420
+				$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes));
421
+				return 0;
422
+			}
423
+			$txn_id = $wpdb->insert_id;
424
+		}
429 425
 
430
-        return $txn_id;
431
-    }
432
-    /**
433
-     * Detects if the MER tables exist
434
-     * @global type $wpdb
435
-     * @return boolean
436
-     */
437
-    private function _mer_tables_exist()
438
-    {
439
-        if ($this->_mer_tables_exist === null) {
440
-            global $wpdb;
426
+		return $txn_id;
427
+	}
428
+	/**
429
+	 * Detects if the MER tables exist
430
+	 * @global type $wpdb
431
+	 * @return boolean
432
+	 */
433
+	private function _mer_tables_exist()
434
+	{
435
+		if ($this->_mer_tables_exist === null) {
436
+			global $wpdb;
441 437
 
442
-            if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) {
443
-                $this->_mer_tables_exist = false;
444
-            } else {
445
-                $this->_mer_tables_exist = true;
446
-            }
447
-        }
448
-        return $this->_mer_tables_exist;
449
-    }
438
+			if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) {
439
+				$this->_mer_tables_exist = false;
440
+			} else {
441
+				$this->_mer_tables_exist = true;
442
+			}
443
+		}
444
+		return $this->_mer_tables_exist;
445
+	}
450 446
 
451
-    /**
452
-     * Gets the 4.1 registration's status given the 3.1 attendee row. We consider
453
-     * whether the event required pre-approval or not,a dn the 4.1 payment status.
454
-     * @global type $wpdb
455
-     * @param type $old_attendee_row
456
-     * @return string
457
-     */
458
-    private function _get_reg_status_for_old_payment_status($old_attendee_row)
459
-    {
460
-        // need event default reg status and if pre_approval was required
461
-        global $wpdb;
462
-        $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM ".$wpdb->prefix."events_detail WHERE id = %d", $old_attendee_row['event_id']));
463
-        return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(
464
-            $old_attendee_row['payment_status'],
465
-            intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve'])
466
-        );
467
-    }
468
-    /**
469
-     * Adds however many rgistrations are indicated by the old attendee's QUANTITY field,
470
-     * and returns an array of their IDs
471
-     * @global type $wpdb
472
-     * @param array $old_attendee
473
-     * @param int $new_attendee_id
474
-     * @param int $new_txn_id
475
-     * @return array of new registratio ids
476
-     */
477
-    private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id)
478
-    {
479
-        global $wpdb;
447
+	/**
448
+	 * Gets the 4.1 registration's status given the 3.1 attendee row. We consider
449
+	 * whether the event required pre-approval or not,a dn the 4.1 payment status.
450
+	 * @global type $wpdb
451
+	 * @param type $old_attendee_row
452
+	 * @return string
453
+	 */
454
+	private function _get_reg_status_for_old_payment_status($old_attendee_row)
455
+	{
456
+		// need event default reg status and if pre_approval was required
457
+		global $wpdb;
458
+		$event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM ".$wpdb->prefix."events_detail WHERE id = %d", $old_attendee_row['event_id']));
459
+		return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(
460
+			$old_attendee_row['payment_status'],
461
+			intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve'])
462
+		);
463
+	}
464
+	/**
465
+	 * Adds however many rgistrations are indicated by the old attendee's QUANTITY field,
466
+	 * and returns an array of their IDs
467
+	 * @global type $wpdb
468
+	 * @param array $old_attendee
469
+	 * @param int $new_attendee_id
470
+	 * @param int $new_txn_id
471
+	 * @return array of new registratio ids
472
+	 */
473
+	private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id)
474
+	{
475
+		global $wpdb;
480 476
 
481
-        $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
482
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts);
483
-        if (! $new_event_id) {
484
-            $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
485
-        }
477
+		$STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
478
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts);
479
+		if (! $new_event_id) {
480
+			$this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
481
+		}
486 482
 
487
-        $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
488
-        if (! $ticket_id) {
489
-            $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
490
-            $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id));
491
-        }
492
-        $regs_on_this_row = intval($old_attendee['quantity']);
493
-        $new_regs = array();
494
-        // 4 cases we need to account for:
495
-        // 1 old attendee_details row with a quantity of X (no mer)
496
-        // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id
497
-        // Y old attendee_details rows with a quantity of x (because of mer)
498
-        // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group
499
-        for ($count = 1; $count <= $regs_on_this_row; $count++) {
500
-            // sum regs on older rows
501
-            $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true);
502
-            $cols_n_values = array(
503
-                'EVT_ID'=>$new_event_id,
504
-                'ATT_ID'=>$new_attendee_id,
505
-                'TXN_ID'=>$new_txn_id,
506
-                'TKT_ID'=>$ticket_id,
507
-                'STS_ID'=>$STS_ID,
508
-                'REG_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
509
-                'REG_final_price'=>$old_attendee['final_price'],
510
-                'REG_session'=> substr($old_attendee['attendee_session'], 0, 44),
511
-                'REG_code'=>sanitize_key($old_attendee['registration_id']),
512
-                'REG_url_link'=>  sanitize_key($old_attendee['registration_id'].'-'.$count),
513
-                'REG_count'=>$regs_on_this_event_and_txn + $count,
514
-                'REG_group_size'=>$this->_sum_old_attendees_on_old_txn($old_attendee, false),
515
-                'REG_att_is_going'=>true,
516
-                'REG_deleted'=>false
517
-            );
518
-            $datatypes = array(
519
-                '%d',// EVT_ID
520
-                '%d',// ATT_ID
521
-                '%d',// TXN_ID
522
-                '%d',// TKT_ID
523
-                '%s',// STS_ID
524
-                '%s',// REG_date
525
-                '%f',// REG_final_price
526
-                '%s',// REG_session
527
-                '%s',// REG_code
528
-                '%s',// REG_url_link
529
-                '%d',// REG_count
530
-                '%d',// REG_group_size
531
-                '%d',// REG_att_is_going
532
-                '%d',// REG_deleted
533
-            );
534
-            $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
535
-            if (! $success) {
536
-                $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes));
537
-                return 0;
538
-            }
539
-            $cols_n_values['REG_ID'] = $wpdb->insert_id;
540
-            $new_regs[] = $wpdb->insert_id;
541
-        }
542
-        $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID);
543
-        return $new_regs;
544
-    }
483
+		$ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
484
+		if (! $ticket_id) {
485
+			$ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
486
+			$this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id));
487
+		}
488
+		$regs_on_this_row = intval($old_attendee['quantity']);
489
+		$new_regs = array();
490
+		// 4 cases we need to account for:
491
+		// 1 old attendee_details row with a quantity of X (no mer)
492
+		// Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id
493
+		// Y old attendee_details rows with a quantity of x (because of mer)
494
+		// Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group
495
+		for ($count = 1; $count <= $regs_on_this_row; $count++) {
496
+			// sum regs on older rows
497
+			$regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true);
498
+			$cols_n_values = array(
499
+				'EVT_ID'=>$new_event_id,
500
+				'ATT_ID'=>$new_attendee_id,
501
+				'TXN_ID'=>$new_txn_id,
502
+				'TKT_ID'=>$ticket_id,
503
+				'STS_ID'=>$STS_ID,
504
+				'REG_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
505
+				'REG_final_price'=>$old_attendee['final_price'],
506
+				'REG_session'=> substr($old_attendee['attendee_session'], 0, 44),
507
+				'REG_code'=>sanitize_key($old_attendee['registration_id']),
508
+				'REG_url_link'=>  sanitize_key($old_attendee['registration_id'].'-'.$count),
509
+				'REG_count'=>$regs_on_this_event_and_txn + $count,
510
+				'REG_group_size'=>$this->_sum_old_attendees_on_old_txn($old_attendee, false),
511
+				'REG_att_is_going'=>true,
512
+				'REG_deleted'=>false
513
+			);
514
+			$datatypes = array(
515
+				'%d',// EVT_ID
516
+				'%d',// ATT_ID
517
+				'%d',// TXN_ID
518
+				'%d',// TKT_ID
519
+				'%s',// STS_ID
520
+				'%s',// REG_date
521
+				'%f',// REG_final_price
522
+				'%s',// REG_session
523
+				'%s',// REG_code
524
+				'%s',// REG_url_link
525
+				'%d',// REG_count
526
+				'%d',// REG_group_size
527
+				'%d',// REG_att_is_going
528
+				'%d',// REG_deleted
529
+			);
530
+			$success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
531
+			if (! $success) {
532
+				$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes));
533
+				return 0;
534
+			}
535
+			$cols_n_values['REG_ID'] = $wpdb->insert_id;
536
+			$new_regs[] = $wpdb->insert_id;
537
+		}
538
+		$this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID);
539
+		return $new_regs;
540
+	}
545 541
 
546
-    /**
547
-     * Increments the sold values on the ticket and its related datetimes by the amount sold,
548
-     * which should be done directly after adding the rows. Yes this means we're constantly incrementing
549
-     * the sold amounts as we go, and is less efficient than a single big query,
550
-     * but its safer because we KNOW these regs have been added, rather than inferring
551
-     * that they WILL be added (because the attendees stage runs nearly last during
552
-     * the migration script)
553
-     * @param type $new_ticket_id
554
-     * @param type $sold
555
-     * @param type $STS_ID
556
-     * @return boolean whether they were successfully updated or not
557
-     */
558
-    protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
559
-    {
560
-        if ($STS_ID != 'RAP') {
561
-            return true;
562
-        }
563
-        global $wpdb;
564
-        $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id));
565
-        if ($success) {
566
-            // get the ticket's datetimes, and increment them too
567
-            $success_update_dateimtes =  $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
542
+	/**
543
+	 * Increments the sold values on the ticket and its related datetimes by the amount sold,
544
+	 * which should be done directly after adding the rows. Yes this means we're constantly incrementing
545
+	 * the sold amounts as we go, and is less efficient than a single big query,
546
+	 * but its safer because we KNOW these regs have been added, rather than inferring
547
+	 * that they WILL be added (because the attendees stage runs nearly last during
548
+	 * the migration script)
549
+	 * @param type $new_ticket_id
550
+	 * @param type $sold
551
+	 * @param type $STS_ID
552
+	 * @return boolean whether they were successfully updated or not
553
+	 */
554
+	protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
555
+	{
556
+		if ($STS_ID != 'RAP') {
557
+			return true;
558
+		}
559
+		global $wpdb;
560
+		$success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id));
561
+		if ($success) {
562
+			// get the ticket's datetimes, and increment them too
563
+			$success_update_dateimtes =  $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
568 564
 				INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID
569 565
 				INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID
570 566
 				SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id));
571
-            if (! $success_update_dateimtes) {
572
-                $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
573
-            }
574
-        } else {
575
-            $this->add_error(sprintf(__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
576
-        }
577
-        return true;
578
-    }
579
-    /**
580
-     * Makes a best guess at which ticket is the one the attendee purchased.
581
-     * Obviously, the old attendee's event_id narrows it down quite a bit;
582
-     * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket
583
-     * however, if we don't find an exact match, see if any of those conditions match;
584
-     * and lastly if none of that works, just use the first ticket for the event we find
585
-     * @param array $old_attendee
586
-     */
587
-    private function _try_to_find_new_ticket_id($old_attendee, $new_event_id)
588
-    {
589
-        global $wpdb;
590
-        $tickets_table = $this->_new_ticket_table;
591
-        $datetime_tickets_table = $this->_new_ticket_datetime_table;
592
-        $datetime_table = $this->_new_datetime_table;
567
+			if (! $success_update_dateimtes) {
568
+				$this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
569
+			}
570
+		} else {
571
+			$this->add_error(sprintf(__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
572
+		}
573
+		return true;
574
+	}
575
+	/**
576
+	 * Makes a best guess at which ticket is the one the attendee purchased.
577
+	 * Obviously, the old attendee's event_id narrows it down quite a bit;
578
+	 * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket
579
+	 * however, if we don't find an exact match, see if any of those conditions match;
580
+	 * and lastly if none of that works, just use the first ticket for the event we find
581
+	 * @param array $old_attendee
582
+	 */
583
+	private function _try_to_find_new_ticket_id($old_attendee, $new_event_id)
584
+	{
585
+		global $wpdb;
586
+		$tickets_table = $this->_new_ticket_table;
587
+		$datetime_tickets_table = $this->_new_ticket_datetime_table;
588
+		$datetime_table = $this->_new_datetime_table;
593 589
 
594
-        $old_att_price_option = $old_attendee['price_option'];
595
-        $old_att_price = floatval($old_attendee['orig_price']);
590
+		$old_att_price_option = $old_attendee['price_option'];
591
+		$old_att_price = floatval($old_attendee['orig_price']);
596 592
 
597
-        $old_att_start_date = $old_attendee['start_date'];
598
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
599
-        $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
600
-        // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
601
-        // the most important condition should be last, as it will be array_shift'ed off last
602
-        $conditions = array(
603
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
604
-            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
605
-            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
606
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
607
-        );
608
-        $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
593
+		$old_att_start_date = $old_attendee['start_date'];
594
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
595
+		$old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
596
+		// add all conditions to an array from which we can SHIFT conditions off in order to widen our search
597
+		// the most important condition should be last, as it will be array_shift'ed off last
598
+		$conditions = array(
599
+			$wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
600
+			$wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
601
+			$wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
602
+			$wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
603
+		);
604
+		$select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
609 605
 			$datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN
610 606
 			$datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID";
611
-        // start running queries, widening search each time by removing a condition
612
-        do {
613
-            $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1";
614
-            $ticket_id_found = $wpdb->get_var($full_query);
615
-            array_shift($conditions);
616
-        } while (! $ticket_id_found && $conditions);
617
-        return $ticket_id_found;
618
-    }
607
+		// start running queries, widening search each time by removing a condition
608
+		do {
609
+			$full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1";
610
+			$ticket_id_found = $wpdb->get_var($full_query);
611
+			array_shift($conditions);
612
+		} while (! $ticket_id_found && $conditions);
613
+		return $ticket_id_found;
614
+	}
619 615
 
620
-    /**
621
-     * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one;
622
-     * and it also tries to find a datetime that works, and a inserts a price, and associates
623
-     * the new ticket to that datetime and price.
624
-     * @return int ticket id
625
-     */
626
-    private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id)
627
-    {
628
-        global $wpdb;
629
-        $old_att_price_option = $old_attendee['price_option'];
630
-        $old_att_price = floatval($old_attendee['orig_price']);
616
+	/**
617
+	 * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one;
618
+	 * and it also tries to find a datetime that works, and a inserts a price, and associates
619
+	 * the new ticket to that datetime and price.
620
+	 * @return int ticket id
621
+	 */
622
+	private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id)
623
+	{
624
+		global $wpdb;
625
+		$old_att_price_option = $old_attendee['price_option'];
626
+		$old_att_price = floatval($old_attendee['orig_price']);
631 627
 
632
-        $old_att_start_date = $old_attendee['start_date'];
633
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
634
-        $old_att_start_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
628
+		$old_att_start_date = $old_attendee['start_date'];
629
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
630
+		$old_att_start_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
635 631
 
636 632
 
637
-        // insert new datetime unless we find one
638
-        $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A);
639
-        if (! $datetime_id) {
640
-            $old_att_end_date = $old_attendee['start_date'];
641
-            $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
642
-            $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00");
643
-            $wpdb->insert(
644
-                $this->_new_datetime_table,
645
-                array(
646
-                        'EVT_ID' => $new_event_id,
647
-                        'DTT_EVT_start' => $old_att_start_datetime,
648
-                        'DTT_EVT_end' => $old_att_end_datetime,
649
-                        'DTT_deleted' => true
650
-                    ),
651
-                array(
652
-                        '%d',// EVT_ID
653
-                        '%s',// DTT_EVT_start
654
-                        '%s',// DTT_EVT_end
655
-                        '%d',// DTT_deleted
656
-                    )
657
-            );
658
-            $datetime_id = $wpdb->insert_id;
659
-        }
633
+		// insert new datetime unless we find one
634
+		$datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A);
635
+		if (! $datetime_id) {
636
+			$old_att_end_date = $old_attendee['start_date'];
637
+			$old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
638
+			$old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00");
639
+			$wpdb->insert(
640
+				$this->_new_datetime_table,
641
+				array(
642
+						'EVT_ID' => $new_event_id,
643
+						'DTT_EVT_start' => $old_att_start_datetime,
644
+						'DTT_EVT_end' => $old_att_end_datetime,
645
+						'DTT_deleted' => true
646
+					),
647
+				array(
648
+						'%d',// EVT_ID
649
+						'%s',// DTT_EVT_start
650
+						'%s',// DTT_EVT_end
651
+						'%d',// DTT_deleted
652
+					)
653
+			);
654
+			$datetime_id = $wpdb->insert_id;
655
+		}
660 656
 
661
-        // insert new ticket
662
-        $success = $wpdb->insert(
663
-            $wpdb->prefix . 'esp_ticket',
664
-            array(
665
-                    'TKT_name' => $old_att_price_option,
666
-                    'TKT_qty' => -1,
667
-                    'TKT_price' => $old_att_price,
668
-                    'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended
669
-                    'TKT_end_date' => $old_att_end_datetime,
657
+		// insert new ticket
658
+		$success = $wpdb->insert(
659
+			$wpdb->prefix . 'esp_ticket',
660
+			array(
661
+					'TKT_name' => $old_att_price_option,
662
+					'TKT_qty' => -1,
663
+					'TKT_price' => $old_att_price,
664
+					'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended
665
+					'TKT_end_date' => $old_att_end_datetime,
670 666
 
671
-                ),
672
-            array(
673
-                    '%s',// name
674
-                    '%d',// qty
675
-                    '%d',// price
676
-                    '%s',// start_date
677
-                    '%s',// end_date
678
-                )
679
-        );
680
-        $ticket_id = $wpdb->insert_id;
681
-        // associate the ticket with the datetime we found earlier
682
-        $wpdb->insert(
683
-            $this->_new_datetime_ticket_table,
684
-            array(
685
-                    'DTT_ID' => $datetime_id,
686
-                    'TKT_ID' => $ticket_id
687
-                ),
688
-            array(
689
-                    '%d',// DTT_ID
690
-                    '%d',// TKT_ID
691
-                )
692
-        );
693
-        // insert new price
694
-        $wpdb->insert(
695
-            $this->_new_price_table,
696
-            array(
697
-                    'PRC_amount' => $old_att_price,
698
-                    'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base,
699
-                    'PRC_name' => $old_att_price_option,
700
-                    'PRC_deleted' => true
701
-                ),
702
-            array(
703
-                    '%d',// PRC_amount
704
-                    '%d',// PRT_ID
705
-                    '%s',// PRC_name
706
-                    '%d',// PRC_deleted
707
-                )
708
-        );
709
-        $price_id = $wpdb->insert_id;
710
-        // associate the price to the ticket
711
-        $wpdb->insert(
712
-            $this->_new_ticket_price_table,
713
-            array(
714
-                    'TKT_ID' => $ticket_id,
715
-                    'PRC_ID' => $price_id
716
-                ),
717
-            array(
718
-                    '%d',// TKT_ID
719
-                    '%d',// PRC_ID
720
-                )
721
-        );
722
-        return $ticket_id;
723
-    }
724
-    /**
725
-     * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie,
726
-     * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL
727
-     * @global type $wpdb
728
-     * @param array $old_attendee_row
729
-     * @param boolean $count_only_older true if you want the running count (ie, the total up to this row), and false if you want ALL
730
-     * @return int
731
-     */
732
-    private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false)
733
-    {
734
-        global $wpdb;
735
-        $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : '';
736
-        $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM ".$this->_old_table." WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id'])));
667
+				),
668
+			array(
669
+					'%s',// name
670
+					'%d',// qty
671
+					'%d',// price
672
+					'%s',// start_date
673
+					'%s',// end_date
674
+				)
675
+		);
676
+		$ticket_id = $wpdb->insert_id;
677
+		// associate the ticket with the datetime we found earlier
678
+		$wpdb->insert(
679
+			$this->_new_datetime_ticket_table,
680
+			array(
681
+					'DTT_ID' => $datetime_id,
682
+					'TKT_ID' => $ticket_id
683
+				),
684
+			array(
685
+					'%d',// DTT_ID
686
+					'%d',// TKT_ID
687
+				)
688
+		);
689
+		// insert new price
690
+		$wpdb->insert(
691
+			$this->_new_price_table,
692
+			array(
693
+					'PRC_amount' => $old_att_price,
694
+					'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base,
695
+					'PRC_name' => $old_att_price_option,
696
+					'PRC_deleted' => true
697
+				),
698
+			array(
699
+					'%d',// PRC_amount
700
+					'%d',// PRT_ID
701
+					'%s',// PRC_name
702
+					'%d',// PRC_deleted
703
+				)
704
+		);
705
+		$price_id = $wpdb->insert_id;
706
+		// associate the price to the ticket
707
+		$wpdb->insert(
708
+			$this->_new_ticket_price_table,
709
+			array(
710
+					'TKT_ID' => $ticket_id,
711
+					'PRC_ID' => $price_id
712
+				),
713
+			array(
714
+					'%d',// TKT_ID
715
+					'%d',// PRC_ID
716
+				)
717
+		);
718
+		return $ticket_id;
719
+	}
720
+	/**
721
+	 * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie,
722
+	 * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL
723
+	 * @global type $wpdb
724
+	 * @param array $old_attendee_row
725
+	 * @param boolean $count_only_older true if you want the running count (ie, the total up to this row), and false if you want ALL
726
+	 * @return int
727
+	 */
728
+	private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false)
729
+	{
730
+		global $wpdb;
731
+		$count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : '';
732
+		$count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM ".$this->_old_table." WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id'])));
737 733
 
738
-        if ($this->_mer_tables_exist()) {
739
-            // if MER exists, then its a little tricky.
740
-            // when users registered by adding items to the cart, and it was a
741
-            // group registration requiring additional attendee INFO, then the attendee rows
742
-            // DO NOT have the same registration_id (although they probably should have)
743
-            // they are related just like MER attendee rows are related, through the MER group table
744
-            // BUT we want to count all the MER attendee rows for the same registration
745
-            $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']);
734
+		if ($this->_mer_tables_exist()) {
735
+			// if MER exists, then its a little tricky.
736
+			// when users registered by adding items to the cart, and it was a
737
+			// group registration requiring additional attendee INFO, then the attendee rows
738
+			// DO NOT have the same registration_id (although they probably should have)
739
+			// they are related just like MER attendee rows are related, through the MER group table
740
+			// BUT we want to count all the MER attendee rows for the same registration
741
+			$primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']);
746 742
 
747
-            $count_using_mer_table = $wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM {$this->_old_table} att INNER JOIN {$this->_old_mer_table} mer ON att.registration_id = mer.registration_id WHERE att.event_id=%d AND mer.primary_registration_id = %s $count_only_older_sql", $old_attendee_row['event_id'], $primary_attendee['registration_id']));
748
-            $count = max($count_using_mer_table, $count);
749
-        }
750
-        return $count;
751
-    }
752
-    private function _insert_new_payment($old_attendee, $new_txn_id)
753
-    {
754
-        global $wpdb;
755
-        // only add a payment for primary attendees
756
-        $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed');
757
-        // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
758
-        if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
759
-            $pay_status_mapping = array(
760
-                'Completed'=>'PAP',
761
-                'Payment Declined'=>'PDC',
762
-                'Cancelled'=>'PCN',
763
-                'Declined'=>'PDC'
764
-            );
765
-            $by_admin = $old_attendee['payment'] == 'Admin';
766
-            $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed
767
-            $cols_n_values = array(
768
-                'TXN_ID'=>$new_txn_id,
769
-                'STS_ID'=>$STS_ID,
770
-                'PAY_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
771
-                'PAY_method'=>'CART',
772
-                'PAY_amount'=>$old_attendee['amount_pd'],
773
-                'PAY_gateway'=>$old_attendee['txn_type'],
774
-                'PAY_gateway_response'=>'',
775
-                'PAY_txn_id_chq_nmbr'=>substr($old_attendee['txn_id'], 0, 32),
776
-                'PAY_via_admin'=>$by_admin,
777
-                'PAY_details'=>$old_attendee['transaction_details']
743
+			$count_using_mer_table = $wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM {$this->_old_table} att INNER JOIN {$this->_old_mer_table} mer ON att.registration_id = mer.registration_id WHERE att.event_id=%d AND mer.primary_registration_id = %s $count_only_older_sql", $old_attendee_row['event_id'], $primary_attendee['registration_id']));
744
+			$count = max($count_using_mer_table, $count);
745
+		}
746
+		return $count;
747
+	}
748
+	private function _insert_new_payment($old_attendee, $new_txn_id)
749
+	{
750
+		global $wpdb;
751
+		// only add a payment for primary attendees
752
+		$old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed');
753
+		// if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
754
+		if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
755
+			$pay_status_mapping = array(
756
+				'Completed'=>'PAP',
757
+				'Payment Declined'=>'PDC',
758
+				'Cancelled'=>'PCN',
759
+				'Declined'=>'PDC'
760
+			);
761
+			$by_admin = $old_attendee['payment'] == 'Admin';
762
+			$STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed
763
+			$cols_n_values = array(
764
+				'TXN_ID'=>$new_txn_id,
765
+				'STS_ID'=>$STS_ID,
766
+				'PAY_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
767
+				'PAY_method'=>'CART',
768
+				'PAY_amount'=>$old_attendee['amount_pd'],
769
+				'PAY_gateway'=>$old_attendee['txn_type'],
770
+				'PAY_gateway_response'=>'',
771
+				'PAY_txn_id_chq_nmbr'=>substr($old_attendee['txn_id'], 0, 32),
772
+				'PAY_via_admin'=>$by_admin,
773
+				'PAY_details'=>$old_attendee['transaction_details']
778 774
 
779
-            );
780
-            $datatypes = array(
781
-                '%d',// TXN_Id
782
-                '%s',// STS_ID
783
-                '%s',// PAY_timestamp
784
-                '%s',// PAY_method
785
-                '%f',// PAY_amount
786
-                '%s',// PAY_gateway
787
-                '%s',// PAY_gateway_response
788
-                '%s',// PAY_txn_id_chq_nmbr
789
-                '%d',// PAY_via_admin
790
-                '%s',// PAY_details
791
-            );
792
-            $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
793
-            if (! $success) {
794
-                $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
795
-                return 0;
796
-            }
797
-            $new_id = $wpdb->insert_id;
798
-            return $new_id;
799
-        } else {
800
-            return 0;
801
-        }
802
-    }
775
+			);
776
+			$datatypes = array(
777
+				'%d',// TXN_Id
778
+				'%s',// STS_ID
779
+				'%s',// PAY_timestamp
780
+				'%s',// PAY_method
781
+				'%f',// PAY_amount
782
+				'%s',// PAY_gateway
783
+				'%s',// PAY_gateway_response
784
+				'%s',// PAY_txn_id_chq_nmbr
785
+				'%d',// PAY_via_admin
786
+				'%s',// PAY_details
787
+			);
788
+			$success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
789
+			if (! $success) {
790
+				$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
791
+				return 0;
792
+			}
793
+			$new_id = $wpdb->insert_id;
794
+			return $new_id;
795
+		} else {
796
+			return 0;
797
+		}
798
+	}
803 799
 
804
-    /**
805
-     * If MER is active, if you want ot fin dthe other registrations on that attendee row
806
-     * @global type $wpdb
807
-     * @param type $old_registration_id
808
-     * @return array
809
-     */
810
-    private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
811
-    {
812
-        if (! $this->_mer_tables_exist()) {
813
-            return false;
814
-        }
815
-        global $wpdb;
816
-        $old_att_for_primary_reg = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->_old_mer_table} AS mer INNER JOIN {$this->_old_table} AS att ON mer.primary_registration_id = att.registration_id WHERE mer.registration_id=%s LIMIT 1", $old_registration_id), ARRAY_A);
817
-        return $old_att_for_primary_reg;
818
-    }
800
+	/**
801
+	 * If MER is active, if you want ot fin dthe other registrations on that attendee row
802
+	 * @global type $wpdb
803
+	 * @param type $old_registration_id
804
+	 * @return array
805
+	 */
806
+	private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
807
+	{
808
+		if (! $this->_mer_tables_exist()) {
809
+			return false;
810
+		}
811
+		global $wpdb;
812
+		$old_att_for_primary_reg = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->_old_mer_table} AS mer INNER JOIN {$this->_old_table} AS att ON mer.primary_registration_id = att.registration_id WHERE mer.registration_id=%s LIMIT 1", $old_registration_id), ARRAY_A);
813
+		return $old_att_for_primary_reg;
814
+	}
819 815
 }
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         $this->_pretty_name = __("Attendees", "event_espresso");
211 211
         $this->_old_table = $wpdb->prefix."events_attendee";
212 212
         $this->_extra_where_sql = 'AS att
213
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
213
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id
214 214
             WHERE e.event_status!="D"';
215 215
         $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group";
216 216
         $this->_new_attendee_cpt_table = $wpdb->posts;
@@ -232,9 +232,9 @@  discard block
 block discarded – undo
232 232
     {
233 233
         // first check if there's already a new attendee with similar characteristics
234 234
         $new_att_id = $this->_find_attendee_cpt_matching($old_row);
235
-        if (! $new_att_id) {
235
+        if ( ! $new_att_id) {
236 236
             $new_att_id = $this->_insert_new_attendee_cpt($old_row);
237
-            if (! $new_att_id) {
237
+            if ( ! $new_att_id) {
238 238
                 // if we couldnt even make an attendee, abandon all hope
239 239
                 return false;
240 240
             }
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
         $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
247 247
 
248 248
         $txn_id = $this->_insert_new_transaction($old_row);
249
-        if (! $txn_id) {
249
+        if ( ! $txn_id) {
250 250
             // if we couldnt make the transaction, also abandon all hope
251 251
             return false;
252 252
         }
@@ -280,31 +280,31 @@  discard block
 block discarded – undo
280 280
     {
281 281
         global $wpdb;
282 282
         $cols_n_values = array(
283
-            'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name
284
-            'post_content'=>'',// ATT_bio
285
-            'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug
286
-            'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
287
-            'post_excerpt'=>'',// ATT_short_bio
288
-            'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
289
-            'post_author'=>0,// ATT_author
290
-            'post_parent'=>0,// ATT_parent
291
-            'post_type'=>'espresso_attendees',// post_type
283
+            'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']), // ATT_full_name
284
+            'post_content'=>'', // ATT_bio
285
+            'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']), // ATT_slug
286
+            'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_created
287
+            'post_excerpt'=>'', // ATT_short_bio
288
+            'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_modified
289
+            'post_author'=>0, // ATT_author
290
+            'post_parent'=>0, // ATT_parent
291
+            'post_type'=>'espresso_attendees', // post_type
292 292
             'post_status'=>'publish'// status
293 293
         );
294 294
         $datatypes = array(
295
-            '%s',// ATT_full_name
296
-            '%s',// ATT_bio
297
-            '%s',// ATT_slug
298
-            '%s',// ATT_created
299
-            '%s',// ATT_short_bio
300
-            '%s',// ATT_modified
301
-            '%d',// ATT_author
302
-            '%d',// ATT_parent
303
-            '%s',// post_type
304
-            '%s',// status
295
+            '%s', // ATT_full_name
296
+            '%s', // ATT_bio
297
+            '%s', // ATT_slug
298
+            '%s', // ATT_created
299
+            '%s', // ATT_short_bio
300
+            '%s', // ATT_modified
301
+            '%d', // ATT_author
302
+            '%d', // ATT_parent
303
+            '%s', // post_type
304
+            '%s', // status
305 305
         );
306 306
         $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
307
-        if (! $success) {
307
+        if ( ! $success) {
308 308
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
309 309
             return 0;
310 310
         }
@@ -342,20 +342,20 @@  discard block
 block discarded – undo
342 342
             'ATT_phone'=>stripslashes($old_attendee['phone']),
343 343
         );
344 344
         $datatypes = array(
345
-            '%d',// ATT_ID
346
-            '%s',// ATT_fname
347
-            '%s',// ATT_lname
348
-            '%s',// ATT_address
349
-            '%s',// ATT_address2
350
-            '%s',// ATT_city
351
-            '%d',// STA_ID
352
-            '%s',// CNT_ISO
353
-            '%s',// ATT_zip
354
-            '%s',// ATT_email
355
-            '%s',// ATT_phone
345
+            '%d', // ATT_ID
346
+            '%s', // ATT_fname
347
+            '%s', // ATT_lname
348
+            '%s', // ATT_address
349
+            '%s', // ATT_address2
350
+            '%s', // ATT_city
351
+            '%d', // STA_ID
352
+            '%s', // CNT_ISO
353
+            '%s', // ATT_zip
354
+            '%s', // ATT_email
355
+            '%s', // ATT_phone
356 356
         );
357 357
         $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
358
-        if (! $success) {
358
+        if ( ! $success) {
359 359
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes));
360 360
             return 0;
361 361
         }
@@ -380,12 +380,12 @@  discard block
 block discarded – undo
380 380
             $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
381 381
         } else { // non-primary attendee, so find its primary attendee's transaction
382 382
             $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id']));
383
-            if (! $primary_attendee_old_id) {
383
+            if ( ! $primary_attendee_old_id) {
384 384
                 $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
385 385
                 $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
386 386
             }
387 387
             $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
388
-            if (! $txn_id) {
388
+            if ( ! $txn_id) {
389 389
                 $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id));
390 390
                 $txn_id = 0;
391 391
             }
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
         // if there isn't yet a transaction row for this, create one
394 394
         // (so even if it was a non-primary attendee with no EE3 primary attendee,
395 395
         // it ought to have SOME transaction, so we'll make one)
396
-        if (! $txn_id) {
396
+        if ( ! $txn_id) {
397 397
             // maps 3.1 payment stati onto 4.1 transaction stati
398 398
             $txn_status_mapping = array(
399 399
                 'Completed'=>'TCM',
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
                 'Cancelled'=>'TIN',
405 405
                 'Declined'=>'TIN'
406 406
             );
407
-            $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
407
+            $STS_ID = isset($txn_status_mapping[$old_attendee['payment_status']]) ? $txn_status_mapping[$old_attendee['payment_status']] : 'TIN';
408 408
             $cols_n_values = array(
409 409
                 'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
410 410
                 'TXN_total'=>floatval($old_attendee['total_cost']),
@@ -413,14 +413,14 @@  discard block
 block discarded – undo
413 413
                 'TXN_hash_salt'=>$old_attendee['hashSalt']
414 414
             );
415 415
             $datatypes = array(
416
-                '%s',// TXN_timestamp
417
-                '%f',// TXN_total
418
-                '%f',// TXN_paid
419
-                '%s',// STS_ID
420
-                '%s',// TXN_hash_salt
416
+                '%s', // TXN_timestamp
417
+                '%f', // TXN_total
418
+                '%f', // TXN_paid
419
+                '%s', // STS_ID
420
+                '%s', // TXN_hash_salt
421 421
             );
422 422
             $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
423
-            if (! $success) {
423
+            if ( ! $success) {
424 424
                 $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes));
425 425
                 return 0;
426 426
             }
@@ -480,12 +480,12 @@  discard block
 block discarded – undo
480 480
 
481 481
         $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
482 482
         $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts);
483
-        if (! $new_event_id) {
483
+        if ( ! $new_event_id) {
484 484
             $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
485 485
         }
486 486
 
487 487
         $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
488
-        if (! $ticket_id) {
488
+        if ( ! $ticket_id) {
489 489
             $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
490 490
             $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id));
491 491
         }
@@ -516,23 +516,23 @@  discard block
 block discarded – undo
516 516
                 'REG_deleted'=>false
517 517
             );
518 518
             $datatypes = array(
519
-                '%d',// EVT_ID
520
-                '%d',// ATT_ID
521
-                '%d',// TXN_ID
522
-                '%d',// TKT_ID
523
-                '%s',// STS_ID
524
-                '%s',// REG_date
525
-                '%f',// REG_final_price
526
-                '%s',// REG_session
527
-                '%s',// REG_code
528
-                '%s',// REG_url_link
529
-                '%d',// REG_count
530
-                '%d',// REG_group_size
531
-                '%d',// REG_att_is_going
532
-                '%d',// REG_deleted
519
+                '%d', // EVT_ID
520
+                '%d', // ATT_ID
521
+                '%d', // TXN_ID
522
+                '%d', // TKT_ID
523
+                '%s', // STS_ID
524
+                '%s', // REG_date
525
+                '%f', // REG_final_price
526
+                '%s', // REG_session
527
+                '%s', // REG_code
528
+                '%s', // REG_url_link
529
+                '%d', // REG_count
530
+                '%d', // REG_group_size
531
+                '%d', // REG_att_is_going
532
+                '%d', // REG_deleted
533 533
             );
534 534
             $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
535
-            if (! $success) {
535
+            if ( ! $success) {
536 536
                 $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes));
537 537
                 return 0;
538 538
             }
@@ -564,11 +564,11 @@  discard block
 block discarded – undo
564 564
         $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id));
565 565
         if ($success) {
566 566
             // get the ticket's datetimes, and increment them too
567
-            $success_update_dateimtes =  $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
567
+            $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
568 568
 				INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID
569 569
 				INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID
570 570
 				SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id));
571
-            if (! $success_update_dateimtes) {
571
+            if ( ! $success_update_dateimtes) {
572 572
                 $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
573 573
             }
574 574
         } else {
@@ -600,10 +600,10 @@  discard block
 block discarded – undo
600 600
         // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
601 601
         // the most important condition should be last, as it will be array_shift'ed off last
602 602
         $conditions = array(
603
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
604
-            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
605
-            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
606
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
603
+            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match?
604
+            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price), // prices match?
605
+            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option), // names match?
606
+            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match?
607 607
         );
608 608
         $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
609 609
 			$datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
             $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1";
614 614
             $ticket_id_found = $wpdb->get_var($full_query);
615 615
             array_shift($conditions);
616
-        } while (! $ticket_id_found && $conditions);
616
+        }while ( ! $ticket_id_found && $conditions);
617 617
         return $ticket_id_found;
618 618
     }
619 619
 
@@ -635,8 +635,8 @@  discard block
 block discarded – undo
635 635
 
636 636
 
637 637
         // insert new datetime unless we find one
638
-        $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A);
639
-        if (! $datetime_id) {
638
+        $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM ".$this->_new_datetime_table." WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A);
639
+        if ( ! $datetime_id) {
640 640
             $old_att_end_date = $old_attendee['start_date'];
641 641
             $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
642 642
             $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00");
@@ -649,10 +649,10 @@  discard block
 block discarded – undo
649 649
                         'DTT_deleted' => true
650 650
                     ),
651 651
                 array(
652
-                        '%d',// EVT_ID
653
-                        '%s',// DTT_EVT_start
654
-                        '%s',// DTT_EVT_end
655
-                        '%d',// DTT_deleted
652
+                        '%d', // EVT_ID
653
+                        '%s', // DTT_EVT_start
654
+                        '%s', // DTT_EVT_end
655
+                        '%d', // DTT_deleted
656 656
                     )
657 657
             );
658 658
             $datetime_id = $wpdb->insert_id;
@@ -660,21 +660,21 @@  discard block
 block discarded – undo
660 660
 
661 661
         // insert new ticket
662 662
         $success = $wpdb->insert(
663
-            $wpdb->prefix . 'esp_ticket',
663
+            $wpdb->prefix.'esp_ticket',
664 664
             array(
665 665
                     'TKT_name' => $old_att_price_option,
666 666
                     'TKT_qty' => -1,
667 667
                     'TKT_price' => $old_att_price,
668
-                    'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended
668
+                    'TKT_start_date' => $old_att_start_datetime, // we really have no clue what the time should be, but at least it was available when they attended
669 669
                     'TKT_end_date' => $old_att_end_datetime,
670 670
 
671 671
                 ),
672 672
             array(
673
-                    '%s',// name
674
-                    '%d',// qty
675
-                    '%d',// price
676
-                    '%s',// start_date
677
-                    '%s',// end_date
673
+                    '%s', // name
674
+                    '%d', // qty
675
+                    '%d', // price
676
+                    '%s', // start_date
677
+                    '%s', // end_date
678 678
                 )
679 679
         );
680 680
         $ticket_id = $wpdb->insert_id;
@@ -686,8 +686,8 @@  discard block
 block discarded – undo
686 686
                     'TKT_ID' => $ticket_id
687 687
                 ),
688 688
             array(
689
-                    '%d',// DTT_ID
690
-                    '%d',// TKT_ID
689
+                    '%d', // DTT_ID
690
+                    '%d', // TKT_ID
691 691
                 )
692 692
         );
693 693
         // insert new price
@@ -700,10 +700,10 @@  discard block
 block discarded – undo
700 700
                     'PRC_deleted' => true
701 701
                 ),
702 702
             array(
703
-                    '%d',// PRC_amount
704
-                    '%d',// PRT_ID
705
-                    '%s',// PRC_name
706
-                    '%d',// PRC_deleted
703
+                    '%d', // PRC_amount
704
+                    '%d', // PRT_ID
705
+                    '%s', // PRC_name
706
+                    '%d', // PRC_deleted
707 707
                 )
708 708
         );
709 709
         $price_id = $wpdb->insert_id;
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
                     'PRC_ID' => $price_id
716 716
                 ),
717 717
             array(
718
-                    '%d',// TKT_ID
719
-                    '%d',// PRC_ID
718
+                    '%d', // TKT_ID
719
+                    '%d', // PRC_ID
720 720
                 )
721 721
         );
722 722
         return $ticket_id;
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
     {
754 754
         global $wpdb;
755 755
         // only add a payment for primary attendees
756
-        $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed');
756
+        $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed');
757 757
         // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
758 758
         if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
759 759
             $pay_status_mapping = array(
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
                 'Declined'=>'PDC'
764 764
             );
765 765
             $by_admin = $old_attendee['payment'] == 'Admin';
766
-            $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed
766
+            $STS_ID = isset($pay_status_mapping[$old_attendee['payment_status']]) ? $pay_status_mapping[$old_attendee['payment_status']] : 'PFL'; // IE, if we don't recognize the status, assume payment failed
767 767
             $cols_n_values = array(
768 768
                 'TXN_ID'=>$new_txn_id,
769 769
                 'STS_ID'=>$STS_ID,
@@ -778,19 +778,19 @@  discard block
 block discarded – undo
778 778
 
779 779
             );
780 780
             $datatypes = array(
781
-                '%d',// TXN_Id
782
-                '%s',// STS_ID
783
-                '%s',// PAY_timestamp
784
-                '%s',// PAY_method
785
-                '%f',// PAY_amount
786
-                '%s',// PAY_gateway
787
-                '%s',// PAY_gateway_response
788
-                '%s',// PAY_txn_id_chq_nmbr
789
-                '%d',// PAY_via_admin
790
-                '%s',// PAY_details
781
+                '%d', // TXN_Id
782
+                '%s', // STS_ID
783
+                '%s', // PAY_timestamp
784
+                '%s', // PAY_method
785
+                '%f', // PAY_amount
786
+                '%s', // PAY_gateway
787
+                '%s', // PAY_gateway_response
788
+                '%s', // PAY_txn_id_chq_nmbr
789
+                '%d', // PAY_via_admin
790
+                '%s', // PAY_details
791 791
             );
792 792
             $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
793
-            if (! $success) {
793
+            if ( ! $success) {
794 794
                 $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
795 795
                 return 0;
796 796
             }
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
      */
810 810
     private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
811 811
     {
812
-        if (! $this->_mer_tables_exist()) {
812
+        if ( ! $this->_mer_tables_exist()) {
813 813
             return false;
814 814
         }
815 815
         global $wpdb;
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_checkins.dmsstage.php 3 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      * (because we know the attendee was for an event as a specific time, and we know
86 86
      * the event's OLD ID...)
87 87
      * @global type $wpdb
88
-     * @param array $old_attendee_row
88
+     * @param array $old_attendee
89 89
      * @return array row of datetime from DB
90 90
      */
91 91
     private function _try_to_find_datetime($old_attendee)
@@ -121,8 +121,7 @@  discard block
 block discarded – undo
121 121
     /**
122 122
      * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
123 123
      * @param int $new_reg_id
124
-     * @param int $new_datetime_id
125
-     * @param string $timestamp mysql datetime
124
+     * @param int $new_datetime
126 125
      * @return int new Check-in id
127 126
      */
128 127
     private function _insert_checkin_record($new_reg_id, $new_datetime)
Please login to merge, or discard this patch.
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -26,132 +26,132 @@
 block discarded – undo
26 26
 
27 27
 class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table
28 28
 {
29
-    private $_new_table;
30
-    public function __construct()
31
-    {
32
-        global $wpdb;
33
-        $this->_pretty_name = __("Checkins", "event_espresso");
34
-        $this->_old_table = $wpdb->prefix."events_attendee";
35
-        $this->_extra_where_sql = 'AS att
29
+	private $_new_table;
30
+	public function __construct()
31
+	{
32
+		global $wpdb;
33
+		$this->_pretty_name = __("Checkins", "event_espresso");
34
+		$this->_old_table = $wpdb->prefix."events_attendee";
35
+		$this->_extra_where_sql = 'AS att
36 36
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
37 37
             WHERE e.event_status!="D"';
38
-        $this->_new_table = $wpdb->prefix."esp_checkin";
39
-        parent::__construct();
40
-    }
41
-    protected function _migrate_old_row($old_row)
42
-    {
43
-        global $wpdb;
44
-        $new_reg_table = $wpdb->prefix."esp_registration";
38
+		$this->_new_table = $wpdb->prefix."esp_checkin";
39
+		parent::__construct();
40
+	}
41
+	protected function _migrate_old_row($old_row)
42
+	{
43
+		global $wpdb;
44
+		$new_reg_table = $wpdb->prefix."esp_registration";
45 45
 
46
-        $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ;
46
+		$num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ;
47 47
 
48
-        $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table);
49
-        if (! $new_registrations_for_attendee) {
50
-            $new_registrations_for_attendee = array();
51
-        }
52
-        $new_datetime = $this->_try_to_find_datetime($old_row);
48
+		$new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table);
49
+		if (! $new_registrations_for_attendee) {
50
+			$new_registrations_for_attendee = array();
51
+		}
52
+		$new_datetime = $this->_try_to_find_datetime($old_row);
53 53
 
54
-        // make sure registrations array is numerically indexed starting at 0 (it probably already is)
55
-        $new_registrations_for_attendee = array_values($new_registrations_for_attendee);
56
-        $new_checkin_ids = array();
57
-        for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) {
58
-            $new_reg_id = $new_registrations_for_attendee[ $i ];
59
-            if (! $new_reg_id) {
60
-                $this->add_error(sprintf(
61
-                    __('It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', "event_espresso"),
62
-                    $this->_json_encode($old_row),
63
-                    abs($num_to_checkin_at_this_time),
64
-                    count($new_registrations_for_attendee),
65
-                    $this->_json_encode($new_registrations_for_attendee)
66
-                ));
67
-                break;
68
-            }
69
-            $new_last_checkin_record = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", $new_reg_id));
70
-            if (! $new_last_checkin_record) {
71
-                $is_checked_in = false;
72
-            } else {
73
-                $is_checked_in = intval($new_last_checkin_record['CHK_in']);
74
-            }
75
-            $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
76
-            if ($new_id) {
77
-                $new_checkin_ids[]= $new_id;
78
-            }
79
-        }
80
-        if ($new_checkin_ids) {
81
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_table, $new_checkin_ids);
82
-        }
83
-    }
54
+		// make sure registrations array is numerically indexed starting at 0 (it probably already is)
55
+		$new_registrations_for_attendee = array_values($new_registrations_for_attendee);
56
+		$new_checkin_ids = array();
57
+		for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) {
58
+			$new_reg_id = $new_registrations_for_attendee[ $i ];
59
+			if (! $new_reg_id) {
60
+				$this->add_error(sprintf(
61
+					__('It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', "event_espresso"),
62
+					$this->_json_encode($old_row),
63
+					abs($num_to_checkin_at_this_time),
64
+					count($new_registrations_for_attendee),
65
+					$this->_json_encode($new_registrations_for_attendee)
66
+				));
67
+				break;
68
+			}
69
+			$new_last_checkin_record = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", $new_reg_id));
70
+			if (! $new_last_checkin_record) {
71
+				$is_checked_in = false;
72
+			} else {
73
+				$is_checked_in = intval($new_last_checkin_record['CHK_in']);
74
+			}
75
+			$new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
76
+			if ($new_id) {
77
+				$new_checkin_ids[]= $new_id;
78
+			}
79
+		}
80
+		if ($new_checkin_ids) {
81
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_table, $new_checkin_ids);
82
+		}
83
+	}
84 84
 
85 85
 
86
-    /**
87
-     * Tries to find the new datetime the Check-in was for, based on the attendee row
88
-     * (because we know the attendee was for an event as a specific time, and we know
89
-     * the event's OLD ID...)
90
-     * @global type $wpdb
91
-     * @param array $old_attendee_row
92
-     * @return array row of datetime from DB
93
-     */
94
-    private function _try_to_find_datetime($old_attendee)
95
-    {
96
-        global $wpdb;
86
+	/**
87
+	 * Tries to find the new datetime the Check-in was for, based on the attendee row
88
+	 * (because we know the attendee was for an event as a specific time, and we know
89
+	 * the event's OLD ID...)
90
+	 * @global type $wpdb
91
+	 * @param array $old_attendee_row
92
+	 * @return array row of datetime from DB
93
+	 */
94
+	private function _try_to_find_datetime($old_attendee)
95
+	{
96
+		global $wpdb;
97 97
 
98
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
99
-        if (! $new_event_id) {
100
-            $this->add_error(sprintf(__("Could nto find new event ID with old event id '%d', on attendee row %s; and because of that couldnt find the correct datetime for Check-in", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
101
-            return 0;
102
-        }
103
-        $old_att_start_date = $old_attendee['start_date'];
104
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
105
-        $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
98
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
99
+		if (! $new_event_id) {
100
+			$this->add_error(sprintf(__("Could nto find new event ID with old event id '%d', on attendee row %s; and because of that couldnt find the correct datetime for Check-in", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
101
+			return 0;
102
+		}
103
+		$old_att_start_date = $old_attendee['start_date'];
104
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
105
+		$old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
106 106
 
107
-        $datetime_table = $wpdb->prefix."esp_datetime";
108
-        // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
109
-        // the most important condition should be last, as it will be array_shift'ed off last
110
-        $conditions = array(
111
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
112
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
113
-        );
114
-        // start running queries, widening search each time by removing a condition
115
-        $datetime_found = null;
116
-        do {
117
-            $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
118
-            $datetime_found = $wpdb->get_row($full_query, ARRAY_A);
119
-            array_shift($conditions);
120
-        } while (! $datetime_found && $conditions);
121
-        return $datetime_found;
122
-    }
107
+		$datetime_table = $wpdb->prefix."esp_datetime";
108
+		// add all conditions to an array from which we can SHIFT conditions off in order to widen our search
109
+		// the most important condition should be last, as it will be array_shift'ed off last
110
+		$conditions = array(
111
+			$wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
112
+			$wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
113
+		);
114
+		// start running queries, widening search each time by removing a condition
115
+		$datetime_found = null;
116
+		do {
117
+			$full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
118
+			$datetime_found = $wpdb->get_row($full_query, ARRAY_A);
119
+			array_shift($conditions);
120
+		} while (! $datetime_found && $conditions);
121
+		return $datetime_found;
122
+	}
123 123
 
124
-    /**
125
-     * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
126
-     * @param int $new_reg_id
127
-     * @param int $new_datetime_id
128
-     * @param string $timestamp mysql datetime
129
-     * @return int new Check-in id
130
-     */
131
-    private function _insert_checkin_record($new_reg_id, $new_datetime)
132
-    {
133
-        global $wpdb;
124
+	/**
125
+	 * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
126
+	 * @param int $new_reg_id
127
+	 * @param int $new_datetime_id
128
+	 * @param string $timestamp mysql datetime
129
+	 * @return int new Check-in id
130
+	 */
131
+	private function _insert_checkin_record($new_reg_id, $new_datetime)
132
+	{
133
+		global $wpdb;
134 134
 
135 135
 
136
-        // ok we can actually do what we set out to do: add a checkin/checkout record
137
-        $cols_n_values = array(
138
-            'REG_ID'=>$new_reg_id,
139
-            'DTT_ID'=>$new_datetime['DTT_ID'],
140
-            'CHK_in'=>true,
141
-            'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
142
-        );
143
-        $datatypes = array(
144
-            '%d',// REG_ID
145
-            '%d',// DTT_ID
146
-            '%d',// CHK_in
147
-            '%s',// CHK_timestamp
148
-        );
149
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
150
-        if (! $success) {
151
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
152
-            return 0;
153
-        }
154
-        $new_id = $wpdb->insert_id;
155
-        return $new_id;
156
-    }
136
+		// ok we can actually do what we set out to do: add a checkin/checkout record
137
+		$cols_n_values = array(
138
+			'REG_ID'=>$new_reg_id,
139
+			'DTT_ID'=>$new_datetime['DTT_ID'],
140
+			'CHK_in'=>true,
141
+			'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
142
+		);
143
+		$datatypes = array(
144
+			'%d',// REG_ID
145
+			'%d',// DTT_ID
146
+			'%d',// CHK_in
147
+			'%s',// CHK_timestamp
148
+		);
149
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
150
+		if (! $success) {
151
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
152
+			return 0;
153
+		}
154
+		$new_id = $wpdb->insert_id;
155
+		return $new_id;
156
+	}
157 157
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         $this->_pretty_name = __("Checkins", "event_espresso");
34 34
         $this->_old_table = $wpdb->prefix."events_attendee";
35 35
         $this->_extra_where_sql = 'AS att
36
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
36
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id
37 37
             WHERE e.event_status!="D"';
38 38
         $this->_new_table = $wpdb->prefix."esp_checkin";
39 39
         parent::__construct();
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
         global $wpdb;
44 44
         $new_reg_table = $wpdb->prefix."esp_registration";
45 45
 
46
-        $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ;
46
+        $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']), intval($old_row['checked_in'])));
47 47
 
48 48
         $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table);
49
-        if (! $new_registrations_for_attendee) {
49
+        if ( ! $new_registrations_for_attendee) {
50 50
             $new_registrations_for_attendee = array();
51 51
         }
52 52
         $new_datetime = $this->_try_to_find_datetime($old_row);
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
         // make sure registrations array is numerically indexed starting at 0 (it probably already is)
55 55
         $new_registrations_for_attendee = array_values($new_registrations_for_attendee);
56 56
         $new_checkin_ids = array();
57
-        for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) {
58
-            $new_reg_id = $new_registrations_for_attendee[ $i ];
59
-            if (! $new_reg_id) {
57
+        for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) {
58
+            $new_reg_id = $new_registrations_for_attendee[$i];
59
+            if ( ! $new_reg_id) {
60 60
                 $this->add_error(sprintf(
61 61
                     __('It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', "event_espresso"),
62 62
                     $this->_json_encode($old_row),
@@ -67,14 +67,14 @@  discard block
 block discarded – undo
67 67
                 break;
68 68
             }
69 69
             $new_last_checkin_record = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", $new_reg_id));
70
-            if (! $new_last_checkin_record) {
70
+            if ( ! $new_last_checkin_record) {
71 71
                 $is_checked_in = false;
72 72
             } else {
73 73
                 $is_checked_in = intval($new_last_checkin_record['CHK_in']);
74 74
             }
75 75
             $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
76 76
             if ($new_id) {
77
-                $new_checkin_ids[]= $new_id;
77
+                $new_checkin_ids[] = $new_id;
78 78
             }
79 79
         }
80 80
         if ($new_checkin_ids) {
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         global $wpdb;
97 97
 
98 98
         $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
99
-        if (! $new_event_id) {
99
+        if ( ! $new_event_id) {
100 100
             $this->add_error(sprintf(__("Could nto find new event ID with old event id '%d', on attendee row %s; and because of that couldnt find the correct datetime for Check-in", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
101 101
             return 0;
102 102
         }
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
         // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
109 109
         // the most important condition should be last, as it will be array_shift'ed off last
110 110
         $conditions = array(
111
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
112
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
111
+            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match?
112
+            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match?
113 113
         );
114 114
         // start running queries, widening search each time by removing a condition
115 115
         $datetime_found = null;
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
             $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
118 118
             $datetime_found = $wpdb->get_row($full_query, ARRAY_A);
119 119
             array_shift($conditions);
120
-        } while (! $datetime_found && $conditions);
120
+        }while ( ! $datetime_found && $conditions);
121 121
         return $datetime_found;
122 122
     }
123 123
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
             'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
142 142
         );
143 143
         $datatypes = array(
144
-            '%d',// REG_ID
145
-            '%d',// DTT_ID
146
-            '%d',// CHK_in
147
-            '%s',// CHK_timestamp
144
+            '%d', // REG_ID
145
+            '%d', // DTT_ID
146
+            '%d', // CHK_in
147
+            '%s', // CHK_timestamp
148 148
         );
149 149
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
150
-        if (! $success) {
150
+        if ( ! $success) {
151 151
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
152 152
             return 0;
153 153
         }
Please login to merge, or discard this patch.