Completed
Branch FET/event-question-group-refac... (19fbf8)
by
unknown
09:05 queued 20s
created
admin/extend/registration_form/Extend_Registration_Form_Admin_Page.core.php 1 patch
Indentation   +1319 added lines, -1319 removed lines patch added patch discarded remove patch
@@ -14,1323 +14,1323 @@
 block discarded – undo
14 14
 class Extend_Registration_Form_Admin_Page extends Registration_Form_Admin_Page
15 15
 {
16 16
 
17
-    /**
18
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
19
-     */
20
-    public function __construct($routing = true)
21
-    {
22
-        define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS);
23
-        define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS);
24
-        define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/');
25
-        define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS);
26
-        define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/');
27
-        parent::__construct($routing);
28
-    }
29
-
30
-
31
-    /**
32
-     * @return void
33
-     */
34
-    protected function _extend_page_config()
35
-    {
36
-        $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN;
37
-        $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID'])
38
-            ? $this->_req_data['QST_ID'] : 0;
39
-        $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID'])
40
-            ? $this->_req_data['QSG_ID'] : 0;
41
-
42
-        $new_page_routes = array(
43
-            'question_groups'    => array(
44
-                'func'       => '_question_groups_overview_list_table',
45
-                'capability' => 'ee_read_question_groups',
46
-            ),
47
-            'add_question'       => array(
48
-                'func'       => '_edit_question',
49
-                'capability' => 'ee_edit_questions',
50
-            ),
51
-            'insert_question'    => array(
52
-                'func'       => '_insert_or_update_question',
53
-                'args'       => array('new_question' => true),
54
-                'capability' => 'ee_edit_questions',
55
-                'noheader'   => true,
56
-            ),
57
-            'duplicate_question' => array(
58
-                'func'       => '_duplicate_question',
59
-                'capability' => 'ee_edit_questions',
60
-                'noheader'   => true,
61
-            ),
62
-            'trash_question'     => array(
63
-                'func'       => '_trash_question',
64
-                'capability' => 'ee_delete_question',
65
-                'obj_id'     => $qst_id,
66
-                'noheader'   => true,
67
-            ),
68
-
69
-            'restore_question' => array(
70
-                'func'       => '_trash_or_restore_questions',
71
-                'capability' => 'ee_delete_question',
72
-                'obj_id'     => $qst_id,
73
-                'args'       => array('trash' => false),
74
-                'noheader'   => true,
75
-            ),
76
-
77
-            'delete_question' => array(
78
-                'func'       => '_delete_question',
79
-                'capability' => 'ee_delete_question',
80
-                'obj_id'     => $qst_id,
81
-                'noheader'   => true,
82
-            ),
83
-
84
-            'trash_questions' => array(
85
-                'func'       => '_trash_or_restore_questions',
86
-                'capability' => 'ee_delete_questions',
87
-                'args'       => array('trash' => true),
88
-                'noheader'   => true,
89
-            ),
90
-
91
-            'restore_questions' => array(
92
-                'func'       => '_trash_or_restore_questions',
93
-                'capability' => 'ee_delete_questions',
94
-                'args'       => array('trash' => false),
95
-                'noheader'   => true,
96
-            ),
97
-
98
-            'delete_questions' => array(
99
-                'func'       => '_delete_questions',
100
-                'args'       => array(),
101
-                'capability' => 'ee_delete_questions',
102
-                'noheader'   => true,
103
-            ),
104
-
105
-            'add_question_group' => array(
106
-                'func'       => '_edit_question_group',
107
-                'capability' => 'ee_edit_question_groups',
108
-            ),
109
-
110
-            'edit_question_group' => array(
111
-                'func'       => '_edit_question_group',
112
-                'capability' => 'ee_edit_question_group',
113
-                'obj_id'     => $qsg_id,
114
-                'args'       => array('edit'),
115
-            ),
116
-
117
-            'delete_question_groups' => array(
118
-                'func'       => '_delete_question_groups',
119
-                'capability' => 'ee_delete_question_groups',
120
-                'noheader'   => true,
121
-            ),
122
-
123
-            'delete_question_group' => array(
124
-                'func'       => '_delete_question_groups',
125
-                'capability' => 'ee_delete_question_group',
126
-                'obj_id'     => $qsg_id,
127
-                'noheader'   => true,
128
-            ),
129
-
130
-            'trash_question_group' => array(
131
-                'func'       => '_trash_or_restore_question_groups',
132
-                'args'       => array('trash' => true),
133
-                'capability' => 'ee_delete_question_group',
134
-                'obj_id'     => $qsg_id,
135
-                'noheader'   => true,
136
-            ),
137
-
138
-            'restore_question_group' => array(
139
-                'func'       => '_trash_or_restore_question_groups',
140
-                'args'       => array('trash' => false),
141
-                'capability' => 'ee_delete_question_group',
142
-                'obj_id'     => $qsg_id,
143
-                'noheader'   => true,
144
-            ),
145
-
146
-            'insert_question_group' => array(
147
-                'func'       => '_insert_or_update_question_group',
148
-                'args'       => array('new_question_group' => true),
149
-                'capability' => 'ee_edit_question_groups',
150
-                'noheader'   => true,
151
-            ),
152
-
153
-            'update_question_group' => array(
154
-                'func'       => '_insert_or_update_question_group',
155
-                'args'       => array('new_question_group' => false),
156
-                'capability' => 'ee_edit_question_group',
157
-                'obj_id'     => $qsg_id,
158
-                'noheader'   => true,
159
-            ),
160
-
161
-            'trash_question_groups' => array(
162
-                'func'       => '_trash_or_restore_question_groups',
163
-                'args'       => array('trash' => true),
164
-                'capability' => 'ee_delete_question_groups',
165
-                'noheader'   => array('trash' => false),
166
-            ),
167
-
168
-            'restore_question_groups' => array(
169
-                'func'       => '_trash_or_restore_question_groups',
170
-                'args'       => array('trash' => false),
171
-                'capability' => 'ee_delete_question_groups',
172
-                'noheader'   => true,
173
-            ),
174
-
175
-
176
-            'espresso_update_question_group_order' => array(
177
-                'func'       => 'update_question_group_order',
178
-                'capability' => 'ee_edit_question_groups',
179
-                'noheader'   => true,
180
-            ),
181
-
182
-            'view_reg_form_settings' => array(
183
-                'func'       => '_reg_form_settings',
184
-                'capability' => 'manage_options',
185
-            ),
186
-
187
-            'update_reg_form_settings' => array(
188
-                'func'       => '_update_reg_form_settings',
189
-                'capability' => 'manage_options',
190
-                'noheader'   => true,
191
-            ),
192
-        );
193
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
194
-
195
-        $new_page_config = array(
196
-
197
-            'question_groups' => array(
198
-                'nav'           => array(
199
-                    'label' => esc_html__('Question Groups', 'event_espresso'),
200
-                    'order' => 20,
201
-                ),
202
-                'list_table'    => 'Registration_Form_Question_Groups_Admin_List_Table',
203
-                'help_tabs'     => array(
204
-                    'registration_form_question_groups_help_tab'                           => array(
205
-                        'title'    => esc_html__('Question Groups', 'event_espresso'),
206
-                        'filename' => 'registration_form_question_groups',
207
-                    ),
208
-                    'registration_form_question_groups_table_column_headings_help_tab'     => array(
209
-                        'title'    => esc_html__('Question Groups Table Column Headings', 'event_espresso'),
210
-                        'filename' => 'registration_form_question_groups_table_column_headings',
211
-                    ),
212
-                    'registration_form_question_groups_views_bulk_actions_search_help_tab' => array(
213
-                        'title'    => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'),
214
-                        'filename' => 'registration_form_question_groups_views_bulk_actions_search',
215
-                    ),
216
-                ),
217
-                'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'),
218
-                'metaboxes'     => $this->_default_espresso_metaboxes,
219
-                'require_nonce' => false,
220
-                'qtips'         => array(
221
-                    'EE_Registration_Form_Tips',
222
-                ),
223
-            ),
224
-
225
-            'add_question' => array(
226
-                'nav'           => array(
227
-                    'label'      => esc_html__('Add Question', 'event_espresso'),
228
-                    'order'      => 5,
229
-                    'persistent' => false,
230
-                ),
231
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
232
-                'help_tabs'     => array(
233
-                    'registration_form_add_question_help_tab' => array(
234
-                        'title'    => esc_html__('Add Question', 'event_espresso'),
235
-                        'filename' => 'registration_form_add_question',
236
-                    ),
237
-                ),
238
-                'help_tour'     => array('Registration_Form_Add_Question_Help_Tour'),
239
-                'require_nonce' => false,
240
-            ),
241
-
242
-            'add_question_group' => array(
243
-                'nav'           => array(
244
-                    'label'      => esc_html__('Add Question Group', 'event_espresso'),
245
-                    'order'      => 5,
246
-                    'persistent' => false,
247
-                ),
248
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
249
-                'help_tabs'     => array(
250
-                    'registration_form_add_question_group_help_tab' => array(
251
-                        'title'    => esc_html__('Add Question Group', 'event_espresso'),
252
-                        'filename' => 'registration_form_add_question_group',
253
-                    ),
254
-                ),
255
-                'help_tour'     => array('Registration_Form_Add_Question_Group_Help_Tour'),
256
-                'require_nonce' => false,
257
-            ),
258
-
259
-            'edit_question_group' => array(
260
-                'nav'           => array(
261
-                    'label'      => esc_html__('Edit Question Group', 'event_espresso'),
262
-                    'order'      => 5,
263
-                    'persistent' => false,
264
-                    'url'        => isset($this->_req_data['question_group_id']) ? add_query_arg(
265
-                        array('question_group_id' => $this->_req_data['question_group_id']),
266
-                        $this->_current_page_view_url
267
-                    ) : $this->_admin_base_url,
268
-                ),
269
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
270
-                'help_tabs'     => array(
271
-                    'registration_form_edit_question_group_help_tab' => array(
272
-                        'title'    => esc_html__('Edit Question Group', 'event_espresso'),
273
-                        'filename' => 'registration_form_edit_question_group',
274
-                    ),
275
-                ),
276
-                'help_tour'     => array('Registration_Form_Edit_Question_Group_Help_Tour'),
277
-                'require_nonce' => false,
278
-            ),
279
-
280
-            'view_reg_form_settings' => array(
281
-                'nav'           => array(
282
-                    'label' => esc_html__('Reg Form Settings', 'event_espresso'),
283
-                    'order' => 40,
284
-                ),
285
-                'labels'        => array(
286
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
287
-                ),
288
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
289
-                'help_tabs'     => array(
290
-                    'registration_form_reg_form_settings_help_tab' => array(
291
-                        'title'    => esc_html__('Registration Form Settings', 'event_espresso'),
292
-                        'filename' => 'registration_form_reg_form_settings',
293
-                    ),
294
-                ),
295
-                'help_tour'     => array('Registration_Form_Settings_Help_Tour'),
296
-                'require_nonce' => false,
297
-            ),
298
-
299
-        );
300
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
301
-
302
-        // change the list table we're going to use so it's the NEW list table!
303
-        $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table';
304
-
305
-
306
-        // additional labels
307
-        $new_labels = array(
308
-            'add_question'          => esc_html__('Add New Question', 'event_espresso'),
309
-            'delete_question'       => esc_html__('Delete Question', 'event_espresso'),
310
-            'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'),
311
-            'edit_question_group'   => esc_html__('Edit Question Group', 'event_espresso'),
312
-            'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'),
313
-        );
314
-        $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels);
315
-    }
316
-
317
-
318
-    /**
319
-     * @return void
320
-     */
321
-    protected function _ajax_hooks()
322
-    {
323
-        add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order'));
324
-    }
325
-
326
-
327
-    /**
328
-     * @return void
329
-     */
330
-    public function load_scripts_styles_question_groups()
331
-    {
332
-        wp_enqueue_script('espresso_ajax_table_sorting');
333
-    }
334
-
335
-
336
-    /**
337
-     * @return void
338
-     */
339
-    public function load_scripts_styles_add_question_group()
340
-    {
341
-        $this->load_scripts_styles_forms();
342
-        $this->load_sortable_question_script();
343
-    }
344
-
345
-
346
-    /**
347
-     * @return void
348
-     */
349
-    public function load_scripts_styles_edit_question_group()
350
-    {
351
-        $this->load_scripts_styles_forms();
352
-        $this->load_sortable_question_script();
353
-    }
354
-
355
-
356
-    /**
357
-     * registers and enqueues script for questions
358
-     *
359
-     * @return void
360
-     */
361
-    public function load_sortable_question_script()
362
-    {
363
-        wp_register_script(
364
-            'ee-question-sortable',
365
-            REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',
366
-            array('jquery-ui-sortable'),
367
-            EVENT_ESPRESSO_VERSION,
368
-            true
369
-        );
370
-        wp_enqueue_script('ee-question-sortable');
371
-    }
372
-
373
-
374
-    /**
375
-     * @return void
376
-     */
377
-    protected function _set_list_table_views_default()
378
-    {
379
-        $this->_views = array(
380
-            'all' => array(
381
-                'slug'        => 'all',
382
-                'label'       => esc_html__('View All Questions', 'event_espresso'),
383
-                'count'       => 0,
384
-                'bulk_action' => array(
385
-                    'trash_questions' => esc_html__('Trash', 'event_espresso'),
386
-                ),
387
-            ),
388
-        );
389
-
390
-        if (EE_Registry::instance()->CAP->current_user_can(
391
-            'ee_delete_questions',
392
-            'espresso_registration_form_trash_questions'
393
-        )
394
-        ) {
395
-            $this->_views['trash'] = array(
396
-                'slug'        => 'trash',
397
-                'label'       => esc_html__('Trash', 'event_espresso'),
398
-                'count'       => 0,
399
-                'bulk_action' => array(
400
-                    'delete_questions'  => esc_html__('Delete Permanently', 'event_espresso'),
401
-                    'restore_questions' => esc_html__('Restore', 'event_espresso'),
402
-                ),
403
-            );
404
-        }
405
-    }
406
-
407
-
408
-    /**
409
-     * @return void
410
-     */
411
-    protected function _set_list_table_views_question_groups()
412
-    {
413
-        $this->_views = array(
414
-            'all' => array(
415
-                'slug'        => 'all',
416
-                'label'       => esc_html__('All', 'event_espresso'),
417
-                'count'       => 0,
418
-                'bulk_action' => array(
419
-                    'trash_question_groups' => esc_html__('Trash', 'event_espresso'),
420
-                ),
421
-            ),
422
-        );
423
-
424
-        if (EE_Registry::instance()->CAP->current_user_can(
425
-            'ee_delete_question_groups',
426
-            'espresso_registration_form_trash_question_groups'
427
-        )
428
-        ) {
429
-            $this->_views['trash'] = array(
430
-                'slug'        => 'trash',
431
-                'label'       => esc_html__('Trash', 'event_espresso'),
432
-                'count'       => 0,
433
-                'bulk_action' => array(
434
-                    'delete_question_groups'  => esc_html__('Delete Permanently', 'event_espresso'),
435
-                    'restore_question_groups' => esc_html__('Restore', 'event_espresso'),
436
-                ),
437
-            );
438
-        }
439
-    }
440
-
441
-
442
-    /**
443
-     * @return void
444
-     * @throws EE_Error
445
-     * @throws InvalidArgumentException
446
-     * @throws InvalidDataTypeException
447
-     * @throws InvalidInterfaceException
448
-     */
449
-    protected function _questions_overview_list_table()
450
-    {
451
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
452
-            'add_question',
453
-            'add_question',
454
-            array(),
455
-            'add-new-h2'
456
-        );
457
-        parent::_questions_overview_list_table();
458
-    }
459
-
460
-
461
-    /**
462
-     * @return void
463
-     * @throws DomainException
464
-     * @throws EE_Error
465
-     * @throws InvalidArgumentException
466
-     * @throws InvalidDataTypeException
467
-     * @throws InvalidInterfaceException
468
-     */
469
-    protected function _question_groups_overview_list_table()
470
-    {
471
-        $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso');
472
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
473
-            'add_question_group',
474
-            'add_question_group',
475
-            array(),
476
-            'add-new-h2'
477
-        );
478
-        $this->display_admin_list_table_page_with_sidebar();
479
-    }
480
-
481
-
482
-    /**
483
-     * @return void
484
-     * @throws EE_Error
485
-     * @throws InvalidArgumentException
486
-     * @throws InvalidDataTypeException
487
-     * @throws InvalidInterfaceException
488
-     */
489
-    protected function _delete_question()
490
-    {
491
-        $success = $this->_delete_items($this->_question_model);
492
-        $this->_redirect_after_action(
493
-            $success,
494
-            $this->_question_model->item_name($success),
495
-            'deleted',
496
-            array('action' => 'default', 'status' => 'all')
497
-        );
498
-    }
499
-
500
-
501
-    /**
502
-     * @return void
503
-     * @throws EE_Error
504
-     * @throws InvalidArgumentException
505
-     * @throws InvalidDataTypeException
506
-     * @throws InvalidInterfaceException
507
-     */
508
-    protected function _delete_questions()
509
-    {
510
-        $success = $this->_delete_items($this->_question_model);
511
-        $this->_redirect_after_action(
512
-            $success,
513
-            $this->_question_model->item_name($success),
514
-            'deleted permanently',
515
-            array('action' => 'default', 'status' => 'trash')
516
-        );
517
-    }
518
-
519
-
520
-    /**
521
-     * Performs the deletion of a single or multiple questions or question groups.
522
-     *
523
-     * @param EEM_Soft_Delete_Base $model
524
-     * @return int number of items deleted permanently
525
-     * @throws EE_Error
526
-     * @throws InvalidArgumentException
527
-     * @throws InvalidDataTypeException
528
-     * @throws InvalidInterfaceException
529
-     */
530
-    private function _delete_items(EEM_Soft_Delete_Base $model)
531
-    {
532
-        $success = 0;
533
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
534
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
535
-            // if array has more than one element than success message should be plural
536
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
537
-            // cycle thru bulk action checkboxes
538
-            while (list($ID, $value) = each($this->_req_data['checkbox'])) {
539
-                if (! $this->_delete_item($ID, $model)) {
540
-                    $success = 0;
541
-                }
542
-            }
543
-        } elseif (! empty($this->_req_data['QSG_ID'])) {
544
-            $success = $this->_delete_item($this->_req_data['QSG_ID'], $model);
545
-        } elseif (! empty($this->_req_data['QST_ID'])) {
546
-            $success = $this->_delete_item($this->_req_data['QST_ID'], $model);
547
-        } else {
548
-            EE_Error::add_error(
549
-                sprintf(
550
-                    esc_html__(
551
-                        "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.",
552
-                        "event_espresso"
553
-                    )
554
-                ),
555
-                __FILE__,
556
-                __FUNCTION__,
557
-                __LINE__
558
-            );
559
-        }
560
-        return $success;
561
-    }
562
-
563
-
564
-    /**
565
-     * Deletes the specified question (and its associated question options) or question group
566
-     *
567
-     * @param int                  $id
568
-     * @param EEM_Soft_Delete_Base $model
569
-     * @return boolean
570
-     * @throws EE_Error
571
-     * @throws InvalidArgumentException
572
-     * @throws InvalidDataTypeException
573
-     * @throws InvalidInterfaceException
574
-     */
575
-    protected function _delete_item($id, $model)
576
-    {
577
-        if ($model instanceof EEM_Question) {
578
-            EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id))));
579
-        }
580
-        return $model->delete_permanently_by_ID(absint($id));
581
-    }
582
-
583
-
584
-    /******************************    QUESTION GROUPS    ******************************/
585
-
586
-
587
-    /**
588
-     * @param string $type
589
-     * @return void
590
-     * @throws DomainException
591
-     * @throws EE_Error
592
-     * @throws InvalidArgumentException
593
-     * @throws InvalidDataTypeException
594
-     * @throws InvalidInterfaceException
595
-     */
596
-    protected function _edit_question_group($type = 'add')
597
-    {
598
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
599
-        $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID'])
600
-            ? absint($this->_req_data['QSG_ID'])
601
-            : false;
602
-
603
-        switch ($this->_req_action) {
604
-            case 'add_question_group':
605
-                $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso');
606
-                break;
607
-            case 'edit_question_group':
608
-                $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso');
609
-                break;
610
-            default:
611
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
612
-        }
613
-        // add ID to title if editing
614
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
615
-        if ($ID) {
616
-            /** @var EE_Question_Group $questionGroup */
617
-            $questionGroup = $this->_question_group_model->get_one_by_ID($ID);
618
-            $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID));
619
-            $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields);
620
-        } else {
621
-            /** @var EE_Question_Group $questionGroup */
622
-            $questionGroup = EEM_Question_Group::instance()->create_default_object();
623
-            $questionGroup->set_order_to_latest();
624
-            $this->_set_add_edit_form_tags('insert_question_group');
625
-        }
626
-        $this->_template_args['values'] = $this->_yes_no_values;
627
-        $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group();
628
-        $this->_template_args['QSG_ID'] = $ID ? $ID : true;
629
-        $this->_template_args['question_group'] = $questionGroup;
630
-
631
-        $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url);
632
-        $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL);
633
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
634
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',
635
-            $this->_template_args,
636
-            true
637
-        );
638
-
639
-        // the details template wrapper
640
-        $this->display_admin_page_with_sidebar();
641
-    }
642
-
643
-
644
-    /**
645
-     * @return void
646
-     * @throws EE_Error
647
-     * @throws InvalidArgumentException
648
-     * @throws InvalidDataTypeException
649
-     * @throws InvalidInterfaceException
650
-     */
651
-    protected function _delete_question_groups()
652
-    {
653
-        $success = $this->_delete_items($this->_question_group_model);
654
-        $this->_redirect_after_action(
655
-            $success,
656
-            $this->_question_group_model->item_name($success),
657
-            'deleted permanently',
658
-            array('action' => 'question_groups', 'status' => 'trash')
659
-        );
660
-    }
661
-
662
-
663
-    /**
664
-     * @param bool $new_question_group
665
-     * @throws EE_Error
666
-     * @throws InvalidArgumentException
667
-     * @throws InvalidDataTypeException
668
-     * @throws InvalidInterfaceException
669
-     */
670
-    protected function _insert_or_update_question_group($new_question_group = true)
671
-    {
672
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
673
-        $set_column_values = $this->_set_column_values_for($this->_question_group_model);
674
-        if ($new_question_group) {
675
-            // make sure identifier is unique
676
-            $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : '';
677
-            $identifier_exists = ! empty($identifier_value)
678
-                ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0
679
-                : false;
680
-            if ($identifier_exists) {
681
-                $set_column_values['QSG_identifier'] .= uniqid('id', true);
682
-            }
683
-            $QSG_ID = $this->_question_group_model->insert($set_column_values);
684
-            $success = $QSG_ID ? 1 : 0;
685
-            if ($success === 0) {
686
-                EE_Error::add_error(
687
-                    esc_html__('Something went wrong saving the question group.', 'event_espresso'),
688
-                    __FILE__,
689
-                    __FUNCTION__,
690
-                    __LINE__
691
-                );
692
-                $this->_redirect_after_action(
693
-                    false,
694
-                    '',
695
-                    '',
696
-                    array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID),
697
-                    true
698
-                );
699
-            }
700
-        } else {
701
-            $QSG_ID = absint($this->_req_data['QSG_ID']);
702
-            unset($set_column_values['QSG_ID']);
703
-            $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID)));
704
-        }
705
-
706
-        $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
707
-            EEM_Attendee::system_question_phone
708
-        );
709
-        // update the existing related questions
710
-        // BUT FIRST...  delete the phone question from the Question_Group_Question
711
-        // if it is being added to this question group (therefore removed from the existing group)
712
-        if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) {
713
-            // delete where QST ID = system phone question ID and Question Group ID is NOT this group
714
-            EEM_Question_Group_Question::instance()->delete(
715
-                array(
716
-                    array(
717
-                        'QST_ID' => $phone_question_id,
718
-                        'QSG_ID' => array('!=', $QSG_ID),
719
-                    ),
720
-                )
721
-            );
722
-        }
723
-        /** @type EE_Question_Group $question_group */
724
-        $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);
725
-        $questions = $question_group->questions();
726
-        // make sure system phone question is added to list of questions for this group
727
-        if (! isset($questions[ $phone_question_id ])) {
728
-            $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
729
-        }
730
-
731
-        foreach ($questions as $question_ID => $question) {
732
-            // first we always check for order.
733
-            if (! empty($this->_req_data['question_orders'][ $question_ID ])) {
734
-                // update question order
735
-                $question_group->update_question_order(
736
-                    $question_ID,
737
-                    $this->_req_data['question_orders'][ $question_ID ]
738
-                );
739
-            }
740
-
741
-            // then we always check if adding or removing.
742
-            if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) {
743
-                $question_group->add_question($question_ID);
744
-            } else {
745
-                // not found, remove it (but only if not a system question for the personal group
746
-                // with the exception of lname system question - we allow removal of it)
747
-                if (in_array(
748
-                    $question->system_ID(),
749
-                    EEM_Question::instance()->required_system_questions_in_system_question_group(
750
-                        $question_group->system_group()
751
-                    )
752
-                )) {
753
-                    continue;
754
-                } else {
755
-                    $question_group->remove_question($question_ID);
756
-                }
757
-            }
758
-        }
759
-        // save new related questions
760
-        if (isset($this->_req_data['questions'])) {
761
-            foreach ($this->_req_data['questions'] as $QST_ID) {
762
-                $question_group->add_question($QST_ID);
763
-                if (isset($this->_req_data['question_orders'][ $QST_ID ])) {
764
-                    $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]);
765
-                }
766
-            }
767
-        }
768
-
769
-        if ($success !== false) {
770
-            $msg = $new_question_group
771
-                ? sprintf(
772
-                    esc_html__('The %s has been created', 'event_espresso'),
773
-                    $this->_question_group_model->item_name()
774
-                )
775
-                : sprintf(
776
-                    esc_html__(
777
-                        'The %s has been updated',
778
-                        'event_espresso'
779
-                    ),
780
-                    $this->_question_group_model->item_name()
781
-                );
782
-            EE_Error::add_success($msg);
783
-        }
784
-        $this->_redirect_after_action(
785
-            false,
786
-            '',
787
-            '',
788
-            array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID),
789
-            true
790
-        );
791
-    }
792
-
793
-
794
-    /**
795
-     * duplicates a question and all its question options and redirects to the new question.
796
-     *
797
-     * @return void
798
-     * @throws EE_Error
799
-     * @throws InvalidArgumentException
800
-     * @throws ReflectionException
801
-     * @throws InvalidDataTypeException
802
-     * @throws InvalidInterfaceException
803
-     */
804
-    public function _duplicate_question()
805
-    {
806
-        $question_ID = (int) $this->_req_data['QST_ID'];
807
-        $question = EEM_Question::instance()->get_one_by_ID($question_ID);
808
-        if ($question instanceof EE_Question) {
809
-            $new_question = $question->duplicate();
810
-            if ($new_question instanceof EE_Question) {
811
-                $this->_redirect_after_action(
812
-                    true,
813
-                    esc_html__('Question', 'event_espresso'),
814
-                    esc_html__('Duplicated', 'event_espresso'),
815
-                    array('action' => 'edit_question', 'QST_ID' => $new_question->ID()),
816
-                    true
817
-                );
818
-            } else {
819
-                global $wpdb;
820
-                EE_Error::add_error(
821
-                    sprintf(
822
-                        esc_html__(
823
-                            'Could not duplicate question with ID %1$d because: %2$s',
824
-                            'event_espresso'
825
-                        ),
826
-                        $question_ID,
827
-                        $wpdb->last_error
828
-                    ),
829
-                    __FILE__,
830
-                    __FUNCTION__,
831
-                    __LINE__
832
-                );
833
-                $this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
834
-            }
835
-        } else {
836
-            EE_Error::add_error(
837
-                sprintf(
838
-                    esc_html__(
839
-                        'Could not duplicate question with ID %d because it didn\'t exist!',
840
-                        'event_espresso'
841
-                    ),
842
-                    $question_ID
843
-                ),
844
-                __FILE__,
845
-                __FUNCTION__,
846
-                __LINE__
847
-            );
848
-            $this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
849
-        }
850
-    }
851
-
852
-
853
-    /**
854
-     * @param bool $trash
855
-     * @throws EE_Error
856
-     */
857
-    protected function _trash_or_restore_question_groups($trash = true)
858
-    {
859
-        $this->_trash_or_restore_items($this->_question_group_model, $trash);
860
-    }
861
-
862
-
863
-    /**
864
-     *_trash_question
865
-     *
866
-     * @return void
867
-     * @throws EE_Error
868
-     */
869
-    protected function _trash_question()
870
-    {
871
-        $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']);
872
-        $query_args = array('action' => 'default', 'status' => 'all');
873
-        $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args);
874
-    }
875
-
876
-
877
-    /**
878
-     * @param bool $trash
879
-     * @throws EE_Error
880
-     */
881
-    protected function _trash_or_restore_questions($trash = true)
882
-    {
883
-        $this->_trash_or_restore_items($this->_question_model, $trash);
884
-    }
885
-
886
-
887
-    /**
888
-     * Internally used to delete or restore items, using the request data. Meant to be
889
-     * flexible between question or question groups
890
-     *
891
-     * @param EEM_Soft_Delete_Base $model
892
-     * @param boolean              $trash whether to trash or restore
893
-     * @throws EE_Error
894
-     */
895
-    private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true)
896
-    {
897
-
898
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
899
-
900
-        $success = 1;
901
-        // Checkboxes
902
-        // echo "trash $trash";
903
-        // var_dump($this->_req_data['checkbox']);die;
904
-        if (isset($this->_req_data['checkbox'])) {
905
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
906
-                // if array has more than one element than success message should be plural
907
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
908
-                // cycle thru bulk action checkboxes
909
-                while (list($ID, $value) = each($this->_req_data['checkbox'])) {
910
-                    if (! $model->delete_or_restore_by_ID($trash, absint($ID))) {
911
-                        $success = 0;
912
-                    }
913
-                }
914
-            } else {
915
-                // grab single id and delete
916
-                $ID = absint($this->_req_data['checkbox']);
917
-                if (! $model->delete_or_restore_by_ID($trash, $ID)) {
918
-                    $success = 0;
919
-                }
920
-            }
921
-        } else {
922
-            // delete via trash link
923
-            // grab single id and delete
924
-            $ID = absint($this->_req_data[ $model->primary_key_name() ]);
925
-            if (! $model->delete_or_restore_by_ID($trash, $ID)) {
926
-                $success = 0;
927
-            }
928
-        }
929
-
930
-
931
-        $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) );
932
-        // echo "action :$action";
933
-        // $action = 'questions' ? 'default' : $action;
934
-        if ($trash) {
935
-            $action_desc = 'trashed';
936
-            $status = 'trash';
937
-        } else {
938
-            $action_desc = 'restored';
939
-            $status = 'all';
940
-        }
941
-        $this->_redirect_after_action(
942
-            $success,
943
-            $model->item_name($success),
944
-            $action_desc,
945
-            array('action' => $action, 'status' => $status)
946
-        );
947
-    }
948
-
949
-
950
-    /**
951
-     * @param            $per_page
952
-     * @param int        $current_page
953
-     * @param bool|false $count
954
-     * @return EE_Soft_Delete_Base_Class[]|int
955
-     * @throws EE_Error
956
-     * @throws InvalidArgumentException
957
-     * @throws InvalidDataTypeException
958
-     * @throws InvalidInterfaceException
959
-     */
960
-    public function get_trashed_questions($per_page, $current_page = 1, $count = false)
961
-    {
962
-        $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
963
-
964
-        if ($count) {
965
-            // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
966
-            $where = isset($query_params[0]) ? array($query_params[0]) : array();
967
-            $results = $this->_question_model->count_deleted($where);
968
-        } else {
969
-            // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
970
-            $results = $this->_question_model->get_all_deleted($query_params);
971
-        }
972
-        return $results;
973
-    }
974
-
975
-
976
-    /**
977
-     * @param            $per_page
978
-     * @param int        $current_page
979
-     * @param bool|false $count
980
-     * @return EE_Soft_Delete_Base_Class[]|int
981
-     * @throws EE_Error
982
-     * @throws InvalidArgumentException
983
-     * @throws InvalidDataTypeException
984
-     * @throws InvalidInterfaceException
985
-     */
986
-    public function get_question_groups($per_page, $current_page = 1, $count = false)
987
-    {
988
-        $questionGroupModel = EEM_Question_Group::instance();
989
-        $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);
990
-        if ($count) {
991
-            $where = isset($query_params[0]) ? array($query_params[0]) : array();
992
-            $results = $questionGroupModel->count($where);
993
-        } else {
994
-            $results = $questionGroupModel->get_all($query_params);
995
-        }
996
-        return $results;
997
-    }
998
-
999
-
1000
-    /**
1001
-     * @param      $per_page
1002
-     * @param int  $current_page
1003
-     * @param bool $count
1004
-     * @return EE_Soft_Delete_Base_Class[]|int
1005
-     * @throws EE_Error
1006
-     * @throws InvalidArgumentException
1007
-     * @throws InvalidDataTypeException
1008
-     * @throws InvalidInterfaceException
1009
-     */
1010
-    public function get_trashed_question_groups($per_page, $current_page = 1, $count = false)
1011
-    {
1012
-        $questionGroupModel = EEM_Question_Group::instance();
1013
-        $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);
1014
-        if ($count) {
1015
-            $where = isset($query_params[0]) ? array($query_params[0]) : array();
1016
-            $query_params['limit'] = null;
1017
-            $results = $questionGroupModel->count_deleted($where);
1018
-        } else {
1019
-            $results = $questionGroupModel->get_all_deleted($query_params);
1020
-        }
1021
-        return $results;
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * method for performing updates to question order
1027
-     *
1028
-     * @return void results array
1029
-     * @throws EE_Error
1030
-     * @throws InvalidArgumentException
1031
-     * @throws InvalidDataTypeException
1032
-     * @throws InvalidInterfaceException
1033
-     */
1034
-    public function update_question_group_order()
1035
-    {
1036
-
1037
-        $success = esc_html__('Question group order was updated successfully.', 'event_espresso');
1038
-
1039
-        // grab our row IDs
1040
-        $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids'])
1041
-            ? explode(',', rtrim($this->_req_data['row_ids'], ','))
1042
-            : array();
1043
-
1044
-        $perpage = ! empty($this->_req_data['perpage'])
1045
-            ? (int) $this->_req_data['perpage']
1046
-            : null;
1047
-        $curpage = ! empty($this->_req_data['curpage'])
1048
-            ? (int) $this->_req_data['curpage']
1049
-            : null;
1050
-
1051
-        if (! empty($row_ids)) {
1052
-            // figure out where we start the row_id count at for the current page.
1053
-            $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;
1054
-
1055
-            $row_count = count($row_ids);
1056
-            for ($i = 0; $i < $row_count; $i++) {
1057
-                // Update the questions when re-ordering
1058
-                $updated = EEM_Question_Group::instance()->update(
1059
-                    array('QSG_order' => $qsgcount),
1060
-                    array(array('QSG_ID' => $row_ids[ $i ]))
1061
-                );
1062
-                if ($updated === false) {
1063
-                    $success = false;
1064
-                }
1065
-                $qsgcount++;
1066
-            }
1067
-        } else {
1068
-            $success = false;
1069
-        }
1070
-
1071
-        $errors = ! $success
1072
-            ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso')
1073
-            : false;
1074
-
1075
-        echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors));
1076
-        die();
1077
-    }
1078
-
1079
-
1080
-
1081
-    /***************************************       REGISTRATION SETTINGS       ***************************************/
1082
-
1083
-
1084
-    /**
1085
-     * @throws DomainException
1086
-     * @throws EE_Error
1087
-     * @throws InvalidArgumentException
1088
-     * @throws InvalidDataTypeException
1089
-     * @throws InvalidInterfaceException
1090
-     */
1091
-    protected function _reg_form_settings()
1092
-    {
1093
-        $this->_template_args['values'] = $this->_yes_no_values;
1094
-        add_action(
1095
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1096
-            array($this, 'email_validation_settings_form'),
1097
-            2
1098
-        );
1099
-        $this->_template_args = (array) apply_filters(
1100
-            'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',
1101
-            $this->_template_args
1102
-        );
1103
-        $this->_set_add_edit_form_tags('update_reg_form_settings');
1104
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1105
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1106
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',
1107
-            $this->_template_args,
1108
-            true
1109
-        );
1110
-        $this->display_admin_page_with_sidebar();
1111
-    }
1112
-
1113
-
1114
-    /**
1115
-     * @return void
1116
-     * @throws EE_Error
1117
-     * @throws InvalidArgumentException
1118
-     * @throws ReflectionException
1119
-     * @throws InvalidDataTypeException
1120
-     * @throws InvalidInterfaceException
1121
-     */
1122
-    protected function _update_reg_form_settings()
1123
-    {
1124
-        EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(
1125
-            EE_Registry::instance()->CFG->registration
1126
-        );
1127
-        EE_Registry::instance()->CFG->registration = apply_filters(
1128
-            'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
1129
-            EE_Registry::instance()->CFG->registration
1130
-        );
1131
-        $success = $this->_update_espresso_configuration(
1132
-            esc_html__('Registration Form Options', 'event_espresso'),
1133
-            EE_Registry::instance()->CFG,
1134
-            __FILE__,
1135
-            __FUNCTION__,
1136
-            __LINE__
1137
-        );
1138
-        $this->_redirect_after_action(
1139
-            $success,
1140
-            esc_html__('Registration Form Options', 'event_espresso'),
1141
-            'updated',
1142
-            array('action' => 'view_reg_form_settings')
1143
-        );
1144
-    }
1145
-
1146
-
1147
-    /**
1148
-     * @return void
1149
-     * @throws EE_Error
1150
-     * @throws InvalidArgumentException
1151
-     * @throws InvalidDataTypeException
1152
-     * @throws InvalidInterfaceException
1153
-     */
1154
-    public function email_validation_settings_form()
1155
-    {
1156
-        echo $this->_email_validation_settings_form()->get_html();
1157
-    }
1158
-
1159
-
1160
-    /**
1161
-     * _email_validation_settings_form
1162
-     *
1163
-     * @access protected
1164
-     * @return EE_Form_Section_Proper
1165
-     * @throws \EE_Error
1166
-     */
1167
-    protected function _email_validation_settings_form()
1168
-    {
1169
-        return new EE_Form_Section_Proper(
1170
-            array(
1171
-                'name'            => 'email_validation_settings',
1172
-                'html_id'         => 'email_validation_settings',
1173
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1174
-                'subsections'     => apply_filters(
1175
-                    'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections',
1176
-                    array(
1177
-                        'email_validation_hdr'   => new EE_Form_Section_HTML(
1178
-                            EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso'))
1179
-                        ),
1180
-                        'email_validation_level' => new EE_Select_Input(
1181
-                            array(
1182
-                                'basic'      => esc_html__('Basic', 'event_espresso'),
1183
-                                'wp_default' => esc_html__('WordPress Default', 'event_espresso'),
1184
-                                'i18n'       => esc_html__('International', 'event_espresso'),
1185
-                                'i18n_dns'   => esc_html__('International + DNS Check', 'event_espresso'),
1186
-                            ),
1187
-                            array(
1188
-                                'html_label_text' => esc_html__('Email Validation Level', 'event_espresso')
1189
-                                                     . EEH_Template::get_help_tab_link('email_validation_info'),
1190
-                                'html_help_text'  => esc_html__(
1191
-                                    'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.',
1192
-                                    'event_espresso'
1193
-                                ),
1194
-                                'default'         => isset(
1195
-                                    EE_Registry::instance()->CFG->registration->email_validation_level
1196
-                                )
1197
-                                    ? EE_Registry::instance()->CFG->registration->email_validation_level
1198
-                                    : 'wp_default',
1199
-                                'required'        => false,
1200
-                            )
1201
-                        ),
1202
-                    )
1203
-                ),
1204
-            )
1205
-        );
1206
-    }
1207
-
1208
-
1209
-    /**
1210
-     * @param EE_Registration_Config $EE_Registration_Config
1211
-     * @return EE_Registration_Config
1212
-     * @throws EE_Error
1213
-     * @throws InvalidArgumentException
1214
-     * @throws ReflectionException
1215
-     * @throws InvalidDataTypeException
1216
-     * @throws InvalidInterfaceException
1217
-     */
1218
-    public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config)
1219
-    {
1220
-        $prev_email_validation_level = $EE_Registration_Config->email_validation_level;
1221
-        try {
1222
-            $email_validation_settings_form = $this->_email_validation_settings_form();
1223
-            // if not displaying a form, then check for form submission
1224
-            if ($email_validation_settings_form->was_submitted()) {
1225
-                // capture form data
1226
-                $email_validation_settings_form->receive_form_submission();
1227
-                // validate form data
1228
-                if ($email_validation_settings_form->is_valid()) {
1229
-                    // grab validated data from form
1230
-                    $valid_data = $email_validation_settings_form->valid_data();
1231
-                    if (isset($valid_data['email_validation_level'])) {
1232
-                        $email_validation_level = $valid_data['email_validation_level'];
1233
-                        // now if they want to use international email addresses
1234
-                        if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') {
1235
-                            // in case we need to reset their email validation level,
1236
-                            // make sure that the previous value wasn't already set to one of the i18n options.
1237
-                            if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') {
1238
-                                // if so, then reset it back to "basic" since that is the only other option that,
1239
-                                // despite offering poor validation, supports i18n email addresses
1240
-                                $prev_email_validation_level = 'basic';
1241
-                            }
1242
-                            // confirm our i18n email validation will work on the server
1243
-                            if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1244
-                                // or reset email validation level to previous value
1245
-                                $email_validation_level = $prev_email_validation_level;
1246
-                            }
1247
-                        }
1248
-                        $EE_Registration_Config->email_validation_level = $email_validation_level;
1249
-                    } else {
1250
-                        EE_Error::add_error(
1251
-                            esc_html__(
1252
-                                'Invalid or missing Email Validation settings. Please refresh the form and try again.',
1253
-                                'event_espresso'
1254
-                            ),
1255
-                            __FILE__,
1256
-                            __FUNCTION__,
1257
-                            __LINE__
1258
-                        );
1259
-                    }
1260
-                } else {
1261
-                    if ($email_validation_settings_form->submission_error_message() !== '') {
1262
-                        EE_Error::add_error(
1263
-                            $email_validation_settings_form->submission_error_message(),
1264
-                            __FILE__,
1265
-                            __FUNCTION__,
1266
-                            __LINE__
1267
-                        );
1268
-                    }
1269
-                }
1270
-            }
1271
-        } catch (EE_Error $e) {
1272
-            $e->get_error();
1273
-        }
1274
-        return $EE_Registration_Config;
1275
-    }
1276
-
1277
-
1278
-    /**
1279
-     * confirms that the server's PHP version has the PCRE module enabled,
1280
-     * and that the PCRE version works with our i18n email validation
1281
-     *
1282
-     * @param EE_Registration_Config $EE_Registration_Config
1283
-     * @param string                 $email_validation_level
1284
-     * @return bool
1285
-     */
1286
-    private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)
1287
-    {
1288
-        // first check that PCRE is enabled
1289
-        if (! defined('PREG_BAD_UTF8_ERROR')) {
1290
-            EE_Error::add_error(
1291
-                sprintf(
1292
-                    esc_html__(
1293
-                        'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.',
1294
-                        'event_espresso'
1295
-                    ),
1296
-                    '<br />'
1297
-                ),
1298
-                __FILE__,
1299
-                __FUNCTION__,
1300
-                __LINE__
1301
-            );
1302
-            return false;
1303
-        } else {
1304
-            // PCRE support is enabled, but let's still
1305
-            // perform a test to see if the server will support it.
1306
-            // but first, save the updated validation level to the config,
1307
-            // so that the validation strategy picks it up.
1308
-            // this will get bumped back down if it doesn't work
1309
-            $EE_Registration_Config->email_validation_level = $email_validation_level;
1310
-            try {
1311
-                $email_validator = new EE_Email_Validation_Strategy();
1312
-                $i18n_email_address = apply_filters(
1313
-                    'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address',
1314
-                    'jägerjü[email protected]'
1315
-                );
1316
-                $email_validator->validate($i18n_email_address);
1317
-            } catch (Exception $e) {
1318
-                EE_Error::add_error(
1319
-                    sprintf(
1320
-                        esc_html__(
1321
-                            'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s',
1322
-                            'event_espresso'
1323
-                        ),
1324
-                        '<br />',
1325
-                        '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>'
1326
-                    ),
1327
-                    __FILE__,
1328
-                    __FUNCTION__,
1329
-                    __LINE__
1330
-                );
1331
-                return false;
1332
-            }
1333
-        }
1334
-        return true;
1335
-    }
17
+	/**
18
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
19
+	 */
20
+	public function __construct($routing = true)
21
+	{
22
+		define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS);
23
+		define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS);
24
+		define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/');
25
+		define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS);
26
+		define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/');
27
+		parent::__construct($routing);
28
+	}
29
+
30
+
31
+	/**
32
+	 * @return void
33
+	 */
34
+	protected function _extend_page_config()
35
+	{
36
+		$this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN;
37
+		$qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID'])
38
+			? $this->_req_data['QST_ID'] : 0;
39
+		$qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID'])
40
+			? $this->_req_data['QSG_ID'] : 0;
41
+
42
+		$new_page_routes = array(
43
+			'question_groups'    => array(
44
+				'func'       => '_question_groups_overview_list_table',
45
+				'capability' => 'ee_read_question_groups',
46
+			),
47
+			'add_question'       => array(
48
+				'func'       => '_edit_question',
49
+				'capability' => 'ee_edit_questions',
50
+			),
51
+			'insert_question'    => array(
52
+				'func'       => '_insert_or_update_question',
53
+				'args'       => array('new_question' => true),
54
+				'capability' => 'ee_edit_questions',
55
+				'noheader'   => true,
56
+			),
57
+			'duplicate_question' => array(
58
+				'func'       => '_duplicate_question',
59
+				'capability' => 'ee_edit_questions',
60
+				'noheader'   => true,
61
+			),
62
+			'trash_question'     => array(
63
+				'func'       => '_trash_question',
64
+				'capability' => 'ee_delete_question',
65
+				'obj_id'     => $qst_id,
66
+				'noheader'   => true,
67
+			),
68
+
69
+			'restore_question' => array(
70
+				'func'       => '_trash_or_restore_questions',
71
+				'capability' => 'ee_delete_question',
72
+				'obj_id'     => $qst_id,
73
+				'args'       => array('trash' => false),
74
+				'noheader'   => true,
75
+			),
76
+
77
+			'delete_question' => array(
78
+				'func'       => '_delete_question',
79
+				'capability' => 'ee_delete_question',
80
+				'obj_id'     => $qst_id,
81
+				'noheader'   => true,
82
+			),
83
+
84
+			'trash_questions' => array(
85
+				'func'       => '_trash_or_restore_questions',
86
+				'capability' => 'ee_delete_questions',
87
+				'args'       => array('trash' => true),
88
+				'noheader'   => true,
89
+			),
90
+
91
+			'restore_questions' => array(
92
+				'func'       => '_trash_or_restore_questions',
93
+				'capability' => 'ee_delete_questions',
94
+				'args'       => array('trash' => false),
95
+				'noheader'   => true,
96
+			),
97
+
98
+			'delete_questions' => array(
99
+				'func'       => '_delete_questions',
100
+				'args'       => array(),
101
+				'capability' => 'ee_delete_questions',
102
+				'noheader'   => true,
103
+			),
104
+
105
+			'add_question_group' => array(
106
+				'func'       => '_edit_question_group',
107
+				'capability' => 'ee_edit_question_groups',
108
+			),
109
+
110
+			'edit_question_group' => array(
111
+				'func'       => '_edit_question_group',
112
+				'capability' => 'ee_edit_question_group',
113
+				'obj_id'     => $qsg_id,
114
+				'args'       => array('edit'),
115
+			),
116
+
117
+			'delete_question_groups' => array(
118
+				'func'       => '_delete_question_groups',
119
+				'capability' => 'ee_delete_question_groups',
120
+				'noheader'   => true,
121
+			),
122
+
123
+			'delete_question_group' => array(
124
+				'func'       => '_delete_question_groups',
125
+				'capability' => 'ee_delete_question_group',
126
+				'obj_id'     => $qsg_id,
127
+				'noheader'   => true,
128
+			),
129
+
130
+			'trash_question_group' => array(
131
+				'func'       => '_trash_or_restore_question_groups',
132
+				'args'       => array('trash' => true),
133
+				'capability' => 'ee_delete_question_group',
134
+				'obj_id'     => $qsg_id,
135
+				'noheader'   => true,
136
+			),
137
+
138
+			'restore_question_group' => array(
139
+				'func'       => '_trash_or_restore_question_groups',
140
+				'args'       => array('trash' => false),
141
+				'capability' => 'ee_delete_question_group',
142
+				'obj_id'     => $qsg_id,
143
+				'noheader'   => true,
144
+			),
145
+
146
+			'insert_question_group' => array(
147
+				'func'       => '_insert_or_update_question_group',
148
+				'args'       => array('new_question_group' => true),
149
+				'capability' => 'ee_edit_question_groups',
150
+				'noheader'   => true,
151
+			),
152
+
153
+			'update_question_group' => array(
154
+				'func'       => '_insert_or_update_question_group',
155
+				'args'       => array('new_question_group' => false),
156
+				'capability' => 'ee_edit_question_group',
157
+				'obj_id'     => $qsg_id,
158
+				'noheader'   => true,
159
+			),
160
+
161
+			'trash_question_groups' => array(
162
+				'func'       => '_trash_or_restore_question_groups',
163
+				'args'       => array('trash' => true),
164
+				'capability' => 'ee_delete_question_groups',
165
+				'noheader'   => array('trash' => false),
166
+			),
167
+
168
+			'restore_question_groups' => array(
169
+				'func'       => '_trash_or_restore_question_groups',
170
+				'args'       => array('trash' => false),
171
+				'capability' => 'ee_delete_question_groups',
172
+				'noheader'   => true,
173
+			),
174
+
175
+
176
+			'espresso_update_question_group_order' => array(
177
+				'func'       => 'update_question_group_order',
178
+				'capability' => 'ee_edit_question_groups',
179
+				'noheader'   => true,
180
+			),
181
+
182
+			'view_reg_form_settings' => array(
183
+				'func'       => '_reg_form_settings',
184
+				'capability' => 'manage_options',
185
+			),
186
+
187
+			'update_reg_form_settings' => array(
188
+				'func'       => '_update_reg_form_settings',
189
+				'capability' => 'manage_options',
190
+				'noheader'   => true,
191
+			),
192
+		);
193
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
194
+
195
+		$new_page_config = array(
196
+
197
+			'question_groups' => array(
198
+				'nav'           => array(
199
+					'label' => esc_html__('Question Groups', 'event_espresso'),
200
+					'order' => 20,
201
+				),
202
+				'list_table'    => 'Registration_Form_Question_Groups_Admin_List_Table',
203
+				'help_tabs'     => array(
204
+					'registration_form_question_groups_help_tab'                           => array(
205
+						'title'    => esc_html__('Question Groups', 'event_espresso'),
206
+						'filename' => 'registration_form_question_groups',
207
+					),
208
+					'registration_form_question_groups_table_column_headings_help_tab'     => array(
209
+						'title'    => esc_html__('Question Groups Table Column Headings', 'event_espresso'),
210
+						'filename' => 'registration_form_question_groups_table_column_headings',
211
+					),
212
+					'registration_form_question_groups_views_bulk_actions_search_help_tab' => array(
213
+						'title'    => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'),
214
+						'filename' => 'registration_form_question_groups_views_bulk_actions_search',
215
+					),
216
+				),
217
+				'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'),
218
+				'metaboxes'     => $this->_default_espresso_metaboxes,
219
+				'require_nonce' => false,
220
+				'qtips'         => array(
221
+					'EE_Registration_Form_Tips',
222
+				),
223
+			),
224
+
225
+			'add_question' => array(
226
+				'nav'           => array(
227
+					'label'      => esc_html__('Add Question', 'event_espresso'),
228
+					'order'      => 5,
229
+					'persistent' => false,
230
+				),
231
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
232
+				'help_tabs'     => array(
233
+					'registration_form_add_question_help_tab' => array(
234
+						'title'    => esc_html__('Add Question', 'event_espresso'),
235
+						'filename' => 'registration_form_add_question',
236
+					),
237
+				),
238
+				'help_tour'     => array('Registration_Form_Add_Question_Help_Tour'),
239
+				'require_nonce' => false,
240
+			),
241
+
242
+			'add_question_group' => array(
243
+				'nav'           => array(
244
+					'label'      => esc_html__('Add Question Group', 'event_espresso'),
245
+					'order'      => 5,
246
+					'persistent' => false,
247
+				),
248
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
249
+				'help_tabs'     => array(
250
+					'registration_form_add_question_group_help_tab' => array(
251
+						'title'    => esc_html__('Add Question Group', 'event_espresso'),
252
+						'filename' => 'registration_form_add_question_group',
253
+					),
254
+				),
255
+				'help_tour'     => array('Registration_Form_Add_Question_Group_Help_Tour'),
256
+				'require_nonce' => false,
257
+			),
258
+
259
+			'edit_question_group' => array(
260
+				'nav'           => array(
261
+					'label'      => esc_html__('Edit Question Group', 'event_espresso'),
262
+					'order'      => 5,
263
+					'persistent' => false,
264
+					'url'        => isset($this->_req_data['question_group_id']) ? add_query_arg(
265
+						array('question_group_id' => $this->_req_data['question_group_id']),
266
+						$this->_current_page_view_url
267
+					) : $this->_admin_base_url,
268
+				),
269
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
270
+				'help_tabs'     => array(
271
+					'registration_form_edit_question_group_help_tab' => array(
272
+						'title'    => esc_html__('Edit Question Group', 'event_espresso'),
273
+						'filename' => 'registration_form_edit_question_group',
274
+					),
275
+				),
276
+				'help_tour'     => array('Registration_Form_Edit_Question_Group_Help_Tour'),
277
+				'require_nonce' => false,
278
+			),
279
+
280
+			'view_reg_form_settings' => array(
281
+				'nav'           => array(
282
+					'label' => esc_html__('Reg Form Settings', 'event_espresso'),
283
+					'order' => 40,
284
+				),
285
+				'labels'        => array(
286
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
287
+				),
288
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
289
+				'help_tabs'     => array(
290
+					'registration_form_reg_form_settings_help_tab' => array(
291
+						'title'    => esc_html__('Registration Form Settings', 'event_espresso'),
292
+						'filename' => 'registration_form_reg_form_settings',
293
+					),
294
+				),
295
+				'help_tour'     => array('Registration_Form_Settings_Help_Tour'),
296
+				'require_nonce' => false,
297
+			),
298
+
299
+		);
300
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
301
+
302
+		// change the list table we're going to use so it's the NEW list table!
303
+		$this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table';
304
+
305
+
306
+		// additional labels
307
+		$new_labels = array(
308
+			'add_question'          => esc_html__('Add New Question', 'event_espresso'),
309
+			'delete_question'       => esc_html__('Delete Question', 'event_espresso'),
310
+			'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'),
311
+			'edit_question_group'   => esc_html__('Edit Question Group', 'event_espresso'),
312
+			'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'),
313
+		);
314
+		$this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels);
315
+	}
316
+
317
+
318
+	/**
319
+	 * @return void
320
+	 */
321
+	protected function _ajax_hooks()
322
+	{
323
+		add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order'));
324
+	}
325
+
326
+
327
+	/**
328
+	 * @return void
329
+	 */
330
+	public function load_scripts_styles_question_groups()
331
+	{
332
+		wp_enqueue_script('espresso_ajax_table_sorting');
333
+	}
334
+
335
+
336
+	/**
337
+	 * @return void
338
+	 */
339
+	public function load_scripts_styles_add_question_group()
340
+	{
341
+		$this->load_scripts_styles_forms();
342
+		$this->load_sortable_question_script();
343
+	}
344
+
345
+
346
+	/**
347
+	 * @return void
348
+	 */
349
+	public function load_scripts_styles_edit_question_group()
350
+	{
351
+		$this->load_scripts_styles_forms();
352
+		$this->load_sortable_question_script();
353
+	}
354
+
355
+
356
+	/**
357
+	 * registers and enqueues script for questions
358
+	 *
359
+	 * @return void
360
+	 */
361
+	public function load_sortable_question_script()
362
+	{
363
+		wp_register_script(
364
+			'ee-question-sortable',
365
+			REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',
366
+			array('jquery-ui-sortable'),
367
+			EVENT_ESPRESSO_VERSION,
368
+			true
369
+		);
370
+		wp_enqueue_script('ee-question-sortable');
371
+	}
372
+
373
+
374
+	/**
375
+	 * @return void
376
+	 */
377
+	protected function _set_list_table_views_default()
378
+	{
379
+		$this->_views = array(
380
+			'all' => array(
381
+				'slug'        => 'all',
382
+				'label'       => esc_html__('View All Questions', 'event_espresso'),
383
+				'count'       => 0,
384
+				'bulk_action' => array(
385
+					'trash_questions' => esc_html__('Trash', 'event_espresso'),
386
+				),
387
+			),
388
+		);
389
+
390
+		if (EE_Registry::instance()->CAP->current_user_can(
391
+			'ee_delete_questions',
392
+			'espresso_registration_form_trash_questions'
393
+		)
394
+		) {
395
+			$this->_views['trash'] = array(
396
+				'slug'        => 'trash',
397
+				'label'       => esc_html__('Trash', 'event_espresso'),
398
+				'count'       => 0,
399
+				'bulk_action' => array(
400
+					'delete_questions'  => esc_html__('Delete Permanently', 'event_espresso'),
401
+					'restore_questions' => esc_html__('Restore', 'event_espresso'),
402
+				),
403
+			);
404
+		}
405
+	}
406
+
407
+
408
+	/**
409
+	 * @return void
410
+	 */
411
+	protected function _set_list_table_views_question_groups()
412
+	{
413
+		$this->_views = array(
414
+			'all' => array(
415
+				'slug'        => 'all',
416
+				'label'       => esc_html__('All', 'event_espresso'),
417
+				'count'       => 0,
418
+				'bulk_action' => array(
419
+					'trash_question_groups' => esc_html__('Trash', 'event_espresso'),
420
+				),
421
+			),
422
+		);
423
+
424
+		if (EE_Registry::instance()->CAP->current_user_can(
425
+			'ee_delete_question_groups',
426
+			'espresso_registration_form_trash_question_groups'
427
+		)
428
+		) {
429
+			$this->_views['trash'] = array(
430
+				'slug'        => 'trash',
431
+				'label'       => esc_html__('Trash', 'event_espresso'),
432
+				'count'       => 0,
433
+				'bulk_action' => array(
434
+					'delete_question_groups'  => esc_html__('Delete Permanently', 'event_espresso'),
435
+					'restore_question_groups' => esc_html__('Restore', 'event_espresso'),
436
+				),
437
+			);
438
+		}
439
+	}
440
+
441
+
442
+	/**
443
+	 * @return void
444
+	 * @throws EE_Error
445
+	 * @throws InvalidArgumentException
446
+	 * @throws InvalidDataTypeException
447
+	 * @throws InvalidInterfaceException
448
+	 */
449
+	protected function _questions_overview_list_table()
450
+	{
451
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
452
+			'add_question',
453
+			'add_question',
454
+			array(),
455
+			'add-new-h2'
456
+		);
457
+		parent::_questions_overview_list_table();
458
+	}
459
+
460
+
461
+	/**
462
+	 * @return void
463
+	 * @throws DomainException
464
+	 * @throws EE_Error
465
+	 * @throws InvalidArgumentException
466
+	 * @throws InvalidDataTypeException
467
+	 * @throws InvalidInterfaceException
468
+	 */
469
+	protected function _question_groups_overview_list_table()
470
+	{
471
+		$this->_search_btn_label = esc_html__('Question Groups', 'event_espresso');
472
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
473
+			'add_question_group',
474
+			'add_question_group',
475
+			array(),
476
+			'add-new-h2'
477
+		);
478
+		$this->display_admin_list_table_page_with_sidebar();
479
+	}
480
+
481
+
482
+	/**
483
+	 * @return void
484
+	 * @throws EE_Error
485
+	 * @throws InvalidArgumentException
486
+	 * @throws InvalidDataTypeException
487
+	 * @throws InvalidInterfaceException
488
+	 */
489
+	protected function _delete_question()
490
+	{
491
+		$success = $this->_delete_items($this->_question_model);
492
+		$this->_redirect_after_action(
493
+			$success,
494
+			$this->_question_model->item_name($success),
495
+			'deleted',
496
+			array('action' => 'default', 'status' => 'all')
497
+		);
498
+	}
499
+
500
+
501
+	/**
502
+	 * @return void
503
+	 * @throws EE_Error
504
+	 * @throws InvalidArgumentException
505
+	 * @throws InvalidDataTypeException
506
+	 * @throws InvalidInterfaceException
507
+	 */
508
+	protected function _delete_questions()
509
+	{
510
+		$success = $this->_delete_items($this->_question_model);
511
+		$this->_redirect_after_action(
512
+			$success,
513
+			$this->_question_model->item_name($success),
514
+			'deleted permanently',
515
+			array('action' => 'default', 'status' => 'trash')
516
+		);
517
+	}
518
+
519
+
520
+	/**
521
+	 * Performs the deletion of a single or multiple questions or question groups.
522
+	 *
523
+	 * @param EEM_Soft_Delete_Base $model
524
+	 * @return int number of items deleted permanently
525
+	 * @throws EE_Error
526
+	 * @throws InvalidArgumentException
527
+	 * @throws InvalidDataTypeException
528
+	 * @throws InvalidInterfaceException
529
+	 */
530
+	private function _delete_items(EEM_Soft_Delete_Base $model)
531
+	{
532
+		$success = 0;
533
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
534
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
535
+			// if array has more than one element than success message should be plural
536
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
537
+			// cycle thru bulk action checkboxes
538
+			while (list($ID, $value) = each($this->_req_data['checkbox'])) {
539
+				if (! $this->_delete_item($ID, $model)) {
540
+					$success = 0;
541
+				}
542
+			}
543
+		} elseif (! empty($this->_req_data['QSG_ID'])) {
544
+			$success = $this->_delete_item($this->_req_data['QSG_ID'], $model);
545
+		} elseif (! empty($this->_req_data['QST_ID'])) {
546
+			$success = $this->_delete_item($this->_req_data['QST_ID'], $model);
547
+		} else {
548
+			EE_Error::add_error(
549
+				sprintf(
550
+					esc_html__(
551
+						"No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.",
552
+						"event_espresso"
553
+					)
554
+				),
555
+				__FILE__,
556
+				__FUNCTION__,
557
+				__LINE__
558
+			);
559
+		}
560
+		return $success;
561
+	}
562
+
563
+
564
+	/**
565
+	 * Deletes the specified question (and its associated question options) or question group
566
+	 *
567
+	 * @param int                  $id
568
+	 * @param EEM_Soft_Delete_Base $model
569
+	 * @return boolean
570
+	 * @throws EE_Error
571
+	 * @throws InvalidArgumentException
572
+	 * @throws InvalidDataTypeException
573
+	 * @throws InvalidInterfaceException
574
+	 */
575
+	protected function _delete_item($id, $model)
576
+	{
577
+		if ($model instanceof EEM_Question) {
578
+			EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id))));
579
+		}
580
+		return $model->delete_permanently_by_ID(absint($id));
581
+	}
582
+
583
+
584
+	/******************************    QUESTION GROUPS    ******************************/
585
+
586
+
587
+	/**
588
+	 * @param string $type
589
+	 * @return void
590
+	 * @throws DomainException
591
+	 * @throws EE_Error
592
+	 * @throws InvalidArgumentException
593
+	 * @throws InvalidDataTypeException
594
+	 * @throws InvalidInterfaceException
595
+	 */
596
+	protected function _edit_question_group($type = 'add')
597
+	{
598
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
599
+		$ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID'])
600
+			? absint($this->_req_data['QSG_ID'])
601
+			: false;
602
+
603
+		switch ($this->_req_action) {
604
+			case 'add_question_group':
605
+				$this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso');
606
+				break;
607
+			case 'edit_question_group':
608
+				$this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso');
609
+				break;
610
+			default:
611
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
612
+		}
613
+		// add ID to title if editing
614
+		$this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
615
+		if ($ID) {
616
+			/** @var EE_Question_Group $questionGroup */
617
+			$questionGroup = $this->_question_group_model->get_one_by_ID($ID);
618
+			$additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID));
619
+			$this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields);
620
+		} else {
621
+			/** @var EE_Question_Group $questionGroup */
622
+			$questionGroup = EEM_Question_Group::instance()->create_default_object();
623
+			$questionGroup->set_order_to_latest();
624
+			$this->_set_add_edit_form_tags('insert_question_group');
625
+		}
626
+		$this->_template_args['values'] = $this->_yes_no_values;
627
+		$this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group();
628
+		$this->_template_args['QSG_ID'] = $ID ? $ID : true;
629
+		$this->_template_args['question_group'] = $questionGroup;
630
+
631
+		$redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url);
632
+		$this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL);
633
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
634
+			REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',
635
+			$this->_template_args,
636
+			true
637
+		);
638
+
639
+		// the details template wrapper
640
+		$this->display_admin_page_with_sidebar();
641
+	}
642
+
643
+
644
+	/**
645
+	 * @return void
646
+	 * @throws EE_Error
647
+	 * @throws InvalidArgumentException
648
+	 * @throws InvalidDataTypeException
649
+	 * @throws InvalidInterfaceException
650
+	 */
651
+	protected function _delete_question_groups()
652
+	{
653
+		$success = $this->_delete_items($this->_question_group_model);
654
+		$this->_redirect_after_action(
655
+			$success,
656
+			$this->_question_group_model->item_name($success),
657
+			'deleted permanently',
658
+			array('action' => 'question_groups', 'status' => 'trash')
659
+		);
660
+	}
661
+
662
+
663
+	/**
664
+	 * @param bool $new_question_group
665
+	 * @throws EE_Error
666
+	 * @throws InvalidArgumentException
667
+	 * @throws InvalidDataTypeException
668
+	 * @throws InvalidInterfaceException
669
+	 */
670
+	protected function _insert_or_update_question_group($new_question_group = true)
671
+	{
672
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
673
+		$set_column_values = $this->_set_column_values_for($this->_question_group_model);
674
+		if ($new_question_group) {
675
+			// make sure identifier is unique
676
+			$identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : '';
677
+			$identifier_exists = ! empty($identifier_value)
678
+				? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0
679
+				: false;
680
+			if ($identifier_exists) {
681
+				$set_column_values['QSG_identifier'] .= uniqid('id', true);
682
+			}
683
+			$QSG_ID = $this->_question_group_model->insert($set_column_values);
684
+			$success = $QSG_ID ? 1 : 0;
685
+			if ($success === 0) {
686
+				EE_Error::add_error(
687
+					esc_html__('Something went wrong saving the question group.', 'event_espresso'),
688
+					__FILE__,
689
+					__FUNCTION__,
690
+					__LINE__
691
+				);
692
+				$this->_redirect_after_action(
693
+					false,
694
+					'',
695
+					'',
696
+					array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID),
697
+					true
698
+				);
699
+			}
700
+		} else {
701
+			$QSG_ID = absint($this->_req_data['QSG_ID']);
702
+			unset($set_column_values['QSG_ID']);
703
+			$success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID)));
704
+		}
705
+
706
+		$phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
707
+			EEM_Attendee::system_question_phone
708
+		);
709
+		// update the existing related questions
710
+		// BUT FIRST...  delete the phone question from the Question_Group_Question
711
+		// if it is being added to this question group (therefore removed from the existing group)
712
+		if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) {
713
+			// delete where QST ID = system phone question ID and Question Group ID is NOT this group
714
+			EEM_Question_Group_Question::instance()->delete(
715
+				array(
716
+					array(
717
+						'QST_ID' => $phone_question_id,
718
+						'QSG_ID' => array('!=', $QSG_ID),
719
+					),
720
+				)
721
+			);
722
+		}
723
+		/** @type EE_Question_Group $question_group */
724
+		$question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);
725
+		$questions = $question_group->questions();
726
+		// make sure system phone question is added to list of questions for this group
727
+		if (! isset($questions[ $phone_question_id ])) {
728
+			$questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
729
+		}
730
+
731
+		foreach ($questions as $question_ID => $question) {
732
+			// first we always check for order.
733
+			if (! empty($this->_req_data['question_orders'][ $question_ID ])) {
734
+				// update question order
735
+				$question_group->update_question_order(
736
+					$question_ID,
737
+					$this->_req_data['question_orders'][ $question_ID ]
738
+				);
739
+			}
740
+
741
+			// then we always check if adding or removing.
742
+			if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) {
743
+				$question_group->add_question($question_ID);
744
+			} else {
745
+				// not found, remove it (but only if not a system question for the personal group
746
+				// with the exception of lname system question - we allow removal of it)
747
+				if (in_array(
748
+					$question->system_ID(),
749
+					EEM_Question::instance()->required_system_questions_in_system_question_group(
750
+						$question_group->system_group()
751
+					)
752
+				)) {
753
+					continue;
754
+				} else {
755
+					$question_group->remove_question($question_ID);
756
+				}
757
+			}
758
+		}
759
+		// save new related questions
760
+		if (isset($this->_req_data['questions'])) {
761
+			foreach ($this->_req_data['questions'] as $QST_ID) {
762
+				$question_group->add_question($QST_ID);
763
+				if (isset($this->_req_data['question_orders'][ $QST_ID ])) {
764
+					$question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]);
765
+				}
766
+			}
767
+		}
768
+
769
+		if ($success !== false) {
770
+			$msg = $new_question_group
771
+				? sprintf(
772
+					esc_html__('The %s has been created', 'event_espresso'),
773
+					$this->_question_group_model->item_name()
774
+				)
775
+				: sprintf(
776
+					esc_html__(
777
+						'The %s has been updated',
778
+						'event_espresso'
779
+					),
780
+					$this->_question_group_model->item_name()
781
+				);
782
+			EE_Error::add_success($msg);
783
+		}
784
+		$this->_redirect_after_action(
785
+			false,
786
+			'',
787
+			'',
788
+			array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID),
789
+			true
790
+		);
791
+	}
792
+
793
+
794
+	/**
795
+	 * duplicates a question and all its question options and redirects to the new question.
796
+	 *
797
+	 * @return void
798
+	 * @throws EE_Error
799
+	 * @throws InvalidArgumentException
800
+	 * @throws ReflectionException
801
+	 * @throws InvalidDataTypeException
802
+	 * @throws InvalidInterfaceException
803
+	 */
804
+	public function _duplicate_question()
805
+	{
806
+		$question_ID = (int) $this->_req_data['QST_ID'];
807
+		$question = EEM_Question::instance()->get_one_by_ID($question_ID);
808
+		if ($question instanceof EE_Question) {
809
+			$new_question = $question->duplicate();
810
+			if ($new_question instanceof EE_Question) {
811
+				$this->_redirect_after_action(
812
+					true,
813
+					esc_html__('Question', 'event_espresso'),
814
+					esc_html__('Duplicated', 'event_espresso'),
815
+					array('action' => 'edit_question', 'QST_ID' => $new_question->ID()),
816
+					true
817
+				);
818
+			} else {
819
+				global $wpdb;
820
+				EE_Error::add_error(
821
+					sprintf(
822
+						esc_html__(
823
+							'Could not duplicate question with ID %1$d because: %2$s',
824
+							'event_espresso'
825
+						),
826
+						$question_ID,
827
+						$wpdb->last_error
828
+					),
829
+					__FILE__,
830
+					__FUNCTION__,
831
+					__LINE__
832
+				);
833
+				$this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
834
+			}
835
+		} else {
836
+			EE_Error::add_error(
837
+				sprintf(
838
+					esc_html__(
839
+						'Could not duplicate question with ID %d because it didn\'t exist!',
840
+						'event_espresso'
841
+					),
842
+					$question_ID
843
+				),
844
+				__FILE__,
845
+				__FUNCTION__,
846
+				__LINE__
847
+			);
848
+			$this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
849
+		}
850
+	}
851
+
852
+
853
+	/**
854
+	 * @param bool $trash
855
+	 * @throws EE_Error
856
+	 */
857
+	protected function _trash_or_restore_question_groups($trash = true)
858
+	{
859
+		$this->_trash_or_restore_items($this->_question_group_model, $trash);
860
+	}
861
+
862
+
863
+	/**
864
+	 *_trash_question
865
+	 *
866
+	 * @return void
867
+	 * @throws EE_Error
868
+	 */
869
+	protected function _trash_question()
870
+	{
871
+		$success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']);
872
+		$query_args = array('action' => 'default', 'status' => 'all');
873
+		$this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args);
874
+	}
875
+
876
+
877
+	/**
878
+	 * @param bool $trash
879
+	 * @throws EE_Error
880
+	 */
881
+	protected function _trash_or_restore_questions($trash = true)
882
+	{
883
+		$this->_trash_or_restore_items($this->_question_model, $trash);
884
+	}
885
+
886
+
887
+	/**
888
+	 * Internally used to delete or restore items, using the request data. Meant to be
889
+	 * flexible between question or question groups
890
+	 *
891
+	 * @param EEM_Soft_Delete_Base $model
892
+	 * @param boolean              $trash whether to trash or restore
893
+	 * @throws EE_Error
894
+	 */
895
+	private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true)
896
+	{
897
+
898
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
899
+
900
+		$success = 1;
901
+		// Checkboxes
902
+		// echo "trash $trash";
903
+		// var_dump($this->_req_data['checkbox']);die;
904
+		if (isset($this->_req_data['checkbox'])) {
905
+			if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
906
+				// if array has more than one element than success message should be plural
907
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
908
+				// cycle thru bulk action checkboxes
909
+				while (list($ID, $value) = each($this->_req_data['checkbox'])) {
910
+					if (! $model->delete_or_restore_by_ID($trash, absint($ID))) {
911
+						$success = 0;
912
+					}
913
+				}
914
+			} else {
915
+				// grab single id and delete
916
+				$ID = absint($this->_req_data['checkbox']);
917
+				if (! $model->delete_or_restore_by_ID($trash, $ID)) {
918
+					$success = 0;
919
+				}
920
+			}
921
+		} else {
922
+			// delete via trash link
923
+			// grab single id and delete
924
+			$ID = absint($this->_req_data[ $model->primary_key_name() ]);
925
+			if (! $model->delete_or_restore_by_ID($trash, $ID)) {
926
+				$success = 0;
927
+			}
928
+		}
929
+
930
+
931
+		$action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) );
932
+		// echo "action :$action";
933
+		// $action = 'questions' ? 'default' : $action;
934
+		if ($trash) {
935
+			$action_desc = 'trashed';
936
+			$status = 'trash';
937
+		} else {
938
+			$action_desc = 'restored';
939
+			$status = 'all';
940
+		}
941
+		$this->_redirect_after_action(
942
+			$success,
943
+			$model->item_name($success),
944
+			$action_desc,
945
+			array('action' => $action, 'status' => $status)
946
+		);
947
+	}
948
+
949
+
950
+	/**
951
+	 * @param            $per_page
952
+	 * @param int        $current_page
953
+	 * @param bool|false $count
954
+	 * @return EE_Soft_Delete_Base_Class[]|int
955
+	 * @throws EE_Error
956
+	 * @throws InvalidArgumentException
957
+	 * @throws InvalidDataTypeException
958
+	 * @throws InvalidInterfaceException
959
+	 */
960
+	public function get_trashed_questions($per_page, $current_page = 1, $count = false)
961
+	{
962
+		$query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
963
+
964
+		if ($count) {
965
+			// note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
966
+			$where = isset($query_params[0]) ? array($query_params[0]) : array();
967
+			$results = $this->_question_model->count_deleted($where);
968
+		} else {
969
+			// note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
970
+			$results = $this->_question_model->get_all_deleted($query_params);
971
+		}
972
+		return $results;
973
+	}
974
+
975
+
976
+	/**
977
+	 * @param            $per_page
978
+	 * @param int        $current_page
979
+	 * @param bool|false $count
980
+	 * @return EE_Soft_Delete_Base_Class[]|int
981
+	 * @throws EE_Error
982
+	 * @throws InvalidArgumentException
983
+	 * @throws InvalidDataTypeException
984
+	 * @throws InvalidInterfaceException
985
+	 */
986
+	public function get_question_groups($per_page, $current_page = 1, $count = false)
987
+	{
988
+		$questionGroupModel = EEM_Question_Group::instance();
989
+		$query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);
990
+		if ($count) {
991
+			$where = isset($query_params[0]) ? array($query_params[0]) : array();
992
+			$results = $questionGroupModel->count($where);
993
+		} else {
994
+			$results = $questionGroupModel->get_all($query_params);
995
+		}
996
+		return $results;
997
+	}
998
+
999
+
1000
+	/**
1001
+	 * @param      $per_page
1002
+	 * @param int  $current_page
1003
+	 * @param bool $count
1004
+	 * @return EE_Soft_Delete_Base_Class[]|int
1005
+	 * @throws EE_Error
1006
+	 * @throws InvalidArgumentException
1007
+	 * @throws InvalidDataTypeException
1008
+	 * @throws InvalidInterfaceException
1009
+	 */
1010
+	public function get_trashed_question_groups($per_page, $current_page = 1, $count = false)
1011
+	{
1012
+		$questionGroupModel = EEM_Question_Group::instance();
1013
+		$query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);
1014
+		if ($count) {
1015
+			$where = isset($query_params[0]) ? array($query_params[0]) : array();
1016
+			$query_params['limit'] = null;
1017
+			$results = $questionGroupModel->count_deleted($where);
1018
+		} else {
1019
+			$results = $questionGroupModel->get_all_deleted($query_params);
1020
+		}
1021
+		return $results;
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * method for performing updates to question order
1027
+	 *
1028
+	 * @return void results array
1029
+	 * @throws EE_Error
1030
+	 * @throws InvalidArgumentException
1031
+	 * @throws InvalidDataTypeException
1032
+	 * @throws InvalidInterfaceException
1033
+	 */
1034
+	public function update_question_group_order()
1035
+	{
1036
+
1037
+		$success = esc_html__('Question group order was updated successfully.', 'event_espresso');
1038
+
1039
+		// grab our row IDs
1040
+		$row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids'])
1041
+			? explode(',', rtrim($this->_req_data['row_ids'], ','))
1042
+			: array();
1043
+
1044
+		$perpage = ! empty($this->_req_data['perpage'])
1045
+			? (int) $this->_req_data['perpage']
1046
+			: null;
1047
+		$curpage = ! empty($this->_req_data['curpage'])
1048
+			? (int) $this->_req_data['curpage']
1049
+			: null;
1050
+
1051
+		if (! empty($row_ids)) {
1052
+			// figure out where we start the row_id count at for the current page.
1053
+			$qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;
1054
+
1055
+			$row_count = count($row_ids);
1056
+			for ($i = 0; $i < $row_count; $i++) {
1057
+				// Update the questions when re-ordering
1058
+				$updated = EEM_Question_Group::instance()->update(
1059
+					array('QSG_order' => $qsgcount),
1060
+					array(array('QSG_ID' => $row_ids[ $i ]))
1061
+				);
1062
+				if ($updated === false) {
1063
+					$success = false;
1064
+				}
1065
+				$qsgcount++;
1066
+			}
1067
+		} else {
1068
+			$success = false;
1069
+		}
1070
+
1071
+		$errors = ! $success
1072
+			? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso')
1073
+			: false;
1074
+
1075
+		echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors));
1076
+		die();
1077
+	}
1078
+
1079
+
1080
+
1081
+	/***************************************       REGISTRATION SETTINGS       ***************************************/
1082
+
1083
+
1084
+	/**
1085
+	 * @throws DomainException
1086
+	 * @throws EE_Error
1087
+	 * @throws InvalidArgumentException
1088
+	 * @throws InvalidDataTypeException
1089
+	 * @throws InvalidInterfaceException
1090
+	 */
1091
+	protected function _reg_form_settings()
1092
+	{
1093
+		$this->_template_args['values'] = $this->_yes_no_values;
1094
+		add_action(
1095
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
1096
+			array($this, 'email_validation_settings_form'),
1097
+			2
1098
+		);
1099
+		$this->_template_args = (array) apply_filters(
1100
+			'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',
1101
+			$this->_template_args
1102
+		);
1103
+		$this->_set_add_edit_form_tags('update_reg_form_settings');
1104
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1105
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1106
+			REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',
1107
+			$this->_template_args,
1108
+			true
1109
+		);
1110
+		$this->display_admin_page_with_sidebar();
1111
+	}
1112
+
1113
+
1114
+	/**
1115
+	 * @return void
1116
+	 * @throws EE_Error
1117
+	 * @throws InvalidArgumentException
1118
+	 * @throws ReflectionException
1119
+	 * @throws InvalidDataTypeException
1120
+	 * @throws InvalidInterfaceException
1121
+	 */
1122
+	protected function _update_reg_form_settings()
1123
+	{
1124
+		EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(
1125
+			EE_Registry::instance()->CFG->registration
1126
+		);
1127
+		EE_Registry::instance()->CFG->registration = apply_filters(
1128
+			'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
1129
+			EE_Registry::instance()->CFG->registration
1130
+		);
1131
+		$success = $this->_update_espresso_configuration(
1132
+			esc_html__('Registration Form Options', 'event_espresso'),
1133
+			EE_Registry::instance()->CFG,
1134
+			__FILE__,
1135
+			__FUNCTION__,
1136
+			__LINE__
1137
+		);
1138
+		$this->_redirect_after_action(
1139
+			$success,
1140
+			esc_html__('Registration Form Options', 'event_espresso'),
1141
+			'updated',
1142
+			array('action' => 'view_reg_form_settings')
1143
+		);
1144
+	}
1145
+
1146
+
1147
+	/**
1148
+	 * @return void
1149
+	 * @throws EE_Error
1150
+	 * @throws InvalidArgumentException
1151
+	 * @throws InvalidDataTypeException
1152
+	 * @throws InvalidInterfaceException
1153
+	 */
1154
+	public function email_validation_settings_form()
1155
+	{
1156
+		echo $this->_email_validation_settings_form()->get_html();
1157
+	}
1158
+
1159
+
1160
+	/**
1161
+	 * _email_validation_settings_form
1162
+	 *
1163
+	 * @access protected
1164
+	 * @return EE_Form_Section_Proper
1165
+	 * @throws \EE_Error
1166
+	 */
1167
+	protected function _email_validation_settings_form()
1168
+	{
1169
+		return new EE_Form_Section_Proper(
1170
+			array(
1171
+				'name'            => 'email_validation_settings',
1172
+				'html_id'         => 'email_validation_settings',
1173
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1174
+				'subsections'     => apply_filters(
1175
+					'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections',
1176
+					array(
1177
+						'email_validation_hdr'   => new EE_Form_Section_HTML(
1178
+							EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso'))
1179
+						),
1180
+						'email_validation_level' => new EE_Select_Input(
1181
+							array(
1182
+								'basic'      => esc_html__('Basic', 'event_espresso'),
1183
+								'wp_default' => esc_html__('WordPress Default', 'event_espresso'),
1184
+								'i18n'       => esc_html__('International', 'event_espresso'),
1185
+								'i18n_dns'   => esc_html__('International + DNS Check', 'event_espresso'),
1186
+							),
1187
+							array(
1188
+								'html_label_text' => esc_html__('Email Validation Level', 'event_espresso')
1189
+													 . EEH_Template::get_help_tab_link('email_validation_info'),
1190
+								'html_help_text'  => esc_html__(
1191
+									'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.',
1192
+									'event_espresso'
1193
+								),
1194
+								'default'         => isset(
1195
+									EE_Registry::instance()->CFG->registration->email_validation_level
1196
+								)
1197
+									? EE_Registry::instance()->CFG->registration->email_validation_level
1198
+									: 'wp_default',
1199
+								'required'        => false,
1200
+							)
1201
+						),
1202
+					)
1203
+				),
1204
+			)
1205
+		);
1206
+	}
1207
+
1208
+
1209
+	/**
1210
+	 * @param EE_Registration_Config $EE_Registration_Config
1211
+	 * @return EE_Registration_Config
1212
+	 * @throws EE_Error
1213
+	 * @throws InvalidArgumentException
1214
+	 * @throws ReflectionException
1215
+	 * @throws InvalidDataTypeException
1216
+	 * @throws InvalidInterfaceException
1217
+	 */
1218
+	public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config)
1219
+	{
1220
+		$prev_email_validation_level = $EE_Registration_Config->email_validation_level;
1221
+		try {
1222
+			$email_validation_settings_form = $this->_email_validation_settings_form();
1223
+			// if not displaying a form, then check for form submission
1224
+			if ($email_validation_settings_form->was_submitted()) {
1225
+				// capture form data
1226
+				$email_validation_settings_form->receive_form_submission();
1227
+				// validate form data
1228
+				if ($email_validation_settings_form->is_valid()) {
1229
+					// grab validated data from form
1230
+					$valid_data = $email_validation_settings_form->valid_data();
1231
+					if (isset($valid_data['email_validation_level'])) {
1232
+						$email_validation_level = $valid_data['email_validation_level'];
1233
+						// now if they want to use international email addresses
1234
+						if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') {
1235
+							// in case we need to reset their email validation level,
1236
+							// make sure that the previous value wasn't already set to one of the i18n options.
1237
+							if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') {
1238
+								// if so, then reset it back to "basic" since that is the only other option that,
1239
+								// despite offering poor validation, supports i18n email addresses
1240
+								$prev_email_validation_level = 'basic';
1241
+							}
1242
+							// confirm our i18n email validation will work on the server
1243
+							if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1244
+								// or reset email validation level to previous value
1245
+								$email_validation_level = $prev_email_validation_level;
1246
+							}
1247
+						}
1248
+						$EE_Registration_Config->email_validation_level = $email_validation_level;
1249
+					} else {
1250
+						EE_Error::add_error(
1251
+							esc_html__(
1252
+								'Invalid or missing Email Validation settings. Please refresh the form and try again.',
1253
+								'event_espresso'
1254
+							),
1255
+							__FILE__,
1256
+							__FUNCTION__,
1257
+							__LINE__
1258
+						);
1259
+					}
1260
+				} else {
1261
+					if ($email_validation_settings_form->submission_error_message() !== '') {
1262
+						EE_Error::add_error(
1263
+							$email_validation_settings_form->submission_error_message(),
1264
+							__FILE__,
1265
+							__FUNCTION__,
1266
+							__LINE__
1267
+						);
1268
+					}
1269
+				}
1270
+			}
1271
+		} catch (EE_Error $e) {
1272
+			$e->get_error();
1273
+		}
1274
+		return $EE_Registration_Config;
1275
+	}
1276
+
1277
+
1278
+	/**
1279
+	 * confirms that the server's PHP version has the PCRE module enabled,
1280
+	 * and that the PCRE version works with our i18n email validation
1281
+	 *
1282
+	 * @param EE_Registration_Config $EE_Registration_Config
1283
+	 * @param string                 $email_validation_level
1284
+	 * @return bool
1285
+	 */
1286
+	private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)
1287
+	{
1288
+		// first check that PCRE is enabled
1289
+		if (! defined('PREG_BAD_UTF8_ERROR')) {
1290
+			EE_Error::add_error(
1291
+				sprintf(
1292
+					esc_html__(
1293
+						'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.',
1294
+						'event_espresso'
1295
+					),
1296
+					'<br />'
1297
+				),
1298
+				__FILE__,
1299
+				__FUNCTION__,
1300
+				__LINE__
1301
+			);
1302
+			return false;
1303
+		} else {
1304
+			// PCRE support is enabled, but let's still
1305
+			// perform a test to see if the server will support it.
1306
+			// but first, save the updated validation level to the config,
1307
+			// so that the validation strategy picks it up.
1308
+			// this will get bumped back down if it doesn't work
1309
+			$EE_Registration_Config->email_validation_level = $email_validation_level;
1310
+			try {
1311
+				$email_validator = new EE_Email_Validation_Strategy();
1312
+				$i18n_email_address = apply_filters(
1313
+					'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address',
1314
+					'jägerjü[email protected]'
1315
+				);
1316
+				$email_validator->validate($i18n_email_address);
1317
+			} catch (Exception $e) {
1318
+				EE_Error::add_error(
1319
+					sprintf(
1320
+						esc_html__(
1321
+							'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s',
1322
+							'event_espresso'
1323
+						),
1324
+						'<br />',
1325
+						'<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>'
1326
+					),
1327
+					__FILE__,
1328
+					__FUNCTION__,
1329
+					__LINE__
1330
+				);
1331
+				return false;
1332
+			}
1333
+		}
1334
+		return true;
1335
+	}
1336 1336
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2667 added lines, -2667 removed lines patch added patch discarded remove patch
@@ -12,2671 +12,2671 @@
 block discarded – undo
12 12
 class Events_Admin_Page extends EE_Admin_Page_CPT
13 13
 {
14 14
 
15
-    /**
16
-     * This will hold the event object for event_details screen.
17
-     *
18
-     * @access protected
19
-     * @var EE_Event $_event
20
-     */
21
-    protected $_event;
22
-
23
-
24
-    /**
25
-     * This will hold the category object for category_details screen.
26
-     *
27
-     * @var stdClass $_category
28
-     */
29
-    protected $_category;
30
-
31
-
32
-    /**
33
-     * This will hold the event model instance
34
-     *
35
-     * @var EEM_Event $_event_model
36
-     */
37
-    protected $_event_model;
38
-
39
-
40
-    /**
41
-     * @var EE_Event
42
-     */
43
-    protected $_cpt_model_obj = false;
44
-
45
-
46
-    /**
47
-     * Initialize page props for this admin page group.
48
-     */
49
-    protected function _init_page_props()
50
-    {
51
-        $this->page_slug = EVENTS_PG_SLUG;
52
-        $this->page_label = EVENTS_LABEL;
53
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
54
-        $this->_admin_base_path = EVENTS_ADMIN;
55
-        $this->_cpt_model_names = array(
56
-            'create_new' => 'EEM_Event',
57
-            'edit'       => 'EEM_Event',
58
-        );
59
-        $this->_cpt_edit_routes = array(
60
-            'espresso_events' => 'edit',
61
-        );
62
-        add_action(
63
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
64
-            array($this, 'verify_event_edit'),
65
-            10,
66
-            2
67
-        );
68
-    }
69
-
70
-
71
-    /**
72
-     * Sets the ajax hooks used for this admin page group.
73
-     */
74
-    protected function _ajax_hooks()
75
-    {
76
-        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
77
-    }
78
-
79
-
80
-    /**
81
-     * Sets the page properties for this admin page group.
82
-     */
83
-    protected function _define_page_props()
84
-    {
85
-        $this->_admin_page_title = EVENTS_LABEL;
86
-        $this->_labels = array(
87
-            'buttons'      => array(
88
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
89
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
90
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
91
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
92
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
93
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
94
-            ),
95
-            'editor_title' => array(
96
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
97
-            ),
98
-            'publishbox'   => array(
99
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
100
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
101
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
102
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
103
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
104
-            ),
105
-        );
106
-    }
107
-
108
-
109
-    /**
110
-     * Sets the page routes property for this admin page group.
111
-     */
112
-    protected function _set_page_routes()
113
-    {
114
-        // load formatter helper
115
-        // load field generator helper
116
-        // is there a evt_id in the request?
117
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
118
-            ? $this->_req_data['EVT_ID']
119
-            : 0;
120
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
121
-        $this->_page_routes = array(
122
-            'default'                       => array(
123
-                'func'       => '_events_overview_list_table',
124
-                'capability' => 'ee_read_events',
125
-            ),
126
-            'create_new'                    => array(
127
-                'func'       => '_create_new_cpt_item',
128
-                'capability' => 'ee_edit_events',
129
-            ),
130
-            'edit'                          => array(
131
-                'func'       => '_edit_cpt_item',
132
-                'capability' => 'ee_edit_event',
133
-                'obj_id'     => $evt_id,
134
-            ),
135
-            'copy_event'                    => array(
136
-                'func'       => '_copy_events',
137
-                'capability' => 'ee_edit_event',
138
-                'obj_id'     => $evt_id,
139
-                'noheader'   => true,
140
-            ),
141
-            'trash_event'                   => array(
142
-                'func'       => '_trash_or_restore_event',
143
-                'args'       => array('event_status' => 'trash'),
144
-                'capability' => 'ee_delete_event',
145
-                'obj_id'     => $evt_id,
146
-                'noheader'   => true,
147
-            ),
148
-            'trash_events'                  => array(
149
-                'func'       => '_trash_or_restore_events',
150
-                'args'       => array('event_status' => 'trash'),
151
-                'capability' => 'ee_delete_events',
152
-                'noheader'   => true,
153
-            ),
154
-            'restore_event'                 => array(
155
-                'func'       => '_trash_or_restore_event',
156
-                'args'       => array('event_status' => 'draft'),
157
-                'capability' => 'ee_delete_event',
158
-                'obj_id'     => $evt_id,
159
-                'noheader'   => true,
160
-            ),
161
-            'restore_events'                => array(
162
-                'func'       => '_trash_or_restore_events',
163
-                'args'       => array('event_status' => 'draft'),
164
-                'capability' => 'ee_delete_events',
165
-                'noheader'   => true,
166
-            ),
167
-            'delete_event'                  => array(
168
-                'func'       => '_delete_event',
169
-                'capability' => 'ee_delete_event',
170
-                'obj_id'     => $evt_id,
171
-                'noheader'   => true,
172
-            ),
173
-            'delete_events'                 => array(
174
-                'func'       => '_delete_events',
175
-                'capability' => 'ee_delete_events',
176
-                'noheader'   => true,
177
-            ),
178
-            'view_report'                   => array(
179
-                'func'      => '_view_report',
180
-                'capablity' => 'ee_edit_events',
181
-            ),
182
-            'default_event_settings'        => array(
183
-                'func'       => '_default_event_settings',
184
-                'capability' => 'manage_options',
185
-            ),
186
-            'update_default_event_settings' => array(
187
-                'func'       => '_update_default_event_settings',
188
-                'capability' => 'manage_options',
189
-                'noheader'   => true,
190
-            ),
191
-            'template_settings'             => array(
192
-                'func'       => '_template_settings',
193
-                'capability' => 'manage_options',
194
-            ),
195
-            // event category tab related
196
-            'add_category'                  => array(
197
-                'func'       => '_category_details',
198
-                'capability' => 'ee_edit_event_category',
199
-                'args'       => array('add'),
200
-            ),
201
-            'edit_category'                 => array(
202
-                'func'       => '_category_details',
203
-                'capability' => 'ee_edit_event_category',
204
-                'args'       => array('edit'),
205
-            ),
206
-            'delete_categories'             => array(
207
-                'func'       => '_delete_categories',
208
-                'capability' => 'ee_delete_event_category',
209
-                'noheader'   => true,
210
-            ),
211
-            'delete_category'               => array(
212
-                'func'       => '_delete_categories',
213
-                'capability' => 'ee_delete_event_category',
214
-                'noheader'   => true,
215
-            ),
216
-            'insert_category'               => array(
217
-                'func'       => '_insert_or_update_category',
218
-                'args'       => array('new_category' => true),
219
-                'capability' => 'ee_edit_event_category',
220
-                'noheader'   => true,
221
-            ),
222
-            'update_category'               => array(
223
-                'func'       => '_insert_or_update_category',
224
-                'args'       => array('new_category' => false),
225
-                'capability' => 'ee_edit_event_category',
226
-                'noheader'   => true,
227
-            ),
228
-            'category_list'                 => array(
229
-                'func'       => '_category_list_table',
230
-                'capability' => 'ee_manage_event_categories',
231
-            ),
232
-        );
233
-    }
234
-
235
-
236
-    /**
237
-     * Set the _page_config property for this admin page group.
238
-     */
239
-    protected function _set_page_config()
240
-    {
241
-        $this->_page_config = array(
242
-            'default'                => array(
243
-                'nav'           => array(
244
-                    'label' => esc_html__('Overview', 'event_espresso'),
245
-                    'order' => 10,
246
-                ),
247
-                'list_table'    => 'Events_Admin_List_Table',
248
-                'help_tabs'     => array(
249
-                    'events_overview_help_tab'                       => array(
250
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
251
-                        'filename' => 'events_overview',
252
-                    ),
253
-                    'events_overview_table_column_headings_help_tab' => array(
254
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
255
-                        'filename' => 'events_overview_table_column_headings',
256
-                    ),
257
-                    'events_overview_filters_help_tab'               => array(
258
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
259
-                        'filename' => 'events_overview_filters',
260
-                    ),
261
-                    'events_overview_view_help_tab'                  => array(
262
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
263
-                        'filename' => 'events_overview_views',
264
-                    ),
265
-                    'events_overview_other_help_tab'                 => array(
266
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
267
-                        'filename' => 'events_overview_other',
268
-                    ),
269
-                ),
270
-                'help_tour'     => array(
271
-                    'Event_Overview_Help_Tour',
272
-                    // 'New_Features_Test_Help_Tour' for testing multiple help tour
273
-                ),
274
-                'qtips'         => array(
275
-                    'EE_Event_List_Table_Tips',
276
-                ),
277
-                'require_nonce' => false,
278
-            ),
279
-            'create_new'             => array(
280
-                'nav'           => array(
281
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
282
-                    'order'      => 5,
283
-                    'persistent' => false,
284
-                ),
285
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
286
-                'help_tabs'     => array(
287
-                    'event_editor_help_tab'                            => array(
288
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
289
-                        'filename' => 'event_editor',
290
-                    ),
291
-                    'event_editor_title_richtexteditor_help_tab'       => array(
292
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
293
-                        'filename' => 'event_editor_title_richtexteditor',
294
-                    ),
295
-                    'event_editor_venue_details_help_tab'              => array(
296
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
297
-                        'filename' => 'event_editor_venue_details',
298
-                    ),
299
-                    'event_editor_event_datetimes_help_tab'            => array(
300
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
301
-                        'filename' => 'event_editor_event_datetimes',
302
-                    ),
303
-                    'event_editor_event_tickets_help_tab'              => array(
304
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
305
-                        'filename' => 'event_editor_event_tickets',
306
-                    ),
307
-                    'event_editor_event_registration_options_help_tab' => array(
308
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
309
-                        'filename' => 'event_editor_event_registration_options',
310
-                    ),
311
-                    'event_editor_tags_categories_help_tab'            => array(
312
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
313
-                        'filename' => 'event_editor_tags_categories',
314
-                    ),
315
-                    'event_editor_questions_registrants_help_tab'      => array(
316
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
317
-                        'filename' => 'event_editor_questions_registrants',
318
-                    ),
319
-                    'event_editor_save_new_event_help_tab'             => array(
320
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
321
-                        'filename' => 'event_editor_save_new_event',
322
-                    ),
323
-                    'event_editor_other_help_tab'                      => array(
324
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
325
-                        'filename' => 'event_editor_other',
326
-                    ),
327
-                ),
328
-                'help_tour'     => array(
329
-                    'Event_Editor_Help_Tour',
330
-                ),
331
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
332
-                'require_nonce' => false,
333
-            ),
334
-            'edit'                   => array(
335
-                'nav'           => array(
336
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
337
-                    'order'      => 5,
338
-                    'persistent' => false,
339
-                    'url'        => isset($this->_req_data['post'])
340
-                        ? EE_Admin_Page::add_query_args_and_nonce(
341
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
342
-                            $this->_current_page_view_url
343
-                        )
344
-                        : $this->_admin_base_url,
345
-                ),
346
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
347
-                'help_tabs'     => array(
348
-                    'event_editor_help_tab'                            => array(
349
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
350
-                        'filename' => 'event_editor',
351
-                    ),
352
-                    'event_editor_title_richtexteditor_help_tab'       => array(
353
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
354
-                        'filename' => 'event_editor_title_richtexteditor',
355
-                    ),
356
-                    'event_editor_venue_details_help_tab'              => array(
357
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
358
-                        'filename' => 'event_editor_venue_details',
359
-                    ),
360
-                    'event_editor_event_datetimes_help_tab'            => array(
361
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
362
-                        'filename' => 'event_editor_event_datetimes',
363
-                    ),
364
-                    'event_editor_event_tickets_help_tab'              => array(
365
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
366
-                        'filename' => 'event_editor_event_tickets',
367
-                    ),
368
-                    'event_editor_event_registration_options_help_tab' => array(
369
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
370
-                        'filename' => 'event_editor_event_registration_options',
371
-                    ),
372
-                    'event_editor_tags_categories_help_tab'            => array(
373
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
374
-                        'filename' => 'event_editor_tags_categories',
375
-                    ),
376
-                    'event_editor_questions_registrants_help_tab'      => array(
377
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
378
-                        'filename' => 'event_editor_questions_registrants',
379
-                    ),
380
-                    'event_editor_save_new_event_help_tab'             => array(
381
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
382
-                        'filename' => 'event_editor_save_new_event',
383
-                    ),
384
-                    'event_editor_other_help_tab'                      => array(
385
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
386
-                        'filename' => 'event_editor_other',
387
-                    ),
388
-                ),
389
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
390
-                'require_nonce' => false,
391
-            ),
392
-            'default_event_settings' => array(
393
-                'nav'           => array(
394
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
395
-                    'order' => 40,
396
-                ),
397
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
398
-                'labels'        => array(
399
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
400
-                ),
401
-                'help_tabs'     => array(
402
-                    'default_settings_help_tab'        => array(
403
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
404
-                        'filename' => 'events_default_settings',
405
-                    ),
406
-                    'default_settings_status_help_tab' => array(
407
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
408
-                        'filename' => 'events_default_settings_status',
409
-                    ),
410
-                    'default_maximum_tickets_help_tab' => array(
411
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
412
-                        'filename' => 'events_default_settings_max_tickets',
413
-                    ),
414
-                ),
415
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
416
-                'require_nonce' => false,
417
-            ),
418
-            // template settings
419
-            'template_settings'      => array(
420
-                'nav'           => array(
421
-                    'label' => esc_html__('Templates', 'event_espresso'),
422
-                    'order' => 30,
423
-                ),
424
-                'metaboxes'     => $this->_default_espresso_metaboxes,
425
-                'help_tabs'     => array(
426
-                    'general_settings_templates_help_tab' => array(
427
-                        'title'    => esc_html__('Templates', 'event_espresso'),
428
-                        'filename' => 'general_settings_templates',
429
-                    ),
430
-                ),
431
-                'help_tour'     => array('Templates_Help_Tour'),
432
-                'require_nonce' => false,
433
-            ),
434
-            // event category stuff
435
-            'add_category'           => array(
436
-                'nav'           => array(
437
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
438
-                    'order'      => 15,
439
-                    'persistent' => false,
440
-                ),
441
-                'help_tabs'     => array(
442
-                    'add_category_help_tab' => array(
443
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
444
-                        'filename' => 'events_add_category',
445
-                    ),
446
-                ),
447
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
448
-                'metaboxes'     => array('_publish_post_box'),
449
-                'require_nonce' => false,
450
-            ),
451
-            'edit_category'          => array(
452
-                'nav'           => array(
453
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
454
-                    'order'      => 15,
455
-                    'persistent' => false,
456
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
457
-                        ? add_query_arg(
458
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
459
-                            $this->_current_page_view_url
460
-                        )
461
-                        : $this->_admin_base_url,
462
-                ),
463
-                'help_tabs'     => array(
464
-                    'edit_category_help_tab' => array(
465
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
466
-                        'filename' => 'events_edit_category',
467
-                    ),
468
-                ),
469
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
470
-                'metaboxes'     => array('_publish_post_box'),
471
-                'require_nonce' => false,
472
-            ),
473
-            'category_list'          => array(
474
-                'nav'           => array(
475
-                    'label' => esc_html__('Categories', 'event_espresso'),
476
-                    'order' => 20,
477
-                ),
478
-                'list_table'    => 'Event_Categories_Admin_List_Table',
479
-                'help_tabs'     => array(
480
-                    'events_categories_help_tab'                       => array(
481
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
482
-                        'filename' => 'events_categories',
483
-                    ),
484
-                    'events_categories_table_column_headings_help_tab' => array(
485
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
486
-                        'filename' => 'events_categories_table_column_headings',
487
-                    ),
488
-                    'events_categories_view_help_tab'                  => array(
489
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
490
-                        'filename' => 'events_categories_views',
491
-                    ),
492
-                    'events_categories_other_help_tab'                 => array(
493
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
494
-                        'filename' => 'events_categories_other',
495
-                    ),
496
-                ),
497
-                'help_tour'     => array(
498
-                    'Event_Categories_Help_Tour',
499
-                ),
500
-                'metaboxes'     => $this->_default_espresso_metaboxes,
501
-                'require_nonce' => false,
502
-            ),
503
-        );
504
-    }
505
-
506
-
507
-    /**
508
-     * Used to register any global screen options if necessary for every route in this admin page group.
509
-     */
510
-    protected function _add_screen_options()
511
-    {
512
-    }
513
-
514
-
515
-    /**
516
-     * Implementing the screen options for the 'default' route.
517
-     */
518
-    protected function _add_screen_options_default()
519
-    {
520
-        $this->_per_page_screen_option();
521
-    }
522
-
523
-
524
-    /**
525
-     * Implementing screen options for the category list route.
526
-     */
527
-    protected function _add_screen_options_category_list()
528
-    {
529
-        $page_title = $this->_admin_page_title;
530
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
531
-        $this->_per_page_screen_option();
532
-        $this->_admin_page_title = $page_title;
533
-    }
534
-
535
-
536
-    /**
537
-     * Used to register any global feature pointers for the admin page group.
538
-     */
539
-    protected function _add_feature_pointers()
540
-    {
541
-    }
542
-
543
-
544
-    /**
545
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
546
-     */
547
-    public function load_scripts_styles()
548
-    {
549
-        wp_register_style(
550
-            'events-admin-css',
551
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
552
-            array(),
553
-            EVENT_ESPRESSO_VERSION
554
-        );
555
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
556
-        wp_enqueue_style('events-admin-css');
557
-        wp_enqueue_style('ee-cat-admin');
558
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
559
-        // registers for all views
560
-        // scripts
561
-        wp_register_script(
562
-            'event_editor_js',
563
-            EVENTS_ASSETS_URL . 'event_editor.js',
564
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
565
-            EVENT_ESPRESSO_VERSION,
566
-            true
567
-        );
568
-    }
569
-
570
-
571
-    /**
572
-     * Enqueuing scripts and styles specific to this view
573
-     */
574
-    public function load_scripts_styles_create_new()
575
-    {
576
-        $this->load_scripts_styles_edit();
577
-    }
578
-
579
-
580
-    /**
581
-     * Enqueuing scripts and styles specific to this view
582
-     */
583
-    public function load_scripts_styles_edit()
584
-    {
585
-        // styles
586
-        wp_enqueue_style('espresso-ui-theme');
587
-        wp_register_style(
588
-            'event-editor-css',
589
-            EVENTS_ASSETS_URL . 'event-editor.css',
590
-            array('ee-admin-css'),
591
-            EVENT_ESPRESSO_VERSION
592
-        );
593
-        wp_enqueue_style('event-editor-css');
594
-        // scripts
595
-        wp_register_script(
596
-            'event-datetime-metabox',
597
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
598
-            array('event_editor_js', 'ee-datepicker'),
599
-            EVENT_ESPRESSO_VERSION
600
-        );
601
-        wp_enqueue_script('event-datetime-metabox');
602
-    }
603
-
604
-
605
-    /**
606
-     * Populating the _views property for the category list table view.
607
-     */
608
-    protected function _set_list_table_views_category_list()
609
-    {
610
-        $this->_views = array(
611
-            'all' => array(
612
-                'slug'        => 'all',
613
-                'label'       => esc_html__('All', 'event_espresso'),
614
-                'count'       => 0,
615
-                'bulk_action' => array(
616
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
617
-                ),
618
-            ),
619
-        );
620
-    }
621
-
622
-
623
-    /**
624
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
625
-     */
626
-    public function admin_init()
627
-    {
628
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
629
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
630
-            'event_espresso'
631
-        );
632
-    }
633
-
634
-
635
-    /**
636
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
637
-     * group.
638
-     */
639
-    public function admin_notices()
640
-    {
641
-    }
642
-
643
-
644
-    /**
645
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
646
-     * this admin page group.
647
-     */
648
-    public function admin_footer_scripts()
649
-    {
650
-    }
651
-
652
-
653
-    /**
654
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
655
-     * warning (via EE_Error::add_error());
656
-     *
657
-     * @param  EE_Event $event Event object
658
-     * @param string    $req_type
659
-     * @return void
660
-     * @throws EE_Error
661
-     * @access public
662
-     */
663
-    public function verify_event_edit($event = null, $req_type = '')
664
-    {
665
-        // don't need to do this when processing
666
-        if (! empty($req_type)) {
667
-            return;
668
-        }
669
-        // no event?
670
-        if (empty($event)) {
671
-            // set event
672
-            $event = $this->_cpt_model_obj;
673
-        }
674
-        // STILL no event?
675
-        if (! $event instanceof EE_Event) {
676
-            return;
677
-        }
678
-        $orig_status = $event->status();
679
-        // first check if event is active.
680
-        if ($orig_status === EEM_Event::cancelled
681
-            || $orig_status === EEM_Event::postponed
682
-            || $event->is_expired()
683
-            || $event->is_inactive()
684
-        ) {
685
-            return;
686
-        }
687
-        // made it here so it IS active... next check that any of the tickets are sold.
688
-        if ($event->is_sold_out(true)) {
689
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
690
-                EE_Error::add_attention(
691
-                    sprintf(
692
-                        esc_html__(
693
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
694
-                            'event_espresso'
695
-                        ),
696
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
697
-                    )
698
-                );
699
-            }
700
-            return;
701
-        } elseif ($orig_status === EEM_Event::sold_out) {
702
-            EE_Error::add_attention(
703
-                sprintf(
704
-                    esc_html__(
705
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
706
-                        'event_espresso'
707
-                    ),
708
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
709
-                )
710
-            );
711
-        }
712
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
713
-        if (! $event->tickets_on_sale()) {
714
-            return;
715
-        }
716
-        // made it here so show warning
717
-        $this->_edit_event_warning();
718
-    }
719
-
720
-
721
-    /**
722
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
723
-     * When needed, hook this into a EE_Error::add_error() notice.
724
-     *
725
-     * @access protected
726
-     * @return void
727
-     */
728
-    protected function _edit_event_warning()
729
-    {
730
-        // we don't want to add warnings during these requests
731
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
732
-            return;
733
-        }
734
-        EE_Error::add_attention(
735
-            sprintf(
736
-                esc_html__(
737
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
738
-                    'event_espresso'
739
-                ),
740
-                '<a class="espresso-help-tab-lnk">',
741
-                '</a>'
742
-            )
743
-        );
744
-    }
745
-
746
-
747
-    /**
748
-     * When a user is creating a new event, notify them if they haven't set their timezone.
749
-     * Otherwise, do the normal logic
750
-     *
751
-     * @return string
752
-     * @throws \EE_Error
753
-     */
754
-    protected function _create_new_cpt_item()
755
-    {
756
-        $has_timezone_string = get_option('timezone_string');
757
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
758
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
759
-            EE_Error::add_attention(
760
-                sprintf(
761
-                    __(
762
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
763
-                        'event_espresso'
764
-                    ),
765
-                    '<br>',
766
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
767
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
768
-                    . '</select>',
769
-                    '<button class="button button-secondary timezone-submit">',
770
-                    '</button><span class="spinner"></span>'
771
-                ),
772
-                __FILE__,
773
-                __FUNCTION__,
774
-                __LINE__
775
-            );
776
-        }
777
-        return parent::_create_new_cpt_item();
778
-    }
779
-
780
-
781
-    /**
782
-     * Sets the _views property for the default route in this admin page group.
783
-     */
784
-    protected function _set_list_table_views_default()
785
-    {
786
-        $this->_views = array(
787
-            'all'   => array(
788
-                'slug'        => 'all',
789
-                'label'       => esc_html__('View All Events', 'event_espresso'),
790
-                'count'       => 0,
791
-                'bulk_action' => array(
792
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
793
-                ),
794
-            ),
795
-            'draft' => array(
796
-                'slug'        => 'draft',
797
-                'label'       => esc_html__('Draft', 'event_espresso'),
798
-                'count'       => 0,
799
-                'bulk_action' => array(
800
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
801
-                ),
802
-            ),
803
-        );
804
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
805
-            $this->_views['trash'] = array(
806
-                'slug'        => 'trash',
807
-                'label'       => esc_html__('Trash', 'event_espresso'),
808
-                'count'       => 0,
809
-                'bulk_action' => array(
810
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
811
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
812
-                ),
813
-            );
814
-        }
815
-    }
816
-
817
-
818
-    /**
819
-     * Provides the legend item array for the default list table view.
820
-     *
821
-     * @return array
822
-     */
823
-    protected function _event_legend_items()
824
-    {
825
-        $items = array(
826
-            'view_details'   => array(
827
-                'class' => 'dashicons dashicons-search',
828
-                'desc'  => esc_html__('View Event', 'event_espresso'),
829
-            ),
830
-            'edit_event'     => array(
831
-                'class' => 'ee-icon ee-icon-calendar-edit',
832
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
833
-            ),
834
-            'view_attendees' => array(
835
-                'class' => 'dashicons dashicons-groups',
836
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
837
-            ),
838
-        );
839
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
840
-        $statuses = array(
841
-            'sold_out_status'  => array(
842
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
843
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
844
-            ),
845
-            'active_status'    => array(
846
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
847
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
848
-            ),
849
-            'upcoming_status'  => array(
850
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
851
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
852
-            ),
853
-            'postponed_status' => array(
854
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
855
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
856
-            ),
857
-            'cancelled_status' => array(
858
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
859
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
860
-            ),
861
-            'expired_status'   => array(
862
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
863
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
864
-            ),
865
-            'inactive_status'  => array(
866
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
867
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
868
-            ),
869
-        );
870
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
871
-        return array_merge($items, $statuses);
872
-    }
873
-
874
-
875
-    /**
876
-     * @return EEM_Event
877
-     */
878
-    private function _event_model()
879
-    {
880
-        if (! $this->_event_model instanceof EEM_Event) {
881
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
882
-        }
883
-        return $this->_event_model;
884
-    }
885
-
886
-
887
-    /**
888
-     * Adds extra buttons to the WP CPT permalink field row.
889
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
890
-     *
891
-     * @param  string $return    the current html
892
-     * @param  int    $id        the post id for the page
893
-     * @param  string $new_title What the title is
894
-     * @param  string $new_slug  what the slug is
895
-     * @return string            The new html string for the permalink area
896
-     */
897
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
898
-    {
899
-        // make sure this is only when editing
900
-        if (! empty($id)) {
901
-            $post = get_post($id);
902
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
903
-                       . esc_html__('Shortcode', 'event_espresso')
904
-                       . '</a> ';
905
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
906
-                       . $post->ID
907
-                       . ']">';
908
-        }
909
-        return $return;
910
-    }
911
-
912
-
913
-    /**
914
-     * _events_overview_list_table
915
-     * This contains the logic for showing the events_overview list
916
-     *
917
-     * @access protected
918
-     * @return void
919
-     * @throws \EE_Error
920
-     */
921
-    protected function _events_overview_list_table()
922
-    {
923
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
924
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
925
-            ? (array) $this->_template_args['after_list_table']
926
-            : array();
927
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
928
-                . EEH_Template::get_button_or_link(
929
-                    get_post_type_archive_link('espresso_events'),
930
-                    esc_html__("View Event Archive Page", "event_espresso"),
931
-                    'button'
932
-                );
933
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
934
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
935
-            'create_new',
936
-            'add',
937
-            array(),
938
-            'add-new-h2'
939
-        );
940
-        $this->display_admin_list_table_page_with_no_sidebar();
941
-    }
942
-
943
-
944
-    /**
945
-     * this allows for extra misc actions in the default WP publish box
946
-     *
947
-     * @return void
948
-     */
949
-    public function extra_misc_actions_publish_box()
950
-    {
951
-        $this->_generate_publish_box_extra_content();
952
-    }
953
-
954
-
955
-    /**
956
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
957
-     * saved.
958
-     * Typically you would use this to save any additional data.
959
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
960
-     * ALSO very important.  When a post transitions from scheduled to published,
961
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
962
-     * other meta saves. So MAKE sure that you handle this accordingly.
963
-     *
964
-     * @access protected
965
-     * @abstract
966
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
967
-     * @param  object $post    The post object of the cpt that was saved.
968
-     * @return void
969
-     * @throws \EE_Error
970
-     */
971
-    protected function _insert_update_cpt_item($post_id, $post)
972
-    {
973
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
974
-            // get out we're not processing an event save.
975
-            return;
976
-        }
977
-        $event_values = array(
978
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
979
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
980
-            'EVT_additional_limit'            => min(
981
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
982
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
983
-            ),
984
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
985
-                ? $this->_req_data['EVT_default_registration_status']
986
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
987
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
988
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
989
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
990
-                ? $this->_req_data['timezone_string'] : null,
991
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
992
-                ? $this->_req_data['externalURL'] : null,
993
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
994
-                ? $this->_req_data['event_phone'] : null,
995
-        );
996
-        // update event
997
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
998
-        // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
999
-        $get_one_where = array(
1000
-            $this->_event_model()->primary_key_name() => $post_id,
1001
-            'OR'                                      => array(
1002
-                'status'   => $post->post_status,
1003
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1004
-                // but the returned object here has a status of "publish", so use the original post status as well
1005
-                'status*1' => $this->_req_data['original_post_status'],
1006
-            ),
1007
-        );
1008
-        $event = $this->_event_model()->get_one(array($get_one_where));
1009
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1010
-        $event_update_callbacks = apply_filters(
1011
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1012
-            array(
1013
-                array($this, '_default_venue_update'),
1014
-                array($this, '_default_tickets_update'),
1015
-            )
1016
-        );
1017
-        $att_success = true;
1018
-        foreach ($event_update_callbacks as $e_callback) {
1019
-            $_success = is_callable($e_callback)
1020
-                ? call_user_func($e_callback, $event, $this->_req_data)
1021
-                : false;
1022
-            // if ANY of these updates fail then we want the appropriate global error message
1023
-            $att_success = ! $att_success ? $att_success : $_success;
1024
-        }
1025
-        // any errors?
1026
-        if ($success && false === $att_success) {
1027
-            EE_Error::add_error(
1028
-                esc_html__(
1029
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1030
-                    'event_espresso'
1031
-                ),
1032
-                __FILE__,
1033
-                __FUNCTION__,
1034
-                __LINE__
1035
-            );
1036
-        } elseif ($success === false) {
1037
-            EE_Error::add_error(
1038
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1039
-                __FILE__,
1040
-                __FUNCTION__,
1041
-                __LINE__
1042
-            );
1043
-        }
1044
-    }
1045
-
1046
-
1047
-    /**
1048
-     * @see parent::restore_item()
1049
-     * @param int $post_id
1050
-     * @param int $revision_id
1051
-     */
1052
-    protected function _restore_cpt_item($post_id, $revision_id)
1053
-    {
1054
-        // copy existing event meta to new post
1055
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1056
-        if ($post_evt instanceof EE_Event) {
1057
-            // meta revision restore
1058
-            $post_evt->restore_revision($revision_id);
1059
-            // related objs restore
1060
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1061
-        }
1062
-    }
1063
-
1064
-
1065
-    /**
1066
-     * Attach the venue to the Event
1067
-     *
1068
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1069
-     * @param  array     $data   The request data from the form
1070
-     * @return bool           Success or fail.
1071
-     */
1072
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1073
-    {
1074
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1075
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1076
-        $rows_affected = null;
1077
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1078
-        // very important.  If we don't have a venue name...
1079
-        // then we'll get out because not necessary to create empty venue
1080
-        if (empty($data['venue_title'])) {
1081
-            return false;
1082
-        }
1083
-        $venue_array = array(
1084
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1085
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1086
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1087
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1088
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1089
-                : null,
1090
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1091
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1092
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1093
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1094
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1095
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1096
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1097
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1098
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1099
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1100
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1101
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1102
-            'status'              => 'publish',
1103
-        );
1104
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1105
-        if (! empty($venue_id)) {
1106
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1107
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1108
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1109
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1110
-            return $rows_affected > 0 ? true : false;
1111
-        } else {
1112
-            // we insert the venue
1113
-            $venue_id = $venue_model->insert($venue_array);
1114
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1115
-            return ! empty($venue_id) ? true : false;
1116
-        }
1117
-        // when we have the ancestor come in it's already been handled by the revision save.
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1123
-     *
1124
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1125
-     * @param  array    $data   The request data from the form
1126
-     * @return array
1127
-     */
1128
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1129
-    {
1130
-        $success = true;
1131
-        $saved_dtt = null;
1132
-        $saved_tickets = array();
1133
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1134
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1135
-            // trim all values to ensure any excess whitespace is removed.
1136
-            $dtt = array_map('trim', $dtt);
1137
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1138
-                : $dtt['DTT_EVT_start'];
1139
-            $datetime_values = array(
1140
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1141
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1142
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1143
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1144
-                'DTT_order'     => $row,
1145
-            );
1146
-            // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1147
-            if (! empty($dtt['DTT_ID'])) {
1148
-                $DTM = EE_Registry::instance()
1149
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1150
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1151
-                $DTM->set_date_format($incoming_date_formats[0]);
1152
-                $DTM->set_time_format($incoming_date_formats[1]);
1153
-                foreach ($datetime_values as $field => $value) {
1154
-                    $DTM->set($field, $value);
1155
-                }
1156
-                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1157
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1158
-            } else {
1159
-                $DTM = EE_Registry::instance()->load_class(
1160
-                    'Datetime',
1161
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1162
-                    false,
1163
-                    false
1164
-                );
1165
-                foreach ($datetime_values as $field => $value) {
1166
-                    $DTM->set($field, $value);
1167
-                }
1168
-            }
1169
-            $DTM->save();
1170
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1171
-            // load DTT helper
1172
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1173
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1174
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1175
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1176
-                $DTT->save();
1177
-            }
1178
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1179
-            $saved_dtt = $DTT;
1180
-            $success = ! $success ? $success : $DTT;
1181
-            // if ANY of these updates fail then we want the appropriate global error message.
1182
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1183
-        }
1184
-        // no dtts get deleted so we don't do any of that logic here.
1185
-        // update tickets next
1186
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1187
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1188
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1189
-            $update_prices = false;
1190
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1191
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1192
-            // trim inputs to ensure any excess whitespace is removed.
1193
-            $tkt = array_map('trim', $tkt);
1194
-            if (empty($tkt['TKT_start_date'])) {
1195
-                // let's use now in the set timezone.
1196
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1197
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1198
-            }
1199
-            if (empty($tkt['TKT_end_date'])) {
1200
-                // use the start date of the first datetime
1201
-                $dtt = $evtobj->first_datetime();
1202
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1203
-                    $incoming_date_formats[0],
1204
-                    $incoming_date_formats[1]
1205
-                );
1206
-            }
1207
-            $TKT_values = array(
1208
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1209
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1210
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1211
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1212
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1213
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1214
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1215
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1216
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1217
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1218
-                'TKT_row'         => $row,
1219
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1220
-                'TKT_price'       => $ticket_price,
1221
-            );
1222
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1223
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1224
-                $TKT_values['TKT_ID'] = 0;
1225
-                $TKT_values['TKT_is_default'] = 0;
1226
-                $TKT_values['TKT_price'] = $ticket_price;
1227
-                $update_prices = true;
1228
-            }
1229
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1230
-            // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1231
-            // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1232
-            if (! empty($tkt['TKT_ID'])) {
1233
-                $TKT = EE_Registry::instance()
1234
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1235
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1236
-                if ($TKT instanceof EE_Ticket) {
1237
-                    $ticket_sold = $TKT->count_related(
1238
-                        'Registration',
1239
-                        array(
1240
-                            array(
1241
-                                'STS_ID' => array(
1242
-                                    'NOT IN',
1243
-                                    array(EEM_Registration::status_id_incomplete),
1244
-                                ),
1245
-                            ),
1246
-                        )
1247
-                    ) > 0 ? true : false;
1248
-                    // let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1249
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1250
-                                      && ! $TKT->get('TKT_deleted');
1251
-                    $TKT->set_date_format($incoming_date_formats[0]);
1252
-                    $TKT->set_time_format($incoming_date_formats[1]);
1253
-                    // set new values
1254
-                    foreach ($TKT_values as $field => $value) {
1255
-                        if ($field == 'TKT_qty') {
1256
-                            $TKT->set_qty($value);
1257
-                        } else {
1258
-                            $TKT->set($field, $value);
1259
-                        }
1260
-                    }
1261
-                    // if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1262
-                    if ($create_new_TKT) {
1263
-                        // archive the old ticket first
1264
-                        $TKT->set('TKT_deleted', 1);
1265
-                        $TKT->save();
1266
-                        // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1267
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1268
-                        // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1269
-                        $TKT = clone $TKT;
1270
-                        $TKT->set('TKT_ID', 0);
1271
-                        $TKT->set('TKT_deleted', 0);
1272
-                        $TKT->set('TKT_price', $ticket_price);
1273
-                        $TKT->set('TKT_sold', 0);
1274
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1275
-                        $update_prices = true;
1276
-                    }
1277
-                    // make sure price is set if it hasn't been already
1278
-                    $TKT->set('TKT_price', $ticket_price);
1279
-                }
1280
-            } else {
1281
-                // no TKT_id so a new TKT
1282
-                $TKT_values['TKT_price'] = $ticket_price;
1283
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1284
-                if ($TKT instanceof EE_Ticket) {
1285
-                    // need to reset values to properly account for the date formats
1286
-                    $TKT->set_date_format($incoming_date_formats[0]);
1287
-                    $TKT->set_time_format($incoming_date_formats[1]);
1288
-                    $TKT->set_timezone($evtobj->get_timezone());
1289
-                    // set new values
1290
-                    foreach ($TKT_values as $field => $value) {
1291
-                        if ($field == 'TKT_qty') {
1292
-                            $TKT->set_qty($value);
1293
-                        } else {
1294
-                            $TKT->set($field, $value);
1295
-                        }
1296
-                    }
1297
-                    $update_prices = true;
1298
-                }
1299
-            }
1300
-            // cap ticket qty by datetime reg limits
1301
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1302
-            // update ticket.
1303
-            $TKT->save();
1304
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1305
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1306
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1307
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1308
-                $TKT->save();
1309
-            }
1310
-            // initially let's add the ticket to the dtt
1311
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1312
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1313
-            // add prices to ticket
1314
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1315
-        }
1316
-        // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1317
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1318
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1319
-        foreach ($tickets_removed as $id) {
1320
-            $id = absint($id);
1321
-            // get the ticket for this id
1322
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1323
-            // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1324
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1325
-            foreach ($dtts as $dtt) {
1326
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1327
-            }
1328
-            // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1329
-            $tkt_to_remove->delete_related_permanently('Price');
1330
-            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1331
-            $tkt_to_remove->delete_permanently();
1332
-        }
1333
-        return array($saved_dtt, $saved_tickets);
1334
-    }
1335
-
1336
-
1337
-    /**
1338
-     * This attaches a list of given prices to a ticket.
1339
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1340
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1341
-     * price info and prices are automatically "archived" via the ticket.
1342
-     *
1343
-     * @access  private
1344
-     * @param array     $prices     Array of prices from the form.
1345
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1346
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1347
-     * @return  void
1348
-     */
1349
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1350
-    {
1351
-        foreach ($prices as $row => $prc) {
1352
-            $PRC_values = array(
1353
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1354
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1355
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1356
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1357
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1358
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1359
-                'PRC_order'      => $row,
1360
-            );
1361
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1362
-                $PRC_values['PRC_ID'] = 0;
1363
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1364
-            } else {
1365
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1366
-                // update this price with new values
1367
-                foreach ($PRC_values as $field => $newprc) {
1368
-                    $PRC->set($field, $newprc);
1369
-                }
1370
-                $PRC->save();
1371
-            }
1372
-            $ticket->_add_relation_to($PRC, 'Price');
1373
-        }
1374
-    }
1375
-
1376
-
1377
-    /**
1378
-     * Add in our autosave ajax handlers
1379
-     *
1380
-     */
1381
-    protected function _ee_autosave_create_new()
1382
-    {
1383
-    }
1384
-
1385
-
1386
-    /**
1387
-     * More autosave handlers.
1388
-     */
1389
-    protected function _ee_autosave_edit()
1390
-    {
1391
-        return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1392
-    }
1393
-
1394
-
1395
-    /**
1396
-     *    _generate_publish_box_extra_content
1397
-     */
1398
-    private function _generate_publish_box_extra_content()
1399
-    {
1400
-        // load formatter helper
1401
-        // args for getting related registrations
1402
-        $approved_query_args = array(
1403
-            array(
1404
-                'REG_deleted' => 0,
1405
-                'STS_ID'      => EEM_Registration::status_id_approved,
1406
-            ),
1407
-        );
1408
-        $not_approved_query_args = array(
1409
-            array(
1410
-                'REG_deleted' => 0,
1411
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1412
-            ),
1413
-        );
1414
-        $pending_payment_query_args = array(
1415
-            array(
1416
-                'REG_deleted' => 0,
1417
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1418
-            ),
1419
-        );
1420
-        // publish box
1421
-        $publish_box_extra_args = array(
1422
-            'view_approved_reg_url'        => add_query_arg(
1423
-                array(
1424
-                    'action'      => 'default',
1425
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1426
-                    '_reg_status' => EEM_Registration::status_id_approved,
1427
-                ),
1428
-                REG_ADMIN_URL
1429
-            ),
1430
-            'view_not_approved_reg_url'    => add_query_arg(
1431
-                array(
1432
-                    'action'      => 'default',
1433
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1434
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1435
-                ),
1436
-                REG_ADMIN_URL
1437
-            ),
1438
-            'view_pending_payment_reg_url' => add_query_arg(
1439
-                array(
1440
-                    'action'      => 'default',
1441
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1442
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1443
-                ),
1444
-                REG_ADMIN_URL
1445
-            ),
1446
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1447
-                'Registration',
1448
-                $approved_query_args
1449
-            ),
1450
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1451
-                'Registration',
1452
-                $not_approved_query_args
1453
-            ),
1454
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1455
-                'Registration',
1456
-                $pending_payment_query_args
1457
-            ),
1458
-            'misc_pub_section_class'       => apply_filters(
1459
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1460
-                'misc-pub-section'
1461
-            ),
1462
-        );
1463
-        ob_start();
1464
-        do_action(
1465
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1466
-            $this->_cpt_model_obj
1467
-        );
1468
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1469
-        // load template
1470
-        EEH_Template::display_template(
1471
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1472
-            $publish_box_extra_args
1473
-        );
1474
-    }
1475
-
1476
-
1477
-    /**
1478
-     * @return EE_Event
1479
-     */
1480
-    public function get_event_object()
1481
-    {
1482
-        return $this->_cpt_model_obj;
1483
-    }
1484
-
1485
-
1486
-
1487
-
1488
-    /** METABOXES * */
1489
-    /**
1490
-     * _register_event_editor_meta_boxes
1491
-     * add all metaboxes related to the event_editor
1492
-     *
1493
-     * @return void
1494
-     */
1495
-    protected function _register_event_editor_meta_boxes()
1496
-    {
1497
-        $this->verify_cpt_object();
1498
-        add_meta_box(
1499
-            'espresso_event_editor_tickets',
1500
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1501
-            array($this, 'ticket_metabox'),
1502
-            $this->page_slug,
1503
-            'normal',
1504
-            'high'
1505
-        );
1506
-        add_meta_box(
1507
-            'espresso_event_editor_event_options',
1508
-            esc_html__('Event Registration Options', 'event_espresso'),
1509
-            array($this, 'registration_options_meta_box'),
1510
-            $this->page_slug,
1511
-            'side',
1512
-            'default'
1513
-        );
1514
-        // NOTE: if you're looking for other metaboxes in here,
1515
-        // where a metabox has a related management page in the admin
1516
-        // you will find it setup in the related management page's "_Hooks" file.
1517
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1518
-    }
1519
-
1520
-
1521
-    /**
1522
-     * @throws DomainException
1523
-     * @throws EE_Error
1524
-     */
1525
-    public function ticket_metabox()
1526
-    {
1527
-        $existing_datetime_ids = $existing_ticket_ids = array();
1528
-        // defaults for template args
1529
-        $template_args = array(
1530
-            'existing_datetime_ids'    => '',
1531
-            'event_datetime_help_link' => '',
1532
-            'ticket_options_help_link' => '',
1533
-            'time'                     => null,
1534
-            'ticket_rows'              => '',
1535
-            'existing_ticket_ids'      => '',
1536
-            'total_ticket_rows'        => 1,
1537
-            'ticket_js_structure'      => '',
1538
-            'trash_icon'               => 'ee-lock-icon',
1539
-            'disabled'                 => '',
1540
-        );
1541
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1542
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1543
-        /**
1544
-         * 1. Start with retrieving Datetimes
1545
-         * 2. Fore each datetime get related tickets
1546
-         * 3. For each ticket get related prices
1547
-         */
1548
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1549
-        /** @type EE_Datetime $first_datetime */
1550
-        $first_datetime = reset($times);
1551
-        // do we get related tickets?
1552
-        if ($first_datetime instanceof EE_Datetime
1553
-            && $first_datetime->ID() !== 0
1554
-        ) {
1555
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1556
-            $template_args['time'] = $first_datetime;
1557
-            $related_tickets = $first_datetime->tickets(
1558
-                array(
1559
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1560
-                    'default_where_conditions' => 'none',
1561
-                )
1562
-            );
1563
-            if (! empty($related_tickets)) {
1564
-                $template_args['total_ticket_rows'] = count($related_tickets);
1565
-                $row = 0;
1566
-                foreach ($related_tickets as $ticket) {
1567
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1568
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1569
-                    $row++;
1570
-                }
1571
-            } else {
1572
-                $template_args['total_ticket_rows'] = 1;
1573
-                /** @type EE_Ticket $ticket */
1574
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1575
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1576
-            }
1577
-        } else {
1578
-            $template_args['time'] = $times[0];
1579
-            /** @type EE_Ticket $ticket */
1580
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1581
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1582
-            // NOTE: we're just sending the first default row
1583
-            // (decaf can't manage default tickets so this should be sufficient);
1584
-        }
1585
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1586
-            'event_editor_event_datetimes_help_tab'
1587
-        );
1588
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1589
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1590
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1591
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1592
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1593
-            true
1594
-        );
1595
-        $template = apply_filters(
1596
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1597
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1598
-        );
1599
-        EEH_Template::display_template($template, $template_args);
1600
-    }
1601
-
1602
-
1603
-    /**
1604
-     * Setup an individual ticket form for the decaf event editor page
1605
-     *
1606
-     * @access private
1607
-     * @param  EE_Ticket $ticket   the ticket object
1608
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1609
-     * @param int        $row
1610
-     * @return string generated html for the ticket row.
1611
-     */
1612
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1613
-    {
1614
-        $template_args = array(
1615
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1616
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1617
-                : '',
1618
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1619
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1620
-            'TKT_name'            => $ticket->get('TKT_name'),
1621
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1622
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1623
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1624
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1625
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1626
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1627
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1628
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1629
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1630
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1631
-                : ' disabled=disabled',
1632
-        );
1633
-        $price = $ticket->ID() !== 0
1634
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1635
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1636
-        $price_args = array(
1637
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1638
-            'PRC_amount'            => $price->get('PRC_amount'),
1639
-            'PRT_ID'                => $price->get('PRT_ID'),
1640
-            'PRC_ID'                => $price->get('PRC_ID'),
1641
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1642
-        );
1643
-        // make sure we have default start and end dates if skeleton
1644
-        // handle rows that should NOT be empty
1645
-        if (empty($template_args['TKT_start_date'])) {
1646
-            // if empty then the start date will be now.
1647
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1648
-        }
1649
-        if (empty($template_args['TKT_end_date'])) {
1650
-            // get the earliest datetime (if present);
1651
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1652
-                ? $this->_cpt_model_obj->get_first_related(
1653
-                    'Datetime',
1654
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1655
-                )
1656
-                : null;
1657
-            if (! empty($earliest_dtt)) {
1658
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1659
-            } else {
1660
-                $template_args['TKT_end_date'] = date(
1661
-                    'Y-m-d h:i a',
1662
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1663
-                );
1664
-            }
1665
-        }
1666
-        $template_args = array_merge($template_args, $price_args);
1667
-        $template = apply_filters(
1668
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1669
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1670
-            $ticket
1671
-        );
1672
-        return EEH_Template::display_template($template, $template_args, true);
1673
-    }
1674
-
1675
-
1676
-    /**
1677
-     * @throws DomainException
1678
-     */
1679
-    public function registration_options_meta_box()
1680
-    {
1681
-        $yes_no_values = array(
1682
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1683
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1684
-        );
1685
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1686
-            array(
1687
-                EEM_Registration::status_id_cancelled,
1688
-                EEM_Registration::status_id_declined,
1689
-                EEM_Registration::status_id_incomplete,
1690
-            ),
1691
-            true
1692
-        );
1693
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1694
-        $template_args['_event'] = $this->_cpt_model_obj;
1695
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1696
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1697
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1698
-            'default_reg_status',
1699
-            $default_reg_status_values,
1700
-            $this->_cpt_model_obj->default_registration_status()
1701
-        );
1702
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1703
-            'display_desc',
1704
-            $yes_no_values,
1705
-            $this->_cpt_model_obj->display_description()
1706
-        );
1707
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1708
-            'display_ticket_selector',
1709
-            $yes_no_values,
1710
-            $this->_cpt_model_obj->display_ticket_selector(),
1711
-            '',
1712
-            '',
1713
-            false
1714
-        );
1715
-        $template_args['additional_registration_options'] = apply_filters(
1716
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1717
-            '',
1718
-            $template_args,
1719
-            $yes_no_values,
1720
-            $default_reg_status_values
1721
-        );
1722
-        EEH_Template::display_template(
1723
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1724
-            $template_args
1725
-        );
1726
-    }
1727
-
1728
-
1729
-    /**
1730
-     * _get_events()
1731
-     * This method simply returns all the events (for the given _view and paging)
1732
-     *
1733
-     * @access public
1734
-     * @param int  $per_page     count of items per page (20 default);
1735
-     * @param int  $current_page what is the current page being viewed.
1736
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1737
-     *                           If FALSE then we return an array of event objects
1738
-     *                           that match the given _view and paging parameters.
1739
-     * @return array an array of event objects.
1740
-     */
1741
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1742
-    {
1743
-        $EEME = $this->_event_model();
1744
-        $offset = ($current_page - 1) * $per_page;
1745
-        $limit = $count ? null : $offset . ',' . $per_page;
1746
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1747
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1748
-        if (isset($this->_req_data['month_range'])) {
1749
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1750
-            // simulate the FIRST day of the month, that fixes issues for months like February
1751
-            // where PHP doesn't know what to assume for date.
1752
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1753
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1754
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1755
-        }
1756
-        $where = array();
1757
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1758
-        // determine what post_status our condition will have for the query.
1759
-        switch ($status) {
1760
-            case 'month':
1761
-            case 'today':
1762
-            case null:
1763
-            case 'all':
1764
-                break;
1765
-            case 'draft':
1766
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1767
-                break;
1768
-            default:
1769
-                $where['status'] = $status;
1770
-        }
1771
-        // categories?
1772
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1773
-            ? $this->_req_data['EVT_CAT'] : null;
1774
-        if (! empty($category)) {
1775
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1776
-            $where['Term_Taxonomy.term_id'] = $category;
1777
-        }
1778
-        // date where conditions
1779
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1780
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1781
-            $DateTime = new DateTime(
1782
-                $year_r . '-' . $month_r . '-01 00:00:00',
1783
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1784
-            );
1785
-            $start = $DateTime->format(implode(' ', $start_formats));
1786
-            $end = $DateTime->setDate(
1787
-                $year_r,
1788
-                $month_r,
1789
-                $DateTime
1790
-                    ->format('t')
1791
-            )->setTime(23, 59, 59)
1792
-                            ->format(implode(' ', $start_formats));
1793
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1794
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1795
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1796
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1797
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1798
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1799
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1800
-            $now = date('Y-m-01');
1801
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1802
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1803
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1804
-                            ->setTime(23, 59, 59)
1805
-                            ->format(implode(' ', $start_formats));
1806
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1807
-        }
1808
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1809
-            $where['EVT_wp_user'] = get_current_user_id();
1810
-        } else {
1811
-            if (! isset($where['status'])) {
1812
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1813
-                    $where['OR'] = array(
1814
-                        'status*restrict_private' => array('!=', 'private'),
1815
-                        'AND'                     => array(
1816
-                            'status*inclusive' => array('=', 'private'),
1817
-                            'EVT_wp_user'      => get_current_user_id(),
1818
-                        ),
1819
-                    );
1820
-                }
1821
-            }
1822
-        }
1823
-        if (isset($this->_req_data['EVT_wp_user'])) {
1824
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1825
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1826
-            ) {
1827
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1828
-            }
1829
-        }
1830
-        // search query handling
1831
-        if (isset($this->_req_data['s'])) {
1832
-            $search_string = '%' . $this->_req_data['s'] . '%';
1833
-            $where['OR'] = array(
1834
-                'EVT_name'       => array('LIKE', $search_string),
1835
-                'EVT_desc'       => array('LIKE', $search_string),
1836
-                'EVT_short_desc' => array('LIKE', $search_string),
1837
-            );
1838
-        }
1839
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1840
-        $query_params = apply_filters(
1841
-            'FHEE__Events_Admin_Page__get_events__query_params',
1842
-            array(
1843
-                $where,
1844
-                'limit'    => $limit,
1845
-                'order_by' => $orderby,
1846
-                'order'    => $order,
1847
-                'group_by' => 'EVT_ID',
1848
-            ),
1849
-            $this->_req_data
1850
-        );
1851
-        // let's first check if we have special requests coming in.
1852
-        if (isset($this->_req_data['active_status'])) {
1853
-            switch ($this->_req_data['active_status']) {
1854
-                case 'upcoming':
1855
-                    return $EEME->get_upcoming_events($query_params, $count);
1856
-                    break;
1857
-                case 'expired':
1858
-                    return $EEME->get_expired_events($query_params, $count);
1859
-                    break;
1860
-                case 'active':
1861
-                    return $EEME->get_active_events($query_params, $count);
1862
-                    break;
1863
-                case 'inactive':
1864
-                    return $EEME->get_inactive_events($query_params, $count);
1865
-                    break;
1866
-            }
1867
-        }
1868
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1869
-        return $events;
1870
-    }
1871
-
1872
-
1873
-    /**
1874
-     * handling for WordPress CPT actions (trash, restore, delete)
1875
-     *
1876
-     * @param string $post_id
1877
-     */
1878
-    public function trash_cpt_item($post_id)
1879
-    {
1880
-        $this->_req_data['EVT_ID'] = $post_id;
1881
-        $this->_trash_or_restore_event('trash', false);
1882
-    }
1883
-
1884
-
1885
-    /**
1886
-     * @param string $post_id
1887
-     */
1888
-    public function restore_cpt_item($post_id)
1889
-    {
1890
-        $this->_req_data['EVT_ID'] = $post_id;
1891
-        $this->_trash_or_restore_event('draft', false);
1892
-    }
1893
-
1894
-
1895
-    /**
1896
-     * @param string $post_id
1897
-     */
1898
-    public function delete_cpt_item($post_id)
1899
-    {
1900
-        $this->_req_data['EVT_ID'] = $post_id;
1901
-        $this->_delete_event(false);
1902
-    }
1903
-
1904
-
1905
-    /**
1906
-     * _trash_or_restore_event
1907
-     *
1908
-     * @access protected
1909
-     * @param  string $event_status
1910
-     * @param bool    $redirect_after
1911
-     */
1912
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1913
-    {
1914
-        // determine the event id and set to array.
1915
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1916
-        // loop thru events
1917
-        if ($EVT_ID) {
1918
-            // clean status
1919
-            $event_status = sanitize_key($event_status);
1920
-            // grab status
1921
-            if (! empty($event_status)) {
1922
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1923
-            } else {
1924
-                $success = false;
1925
-                $msg = esc_html__(
1926
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1927
-                    'event_espresso'
1928
-                );
1929
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1930
-            }
1931
-        } else {
1932
-            $success = false;
1933
-            $msg = esc_html__(
1934
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1935
-                'event_espresso'
1936
-            );
1937
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1938
-        }
1939
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1940
-        if ($redirect_after) {
1941
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1942
-        }
1943
-    }
1944
-
1945
-
1946
-    /**
1947
-     * _trash_or_restore_events
1948
-     *
1949
-     * @access protected
1950
-     * @param  string $event_status
1951
-     * @return void
1952
-     */
1953
-    protected function _trash_or_restore_events($event_status = 'trash')
1954
-    {
1955
-        // clean status
1956
-        $event_status = sanitize_key($event_status);
1957
-        // grab status
1958
-        if (! empty($event_status)) {
1959
-            $success = true;
1960
-            // determine the event id and set to array.
1961
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1962
-            // loop thru events
1963
-            foreach ($EVT_IDs as $EVT_ID) {
1964
-                if ($EVT_ID = absint($EVT_ID)) {
1965
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1966
-                    $success = $results !== false ? $success : false;
1967
-                } else {
1968
-                    $msg = sprintf(
1969
-                        esc_html__(
1970
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1971
-                            'event_espresso'
1972
-                        ),
1973
-                        $EVT_ID
1974
-                    );
1975
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1976
-                    $success = false;
1977
-                }
1978
-            }
1979
-        } else {
1980
-            $success = false;
1981
-            $msg = esc_html__(
1982
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1983
-                'event_espresso'
1984
-            );
1985
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1986
-        }
1987
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1988
-        $success = $success ? 2 : false;
1989
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1990
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1991
-    }
1992
-
1993
-
1994
-    /**
1995
-     * _trash_or_restore_events
1996
-     *
1997
-     * @access  private
1998
-     * @param  int    $EVT_ID
1999
-     * @param  string $event_status
2000
-     * @return bool
2001
-     */
2002
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2003
-    {
2004
-        // grab event id
2005
-        if (! $EVT_ID) {
2006
-            $msg = esc_html__(
2007
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2008
-                'event_espresso'
2009
-            );
2010
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2011
-            return false;
2012
-        }
2013
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2014
-        // clean status
2015
-        $event_status = sanitize_key($event_status);
2016
-        // grab status
2017
-        if (empty($event_status)) {
2018
-            $msg = esc_html__(
2019
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2020
-                'event_espresso'
2021
-            );
2022
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2023
-            return false;
2024
-        }
2025
-        // was event trashed or restored ?
2026
-        switch ($event_status) {
2027
-            case 'draft':
2028
-                $action = 'restored from the trash';
2029
-                $hook = 'AHEE_event_restored_from_trash';
2030
-                break;
2031
-            case 'trash':
2032
-                $action = 'moved to the trash';
2033
-                $hook = 'AHEE_event_moved_to_trash';
2034
-                break;
2035
-            default:
2036
-                $action = 'updated';
2037
-                $hook = false;
2038
-        }
2039
-        // use class to change status
2040
-        $this->_cpt_model_obj->set_status($event_status);
2041
-        $success = $this->_cpt_model_obj->save();
2042
-        if ($success === false) {
2043
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2044
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2045
-            return false;
2046
-        }
2047
-        if ($hook) {
2048
-            do_action($hook);
2049
-        }
2050
-        return true;
2051
-    }
2052
-
2053
-
2054
-    /**
2055
-     * _delete_event
2056
-     *
2057
-     * @access protected
2058
-     * @param bool $redirect_after
2059
-     */
2060
-    protected function _delete_event($redirect_after = true)
2061
-    {
2062
-        // determine the event id and set to array.
2063
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2064
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2065
-        // loop thru events
2066
-        if ($EVT_ID) {
2067
-            $success = $this->_permanently_delete_event($EVT_ID);
2068
-            // get list of events with no prices
2069
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2070
-            // remove this event from the list of events with no prices
2071
-            if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2072
-                unset($espresso_no_ticket_prices[ $EVT_ID ]);
2073
-            }
2074
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2075
-        } else {
2076
-            $success = false;
2077
-            $msg = esc_html__(
2078
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2079
-                'event_espresso'
2080
-            );
2081
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2082
-        }
2083
-        if ($redirect_after) {
2084
-            $this->_redirect_after_action(
2085
-                $success,
2086
-                'Event',
2087
-                'deleted',
2088
-                array('action' => 'default', 'status' => 'trash')
2089
-            );
2090
-        }
2091
-    }
2092
-
2093
-
2094
-    /**
2095
-     * _delete_events
2096
-     *
2097
-     * @access protected
2098
-     * @return void
2099
-     */
2100
-    protected function _delete_events()
2101
-    {
2102
-        $success = true;
2103
-        // get list of events with no prices
2104
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2105
-        // determine the event id and set to array.
2106
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2107
-        // loop thru events
2108
-        foreach ($EVT_IDs as $EVT_ID) {
2109
-            $EVT_ID = absint($EVT_ID);
2110
-            if ($EVT_ID) {
2111
-                $results = $this->_permanently_delete_event($EVT_ID);
2112
-                $success = $results !== false ? $success : false;
2113
-                // remove this event from the list of events with no prices
2114
-                unset($espresso_no_ticket_prices[ $EVT_ID ]);
2115
-            } else {
2116
-                $success = false;
2117
-                $msg = esc_html__(
2118
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2119
-                    'event_espresso'
2120
-                );
2121
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2122
-            }
2123
-        }
2124
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2125
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2126
-        $success = $success ? 2 : false;
2127
-        $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2128
-    }
2129
-
2130
-
2131
-    /**
2132
-     * _permanently_delete_event
2133
-     *
2134
-     * @access  private
2135
-     * @param  int $EVT_ID
2136
-     * @return bool
2137
-     */
2138
-    private function _permanently_delete_event($EVT_ID = 0)
2139
-    {
2140
-        // grab event id
2141
-        if (! $EVT_ID) {
2142
-            $msg = esc_html__(
2143
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2144
-                'event_espresso'
2145
-            );
2146
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2147
-            return false;
2148
-        }
2149
-        if (! $this->_cpt_model_obj instanceof EE_Event
2150
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2151
-        ) {
2152
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2153
-        }
2154
-        if (! $this->_cpt_model_obj instanceof EE_Event) {
2155
-            return false;
2156
-        }
2157
-        // need to delete related tickets and prices first.
2158
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2159
-        foreach ($datetimes as $datetime) {
2160
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2161
-            $tickets = $datetime->get_many_related('Ticket');
2162
-            foreach ($tickets as $ticket) {
2163
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2164
-                $ticket->delete_related_permanently('Price');
2165
-                $ticket->delete_permanently();
2166
-            }
2167
-            $datetime->delete();
2168
-        }
2169
-        // what about related venues or terms?
2170
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2171
-        foreach ($venues as $venue) {
2172
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2173
-        }
2174
-        // any attached question groups?
2175
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2176
-        if (! empty($question_groups)) {
2177
-            foreach ($question_groups as $question_group) {
2178
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2179
-            }
2180
-        }
2181
-        // Message Template Groups
2182
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2183
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2184
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2185
-        foreach ($term_taxonomies as $term_taxonomy) {
2186
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2187
-        }
2188
-        $success = $this->_cpt_model_obj->delete_permanently();
2189
-        // did it all go as planned ?
2190
-        if ($success) {
2191
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2192
-            EE_Error::add_success($msg);
2193
-        } else {
2194
-            $msg = sprintf(
2195
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2196
-                $EVT_ID
2197
-            );
2198
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2199
-            return false;
2200
-        }
2201
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2202
-        return true;
2203
-    }
2204
-
2205
-
2206
-    /**
2207
-     * get total number of events
2208
-     *
2209
-     * @access public
2210
-     * @return int
2211
-     */
2212
-    public function total_events()
2213
-    {
2214
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2215
-        return $count;
2216
-    }
2217
-
2218
-
2219
-    /**
2220
-     * get total number of draft events
2221
-     *
2222
-     * @access public
2223
-     * @return int
2224
-     */
2225
-    public function total_events_draft()
2226
-    {
2227
-        $where = array(
2228
-            'status' => array('IN', array('draft', 'auto-draft')),
2229
-        );
2230
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2231
-        return $count;
2232
-    }
2233
-
2234
-
2235
-    /**
2236
-     * get total number of trashed events
2237
-     *
2238
-     * @access public
2239
-     * @return int
2240
-     */
2241
-    public function total_trashed_events()
2242
-    {
2243
-        $where = array(
2244
-            'status' => 'trash',
2245
-        );
2246
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2247
-        return $count;
2248
-    }
2249
-
2250
-
2251
-    /**
2252
-     *    _default_event_settings
2253
-     *    This generates the Default Settings Tab
2254
-     *
2255
-     * @return void
2256
-     * @throws EE_Error
2257
-     */
2258
-    protected function _default_event_settings()
2259
-    {
2260
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2261
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2262
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2263
-        $this->display_admin_page_with_sidebar();
2264
-    }
2265
-
2266
-
2267
-    /**
2268
-     * Return the form for event settings.
2269
-     *
2270
-     * @return EE_Form_Section_Proper
2271
-     * @throws EE_Error
2272
-     */
2273
-    protected function _default_event_settings_form()
2274
-    {
2275
-        $registration_config = EE_Registry::instance()->CFG->registration;
2276
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2277
-            // exclude
2278
-            array(
2279
-                EEM_Registration::status_id_cancelled,
2280
-                EEM_Registration::status_id_declined,
2281
-                EEM_Registration::status_id_incomplete,
2282
-                EEM_Registration::status_id_wait_list,
2283
-            ),
2284
-            true
2285
-        );
2286
-        return new EE_Form_Section_Proper(
2287
-            array(
2288
-                'name'            => 'update_default_event_settings',
2289
-                'html_id'         => 'update_default_event_settings',
2290
-                'html_class'      => 'form-table',
2291
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2292
-                'subsections'     => apply_filters(
2293
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2294
-                    array(
2295
-                        'default_reg_status'  => new EE_Select_Input(
2296
-                            $registration_stati_for_selection,
2297
-                            array(
2298
-                                'default'         => isset($registration_config->default_STS_ID)
2299
-                                                     && array_key_exists(
2300
-                                                         $registration_config->default_STS_ID,
2301
-                                                         $registration_stati_for_selection
2302
-                                                     )
2303
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2304
-                                    : EEM_Registration::status_id_pending_payment,
2305
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2306
-                                                     . EEH_Template::get_help_tab_link(
2307
-                                                         'default_settings_status_help_tab'
2308
-                                                     ),
2309
-                                'html_help_text'  => esc_html__(
2310
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2311
-                                    'event_espresso'
2312
-                                ),
2313
-                            )
2314
-                        ),
2315
-                        'default_max_tickets' => new EE_Integer_Input(
2316
-                            array(
2317
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2318
-                                    ? $registration_config->default_maximum_number_of_tickets
2319
-                                    : EEM_Event::get_default_additional_limit(),
2320
-                                'html_label_text' => esc_html__(
2321
-                                    'Default Maximum Tickets Allowed Per Order:',
2322
-                                    'event_espresso'
2323
-                                )
2324
-                                                     . EEH_Template::get_help_tab_link(
2325
-                                                         'default_maximum_tickets_help_tab"'
2326
-                                                     ),
2327
-                                'html_help_text'  => esc_html__(
2328
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2329
-                                    'event_espresso'
2330
-                                ),
2331
-                            )
2332
-                        ),
2333
-                    )
2334
-                ),
2335
-            )
2336
-        );
2337
-    }
2338
-
2339
-
2340
-    /**
2341
-     * _update_default_event_settings
2342
-     *
2343
-     * @access protected
2344
-     * @return void
2345
-     * @throws EE_Error
2346
-     */
2347
-    protected function _update_default_event_settings()
2348
-    {
2349
-        $registration_config = EE_Registry::instance()->CFG->registration;
2350
-        $form = $this->_default_event_settings_form();
2351
-        if ($form->was_submitted()) {
2352
-            $form->receive_form_submission();
2353
-            if ($form->is_valid()) {
2354
-                $valid_data = $form->valid_data();
2355
-                if (isset($valid_data['default_reg_status'])) {
2356
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2357
-                }
2358
-                if (isset($valid_data['default_max_tickets'])) {
2359
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2360
-                }
2361
-                // update because data was valid!
2362
-                EE_Registry::instance()->CFG->update_espresso_config();
2363
-                EE_Error::overwrite_success();
2364
-                EE_Error::add_success(
2365
-                    __('Default Event Settings were updated', 'event_espresso')
2366
-                );
2367
-            }
2368
-        }
2369
-        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2370
-    }
2371
-
2372
-
2373
-    /*************        Templates        *************/
2374
-    protected function _template_settings()
2375
-    {
2376
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2377
-        $this->_template_args['preview_img'] = '<img src="'
2378
-                                               . EVENTS_ASSETS_URL
2379
-                                               . DS
2380
-                                               . 'images'
2381
-                                               . DS
2382
-                                               . 'caffeinated_template_features.jpg" alt="'
2383
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2384
-                                               . '" />';
2385
-        $this->_template_args['preview_text'] = '<strong>'
2386
-                                                . esc_html__(
2387
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2388
-                                                    'event_espresso'
2389
-                                                ) . '</strong>';
2390
-        $this->display_admin_caf_preview_page('template_settings_tab');
2391
-    }
2392
-
2393
-
2394
-    /** Event Category Stuff **/
2395
-    /**
2396
-     * set the _category property with the category object for the loaded page.
2397
-     *
2398
-     * @access private
2399
-     * @return void
2400
-     */
2401
-    private function _set_category_object()
2402
-    {
2403
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2404
-            return;
2405
-        } //already have the category object so get out.
2406
-        // set default category object
2407
-        $this->_set_empty_category_object();
2408
-        // only set if we've got an id
2409
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2410
-            return;
2411
-        }
2412
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2413
-        $term = get_term($category_id, 'espresso_event_categories');
2414
-        if (! empty($term)) {
2415
-            $this->_category->category_name = $term->name;
2416
-            $this->_category->category_identifier = $term->slug;
2417
-            $this->_category->category_desc = $term->description;
2418
-            $this->_category->id = $term->term_id;
2419
-            $this->_category->parent = $term->parent;
2420
-        }
2421
-    }
2422
-
2423
-
2424
-    /**
2425
-     * Clears out category properties.
2426
-     */
2427
-    private function _set_empty_category_object()
2428
-    {
2429
-        $this->_category = new stdClass();
2430
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2431
-        $this->_category->id = $this->_category->parent = 0;
2432
-    }
2433
-
2434
-
2435
-    /**
2436
-     * @throws EE_Error
2437
-     */
2438
-    protected function _category_list_table()
2439
-    {
2440
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2441
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2442
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2443
-            'add_category',
2444
-            'add_category',
2445
-            array(),
2446
-            'add-new-h2'
2447
-        );
2448
-        $this->display_admin_list_table_page_with_sidebar();
2449
-    }
2450
-
2451
-
2452
-    /**
2453
-     * Output category details view.
2454
-     */
2455
-    protected function _category_details($view)
2456
-    {
2457
-        // load formatter helper
2458
-        // load field generator helper
2459
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2460
-        $this->_set_add_edit_form_tags($route);
2461
-        $this->_set_category_object();
2462
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2463
-        $delete_action = 'delete_category';
2464
-        // custom redirect
2465
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2466
-            array('action' => 'category_list'),
2467
-            $this->_admin_base_url
2468
-        );
2469
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2470
-        // take care of contents
2471
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2472
-        $this->display_admin_page_with_sidebar();
2473
-    }
2474
-
2475
-
2476
-    /**
2477
-     * Output category details content.
2478
-     */
2479
-    protected function _category_details_content()
2480
-    {
2481
-        $editor_args['category_desc'] = array(
2482
-            'type'          => 'wp_editor',
2483
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2484
-            'class'         => 'my_editor_custom',
2485
-            'wpeditor_args' => array('media_buttons' => false),
2486
-        );
2487
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2488
-        $all_terms = get_terms(
2489
-            array('espresso_event_categories'),
2490
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2491
-        );
2492
-        // setup category select for term parents.
2493
-        $category_select_values[] = array(
2494
-            'text' => esc_html__('No Parent', 'event_espresso'),
2495
-            'id'   => 0,
2496
-        );
2497
-        foreach ($all_terms as $term) {
2498
-            $category_select_values[] = array(
2499
-                'text' => $term->name,
2500
-                'id'   => $term->term_id,
2501
-            );
2502
-        }
2503
-        $category_select = EEH_Form_Fields::select_input(
2504
-            'category_parent',
2505
-            $category_select_values,
2506
-            $this->_category->parent
2507
-        );
2508
-        $template_args = array(
2509
-            'category'                 => $this->_category,
2510
-            'category_select'          => $category_select,
2511
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2512
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2513
-            'disable'                  => '',
2514
-            'disabled_message'         => false,
2515
-        );
2516
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2517
-        return EEH_Template::display_template($template, $template_args, true);
2518
-    }
2519
-
2520
-
2521
-    /**
2522
-     * Handles deleting categories.
2523
-     */
2524
-    protected function _delete_categories()
2525
-    {
2526
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2527
-            : (array) $this->_req_data['category_id'];
2528
-        foreach ($cat_ids as $cat_id) {
2529
-            $this->_delete_category($cat_id);
2530
-        }
2531
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2532
-        $query_args = array(
2533
-            'action' => 'category_list',
2534
-        );
2535
-        $this->_redirect_after_action(0, '', '', $query_args);
2536
-    }
2537
-
2538
-
2539
-    /**
2540
-     * Handles deleting specific category.
2541
-     *
2542
-     * @param int $cat_id
2543
-     */
2544
-    protected function _delete_category($cat_id)
2545
-    {
2546
-        $cat_id = absint($cat_id);
2547
-        wp_delete_term($cat_id, 'espresso_event_categories');
2548
-    }
2549
-
2550
-
2551
-    /**
2552
-     * Handles triggering the update or insertion of a new category.
2553
-     *
2554
-     * @param bool $new_category true means we're triggering the insert of a new category.
2555
-     */
2556
-    protected function _insert_or_update_category($new_category)
2557
-    {
2558
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2559
-        $success = 0; // we already have a success message so lets not send another.
2560
-        if ($cat_id) {
2561
-            $query_args = array(
2562
-                'action'     => 'edit_category',
2563
-                'EVT_CAT_ID' => $cat_id,
2564
-            );
2565
-        } else {
2566
-            $query_args = array('action' => 'add_category');
2567
-        }
2568
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2569
-    }
2570
-
2571
-
2572
-    /**
2573
-     * Inserts or updates category
2574
-     *
2575
-     * @param bool $update (true indicates we're updating a category).
2576
-     * @return bool|mixed|string
2577
-     */
2578
-    private function _insert_category($update = false)
2579
-    {
2580
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2581
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2582
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2583
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2584
-        if (empty($category_name)) {
2585
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2586
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2587
-            return false;
2588
-        }
2589
-        $term_args = array(
2590
-            'name'        => $category_name,
2591
-            'description' => $category_desc,
2592
-            'parent'      => $category_parent,
2593
-        );
2594
-        // was the category_identifier input disabled?
2595
-        if (isset($this->_req_data['category_identifier'])) {
2596
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2597
-        }
2598
-        $insert_ids = $update
2599
-            ? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2600
-            : wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2601
-        if (! is_array($insert_ids)) {
2602
-            $msg = esc_html__(
2603
-                'An error occurred and the category has not been saved to the database.',
2604
-                'event_espresso'
2605
-            );
2606
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2607
-        } else {
2608
-            $cat_id = $insert_ids['term_id'];
2609
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2610
-            EE_Error::add_success($msg);
2611
-        }
2612
-        return $cat_id;
2613
-    }
2614
-
2615
-
2616
-    /**
2617
-     * Gets categories or count of categories matching the arguments in the request.
2618
-     *
2619
-     * @param int  $per_page
2620
-     * @param int  $current_page
2621
-     * @param bool $count
2622
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2623
-     */
2624
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2625
-    {
2626
-        // testing term stuff
2627
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2628
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2629
-        $limit = ($current_page - 1) * $per_page;
2630
-        $where = array('taxonomy' => 'espresso_event_categories');
2631
-        if (isset($this->_req_data['s'])) {
2632
-            $sstr = '%' . $this->_req_data['s'] . '%';
2633
-            $where['OR'] = array(
2634
-                'Term.name'   => array('LIKE', $sstr),
2635
-                'description' => array('LIKE', $sstr),
2636
-            );
2637
-        }
2638
-        $query_params = array(
2639
-            $where,
2640
-            'order_by'   => array($orderby => $order),
2641
-            'limit'      => $limit . ',' . $per_page,
2642
-            'force_join' => array('Term'),
2643
-        );
2644
-        $categories = $count
2645
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2646
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2647
-        return $categories;
2648
-    }
2649
-
2650
-    /* end category stuff */
2651
-    /**************/
2652
-
2653
-
2654
-    /**
2655
-     * Callback for the `ee_save_timezone_setting` ajax action.
2656
-     *
2657
-     * @throws EE_Error
2658
-     */
2659
-    public function save_timezonestring_setting()
2660
-    {
2661
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2662
-            ? $this->_req_data['timezone_selected']
2663
-            : '';
2664
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2665
-            EE_Error::add_error(
2666
-                esc_html('An invalid timezone string submitted.', 'event_espresso'),
2667
-                __FILE__,
2668
-                __FUNCTION__,
2669
-                __LINE__
2670
-            );
2671
-            $this->_template_args['error'] = true;
2672
-            $this->_return_json();
2673
-        }
2674
-
2675
-        update_option('timezone_string', $timezone_string);
2676
-        EE_Error::add_success(
2677
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2678
-        );
2679
-        $this->_template_args['success'] = true;
2680
-        $this->_return_json(true, array('action' => 'create_new'));
2681
-    }
15
+	/**
16
+	 * This will hold the event object for event_details screen.
17
+	 *
18
+	 * @access protected
19
+	 * @var EE_Event $_event
20
+	 */
21
+	protected $_event;
22
+
23
+
24
+	/**
25
+	 * This will hold the category object for category_details screen.
26
+	 *
27
+	 * @var stdClass $_category
28
+	 */
29
+	protected $_category;
30
+
31
+
32
+	/**
33
+	 * This will hold the event model instance
34
+	 *
35
+	 * @var EEM_Event $_event_model
36
+	 */
37
+	protected $_event_model;
38
+
39
+
40
+	/**
41
+	 * @var EE_Event
42
+	 */
43
+	protected $_cpt_model_obj = false;
44
+
45
+
46
+	/**
47
+	 * Initialize page props for this admin page group.
48
+	 */
49
+	protected function _init_page_props()
50
+	{
51
+		$this->page_slug = EVENTS_PG_SLUG;
52
+		$this->page_label = EVENTS_LABEL;
53
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
54
+		$this->_admin_base_path = EVENTS_ADMIN;
55
+		$this->_cpt_model_names = array(
56
+			'create_new' => 'EEM_Event',
57
+			'edit'       => 'EEM_Event',
58
+		);
59
+		$this->_cpt_edit_routes = array(
60
+			'espresso_events' => 'edit',
61
+		);
62
+		add_action(
63
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
64
+			array($this, 'verify_event_edit'),
65
+			10,
66
+			2
67
+		);
68
+	}
69
+
70
+
71
+	/**
72
+	 * Sets the ajax hooks used for this admin page group.
73
+	 */
74
+	protected function _ajax_hooks()
75
+	{
76
+		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
77
+	}
78
+
79
+
80
+	/**
81
+	 * Sets the page properties for this admin page group.
82
+	 */
83
+	protected function _define_page_props()
84
+	{
85
+		$this->_admin_page_title = EVENTS_LABEL;
86
+		$this->_labels = array(
87
+			'buttons'      => array(
88
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
89
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
90
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
91
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
92
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
93
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
94
+			),
95
+			'editor_title' => array(
96
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
97
+			),
98
+			'publishbox'   => array(
99
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
100
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
101
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
102
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
103
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
104
+			),
105
+		);
106
+	}
107
+
108
+
109
+	/**
110
+	 * Sets the page routes property for this admin page group.
111
+	 */
112
+	protected function _set_page_routes()
113
+	{
114
+		// load formatter helper
115
+		// load field generator helper
116
+		// is there a evt_id in the request?
117
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
118
+			? $this->_req_data['EVT_ID']
119
+			: 0;
120
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
121
+		$this->_page_routes = array(
122
+			'default'                       => array(
123
+				'func'       => '_events_overview_list_table',
124
+				'capability' => 'ee_read_events',
125
+			),
126
+			'create_new'                    => array(
127
+				'func'       => '_create_new_cpt_item',
128
+				'capability' => 'ee_edit_events',
129
+			),
130
+			'edit'                          => array(
131
+				'func'       => '_edit_cpt_item',
132
+				'capability' => 'ee_edit_event',
133
+				'obj_id'     => $evt_id,
134
+			),
135
+			'copy_event'                    => array(
136
+				'func'       => '_copy_events',
137
+				'capability' => 'ee_edit_event',
138
+				'obj_id'     => $evt_id,
139
+				'noheader'   => true,
140
+			),
141
+			'trash_event'                   => array(
142
+				'func'       => '_trash_or_restore_event',
143
+				'args'       => array('event_status' => 'trash'),
144
+				'capability' => 'ee_delete_event',
145
+				'obj_id'     => $evt_id,
146
+				'noheader'   => true,
147
+			),
148
+			'trash_events'                  => array(
149
+				'func'       => '_trash_or_restore_events',
150
+				'args'       => array('event_status' => 'trash'),
151
+				'capability' => 'ee_delete_events',
152
+				'noheader'   => true,
153
+			),
154
+			'restore_event'                 => array(
155
+				'func'       => '_trash_or_restore_event',
156
+				'args'       => array('event_status' => 'draft'),
157
+				'capability' => 'ee_delete_event',
158
+				'obj_id'     => $evt_id,
159
+				'noheader'   => true,
160
+			),
161
+			'restore_events'                => array(
162
+				'func'       => '_trash_or_restore_events',
163
+				'args'       => array('event_status' => 'draft'),
164
+				'capability' => 'ee_delete_events',
165
+				'noheader'   => true,
166
+			),
167
+			'delete_event'                  => array(
168
+				'func'       => '_delete_event',
169
+				'capability' => 'ee_delete_event',
170
+				'obj_id'     => $evt_id,
171
+				'noheader'   => true,
172
+			),
173
+			'delete_events'                 => array(
174
+				'func'       => '_delete_events',
175
+				'capability' => 'ee_delete_events',
176
+				'noheader'   => true,
177
+			),
178
+			'view_report'                   => array(
179
+				'func'      => '_view_report',
180
+				'capablity' => 'ee_edit_events',
181
+			),
182
+			'default_event_settings'        => array(
183
+				'func'       => '_default_event_settings',
184
+				'capability' => 'manage_options',
185
+			),
186
+			'update_default_event_settings' => array(
187
+				'func'       => '_update_default_event_settings',
188
+				'capability' => 'manage_options',
189
+				'noheader'   => true,
190
+			),
191
+			'template_settings'             => array(
192
+				'func'       => '_template_settings',
193
+				'capability' => 'manage_options',
194
+			),
195
+			// event category tab related
196
+			'add_category'                  => array(
197
+				'func'       => '_category_details',
198
+				'capability' => 'ee_edit_event_category',
199
+				'args'       => array('add'),
200
+			),
201
+			'edit_category'                 => array(
202
+				'func'       => '_category_details',
203
+				'capability' => 'ee_edit_event_category',
204
+				'args'       => array('edit'),
205
+			),
206
+			'delete_categories'             => array(
207
+				'func'       => '_delete_categories',
208
+				'capability' => 'ee_delete_event_category',
209
+				'noheader'   => true,
210
+			),
211
+			'delete_category'               => array(
212
+				'func'       => '_delete_categories',
213
+				'capability' => 'ee_delete_event_category',
214
+				'noheader'   => true,
215
+			),
216
+			'insert_category'               => array(
217
+				'func'       => '_insert_or_update_category',
218
+				'args'       => array('new_category' => true),
219
+				'capability' => 'ee_edit_event_category',
220
+				'noheader'   => true,
221
+			),
222
+			'update_category'               => array(
223
+				'func'       => '_insert_or_update_category',
224
+				'args'       => array('new_category' => false),
225
+				'capability' => 'ee_edit_event_category',
226
+				'noheader'   => true,
227
+			),
228
+			'category_list'                 => array(
229
+				'func'       => '_category_list_table',
230
+				'capability' => 'ee_manage_event_categories',
231
+			),
232
+		);
233
+	}
234
+
235
+
236
+	/**
237
+	 * Set the _page_config property for this admin page group.
238
+	 */
239
+	protected function _set_page_config()
240
+	{
241
+		$this->_page_config = array(
242
+			'default'                => array(
243
+				'nav'           => array(
244
+					'label' => esc_html__('Overview', 'event_espresso'),
245
+					'order' => 10,
246
+				),
247
+				'list_table'    => 'Events_Admin_List_Table',
248
+				'help_tabs'     => array(
249
+					'events_overview_help_tab'                       => array(
250
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
251
+						'filename' => 'events_overview',
252
+					),
253
+					'events_overview_table_column_headings_help_tab' => array(
254
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
255
+						'filename' => 'events_overview_table_column_headings',
256
+					),
257
+					'events_overview_filters_help_tab'               => array(
258
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
259
+						'filename' => 'events_overview_filters',
260
+					),
261
+					'events_overview_view_help_tab'                  => array(
262
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
263
+						'filename' => 'events_overview_views',
264
+					),
265
+					'events_overview_other_help_tab'                 => array(
266
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
267
+						'filename' => 'events_overview_other',
268
+					),
269
+				),
270
+				'help_tour'     => array(
271
+					'Event_Overview_Help_Tour',
272
+					// 'New_Features_Test_Help_Tour' for testing multiple help tour
273
+				),
274
+				'qtips'         => array(
275
+					'EE_Event_List_Table_Tips',
276
+				),
277
+				'require_nonce' => false,
278
+			),
279
+			'create_new'             => array(
280
+				'nav'           => array(
281
+					'label'      => esc_html__('Add Event', 'event_espresso'),
282
+					'order'      => 5,
283
+					'persistent' => false,
284
+				),
285
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
286
+				'help_tabs'     => array(
287
+					'event_editor_help_tab'                            => array(
288
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
289
+						'filename' => 'event_editor',
290
+					),
291
+					'event_editor_title_richtexteditor_help_tab'       => array(
292
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
293
+						'filename' => 'event_editor_title_richtexteditor',
294
+					),
295
+					'event_editor_venue_details_help_tab'              => array(
296
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
297
+						'filename' => 'event_editor_venue_details',
298
+					),
299
+					'event_editor_event_datetimes_help_tab'            => array(
300
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
301
+						'filename' => 'event_editor_event_datetimes',
302
+					),
303
+					'event_editor_event_tickets_help_tab'              => array(
304
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
305
+						'filename' => 'event_editor_event_tickets',
306
+					),
307
+					'event_editor_event_registration_options_help_tab' => array(
308
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
309
+						'filename' => 'event_editor_event_registration_options',
310
+					),
311
+					'event_editor_tags_categories_help_tab'            => array(
312
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
313
+						'filename' => 'event_editor_tags_categories',
314
+					),
315
+					'event_editor_questions_registrants_help_tab'      => array(
316
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
317
+						'filename' => 'event_editor_questions_registrants',
318
+					),
319
+					'event_editor_save_new_event_help_tab'             => array(
320
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
321
+						'filename' => 'event_editor_save_new_event',
322
+					),
323
+					'event_editor_other_help_tab'                      => array(
324
+						'title'    => esc_html__('Event Other', 'event_espresso'),
325
+						'filename' => 'event_editor_other',
326
+					),
327
+				),
328
+				'help_tour'     => array(
329
+					'Event_Editor_Help_Tour',
330
+				),
331
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
332
+				'require_nonce' => false,
333
+			),
334
+			'edit'                   => array(
335
+				'nav'           => array(
336
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
337
+					'order'      => 5,
338
+					'persistent' => false,
339
+					'url'        => isset($this->_req_data['post'])
340
+						? EE_Admin_Page::add_query_args_and_nonce(
341
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
342
+							$this->_current_page_view_url
343
+						)
344
+						: $this->_admin_base_url,
345
+				),
346
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
347
+				'help_tabs'     => array(
348
+					'event_editor_help_tab'                            => array(
349
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
350
+						'filename' => 'event_editor',
351
+					),
352
+					'event_editor_title_richtexteditor_help_tab'       => array(
353
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
354
+						'filename' => 'event_editor_title_richtexteditor',
355
+					),
356
+					'event_editor_venue_details_help_tab'              => array(
357
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
358
+						'filename' => 'event_editor_venue_details',
359
+					),
360
+					'event_editor_event_datetimes_help_tab'            => array(
361
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
362
+						'filename' => 'event_editor_event_datetimes',
363
+					),
364
+					'event_editor_event_tickets_help_tab'              => array(
365
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
366
+						'filename' => 'event_editor_event_tickets',
367
+					),
368
+					'event_editor_event_registration_options_help_tab' => array(
369
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
370
+						'filename' => 'event_editor_event_registration_options',
371
+					),
372
+					'event_editor_tags_categories_help_tab'            => array(
373
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
374
+						'filename' => 'event_editor_tags_categories',
375
+					),
376
+					'event_editor_questions_registrants_help_tab'      => array(
377
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
378
+						'filename' => 'event_editor_questions_registrants',
379
+					),
380
+					'event_editor_save_new_event_help_tab'             => array(
381
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
382
+						'filename' => 'event_editor_save_new_event',
383
+					),
384
+					'event_editor_other_help_tab'                      => array(
385
+						'title'    => esc_html__('Event Other', 'event_espresso'),
386
+						'filename' => 'event_editor_other',
387
+					),
388
+				),
389
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
390
+				'require_nonce' => false,
391
+			),
392
+			'default_event_settings' => array(
393
+				'nav'           => array(
394
+					'label' => esc_html__('Default Settings', 'event_espresso'),
395
+					'order' => 40,
396
+				),
397
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
398
+				'labels'        => array(
399
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
400
+				),
401
+				'help_tabs'     => array(
402
+					'default_settings_help_tab'        => array(
403
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
404
+						'filename' => 'events_default_settings',
405
+					),
406
+					'default_settings_status_help_tab' => array(
407
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
408
+						'filename' => 'events_default_settings_status',
409
+					),
410
+					'default_maximum_tickets_help_tab' => array(
411
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
412
+						'filename' => 'events_default_settings_max_tickets',
413
+					),
414
+				),
415
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
416
+				'require_nonce' => false,
417
+			),
418
+			// template settings
419
+			'template_settings'      => array(
420
+				'nav'           => array(
421
+					'label' => esc_html__('Templates', 'event_espresso'),
422
+					'order' => 30,
423
+				),
424
+				'metaboxes'     => $this->_default_espresso_metaboxes,
425
+				'help_tabs'     => array(
426
+					'general_settings_templates_help_tab' => array(
427
+						'title'    => esc_html__('Templates', 'event_espresso'),
428
+						'filename' => 'general_settings_templates',
429
+					),
430
+				),
431
+				'help_tour'     => array('Templates_Help_Tour'),
432
+				'require_nonce' => false,
433
+			),
434
+			// event category stuff
435
+			'add_category'           => array(
436
+				'nav'           => array(
437
+					'label'      => esc_html__('Add Category', 'event_espresso'),
438
+					'order'      => 15,
439
+					'persistent' => false,
440
+				),
441
+				'help_tabs'     => array(
442
+					'add_category_help_tab' => array(
443
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
444
+						'filename' => 'events_add_category',
445
+					),
446
+				),
447
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
448
+				'metaboxes'     => array('_publish_post_box'),
449
+				'require_nonce' => false,
450
+			),
451
+			'edit_category'          => array(
452
+				'nav'           => array(
453
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
454
+					'order'      => 15,
455
+					'persistent' => false,
456
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
457
+						? add_query_arg(
458
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
459
+							$this->_current_page_view_url
460
+						)
461
+						: $this->_admin_base_url,
462
+				),
463
+				'help_tabs'     => array(
464
+					'edit_category_help_tab' => array(
465
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
466
+						'filename' => 'events_edit_category',
467
+					),
468
+				),
469
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
470
+				'metaboxes'     => array('_publish_post_box'),
471
+				'require_nonce' => false,
472
+			),
473
+			'category_list'          => array(
474
+				'nav'           => array(
475
+					'label' => esc_html__('Categories', 'event_espresso'),
476
+					'order' => 20,
477
+				),
478
+				'list_table'    => 'Event_Categories_Admin_List_Table',
479
+				'help_tabs'     => array(
480
+					'events_categories_help_tab'                       => array(
481
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
482
+						'filename' => 'events_categories',
483
+					),
484
+					'events_categories_table_column_headings_help_tab' => array(
485
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
486
+						'filename' => 'events_categories_table_column_headings',
487
+					),
488
+					'events_categories_view_help_tab'                  => array(
489
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
490
+						'filename' => 'events_categories_views',
491
+					),
492
+					'events_categories_other_help_tab'                 => array(
493
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
494
+						'filename' => 'events_categories_other',
495
+					),
496
+				),
497
+				'help_tour'     => array(
498
+					'Event_Categories_Help_Tour',
499
+				),
500
+				'metaboxes'     => $this->_default_espresso_metaboxes,
501
+				'require_nonce' => false,
502
+			),
503
+		);
504
+	}
505
+
506
+
507
+	/**
508
+	 * Used to register any global screen options if necessary for every route in this admin page group.
509
+	 */
510
+	protected function _add_screen_options()
511
+	{
512
+	}
513
+
514
+
515
+	/**
516
+	 * Implementing the screen options for the 'default' route.
517
+	 */
518
+	protected function _add_screen_options_default()
519
+	{
520
+		$this->_per_page_screen_option();
521
+	}
522
+
523
+
524
+	/**
525
+	 * Implementing screen options for the category list route.
526
+	 */
527
+	protected function _add_screen_options_category_list()
528
+	{
529
+		$page_title = $this->_admin_page_title;
530
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
531
+		$this->_per_page_screen_option();
532
+		$this->_admin_page_title = $page_title;
533
+	}
534
+
535
+
536
+	/**
537
+	 * Used to register any global feature pointers for the admin page group.
538
+	 */
539
+	protected function _add_feature_pointers()
540
+	{
541
+	}
542
+
543
+
544
+	/**
545
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
546
+	 */
547
+	public function load_scripts_styles()
548
+	{
549
+		wp_register_style(
550
+			'events-admin-css',
551
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
552
+			array(),
553
+			EVENT_ESPRESSO_VERSION
554
+		);
555
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
556
+		wp_enqueue_style('events-admin-css');
557
+		wp_enqueue_style('ee-cat-admin');
558
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
559
+		// registers for all views
560
+		// scripts
561
+		wp_register_script(
562
+			'event_editor_js',
563
+			EVENTS_ASSETS_URL . 'event_editor.js',
564
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
565
+			EVENT_ESPRESSO_VERSION,
566
+			true
567
+		);
568
+	}
569
+
570
+
571
+	/**
572
+	 * Enqueuing scripts and styles specific to this view
573
+	 */
574
+	public function load_scripts_styles_create_new()
575
+	{
576
+		$this->load_scripts_styles_edit();
577
+	}
578
+
579
+
580
+	/**
581
+	 * Enqueuing scripts and styles specific to this view
582
+	 */
583
+	public function load_scripts_styles_edit()
584
+	{
585
+		// styles
586
+		wp_enqueue_style('espresso-ui-theme');
587
+		wp_register_style(
588
+			'event-editor-css',
589
+			EVENTS_ASSETS_URL . 'event-editor.css',
590
+			array('ee-admin-css'),
591
+			EVENT_ESPRESSO_VERSION
592
+		);
593
+		wp_enqueue_style('event-editor-css');
594
+		// scripts
595
+		wp_register_script(
596
+			'event-datetime-metabox',
597
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
598
+			array('event_editor_js', 'ee-datepicker'),
599
+			EVENT_ESPRESSO_VERSION
600
+		);
601
+		wp_enqueue_script('event-datetime-metabox');
602
+	}
603
+
604
+
605
+	/**
606
+	 * Populating the _views property for the category list table view.
607
+	 */
608
+	protected function _set_list_table_views_category_list()
609
+	{
610
+		$this->_views = array(
611
+			'all' => array(
612
+				'slug'        => 'all',
613
+				'label'       => esc_html__('All', 'event_espresso'),
614
+				'count'       => 0,
615
+				'bulk_action' => array(
616
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
617
+				),
618
+			),
619
+		);
620
+	}
621
+
622
+
623
+	/**
624
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
625
+	 */
626
+	public function admin_init()
627
+	{
628
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
629
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
630
+			'event_espresso'
631
+		);
632
+	}
633
+
634
+
635
+	/**
636
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
637
+	 * group.
638
+	 */
639
+	public function admin_notices()
640
+	{
641
+	}
642
+
643
+
644
+	/**
645
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
646
+	 * this admin page group.
647
+	 */
648
+	public function admin_footer_scripts()
649
+	{
650
+	}
651
+
652
+
653
+	/**
654
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
655
+	 * warning (via EE_Error::add_error());
656
+	 *
657
+	 * @param  EE_Event $event Event object
658
+	 * @param string    $req_type
659
+	 * @return void
660
+	 * @throws EE_Error
661
+	 * @access public
662
+	 */
663
+	public function verify_event_edit($event = null, $req_type = '')
664
+	{
665
+		// don't need to do this when processing
666
+		if (! empty($req_type)) {
667
+			return;
668
+		}
669
+		// no event?
670
+		if (empty($event)) {
671
+			// set event
672
+			$event = $this->_cpt_model_obj;
673
+		}
674
+		// STILL no event?
675
+		if (! $event instanceof EE_Event) {
676
+			return;
677
+		}
678
+		$orig_status = $event->status();
679
+		// first check if event is active.
680
+		if ($orig_status === EEM_Event::cancelled
681
+			|| $orig_status === EEM_Event::postponed
682
+			|| $event->is_expired()
683
+			|| $event->is_inactive()
684
+		) {
685
+			return;
686
+		}
687
+		// made it here so it IS active... next check that any of the tickets are sold.
688
+		if ($event->is_sold_out(true)) {
689
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
690
+				EE_Error::add_attention(
691
+					sprintf(
692
+						esc_html__(
693
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
694
+							'event_espresso'
695
+						),
696
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
697
+					)
698
+				);
699
+			}
700
+			return;
701
+		} elseif ($orig_status === EEM_Event::sold_out) {
702
+			EE_Error::add_attention(
703
+				sprintf(
704
+					esc_html__(
705
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
706
+						'event_espresso'
707
+					),
708
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
709
+				)
710
+			);
711
+		}
712
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
713
+		if (! $event->tickets_on_sale()) {
714
+			return;
715
+		}
716
+		// made it here so show warning
717
+		$this->_edit_event_warning();
718
+	}
719
+
720
+
721
+	/**
722
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
723
+	 * When needed, hook this into a EE_Error::add_error() notice.
724
+	 *
725
+	 * @access protected
726
+	 * @return void
727
+	 */
728
+	protected function _edit_event_warning()
729
+	{
730
+		// we don't want to add warnings during these requests
731
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
732
+			return;
733
+		}
734
+		EE_Error::add_attention(
735
+			sprintf(
736
+				esc_html__(
737
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
738
+					'event_espresso'
739
+				),
740
+				'<a class="espresso-help-tab-lnk">',
741
+				'</a>'
742
+			)
743
+		);
744
+	}
745
+
746
+
747
+	/**
748
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
749
+	 * Otherwise, do the normal logic
750
+	 *
751
+	 * @return string
752
+	 * @throws \EE_Error
753
+	 */
754
+	protected function _create_new_cpt_item()
755
+	{
756
+		$has_timezone_string = get_option('timezone_string');
757
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
758
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
759
+			EE_Error::add_attention(
760
+				sprintf(
761
+					__(
762
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
763
+						'event_espresso'
764
+					),
765
+					'<br>',
766
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
767
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
768
+					. '</select>',
769
+					'<button class="button button-secondary timezone-submit">',
770
+					'</button><span class="spinner"></span>'
771
+				),
772
+				__FILE__,
773
+				__FUNCTION__,
774
+				__LINE__
775
+			);
776
+		}
777
+		return parent::_create_new_cpt_item();
778
+	}
779
+
780
+
781
+	/**
782
+	 * Sets the _views property for the default route in this admin page group.
783
+	 */
784
+	protected function _set_list_table_views_default()
785
+	{
786
+		$this->_views = array(
787
+			'all'   => array(
788
+				'slug'        => 'all',
789
+				'label'       => esc_html__('View All Events', 'event_espresso'),
790
+				'count'       => 0,
791
+				'bulk_action' => array(
792
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
793
+				),
794
+			),
795
+			'draft' => array(
796
+				'slug'        => 'draft',
797
+				'label'       => esc_html__('Draft', 'event_espresso'),
798
+				'count'       => 0,
799
+				'bulk_action' => array(
800
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
801
+				),
802
+			),
803
+		);
804
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
805
+			$this->_views['trash'] = array(
806
+				'slug'        => 'trash',
807
+				'label'       => esc_html__('Trash', 'event_espresso'),
808
+				'count'       => 0,
809
+				'bulk_action' => array(
810
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
811
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
812
+				),
813
+			);
814
+		}
815
+	}
816
+
817
+
818
+	/**
819
+	 * Provides the legend item array for the default list table view.
820
+	 *
821
+	 * @return array
822
+	 */
823
+	protected function _event_legend_items()
824
+	{
825
+		$items = array(
826
+			'view_details'   => array(
827
+				'class' => 'dashicons dashicons-search',
828
+				'desc'  => esc_html__('View Event', 'event_espresso'),
829
+			),
830
+			'edit_event'     => array(
831
+				'class' => 'ee-icon ee-icon-calendar-edit',
832
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
833
+			),
834
+			'view_attendees' => array(
835
+				'class' => 'dashicons dashicons-groups',
836
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
837
+			),
838
+		);
839
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
840
+		$statuses = array(
841
+			'sold_out_status'  => array(
842
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
843
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
844
+			),
845
+			'active_status'    => array(
846
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
847
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
848
+			),
849
+			'upcoming_status'  => array(
850
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
851
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
852
+			),
853
+			'postponed_status' => array(
854
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
855
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
856
+			),
857
+			'cancelled_status' => array(
858
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
859
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
860
+			),
861
+			'expired_status'   => array(
862
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
863
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
864
+			),
865
+			'inactive_status'  => array(
866
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
867
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
868
+			),
869
+		);
870
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
871
+		return array_merge($items, $statuses);
872
+	}
873
+
874
+
875
+	/**
876
+	 * @return EEM_Event
877
+	 */
878
+	private function _event_model()
879
+	{
880
+		if (! $this->_event_model instanceof EEM_Event) {
881
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
882
+		}
883
+		return $this->_event_model;
884
+	}
885
+
886
+
887
+	/**
888
+	 * Adds extra buttons to the WP CPT permalink field row.
889
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
890
+	 *
891
+	 * @param  string $return    the current html
892
+	 * @param  int    $id        the post id for the page
893
+	 * @param  string $new_title What the title is
894
+	 * @param  string $new_slug  what the slug is
895
+	 * @return string            The new html string for the permalink area
896
+	 */
897
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
898
+	{
899
+		// make sure this is only when editing
900
+		if (! empty($id)) {
901
+			$post = get_post($id);
902
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
903
+					   . esc_html__('Shortcode', 'event_espresso')
904
+					   . '</a> ';
905
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
906
+					   . $post->ID
907
+					   . ']">';
908
+		}
909
+		return $return;
910
+	}
911
+
912
+
913
+	/**
914
+	 * _events_overview_list_table
915
+	 * This contains the logic for showing the events_overview list
916
+	 *
917
+	 * @access protected
918
+	 * @return void
919
+	 * @throws \EE_Error
920
+	 */
921
+	protected function _events_overview_list_table()
922
+	{
923
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
924
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
925
+			? (array) $this->_template_args['after_list_table']
926
+			: array();
927
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
928
+				. EEH_Template::get_button_or_link(
929
+					get_post_type_archive_link('espresso_events'),
930
+					esc_html__("View Event Archive Page", "event_espresso"),
931
+					'button'
932
+				);
933
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
934
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
935
+			'create_new',
936
+			'add',
937
+			array(),
938
+			'add-new-h2'
939
+		);
940
+		$this->display_admin_list_table_page_with_no_sidebar();
941
+	}
942
+
943
+
944
+	/**
945
+	 * this allows for extra misc actions in the default WP publish box
946
+	 *
947
+	 * @return void
948
+	 */
949
+	public function extra_misc_actions_publish_box()
950
+	{
951
+		$this->_generate_publish_box_extra_content();
952
+	}
953
+
954
+
955
+	/**
956
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
957
+	 * saved.
958
+	 * Typically you would use this to save any additional data.
959
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
960
+	 * ALSO very important.  When a post transitions from scheduled to published,
961
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
962
+	 * other meta saves. So MAKE sure that you handle this accordingly.
963
+	 *
964
+	 * @access protected
965
+	 * @abstract
966
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
967
+	 * @param  object $post    The post object of the cpt that was saved.
968
+	 * @return void
969
+	 * @throws \EE_Error
970
+	 */
971
+	protected function _insert_update_cpt_item($post_id, $post)
972
+	{
973
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
974
+			// get out we're not processing an event save.
975
+			return;
976
+		}
977
+		$event_values = array(
978
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
979
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
980
+			'EVT_additional_limit'            => min(
981
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
982
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
983
+			),
984
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
985
+				? $this->_req_data['EVT_default_registration_status']
986
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
987
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
988
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
989
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
990
+				? $this->_req_data['timezone_string'] : null,
991
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
992
+				? $this->_req_data['externalURL'] : null,
993
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
994
+				? $this->_req_data['event_phone'] : null,
995
+		);
996
+		// update event
997
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
998
+		// get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
999
+		$get_one_where = array(
1000
+			$this->_event_model()->primary_key_name() => $post_id,
1001
+			'OR'                                      => array(
1002
+				'status'   => $post->post_status,
1003
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1004
+				// but the returned object here has a status of "publish", so use the original post status as well
1005
+				'status*1' => $this->_req_data['original_post_status'],
1006
+			),
1007
+		);
1008
+		$event = $this->_event_model()->get_one(array($get_one_where));
1009
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1010
+		$event_update_callbacks = apply_filters(
1011
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1012
+			array(
1013
+				array($this, '_default_venue_update'),
1014
+				array($this, '_default_tickets_update'),
1015
+			)
1016
+		);
1017
+		$att_success = true;
1018
+		foreach ($event_update_callbacks as $e_callback) {
1019
+			$_success = is_callable($e_callback)
1020
+				? call_user_func($e_callback, $event, $this->_req_data)
1021
+				: false;
1022
+			// if ANY of these updates fail then we want the appropriate global error message
1023
+			$att_success = ! $att_success ? $att_success : $_success;
1024
+		}
1025
+		// any errors?
1026
+		if ($success && false === $att_success) {
1027
+			EE_Error::add_error(
1028
+				esc_html__(
1029
+					'Event Details saved successfully but something went wrong with saving attachments.',
1030
+					'event_espresso'
1031
+				),
1032
+				__FILE__,
1033
+				__FUNCTION__,
1034
+				__LINE__
1035
+			);
1036
+		} elseif ($success === false) {
1037
+			EE_Error::add_error(
1038
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1039
+				__FILE__,
1040
+				__FUNCTION__,
1041
+				__LINE__
1042
+			);
1043
+		}
1044
+	}
1045
+
1046
+
1047
+	/**
1048
+	 * @see parent::restore_item()
1049
+	 * @param int $post_id
1050
+	 * @param int $revision_id
1051
+	 */
1052
+	protected function _restore_cpt_item($post_id, $revision_id)
1053
+	{
1054
+		// copy existing event meta to new post
1055
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1056
+		if ($post_evt instanceof EE_Event) {
1057
+			// meta revision restore
1058
+			$post_evt->restore_revision($revision_id);
1059
+			// related objs restore
1060
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1061
+		}
1062
+	}
1063
+
1064
+
1065
+	/**
1066
+	 * Attach the venue to the Event
1067
+	 *
1068
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1069
+	 * @param  array     $data   The request data from the form
1070
+	 * @return bool           Success or fail.
1071
+	 */
1072
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1073
+	{
1074
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1075
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1076
+		$rows_affected = null;
1077
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1078
+		// very important.  If we don't have a venue name...
1079
+		// then we'll get out because not necessary to create empty venue
1080
+		if (empty($data['venue_title'])) {
1081
+			return false;
1082
+		}
1083
+		$venue_array = array(
1084
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1085
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1086
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1087
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1088
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1089
+				: null,
1090
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1091
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1092
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1093
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1094
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1095
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1096
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1097
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1098
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1099
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1100
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1101
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1102
+			'status'              => 'publish',
1103
+		);
1104
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1105
+		if (! empty($venue_id)) {
1106
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1107
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1108
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1109
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1110
+			return $rows_affected > 0 ? true : false;
1111
+		} else {
1112
+			// we insert the venue
1113
+			$venue_id = $venue_model->insert($venue_array);
1114
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1115
+			return ! empty($venue_id) ? true : false;
1116
+		}
1117
+		// when we have the ancestor come in it's already been handled by the revision save.
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1123
+	 *
1124
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1125
+	 * @param  array    $data   The request data from the form
1126
+	 * @return array
1127
+	 */
1128
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1129
+	{
1130
+		$success = true;
1131
+		$saved_dtt = null;
1132
+		$saved_tickets = array();
1133
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1134
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1135
+			// trim all values to ensure any excess whitespace is removed.
1136
+			$dtt = array_map('trim', $dtt);
1137
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1138
+				: $dtt['DTT_EVT_start'];
1139
+			$datetime_values = array(
1140
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1141
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1142
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1143
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1144
+				'DTT_order'     => $row,
1145
+			);
1146
+			// if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1147
+			if (! empty($dtt['DTT_ID'])) {
1148
+				$DTM = EE_Registry::instance()
1149
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1150
+								  ->get_one_by_ID($dtt['DTT_ID']);
1151
+				$DTM->set_date_format($incoming_date_formats[0]);
1152
+				$DTM->set_time_format($incoming_date_formats[1]);
1153
+				foreach ($datetime_values as $field => $value) {
1154
+					$DTM->set($field, $value);
1155
+				}
1156
+				// make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1157
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1158
+			} else {
1159
+				$DTM = EE_Registry::instance()->load_class(
1160
+					'Datetime',
1161
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1162
+					false,
1163
+					false
1164
+				);
1165
+				foreach ($datetime_values as $field => $value) {
1166
+					$DTM->set($field, $value);
1167
+				}
1168
+			}
1169
+			$DTM->save();
1170
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1171
+			// load DTT helper
1172
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1173
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1174
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1175
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1176
+				$DTT->save();
1177
+			}
1178
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1179
+			$saved_dtt = $DTT;
1180
+			$success = ! $success ? $success : $DTT;
1181
+			// if ANY of these updates fail then we want the appropriate global error message.
1182
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1183
+		}
1184
+		// no dtts get deleted so we don't do any of that logic here.
1185
+		// update tickets next
1186
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1187
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1188
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1189
+			$update_prices = false;
1190
+			$ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1191
+				? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1192
+			// trim inputs to ensure any excess whitespace is removed.
1193
+			$tkt = array_map('trim', $tkt);
1194
+			if (empty($tkt['TKT_start_date'])) {
1195
+				// let's use now in the set timezone.
1196
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1197
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1198
+			}
1199
+			if (empty($tkt['TKT_end_date'])) {
1200
+				// use the start date of the first datetime
1201
+				$dtt = $evtobj->first_datetime();
1202
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1203
+					$incoming_date_formats[0],
1204
+					$incoming_date_formats[1]
1205
+				);
1206
+			}
1207
+			$TKT_values = array(
1208
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1209
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1210
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1211
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1212
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1213
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1214
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1215
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1216
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1217
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1218
+				'TKT_row'         => $row,
1219
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1220
+				'TKT_price'       => $ticket_price,
1221
+			);
1222
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1223
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1224
+				$TKT_values['TKT_ID'] = 0;
1225
+				$TKT_values['TKT_is_default'] = 0;
1226
+				$TKT_values['TKT_price'] = $ticket_price;
1227
+				$update_prices = true;
1228
+			}
1229
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1230
+			// we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1231
+			// keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1232
+			if (! empty($tkt['TKT_ID'])) {
1233
+				$TKT = EE_Registry::instance()
1234
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1235
+								  ->get_one_by_ID($tkt['TKT_ID']);
1236
+				if ($TKT instanceof EE_Ticket) {
1237
+					$ticket_sold = $TKT->count_related(
1238
+						'Registration',
1239
+						array(
1240
+							array(
1241
+								'STS_ID' => array(
1242
+									'NOT IN',
1243
+									array(EEM_Registration::status_id_incomplete),
1244
+								),
1245
+							),
1246
+						)
1247
+					) > 0 ? true : false;
1248
+					// let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1249
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1250
+									  && ! $TKT->get('TKT_deleted');
1251
+					$TKT->set_date_format($incoming_date_formats[0]);
1252
+					$TKT->set_time_format($incoming_date_formats[1]);
1253
+					// set new values
1254
+					foreach ($TKT_values as $field => $value) {
1255
+						if ($field == 'TKT_qty') {
1256
+							$TKT->set_qty($value);
1257
+						} else {
1258
+							$TKT->set($field, $value);
1259
+						}
1260
+					}
1261
+					// if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1262
+					if ($create_new_TKT) {
1263
+						// archive the old ticket first
1264
+						$TKT->set('TKT_deleted', 1);
1265
+						$TKT->save();
1266
+						// make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1267
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1268
+						// create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1269
+						$TKT = clone $TKT;
1270
+						$TKT->set('TKT_ID', 0);
1271
+						$TKT->set('TKT_deleted', 0);
1272
+						$TKT->set('TKT_price', $ticket_price);
1273
+						$TKT->set('TKT_sold', 0);
1274
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1275
+						$update_prices = true;
1276
+					}
1277
+					// make sure price is set if it hasn't been already
1278
+					$TKT->set('TKT_price', $ticket_price);
1279
+				}
1280
+			} else {
1281
+				// no TKT_id so a new TKT
1282
+				$TKT_values['TKT_price'] = $ticket_price;
1283
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1284
+				if ($TKT instanceof EE_Ticket) {
1285
+					// need to reset values to properly account for the date formats
1286
+					$TKT->set_date_format($incoming_date_formats[0]);
1287
+					$TKT->set_time_format($incoming_date_formats[1]);
1288
+					$TKT->set_timezone($evtobj->get_timezone());
1289
+					// set new values
1290
+					foreach ($TKT_values as $field => $value) {
1291
+						if ($field == 'TKT_qty') {
1292
+							$TKT->set_qty($value);
1293
+						} else {
1294
+							$TKT->set($field, $value);
1295
+						}
1296
+					}
1297
+					$update_prices = true;
1298
+				}
1299
+			}
1300
+			// cap ticket qty by datetime reg limits
1301
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1302
+			// update ticket.
1303
+			$TKT->save();
1304
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1305
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1306
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1307
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1308
+				$TKT->save();
1309
+			}
1310
+			// initially let's add the ticket to the dtt
1311
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1312
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1313
+			// add prices to ticket
1314
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1315
+		}
1316
+		// however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1317
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1318
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1319
+		foreach ($tickets_removed as $id) {
1320
+			$id = absint($id);
1321
+			// get the ticket for this id
1322
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1323
+			// need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1324
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1325
+			foreach ($dtts as $dtt) {
1326
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1327
+			}
1328
+			// need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1329
+			$tkt_to_remove->delete_related_permanently('Price');
1330
+			// finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1331
+			$tkt_to_remove->delete_permanently();
1332
+		}
1333
+		return array($saved_dtt, $saved_tickets);
1334
+	}
1335
+
1336
+
1337
+	/**
1338
+	 * This attaches a list of given prices to a ticket.
1339
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1340
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1341
+	 * price info and prices are automatically "archived" via the ticket.
1342
+	 *
1343
+	 * @access  private
1344
+	 * @param array     $prices     Array of prices from the form.
1345
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1346
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1347
+	 * @return  void
1348
+	 */
1349
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1350
+	{
1351
+		foreach ($prices as $row => $prc) {
1352
+			$PRC_values = array(
1353
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1354
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1355
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1356
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1357
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1358
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1359
+				'PRC_order'      => $row,
1360
+			);
1361
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1362
+				$PRC_values['PRC_ID'] = 0;
1363
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1364
+			} else {
1365
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1366
+				// update this price with new values
1367
+				foreach ($PRC_values as $field => $newprc) {
1368
+					$PRC->set($field, $newprc);
1369
+				}
1370
+				$PRC->save();
1371
+			}
1372
+			$ticket->_add_relation_to($PRC, 'Price');
1373
+		}
1374
+	}
1375
+
1376
+
1377
+	/**
1378
+	 * Add in our autosave ajax handlers
1379
+	 *
1380
+	 */
1381
+	protected function _ee_autosave_create_new()
1382
+	{
1383
+	}
1384
+
1385
+
1386
+	/**
1387
+	 * More autosave handlers.
1388
+	 */
1389
+	protected function _ee_autosave_edit()
1390
+	{
1391
+		return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1392
+	}
1393
+
1394
+
1395
+	/**
1396
+	 *    _generate_publish_box_extra_content
1397
+	 */
1398
+	private function _generate_publish_box_extra_content()
1399
+	{
1400
+		// load formatter helper
1401
+		// args for getting related registrations
1402
+		$approved_query_args = array(
1403
+			array(
1404
+				'REG_deleted' => 0,
1405
+				'STS_ID'      => EEM_Registration::status_id_approved,
1406
+			),
1407
+		);
1408
+		$not_approved_query_args = array(
1409
+			array(
1410
+				'REG_deleted' => 0,
1411
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1412
+			),
1413
+		);
1414
+		$pending_payment_query_args = array(
1415
+			array(
1416
+				'REG_deleted' => 0,
1417
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1418
+			),
1419
+		);
1420
+		// publish box
1421
+		$publish_box_extra_args = array(
1422
+			'view_approved_reg_url'        => add_query_arg(
1423
+				array(
1424
+					'action'      => 'default',
1425
+					'event_id'    => $this->_cpt_model_obj->ID(),
1426
+					'_reg_status' => EEM_Registration::status_id_approved,
1427
+				),
1428
+				REG_ADMIN_URL
1429
+			),
1430
+			'view_not_approved_reg_url'    => add_query_arg(
1431
+				array(
1432
+					'action'      => 'default',
1433
+					'event_id'    => $this->_cpt_model_obj->ID(),
1434
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1435
+				),
1436
+				REG_ADMIN_URL
1437
+			),
1438
+			'view_pending_payment_reg_url' => add_query_arg(
1439
+				array(
1440
+					'action'      => 'default',
1441
+					'event_id'    => $this->_cpt_model_obj->ID(),
1442
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1443
+				),
1444
+				REG_ADMIN_URL
1445
+			),
1446
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1447
+				'Registration',
1448
+				$approved_query_args
1449
+			),
1450
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1451
+				'Registration',
1452
+				$not_approved_query_args
1453
+			),
1454
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1455
+				'Registration',
1456
+				$pending_payment_query_args
1457
+			),
1458
+			'misc_pub_section_class'       => apply_filters(
1459
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1460
+				'misc-pub-section'
1461
+			),
1462
+		);
1463
+		ob_start();
1464
+		do_action(
1465
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1466
+			$this->_cpt_model_obj
1467
+		);
1468
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1469
+		// load template
1470
+		EEH_Template::display_template(
1471
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1472
+			$publish_box_extra_args
1473
+		);
1474
+	}
1475
+
1476
+
1477
+	/**
1478
+	 * @return EE_Event
1479
+	 */
1480
+	public function get_event_object()
1481
+	{
1482
+		return $this->_cpt_model_obj;
1483
+	}
1484
+
1485
+
1486
+
1487
+
1488
+	/** METABOXES * */
1489
+	/**
1490
+	 * _register_event_editor_meta_boxes
1491
+	 * add all metaboxes related to the event_editor
1492
+	 *
1493
+	 * @return void
1494
+	 */
1495
+	protected function _register_event_editor_meta_boxes()
1496
+	{
1497
+		$this->verify_cpt_object();
1498
+		add_meta_box(
1499
+			'espresso_event_editor_tickets',
1500
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1501
+			array($this, 'ticket_metabox'),
1502
+			$this->page_slug,
1503
+			'normal',
1504
+			'high'
1505
+		);
1506
+		add_meta_box(
1507
+			'espresso_event_editor_event_options',
1508
+			esc_html__('Event Registration Options', 'event_espresso'),
1509
+			array($this, 'registration_options_meta_box'),
1510
+			$this->page_slug,
1511
+			'side',
1512
+			'default'
1513
+		);
1514
+		// NOTE: if you're looking for other metaboxes in here,
1515
+		// where a metabox has a related management page in the admin
1516
+		// you will find it setup in the related management page's "_Hooks" file.
1517
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1518
+	}
1519
+
1520
+
1521
+	/**
1522
+	 * @throws DomainException
1523
+	 * @throws EE_Error
1524
+	 */
1525
+	public function ticket_metabox()
1526
+	{
1527
+		$existing_datetime_ids = $existing_ticket_ids = array();
1528
+		// defaults for template args
1529
+		$template_args = array(
1530
+			'existing_datetime_ids'    => '',
1531
+			'event_datetime_help_link' => '',
1532
+			'ticket_options_help_link' => '',
1533
+			'time'                     => null,
1534
+			'ticket_rows'              => '',
1535
+			'existing_ticket_ids'      => '',
1536
+			'total_ticket_rows'        => 1,
1537
+			'ticket_js_structure'      => '',
1538
+			'trash_icon'               => 'ee-lock-icon',
1539
+			'disabled'                 => '',
1540
+		);
1541
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1542
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1543
+		/**
1544
+		 * 1. Start with retrieving Datetimes
1545
+		 * 2. Fore each datetime get related tickets
1546
+		 * 3. For each ticket get related prices
1547
+		 */
1548
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1549
+		/** @type EE_Datetime $first_datetime */
1550
+		$first_datetime = reset($times);
1551
+		// do we get related tickets?
1552
+		if ($first_datetime instanceof EE_Datetime
1553
+			&& $first_datetime->ID() !== 0
1554
+		) {
1555
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1556
+			$template_args['time'] = $first_datetime;
1557
+			$related_tickets = $first_datetime->tickets(
1558
+				array(
1559
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1560
+					'default_where_conditions' => 'none',
1561
+				)
1562
+			);
1563
+			if (! empty($related_tickets)) {
1564
+				$template_args['total_ticket_rows'] = count($related_tickets);
1565
+				$row = 0;
1566
+				foreach ($related_tickets as $ticket) {
1567
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1568
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1569
+					$row++;
1570
+				}
1571
+			} else {
1572
+				$template_args['total_ticket_rows'] = 1;
1573
+				/** @type EE_Ticket $ticket */
1574
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1575
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1576
+			}
1577
+		} else {
1578
+			$template_args['time'] = $times[0];
1579
+			/** @type EE_Ticket $ticket */
1580
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1581
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1582
+			// NOTE: we're just sending the first default row
1583
+			// (decaf can't manage default tickets so this should be sufficient);
1584
+		}
1585
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1586
+			'event_editor_event_datetimes_help_tab'
1587
+		);
1588
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1589
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1590
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1591
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1592
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1593
+			true
1594
+		);
1595
+		$template = apply_filters(
1596
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1597
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1598
+		);
1599
+		EEH_Template::display_template($template, $template_args);
1600
+	}
1601
+
1602
+
1603
+	/**
1604
+	 * Setup an individual ticket form for the decaf event editor page
1605
+	 *
1606
+	 * @access private
1607
+	 * @param  EE_Ticket $ticket   the ticket object
1608
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1609
+	 * @param int        $row
1610
+	 * @return string generated html for the ticket row.
1611
+	 */
1612
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1613
+	{
1614
+		$template_args = array(
1615
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1616
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1617
+				: '',
1618
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1619
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1620
+			'TKT_name'            => $ticket->get('TKT_name'),
1621
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1622
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1623
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1624
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1625
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1626
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1627
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1628
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1629
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1630
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1631
+				: ' disabled=disabled',
1632
+		);
1633
+		$price = $ticket->ID() !== 0
1634
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1635
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1636
+		$price_args = array(
1637
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1638
+			'PRC_amount'            => $price->get('PRC_amount'),
1639
+			'PRT_ID'                => $price->get('PRT_ID'),
1640
+			'PRC_ID'                => $price->get('PRC_ID'),
1641
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1642
+		);
1643
+		// make sure we have default start and end dates if skeleton
1644
+		// handle rows that should NOT be empty
1645
+		if (empty($template_args['TKT_start_date'])) {
1646
+			// if empty then the start date will be now.
1647
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1648
+		}
1649
+		if (empty($template_args['TKT_end_date'])) {
1650
+			// get the earliest datetime (if present);
1651
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1652
+				? $this->_cpt_model_obj->get_first_related(
1653
+					'Datetime',
1654
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1655
+				)
1656
+				: null;
1657
+			if (! empty($earliest_dtt)) {
1658
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1659
+			} else {
1660
+				$template_args['TKT_end_date'] = date(
1661
+					'Y-m-d h:i a',
1662
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1663
+				);
1664
+			}
1665
+		}
1666
+		$template_args = array_merge($template_args, $price_args);
1667
+		$template = apply_filters(
1668
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1669
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1670
+			$ticket
1671
+		);
1672
+		return EEH_Template::display_template($template, $template_args, true);
1673
+	}
1674
+
1675
+
1676
+	/**
1677
+	 * @throws DomainException
1678
+	 */
1679
+	public function registration_options_meta_box()
1680
+	{
1681
+		$yes_no_values = array(
1682
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1683
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1684
+		);
1685
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1686
+			array(
1687
+				EEM_Registration::status_id_cancelled,
1688
+				EEM_Registration::status_id_declined,
1689
+				EEM_Registration::status_id_incomplete,
1690
+			),
1691
+			true
1692
+		);
1693
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1694
+		$template_args['_event'] = $this->_cpt_model_obj;
1695
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1696
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1697
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1698
+			'default_reg_status',
1699
+			$default_reg_status_values,
1700
+			$this->_cpt_model_obj->default_registration_status()
1701
+		);
1702
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1703
+			'display_desc',
1704
+			$yes_no_values,
1705
+			$this->_cpt_model_obj->display_description()
1706
+		);
1707
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1708
+			'display_ticket_selector',
1709
+			$yes_no_values,
1710
+			$this->_cpt_model_obj->display_ticket_selector(),
1711
+			'',
1712
+			'',
1713
+			false
1714
+		);
1715
+		$template_args['additional_registration_options'] = apply_filters(
1716
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1717
+			'',
1718
+			$template_args,
1719
+			$yes_no_values,
1720
+			$default_reg_status_values
1721
+		);
1722
+		EEH_Template::display_template(
1723
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1724
+			$template_args
1725
+		);
1726
+	}
1727
+
1728
+
1729
+	/**
1730
+	 * _get_events()
1731
+	 * This method simply returns all the events (for the given _view and paging)
1732
+	 *
1733
+	 * @access public
1734
+	 * @param int  $per_page     count of items per page (20 default);
1735
+	 * @param int  $current_page what is the current page being viewed.
1736
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1737
+	 *                           If FALSE then we return an array of event objects
1738
+	 *                           that match the given _view and paging parameters.
1739
+	 * @return array an array of event objects.
1740
+	 */
1741
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1742
+	{
1743
+		$EEME = $this->_event_model();
1744
+		$offset = ($current_page - 1) * $per_page;
1745
+		$limit = $count ? null : $offset . ',' . $per_page;
1746
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1747
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1748
+		if (isset($this->_req_data['month_range'])) {
1749
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1750
+			// simulate the FIRST day of the month, that fixes issues for months like February
1751
+			// where PHP doesn't know what to assume for date.
1752
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1753
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1754
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1755
+		}
1756
+		$where = array();
1757
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1758
+		// determine what post_status our condition will have for the query.
1759
+		switch ($status) {
1760
+			case 'month':
1761
+			case 'today':
1762
+			case null:
1763
+			case 'all':
1764
+				break;
1765
+			case 'draft':
1766
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1767
+				break;
1768
+			default:
1769
+				$where['status'] = $status;
1770
+		}
1771
+		// categories?
1772
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1773
+			? $this->_req_data['EVT_CAT'] : null;
1774
+		if (! empty($category)) {
1775
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1776
+			$where['Term_Taxonomy.term_id'] = $category;
1777
+		}
1778
+		// date where conditions
1779
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1780
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1781
+			$DateTime = new DateTime(
1782
+				$year_r . '-' . $month_r . '-01 00:00:00',
1783
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1784
+			);
1785
+			$start = $DateTime->format(implode(' ', $start_formats));
1786
+			$end = $DateTime->setDate(
1787
+				$year_r,
1788
+				$month_r,
1789
+				$DateTime
1790
+					->format('t')
1791
+			)->setTime(23, 59, 59)
1792
+							->format(implode(' ', $start_formats));
1793
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1794
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1795
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1796
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1797
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1798
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1799
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1800
+			$now = date('Y-m-01');
1801
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1802
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1803
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1804
+							->setTime(23, 59, 59)
1805
+							->format(implode(' ', $start_formats));
1806
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1807
+		}
1808
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1809
+			$where['EVT_wp_user'] = get_current_user_id();
1810
+		} else {
1811
+			if (! isset($where['status'])) {
1812
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1813
+					$where['OR'] = array(
1814
+						'status*restrict_private' => array('!=', 'private'),
1815
+						'AND'                     => array(
1816
+							'status*inclusive' => array('=', 'private'),
1817
+							'EVT_wp_user'      => get_current_user_id(),
1818
+						),
1819
+					);
1820
+				}
1821
+			}
1822
+		}
1823
+		if (isset($this->_req_data['EVT_wp_user'])) {
1824
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1825
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1826
+			) {
1827
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1828
+			}
1829
+		}
1830
+		// search query handling
1831
+		if (isset($this->_req_data['s'])) {
1832
+			$search_string = '%' . $this->_req_data['s'] . '%';
1833
+			$where['OR'] = array(
1834
+				'EVT_name'       => array('LIKE', $search_string),
1835
+				'EVT_desc'       => array('LIKE', $search_string),
1836
+				'EVT_short_desc' => array('LIKE', $search_string),
1837
+			);
1838
+		}
1839
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1840
+		$query_params = apply_filters(
1841
+			'FHEE__Events_Admin_Page__get_events__query_params',
1842
+			array(
1843
+				$where,
1844
+				'limit'    => $limit,
1845
+				'order_by' => $orderby,
1846
+				'order'    => $order,
1847
+				'group_by' => 'EVT_ID',
1848
+			),
1849
+			$this->_req_data
1850
+		);
1851
+		// let's first check if we have special requests coming in.
1852
+		if (isset($this->_req_data['active_status'])) {
1853
+			switch ($this->_req_data['active_status']) {
1854
+				case 'upcoming':
1855
+					return $EEME->get_upcoming_events($query_params, $count);
1856
+					break;
1857
+				case 'expired':
1858
+					return $EEME->get_expired_events($query_params, $count);
1859
+					break;
1860
+				case 'active':
1861
+					return $EEME->get_active_events($query_params, $count);
1862
+					break;
1863
+				case 'inactive':
1864
+					return $EEME->get_inactive_events($query_params, $count);
1865
+					break;
1866
+			}
1867
+		}
1868
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1869
+		return $events;
1870
+	}
1871
+
1872
+
1873
+	/**
1874
+	 * handling for WordPress CPT actions (trash, restore, delete)
1875
+	 *
1876
+	 * @param string $post_id
1877
+	 */
1878
+	public function trash_cpt_item($post_id)
1879
+	{
1880
+		$this->_req_data['EVT_ID'] = $post_id;
1881
+		$this->_trash_or_restore_event('trash', false);
1882
+	}
1883
+
1884
+
1885
+	/**
1886
+	 * @param string $post_id
1887
+	 */
1888
+	public function restore_cpt_item($post_id)
1889
+	{
1890
+		$this->_req_data['EVT_ID'] = $post_id;
1891
+		$this->_trash_or_restore_event('draft', false);
1892
+	}
1893
+
1894
+
1895
+	/**
1896
+	 * @param string $post_id
1897
+	 */
1898
+	public function delete_cpt_item($post_id)
1899
+	{
1900
+		$this->_req_data['EVT_ID'] = $post_id;
1901
+		$this->_delete_event(false);
1902
+	}
1903
+
1904
+
1905
+	/**
1906
+	 * _trash_or_restore_event
1907
+	 *
1908
+	 * @access protected
1909
+	 * @param  string $event_status
1910
+	 * @param bool    $redirect_after
1911
+	 */
1912
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1913
+	{
1914
+		// determine the event id and set to array.
1915
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1916
+		// loop thru events
1917
+		if ($EVT_ID) {
1918
+			// clean status
1919
+			$event_status = sanitize_key($event_status);
1920
+			// grab status
1921
+			if (! empty($event_status)) {
1922
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1923
+			} else {
1924
+				$success = false;
1925
+				$msg = esc_html__(
1926
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1927
+					'event_espresso'
1928
+				);
1929
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1930
+			}
1931
+		} else {
1932
+			$success = false;
1933
+			$msg = esc_html__(
1934
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1935
+				'event_espresso'
1936
+			);
1937
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1938
+		}
1939
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1940
+		if ($redirect_after) {
1941
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1942
+		}
1943
+	}
1944
+
1945
+
1946
+	/**
1947
+	 * _trash_or_restore_events
1948
+	 *
1949
+	 * @access protected
1950
+	 * @param  string $event_status
1951
+	 * @return void
1952
+	 */
1953
+	protected function _trash_or_restore_events($event_status = 'trash')
1954
+	{
1955
+		// clean status
1956
+		$event_status = sanitize_key($event_status);
1957
+		// grab status
1958
+		if (! empty($event_status)) {
1959
+			$success = true;
1960
+			// determine the event id and set to array.
1961
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1962
+			// loop thru events
1963
+			foreach ($EVT_IDs as $EVT_ID) {
1964
+				if ($EVT_ID = absint($EVT_ID)) {
1965
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1966
+					$success = $results !== false ? $success : false;
1967
+				} else {
1968
+					$msg = sprintf(
1969
+						esc_html__(
1970
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1971
+							'event_espresso'
1972
+						),
1973
+						$EVT_ID
1974
+					);
1975
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1976
+					$success = false;
1977
+				}
1978
+			}
1979
+		} else {
1980
+			$success = false;
1981
+			$msg = esc_html__(
1982
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1983
+				'event_espresso'
1984
+			);
1985
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1986
+		}
1987
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1988
+		$success = $success ? 2 : false;
1989
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1990
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1991
+	}
1992
+
1993
+
1994
+	/**
1995
+	 * _trash_or_restore_events
1996
+	 *
1997
+	 * @access  private
1998
+	 * @param  int    $EVT_ID
1999
+	 * @param  string $event_status
2000
+	 * @return bool
2001
+	 */
2002
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2003
+	{
2004
+		// grab event id
2005
+		if (! $EVT_ID) {
2006
+			$msg = esc_html__(
2007
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2008
+				'event_espresso'
2009
+			);
2010
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2011
+			return false;
2012
+		}
2013
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2014
+		// clean status
2015
+		$event_status = sanitize_key($event_status);
2016
+		// grab status
2017
+		if (empty($event_status)) {
2018
+			$msg = esc_html__(
2019
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2020
+				'event_espresso'
2021
+			);
2022
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2023
+			return false;
2024
+		}
2025
+		// was event trashed or restored ?
2026
+		switch ($event_status) {
2027
+			case 'draft':
2028
+				$action = 'restored from the trash';
2029
+				$hook = 'AHEE_event_restored_from_trash';
2030
+				break;
2031
+			case 'trash':
2032
+				$action = 'moved to the trash';
2033
+				$hook = 'AHEE_event_moved_to_trash';
2034
+				break;
2035
+			default:
2036
+				$action = 'updated';
2037
+				$hook = false;
2038
+		}
2039
+		// use class to change status
2040
+		$this->_cpt_model_obj->set_status($event_status);
2041
+		$success = $this->_cpt_model_obj->save();
2042
+		if ($success === false) {
2043
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2044
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2045
+			return false;
2046
+		}
2047
+		if ($hook) {
2048
+			do_action($hook);
2049
+		}
2050
+		return true;
2051
+	}
2052
+
2053
+
2054
+	/**
2055
+	 * _delete_event
2056
+	 *
2057
+	 * @access protected
2058
+	 * @param bool $redirect_after
2059
+	 */
2060
+	protected function _delete_event($redirect_after = true)
2061
+	{
2062
+		// determine the event id and set to array.
2063
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2064
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2065
+		// loop thru events
2066
+		if ($EVT_ID) {
2067
+			$success = $this->_permanently_delete_event($EVT_ID);
2068
+			// get list of events with no prices
2069
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2070
+			// remove this event from the list of events with no prices
2071
+			if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2072
+				unset($espresso_no_ticket_prices[ $EVT_ID ]);
2073
+			}
2074
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2075
+		} else {
2076
+			$success = false;
2077
+			$msg = esc_html__(
2078
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2079
+				'event_espresso'
2080
+			);
2081
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2082
+		}
2083
+		if ($redirect_after) {
2084
+			$this->_redirect_after_action(
2085
+				$success,
2086
+				'Event',
2087
+				'deleted',
2088
+				array('action' => 'default', 'status' => 'trash')
2089
+			);
2090
+		}
2091
+	}
2092
+
2093
+
2094
+	/**
2095
+	 * _delete_events
2096
+	 *
2097
+	 * @access protected
2098
+	 * @return void
2099
+	 */
2100
+	protected function _delete_events()
2101
+	{
2102
+		$success = true;
2103
+		// get list of events with no prices
2104
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2105
+		// determine the event id and set to array.
2106
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2107
+		// loop thru events
2108
+		foreach ($EVT_IDs as $EVT_ID) {
2109
+			$EVT_ID = absint($EVT_ID);
2110
+			if ($EVT_ID) {
2111
+				$results = $this->_permanently_delete_event($EVT_ID);
2112
+				$success = $results !== false ? $success : false;
2113
+				// remove this event from the list of events with no prices
2114
+				unset($espresso_no_ticket_prices[ $EVT_ID ]);
2115
+			} else {
2116
+				$success = false;
2117
+				$msg = esc_html__(
2118
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2119
+					'event_espresso'
2120
+				);
2121
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2122
+			}
2123
+		}
2124
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2125
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2126
+		$success = $success ? 2 : false;
2127
+		$this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2128
+	}
2129
+
2130
+
2131
+	/**
2132
+	 * _permanently_delete_event
2133
+	 *
2134
+	 * @access  private
2135
+	 * @param  int $EVT_ID
2136
+	 * @return bool
2137
+	 */
2138
+	private function _permanently_delete_event($EVT_ID = 0)
2139
+	{
2140
+		// grab event id
2141
+		if (! $EVT_ID) {
2142
+			$msg = esc_html__(
2143
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2144
+				'event_espresso'
2145
+			);
2146
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2147
+			return false;
2148
+		}
2149
+		if (! $this->_cpt_model_obj instanceof EE_Event
2150
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2151
+		) {
2152
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2153
+		}
2154
+		if (! $this->_cpt_model_obj instanceof EE_Event) {
2155
+			return false;
2156
+		}
2157
+		// need to delete related tickets and prices first.
2158
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2159
+		foreach ($datetimes as $datetime) {
2160
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2161
+			$tickets = $datetime->get_many_related('Ticket');
2162
+			foreach ($tickets as $ticket) {
2163
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2164
+				$ticket->delete_related_permanently('Price');
2165
+				$ticket->delete_permanently();
2166
+			}
2167
+			$datetime->delete();
2168
+		}
2169
+		// what about related venues or terms?
2170
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2171
+		foreach ($venues as $venue) {
2172
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2173
+		}
2174
+		// any attached question groups?
2175
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2176
+		if (! empty($question_groups)) {
2177
+			foreach ($question_groups as $question_group) {
2178
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2179
+			}
2180
+		}
2181
+		// Message Template Groups
2182
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2183
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2184
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2185
+		foreach ($term_taxonomies as $term_taxonomy) {
2186
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2187
+		}
2188
+		$success = $this->_cpt_model_obj->delete_permanently();
2189
+		// did it all go as planned ?
2190
+		if ($success) {
2191
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2192
+			EE_Error::add_success($msg);
2193
+		} else {
2194
+			$msg = sprintf(
2195
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2196
+				$EVT_ID
2197
+			);
2198
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2199
+			return false;
2200
+		}
2201
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2202
+		return true;
2203
+	}
2204
+
2205
+
2206
+	/**
2207
+	 * get total number of events
2208
+	 *
2209
+	 * @access public
2210
+	 * @return int
2211
+	 */
2212
+	public function total_events()
2213
+	{
2214
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2215
+		return $count;
2216
+	}
2217
+
2218
+
2219
+	/**
2220
+	 * get total number of draft events
2221
+	 *
2222
+	 * @access public
2223
+	 * @return int
2224
+	 */
2225
+	public function total_events_draft()
2226
+	{
2227
+		$where = array(
2228
+			'status' => array('IN', array('draft', 'auto-draft')),
2229
+		);
2230
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2231
+		return $count;
2232
+	}
2233
+
2234
+
2235
+	/**
2236
+	 * get total number of trashed events
2237
+	 *
2238
+	 * @access public
2239
+	 * @return int
2240
+	 */
2241
+	public function total_trashed_events()
2242
+	{
2243
+		$where = array(
2244
+			'status' => 'trash',
2245
+		);
2246
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2247
+		return $count;
2248
+	}
2249
+
2250
+
2251
+	/**
2252
+	 *    _default_event_settings
2253
+	 *    This generates the Default Settings Tab
2254
+	 *
2255
+	 * @return void
2256
+	 * @throws EE_Error
2257
+	 */
2258
+	protected function _default_event_settings()
2259
+	{
2260
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2261
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2262
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2263
+		$this->display_admin_page_with_sidebar();
2264
+	}
2265
+
2266
+
2267
+	/**
2268
+	 * Return the form for event settings.
2269
+	 *
2270
+	 * @return EE_Form_Section_Proper
2271
+	 * @throws EE_Error
2272
+	 */
2273
+	protected function _default_event_settings_form()
2274
+	{
2275
+		$registration_config = EE_Registry::instance()->CFG->registration;
2276
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2277
+			// exclude
2278
+			array(
2279
+				EEM_Registration::status_id_cancelled,
2280
+				EEM_Registration::status_id_declined,
2281
+				EEM_Registration::status_id_incomplete,
2282
+				EEM_Registration::status_id_wait_list,
2283
+			),
2284
+			true
2285
+		);
2286
+		return new EE_Form_Section_Proper(
2287
+			array(
2288
+				'name'            => 'update_default_event_settings',
2289
+				'html_id'         => 'update_default_event_settings',
2290
+				'html_class'      => 'form-table',
2291
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2292
+				'subsections'     => apply_filters(
2293
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2294
+					array(
2295
+						'default_reg_status'  => new EE_Select_Input(
2296
+							$registration_stati_for_selection,
2297
+							array(
2298
+								'default'         => isset($registration_config->default_STS_ID)
2299
+													 && array_key_exists(
2300
+														 $registration_config->default_STS_ID,
2301
+														 $registration_stati_for_selection
2302
+													 )
2303
+									? sanitize_text_field($registration_config->default_STS_ID)
2304
+									: EEM_Registration::status_id_pending_payment,
2305
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2306
+													 . EEH_Template::get_help_tab_link(
2307
+														 'default_settings_status_help_tab'
2308
+													 ),
2309
+								'html_help_text'  => esc_html__(
2310
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2311
+									'event_espresso'
2312
+								),
2313
+							)
2314
+						),
2315
+						'default_max_tickets' => new EE_Integer_Input(
2316
+							array(
2317
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2318
+									? $registration_config->default_maximum_number_of_tickets
2319
+									: EEM_Event::get_default_additional_limit(),
2320
+								'html_label_text' => esc_html__(
2321
+									'Default Maximum Tickets Allowed Per Order:',
2322
+									'event_espresso'
2323
+								)
2324
+													 . EEH_Template::get_help_tab_link(
2325
+														 'default_maximum_tickets_help_tab"'
2326
+													 ),
2327
+								'html_help_text'  => esc_html__(
2328
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2329
+									'event_espresso'
2330
+								),
2331
+							)
2332
+						),
2333
+					)
2334
+				),
2335
+			)
2336
+		);
2337
+	}
2338
+
2339
+
2340
+	/**
2341
+	 * _update_default_event_settings
2342
+	 *
2343
+	 * @access protected
2344
+	 * @return void
2345
+	 * @throws EE_Error
2346
+	 */
2347
+	protected function _update_default_event_settings()
2348
+	{
2349
+		$registration_config = EE_Registry::instance()->CFG->registration;
2350
+		$form = $this->_default_event_settings_form();
2351
+		if ($form->was_submitted()) {
2352
+			$form->receive_form_submission();
2353
+			if ($form->is_valid()) {
2354
+				$valid_data = $form->valid_data();
2355
+				if (isset($valid_data['default_reg_status'])) {
2356
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2357
+				}
2358
+				if (isset($valid_data['default_max_tickets'])) {
2359
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2360
+				}
2361
+				// update because data was valid!
2362
+				EE_Registry::instance()->CFG->update_espresso_config();
2363
+				EE_Error::overwrite_success();
2364
+				EE_Error::add_success(
2365
+					__('Default Event Settings were updated', 'event_espresso')
2366
+				);
2367
+			}
2368
+		}
2369
+		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2370
+	}
2371
+
2372
+
2373
+	/*************        Templates        *************/
2374
+	protected function _template_settings()
2375
+	{
2376
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2377
+		$this->_template_args['preview_img'] = '<img src="'
2378
+											   . EVENTS_ASSETS_URL
2379
+											   . DS
2380
+											   . 'images'
2381
+											   . DS
2382
+											   . 'caffeinated_template_features.jpg" alt="'
2383
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2384
+											   . '" />';
2385
+		$this->_template_args['preview_text'] = '<strong>'
2386
+												. esc_html__(
2387
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2388
+													'event_espresso'
2389
+												) . '</strong>';
2390
+		$this->display_admin_caf_preview_page('template_settings_tab');
2391
+	}
2392
+
2393
+
2394
+	/** Event Category Stuff **/
2395
+	/**
2396
+	 * set the _category property with the category object for the loaded page.
2397
+	 *
2398
+	 * @access private
2399
+	 * @return void
2400
+	 */
2401
+	private function _set_category_object()
2402
+	{
2403
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2404
+			return;
2405
+		} //already have the category object so get out.
2406
+		// set default category object
2407
+		$this->_set_empty_category_object();
2408
+		// only set if we've got an id
2409
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2410
+			return;
2411
+		}
2412
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2413
+		$term = get_term($category_id, 'espresso_event_categories');
2414
+		if (! empty($term)) {
2415
+			$this->_category->category_name = $term->name;
2416
+			$this->_category->category_identifier = $term->slug;
2417
+			$this->_category->category_desc = $term->description;
2418
+			$this->_category->id = $term->term_id;
2419
+			$this->_category->parent = $term->parent;
2420
+		}
2421
+	}
2422
+
2423
+
2424
+	/**
2425
+	 * Clears out category properties.
2426
+	 */
2427
+	private function _set_empty_category_object()
2428
+	{
2429
+		$this->_category = new stdClass();
2430
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2431
+		$this->_category->id = $this->_category->parent = 0;
2432
+	}
2433
+
2434
+
2435
+	/**
2436
+	 * @throws EE_Error
2437
+	 */
2438
+	protected function _category_list_table()
2439
+	{
2440
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2441
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2442
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2443
+			'add_category',
2444
+			'add_category',
2445
+			array(),
2446
+			'add-new-h2'
2447
+		);
2448
+		$this->display_admin_list_table_page_with_sidebar();
2449
+	}
2450
+
2451
+
2452
+	/**
2453
+	 * Output category details view.
2454
+	 */
2455
+	protected function _category_details($view)
2456
+	{
2457
+		// load formatter helper
2458
+		// load field generator helper
2459
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2460
+		$this->_set_add_edit_form_tags($route);
2461
+		$this->_set_category_object();
2462
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2463
+		$delete_action = 'delete_category';
2464
+		// custom redirect
2465
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2466
+			array('action' => 'category_list'),
2467
+			$this->_admin_base_url
2468
+		);
2469
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2470
+		// take care of contents
2471
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2472
+		$this->display_admin_page_with_sidebar();
2473
+	}
2474
+
2475
+
2476
+	/**
2477
+	 * Output category details content.
2478
+	 */
2479
+	protected function _category_details_content()
2480
+	{
2481
+		$editor_args['category_desc'] = array(
2482
+			'type'          => 'wp_editor',
2483
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2484
+			'class'         => 'my_editor_custom',
2485
+			'wpeditor_args' => array('media_buttons' => false),
2486
+		);
2487
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2488
+		$all_terms = get_terms(
2489
+			array('espresso_event_categories'),
2490
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2491
+		);
2492
+		// setup category select for term parents.
2493
+		$category_select_values[] = array(
2494
+			'text' => esc_html__('No Parent', 'event_espresso'),
2495
+			'id'   => 0,
2496
+		);
2497
+		foreach ($all_terms as $term) {
2498
+			$category_select_values[] = array(
2499
+				'text' => $term->name,
2500
+				'id'   => $term->term_id,
2501
+			);
2502
+		}
2503
+		$category_select = EEH_Form_Fields::select_input(
2504
+			'category_parent',
2505
+			$category_select_values,
2506
+			$this->_category->parent
2507
+		);
2508
+		$template_args = array(
2509
+			'category'                 => $this->_category,
2510
+			'category_select'          => $category_select,
2511
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2512
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2513
+			'disable'                  => '',
2514
+			'disabled_message'         => false,
2515
+		);
2516
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2517
+		return EEH_Template::display_template($template, $template_args, true);
2518
+	}
2519
+
2520
+
2521
+	/**
2522
+	 * Handles deleting categories.
2523
+	 */
2524
+	protected function _delete_categories()
2525
+	{
2526
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2527
+			: (array) $this->_req_data['category_id'];
2528
+		foreach ($cat_ids as $cat_id) {
2529
+			$this->_delete_category($cat_id);
2530
+		}
2531
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2532
+		$query_args = array(
2533
+			'action' => 'category_list',
2534
+		);
2535
+		$this->_redirect_after_action(0, '', '', $query_args);
2536
+	}
2537
+
2538
+
2539
+	/**
2540
+	 * Handles deleting specific category.
2541
+	 *
2542
+	 * @param int $cat_id
2543
+	 */
2544
+	protected function _delete_category($cat_id)
2545
+	{
2546
+		$cat_id = absint($cat_id);
2547
+		wp_delete_term($cat_id, 'espresso_event_categories');
2548
+	}
2549
+
2550
+
2551
+	/**
2552
+	 * Handles triggering the update or insertion of a new category.
2553
+	 *
2554
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2555
+	 */
2556
+	protected function _insert_or_update_category($new_category)
2557
+	{
2558
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2559
+		$success = 0; // we already have a success message so lets not send another.
2560
+		if ($cat_id) {
2561
+			$query_args = array(
2562
+				'action'     => 'edit_category',
2563
+				'EVT_CAT_ID' => $cat_id,
2564
+			);
2565
+		} else {
2566
+			$query_args = array('action' => 'add_category');
2567
+		}
2568
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2569
+	}
2570
+
2571
+
2572
+	/**
2573
+	 * Inserts or updates category
2574
+	 *
2575
+	 * @param bool $update (true indicates we're updating a category).
2576
+	 * @return bool|mixed|string
2577
+	 */
2578
+	private function _insert_category($update = false)
2579
+	{
2580
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2581
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2582
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2583
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2584
+		if (empty($category_name)) {
2585
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2586
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2587
+			return false;
2588
+		}
2589
+		$term_args = array(
2590
+			'name'        => $category_name,
2591
+			'description' => $category_desc,
2592
+			'parent'      => $category_parent,
2593
+		);
2594
+		// was the category_identifier input disabled?
2595
+		if (isset($this->_req_data['category_identifier'])) {
2596
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2597
+		}
2598
+		$insert_ids = $update
2599
+			? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2600
+			: wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2601
+		if (! is_array($insert_ids)) {
2602
+			$msg = esc_html__(
2603
+				'An error occurred and the category has not been saved to the database.',
2604
+				'event_espresso'
2605
+			);
2606
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2607
+		} else {
2608
+			$cat_id = $insert_ids['term_id'];
2609
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2610
+			EE_Error::add_success($msg);
2611
+		}
2612
+		return $cat_id;
2613
+	}
2614
+
2615
+
2616
+	/**
2617
+	 * Gets categories or count of categories matching the arguments in the request.
2618
+	 *
2619
+	 * @param int  $per_page
2620
+	 * @param int  $current_page
2621
+	 * @param bool $count
2622
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2623
+	 */
2624
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2625
+	{
2626
+		// testing term stuff
2627
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2628
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2629
+		$limit = ($current_page - 1) * $per_page;
2630
+		$where = array('taxonomy' => 'espresso_event_categories');
2631
+		if (isset($this->_req_data['s'])) {
2632
+			$sstr = '%' . $this->_req_data['s'] . '%';
2633
+			$where['OR'] = array(
2634
+				'Term.name'   => array('LIKE', $sstr),
2635
+				'description' => array('LIKE', $sstr),
2636
+			);
2637
+		}
2638
+		$query_params = array(
2639
+			$where,
2640
+			'order_by'   => array($orderby => $order),
2641
+			'limit'      => $limit . ',' . $per_page,
2642
+			'force_join' => array('Term'),
2643
+		);
2644
+		$categories = $count
2645
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2646
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2647
+		return $categories;
2648
+	}
2649
+
2650
+	/* end category stuff */
2651
+	/**************/
2652
+
2653
+
2654
+	/**
2655
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2656
+	 *
2657
+	 * @throws EE_Error
2658
+	 */
2659
+	public function save_timezonestring_setting()
2660
+	{
2661
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2662
+			? $this->_req_data['timezone_selected']
2663
+			: '';
2664
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2665
+			EE_Error::add_error(
2666
+				esc_html('An invalid timezone string submitted.', 'event_espresso'),
2667
+				__FILE__,
2668
+				__FUNCTION__,
2669
+				__LINE__
2670
+			);
2671
+			$this->_template_args['error'] = true;
2672
+			$this->_return_json();
2673
+		}
2674
+
2675
+		update_option('timezone_string', $timezone_string);
2676
+		EE_Error::add_success(
2677
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2678
+		);
2679
+		$this->_template_args['success'] = true;
2680
+		$this->_return_json(true, array('action' => 'create_new'));
2681
+	}
2682 2682
 }
Please login to merge, or discard this patch.
core/EE_Config.core.php 2 patches
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
     public static function instance()
146 146
     {
147 147
         // check if class object is instantiated, and instantiated properly
148
-        if (! self::$_instance instanceof EE_Config) {
148
+        if ( ! self::$_instance instanceof EE_Config) {
149 149
             self::$_instance = new self();
150 150
         }
151 151
         return self::$_instance;
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 $this
284 284
             );
285 285
             if (is_object($settings) && property_exists($this, $config)) {
286
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
286
+                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings);
287 287
                 // call configs populate method to ensure any defaults are set for empty values.
288 288
                 if (method_exists($settings, 'populate')) {
289 289
                     $this->{$config}->populate();
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
                         break;
557 557
                     // TEST #2 : check that settings section exists
558 558
                     case 2:
559
-                        if (! isset($this->{$section})) {
559
+                        if ( ! isset($this->{$section})) {
560 560
                             if ($display_errors) {
561 561
                                 throw new EE_Error(
562 562
                                     sprintf(
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
                         break;
571 571
                     // TEST #3 : check that section is the proper format
572 572
                     case 3:
573
-                        if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
573
+                        if ( ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574 574
                         ) {
575 575
                             if ($display_errors) {
576 576
                                 throw new EE_Error(
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
                         break;
617 617
                     // TEST #6 : verify config class is accessible
618 618
                     case 6:
619
-                        if (! class_exists($config_class)) {
619
+                        if ( ! class_exists($config_class)) {
620 620
                             if ($display_errors) {
621 621
                                 throw new EE_Error(
622 622
                                     sprintf(
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
                         break;
634 634
                     // TEST #7 : check that config has even been set
635 635
                     case 7:
636
-                        if (! isset($this->{$section}->{$name})) {
636
+                        if ( ! isset($this->{$section}->{$name})) {
637 637
                             if ($display_errors) {
638 638
                                 throw new EE_Error(
639 639
                                     sprintf(
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
                         break;
652 652
                     // TEST #8 : check that config is the requested type
653 653
                     case 8:
654
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
654
+                        if ( ! $this->{$section}->{$name} instanceof $config_class) {
655 655
                             if ($display_errors) {
656 656
                                 throw new EE_Error(
657 657
                                     sprintf(
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
                         break;
671 671
                     // TEST #9 : verify config object
672 672
                     case 9:
673
-                        if (! $config_obj instanceof EE_Config_Base) {
673
+                        if ( ! $config_obj instanceof EE_Config_Base) {
674 674
                             if ($display_errors) {
675 675
                                 throw new EE_Error(
676 676
                                     sprintf(
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
      */
703 703
     private function _generate_config_option_name($section = '', $name = '')
704 704
     {
705
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
705
+        return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name));
706 706
     }
707 707
 
708 708
 
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
     {
720 720
         return ! empty($config_class)
721 721
             ? $config_class
722
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
722
+            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config';
723 723
     }
724 724
 
725 725
 
@@ -738,17 +738,17 @@  discard block
 block discarded – undo
738 738
         // ensure config class is set to something
739 739
         $config_class = $this->_set_config_class($config_class, $name);
740 740
         // run tests 1-4, 6, and 7 to verify all config params are set and valid
741
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
741
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742 742
             return null;
743 743
         }
744 744
         $config_option_name = $this->_generate_config_option_name($section, $name);
745 745
         // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
746
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
747
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
746
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
747
+            $this->_addon_option_names[$config_option_name] = $config_class;
748 748
             $this->update_addon_option_names();
749 749
         }
750 750
         // verify the incoming config object but suppress errors
751
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
751
+        if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752 752
             $config_obj = new $config_class();
753 753
         }
754 754
         if (get_option($config_option_name)) {
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
         // get class name of the incoming object
796 796
         $config_class = get_class($config_obj);
797 797
         // run tests 1-5 and 9 to verify config
798
-        if (! $this->_verify_config_params(
798
+        if ( ! $this->_verify_config_params(
799 799
             $section,
800 800
             $name,
801 801
             $config_class,
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
         }
808 808
         $config_option_name = $this->_generate_config_option_name($section, $name);
809 809
         // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
810
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
810
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
811 811
             // save new config to db
812 812
             if ($this->set_config($section, $name, $config_class, $config_obj)) {
813 813
                 return true;
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
                             'event_espresso'
834 834
                         ),
835 835
                         $config_class,
836
-                        'EE_Config->' . $section . '->' . $name
836
+                        'EE_Config->'.$section.'->'.$name
837 837
                     ),
838 838
                     __FILE__,
839 839
                     __FUNCTION__,
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
         // ensure config class is set to something
860 860
         $config_class = $this->_set_config_class($config_class, $name);
861 861
         // run tests 1-4, 6 and 7 to verify that all params have been set
862
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
862
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863 863
             return null;
864 864
         }
865 865
         // now test if the requested config object exists, but suppress errors
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
         // retrieve the wp-option for this config class.
905 905
         $config_option = maybe_unserialize(get_option($config_option_name, array()));
906 906
         if (empty($config_option)) {
907
-            EE_Config::log($config_option_name . '-NOT-FOUND');
907
+            EE_Config::log($config_option_name.'-NOT-FOUND');
908 908
         }
909 909
         return $config_option;
910 910
     }
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
             // copy incoming $_REQUEST and sanitize it so we can save it
923 923
             $_request = $_REQUEST;
924 924
             array_walk_recursive($_request, 'sanitize_text_field');
925
-            $config_log[ (string) microtime(true) ] = array(
925
+            $config_log[(string) microtime(true)] = array(
926 926
                 'config_name' => $config_option_name,
927 927
                 'request'     => $_request,
928 928
             );
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
      */
938 938
     public static function trim_log()
939 939
     {
940
-        if (! EE_Config::logging_enabled()) {
940
+        if ( ! EE_Config::logging_enabled()) {
941 941
             return;
942 942
         }
943 943
         $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
     public static function get_page_for_posts()
962 962
     {
963 963
         $page_for_posts = get_option('page_for_posts');
964
-        if (! $page_for_posts) {
964
+        if ( ! $page_for_posts) {
965 965
             return 'posts';
966 966
         }
967 967
         /** @type WPDB $wpdb */
@@ -1011,20 +1011,20 @@  discard block
 block discarded – undo
1011 1011
     {
1012 1012
         // only init widgets on admin pages when not in complete maintenance, and
1013 1013
         // on frontend when not in any maintenance mode
1014
-        if (! EE_Maintenance_Mode::instance()->level()
1014
+        if ( ! EE_Maintenance_Mode::instance()->level()
1015 1015
             || (
1016 1016
                 is_admin()
1017 1017
                 && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018 1018
             )
1019 1019
         ) {
1020 1020
             // grab list of installed widgets
1021
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1021
+            $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR);
1022 1022
             // filter list of modules to register
1023 1023
             $widgets_to_register = apply_filters(
1024 1024
                 'FHEE__EE_Config__register_widgets__widgets_to_register',
1025 1025
                 $widgets_to_register
1026 1026
             );
1027
-            if (! empty($widgets_to_register)) {
1027
+            if ( ! empty($widgets_to_register)) {
1028 1028
                 // cycle thru widget folders
1029 1029
                 foreach ($widgets_to_register as $widget_path) {
1030 1030
                     // add to list of installed widget modules
@@ -1074,31 +1074,31 @@  discard block
 block discarded – undo
1074 1074
         // create classname from widget directory name
1075 1075
         $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076 1076
         // add class prefix
1077
-        $widget_class = 'EEW_' . $widget;
1077
+        $widget_class = 'EEW_'.$widget;
1078 1078
         // does the widget exist ?
1079
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1079
+        if ( ! is_readable($widget_path.DS.$widget_class.$widget_ext)) {
1080 1080
             $msg = sprintf(
1081 1081
                 __(
1082 1082
                     'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1083 1083
                     'event_espresso'
1084 1084
                 ),
1085 1085
                 $widget_class,
1086
-                $widget_path . DS . $widget_class . $widget_ext
1086
+                $widget_path.DS.$widget_class.$widget_ext
1087 1087
             );
1088
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1088
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1089 1089
             return;
1090 1090
         }
1091 1091
         // load the widget class file
1092
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1092
+        require_once($widget_path.DS.$widget_class.$widget_ext);
1093 1093
         // verify that class exists
1094
-        if (! class_exists($widget_class)) {
1094
+        if ( ! class_exists($widget_class)) {
1095 1095
             $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1096
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1096
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1097 1097
             return;
1098 1098
         }
1099 1099
         register_widget($widget_class);
1100 1100
         // add to array of registered widgets
1101
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1101
+        EE_Registry::instance()->widgets->{$widget_class} = $widget_path.DS.$widget_class.$widget_ext;
1102 1102
     }
1103 1103
 
1104 1104
 
@@ -1111,18 +1111,18 @@  discard block
 block discarded – undo
1111 1111
     private function _register_modules()
1112 1112
     {
1113 1113
         // grab list of installed modules
1114
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1114
+        $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR);
1115 1115
         // filter list of modules to register
1116 1116
         $modules_to_register = apply_filters(
1117 1117
             'FHEE__EE_Config__register_modules__modules_to_register',
1118 1118
             $modules_to_register
1119 1119
         );
1120
-        if (! empty($modules_to_register)) {
1120
+        if ( ! empty($modules_to_register)) {
1121 1121
             // loop through folders
1122 1122
             foreach ($modules_to_register as $module_path) {
1123 1123
                 /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1124
-                if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1125
-                    && $module_path !== EE_MODULES . 'gateways'
1124
+                if ($module_path !== EE_MODULES.'zzz-copy-this-module-template'
1125
+                    && $module_path !== EE_MODULES.'gateways'
1126 1126
                 ) {
1127 1127
                     // add to list of installed modules
1128 1128
                     EE_Config::register_module($module_path);
@@ -1159,25 +1159,25 @@  discard block
 block discarded – undo
1159 1159
             // remove last segment
1160 1160
             array_pop($module_path);
1161 1161
             // glue it back together
1162
-            $module_path = implode(DS, $module_path) . DS;
1162
+            $module_path = implode(DS, $module_path).DS;
1163 1163
             // take first segment from file name pieces and sanitize it
1164 1164
             $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165 1165
             // ensure class prefix is added
1166
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1166
+            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module;
1167 1167
         } else {
1168 1168
             // we need to generate the filename based off of the folder name
1169 1169
             // grab and sanitize module name
1170 1170
             $module = strtolower(basename($module_path));
1171 1171
             $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172 1172
             // like trailingslashit()
1173
-            $module_path = rtrim($module_path, DS) . DS;
1173
+            $module_path = rtrim($module_path, DS).DS;
1174 1174
             // create classname from module directory name
1175 1175
             $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176 1176
             // add class prefix
1177
-            $module_class = 'EED_' . $module;
1177
+            $module_class = 'EED_'.$module;
1178 1178
         }
1179 1179
         // does the module exist ?
1180
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1180
+        if ( ! is_readable($module_path.DS.$module_class.$module_ext)) {
1181 1181
             $msg = sprintf(
1182 1182
                 __(
1183 1183
                     'The requested %s module file could not be found or is not readable due to file permissions.',
@@ -1185,19 +1185,19 @@  discard block
 block discarded – undo
1185 1185
                 ),
1186 1186
                 $module
1187 1187
             );
1188
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1188
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1189 1189
             return false;
1190 1190
         }
1191 1191
         // load the module class file
1192
-        require_once($module_path . $module_class . $module_ext);
1192
+        require_once($module_path.$module_class.$module_ext);
1193 1193
         // verify that class exists
1194
-        if (! class_exists($module_class)) {
1194
+        if ( ! class_exists($module_class)) {
1195 1195
             $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1196
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1196
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1197 1197
             return false;
1198 1198
         }
1199 1199
         // add to array of registered modules
1200
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1200
+        EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext;
1201 1201
         do_action(
1202 1202
             'AHEE__EE_Config__register_module__complete',
1203 1203
             $module_class,
@@ -1248,26 +1248,26 @@  discard block
 block discarded – undo
1248 1248
     {
1249 1249
         do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250 1250
         $module = str_replace('EED_', '', $module);
1251
-        $module_class = 'EED_' . $module;
1252
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1251
+        $module_class = 'EED_'.$module;
1252
+        if ( ! isset(EE_Registry::instance()->modules->{$module_class})) {
1253 1253
             $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1254
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1255 1255
             return false;
1256 1256
         }
1257 1257
         if (empty($route)) {
1258 1258
             $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1259
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1260 1260
             return false;
1261 1261
         }
1262
-        if (! method_exists('EED_' . $module, $method_name)) {
1262
+        if ( ! method_exists('EED_'.$module, $method_name)) {
1263 1263
             $msg = sprintf(
1264 1264
                 __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265 1265
                 $route
1266 1266
             );
1267
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1267
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1268 1268
             return false;
1269 1269
         }
1270
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1270
+        EE_Config::$_module_route_map[(string) $key][(string) $route] = array('EED_'.$module, $method_name);
1271 1271
         return true;
1272 1272
     }
1273 1273
 
@@ -1284,8 +1284,8 @@  discard block
 block discarded – undo
1284 1284
     {
1285 1285
         do_action('AHEE__EE_Config__get_route__begin', $route);
1286 1286
         $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1287
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1288
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1287
+        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1288
+            return EE_Config::$_module_route_map[$key][$route];
1289 1289
         }
1290 1290
         return null;
1291 1291
     }
@@ -1317,47 +1317,47 @@  discard block
 block discarded – undo
1317 1317
     public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318 1318
     {
1319 1319
         do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1320
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1321 1321
             $msg = sprintf(
1322 1322
                 __('The module route %s for this forward has not been registered.', 'event_espresso'),
1323 1323
                 $route
1324 1324
             );
1325
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1325
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1326 1326
             return false;
1327 1327
         }
1328 1328
         if (empty($forward)) {
1329 1329
             $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1330
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1331 1331
             return false;
1332 1332
         }
1333 1333
         if (is_array($forward)) {
1334
-            if (! isset($forward[1])) {
1334
+            if ( ! isset($forward[1])) {
1335 1335
                 $msg = sprintf(
1336 1336
                     __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337 1337
                     $route
1338 1338
                 );
1339
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1339
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1340 1340
                 return false;
1341 1341
             }
1342
-            if (! method_exists($forward[0], $forward[1])) {
1342
+            if ( ! method_exists($forward[0], $forward[1])) {
1343 1343
                 $msg = sprintf(
1344 1344
                     __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345 1345
                     $forward[1],
1346 1346
                     $route
1347 1347
                 );
1348
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1348
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1349 1349
                 return false;
1350 1350
             }
1351
-        } elseif (! function_exists($forward)) {
1351
+        } elseif ( ! function_exists($forward)) {
1352 1352
             $msg = sprintf(
1353 1353
                 __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354 1354
                 $forward,
1355 1355
                 $route
1356 1356
             );
1357
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1357
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1358 1358
             return false;
1359 1359
         }
1360
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1360
+        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1361 1361
         return true;
1362 1362
     }
1363 1363
 
@@ -1375,10 +1375,10 @@  discard block
 block discarded – undo
1375 1375
     public static function get_forward($route = null, $status = 0, $key = 'ee')
1376 1376
     {
1377 1377
         do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1378
+        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1379 1379
             return apply_filters(
1380 1380
                 'FHEE__EE_Config__get_forward',
1381
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1381
+                EE_Config::$_module_forward_map[$key][$route][$status],
1382 1382
                 $route,
1383 1383
                 $status
1384 1384
             );
@@ -1402,15 +1402,15 @@  discard block
 block discarded – undo
1402 1402
     public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403 1403
     {
1404 1404
         do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1405
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1406 1406
             $msg = sprintf(
1407 1407
                 __('The module route %s for this view has not been registered.', 'event_espresso'),
1408 1408
                 $route
1409 1409
             );
1410
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1410
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1411 1411
             return false;
1412 1412
         }
1413
-        if (! is_readable($view)) {
1413
+        if ( ! is_readable($view)) {
1414 1414
             $msg = sprintf(
1415 1415
                 __(
1416 1416
                     'The %s view file could not be found or is not readable due to file permissions.',
@@ -1418,10 +1418,10 @@  discard block
 block discarded – undo
1418 1418
                 ),
1419 1419
                 $view
1420 1420
             );
1421
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1421
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1422 1422
             return false;
1423 1423
         }
1424
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1424
+        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1425 1425
         return true;
1426 1426
     }
1427 1427
 
@@ -1439,10 +1439,10 @@  discard block
 block discarded – undo
1439 1439
     public static function get_view($route = null, $status = 0, $key = 'ee')
1440 1440
     {
1441 1441
         do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1442
+        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1443 1443
             return apply_filters(
1444 1444
                 'FHEE__EE_Config__get_view',
1445
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1445
+                EE_Config::$_module_view_map[$key][$route][$status],
1446 1446
                 $route,
1447 1447
                 $status
1448 1448
             );
@@ -1469,7 +1469,7 @@  discard block
 block discarded – undo
1469 1469
     public static function getLegacyShortcodesManager()
1470 1470
     {
1471 1471
 
1472
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1472
+        if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473 1473
             EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474 1474
                 EE_Registry::instance()
1475 1475
             );
@@ -1516,7 +1516,7 @@  discard block
 block discarded – undo
1516 1516
      */
1517 1517
     public function get_pretty($property)
1518 1518
     {
1519
-        if (! property_exists($this, $property)) {
1519
+        if ( ! property_exists($this, $property)) {
1520 1520
             throw new EE_Error(
1521 1521
                 sprintf(
1522 1522
                     __(
@@ -1745,11 +1745,11 @@  discard block
 block discarded – undo
1745 1745
      */
1746 1746
     public function reg_page_url()
1747 1747
     {
1748
-        if (! $this->reg_page_url) {
1748
+        if ( ! $this->reg_page_url) {
1749 1749
             $this->reg_page_url = add_query_arg(
1750 1750
                 array('uts' => time()),
1751 1751
                 get_permalink($this->reg_page_id)
1752
-            ) . '#checkout';
1752
+            ).'#checkout';
1753 1753
         }
1754 1754
         return $this->reg_page_url;
1755 1755
     }
@@ -1765,7 +1765,7 @@  discard block
 block discarded – undo
1765 1765
      */
1766 1766
     public function txn_page_url($query_args = array())
1767 1767
     {
1768
-        if (! $this->txn_page_url) {
1768
+        if ( ! $this->txn_page_url) {
1769 1769
             $this->txn_page_url = get_permalink($this->txn_page_id);
1770 1770
         }
1771 1771
         if ($query_args) {
@@ -1786,7 +1786,7 @@  discard block
 block discarded – undo
1786 1786
      */
1787 1787
     public function thank_you_page_url($query_args = array())
1788 1788
     {
1789
-        if (! $this->thank_you_page_url) {
1789
+        if ( ! $this->thank_you_page_url) {
1790 1790
             $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791 1791
         }
1792 1792
         if ($query_args) {
@@ -1805,7 +1805,7 @@  discard block
 block discarded – undo
1805 1805
      */
1806 1806
     public function cancel_page_url()
1807 1807
     {
1808
-        if (! $this->cancel_page_url) {
1808
+        if ( ! $this->cancel_page_url) {
1809 1809
             $this->cancel_page_url = get_permalink($this->cancel_page_id);
1810 1810
         }
1811 1811
         return $this->cancel_page_url;
@@ -1848,13 +1848,13 @@  discard block
 block discarded – undo
1848 1848
         $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849 1849
         $option = self::OPTION_NAME_UXIP;
1850 1850
         // set correct table for query
1851
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1851
+        $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options';
1852 1852
         // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853 1853
         // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854 1854
         // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855 1855
         // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856 1856
         // for the purpose of caching.
1857
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1857
+        $pre = apply_filters('pre_option_'.$option, false, $option);
1858 1858
         if (false !== $pre) {
1859 1859
             EE_Core_Config::$ee_ueip_option = $pre;
1860 1860
             return EE_Core_Config::$ee_ueip_option;
@@ -1868,10 +1868,10 @@  discard block
 block discarded – undo
1868 1868
         if (is_object($row)) {
1869 1869
             $value = $row->option_value;
1870 1870
         } else { // option does not exist so use default.
1871
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1871
+            EE_Core_Config::$ee_ueip_option = apply_filters('default_option_'.$option, false, $option);
1872 1872
             return EE_Core_Config::$ee_ueip_option;
1873 1873
         }
1874
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1874
+        EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option);
1875 1875
         return EE_Core_Config::$ee_ueip_option;
1876 1876
     }
1877 1877
 
@@ -2125,37 +2125,37 @@  discard block
 block discarded – undo
2125 2125
         // but override if requested
2126 2126
         $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127 2127
         // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2128
-        if (! empty($CNT_ISO)
2128
+        if ( ! empty($CNT_ISO)
2129 2129
             && EE_Maintenance_Mode::instance()->models_can_query()
2130 2130
             && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131 2131
         ) {
2132 2132
             // retrieve the country settings from the db, just in case they have been customized
2133 2133
             $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134 2134
             if ($country instanceof EE_Country) {
2135
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2136
-                $this->name = $country->currency_name_single();    // Dollar
2137
-                $this->plural = $country->currency_name_plural();    // Dollars
2138
-                $this->sign = $country->currency_sign();            // currency sign: $
2135
+                $this->code = $country->currency_code(); // currency code: USD, CAD, EUR
2136
+                $this->name = $country->currency_name_single(); // Dollar
2137
+                $this->plural = $country->currency_name_plural(); // Dollars
2138
+                $this->sign = $country->currency_sign(); // currency sign: $
2139 2139
                 $this->sign_b4 = $country->currency_sign_before(
2140
-                );        // currency sign before or after: $TRUE  or  FALSE$
2141
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2140
+                ); // currency sign before or after: $TRUE  or  FALSE$
2141
+                $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00  3 = 0.000
2142 2142
                 $this->dec_mrk = $country->currency_decimal_mark(
2143
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2143
+                ); // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144 2144
                 $this->thsnds = $country->currency_thousands_separator(
2145
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2145
+                ); // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146 2146
             }
2147 2147
         }
2148 2148
         // fallback to hardcoded defaults, in case the above failed
2149 2149
         if (empty($this->code)) {
2150 2150
             // set default currency settings
2151
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2152
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2153
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2154
-            $this->sign = '$';    // currency sign: $
2155
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2156
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2157
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2151
+            $this->code = 'USD'; // currency code: USD, CAD, EUR
2152
+            $this->name = __('Dollar', 'event_espresso'); // Dollar
2153
+            $this->plural = __('Dollars', 'event_espresso'); // Dollars
2154
+            $this->sign = '$'; // currency sign: $
2155
+            $this->sign_b4 = true; // currency sign before or after: $TRUE  or  FALSE$
2156
+            $this->dec_plc = 2; // decimal places: 2 = 0.00  3 = 0.000
2157
+            $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
+            $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159 2159
         }
2160 2160
     }
2161 2161
 }
@@ -2414,8 +2414,8 @@  discard block
 block discarded – undo
2414 2414
             $closing_a_tag = '';
2415 2415
             if (function_exists('get_privacy_policy_url')) {
2416 2416
                 $privacy_page_url = get_privacy_policy_url();
2417
-                if (! empty($privacy_page_url)) {
2418
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2417
+                if ( ! empty($privacy_page_url)) {
2418
+                    $opening_a_tag = '<a href="'.$privacy_page_url.'" target="_blank">';
2419 2419
                     $closing_a_tag = '</a>';
2420 2420
                 }
2421 2421
             }
@@ -2627,7 +2627,7 @@  discard block
 block discarded – undo
2627 2627
     public function log_file_name($reset = false)
2628 2628
     {
2629 2629
         if (empty($this->log_file_name) || $reset) {
2630
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2630
+            $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt';
2631 2631
             EE_Config::instance()->update_espresso_config(false, false);
2632 2632
         }
2633 2633
         return $this->log_file_name;
@@ -2641,7 +2641,7 @@  discard block
 block discarded – undo
2641 2641
     public function debug_file_name($reset = false)
2642 2642
     {
2643 2643
         if (empty($this->debug_file_name) || $reset) {
2644
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2644
+            $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt';
2645 2645
             EE_Config::instance()->update_espresso_config(false, false);
2646 2646
         }
2647 2647
         return $this->debug_file_name;
@@ -2845,21 +2845,21 @@  discard block
 block discarded – undo
2845 2845
         $this->use_google_maps = true;
2846 2846
         $this->google_map_api_key = '';
2847 2847
         // for event details pages (reg page)
2848
-        $this->event_details_map_width = 585;            // ee_map_width_single
2849
-        $this->event_details_map_height = 362;            // ee_map_height_single
2850
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2851
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2852
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2853
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2854
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2848
+        $this->event_details_map_width = 585; // ee_map_width_single
2849
+        $this->event_details_map_height = 362; // ee_map_height_single
2850
+        $this->event_details_map_zoom = 14; // ee_map_zoom_single
2851
+        $this->event_details_display_nav = true; // ee_map_nav_display_single
2852
+        $this->event_details_nav_size = false; // ee_map_nav_size_single
2853
+        $this->event_details_control_type = 'default'; // ee_map_type_control_single
2854
+        $this->event_details_map_align = 'center'; // ee_map_align_single
2855 2855
         // for event list pages
2856
-        $this->event_list_map_width = 300;            // ee_map_width
2857
-        $this->event_list_map_height = 185;        // ee_map_height
2858
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2859
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2860
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2861
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2862
-        $this->event_list_map_align = 'center';            // ee_map_align
2856
+        $this->event_list_map_width = 300; // ee_map_width
2857
+        $this->event_list_map_height = 185; // ee_map_height
2858
+        $this->event_list_map_zoom = 12; // ee_map_zoom
2859
+        $this->event_list_display_nav = false; // ee_map_nav_display
2860
+        $this->event_list_nav_size = true; // ee_map_nav_size
2861
+        $this->event_list_control_type = 'dropdown'; // ee_map_type_control
2862
+        $this->event_list_map_align = 'center'; // ee_map_align
2863 2863
     }
2864 2864
 }
2865 2865
 
@@ -3177,7 +3177,7 @@  discard block
 block discarded – undo
3177 3177
      */
3178 3178
     public function max_input_vars_limit_check($input_count = 0)
3179 3179
     {
3180
-        if (! empty($this->php->max_input_vars)
3180
+        if ( ! empty($this->php->max_input_vars)
3181 3181
             && ($input_count >= $this->php->max_input_vars)
3182 3182
         ) {
3183 3183
             // check the server setting because the config value could be stale
Please login to merge, or discard this patch.
Indentation   +3151 added lines, -3151 removed lines patch added patch discarded remove patch
@@ -14,2509 +14,2509 @@  discard block
 block discarded – undo
14 14
 final class EE_Config implements ResettableInterface
15 15
 {
16 16
 
17
-    const OPTION_NAME = 'ee_config';
18
-
19
-    const LOG_NAME = 'ee_config_log';
20
-
21
-    const LOG_LENGTH = 100;
22
-
23
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
24
-
25
-    /**
26
-     *    instance of the EE_Config object
27
-     *
28
-     * @var    EE_Config $_instance
29
-     * @access    private
30
-     */
31
-    private static $_instance;
32
-
33
-    /**
34
-     * @var boolean $_logging_enabled
35
-     */
36
-    private static $_logging_enabled = false;
37
-
38
-    /**
39
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
40
-     */
41
-    private $legacy_shortcodes_manager;
42
-
43
-    /**
44
-     * An StdClass whose property names are addon slugs,
45
-     * and values are their config classes
46
-     *
47
-     * @var StdClass
48
-     */
49
-    public $addons;
50
-
51
-    /**
52
-     * @var EE_Admin_Config
53
-     */
54
-    public $admin;
55
-
56
-    /**
57
-     * @var EE_Core_Config
58
-     */
59
-    public $core;
60
-
61
-    /**
62
-     * @var EE_Currency_Config
63
-     */
64
-    public $currency;
65
-
66
-    /**
67
-     * @var EE_Organization_Config
68
-     */
69
-    public $organization;
70
-
71
-    /**
72
-     * @var EE_Registration_Config
73
-     */
74
-    public $registration;
75
-
76
-    /**
77
-     * @var EE_Template_Config
78
-     */
79
-    public $template_settings;
80
-
81
-    /**
82
-     * Holds EE environment values.
83
-     *
84
-     * @var EE_Environment_Config
85
-     */
86
-    public $environment;
87
-
88
-    /**
89
-     * settings pertaining to Google maps
90
-     *
91
-     * @var EE_Map_Config
92
-     */
93
-    public $map_settings;
94
-
95
-    /**
96
-     * settings pertaining to Taxes
97
-     *
98
-     * @var EE_Tax_Config
99
-     */
100
-    public $tax_settings;
101
-
102
-    /**
103
-     * Settings pertaining to global messages settings.
104
-     *
105
-     * @var EE_Messages_Config
106
-     */
107
-    public $messages;
108
-
109
-    /**
110
-     * @deprecated
111
-     * @var EE_Gateway_Config
112
-     */
113
-    public $gateway;
114
-
115
-    /**
116
-     * @var    array $_addon_option_names
117
-     * @access    private
118
-     */
119
-    private $_addon_option_names = array();
120
-
121
-    /**
122
-     * @var    array $_module_route_map
123
-     * @access    private
124
-     */
125
-    private static $_module_route_map = array();
126
-
127
-    /**
128
-     * @var    array $_module_forward_map
129
-     * @access    private
130
-     */
131
-    private static $_module_forward_map = array();
132
-
133
-    /**
134
-     * @var    array $_module_view_map
135
-     * @access    private
136
-     */
137
-    private static $_module_view_map = array();
138
-
139
-
140
-    /**
141
-     * @singleton method used to instantiate class object
142
-     * @access    public
143
-     * @return EE_Config instance
144
-     */
145
-    public static function instance()
146
-    {
147
-        // check if class object is instantiated, and instantiated properly
148
-        if (! self::$_instance instanceof EE_Config) {
149
-            self::$_instance = new self();
150
-        }
151
-        return self::$_instance;
152
-    }
153
-
154
-
155
-    /**
156
-     * Resets the config
157
-     *
158
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
159
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
160
-     *                               reflect its state in the database
161
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
162
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
163
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
164
-     *                               site was put into maintenance mode)
165
-     * @return EE_Config
166
-     */
167
-    public static function reset($hard_reset = false, $reinstantiate = true)
168
-    {
169
-        if (self::$_instance instanceof EE_Config) {
170
-            if ($hard_reset) {
171
-                self::$_instance->legacy_shortcodes_manager = null;
172
-                self::$_instance->_addon_option_names = array();
173
-                self::$_instance->_initialize_config();
174
-                self::$_instance->update_espresso_config();
175
-            }
176
-            self::$_instance->update_addon_option_names();
177
-        }
178
-        self::$_instance = null;
179
-        // we don't need to reset the static properties imo because those should
180
-        // only change when a module is added or removed. Currently we don't
181
-        // support removing a module during a request when it previously existed
182
-        if ($reinstantiate) {
183
-            return self::instance();
184
-        } else {
185
-            return null;
186
-        }
187
-    }
188
-
189
-
190
-    /**
191
-     *    class constructor
192
-     *
193
-     * @access    private
194
-     */
195
-    private function __construct()
196
-    {
197
-        do_action('AHEE__EE_Config__construct__begin', $this);
198
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
199
-        // setup empty config classes
200
-        $this->_initialize_config();
201
-        // load existing EE site settings
202
-        $this->_load_core_config();
203
-        // confirm everything loaded correctly and set filtered defaults if not
204
-        $this->_verify_config();
205
-        //  register shortcodes and modules
206
-        add_action(
207
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
208
-            array($this, 'register_shortcodes_and_modules'),
209
-            999
210
-        );
211
-        //  initialize shortcodes and modules
212
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
213
-        // register widgets
214
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
215
-        // shutdown
216
-        add_action('shutdown', array($this, 'shutdown'), 10);
217
-        // construct__end hook
218
-        do_action('AHEE__EE_Config__construct__end', $this);
219
-        // hardcoded hack
220
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
221
-    }
222
-
223
-
224
-    /**
225
-     * @return boolean
226
-     */
227
-    public static function logging_enabled()
228
-    {
229
-        return self::$_logging_enabled;
230
-    }
231
-
232
-
233
-    /**
234
-     * use to get the current theme if needed from static context
235
-     *
236
-     * @return string current theme set.
237
-     */
238
-    public static function get_current_theme()
239
-    {
240
-        return isset(self::$_instance->template_settings->current_espresso_theme)
241
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
242
-    }
243
-
244
-
245
-    /**
246
-     *        _initialize_config
247
-     *
248
-     * @access private
249
-     * @return void
250
-     */
251
-    private function _initialize_config()
252
-    {
253
-        EE_Config::trim_log();
254
-        // set defaults
255
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
256
-        $this->addons = new stdClass();
257
-        // set _module_route_map
258
-        EE_Config::$_module_route_map = array();
259
-        // set _module_forward_map
260
-        EE_Config::$_module_forward_map = array();
261
-        // set _module_view_map
262
-        EE_Config::$_module_view_map = array();
263
-    }
264
-
265
-
266
-    /**
267
-     *        load core plugin configuration
268
-     *
269
-     * @access private
270
-     * @return void
271
-     */
272
-    private function _load_core_config()
273
-    {
274
-        // load_core_config__start hook
275
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
276
-        $espresso_config = $this->get_espresso_config();
277
-        foreach ($espresso_config as $config => $settings) {
278
-            // load_core_config__start hook
279
-            $settings = apply_filters(
280
-                'FHEE__EE_Config___load_core_config__config_settings',
281
-                $settings,
282
-                $config,
283
-                $this
284
-            );
285
-            if (is_object($settings) && property_exists($this, $config)) {
286
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
287
-                // call configs populate method to ensure any defaults are set for empty values.
288
-                if (method_exists($settings, 'populate')) {
289
-                    $this->{$config}->populate();
290
-                }
291
-                if (method_exists($settings, 'do_hooks')) {
292
-                    $this->{$config}->do_hooks();
293
-                }
294
-            }
295
-        }
296
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
297
-            $this->update_espresso_config();
298
-        }
299
-        // load_core_config__end hook
300
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
301
-    }
302
-
303
-
304
-    /**
305
-     *    _verify_config
306
-     *
307
-     * @access    protected
308
-     * @return    void
309
-     */
310
-    protected function _verify_config()
311
-    {
312
-        $this->core = $this->core instanceof EE_Core_Config
313
-            ? $this->core
314
-            : new EE_Core_Config();
315
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
316
-        $this->organization = $this->organization instanceof EE_Organization_Config
317
-            ? $this->organization
318
-            : new EE_Organization_Config();
319
-        $this->organization = apply_filters(
320
-            'FHEE__EE_Config___initialize_config__organization',
321
-            $this->organization
322
-        );
323
-        $this->currency = $this->currency instanceof EE_Currency_Config
324
-            ? $this->currency
325
-            : new EE_Currency_Config();
326
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
327
-        $this->registration = $this->registration instanceof EE_Registration_Config
328
-            ? $this->registration
329
-            : new EE_Registration_Config();
330
-        $this->registration = apply_filters(
331
-            'FHEE__EE_Config___initialize_config__registration',
332
-            $this->registration
333
-        );
334
-        $this->admin = $this->admin instanceof EE_Admin_Config
335
-            ? $this->admin
336
-            : new EE_Admin_Config();
337
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
338
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
339
-            ? $this->template_settings
340
-            : new EE_Template_Config();
341
-        $this->template_settings = apply_filters(
342
-            'FHEE__EE_Config___initialize_config__template_settings',
343
-            $this->template_settings
344
-        );
345
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
346
-            ? $this->map_settings
347
-            : new EE_Map_Config();
348
-        $this->map_settings = apply_filters(
349
-            'FHEE__EE_Config___initialize_config__map_settings',
350
-            $this->map_settings
351
-        );
352
-        $this->environment = $this->environment instanceof EE_Environment_Config
353
-            ? $this->environment
354
-            : new EE_Environment_Config();
355
-        $this->environment = apply_filters(
356
-            'FHEE__EE_Config___initialize_config__environment',
357
-            $this->environment
358
-        );
359
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
360
-            ? $this->tax_settings
361
-            : new EE_Tax_Config();
362
-        $this->tax_settings = apply_filters(
363
-            'FHEE__EE_Config___initialize_config__tax_settings',
364
-            $this->tax_settings
365
-        );
366
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
367
-        $this->messages = $this->messages instanceof EE_Messages_Config
368
-            ? $this->messages
369
-            : new EE_Messages_Config();
370
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
371
-            ? $this->gateway
372
-            : new EE_Gateway_Config();
373
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
374
-        $this->legacy_shortcodes_manager = null;
375
-    }
376
-
377
-
378
-    /**
379
-     *    get_espresso_config
380
-     *
381
-     * @access    public
382
-     * @return    array of espresso config stuff
383
-     */
384
-    public function get_espresso_config()
385
-    {
386
-        // grab espresso configuration
387
-        return apply_filters(
388
-            'FHEE__EE_Config__get_espresso_config__CFG',
389
-            get_option(EE_Config::OPTION_NAME, array())
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     *    double_check_config_comparison
396
-     *
397
-     * @access    public
398
-     * @param string $option
399
-     * @param        $old_value
400
-     * @param        $value
401
-     */
402
-    public function double_check_config_comparison($option = '', $old_value, $value)
403
-    {
404
-        // make sure we're checking the ee config
405
-        if ($option === EE_Config::OPTION_NAME) {
406
-            // run a loose comparison of the old value against the new value for type and properties,
407
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
408
-            if ($value != $old_value) {
409
-                // if they are NOT the same, then remove the hook,
410
-                // which means the subsequent update results will be based solely on the update query results
411
-                // the reason we do this is because, as stated above,
412
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
413
-                // this happens PRIOR to serialization and any subsequent update.
414
-                // If values are found to match their previous old value,
415
-                // then WP bails before performing any update.
416
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
417
-                // it just pulled from the db, with the one being passed to it (which will not match).
418
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
419
-                // MySQL MAY ALSO NOT perform the update because
420
-                // the string it sees in the db looks the same as the new one it has been passed!!!
421
-                // This results in the query returning an "affected rows" value of ZERO,
422
-                // which gets returned immediately by WP update_option and looks like an error.
423
-                remove_action('update_option', array($this, 'check_config_updated'));
424
-            }
425
-        }
426
-    }
427
-
428
-
429
-    /**
430
-     *    update_espresso_config
431
-     *
432
-     * @access   public
433
-     */
434
-    protected function _reset_espresso_addon_config()
435
-    {
436
-        $this->_addon_option_names = array();
437
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
438
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
439
-            if ($addon_config_obj instanceof EE_Config_Base) {
440
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
441
-            }
442
-            $this->addons->{$addon_name} = null;
443
-        }
444
-    }
445
-
446
-
447
-    /**
448
-     *    update_espresso_config
449
-     *
450
-     * @access   public
451
-     * @param   bool $add_success
452
-     * @param   bool $add_error
453
-     * @return   bool
454
-     */
455
-    public function update_espresso_config($add_success = false, $add_error = true)
456
-    {
457
-        // don't allow config updates during WP heartbeats
458
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
459
-            return false;
460
-        }
461
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
462
-        // $clone = clone( self::$_instance );
463
-        // self::$_instance = NULL;
464
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
465
-        $this->_reset_espresso_addon_config();
466
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
467
-        // but BEFORE the actual update occurs
468
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
469
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
470
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
471
-        $this->legacy_shortcodes_manager = null;
472
-        // now update "ee_config"
473
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
474
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
475
-        EE_Config::log(EE_Config::OPTION_NAME);
476
-        // if not saved... check if the hook we just added still exists;
477
-        // if it does, it means one of two things:
478
-        // that update_option bailed at the($value === $old_value) conditional,
479
-        // or...
480
-        // the db update query returned 0 rows affected
481
-        // (probably because the data  value was the same from it's perspective)
482
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
483
-        // but just means no update occurred, so don't display an error to the user.
484
-        // BUT... if update_option returns FALSE, AND the hook is missing,
485
-        // then it means that something truly went wrong
486
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
487
-        // remove our action since we don't want it in the system anymore
488
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
489
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
490
-        // self::$_instance = $clone;
491
-        // unset( $clone );
492
-        // if config remains the same or was updated successfully
493
-        if ($saved) {
494
-            if ($add_success) {
495
-                EE_Error::add_success(
496
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
497
-                    __FILE__,
498
-                    __FUNCTION__,
499
-                    __LINE__
500
-                );
501
-            }
502
-            return true;
503
-        } else {
504
-            if ($add_error) {
505
-                EE_Error::add_error(
506
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
507
-                    __FILE__,
508
-                    __FUNCTION__,
509
-                    __LINE__
510
-                );
511
-            }
512
-            return false;
513
-        }
514
-    }
515
-
516
-
517
-    /**
518
-     *    _verify_config_params
519
-     *
520
-     * @access    private
521
-     * @param    string         $section
522
-     * @param    string         $name
523
-     * @param    string         $config_class
524
-     * @param    EE_Config_Base $config_obj
525
-     * @param    array          $tests_to_run
526
-     * @param    bool           $display_errors
527
-     * @return    bool    TRUE on success, FALSE on fail
528
-     */
529
-    private function _verify_config_params(
530
-        $section = '',
531
-        $name = '',
532
-        $config_class = '',
533
-        $config_obj = null,
534
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
535
-        $display_errors = true
536
-    ) {
537
-        try {
538
-            foreach ($tests_to_run as $test) {
539
-                switch ($test) {
540
-                    // TEST #1 : check that section was set
541
-                    case 1:
542
-                        if (empty($section)) {
543
-                            if ($display_errors) {
544
-                                throw new EE_Error(
545
-                                    sprintf(
546
-                                        __(
547
-                                            'No configuration section has been provided while attempting to save "%s".',
548
-                                            'event_espresso'
549
-                                        ),
550
-                                        $config_class
551
-                                    )
552
-                                );
553
-                            }
554
-                            return false;
555
-                        }
556
-                        break;
557
-                    // TEST #2 : check that settings section exists
558
-                    case 2:
559
-                        if (! isset($this->{$section})) {
560
-                            if ($display_errors) {
561
-                                throw new EE_Error(
562
-                                    sprintf(
563
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
564
-                                        $section
565
-                                    )
566
-                                );
567
-                            }
568
-                            return false;
569
-                        }
570
-                        break;
571
-                    // TEST #3 : check that section is the proper format
572
-                    case 3:
573
-                        if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574
-                        ) {
575
-                            if ($display_errors) {
576
-                                throw new EE_Error(
577
-                                    sprintf(
578
-                                        __(
579
-                                            'The "%s" configuration settings have not been formatted correctly.',
580
-                                            'event_espresso'
581
-                                        ),
582
-                                        $section
583
-                                    )
584
-                                );
585
-                            }
586
-                            return false;
587
-                        }
588
-                        break;
589
-                    // TEST #4 : check that config section name has been set
590
-                    case 4:
591
-                        if (empty($name)) {
592
-                            if ($display_errors) {
593
-                                throw new EE_Error(
594
-                                    __(
595
-                                        'No name has been provided for the specific configuration section.',
596
-                                        'event_espresso'
597
-                                    )
598
-                                );
599
-                            }
600
-                            return false;
601
-                        }
602
-                        break;
603
-                    // TEST #5 : check that a config class name has been set
604
-                    case 5:
605
-                        if (empty($config_class)) {
606
-                            if ($display_errors) {
607
-                                throw new EE_Error(
608
-                                    __(
609
-                                        'No class name has been provided for the specific configuration section.',
610
-                                        'event_espresso'
611
-                                    )
612
-                                );
613
-                            }
614
-                            return false;
615
-                        }
616
-                        break;
617
-                    // TEST #6 : verify config class is accessible
618
-                    case 6:
619
-                        if (! class_exists($config_class)) {
620
-                            if ($display_errors) {
621
-                                throw new EE_Error(
622
-                                    sprintf(
623
-                                        __(
624
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
625
-                                            'event_espresso'
626
-                                        ),
627
-                                        $config_class
628
-                                    )
629
-                                );
630
-                            }
631
-                            return false;
632
-                        }
633
-                        break;
634
-                    // TEST #7 : check that config has even been set
635
-                    case 7:
636
-                        if (! isset($this->{$section}->{$name})) {
637
-                            if ($display_errors) {
638
-                                throw new EE_Error(
639
-                                    sprintf(
640
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
641
-                                        $section,
642
-                                        $name
643
-                                    )
644
-                                );
645
-                            }
646
-                            return false;
647
-                        } else {
648
-                            // and make sure it's not serialized
649
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
650
-                        }
651
-                        break;
652
-                    // TEST #8 : check that config is the requested type
653
-                    case 8:
654
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
655
-                            if ($display_errors) {
656
-                                throw new EE_Error(
657
-                                    sprintf(
658
-                                        __(
659
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
660
-                                            'event_espresso'
661
-                                        ),
662
-                                        $section,
663
-                                        $name,
664
-                                        $config_class
665
-                                    )
666
-                                );
667
-                            }
668
-                            return false;
669
-                        }
670
-                        break;
671
-                    // TEST #9 : verify config object
672
-                    case 9:
673
-                        if (! $config_obj instanceof EE_Config_Base) {
674
-                            if ($display_errors) {
675
-                                throw new EE_Error(
676
-                                    sprintf(
677
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
678
-                                        print_r($config_obj, true)
679
-                                    )
680
-                                );
681
-                            }
682
-                            return false;
683
-                        }
684
-                        break;
685
-                }
686
-            }
687
-        } catch (EE_Error $e) {
688
-            $e->get_error();
689
-        }
690
-        // you have successfully run the gauntlet
691
-        return true;
692
-    }
693
-
694
-
695
-    /**
696
-     *    _generate_config_option_name
697
-     *
698
-     * @access        protected
699
-     * @param        string $section
700
-     * @param        string $name
701
-     * @return        string
702
-     */
703
-    private function _generate_config_option_name($section = '', $name = '')
704
-    {
705
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
706
-    }
707
-
708
-
709
-    /**
710
-     *    _set_config_class
711
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
712
-     *
713
-     * @access    private
714
-     * @param    string $config_class
715
-     * @param    string $name
716
-     * @return    string
717
-     */
718
-    private function _set_config_class($config_class = '', $name = '')
719
-    {
720
-        return ! empty($config_class)
721
-            ? $config_class
722
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
723
-    }
724
-
725
-
726
-    /**
727
-     *    set_config
728
-     *
729
-     * @access    protected
730
-     * @param    string         $section
731
-     * @param    string         $name
732
-     * @param    string         $config_class
733
-     * @param    EE_Config_Base $config_obj
734
-     * @return    EE_Config_Base
735
-     */
736
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
737
-    {
738
-        // ensure config class is set to something
739
-        $config_class = $this->_set_config_class($config_class, $name);
740
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
741
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742
-            return null;
743
-        }
744
-        $config_option_name = $this->_generate_config_option_name($section, $name);
745
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
746
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
747
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
748
-            $this->update_addon_option_names();
749
-        }
750
-        // verify the incoming config object but suppress errors
751
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752
-            $config_obj = new $config_class();
753
-        }
754
-        if (get_option($config_option_name)) {
755
-            EE_Config::log($config_option_name);
756
-            update_option($config_option_name, $config_obj);
757
-            $this->{$section}->{$name} = $config_obj;
758
-            return $this->{$section}->{$name};
759
-        } else {
760
-            // create a wp-option for this config
761
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
762
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
763
-                return $this->{$section}->{$name};
764
-            } else {
765
-                EE_Error::add_error(
766
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
767
-                    __FILE__,
768
-                    __FUNCTION__,
769
-                    __LINE__
770
-                );
771
-                return null;
772
-            }
773
-        }
774
-    }
775
-
776
-
777
-    /**
778
-     *    update_config
779
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
780
-     *
781
-     * @access    public
782
-     * @param    string                $section
783
-     * @param    string                $name
784
-     * @param    EE_Config_Base|string $config_obj
785
-     * @param    bool                  $throw_errors
786
-     * @return    bool
787
-     */
788
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
789
-    {
790
-        // don't allow config updates during WP heartbeats
791
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
792
-            return false;
793
-        }
794
-        $config_obj = maybe_unserialize($config_obj);
795
-        // get class name of the incoming object
796
-        $config_class = get_class($config_obj);
797
-        // run tests 1-5 and 9 to verify config
798
-        if (! $this->_verify_config_params(
799
-            $section,
800
-            $name,
801
-            $config_class,
802
-            $config_obj,
803
-            array(1, 2, 3, 4, 7, 9)
804
-        )
805
-        ) {
806
-            return false;
807
-        }
808
-        $config_option_name = $this->_generate_config_option_name($section, $name);
809
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
810
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
811
-            // save new config to db
812
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
813
-                return true;
814
-            }
815
-        } else {
816
-            // first check if the record already exists
817
-            $existing_config = get_option($config_option_name);
818
-            $config_obj = serialize($config_obj);
819
-            // just return if db record is already up to date (NOT type safe comparison)
820
-            if ($existing_config == $config_obj) {
821
-                $this->{$section}->{$name} = $config_obj;
822
-                return true;
823
-            } elseif (update_option($config_option_name, $config_obj)) {
824
-                EE_Config::log($config_option_name);
825
-                // update wp-option for this config class
826
-                $this->{$section}->{$name} = $config_obj;
827
-                return true;
828
-            } elseif ($throw_errors) {
829
-                EE_Error::add_error(
830
-                    sprintf(
831
-                        __(
832
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
833
-                            'event_espresso'
834
-                        ),
835
-                        $config_class,
836
-                        'EE_Config->' . $section . '->' . $name
837
-                    ),
838
-                    __FILE__,
839
-                    __FUNCTION__,
840
-                    __LINE__
841
-                );
842
-            }
843
-        }
844
-        return false;
845
-    }
846
-
847
-
848
-    /**
849
-     *    get_config
850
-     *
851
-     * @access    public
852
-     * @param    string $section
853
-     * @param    string $name
854
-     * @param    string $config_class
855
-     * @return    mixed EE_Config_Base | NULL
856
-     */
857
-    public function get_config($section = '', $name = '', $config_class = '')
858
-    {
859
-        // ensure config class is set to something
860
-        $config_class = $this->_set_config_class($config_class, $name);
861
-        // run tests 1-4, 6 and 7 to verify that all params have been set
862
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863
-            return null;
864
-        }
865
-        // now test if the requested config object exists, but suppress errors
866
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
867
-            // config already exists, so pass it back
868
-            return $this->{$section}->{$name};
869
-        }
870
-        // load config option from db if it exists
871
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
872
-        // verify the newly retrieved config object, but suppress errors
873
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
874
-            // config is good, so set it and pass it back
875
-            $this->{$section}->{$name} = $config_obj;
876
-            return $this->{$section}->{$name};
877
-        }
878
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
879
-        $config_obj = $this->set_config($section, $name, $config_class);
880
-        // verify the newly created config object
881
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
882
-            return $this->{$section}->{$name};
883
-        } else {
884
-            EE_Error::add_error(
885
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
886
-                __FILE__,
887
-                __FUNCTION__,
888
-                __LINE__
889
-            );
890
-        }
891
-        return null;
892
-    }
893
-
894
-
895
-    /**
896
-     *    get_config_option
897
-     *
898
-     * @access    public
899
-     * @param    string $config_option_name
900
-     * @return    mixed EE_Config_Base | FALSE
901
-     */
902
-    public function get_config_option($config_option_name = '')
903
-    {
904
-        // retrieve the wp-option for this config class.
905
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
906
-        if (empty($config_option)) {
907
-            EE_Config::log($config_option_name . '-NOT-FOUND');
908
-        }
909
-        return $config_option;
910
-    }
911
-
912
-
913
-    /**
914
-     * log
915
-     *
916
-     * @param string $config_option_name
917
-     */
918
-    public static function log($config_option_name = '')
919
-    {
920
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
921
-            $config_log = get_option(EE_Config::LOG_NAME, array());
922
-            // copy incoming $_REQUEST and sanitize it so we can save it
923
-            $_request = $_REQUEST;
924
-            array_walk_recursive($_request, 'sanitize_text_field');
925
-            $config_log[ (string) microtime(true) ] = array(
926
-                'config_name' => $config_option_name,
927
-                'request'     => $_request,
928
-            );
929
-            update_option(EE_Config::LOG_NAME, $config_log);
930
-        }
931
-    }
932
-
933
-
934
-    /**
935
-     * trim_log
936
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
937
-     */
938
-    public static function trim_log()
939
-    {
940
-        if (! EE_Config::logging_enabled()) {
941
-            return;
942
-        }
943
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
944
-        $log_length = count($config_log);
945
-        if ($log_length > EE_Config::LOG_LENGTH) {
946
-            ksort($config_log);
947
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
948
-            update_option(EE_Config::LOG_NAME, $config_log);
949
-        }
950
-    }
951
-
952
-
953
-    /**
954
-     *    get_page_for_posts
955
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
956
-     *    wp-option "page_for_posts", or "posts" if no page is selected
957
-     *
958
-     * @access    public
959
-     * @return    string
960
-     */
961
-    public static function get_page_for_posts()
962
-    {
963
-        $page_for_posts = get_option('page_for_posts');
964
-        if (! $page_for_posts) {
965
-            return 'posts';
966
-        }
967
-        /** @type WPDB $wpdb */
968
-        global $wpdb;
969
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
970
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
971
-    }
972
-
973
-
974
-    /**
975
-     *    register_shortcodes_and_modules.
976
-     *    At this point, it's too early to tell if we're maintenance mode or not.
977
-     *    In fact, this is where we give modules a chance to let core know they exist
978
-     *    so they can help trigger maintenance mode if it's needed
979
-     *
980
-     * @access    public
981
-     * @return    void
982
-     */
983
-    public function register_shortcodes_and_modules()
984
-    {
985
-        // allow modules to set hooks for the rest of the system
986
-        EE_Registry::instance()->modules = $this->_register_modules();
987
-    }
988
-
989
-
990
-    /**
991
-     *    initialize_shortcodes_and_modules
992
-     *    meaning they can start adding their hooks to get stuff done
993
-     *
994
-     * @access    public
995
-     * @return    void
996
-     */
997
-    public function initialize_shortcodes_and_modules()
998
-    {
999
-        // allow modules to set hooks for the rest of the system
1000
-        $this->_initialize_modules();
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     *    widgets_init
1006
-     *
1007
-     * @access private
1008
-     * @return void
1009
-     */
1010
-    public function widgets_init()
1011
-    {
1012
-        // only init widgets on admin pages when not in complete maintenance, and
1013
-        // on frontend when not in any maintenance mode
1014
-        if (! EE_Maintenance_Mode::instance()->level()
1015
-            || (
1016
-                is_admin()
1017
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018
-            )
1019
-        ) {
1020
-            // grab list of installed widgets
1021
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1022
-            // filter list of modules to register
1023
-            $widgets_to_register = apply_filters(
1024
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1025
-                $widgets_to_register
1026
-            );
1027
-            if (! empty($widgets_to_register)) {
1028
-                // cycle thru widget folders
1029
-                foreach ($widgets_to_register as $widget_path) {
1030
-                    // add to list of installed widget modules
1031
-                    EE_Config::register_ee_widget($widget_path);
1032
-                }
1033
-            }
1034
-            // filter list of installed modules
1035
-            EE_Registry::instance()->widgets = apply_filters(
1036
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1037
-                EE_Registry::instance()->widgets
1038
-            );
1039
-        }
1040
-    }
1041
-
1042
-
1043
-    /**
1044
-     *    register_ee_widget - makes core aware of this widget
1045
-     *
1046
-     * @access    public
1047
-     * @param    string $widget_path - full path up to and including widget folder
1048
-     * @return    void
1049
-     */
1050
-    public static function register_ee_widget($widget_path = null)
1051
-    {
1052
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1053
-        $widget_ext = '.widget.php';
1054
-        // make all separators match
1055
-        $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1056
-        // does the file path INCLUDE the actual file name as part of the path ?
1057
-        if (strpos($widget_path, $widget_ext) !== false) {
1058
-            // grab and shortcode file name from directory name and break apart at dots
1059
-            $file_name = explode('.', basename($widget_path));
1060
-            // take first segment from file name pieces and remove class prefix if it exists
1061
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1062
-            // sanitize shortcode directory name
1063
-            $widget = sanitize_key($widget);
1064
-            // now we need to rebuild the shortcode path
1065
-            $widget_path = explode(DS, $widget_path);
1066
-            // remove last segment
1067
-            array_pop($widget_path);
1068
-            // glue it back together
1069
-            $widget_path = implode(DS, $widget_path);
1070
-        } else {
1071
-            // grab and sanitize widget directory name
1072
-            $widget = sanitize_key(basename($widget_path));
1073
-        }
1074
-        // create classname from widget directory name
1075
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076
-        // add class prefix
1077
-        $widget_class = 'EEW_' . $widget;
1078
-        // does the widget exist ?
1079
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1080
-            $msg = sprintf(
1081
-                __(
1082
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1083
-                    'event_espresso'
1084
-                ),
1085
-                $widget_class,
1086
-                $widget_path . DS . $widget_class . $widget_ext
1087
-            );
1088
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1089
-            return;
1090
-        }
1091
-        // load the widget class file
1092
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1093
-        // verify that class exists
1094
-        if (! class_exists($widget_class)) {
1095
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1096
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1097
-            return;
1098
-        }
1099
-        register_widget($widget_class);
1100
-        // add to array of registered widgets
1101
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1102
-    }
1103
-
1104
-
1105
-    /**
1106
-     *        _register_modules
1107
-     *
1108
-     * @access private
1109
-     * @return array
1110
-     */
1111
-    private function _register_modules()
1112
-    {
1113
-        // grab list of installed modules
1114
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1115
-        // filter list of modules to register
1116
-        $modules_to_register = apply_filters(
1117
-            'FHEE__EE_Config__register_modules__modules_to_register',
1118
-            $modules_to_register
1119
-        );
1120
-        if (! empty($modules_to_register)) {
1121
-            // loop through folders
1122
-            foreach ($modules_to_register as $module_path) {
1123
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1124
-                if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1125
-                    && $module_path !== EE_MODULES . 'gateways'
1126
-                ) {
1127
-                    // add to list of installed modules
1128
-                    EE_Config::register_module($module_path);
1129
-                }
1130
-            }
1131
-        }
1132
-        // filter list of installed modules
1133
-        return apply_filters(
1134
-            'FHEE__EE_Config___register_modules__installed_modules',
1135
-            EE_Registry::instance()->modules
1136
-        );
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     *    register_module - makes core aware of this module
1142
-     *
1143
-     * @access    public
1144
-     * @param    string $module_path - full path up to and including module folder
1145
-     * @return    bool
1146
-     */
1147
-    public static function register_module($module_path = null)
1148
-    {
1149
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1150
-        $module_ext = '.module.php';
1151
-        // make all separators match
1152
-        $module_path = str_replace(array('\\', '/'), DS, $module_path);
1153
-        // does the file path INCLUDE the actual file name as part of the path ?
1154
-        if (strpos($module_path, $module_ext) !== false) {
1155
-            // grab and shortcode file name from directory name and break apart at dots
1156
-            $module_file = explode('.', basename($module_path));
1157
-            // now we need to rebuild the shortcode path
1158
-            $module_path = explode(DS, $module_path);
1159
-            // remove last segment
1160
-            array_pop($module_path);
1161
-            // glue it back together
1162
-            $module_path = implode(DS, $module_path) . DS;
1163
-            // take first segment from file name pieces and sanitize it
1164
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165
-            // ensure class prefix is added
1166
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1167
-        } else {
1168
-            // we need to generate the filename based off of the folder name
1169
-            // grab and sanitize module name
1170
-            $module = strtolower(basename($module_path));
1171
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172
-            // like trailingslashit()
1173
-            $module_path = rtrim($module_path, DS) . DS;
1174
-            // create classname from module directory name
1175
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176
-            // add class prefix
1177
-            $module_class = 'EED_' . $module;
1178
-        }
1179
-        // does the module exist ?
1180
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1181
-            $msg = sprintf(
1182
-                __(
1183
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1184
-                    'event_espresso'
1185
-                ),
1186
-                $module
1187
-            );
1188
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1189
-            return false;
1190
-        }
1191
-        // load the module class file
1192
-        require_once($module_path . $module_class . $module_ext);
1193
-        // verify that class exists
1194
-        if (! class_exists($module_class)) {
1195
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1196
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1197
-            return false;
1198
-        }
1199
-        // add to array of registered modules
1200
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1201
-        do_action(
1202
-            'AHEE__EE_Config__register_module__complete',
1203
-            $module_class,
1204
-            EE_Registry::instance()->modules->{$module_class}
1205
-        );
1206
-        return true;
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     *    _initialize_modules
1212
-     *    allow modules to set hooks for the rest of the system
1213
-     *
1214
-     * @access private
1215
-     * @return void
1216
-     */
1217
-    private function _initialize_modules()
1218
-    {
1219
-        // cycle thru shortcode folders
1220
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1221
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1222
-            // which set hooks ?
1223
-            if (is_admin()) {
1224
-                // fire immediately
1225
-                call_user_func(array($module_class, 'set_hooks_admin'));
1226
-            } else {
1227
-                // delay until other systems are online
1228
-                add_action(
1229
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1230
-                    array($module_class, 'set_hooks')
1231
-                );
1232
-            }
1233
-        }
1234
-    }
1235
-
1236
-
1237
-    /**
1238
-     *    register_route - adds module method routes to route_map
1239
-     *
1240
-     * @access    public
1241
-     * @param    string $route       - "pretty" public alias for module method
1242
-     * @param    string $module      - module name (classname without EED_ prefix)
1243
-     * @param    string $method_name - the actual module method to be routed to
1244
-     * @param    string $key         - url param key indicating a route is being called
1245
-     * @return    bool
1246
-     */
1247
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1248
-    {
1249
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250
-        $module = str_replace('EED_', '', $module);
1251
-        $module_class = 'EED_' . $module;
1252
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1253
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1255
-            return false;
1256
-        }
1257
-        if (empty($route)) {
1258
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1260
-            return false;
1261
-        }
1262
-        if (! method_exists('EED_' . $module, $method_name)) {
1263
-            $msg = sprintf(
1264
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265
-                $route
1266
-            );
1267
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1268
-            return false;
1269
-        }
1270
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1271
-        return true;
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     *    get_route - get module method route
1277
-     *
1278
-     * @access    public
1279
-     * @param    string $route - "pretty" public alias for module method
1280
-     * @param    string $key   - url param key indicating a route is being called
1281
-     * @return    string
1282
-     */
1283
-    public static function get_route($route = null, $key = 'ee')
1284
-    {
1285
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1286
-        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1287
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1288
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1289
-        }
1290
-        return null;
1291
-    }
1292
-
1293
-
1294
-    /**
1295
-     *    get_routes - get ALL module method routes
1296
-     *
1297
-     * @access    public
1298
-     * @return    array
1299
-     */
1300
-    public static function get_routes()
1301
-    {
1302
-        return EE_Config::$_module_route_map;
1303
-    }
1304
-
1305
-
1306
-    /**
1307
-     *    register_forward - allows modules to forward request to another module for further processing
1308
-     *
1309
-     * @access    public
1310
-     * @param    string       $route   - "pretty" public alias for module method
1311
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1312
-     *                                 class, allows different forwards to be served based on status
1313
-     * @param    array|string $forward - function name or array( class, method )
1314
-     * @param    string       $key     - url param key indicating a route is being called
1315
-     * @return    bool
1316
-     */
1317
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318
-    {
1319
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1321
-            $msg = sprintf(
1322
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1323
-                $route
1324
-            );
1325
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1326
-            return false;
1327
-        }
1328
-        if (empty($forward)) {
1329
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1331
-            return false;
1332
-        }
1333
-        if (is_array($forward)) {
1334
-            if (! isset($forward[1])) {
1335
-                $msg = sprintf(
1336
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337
-                    $route
1338
-                );
1339
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1340
-                return false;
1341
-            }
1342
-            if (! method_exists($forward[0], $forward[1])) {
1343
-                $msg = sprintf(
1344
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345
-                    $forward[1],
1346
-                    $route
1347
-                );
1348
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1349
-                return false;
1350
-            }
1351
-        } elseif (! function_exists($forward)) {
1352
-            $msg = sprintf(
1353
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354
-                $forward,
1355
-                $route
1356
-            );
1357
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1358
-            return false;
1359
-        }
1360
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1361
-        return true;
1362
-    }
1363
-
1364
-
1365
-    /**
1366
-     *    get_forward - get forwarding route
1367
-     *
1368
-     * @access    public
1369
-     * @param    string  $route  - "pretty" public alias for module method
1370
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1371
-     *                           allows different forwards to be served based on status
1372
-     * @param    string  $key    - url param key indicating a route is being called
1373
-     * @return    string
1374
-     */
1375
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1376
-    {
1377
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1379
-            return apply_filters(
1380
-                'FHEE__EE_Config__get_forward',
1381
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1382
-                $route,
1383
-                $status
1384
-            );
1385
-        }
1386
-        return null;
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1392
-     *    results
1393
-     *
1394
-     * @access    public
1395
-     * @param    string  $route  - "pretty" public alias for module method
1396
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1397
-     *                           allows different views to be served based on status
1398
-     * @param    string  $view
1399
-     * @param    string  $key    - url param key indicating a route is being called
1400
-     * @return    bool
1401
-     */
1402
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403
-    {
1404
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1406
-            $msg = sprintf(
1407
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1408
-                $route
1409
-            );
1410
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1411
-            return false;
1412
-        }
1413
-        if (! is_readable($view)) {
1414
-            $msg = sprintf(
1415
-                __(
1416
-                    'The %s view file could not be found or is not readable due to file permissions.',
1417
-                    'event_espresso'
1418
-                ),
1419
-                $view
1420
-            );
1421
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
-            return false;
1423
-        }
1424
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1425
-        return true;
1426
-    }
1427
-
1428
-
1429
-    /**
1430
-     *    get_view - get view for route and status
1431
-     *
1432
-     * @access    public
1433
-     * @param    string  $route  - "pretty" public alias for module method
1434
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1435
-     *                           allows different views to be served based on status
1436
-     * @param    string  $key    - url param key indicating a route is being called
1437
-     * @return    string
1438
-     */
1439
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1440
-    {
1441
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1443
-            return apply_filters(
1444
-                'FHEE__EE_Config__get_view',
1445
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1446
-                $route,
1447
-                $status
1448
-            );
1449
-        }
1450
-        return null;
1451
-    }
1452
-
1453
-
1454
-    public function update_addon_option_names()
1455
-    {
1456
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1457
-    }
1458
-
1459
-
1460
-    public function shutdown()
1461
-    {
1462
-        $this->update_addon_option_names();
1463
-    }
1464
-
1465
-
1466
-    /**
1467
-     * @return LegacyShortcodesManager
1468
-     */
1469
-    public static function getLegacyShortcodesManager()
1470
-    {
1471
-
1472
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473
-            EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474
-                EE_Registry::instance()
1475
-            );
1476
-        }
1477
-        return EE_Config::instance()->legacy_shortcodes_manager;
1478
-    }
1479
-
1480
-
1481
-    /**
1482
-     * register_shortcode - makes core aware of this shortcode
1483
-     *
1484
-     * @deprecated 4.9.26
1485
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1486
-     * @return    bool
1487
-     */
1488
-    public static function register_shortcode($shortcode_path = null)
1489
-    {
1490
-        EE_Error::doing_it_wrong(
1491
-            __METHOD__,
1492
-            __(
1493
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1494
-                'event_espresso'
1495
-            ),
1496
-            '4.9.26'
1497
-        );
1498
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1499
-    }
1500
-}
1501
-
1502
-/**
1503
- * Base class used for config classes. These classes should generally not have
1504
- * magic functions in use, except we'll allow them to magically set and get stuff...
1505
- * basically, they should just be well-defined stdClasses
1506
- */
1507
-class EE_Config_Base
1508
-{
1509
-
1510
-    /**
1511
-     * Utility function for escaping the value of a property and returning.
1512
-     *
1513
-     * @param string $property property name (checks to see if exists).
1514
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1515
-     * @throws \EE_Error
1516
-     */
1517
-    public function get_pretty($property)
1518
-    {
1519
-        if (! property_exists($this, $property)) {
1520
-            throw new EE_Error(
1521
-                sprintf(
1522
-                    __(
1523
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1524
-                        'event_espresso'
1525
-                    ),
1526
-                    get_class($this),
1527
-                    $property
1528
-                )
1529
-            );
1530
-        }
1531
-        // just handling escaping of strings for now.
1532
-        if (is_string($this->{$property})) {
1533
-            return stripslashes($this->{$property});
1534
-        }
1535
-        return $this->{$property};
1536
-    }
1537
-
1538
-
1539
-    public function populate()
1540
-    {
1541
-        // grab defaults via a new instance of this class.
1542
-        $class_name = get_class($this);
1543
-        $defaults = new $class_name;
1544
-        // loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1545
-        // default from our $defaults object.
1546
-        foreach (get_object_vars($defaults) as $property => $value) {
1547
-            if ($this->{$property} === null) {
1548
-                $this->{$property} = $value;
1549
-            }
1550
-        }
1551
-        // cleanup
1552
-        unset($defaults);
1553
-    }
1554
-
1555
-
1556
-    /**
1557
-     *        __isset
1558
-     *
1559
-     * @param $a
1560
-     * @return bool
1561
-     */
1562
-    public function __isset($a)
1563
-    {
1564
-        return false;
1565
-    }
1566
-
1567
-
1568
-    /**
1569
-     *        __unset
1570
-     *
1571
-     * @param $a
1572
-     * @return bool
1573
-     */
1574
-    public function __unset($a)
1575
-    {
1576
-        return false;
1577
-    }
1578
-
1579
-
1580
-    /**
1581
-     *        __clone
1582
-     */
1583
-    public function __clone()
1584
-    {
1585
-    }
1586
-
1587
-
1588
-    /**
1589
-     *        __wakeup
1590
-     */
1591
-    public function __wakeup()
1592
-    {
1593
-    }
1594
-
1595
-
1596
-    /**
1597
-     *        __destruct
1598
-     */
1599
-    public function __destruct()
1600
-    {
1601
-    }
1602
-}
1603
-
1604
-/**
1605
- * Class for defining what's in the EE_Config relating to registration settings
1606
- */
1607
-class EE_Core_Config extends EE_Config_Base
1608
-{
1609
-
1610
-    const OPTION_NAME_UXIP = 'ee_ueip_optin';
1611
-
1612
-
1613
-    public $current_blog_id;
1614
-
1615
-    public $ee_ueip_optin;
1616
-
1617
-    public $ee_ueip_has_notified;
1618
-
1619
-    /**
1620
-     * Not to be confused with the 4 critical page variables (See
1621
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1622
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1623
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1624
-     *
1625
-     * @var array
1626
-     */
1627
-    public $post_shortcodes;
1628
-
1629
-    public $module_route_map;
1630
-
1631
-    public $module_forward_map;
1632
-
1633
-    public $module_view_map;
1634
-
1635
-    /**
1636
-     * The next 4 vars are the IDs of critical EE pages.
1637
-     *
1638
-     * @var int
1639
-     */
1640
-    public $reg_page_id;
1641
-
1642
-    public $txn_page_id;
1643
-
1644
-    public $thank_you_page_id;
1645
-
1646
-    public $cancel_page_id;
1647
-
1648
-    /**
1649
-     * The next 4 vars are the URLs of critical EE pages.
1650
-     *
1651
-     * @var int
1652
-     */
1653
-    public $reg_page_url;
1654
-
1655
-    public $txn_page_url;
1656
-
1657
-    public $thank_you_page_url;
1658
-
1659
-    public $cancel_page_url;
1660
-
1661
-    /**
1662
-     * The next vars relate to the custom slugs for EE CPT routes
1663
-     */
1664
-    public $event_cpt_slug;
1665
-
1666
-    /**
1667
-     * This caches the _ee_ueip_option in case this config is reset in the same
1668
-     * request across blog switches in a multisite context.
1669
-     * Avoids extra queries to the db for this option.
1670
-     *
1671
-     * @var bool
1672
-     */
1673
-    public static $ee_ueip_option;
1674
-
1675
-
1676
-    /**
1677
-     *    class constructor
1678
-     *
1679
-     * @access    public
1680
-     */
1681
-    public function __construct()
1682
-    {
1683
-        // set default organization settings
1684
-        $this->current_blog_id = get_current_blog_id();
1685
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1686
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1687
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1688
-        $this->post_shortcodes = array();
1689
-        $this->module_route_map = array();
1690
-        $this->module_forward_map = array();
1691
-        $this->module_view_map = array();
1692
-        // critical EE page IDs
1693
-        $this->reg_page_id = 0;
1694
-        $this->txn_page_id = 0;
1695
-        $this->thank_you_page_id = 0;
1696
-        $this->cancel_page_id = 0;
1697
-        // critical EE page URLs
1698
-        $this->reg_page_url = '';
1699
-        $this->txn_page_url = '';
1700
-        $this->thank_you_page_url = '';
1701
-        $this->cancel_page_url = '';
1702
-        // cpt slugs
1703
-        $this->event_cpt_slug = __('events', 'event_espresso');
1704
-        // ueip constant check
1705
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1706
-            $this->ee_ueip_optin = false;
1707
-            $this->ee_ueip_has_notified = true;
1708
-        }
1709
-    }
1710
-
1711
-
1712
-    /**
1713
-     * @return array
1714
-     */
1715
-    public function get_critical_pages_array()
1716
-    {
1717
-        return array(
1718
-            $this->reg_page_id,
1719
-            $this->txn_page_id,
1720
-            $this->thank_you_page_id,
1721
-            $this->cancel_page_id,
1722
-        );
1723
-    }
1724
-
1725
-
1726
-    /**
1727
-     * @return array
1728
-     */
1729
-    public function get_critical_pages_shortcodes_array()
1730
-    {
1731
-        return array(
1732
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1733
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1734
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1735
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1736
-        );
1737
-    }
1738
-
1739
-
1740
-    /**
1741
-     *  gets/returns URL for EE reg_page
1742
-     *
1743
-     * @access    public
1744
-     * @return    string
1745
-     */
1746
-    public function reg_page_url()
1747
-    {
1748
-        if (! $this->reg_page_url) {
1749
-            $this->reg_page_url = add_query_arg(
1750
-                array('uts' => time()),
1751
-                get_permalink($this->reg_page_id)
1752
-            ) . '#checkout';
1753
-        }
1754
-        return $this->reg_page_url;
1755
-    }
1756
-
1757
-
1758
-    /**
1759
-     *  gets/returns URL for EE txn_page
1760
-     *
1761
-     * @param array $query_args like what gets passed to
1762
-     *                          add_query_arg() as the first argument
1763
-     * @access    public
1764
-     * @return    string
1765
-     */
1766
-    public function txn_page_url($query_args = array())
1767
-    {
1768
-        if (! $this->txn_page_url) {
1769
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1770
-        }
1771
-        if ($query_args) {
1772
-            return add_query_arg($query_args, $this->txn_page_url);
1773
-        } else {
1774
-            return $this->txn_page_url;
1775
-        }
1776
-    }
1777
-
1778
-
1779
-    /**
1780
-     *  gets/returns URL for EE thank_you_page
1781
-     *
1782
-     * @param array $query_args like what gets passed to
1783
-     *                          add_query_arg() as the first argument
1784
-     * @access    public
1785
-     * @return    string
1786
-     */
1787
-    public function thank_you_page_url($query_args = array())
1788
-    {
1789
-        if (! $this->thank_you_page_url) {
1790
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791
-        }
1792
-        if ($query_args) {
1793
-            return add_query_arg($query_args, $this->thank_you_page_url);
1794
-        } else {
1795
-            return $this->thank_you_page_url;
1796
-        }
1797
-    }
1798
-
1799
-
1800
-    /**
1801
-     *  gets/returns URL for EE cancel_page
1802
-     *
1803
-     * @access    public
1804
-     * @return    string
1805
-     */
1806
-    public function cancel_page_url()
1807
-    {
1808
-        if (! $this->cancel_page_url) {
1809
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1810
-        }
1811
-        return $this->cancel_page_url;
1812
-    }
1813
-
1814
-
1815
-    /**
1816
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1817
-     *
1818
-     * @since 4.7.5
1819
-     */
1820
-    protected function _reset_urls()
1821
-    {
1822
-        $this->reg_page_url = '';
1823
-        $this->txn_page_url = '';
1824
-        $this->cancel_page_url = '';
1825
-        $this->thank_you_page_url = '';
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * Used to return what the optin value is set for the EE User Experience Program.
1831
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1832
-     * on the main site only.
1833
-     *
1834
-     * @return bool
1835
-     */
1836
-    protected function _get_main_ee_ueip_optin()
1837
-    {
1838
-        // if this is the main site then we can just bypass our direct query.
1839
-        if (is_main_site()) {
1840
-            return get_option(self::OPTION_NAME_UXIP, false);
1841
-        }
1842
-        // is this already cached for this request?  If so use it.
1843
-        if (EE_Core_Config::$ee_ueip_option !== null) {
1844
-            return EE_Core_Config::$ee_ueip_option;
1845
-        }
1846
-        global $wpdb;
1847
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1848
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849
-        $option = self::OPTION_NAME_UXIP;
1850
-        // set correct table for query
1851
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1852
-        // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853
-        // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854
-        // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855
-        // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856
-        // for the purpose of caching.
1857
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1858
-        if (false !== $pre) {
1859
-            EE_Core_Config::$ee_ueip_option = $pre;
1860
-            return EE_Core_Config::$ee_ueip_option;
1861
-        }
1862
-        $row = $wpdb->get_row(
1863
-            $wpdb->prepare(
1864
-                "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1865
-                $option
1866
-            )
1867
-        );
1868
-        if (is_object($row)) {
1869
-            $value = $row->option_value;
1870
-        } else { // option does not exist so use default.
1871
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1872
-            return EE_Core_Config::$ee_ueip_option;
1873
-        }
1874
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1875
-        return EE_Core_Config::$ee_ueip_option;
1876
-    }
1877
-
1878
-
1879
-    /**
1880
-     * Utility function for escaping the value of a property and returning.
1881
-     *
1882
-     * @param string $property property name (checks to see if exists).
1883
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1884
-     * @throws \EE_Error
1885
-     */
1886
-    public function get_pretty($property)
1887
-    {
1888
-        if ($property === self::OPTION_NAME_UXIP) {
1889
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1890
-        }
1891
-        return parent::get_pretty($property);
1892
-    }
1893
-
1894
-
1895
-    /**
1896
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1897
-     * on the object.
1898
-     *
1899
-     * @return array
1900
-     */
1901
-    public function __sleep()
1902
-    {
1903
-        // reset all url properties
1904
-        $this->_reset_urls();
1905
-        // return what to save to db
1906
-        return array_keys(get_object_vars($this));
1907
-    }
1908
-}
1909
-
1910
-/**
1911
- * Config class for storing info on the Organization
1912
- */
1913
-class EE_Organization_Config extends EE_Config_Base
1914
-{
1915
-
1916
-    /**
1917
-     * @var string $name
1918
-     * eg EE4.1
1919
-     */
1920
-    public $name;
1921
-
1922
-    /**
1923
-     * @var string $address_1
1924
-     * eg 123 Onna Road
1925
-     */
1926
-    public $address_1 = '';
1927
-
1928
-    /**
1929
-     * @var string $address_2
1930
-     * eg PO Box 123
1931
-     */
1932
-    public $address_2 = '';
1933
-
1934
-    /**
1935
-     * @var string $city
1936
-     * eg Inna City
1937
-     */
1938
-    public $city = '';
1939
-
1940
-    /**
1941
-     * @var int $STA_ID
1942
-     * eg 4
1943
-     */
1944
-    public $STA_ID = 0;
1945
-
1946
-    /**
1947
-     * @var string $CNT_ISO
1948
-     * eg US
1949
-     */
1950
-    public $CNT_ISO = '';
1951
-
1952
-    /**
1953
-     * @var string $zip
1954
-     * eg 12345  or V1A 2B3
1955
-     */
1956
-    public $zip = '';
1957
-
1958
-    /**
1959
-     * @var string $email
1960
-     * eg [email protected]
1961
-     */
1962
-    public $email;
1963
-
1964
-    /**
1965
-     * @var string $phone
1966
-     * eg. 111-111-1111
1967
-     */
1968
-    public $phone = '';
1969
-
1970
-    /**
1971
-     * @var string $vat
1972
-     * VAT/Tax Number
1973
-     */
1974
-    public $vat = '';
1975
-
1976
-    /**
1977
-     * @var string $logo_url
1978
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1979
-     */
1980
-    public $logo_url = '';
1981
-
1982
-    /**
1983
-     * The below are all various properties for holding links to organization social network profiles
1984
-     *
1985
-     * @var string
1986
-     */
1987
-    /**
1988
-     * facebook (facebook.com/profile.name)
1989
-     *
1990
-     * @var string
1991
-     */
1992
-    public $facebook = '';
1993
-
1994
-    /**
1995
-     * twitter (twitter.com/twitter_handle)
1996
-     *
1997
-     * @var string
1998
-     */
1999
-    public $twitter = '';
2000
-
2001
-    /**
2002
-     * linkedin (linkedin.com/in/profile_name)
2003
-     *
2004
-     * @var string
2005
-     */
2006
-    public $linkedin = '';
2007
-
2008
-    /**
2009
-     * pinterest (www.pinterest.com/profile_name)
2010
-     *
2011
-     * @var string
2012
-     */
2013
-    public $pinterest = '';
2014
-
2015
-    /**
2016
-     * google+ (google.com/+profileName)
2017
-     *
2018
-     * @var string
2019
-     */
2020
-    public $google = '';
2021
-
2022
-    /**
2023
-     * instagram (instagram.com/handle)
2024
-     *
2025
-     * @var string
2026
-     */
2027
-    public $instagram = '';
2028
-
2029
-
2030
-    /**
2031
-     *    class constructor
2032
-     *
2033
-     * @access    public
2034
-     */
2035
-    public function __construct()
2036
-    {
2037
-        // set default organization settings
2038
-        // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2039
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2040
-        $this->email = get_bloginfo('admin_email');
2041
-    }
2042
-}
2043
-
2044
-/**
2045
- * Class for defining what's in the EE_Config relating to currency
2046
- */
2047
-class EE_Currency_Config extends EE_Config_Base
2048
-{
2049
-
2050
-    /**
2051
-     * @var string $code
2052
-     * eg 'US'
2053
-     */
2054
-    public $code;
2055
-
2056
-    /**
2057
-     * @var string $name
2058
-     * eg 'Dollar'
2059
-     */
2060
-    public $name;
2061
-
2062
-    /**
2063
-     * plural name
2064
-     *
2065
-     * @var string $plural
2066
-     * eg 'Dollars'
2067
-     */
2068
-    public $plural;
2069
-
2070
-    /**
2071
-     * currency sign
2072
-     *
2073
-     * @var string $sign
2074
-     * eg '$'
2075
-     */
2076
-    public $sign;
2077
-
2078
-    /**
2079
-     * Whether the currency sign should come before the number or not
2080
-     *
2081
-     * @var boolean $sign_b4
2082
-     */
2083
-    public $sign_b4;
2084
-
2085
-    /**
2086
-     * How many digits should come after the decimal place
2087
-     *
2088
-     * @var int $dec_plc
2089
-     */
2090
-    public $dec_plc;
2091
-
2092
-    /**
2093
-     * Symbol to use for decimal mark
2094
-     *
2095
-     * @var string $dec_mrk
2096
-     * eg '.'
2097
-     */
2098
-    public $dec_mrk;
2099
-
2100
-    /**
2101
-     * Symbol to use for thousands
2102
-     *
2103
-     * @var string $thsnds
2104
-     * eg ','
2105
-     */
2106
-    public $thsnds;
2107
-
2108
-
2109
-    /**
2110
-     *    class constructor
2111
-     *
2112
-     * @access    public
2113
-     * @param string $CNT_ISO
2114
-     * @throws \EE_Error
2115
-     */
2116
-    public function __construct($CNT_ISO = '')
2117
-    {
2118
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2119
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2120
-        // get country code from organization settings or use default
2121
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2122
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2123
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2124
-            : '';
2125
-        // but override if requested
2126
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2128
-        if (! empty($CNT_ISO)
2129
-            && EE_Maintenance_Mode::instance()->models_can_query()
2130
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131
-        ) {
2132
-            // retrieve the country settings from the db, just in case they have been customized
2133
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134
-            if ($country instanceof EE_Country) {
2135
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2136
-                $this->name = $country->currency_name_single();    // Dollar
2137
-                $this->plural = $country->currency_name_plural();    // Dollars
2138
-                $this->sign = $country->currency_sign();            // currency sign: $
2139
-                $this->sign_b4 = $country->currency_sign_before(
2140
-                );        // currency sign before or after: $TRUE  or  FALSE$
2141
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2142
-                $this->dec_mrk = $country->currency_decimal_mark(
2143
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144
-                $this->thsnds = $country->currency_thousands_separator(
2145
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146
-            }
2147
-        }
2148
-        // fallback to hardcoded defaults, in case the above failed
2149
-        if (empty($this->code)) {
2150
-            // set default currency settings
2151
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2152
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2153
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2154
-            $this->sign = '$';    // currency sign: $
2155
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2156
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2157
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159
-        }
2160
-    }
2161
-}
2162
-
2163
-/**
2164
- * Class for defining what's in the EE_Config relating to registration settings
2165
- */
2166
-class EE_Registration_Config extends EE_Config_Base
2167
-{
2168
-
2169
-    /**
2170
-     * Default registration status
2171
-     *
2172
-     * @var string $default_STS_ID
2173
-     * eg 'RPP'
2174
-     */
2175
-    public $default_STS_ID;
2176
-
2177
-    /**
2178
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2179
-     * registrations)
2180
-     *
2181
-     * @var int
2182
-     */
2183
-    public $default_maximum_number_of_tickets;
2184
-
2185
-    /**
2186
-     * level of validation to apply to email addresses
2187
-     *
2188
-     * @var string $email_validation_level
2189
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2190
-     */
2191
-    public $email_validation_level;
2192
-
2193
-    /**
2194
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2195
-     *
2196
-     * @var boolean $show_pending_payment_options
2197
-     */
2198
-    public $show_pending_payment_options;
2199
-
2200
-    /**
2201
-     * Whether to skip the registration confirmation page
2202
-     *
2203
-     * @var boolean $skip_reg_confirmation
2204
-     */
2205
-    public $skip_reg_confirmation;
2206
-
2207
-    /**
2208
-     * an array of SPCO reg steps where:
2209
-     *        the keys denotes the reg step order
2210
-     *        each element consists of an array with the following elements:
2211
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2212
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2213
-     *            "slug" => the URL param used to trigger the reg step
2214
-     *
2215
-     * @var array $reg_steps
2216
-     */
2217
-    public $reg_steps;
2218
-
2219
-    /**
2220
-     * Whether registration confirmation should be the last page of SPCO
2221
-     *
2222
-     * @var boolean $reg_confirmation_last
2223
-     */
2224
-    public $reg_confirmation_last;
2225
-
2226
-    /**
2227
-     * Whether or not to enable the EE Bot Trap
2228
-     *
2229
-     * @var boolean $use_bot_trap
2230
-     */
2231
-    public $use_bot_trap;
2232
-
2233
-    /**
2234
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2235
-     *
2236
-     * @var boolean $use_encryption
2237
-     */
2238
-    public $use_encryption;
2239
-
2240
-    /**
2241
-     * Whether or not to use ReCaptcha
2242
-     *
2243
-     * @var boolean $use_captcha
2244
-     */
2245
-    public $use_captcha;
2246
-
2247
-    /**
2248
-     * ReCaptcha Theme
2249
-     *
2250
-     * @var string $recaptcha_theme
2251
-     *    options: 'dark', 'light', 'invisible'
2252
-     */
2253
-    public $recaptcha_theme;
2254
-
2255
-    /**
2256
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2257
-     *
2258
-     * @var string $recaptcha_badge
2259
-     *    options: 'bottomright', 'bottomleft', 'inline'
2260
-     */
2261
-    public $recaptcha_badge;
17
+	const OPTION_NAME = 'ee_config';
18
+
19
+	const LOG_NAME = 'ee_config_log';
20
+
21
+	const LOG_LENGTH = 100;
22
+
23
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
24
+
25
+	/**
26
+	 *    instance of the EE_Config object
27
+	 *
28
+	 * @var    EE_Config $_instance
29
+	 * @access    private
30
+	 */
31
+	private static $_instance;
32
+
33
+	/**
34
+	 * @var boolean $_logging_enabled
35
+	 */
36
+	private static $_logging_enabled = false;
37
+
38
+	/**
39
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
40
+	 */
41
+	private $legacy_shortcodes_manager;
42
+
43
+	/**
44
+	 * An StdClass whose property names are addon slugs,
45
+	 * and values are their config classes
46
+	 *
47
+	 * @var StdClass
48
+	 */
49
+	public $addons;
50
+
51
+	/**
52
+	 * @var EE_Admin_Config
53
+	 */
54
+	public $admin;
55
+
56
+	/**
57
+	 * @var EE_Core_Config
58
+	 */
59
+	public $core;
60
+
61
+	/**
62
+	 * @var EE_Currency_Config
63
+	 */
64
+	public $currency;
65
+
66
+	/**
67
+	 * @var EE_Organization_Config
68
+	 */
69
+	public $organization;
70
+
71
+	/**
72
+	 * @var EE_Registration_Config
73
+	 */
74
+	public $registration;
75
+
76
+	/**
77
+	 * @var EE_Template_Config
78
+	 */
79
+	public $template_settings;
80
+
81
+	/**
82
+	 * Holds EE environment values.
83
+	 *
84
+	 * @var EE_Environment_Config
85
+	 */
86
+	public $environment;
87
+
88
+	/**
89
+	 * settings pertaining to Google maps
90
+	 *
91
+	 * @var EE_Map_Config
92
+	 */
93
+	public $map_settings;
94
+
95
+	/**
96
+	 * settings pertaining to Taxes
97
+	 *
98
+	 * @var EE_Tax_Config
99
+	 */
100
+	public $tax_settings;
101
+
102
+	/**
103
+	 * Settings pertaining to global messages settings.
104
+	 *
105
+	 * @var EE_Messages_Config
106
+	 */
107
+	public $messages;
108
+
109
+	/**
110
+	 * @deprecated
111
+	 * @var EE_Gateway_Config
112
+	 */
113
+	public $gateway;
114
+
115
+	/**
116
+	 * @var    array $_addon_option_names
117
+	 * @access    private
118
+	 */
119
+	private $_addon_option_names = array();
120
+
121
+	/**
122
+	 * @var    array $_module_route_map
123
+	 * @access    private
124
+	 */
125
+	private static $_module_route_map = array();
126
+
127
+	/**
128
+	 * @var    array $_module_forward_map
129
+	 * @access    private
130
+	 */
131
+	private static $_module_forward_map = array();
132
+
133
+	/**
134
+	 * @var    array $_module_view_map
135
+	 * @access    private
136
+	 */
137
+	private static $_module_view_map = array();
138
+
139
+
140
+	/**
141
+	 * @singleton method used to instantiate class object
142
+	 * @access    public
143
+	 * @return EE_Config instance
144
+	 */
145
+	public static function instance()
146
+	{
147
+		// check if class object is instantiated, and instantiated properly
148
+		if (! self::$_instance instanceof EE_Config) {
149
+			self::$_instance = new self();
150
+		}
151
+		return self::$_instance;
152
+	}
153
+
154
+
155
+	/**
156
+	 * Resets the config
157
+	 *
158
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
159
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
160
+	 *                               reflect its state in the database
161
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
162
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
163
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
164
+	 *                               site was put into maintenance mode)
165
+	 * @return EE_Config
166
+	 */
167
+	public static function reset($hard_reset = false, $reinstantiate = true)
168
+	{
169
+		if (self::$_instance instanceof EE_Config) {
170
+			if ($hard_reset) {
171
+				self::$_instance->legacy_shortcodes_manager = null;
172
+				self::$_instance->_addon_option_names = array();
173
+				self::$_instance->_initialize_config();
174
+				self::$_instance->update_espresso_config();
175
+			}
176
+			self::$_instance->update_addon_option_names();
177
+		}
178
+		self::$_instance = null;
179
+		// we don't need to reset the static properties imo because those should
180
+		// only change when a module is added or removed. Currently we don't
181
+		// support removing a module during a request when it previously existed
182
+		if ($reinstantiate) {
183
+			return self::instance();
184
+		} else {
185
+			return null;
186
+		}
187
+	}
188
+
189
+
190
+	/**
191
+	 *    class constructor
192
+	 *
193
+	 * @access    private
194
+	 */
195
+	private function __construct()
196
+	{
197
+		do_action('AHEE__EE_Config__construct__begin', $this);
198
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
199
+		// setup empty config classes
200
+		$this->_initialize_config();
201
+		// load existing EE site settings
202
+		$this->_load_core_config();
203
+		// confirm everything loaded correctly and set filtered defaults if not
204
+		$this->_verify_config();
205
+		//  register shortcodes and modules
206
+		add_action(
207
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
208
+			array($this, 'register_shortcodes_and_modules'),
209
+			999
210
+		);
211
+		//  initialize shortcodes and modules
212
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
213
+		// register widgets
214
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
215
+		// shutdown
216
+		add_action('shutdown', array($this, 'shutdown'), 10);
217
+		// construct__end hook
218
+		do_action('AHEE__EE_Config__construct__end', $this);
219
+		// hardcoded hack
220
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return boolean
226
+	 */
227
+	public static function logging_enabled()
228
+	{
229
+		return self::$_logging_enabled;
230
+	}
231
+
232
+
233
+	/**
234
+	 * use to get the current theme if needed from static context
235
+	 *
236
+	 * @return string current theme set.
237
+	 */
238
+	public static function get_current_theme()
239
+	{
240
+		return isset(self::$_instance->template_settings->current_espresso_theme)
241
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
242
+	}
243
+
244
+
245
+	/**
246
+	 *        _initialize_config
247
+	 *
248
+	 * @access private
249
+	 * @return void
250
+	 */
251
+	private function _initialize_config()
252
+	{
253
+		EE_Config::trim_log();
254
+		// set defaults
255
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
256
+		$this->addons = new stdClass();
257
+		// set _module_route_map
258
+		EE_Config::$_module_route_map = array();
259
+		// set _module_forward_map
260
+		EE_Config::$_module_forward_map = array();
261
+		// set _module_view_map
262
+		EE_Config::$_module_view_map = array();
263
+	}
264
+
265
+
266
+	/**
267
+	 *        load core plugin configuration
268
+	 *
269
+	 * @access private
270
+	 * @return void
271
+	 */
272
+	private function _load_core_config()
273
+	{
274
+		// load_core_config__start hook
275
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
276
+		$espresso_config = $this->get_espresso_config();
277
+		foreach ($espresso_config as $config => $settings) {
278
+			// load_core_config__start hook
279
+			$settings = apply_filters(
280
+				'FHEE__EE_Config___load_core_config__config_settings',
281
+				$settings,
282
+				$config,
283
+				$this
284
+			);
285
+			if (is_object($settings) && property_exists($this, $config)) {
286
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
287
+				// call configs populate method to ensure any defaults are set for empty values.
288
+				if (method_exists($settings, 'populate')) {
289
+					$this->{$config}->populate();
290
+				}
291
+				if (method_exists($settings, 'do_hooks')) {
292
+					$this->{$config}->do_hooks();
293
+				}
294
+			}
295
+		}
296
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
297
+			$this->update_espresso_config();
298
+		}
299
+		// load_core_config__end hook
300
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
301
+	}
302
+
303
+
304
+	/**
305
+	 *    _verify_config
306
+	 *
307
+	 * @access    protected
308
+	 * @return    void
309
+	 */
310
+	protected function _verify_config()
311
+	{
312
+		$this->core = $this->core instanceof EE_Core_Config
313
+			? $this->core
314
+			: new EE_Core_Config();
315
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
316
+		$this->organization = $this->organization instanceof EE_Organization_Config
317
+			? $this->organization
318
+			: new EE_Organization_Config();
319
+		$this->organization = apply_filters(
320
+			'FHEE__EE_Config___initialize_config__organization',
321
+			$this->organization
322
+		);
323
+		$this->currency = $this->currency instanceof EE_Currency_Config
324
+			? $this->currency
325
+			: new EE_Currency_Config();
326
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
327
+		$this->registration = $this->registration instanceof EE_Registration_Config
328
+			? $this->registration
329
+			: new EE_Registration_Config();
330
+		$this->registration = apply_filters(
331
+			'FHEE__EE_Config___initialize_config__registration',
332
+			$this->registration
333
+		);
334
+		$this->admin = $this->admin instanceof EE_Admin_Config
335
+			? $this->admin
336
+			: new EE_Admin_Config();
337
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
338
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
339
+			? $this->template_settings
340
+			: new EE_Template_Config();
341
+		$this->template_settings = apply_filters(
342
+			'FHEE__EE_Config___initialize_config__template_settings',
343
+			$this->template_settings
344
+		);
345
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
346
+			? $this->map_settings
347
+			: new EE_Map_Config();
348
+		$this->map_settings = apply_filters(
349
+			'FHEE__EE_Config___initialize_config__map_settings',
350
+			$this->map_settings
351
+		);
352
+		$this->environment = $this->environment instanceof EE_Environment_Config
353
+			? $this->environment
354
+			: new EE_Environment_Config();
355
+		$this->environment = apply_filters(
356
+			'FHEE__EE_Config___initialize_config__environment',
357
+			$this->environment
358
+		);
359
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
360
+			? $this->tax_settings
361
+			: new EE_Tax_Config();
362
+		$this->tax_settings = apply_filters(
363
+			'FHEE__EE_Config___initialize_config__tax_settings',
364
+			$this->tax_settings
365
+		);
366
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
367
+		$this->messages = $this->messages instanceof EE_Messages_Config
368
+			? $this->messages
369
+			: new EE_Messages_Config();
370
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
371
+			? $this->gateway
372
+			: new EE_Gateway_Config();
373
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
374
+		$this->legacy_shortcodes_manager = null;
375
+	}
376
+
377
+
378
+	/**
379
+	 *    get_espresso_config
380
+	 *
381
+	 * @access    public
382
+	 * @return    array of espresso config stuff
383
+	 */
384
+	public function get_espresso_config()
385
+	{
386
+		// grab espresso configuration
387
+		return apply_filters(
388
+			'FHEE__EE_Config__get_espresso_config__CFG',
389
+			get_option(EE_Config::OPTION_NAME, array())
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 *    double_check_config_comparison
396
+	 *
397
+	 * @access    public
398
+	 * @param string $option
399
+	 * @param        $old_value
400
+	 * @param        $value
401
+	 */
402
+	public function double_check_config_comparison($option = '', $old_value, $value)
403
+	{
404
+		// make sure we're checking the ee config
405
+		if ($option === EE_Config::OPTION_NAME) {
406
+			// run a loose comparison of the old value against the new value for type and properties,
407
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
408
+			if ($value != $old_value) {
409
+				// if they are NOT the same, then remove the hook,
410
+				// which means the subsequent update results will be based solely on the update query results
411
+				// the reason we do this is because, as stated above,
412
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
413
+				// this happens PRIOR to serialization and any subsequent update.
414
+				// If values are found to match their previous old value,
415
+				// then WP bails before performing any update.
416
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
417
+				// it just pulled from the db, with the one being passed to it (which will not match).
418
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
419
+				// MySQL MAY ALSO NOT perform the update because
420
+				// the string it sees in the db looks the same as the new one it has been passed!!!
421
+				// This results in the query returning an "affected rows" value of ZERO,
422
+				// which gets returned immediately by WP update_option and looks like an error.
423
+				remove_action('update_option', array($this, 'check_config_updated'));
424
+			}
425
+		}
426
+	}
427
+
428
+
429
+	/**
430
+	 *    update_espresso_config
431
+	 *
432
+	 * @access   public
433
+	 */
434
+	protected function _reset_espresso_addon_config()
435
+	{
436
+		$this->_addon_option_names = array();
437
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
438
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
439
+			if ($addon_config_obj instanceof EE_Config_Base) {
440
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
441
+			}
442
+			$this->addons->{$addon_name} = null;
443
+		}
444
+	}
445
+
446
+
447
+	/**
448
+	 *    update_espresso_config
449
+	 *
450
+	 * @access   public
451
+	 * @param   bool $add_success
452
+	 * @param   bool $add_error
453
+	 * @return   bool
454
+	 */
455
+	public function update_espresso_config($add_success = false, $add_error = true)
456
+	{
457
+		// don't allow config updates during WP heartbeats
458
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
459
+			return false;
460
+		}
461
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
462
+		// $clone = clone( self::$_instance );
463
+		// self::$_instance = NULL;
464
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
465
+		$this->_reset_espresso_addon_config();
466
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
467
+		// but BEFORE the actual update occurs
468
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
469
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
470
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
471
+		$this->legacy_shortcodes_manager = null;
472
+		// now update "ee_config"
473
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
474
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
475
+		EE_Config::log(EE_Config::OPTION_NAME);
476
+		// if not saved... check if the hook we just added still exists;
477
+		// if it does, it means one of two things:
478
+		// that update_option bailed at the($value === $old_value) conditional,
479
+		// or...
480
+		// the db update query returned 0 rows affected
481
+		// (probably because the data  value was the same from it's perspective)
482
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
483
+		// but just means no update occurred, so don't display an error to the user.
484
+		// BUT... if update_option returns FALSE, AND the hook is missing,
485
+		// then it means that something truly went wrong
486
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
487
+		// remove our action since we don't want it in the system anymore
488
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
489
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
490
+		// self::$_instance = $clone;
491
+		// unset( $clone );
492
+		// if config remains the same or was updated successfully
493
+		if ($saved) {
494
+			if ($add_success) {
495
+				EE_Error::add_success(
496
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
497
+					__FILE__,
498
+					__FUNCTION__,
499
+					__LINE__
500
+				);
501
+			}
502
+			return true;
503
+		} else {
504
+			if ($add_error) {
505
+				EE_Error::add_error(
506
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
507
+					__FILE__,
508
+					__FUNCTION__,
509
+					__LINE__
510
+				);
511
+			}
512
+			return false;
513
+		}
514
+	}
515
+
516
+
517
+	/**
518
+	 *    _verify_config_params
519
+	 *
520
+	 * @access    private
521
+	 * @param    string         $section
522
+	 * @param    string         $name
523
+	 * @param    string         $config_class
524
+	 * @param    EE_Config_Base $config_obj
525
+	 * @param    array          $tests_to_run
526
+	 * @param    bool           $display_errors
527
+	 * @return    bool    TRUE on success, FALSE on fail
528
+	 */
529
+	private function _verify_config_params(
530
+		$section = '',
531
+		$name = '',
532
+		$config_class = '',
533
+		$config_obj = null,
534
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
535
+		$display_errors = true
536
+	) {
537
+		try {
538
+			foreach ($tests_to_run as $test) {
539
+				switch ($test) {
540
+					// TEST #1 : check that section was set
541
+					case 1:
542
+						if (empty($section)) {
543
+							if ($display_errors) {
544
+								throw new EE_Error(
545
+									sprintf(
546
+										__(
547
+											'No configuration section has been provided while attempting to save "%s".',
548
+											'event_espresso'
549
+										),
550
+										$config_class
551
+									)
552
+								);
553
+							}
554
+							return false;
555
+						}
556
+						break;
557
+					// TEST #2 : check that settings section exists
558
+					case 2:
559
+						if (! isset($this->{$section})) {
560
+							if ($display_errors) {
561
+								throw new EE_Error(
562
+									sprintf(
563
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
564
+										$section
565
+									)
566
+								);
567
+							}
568
+							return false;
569
+						}
570
+						break;
571
+					// TEST #3 : check that section is the proper format
572
+					case 3:
573
+						if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574
+						) {
575
+							if ($display_errors) {
576
+								throw new EE_Error(
577
+									sprintf(
578
+										__(
579
+											'The "%s" configuration settings have not been formatted correctly.',
580
+											'event_espresso'
581
+										),
582
+										$section
583
+									)
584
+								);
585
+							}
586
+							return false;
587
+						}
588
+						break;
589
+					// TEST #4 : check that config section name has been set
590
+					case 4:
591
+						if (empty($name)) {
592
+							if ($display_errors) {
593
+								throw new EE_Error(
594
+									__(
595
+										'No name has been provided for the specific configuration section.',
596
+										'event_espresso'
597
+									)
598
+								);
599
+							}
600
+							return false;
601
+						}
602
+						break;
603
+					// TEST #5 : check that a config class name has been set
604
+					case 5:
605
+						if (empty($config_class)) {
606
+							if ($display_errors) {
607
+								throw new EE_Error(
608
+									__(
609
+										'No class name has been provided for the specific configuration section.',
610
+										'event_espresso'
611
+									)
612
+								);
613
+							}
614
+							return false;
615
+						}
616
+						break;
617
+					// TEST #6 : verify config class is accessible
618
+					case 6:
619
+						if (! class_exists($config_class)) {
620
+							if ($display_errors) {
621
+								throw new EE_Error(
622
+									sprintf(
623
+										__(
624
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
625
+											'event_espresso'
626
+										),
627
+										$config_class
628
+									)
629
+								);
630
+							}
631
+							return false;
632
+						}
633
+						break;
634
+					// TEST #7 : check that config has even been set
635
+					case 7:
636
+						if (! isset($this->{$section}->{$name})) {
637
+							if ($display_errors) {
638
+								throw new EE_Error(
639
+									sprintf(
640
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
641
+										$section,
642
+										$name
643
+									)
644
+								);
645
+							}
646
+							return false;
647
+						} else {
648
+							// and make sure it's not serialized
649
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
650
+						}
651
+						break;
652
+					// TEST #8 : check that config is the requested type
653
+					case 8:
654
+						if (! $this->{$section}->{$name} instanceof $config_class) {
655
+							if ($display_errors) {
656
+								throw new EE_Error(
657
+									sprintf(
658
+										__(
659
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
660
+											'event_espresso'
661
+										),
662
+										$section,
663
+										$name,
664
+										$config_class
665
+									)
666
+								);
667
+							}
668
+							return false;
669
+						}
670
+						break;
671
+					// TEST #9 : verify config object
672
+					case 9:
673
+						if (! $config_obj instanceof EE_Config_Base) {
674
+							if ($display_errors) {
675
+								throw new EE_Error(
676
+									sprintf(
677
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
678
+										print_r($config_obj, true)
679
+									)
680
+								);
681
+							}
682
+							return false;
683
+						}
684
+						break;
685
+				}
686
+			}
687
+		} catch (EE_Error $e) {
688
+			$e->get_error();
689
+		}
690
+		// you have successfully run the gauntlet
691
+		return true;
692
+	}
693
+
694
+
695
+	/**
696
+	 *    _generate_config_option_name
697
+	 *
698
+	 * @access        protected
699
+	 * @param        string $section
700
+	 * @param        string $name
701
+	 * @return        string
702
+	 */
703
+	private function _generate_config_option_name($section = '', $name = '')
704
+	{
705
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
706
+	}
707
+
708
+
709
+	/**
710
+	 *    _set_config_class
711
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
712
+	 *
713
+	 * @access    private
714
+	 * @param    string $config_class
715
+	 * @param    string $name
716
+	 * @return    string
717
+	 */
718
+	private function _set_config_class($config_class = '', $name = '')
719
+	{
720
+		return ! empty($config_class)
721
+			? $config_class
722
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
723
+	}
724
+
725
+
726
+	/**
727
+	 *    set_config
728
+	 *
729
+	 * @access    protected
730
+	 * @param    string         $section
731
+	 * @param    string         $name
732
+	 * @param    string         $config_class
733
+	 * @param    EE_Config_Base $config_obj
734
+	 * @return    EE_Config_Base
735
+	 */
736
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
737
+	{
738
+		// ensure config class is set to something
739
+		$config_class = $this->_set_config_class($config_class, $name);
740
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
741
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742
+			return null;
743
+		}
744
+		$config_option_name = $this->_generate_config_option_name($section, $name);
745
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
746
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
747
+			$this->_addon_option_names[ $config_option_name ] = $config_class;
748
+			$this->update_addon_option_names();
749
+		}
750
+		// verify the incoming config object but suppress errors
751
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752
+			$config_obj = new $config_class();
753
+		}
754
+		if (get_option($config_option_name)) {
755
+			EE_Config::log($config_option_name);
756
+			update_option($config_option_name, $config_obj);
757
+			$this->{$section}->{$name} = $config_obj;
758
+			return $this->{$section}->{$name};
759
+		} else {
760
+			// create a wp-option for this config
761
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
762
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
763
+				return $this->{$section}->{$name};
764
+			} else {
765
+				EE_Error::add_error(
766
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
767
+					__FILE__,
768
+					__FUNCTION__,
769
+					__LINE__
770
+				);
771
+				return null;
772
+			}
773
+		}
774
+	}
775
+
776
+
777
+	/**
778
+	 *    update_config
779
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
780
+	 *
781
+	 * @access    public
782
+	 * @param    string                $section
783
+	 * @param    string                $name
784
+	 * @param    EE_Config_Base|string $config_obj
785
+	 * @param    bool                  $throw_errors
786
+	 * @return    bool
787
+	 */
788
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
789
+	{
790
+		// don't allow config updates during WP heartbeats
791
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
792
+			return false;
793
+		}
794
+		$config_obj = maybe_unserialize($config_obj);
795
+		// get class name of the incoming object
796
+		$config_class = get_class($config_obj);
797
+		// run tests 1-5 and 9 to verify config
798
+		if (! $this->_verify_config_params(
799
+			$section,
800
+			$name,
801
+			$config_class,
802
+			$config_obj,
803
+			array(1, 2, 3, 4, 7, 9)
804
+		)
805
+		) {
806
+			return false;
807
+		}
808
+		$config_option_name = $this->_generate_config_option_name($section, $name);
809
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
810
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
811
+			// save new config to db
812
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
813
+				return true;
814
+			}
815
+		} else {
816
+			// first check if the record already exists
817
+			$existing_config = get_option($config_option_name);
818
+			$config_obj = serialize($config_obj);
819
+			// just return if db record is already up to date (NOT type safe comparison)
820
+			if ($existing_config == $config_obj) {
821
+				$this->{$section}->{$name} = $config_obj;
822
+				return true;
823
+			} elseif (update_option($config_option_name, $config_obj)) {
824
+				EE_Config::log($config_option_name);
825
+				// update wp-option for this config class
826
+				$this->{$section}->{$name} = $config_obj;
827
+				return true;
828
+			} elseif ($throw_errors) {
829
+				EE_Error::add_error(
830
+					sprintf(
831
+						__(
832
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
833
+							'event_espresso'
834
+						),
835
+						$config_class,
836
+						'EE_Config->' . $section . '->' . $name
837
+					),
838
+					__FILE__,
839
+					__FUNCTION__,
840
+					__LINE__
841
+				);
842
+			}
843
+		}
844
+		return false;
845
+	}
846
+
847
+
848
+	/**
849
+	 *    get_config
850
+	 *
851
+	 * @access    public
852
+	 * @param    string $section
853
+	 * @param    string $name
854
+	 * @param    string $config_class
855
+	 * @return    mixed EE_Config_Base | NULL
856
+	 */
857
+	public function get_config($section = '', $name = '', $config_class = '')
858
+	{
859
+		// ensure config class is set to something
860
+		$config_class = $this->_set_config_class($config_class, $name);
861
+		// run tests 1-4, 6 and 7 to verify that all params have been set
862
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863
+			return null;
864
+		}
865
+		// now test if the requested config object exists, but suppress errors
866
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
867
+			// config already exists, so pass it back
868
+			return $this->{$section}->{$name};
869
+		}
870
+		// load config option from db if it exists
871
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
872
+		// verify the newly retrieved config object, but suppress errors
873
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
874
+			// config is good, so set it and pass it back
875
+			$this->{$section}->{$name} = $config_obj;
876
+			return $this->{$section}->{$name};
877
+		}
878
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
879
+		$config_obj = $this->set_config($section, $name, $config_class);
880
+		// verify the newly created config object
881
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
882
+			return $this->{$section}->{$name};
883
+		} else {
884
+			EE_Error::add_error(
885
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
886
+				__FILE__,
887
+				__FUNCTION__,
888
+				__LINE__
889
+			);
890
+		}
891
+		return null;
892
+	}
893
+
894
+
895
+	/**
896
+	 *    get_config_option
897
+	 *
898
+	 * @access    public
899
+	 * @param    string $config_option_name
900
+	 * @return    mixed EE_Config_Base | FALSE
901
+	 */
902
+	public function get_config_option($config_option_name = '')
903
+	{
904
+		// retrieve the wp-option for this config class.
905
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
906
+		if (empty($config_option)) {
907
+			EE_Config::log($config_option_name . '-NOT-FOUND');
908
+		}
909
+		return $config_option;
910
+	}
911
+
912
+
913
+	/**
914
+	 * log
915
+	 *
916
+	 * @param string $config_option_name
917
+	 */
918
+	public static function log($config_option_name = '')
919
+	{
920
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
921
+			$config_log = get_option(EE_Config::LOG_NAME, array());
922
+			// copy incoming $_REQUEST and sanitize it so we can save it
923
+			$_request = $_REQUEST;
924
+			array_walk_recursive($_request, 'sanitize_text_field');
925
+			$config_log[ (string) microtime(true) ] = array(
926
+				'config_name' => $config_option_name,
927
+				'request'     => $_request,
928
+			);
929
+			update_option(EE_Config::LOG_NAME, $config_log);
930
+		}
931
+	}
932
+
933
+
934
+	/**
935
+	 * trim_log
936
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
937
+	 */
938
+	public static function trim_log()
939
+	{
940
+		if (! EE_Config::logging_enabled()) {
941
+			return;
942
+		}
943
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
944
+		$log_length = count($config_log);
945
+		if ($log_length > EE_Config::LOG_LENGTH) {
946
+			ksort($config_log);
947
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
948
+			update_option(EE_Config::LOG_NAME, $config_log);
949
+		}
950
+	}
951
+
952
+
953
+	/**
954
+	 *    get_page_for_posts
955
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
956
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
957
+	 *
958
+	 * @access    public
959
+	 * @return    string
960
+	 */
961
+	public static function get_page_for_posts()
962
+	{
963
+		$page_for_posts = get_option('page_for_posts');
964
+		if (! $page_for_posts) {
965
+			return 'posts';
966
+		}
967
+		/** @type WPDB $wpdb */
968
+		global $wpdb;
969
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
970
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
971
+	}
972
+
973
+
974
+	/**
975
+	 *    register_shortcodes_and_modules.
976
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
977
+	 *    In fact, this is where we give modules a chance to let core know they exist
978
+	 *    so they can help trigger maintenance mode if it's needed
979
+	 *
980
+	 * @access    public
981
+	 * @return    void
982
+	 */
983
+	public function register_shortcodes_and_modules()
984
+	{
985
+		// allow modules to set hooks for the rest of the system
986
+		EE_Registry::instance()->modules = $this->_register_modules();
987
+	}
988
+
989
+
990
+	/**
991
+	 *    initialize_shortcodes_and_modules
992
+	 *    meaning they can start adding their hooks to get stuff done
993
+	 *
994
+	 * @access    public
995
+	 * @return    void
996
+	 */
997
+	public function initialize_shortcodes_and_modules()
998
+	{
999
+		// allow modules to set hooks for the rest of the system
1000
+		$this->_initialize_modules();
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 *    widgets_init
1006
+	 *
1007
+	 * @access private
1008
+	 * @return void
1009
+	 */
1010
+	public function widgets_init()
1011
+	{
1012
+		// only init widgets on admin pages when not in complete maintenance, and
1013
+		// on frontend when not in any maintenance mode
1014
+		if (! EE_Maintenance_Mode::instance()->level()
1015
+			|| (
1016
+				is_admin()
1017
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018
+			)
1019
+		) {
1020
+			// grab list of installed widgets
1021
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1022
+			// filter list of modules to register
1023
+			$widgets_to_register = apply_filters(
1024
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1025
+				$widgets_to_register
1026
+			);
1027
+			if (! empty($widgets_to_register)) {
1028
+				// cycle thru widget folders
1029
+				foreach ($widgets_to_register as $widget_path) {
1030
+					// add to list of installed widget modules
1031
+					EE_Config::register_ee_widget($widget_path);
1032
+				}
1033
+			}
1034
+			// filter list of installed modules
1035
+			EE_Registry::instance()->widgets = apply_filters(
1036
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1037
+				EE_Registry::instance()->widgets
1038
+			);
1039
+		}
1040
+	}
1041
+
1042
+
1043
+	/**
1044
+	 *    register_ee_widget - makes core aware of this widget
1045
+	 *
1046
+	 * @access    public
1047
+	 * @param    string $widget_path - full path up to and including widget folder
1048
+	 * @return    void
1049
+	 */
1050
+	public static function register_ee_widget($widget_path = null)
1051
+	{
1052
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1053
+		$widget_ext = '.widget.php';
1054
+		// make all separators match
1055
+		$widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1056
+		// does the file path INCLUDE the actual file name as part of the path ?
1057
+		if (strpos($widget_path, $widget_ext) !== false) {
1058
+			// grab and shortcode file name from directory name and break apart at dots
1059
+			$file_name = explode('.', basename($widget_path));
1060
+			// take first segment from file name pieces and remove class prefix if it exists
1061
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1062
+			// sanitize shortcode directory name
1063
+			$widget = sanitize_key($widget);
1064
+			// now we need to rebuild the shortcode path
1065
+			$widget_path = explode(DS, $widget_path);
1066
+			// remove last segment
1067
+			array_pop($widget_path);
1068
+			// glue it back together
1069
+			$widget_path = implode(DS, $widget_path);
1070
+		} else {
1071
+			// grab and sanitize widget directory name
1072
+			$widget = sanitize_key(basename($widget_path));
1073
+		}
1074
+		// create classname from widget directory name
1075
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076
+		// add class prefix
1077
+		$widget_class = 'EEW_' . $widget;
1078
+		// does the widget exist ?
1079
+		if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1080
+			$msg = sprintf(
1081
+				__(
1082
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1083
+					'event_espresso'
1084
+				),
1085
+				$widget_class,
1086
+				$widget_path . DS . $widget_class . $widget_ext
1087
+			);
1088
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1089
+			return;
1090
+		}
1091
+		// load the widget class file
1092
+		require_once($widget_path . DS . $widget_class . $widget_ext);
1093
+		// verify that class exists
1094
+		if (! class_exists($widget_class)) {
1095
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1096
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1097
+			return;
1098
+		}
1099
+		register_widget($widget_class);
1100
+		// add to array of registered widgets
1101
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1102
+	}
1103
+
1104
+
1105
+	/**
1106
+	 *        _register_modules
1107
+	 *
1108
+	 * @access private
1109
+	 * @return array
1110
+	 */
1111
+	private function _register_modules()
1112
+	{
1113
+		// grab list of installed modules
1114
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1115
+		// filter list of modules to register
1116
+		$modules_to_register = apply_filters(
1117
+			'FHEE__EE_Config__register_modules__modules_to_register',
1118
+			$modules_to_register
1119
+		);
1120
+		if (! empty($modules_to_register)) {
1121
+			// loop through folders
1122
+			foreach ($modules_to_register as $module_path) {
1123
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1124
+				if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1125
+					&& $module_path !== EE_MODULES . 'gateways'
1126
+				) {
1127
+					// add to list of installed modules
1128
+					EE_Config::register_module($module_path);
1129
+				}
1130
+			}
1131
+		}
1132
+		// filter list of installed modules
1133
+		return apply_filters(
1134
+			'FHEE__EE_Config___register_modules__installed_modules',
1135
+			EE_Registry::instance()->modules
1136
+		);
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 *    register_module - makes core aware of this module
1142
+	 *
1143
+	 * @access    public
1144
+	 * @param    string $module_path - full path up to and including module folder
1145
+	 * @return    bool
1146
+	 */
1147
+	public static function register_module($module_path = null)
1148
+	{
1149
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1150
+		$module_ext = '.module.php';
1151
+		// make all separators match
1152
+		$module_path = str_replace(array('\\', '/'), DS, $module_path);
1153
+		// does the file path INCLUDE the actual file name as part of the path ?
1154
+		if (strpos($module_path, $module_ext) !== false) {
1155
+			// grab and shortcode file name from directory name and break apart at dots
1156
+			$module_file = explode('.', basename($module_path));
1157
+			// now we need to rebuild the shortcode path
1158
+			$module_path = explode(DS, $module_path);
1159
+			// remove last segment
1160
+			array_pop($module_path);
1161
+			// glue it back together
1162
+			$module_path = implode(DS, $module_path) . DS;
1163
+			// take first segment from file name pieces and sanitize it
1164
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165
+			// ensure class prefix is added
1166
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1167
+		} else {
1168
+			// we need to generate the filename based off of the folder name
1169
+			// grab and sanitize module name
1170
+			$module = strtolower(basename($module_path));
1171
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172
+			// like trailingslashit()
1173
+			$module_path = rtrim($module_path, DS) . DS;
1174
+			// create classname from module directory name
1175
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176
+			// add class prefix
1177
+			$module_class = 'EED_' . $module;
1178
+		}
1179
+		// does the module exist ?
1180
+		if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1181
+			$msg = sprintf(
1182
+				__(
1183
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1184
+					'event_espresso'
1185
+				),
1186
+				$module
1187
+			);
1188
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1189
+			return false;
1190
+		}
1191
+		// load the module class file
1192
+		require_once($module_path . $module_class . $module_ext);
1193
+		// verify that class exists
1194
+		if (! class_exists($module_class)) {
1195
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1196
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1197
+			return false;
1198
+		}
1199
+		// add to array of registered modules
1200
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1201
+		do_action(
1202
+			'AHEE__EE_Config__register_module__complete',
1203
+			$module_class,
1204
+			EE_Registry::instance()->modules->{$module_class}
1205
+		);
1206
+		return true;
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 *    _initialize_modules
1212
+	 *    allow modules to set hooks for the rest of the system
1213
+	 *
1214
+	 * @access private
1215
+	 * @return void
1216
+	 */
1217
+	private function _initialize_modules()
1218
+	{
1219
+		// cycle thru shortcode folders
1220
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1221
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1222
+			// which set hooks ?
1223
+			if (is_admin()) {
1224
+				// fire immediately
1225
+				call_user_func(array($module_class, 'set_hooks_admin'));
1226
+			} else {
1227
+				// delay until other systems are online
1228
+				add_action(
1229
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1230
+					array($module_class, 'set_hooks')
1231
+				);
1232
+			}
1233
+		}
1234
+	}
1235
+
1236
+
1237
+	/**
1238
+	 *    register_route - adds module method routes to route_map
1239
+	 *
1240
+	 * @access    public
1241
+	 * @param    string $route       - "pretty" public alias for module method
1242
+	 * @param    string $module      - module name (classname without EED_ prefix)
1243
+	 * @param    string $method_name - the actual module method to be routed to
1244
+	 * @param    string $key         - url param key indicating a route is being called
1245
+	 * @return    bool
1246
+	 */
1247
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1248
+	{
1249
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250
+		$module = str_replace('EED_', '', $module);
1251
+		$module_class = 'EED_' . $module;
1252
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1253
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1255
+			return false;
1256
+		}
1257
+		if (empty($route)) {
1258
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1260
+			return false;
1261
+		}
1262
+		if (! method_exists('EED_' . $module, $method_name)) {
1263
+			$msg = sprintf(
1264
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265
+				$route
1266
+			);
1267
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1268
+			return false;
1269
+		}
1270
+		EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1271
+		return true;
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 *    get_route - get module method route
1277
+	 *
1278
+	 * @access    public
1279
+	 * @param    string $route - "pretty" public alias for module method
1280
+	 * @param    string $key   - url param key indicating a route is being called
1281
+	 * @return    string
1282
+	 */
1283
+	public static function get_route($route = null, $key = 'ee')
1284
+	{
1285
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1286
+		$route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1287
+		if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1288
+			return EE_Config::$_module_route_map[ $key ][ $route ];
1289
+		}
1290
+		return null;
1291
+	}
1292
+
1293
+
1294
+	/**
1295
+	 *    get_routes - get ALL module method routes
1296
+	 *
1297
+	 * @access    public
1298
+	 * @return    array
1299
+	 */
1300
+	public static function get_routes()
1301
+	{
1302
+		return EE_Config::$_module_route_map;
1303
+	}
1304
+
1305
+
1306
+	/**
1307
+	 *    register_forward - allows modules to forward request to another module for further processing
1308
+	 *
1309
+	 * @access    public
1310
+	 * @param    string       $route   - "pretty" public alias for module method
1311
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1312
+	 *                                 class, allows different forwards to be served based on status
1313
+	 * @param    array|string $forward - function name or array( class, method )
1314
+	 * @param    string       $key     - url param key indicating a route is being called
1315
+	 * @return    bool
1316
+	 */
1317
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318
+	{
1319
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1321
+			$msg = sprintf(
1322
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1323
+				$route
1324
+			);
1325
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1326
+			return false;
1327
+		}
1328
+		if (empty($forward)) {
1329
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1331
+			return false;
1332
+		}
1333
+		if (is_array($forward)) {
1334
+			if (! isset($forward[1])) {
1335
+				$msg = sprintf(
1336
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337
+					$route
1338
+				);
1339
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1340
+				return false;
1341
+			}
1342
+			if (! method_exists($forward[0], $forward[1])) {
1343
+				$msg = sprintf(
1344
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345
+					$forward[1],
1346
+					$route
1347
+				);
1348
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1349
+				return false;
1350
+			}
1351
+		} elseif (! function_exists($forward)) {
1352
+			$msg = sprintf(
1353
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354
+				$forward,
1355
+				$route
1356
+			);
1357
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1358
+			return false;
1359
+		}
1360
+		EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1361
+		return true;
1362
+	}
1363
+
1364
+
1365
+	/**
1366
+	 *    get_forward - get forwarding route
1367
+	 *
1368
+	 * @access    public
1369
+	 * @param    string  $route  - "pretty" public alias for module method
1370
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1371
+	 *                           allows different forwards to be served based on status
1372
+	 * @param    string  $key    - url param key indicating a route is being called
1373
+	 * @return    string
1374
+	 */
1375
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1376
+	{
1377
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
+		if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1379
+			return apply_filters(
1380
+				'FHEE__EE_Config__get_forward',
1381
+				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1382
+				$route,
1383
+				$status
1384
+			);
1385
+		}
1386
+		return null;
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1392
+	 *    results
1393
+	 *
1394
+	 * @access    public
1395
+	 * @param    string  $route  - "pretty" public alias for module method
1396
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1397
+	 *                           allows different views to be served based on status
1398
+	 * @param    string  $view
1399
+	 * @param    string  $key    - url param key indicating a route is being called
1400
+	 * @return    bool
1401
+	 */
1402
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403
+	{
1404
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1406
+			$msg = sprintf(
1407
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1408
+				$route
1409
+			);
1410
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1411
+			return false;
1412
+		}
1413
+		if (! is_readable($view)) {
1414
+			$msg = sprintf(
1415
+				__(
1416
+					'The %s view file could not be found or is not readable due to file permissions.',
1417
+					'event_espresso'
1418
+				),
1419
+				$view
1420
+			);
1421
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
+			return false;
1423
+		}
1424
+		EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1425
+		return true;
1426
+	}
1427
+
1428
+
1429
+	/**
1430
+	 *    get_view - get view for route and status
1431
+	 *
1432
+	 * @access    public
1433
+	 * @param    string  $route  - "pretty" public alias for module method
1434
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1435
+	 *                           allows different views to be served based on status
1436
+	 * @param    string  $key    - url param key indicating a route is being called
1437
+	 * @return    string
1438
+	 */
1439
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1440
+	{
1441
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
+		if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1443
+			return apply_filters(
1444
+				'FHEE__EE_Config__get_view',
1445
+				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1446
+				$route,
1447
+				$status
1448
+			);
1449
+		}
1450
+		return null;
1451
+	}
1452
+
1453
+
1454
+	public function update_addon_option_names()
1455
+	{
1456
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1457
+	}
1458
+
1459
+
1460
+	public function shutdown()
1461
+	{
1462
+		$this->update_addon_option_names();
1463
+	}
1464
+
1465
+
1466
+	/**
1467
+	 * @return LegacyShortcodesManager
1468
+	 */
1469
+	public static function getLegacyShortcodesManager()
1470
+	{
1471
+
1472
+		if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473
+			EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474
+				EE_Registry::instance()
1475
+			);
1476
+		}
1477
+		return EE_Config::instance()->legacy_shortcodes_manager;
1478
+	}
1479
+
1480
+
1481
+	/**
1482
+	 * register_shortcode - makes core aware of this shortcode
1483
+	 *
1484
+	 * @deprecated 4.9.26
1485
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1486
+	 * @return    bool
1487
+	 */
1488
+	public static function register_shortcode($shortcode_path = null)
1489
+	{
1490
+		EE_Error::doing_it_wrong(
1491
+			__METHOD__,
1492
+			__(
1493
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1494
+				'event_espresso'
1495
+			),
1496
+			'4.9.26'
1497
+		);
1498
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1499
+	}
1500
+}
2262 1501
 
2263
-    /**
2264
-     * ReCaptcha Type
2265
-     *
2266
-     * @var string $recaptcha_type
2267
-     *    options: 'audio', 'image'
2268
-     */
2269
-    public $recaptcha_type;
1502
+/**
1503
+ * Base class used for config classes. These classes should generally not have
1504
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1505
+ * basically, they should just be well-defined stdClasses
1506
+ */
1507
+class EE_Config_Base
1508
+{
2270 1509
 
2271
-    /**
2272
-     * ReCaptcha language
2273
-     *
2274
-     * @var string $recaptcha_language
2275
-     * eg 'en'
2276
-     */
2277
-    public $recaptcha_language;
1510
+	/**
1511
+	 * Utility function for escaping the value of a property and returning.
1512
+	 *
1513
+	 * @param string $property property name (checks to see if exists).
1514
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1515
+	 * @throws \EE_Error
1516
+	 */
1517
+	public function get_pretty($property)
1518
+	{
1519
+		if (! property_exists($this, $property)) {
1520
+			throw new EE_Error(
1521
+				sprintf(
1522
+					__(
1523
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1524
+						'event_espresso'
1525
+					),
1526
+					get_class($this),
1527
+					$property
1528
+				)
1529
+			);
1530
+		}
1531
+		// just handling escaping of strings for now.
1532
+		if (is_string($this->{$property})) {
1533
+			return stripslashes($this->{$property});
1534
+		}
1535
+		return $this->{$property};
1536
+	}
1537
+
1538
+
1539
+	public function populate()
1540
+	{
1541
+		// grab defaults via a new instance of this class.
1542
+		$class_name = get_class($this);
1543
+		$defaults = new $class_name;
1544
+		// loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1545
+		// default from our $defaults object.
1546
+		foreach (get_object_vars($defaults) as $property => $value) {
1547
+			if ($this->{$property} === null) {
1548
+				$this->{$property} = $value;
1549
+			}
1550
+		}
1551
+		// cleanup
1552
+		unset($defaults);
1553
+	}
1554
+
1555
+
1556
+	/**
1557
+	 *        __isset
1558
+	 *
1559
+	 * @param $a
1560
+	 * @return bool
1561
+	 */
1562
+	public function __isset($a)
1563
+	{
1564
+		return false;
1565
+	}
1566
+
1567
+
1568
+	/**
1569
+	 *        __unset
1570
+	 *
1571
+	 * @param $a
1572
+	 * @return bool
1573
+	 */
1574
+	public function __unset($a)
1575
+	{
1576
+		return false;
1577
+	}
1578
+
1579
+
1580
+	/**
1581
+	 *        __clone
1582
+	 */
1583
+	public function __clone()
1584
+	{
1585
+	}
1586
+
1587
+
1588
+	/**
1589
+	 *        __wakeup
1590
+	 */
1591
+	public function __wakeup()
1592
+	{
1593
+	}
1594
+
1595
+
1596
+	/**
1597
+	 *        __destruct
1598
+	 */
1599
+	public function __destruct()
1600
+	{
1601
+	}
1602
+}
2278 1603
 
2279
-    /**
2280
-     * ReCaptcha public key
2281
-     *
2282
-     * @var string $recaptcha_publickey
2283
-     */
2284
-    public $recaptcha_publickey;
1604
+/**
1605
+ * Class for defining what's in the EE_Config relating to registration settings
1606
+ */
1607
+class EE_Core_Config extends EE_Config_Base
1608
+{
2285 1609
 
2286
-    /**
2287
-     * ReCaptcha private key
2288
-     *
2289
-     * @var string $recaptcha_privatekey
2290
-     */
2291
-    public $recaptcha_privatekey;
1610
+	const OPTION_NAME_UXIP = 'ee_ueip_optin';
1611
+
1612
+
1613
+	public $current_blog_id;
1614
+
1615
+	public $ee_ueip_optin;
1616
+
1617
+	public $ee_ueip_has_notified;
1618
+
1619
+	/**
1620
+	 * Not to be confused with the 4 critical page variables (See
1621
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1622
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1623
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1624
+	 *
1625
+	 * @var array
1626
+	 */
1627
+	public $post_shortcodes;
1628
+
1629
+	public $module_route_map;
1630
+
1631
+	public $module_forward_map;
1632
+
1633
+	public $module_view_map;
1634
+
1635
+	/**
1636
+	 * The next 4 vars are the IDs of critical EE pages.
1637
+	 *
1638
+	 * @var int
1639
+	 */
1640
+	public $reg_page_id;
1641
+
1642
+	public $txn_page_id;
1643
+
1644
+	public $thank_you_page_id;
1645
+
1646
+	public $cancel_page_id;
1647
+
1648
+	/**
1649
+	 * The next 4 vars are the URLs of critical EE pages.
1650
+	 *
1651
+	 * @var int
1652
+	 */
1653
+	public $reg_page_url;
1654
+
1655
+	public $txn_page_url;
1656
+
1657
+	public $thank_you_page_url;
1658
+
1659
+	public $cancel_page_url;
1660
+
1661
+	/**
1662
+	 * The next vars relate to the custom slugs for EE CPT routes
1663
+	 */
1664
+	public $event_cpt_slug;
1665
+
1666
+	/**
1667
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1668
+	 * request across blog switches in a multisite context.
1669
+	 * Avoids extra queries to the db for this option.
1670
+	 *
1671
+	 * @var bool
1672
+	 */
1673
+	public static $ee_ueip_option;
1674
+
1675
+
1676
+	/**
1677
+	 *    class constructor
1678
+	 *
1679
+	 * @access    public
1680
+	 */
1681
+	public function __construct()
1682
+	{
1683
+		// set default organization settings
1684
+		$this->current_blog_id = get_current_blog_id();
1685
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1686
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1687
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1688
+		$this->post_shortcodes = array();
1689
+		$this->module_route_map = array();
1690
+		$this->module_forward_map = array();
1691
+		$this->module_view_map = array();
1692
+		// critical EE page IDs
1693
+		$this->reg_page_id = 0;
1694
+		$this->txn_page_id = 0;
1695
+		$this->thank_you_page_id = 0;
1696
+		$this->cancel_page_id = 0;
1697
+		// critical EE page URLs
1698
+		$this->reg_page_url = '';
1699
+		$this->txn_page_url = '';
1700
+		$this->thank_you_page_url = '';
1701
+		$this->cancel_page_url = '';
1702
+		// cpt slugs
1703
+		$this->event_cpt_slug = __('events', 'event_espresso');
1704
+		// ueip constant check
1705
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1706
+			$this->ee_ueip_optin = false;
1707
+			$this->ee_ueip_has_notified = true;
1708
+		}
1709
+	}
1710
+
1711
+
1712
+	/**
1713
+	 * @return array
1714
+	 */
1715
+	public function get_critical_pages_array()
1716
+	{
1717
+		return array(
1718
+			$this->reg_page_id,
1719
+			$this->txn_page_id,
1720
+			$this->thank_you_page_id,
1721
+			$this->cancel_page_id,
1722
+		);
1723
+	}
1724
+
1725
+
1726
+	/**
1727
+	 * @return array
1728
+	 */
1729
+	public function get_critical_pages_shortcodes_array()
1730
+	{
1731
+		return array(
1732
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1733
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1734
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1735
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1736
+		);
1737
+	}
1738
+
1739
+
1740
+	/**
1741
+	 *  gets/returns URL for EE reg_page
1742
+	 *
1743
+	 * @access    public
1744
+	 * @return    string
1745
+	 */
1746
+	public function reg_page_url()
1747
+	{
1748
+		if (! $this->reg_page_url) {
1749
+			$this->reg_page_url = add_query_arg(
1750
+				array('uts' => time()),
1751
+				get_permalink($this->reg_page_id)
1752
+			) . '#checkout';
1753
+		}
1754
+		return $this->reg_page_url;
1755
+	}
1756
+
1757
+
1758
+	/**
1759
+	 *  gets/returns URL for EE txn_page
1760
+	 *
1761
+	 * @param array $query_args like what gets passed to
1762
+	 *                          add_query_arg() as the first argument
1763
+	 * @access    public
1764
+	 * @return    string
1765
+	 */
1766
+	public function txn_page_url($query_args = array())
1767
+	{
1768
+		if (! $this->txn_page_url) {
1769
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1770
+		}
1771
+		if ($query_args) {
1772
+			return add_query_arg($query_args, $this->txn_page_url);
1773
+		} else {
1774
+			return $this->txn_page_url;
1775
+		}
1776
+	}
1777
+
1778
+
1779
+	/**
1780
+	 *  gets/returns URL for EE thank_you_page
1781
+	 *
1782
+	 * @param array $query_args like what gets passed to
1783
+	 *                          add_query_arg() as the first argument
1784
+	 * @access    public
1785
+	 * @return    string
1786
+	 */
1787
+	public function thank_you_page_url($query_args = array())
1788
+	{
1789
+		if (! $this->thank_you_page_url) {
1790
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791
+		}
1792
+		if ($query_args) {
1793
+			return add_query_arg($query_args, $this->thank_you_page_url);
1794
+		} else {
1795
+			return $this->thank_you_page_url;
1796
+		}
1797
+	}
1798
+
1799
+
1800
+	/**
1801
+	 *  gets/returns URL for EE cancel_page
1802
+	 *
1803
+	 * @access    public
1804
+	 * @return    string
1805
+	 */
1806
+	public function cancel_page_url()
1807
+	{
1808
+		if (! $this->cancel_page_url) {
1809
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1810
+		}
1811
+		return $this->cancel_page_url;
1812
+	}
1813
+
1814
+
1815
+	/**
1816
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1817
+	 *
1818
+	 * @since 4.7.5
1819
+	 */
1820
+	protected function _reset_urls()
1821
+	{
1822
+		$this->reg_page_url = '';
1823
+		$this->txn_page_url = '';
1824
+		$this->cancel_page_url = '';
1825
+		$this->thank_you_page_url = '';
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * Used to return what the optin value is set for the EE User Experience Program.
1831
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1832
+	 * on the main site only.
1833
+	 *
1834
+	 * @return bool
1835
+	 */
1836
+	protected function _get_main_ee_ueip_optin()
1837
+	{
1838
+		// if this is the main site then we can just bypass our direct query.
1839
+		if (is_main_site()) {
1840
+			return get_option(self::OPTION_NAME_UXIP, false);
1841
+		}
1842
+		// is this already cached for this request?  If so use it.
1843
+		if (EE_Core_Config::$ee_ueip_option !== null) {
1844
+			return EE_Core_Config::$ee_ueip_option;
1845
+		}
1846
+		global $wpdb;
1847
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1848
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849
+		$option = self::OPTION_NAME_UXIP;
1850
+		// set correct table for query
1851
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1852
+		// rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853
+		// get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854
+		// re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855
+		// this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856
+		// for the purpose of caching.
1857
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1858
+		if (false !== $pre) {
1859
+			EE_Core_Config::$ee_ueip_option = $pre;
1860
+			return EE_Core_Config::$ee_ueip_option;
1861
+		}
1862
+		$row = $wpdb->get_row(
1863
+			$wpdb->prepare(
1864
+				"SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1865
+				$option
1866
+			)
1867
+		);
1868
+		if (is_object($row)) {
1869
+			$value = $row->option_value;
1870
+		} else { // option does not exist so use default.
1871
+			EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1872
+			return EE_Core_Config::$ee_ueip_option;
1873
+		}
1874
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1875
+		return EE_Core_Config::$ee_ueip_option;
1876
+	}
1877
+
1878
+
1879
+	/**
1880
+	 * Utility function for escaping the value of a property and returning.
1881
+	 *
1882
+	 * @param string $property property name (checks to see if exists).
1883
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1884
+	 * @throws \EE_Error
1885
+	 */
1886
+	public function get_pretty($property)
1887
+	{
1888
+		if ($property === self::OPTION_NAME_UXIP) {
1889
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1890
+		}
1891
+		return parent::get_pretty($property);
1892
+	}
1893
+
1894
+
1895
+	/**
1896
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1897
+	 * on the object.
1898
+	 *
1899
+	 * @return array
1900
+	 */
1901
+	public function __sleep()
1902
+	{
1903
+		// reset all url properties
1904
+		$this->_reset_urls();
1905
+		// return what to save to db
1906
+		return array_keys(get_object_vars($this));
1907
+	}
1908
+}
2292 1909
 
2293
-    /**
2294
-     * array of form names protected by ReCaptcha
2295
-     *
2296
-     * @var array $recaptcha_protected_forms
2297
-     */
2298
-    public $recaptcha_protected_forms;
1910
+/**
1911
+ * Config class for storing info on the Organization
1912
+ */
1913
+class EE_Organization_Config extends EE_Config_Base
1914
+{
2299 1915
 
2300
-    /**
2301
-     * ReCaptcha width
2302
-     *
2303
-     * @var int $recaptcha_width
2304
-     * @deprecated
2305
-     */
2306
-    public $recaptcha_width;
1916
+	/**
1917
+	 * @var string $name
1918
+	 * eg EE4.1
1919
+	 */
1920
+	public $name;
1921
+
1922
+	/**
1923
+	 * @var string $address_1
1924
+	 * eg 123 Onna Road
1925
+	 */
1926
+	public $address_1 = '';
1927
+
1928
+	/**
1929
+	 * @var string $address_2
1930
+	 * eg PO Box 123
1931
+	 */
1932
+	public $address_2 = '';
1933
+
1934
+	/**
1935
+	 * @var string $city
1936
+	 * eg Inna City
1937
+	 */
1938
+	public $city = '';
1939
+
1940
+	/**
1941
+	 * @var int $STA_ID
1942
+	 * eg 4
1943
+	 */
1944
+	public $STA_ID = 0;
1945
+
1946
+	/**
1947
+	 * @var string $CNT_ISO
1948
+	 * eg US
1949
+	 */
1950
+	public $CNT_ISO = '';
1951
+
1952
+	/**
1953
+	 * @var string $zip
1954
+	 * eg 12345  or V1A 2B3
1955
+	 */
1956
+	public $zip = '';
1957
+
1958
+	/**
1959
+	 * @var string $email
1960
+	 * eg [email protected]
1961
+	 */
1962
+	public $email;
1963
+
1964
+	/**
1965
+	 * @var string $phone
1966
+	 * eg. 111-111-1111
1967
+	 */
1968
+	public $phone = '';
1969
+
1970
+	/**
1971
+	 * @var string $vat
1972
+	 * VAT/Tax Number
1973
+	 */
1974
+	public $vat = '';
1975
+
1976
+	/**
1977
+	 * @var string $logo_url
1978
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1979
+	 */
1980
+	public $logo_url = '';
1981
+
1982
+	/**
1983
+	 * The below are all various properties for holding links to organization social network profiles
1984
+	 *
1985
+	 * @var string
1986
+	 */
1987
+	/**
1988
+	 * facebook (facebook.com/profile.name)
1989
+	 *
1990
+	 * @var string
1991
+	 */
1992
+	public $facebook = '';
1993
+
1994
+	/**
1995
+	 * twitter (twitter.com/twitter_handle)
1996
+	 *
1997
+	 * @var string
1998
+	 */
1999
+	public $twitter = '';
2000
+
2001
+	/**
2002
+	 * linkedin (linkedin.com/in/profile_name)
2003
+	 *
2004
+	 * @var string
2005
+	 */
2006
+	public $linkedin = '';
2007
+
2008
+	/**
2009
+	 * pinterest (www.pinterest.com/profile_name)
2010
+	 *
2011
+	 * @var string
2012
+	 */
2013
+	public $pinterest = '';
2014
+
2015
+	/**
2016
+	 * google+ (google.com/+profileName)
2017
+	 *
2018
+	 * @var string
2019
+	 */
2020
+	public $google = '';
2021
+
2022
+	/**
2023
+	 * instagram (instagram.com/handle)
2024
+	 *
2025
+	 * @var string
2026
+	 */
2027
+	public $instagram = '';
2028
+
2029
+
2030
+	/**
2031
+	 *    class constructor
2032
+	 *
2033
+	 * @access    public
2034
+	 */
2035
+	public function __construct()
2036
+	{
2037
+		// set default organization settings
2038
+		// decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2039
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2040
+		$this->email = get_bloginfo('admin_email');
2041
+	}
2042
+}
2307 2043
 
2308
-    /**
2309
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2310
-     *
2311
-     * @var boolean $track_invalid_checkout_access
2312
-     */
2313
-    protected $track_invalid_checkout_access = true;
2044
+/**
2045
+ * Class for defining what's in the EE_Config relating to currency
2046
+ */
2047
+class EE_Currency_Config extends EE_Config_Base
2048
+{
2314 2049
 
2315
-    /**
2316
-     * Whether or not to show the privacy policy consent checkbox
2317
-     *
2318
-     * @var bool
2319
-     */
2320
-    public $consent_checkbox_enabled;
2050
+	/**
2051
+	 * @var string $code
2052
+	 * eg 'US'
2053
+	 */
2054
+	public $code;
2055
+
2056
+	/**
2057
+	 * @var string $name
2058
+	 * eg 'Dollar'
2059
+	 */
2060
+	public $name;
2061
+
2062
+	/**
2063
+	 * plural name
2064
+	 *
2065
+	 * @var string $plural
2066
+	 * eg 'Dollars'
2067
+	 */
2068
+	public $plural;
2069
+
2070
+	/**
2071
+	 * currency sign
2072
+	 *
2073
+	 * @var string $sign
2074
+	 * eg '$'
2075
+	 */
2076
+	public $sign;
2077
+
2078
+	/**
2079
+	 * Whether the currency sign should come before the number or not
2080
+	 *
2081
+	 * @var boolean $sign_b4
2082
+	 */
2083
+	public $sign_b4;
2084
+
2085
+	/**
2086
+	 * How many digits should come after the decimal place
2087
+	 *
2088
+	 * @var int $dec_plc
2089
+	 */
2090
+	public $dec_plc;
2091
+
2092
+	/**
2093
+	 * Symbol to use for decimal mark
2094
+	 *
2095
+	 * @var string $dec_mrk
2096
+	 * eg '.'
2097
+	 */
2098
+	public $dec_mrk;
2099
+
2100
+	/**
2101
+	 * Symbol to use for thousands
2102
+	 *
2103
+	 * @var string $thsnds
2104
+	 * eg ','
2105
+	 */
2106
+	public $thsnds;
2107
+
2108
+
2109
+	/**
2110
+	 *    class constructor
2111
+	 *
2112
+	 * @access    public
2113
+	 * @param string $CNT_ISO
2114
+	 * @throws \EE_Error
2115
+	 */
2116
+	public function __construct($CNT_ISO = '')
2117
+	{
2118
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2119
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2120
+		// get country code from organization settings or use default
2121
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2122
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2123
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2124
+			: '';
2125
+		// but override if requested
2126
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2128
+		if (! empty($CNT_ISO)
2129
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2130
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131
+		) {
2132
+			// retrieve the country settings from the db, just in case they have been customized
2133
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134
+			if ($country instanceof EE_Country) {
2135
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2136
+				$this->name = $country->currency_name_single();    // Dollar
2137
+				$this->plural = $country->currency_name_plural();    // Dollars
2138
+				$this->sign = $country->currency_sign();            // currency sign: $
2139
+				$this->sign_b4 = $country->currency_sign_before(
2140
+				);        // currency sign before or after: $TRUE  or  FALSE$
2141
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2142
+				$this->dec_mrk = $country->currency_decimal_mark(
2143
+				);    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144
+				$this->thsnds = $country->currency_thousands_separator(
2145
+				);    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146
+			}
2147
+		}
2148
+		// fallback to hardcoded defaults, in case the above failed
2149
+		if (empty($this->code)) {
2150
+			// set default currency settings
2151
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2152
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2153
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2154
+			$this->sign = '$';    // currency sign: $
2155
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2156
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2157
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159
+		}
2160
+	}
2161
+}
2321 2162
 
2322
-    /**
2323
-     * Label text to show on the checkbox
2324
-     *
2325
-     * @var string
2326
-     */
2327
-    public $consent_checkbox_label_text;
2163
+/**
2164
+ * Class for defining what's in the EE_Config relating to registration settings
2165
+ */
2166
+class EE_Registration_Config extends EE_Config_Base
2167
+{
2328 2168
 
2329
-    /*
2169
+	/**
2170
+	 * Default registration status
2171
+	 *
2172
+	 * @var string $default_STS_ID
2173
+	 * eg 'RPP'
2174
+	 */
2175
+	public $default_STS_ID;
2176
+
2177
+	/**
2178
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2179
+	 * registrations)
2180
+	 *
2181
+	 * @var int
2182
+	 */
2183
+	public $default_maximum_number_of_tickets;
2184
+
2185
+	/**
2186
+	 * level of validation to apply to email addresses
2187
+	 *
2188
+	 * @var string $email_validation_level
2189
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2190
+	 */
2191
+	public $email_validation_level;
2192
+
2193
+	/**
2194
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2195
+	 *
2196
+	 * @var boolean $show_pending_payment_options
2197
+	 */
2198
+	public $show_pending_payment_options;
2199
+
2200
+	/**
2201
+	 * Whether to skip the registration confirmation page
2202
+	 *
2203
+	 * @var boolean $skip_reg_confirmation
2204
+	 */
2205
+	public $skip_reg_confirmation;
2206
+
2207
+	/**
2208
+	 * an array of SPCO reg steps where:
2209
+	 *        the keys denotes the reg step order
2210
+	 *        each element consists of an array with the following elements:
2211
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2212
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2213
+	 *            "slug" => the URL param used to trigger the reg step
2214
+	 *
2215
+	 * @var array $reg_steps
2216
+	 */
2217
+	public $reg_steps;
2218
+
2219
+	/**
2220
+	 * Whether registration confirmation should be the last page of SPCO
2221
+	 *
2222
+	 * @var boolean $reg_confirmation_last
2223
+	 */
2224
+	public $reg_confirmation_last;
2225
+
2226
+	/**
2227
+	 * Whether or not to enable the EE Bot Trap
2228
+	 *
2229
+	 * @var boolean $use_bot_trap
2230
+	 */
2231
+	public $use_bot_trap;
2232
+
2233
+	/**
2234
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2235
+	 *
2236
+	 * @var boolean $use_encryption
2237
+	 */
2238
+	public $use_encryption;
2239
+
2240
+	/**
2241
+	 * Whether or not to use ReCaptcha
2242
+	 *
2243
+	 * @var boolean $use_captcha
2244
+	 */
2245
+	public $use_captcha;
2246
+
2247
+	/**
2248
+	 * ReCaptcha Theme
2249
+	 *
2250
+	 * @var string $recaptcha_theme
2251
+	 *    options: 'dark', 'light', 'invisible'
2252
+	 */
2253
+	public $recaptcha_theme;
2254
+
2255
+	/**
2256
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2257
+	 *
2258
+	 * @var string $recaptcha_badge
2259
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2260
+	 */
2261
+	public $recaptcha_badge;
2262
+
2263
+	/**
2264
+	 * ReCaptcha Type
2265
+	 *
2266
+	 * @var string $recaptcha_type
2267
+	 *    options: 'audio', 'image'
2268
+	 */
2269
+	public $recaptcha_type;
2270
+
2271
+	/**
2272
+	 * ReCaptcha language
2273
+	 *
2274
+	 * @var string $recaptcha_language
2275
+	 * eg 'en'
2276
+	 */
2277
+	public $recaptcha_language;
2278
+
2279
+	/**
2280
+	 * ReCaptcha public key
2281
+	 *
2282
+	 * @var string $recaptcha_publickey
2283
+	 */
2284
+	public $recaptcha_publickey;
2285
+
2286
+	/**
2287
+	 * ReCaptcha private key
2288
+	 *
2289
+	 * @var string $recaptcha_privatekey
2290
+	 */
2291
+	public $recaptcha_privatekey;
2292
+
2293
+	/**
2294
+	 * array of form names protected by ReCaptcha
2295
+	 *
2296
+	 * @var array $recaptcha_protected_forms
2297
+	 */
2298
+	public $recaptcha_protected_forms;
2299
+
2300
+	/**
2301
+	 * ReCaptcha width
2302
+	 *
2303
+	 * @var int $recaptcha_width
2304
+	 * @deprecated
2305
+	 */
2306
+	public $recaptcha_width;
2307
+
2308
+	/**
2309
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2310
+	 *
2311
+	 * @var boolean $track_invalid_checkout_access
2312
+	 */
2313
+	protected $track_invalid_checkout_access = true;
2314
+
2315
+	/**
2316
+	 * Whether or not to show the privacy policy consent checkbox
2317
+	 *
2318
+	 * @var bool
2319
+	 */
2320
+	public $consent_checkbox_enabled;
2321
+
2322
+	/**
2323
+	 * Label text to show on the checkbox
2324
+	 *
2325
+	 * @var string
2326
+	 */
2327
+	public $consent_checkbox_label_text;
2328
+
2329
+	/*
2330 2330
      * String describing how long to keep payment logs. Passed into DateTime constructor
2331 2331
      * @var string
2332 2332
      */
2333
-    public $gateway_log_lifespan = '1 week';
2334
-
2335
-
2336
-    /**
2337
-     *    class constructor
2338
-     *
2339
-     * @access    public
2340
-     */
2341
-    public function __construct()
2342
-    {
2343
-        // set default registration settings
2344
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2345
-        $this->email_validation_level = 'wp_default';
2346
-        $this->show_pending_payment_options = true;
2347
-        $this->skip_reg_confirmation = true;
2348
-        $this->reg_steps = array();
2349
-        $this->reg_confirmation_last = false;
2350
-        $this->use_bot_trap = true;
2351
-        $this->use_encryption = true;
2352
-        $this->use_captcha = false;
2353
-        $this->recaptcha_theme = 'light';
2354
-        $this->recaptcha_badge = 'bottomleft';
2355
-        $this->recaptcha_type = 'image';
2356
-        $this->recaptcha_language = 'en';
2357
-        $this->recaptcha_publickey = null;
2358
-        $this->recaptcha_privatekey = null;
2359
-        $this->recaptcha_protected_forms = array();
2360
-        $this->recaptcha_width = 500;
2361
-        $this->default_maximum_number_of_tickets = 10;
2362
-        $this->consent_checkbox_enabled = false;
2363
-        $this->consent_checkbox_label_text = '';
2364
-        $this->gateway_log_lifespan = '7 days';
2365
-    }
2366
-
2367
-
2368
-    /**
2369
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2370
-     *
2371
-     * @since 4.8.8.rc.019
2372
-     */
2373
-    public function do_hooks()
2374
-    {
2375
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2376
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2377
-        add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2378
-    }
2379
-
2380
-
2381
-    /**
2382
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2383
-     * EVT_default_registration_status field matches the config setting for default_STS_ID.
2384
-     */
2385
-    public function set_default_reg_status_on_EEM_Event()
2386
-    {
2387
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2388
-    }
2389
-
2390
-
2391
-    /**
2392
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2393
-     * for Events matches the config setting for default_maximum_number_of_tickets
2394
-     */
2395
-    public function set_default_max_ticket_on_EEM_Event()
2396
-    {
2397
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2398
-    }
2399
-
2400
-
2401
-    /**
2402
-     * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2403
-     * constructed because that happens before we can get the privacy policy page's permalink.
2404
-     *
2405
-     * @throws InvalidArgumentException
2406
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2407
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2408
-     */
2409
-    public function setDefaultCheckboxLabelText()
2410
-    {
2411
-        if ($this->getConsentCheckboxLabelText() === null
2412
-            || $this->getConsentCheckboxLabelText() === '') {
2413
-            $opening_a_tag = '';
2414
-            $closing_a_tag = '';
2415
-            if (function_exists('get_privacy_policy_url')) {
2416
-                $privacy_page_url = get_privacy_policy_url();
2417
-                if (! empty($privacy_page_url)) {
2418
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2419
-                    $closing_a_tag = '</a>';
2420
-                }
2421
-            }
2422
-            $loader = LoaderFactory::getLoader();
2423
-            $org_config = $loader->getShared('EE_Organization_Config');
2424
-            /**
2425
-             * @var $org_config EE_Organization_Config
2426
-             */
2427
-
2428
-            $this->setConsentCheckboxLabelText(
2429
-                sprintf(
2430
-                    esc_html__(
2431
-                        'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2432
-                        'event_espresso'
2433
-                    ),
2434
-                    $org_config->name,
2435
-                    $opening_a_tag,
2436
-                    $closing_a_tag
2437
-                )
2438
-            );
2439
-        }
2440
-    }
2441
-
2442
-
2443
-    /**
2444
-     * @return boolean
2445
-     */
2446
-    public function track_invalid_checkout_access()
2447
-    {
2448
-        return $this->track_invalid_checkout_access;
2449
-    }
2450
-
2451
-
2452
-    /**
2453
-     * @param boolean $track_invalid_checkout_access
2454
-     */
2455
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2456
-    {
2457
-        $this->track_invalid_checkout_access = filter_var(
2458
-            $track_invalid_checkout_access,
2459
-            FILTER_VALIDATE_BOOLEAN
2460
-        );
2461
-    }
2462
-
2463
-
2464
-    /**
2465
-     * Gets the options to make availalbe for the gateway log lifespan
2466
-     * @return array
2467
-     */
2468
-    public function gatewayLogLifespanOptions()
2469
-    {
2470
-        return (array) apply_filters(
2471
-            'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2472
-            array(
2473
-                '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2474
-                '1 day' => esc_html__('1 Day', 'event_espresso'),
2475
-                '7 days' => esc_html__('7 Days', 'event_espresso'),
2476
-                '14 days' => esc_html__('14 Days', 'event_espresso'),
2477
-                '30 days' => esc_html__('30 Days', 'event_espresso')
2478
-            )
2479
-        );
2480
-    }
2481
-
2482
-
2483
-    /**
2484
-     * @return bool
2485
-     */
2486
-    public function isConsentCheckboxEnabled()
2487
-    {
2488
-        return $this->consent_checkbox_enabled;
2489
-    }
2490
-
2491
-
2492
-    /**
2493
-     * @param bool $consent_checkbox_enabled
2494
-     */
2495
-    public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2496
-    {
2497
-        $this->consent_checkbox_enabled = filter_var(
2498
-            $consent_checkbox_enabled,
2499
-            FILTER_VALIDATE_BOOLEAN
2500
-        );
2501
-    }
2502
-
2503
-
2504
-    /**
2505
-     * @return string
2506
-     */
2507
-    public function getConsentCheckboxLabelText()
2508
-    {
2509
-        return $this->consent_checkbox_label_text;
2510
-    }
2511
-
2512
-
2513
-    /**
2514
-     * @param string $consent_checkbox_label_text
2515
-     */
2516
-    public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2517
-    {
2518
-        $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2519
-    }
2333
+	public $gateway_log_lifespan = '1 week';
2334
+
2335
+
2336
+	/**
2337
+	 *    class constructor
2338
+	 *
2339
+	 * @access    public
2340
+	 */
2341
+	public function __construct()
2342
+	{
2343
+		// set default registration settings
2344
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2345
+		$this->email_validation_level = 'wp_default';
2346
+		$this->show_pending_payment_options = true;
2347
+		$this->skip_reg_confirmation = true;
2348
+		$this->reg_steps = array();
2349
+		$this->reg_confirmation_last = false;
2350
+		$this->use_bot_trap = true;
2351
+		$this->use_encryption = true;
2352
+		$this->use_captcha = false;
2353
+		$this->recaptcha_theme = 'light';
2354
+		$this->recaptcha_badge = 'bottomleft';
2355
+		$this->recaptcha_type = 'image';
2356
+		$this->recaptcha_language = 'en';
2357
+		$this->recaptcha_publickey = null;
2358
+		$this->recaptcha_privatekey = null;
2359
+		$this->recaptcha_protected_forms = array();
2360
+		$this->recaptcha_width = 500;
2361
+		$this->default_maximum_number_of_tickets = 10;
2362
+		$this->consent_checkbox_enabled = false;
2363
+		$this->consent_checkbox_label_text = '';
2364
+		$this->gateway_log_lifespan = '7 days';
2365
+	}
2366
+
2367
+
2368
+	/**
2369
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2370
+	 *
2371
+	 * @since 4.8.8.rc.019
2372
+	 */
2373
+	public function do_hooks()
2374
+	{
2375
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2376
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2377
+		add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2378
+	}
2379
+
2380
+
2381
+	/**
2382
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2383
+	 * EVT_default_registration_status field matches the config setting for default_STS_ID.
2384
+	 */
2385
+	public function set_default_reg_status_on_EEM_Event()
2386
+	{
2387
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2388
+	}
2389
+
2390
+
2391
+	/**
2392
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2393
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2394
+	 */
2395
+	public function set_default_max_ticket_on_EEM_Event()
2396
+	{
2397
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2398
+	}
2399
+
2400
+
2401
+	/**
2402
+	 * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2403
+	 * constructed because that happens before we can get the privacy policy page's permalink.
2404
+	 *
2405
+	 * @throws InvalidArgumentException
2406
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2407
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2408
+	 */
2409
+	public function setDefaultCheckboxLabelText()
2410
+	{
2411
+		if ($this->getConsentCheckboxLabelText() === null
2412
+			|| $this->getConsentCheckboxLabelText() === '') {
2413
+			$opening_a_tag = '';
2414
+			$closing_a_tag = '';
2415
+			if (function_exists('get_privacy_policy_url')) {
2416
+				$privacy_page_url = get_privacy_policy_url();
2417
+				if (! empty($privacy_page_url)) {
2418
+					$opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2419
+					$closing_a_tag = '</a>';
2420
+				}
2421
+			}
2422
+			$loader = LoaderFactory::getLoader();
2423
+			$org_config = $loader->getShared('EE_Organization_Config');
2424
+			/**
2425
+			 * @var $org_config EE_Organization_Config
2426
+			 */
2427
+
2428
+			$this->setConsentCheckboxLabelText(
2429
+				sprintf(
2430
+					esc_html__(
2431
+						'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2432
+						'event_espresso'
2433
+					),
2434
+					$org_config->name,
2435
+					$opening_a_tag,
2436
+					$closing_a_tag
2437
+				)
2438
+			);
2439
+		}
2440
+	}
2441
+
2442
+
2443
+	/**
2444
+	 * @return boolean
2445
+	 */
2446
+	public function track_invalid_checkout_access()
2447
+	{
2448
+		return $this->track_invalid_checkout_access;
2449
+	}
2450
+
2451
+
2452
+	/**
2453
+	 * @param boolean $track_invalid_checkout_access
2454
+	 */
2455
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2456
+	{
2457
+		$this->track_invalid_checkout_access = filter_var(
2458
+			$track_invalid_checkout_access,
2459
+			FILTER_VALIDATE_BOOLEAN
2460
+		);
2461
+	}
2462
+
2463
+
2464
+	/**
2465
+	 * Gets the options to make availalbe for the gateway log lifespan
2466
+	 * @return array
2467
+	 */
2468
+	public function gatewayLogLifespanOptions()
2469
+	{
2470
+		return (array) apply_filters(
2471
+			'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2472
+			array(
2473
+				'1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2474
+				'1 day' => esc_html__('1 Day', 'event_espresso'),
2475
+				'7 days' => esc_html__('7 Days', 'event_espresso'),
2476
+				'14 days' => esc_html__('14 Days', 'event_espresso'),
2477
+				'30 days' => esc_html__('30 Days', 'event_espresso')
2478
+			)
2479
+		);
2480
+	}
2481
+
2482
+
2483
+	/**
2484
+	 * @return bool
2485
+	 */
2486
+	public function isConsentCheckboxEnabled()
2487
+	{
2488
+		return $this->consent_checkbox_enabled;
2489
+	}
2490
+
2491
+
2492
+	/**
2493
+	 * @param bool $consent_checkbox_enabled
2494
+	 */
2495
+	public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2496
+	{
2497
+		$this->consent_checkbox_enabled = filter_var(
2498
+			$consent_checkbox_enabled,
2499
+			FILTER_VALIDATE_BOOLEAN
2500
+		);
2501
+	}
2502
+
2503
+
2504
+	/**
2505
+	 * @return string
2506
+	 */
2507
+	public function getConsentCheckboxLabelText()
2508
+	{
2509
+		return $this->consent_checkbox_label_text;
2510
+	}
2511
+
2512
+
2513
+	/**
2514
+	 * @param string $consent_checkbox_label_text
2515
+	 */
2516
+	public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2517
+	{
2518
+		$this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2519
+	}
2520 2520
 }
2521 2521
 
2522 2522
 /**
@@ -2525,154 +2525,154 @@  discard block
 block discarded – undo
2525 2525
 class EE_Admin_Config extends EE_Config_Base
2526 2526
 {
2527 2527
 
2528
-    /**
2529
-     * @var boolean $use_personnel_manager
2530
-     */
2531
-    public $use_personnel_manager;
2532
-
2533
-    /**
2534
-     * @var boolean $use_dashboard_widget
2535
-     */
2536
-    public $use_dashboard_widget;
2537
-
2538
-    /**
2539
-     * @var int $events_in_dashboard
2540
-     */
2541
-    public $events_in_dashboard;
2542
-
2543
-    /**
2544
-     * @var boolean $use_event_timezones
2545
-     */
2546
-    public $use_event_timezones;
2547
-
2548
-    /**
2549
-     * @var boolean $use_full_logging
2550
-     */
2551
-    public $use_full_logging;
2552
-
2553
-    /**
2554
-     * @var string $log_file_name
2555
-     */
2556
-    public $log_file_name;
2557
-
2558
-    /**
2559
-     * @var string $debug_file_name
2560
-     */
2561
-    public $debug_file_name;
2562
-
2563
-    /**
2564
-     * @var boolean $use_remote_logging
2565
-     */
2566
-    public $use_remote_logging;
2567
-
2568
-    /**
2569
-     * @var string $remote_logging_url
2570
-     */
2571
-    public $remote_logging_url;
2572
-
2573
-    /**
2574
-     * @var boolean $show_reg_footer
2575
-     */
2576
-    public $show_reg_footer;
2577
-
2578
-    /**
2579
-     * @var string $affiliate_id
2580
-     */
2581
-    public $affiliate_id;
2582
-
2583
-    /**
2584
-     * help tours on or off (global setting)
2585
-     *
2586
-     * @var boolean
2587
-     */
2588
-    public $help_tour_activation;
2589
-
2590
-    /**
2591
-     * adds extra layer of encoding to session data to prevent serialization errors
2592
-     * but is incompatible with some server configuration errors
2593
-     * if you get "500 internal server errors" during registration, try turning this on
2594
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2595
-     *
2596
-     * @var boolean $encode_session_data
2597
-     */
2598
-    private $encode_session_data = false;
2599
-
2600
-
2601
-    /**
2602
-     *    class constructor
2603
-     *
2604
-     * @access    public
2605
-     */
2606
-    public function __construct()
2607
-    {
2608
-        // set default general admin settings
2609
-        $this->use_personnel_manager = true;
2610
-        $this->use_dashboard_widget = true;
2611
-        $this->events_in_dashboard = 30;
2612
-        $this->use_event_timezones = false;
2613
-        $this->use_full_logging = false;
2614
-        $this->use_remote_logging = false;
2615
-        $this->remote_logging_url = null;
2616
-        $this->show_reg_footer = true;
2617
-        $this->affiliate_id = 'default';
2618
-        $this->help_tour_activation = true;
2619
-        $this->encode_session_data = false;
2620
-    }
2621
-
2622
-
2623
-    /**
2624
-     * @param bool $reset
2625
-     * @return string
2626
-     */
2627
-    public function log_file_name($reset = false)
2628
-    {
2629
-        if (empty($this->log_file_name) || $reset) {
2630
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2631
-            EE_Config::instance()->update_espresso_config(false, false);
2632
-        }
2633
-        return $this->log_file_name;
2634
-    }
2635
-
2636
-
2637
-    /**
2638
-     * @param bool $reset
2639
-     * @return string
2640
-     */
2641
-    public function debug_file_name($reset = false)
2642
-    {
2643
-        if (empty($this->debug_file_name) || $reset) {
2644
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2645
-            EE_Config::instance()->update_espresso_config(false, false);
2646
-        }
2647
-        return $this->debug_file_name;
2648
-    }
2649
-
2650
-
2651
-    /**
2652
-     * @return string
2653
-     */
2654
-    public function affiliate_id()
2655
-    {
2656
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2657
-    }
2658
-
2659
-
2660
-    /**
2661
-     * @return boolean
2662
-     */
2663
-    public function encode_session_data()
2664
-    {
2665
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2666
-    }
2667
-
2668
-
2669
-    /**
2670
-     * @param boolean $encode_session_data
2671
-     */
2672
-    public function set_encode_session_data($encode_session_data)
2673
-    {
2674
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2675
-    }
2528
+	/**
2529
+	 * @var boolean $use_personnel_manager
2530
+	 */
2531
+	public $use_personnel_manager;
2532
+
2533
+	/**
2534
+	 * @var boolean $use_dashboard_widget
2535
+	 */
2536
+	public $use_dashboard_widget;
2537
+
2538
+	/**
2539
+	 * @var int $events_in_dashboard
2540
+	 */
2541
+	public $events_in_dashboard;
2542
+
2543
+	/**
2544
+	 * @var boolean $use_event_timezones
2545
+	 */
2546
+	public $use_event_timezones;
2547
+
2548
+	/**
2549
+	 * @var boolean $use_full_logging
2550
+	 */
2551
+	public $use_full_logging;
2552
+
2553
+	/**
2554
+	 * @var string $log_file_name
2555
+	 */
2556
+	public $log_file_name;
2557
+
2558
+	/**
2559
+	 * @var string $debug_file_name
2560
+	 */
2561
+	public $debug_file_name;
2562
+
2563
+	/**
2564
+	 * @var boolean $use_remote_logging
2565
+	 */
2566
+	public $use_remote_logging;
2567
+
2568
+	/**
2569
+	 * @var string $remote_logging_url
2570
+	 */
2571
+	public $remote_logging_url;
2572
+
2573
+	/**
2574
+	 * @var boolean $show_reg_footer
2575
+	 */
2576
+	public $show_reg_footer;
2577
+
2578
+	/**
2579
+	 * @var string $affiliate_id
2580
+	 */
2581
+	public $affiliate_id;
2582
+
2583
+	/**
2584
+	 * help tours on or off (global setting)
2585
+	 *
2586
+	 * @var boolean
2587
+	 */
2588
+	public $help_tour_activation;
2589
+
2590
+	/**
2591
+	 * adds extra layer of encoding to session data to prevent serialization errors
2592
+	 * but is incompatible with some server configuration errors
2593
+	 * if you get "500 internal server errors" during registration, try turning this on
2594
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2595
+	 *
2596
+	 * @var boolean $encode_session_data
2597
+	 */
2598
+	private $encode_session_data = false;
2599
+
2600
+
2601
+	/**
2602
+	 *    class constructor
2603
+	 *
2604
+	 * @access    public
2605
+	 */
2606
+	public function __construct()
2607
+	{
2608
+		// set default general admin settings
2609
+		$this->use_personnel_manager = true;
2610
+		$this->use_dashboard_widget = true;
2611
+		$this->events_in_dashboard = 30;
2612
+		$this->use_event_timezones = false;
2613
+		$this->use_full_logging = false;
2614
+		$this->use_remote_logging = false;
2615
+		$this->remote_logging_url = null;
2616
+		$this->show_reg_footer = true;
2617
+		$this->affiliate_id = 'default';
2618
+		$this->help_tour_activation = true;
2619
+		$this->encode_session_data = false;
2620
+	}
2621
+
2622
+
2623
+	/**
2624
+	 * @param bool $reset
2625
+	 * @return string
2626
+	 */
2627
+	public function log_file_name($reset = false)
2628
+	{
2629
+		if (empty($this->log_file_name) || $reset) {
2630
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2631
+			EE_Config::instance()->update_espresso_config(false, false);
2632
+		}
2633
+		return $this->log_file_name;
2634
+	}
2635
+
2636
+
2637
+	/**
2638
+	 * @param bool $reset
2639
+	 * @return string
2640
+	 */
2641
+	public function debug_file_name($reset = false)
2642
+	{
2643
+		if (empty($this->debug_file_name) || $reset) {
2644
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2645
+			EE_Config::instance()->update_espresso_config(false, false);
2646
+		}
2647
+		return $this->debug_file_name;
2648
+	}
2649
+
2650
+
2651
+	/**
2652
+	 * @return string
2653
+	 */
2654
+	public function affiliate_id()
2655
+	{
2656
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2657
+	}
2658
+
2659
+
2660
+	/**
2661
+	 * @return boolean
2662
+	 */
2663
+	public function encode_session_data()
2664
+	{
2665
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2666
+	}
2667
+
2668
+
2669
+	/**
2670
+	 * @param boolean $encode_session_data
2671
+	 */
2672
+	public function set_encode_session_data($encode_session_data)
2673
+	{
2674
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2675
+	}
2676 2676
 }
2677 2677
 
2678 2678
 /**
@@ -2681,70 +2681,70 @@  discard block
 block discarded – undo
2681 2681
 class EE_Template_Config extends EE_Config_Base
2682 2682
 {
2683 2683
 
2684
-    /**
2685
-     * @var boolean $enable_default_style
2686
-     */
2687
-    public $enable_default_style;
2688
-
2689
-    /**
2690
-     * @var string $custom_style_sheet
2691
-     */
2692
-    public $custom_style_sheet;
2693
-
2694
-    /**
2695
-     * @var boolean $display_address_in_regform
2696
-     */
2697
-    public $display_address_in_regform;
2698
-
2699
-    /**
2700
-     * @var int $display_description_on_multi_reg_page
2701
-     */
2702
-    public $display_description_on_multi_reg_page;
2703
-
2704
-    /**
2705
-     * @var boolean $use_custom_templates
2706
-     */
2707
-    public $use_custom_templates;
2708
-
2709
-    /**
2710
-     * @var string $current_espresso_theme
2711
-     */
2712
-    public $current_espresso_theme;
2713
-
2714
-    /**
2715
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2716
-     */
2717
-    public $EED_Ticket_Selector;
2718
-
2719
-    /**
2720
-     * @var EE_Event_Single_Config $EED_Event_Single
2721
-     */
2722
-    public $EED_Event_Single;
2723
-
2724
-    /**
2725
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2726
-     */
2727
-    public $EED_Events_Archive;
2728
-
2729
-
2730
-    /**
2731
-     *    class constructor
2732
-     *
2733
-     * @access    public
2734
-     */
2735
-    public function __construct()
2736
-    {
2737
-        // set default template settings
2738
-        $this->enable_default_style = true;
2739
-        $this->custom_style_sheet = null;
2740
-        $this->display_address_in_regform = true;
2741
-        $this->display_description_on_multi_reg_page = false;
2742
-        $this->use_custom_templates = false;
2743
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2744
-        $this->EED_Event_Single = null;
2745
-        $this->EED_Events_Archive = null;
2746
-        $this->EED_Ticket_Selector = null;
2747
-    }
2684
+	/**
2685
+	 * @var boolean $enable_default_style
2686
+	 */
2687
+	public $enable_default_style;
2688
+
2689
+	/**
2690
+	 * @var string $custom_style_sheet
2691
+	 */
2692
+	public $custom_style_sheet;
2693
+
2694
+	/**
2695
+	 * @var boolean $display_address_in_regform
2696
+	 */
2697
+	public $display_address_in_regform;
2698
+
2699
+	/**
2700
+	 * @var int $display_description_on_multi_reg_page
2701
+	 */
2702
+	public $display_description_on_multi_reg_page;
2703
+
2704
+	/**
2705
+	 * @var boolean $use_custom_templates
2706
+	 */
2707
+	public $use_custom_templates;
2708
+
2709
+	/**
2710
+	 * @var string $current_espresso_theme
2711
+	 */
2712
+	public $current_espresso_theme;
2713
+
2714
+	/**
2715
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2716
+	 */
2717
+	public $EED_Ticket_Selector;
2718
+
2719
+	/**
2720
+	 * @var EE_Event_Single_Config $EED_Event_Single
2721
+	 */
2722
+	public $EED_Event_Single;
2723
+
2724
+	/**
2725
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2726
+	 */
2727
+	public $EED_Events_Archive;
2728
+
2729
+
2730
+	/**
2731
+	 *    class constructor
2732
+	 *
2733
+	 * @access    public
2734
+	 */
2735
+	public function __construct()
2736
+	{
2737
+		// set default template settings
2738
+		$this->enable_default_style = true;
2739
+		$this->custom_style_sheet = null;
2740
+		$this->display_address_in_regform = true;
2741
+		$this->display_description_on_multi_reg_page = false;
2742
+		$this->use_custom_templates = false;
2743
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2744
+		$this->EED_Event_Single = null;
2745
+		$this->EED_Events_Archive = null;
2746
+		$this->EED_Ticket_Selector = null;
2747
+	}
2748 2748
 }
2749 2749
 
2750 2750
 /**
@@ -2753,114 +2753,114 @@  discard block
 block discarded – undo
2753 2753
 class EE_Map_Config extends EE_Config_Base
2754 2754
 {
2755 2755
 
2756
-    /**
2757
-     * @var boolean $use_google_maps
2758
-     */
2759
-    public $use_google_maps;
2760
-
2761
-    /**
2762
-     * @var string $api_key
2763
-     */
2764
-    public $google_map_api_key;
2765
-
2766
-    /**
2767
-     * @var int $event_details_map_width
2768
-     */
2769
-    public $event_details_map_width;
2770
-
2771
-    /**
2772
-     * @var int $event_details_map_height
2773
-     */
2774
-    public $event_details_map_height;
2775
-
2776
-    /**
2777
-     * @var int $event_details_map_zoom
2778
-     */
2779
-    public $event_details_map_zoom;
2780
-
2781
-    /**
2782
-     * @var boolean $event_details_display_nav
2783
-     */
2784
-    public $event_details_display_nav;
2785
-
2786
-    /**
2787
-     * @var boolean $event_details_nav_size
2788
-     */
2789
-    public $event_details_nav_size;
2790
-
2791
-    /**
2792
-     * @var string $event_details_control_type
2793
-     */
2794
-    public $event_details_control_type;
2795
-
2796
-    /**
2797
-     * @var string $event_details_map_align
2798
-     */
2799
-    public $event_details_map_align;
2800
-
2801
-    /**
2802
-     * @var int $event_list_map_width
2803
-     */
2804
-    public $event_list_map_width;
2805
-
2806
-    /**
2807
-     * @var int $event_list_map_height
2808
-     */
2809
-    public $event_list_map_height;
2810
-
2811
-    /**
2812
-     * @var int $event_list_map_zoom
2813
-     */
2814
-    public $event_list_map_zoom;
2815
-
2816
-    /**
2817
-     * @var boolean $event_list_display_nav
2818
-     */
2819
-    public $event_list_display_nav;
2820
-
2821
-    /**
2822
-     * @var boolean $event_list_nav_size
2823
-     */
2824
-    public $event_list_nav_size;
2825
-
2826
-    /**
2827
-     * @var string $event_list_control_type
2828
-     */
2829
-    public $event_list_control_type;
2830
-
2831
-    /**
2832
-     * @var string $event_list_map_align
2833
-     */
2834
-    public $event_list_map_align;
2835
-
2836
-
2837
-    /**
2838
-     *    class constructor
2839
-     *
2840
-     * @access    public
2841
-     */
2842
-    public function __construct()
2843
-    {
2844
-        // set default map settings
2845
-        $this->use_google_maps = true;
2846
-        $this->google_map_api_key = '';
2847
-        // for event details pages (reg page)
2848
-        $this->event_details_map_width = 585;            // ee_map_width_single
2849
-        $this->event_details_map_height = 362;            // ee_map_height_single
2850
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2851
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2852
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2853
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2854
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2855
-        // for event list pages
2856
-        $this->event_list_map_width = 300;            // ee_map_width
2857
-        $this->event_list_map_height = 185;        // ee_map_height
2858
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2859
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2860
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2861
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2862
-        $this->event_list_map_align = 'center';            // ee_map_align
2863
-    }
2756
+	/**
2757
+	 * @var boolean $use_google_maps
2758
+	 */
2759
+	public $use_google_maps;
2760
+
2761
+	/**
2762
+	 * @var string $api_key
2763
+	 */
2764
+	public $google_map_api_key;
2765
+
2766
+	/**
2767
+	 * @var int $event_details_map_width
2768
+	 */
2769
+	public $event_details_map_width;
2770
+
2771
+	/**
2772
+	 * @var int $event_details_map_height
2773
+	 */
2774
+	public $event_details_map_height;
2775
+
2776
+	/**
2777
+	 * @var int $event_details_map_zoom
2778
+	 */
2779
+	public $event_details_map_zoom;
2780
+
2781
+	/**
2782
+	 * @var boolean $event_details_display_nav
2783
+	 */
2784
+	public $event_details_display_nav;
2785
+
2786
+	/**
2787
+	 * @var boolean $event_details_nav_size
2788
+	 */
2789
+	public $event_details_nav_size;
2790
+
2791
+	/**
2792
+	 * @var string $event_details_control_type
2793
+	 */
2794
+	public $event_details_control_type;
2795
+
2796
+	/**
2797
+	 * @var string $event_details_map_align
2798
+	 */
2799
+	public $event_details_map_align;
2800
+
2801
+	/**
2802
+	 * @var int $event_list_map_width
2803
+	 */
2804
+	public $event_list_map_width;
2805
+
2806
+	/**
2807
+	 * @var int $event_list_map_height
2808
+	 */
2809
+	public $event_list_map_height;
2810
+
2811
+	/**
2812
+	 * @var int $event_list_map_zoom
2813
+	 */
2814
+	public $event_list_map_zoom;
2815
+
2816
+	/**
2817
+	 * @var boolean $event_list_display_nav
2818
+	 */
2819
+	public $event_list_display_nav;
2820
+
2821
+	/**
2822
+	 * @var boolean $event_list_nav_size
2823
+	 */
2824
+	public $event_list_nav_size;
2825
+
2826
+	/**
2827
+	 * @var string $event_list_control_type
2828
+	 */
2829
+	public $event_list_control_type;
2830
+
2831
+	/**
2832
+	 * @var string $event_list_map_align
2833
+	 */
2834
+	public $event_list_map_align;
2835
+
2836
+
2837
+	/**
2838
+	 *    class constructor
2839
+	 *
2840
+	 * @access    public
2841
+	 */
2842
+	public function __construct()
2843
+	{
2844
+		// set default map settings
2845
+		$this->use_google_maps = true;
2846
+		$this->google_map_api_key = '';
2847
+		// for event details pages (reg page)
2848
+		$this->event_details_map_width = 585;            // ee_map_width_single
2849
+		$this->event_details_map_height = 362;            // ee_map_height_single
2850
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2851
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2852
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2853
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2854
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2855
+		// for event list pages
2856
+		$this->event_list_map_width = 300;            // ee_map_width
2857
+		$this->event_list_map_height = 185;        // ee_map_height
2858
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2859
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2860
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2861
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2862
+		$this->event_list_map_align = 'center';            // ee_map_align
2863
+	}
2864 2864
 }
2865 2865
 
2866 2866
 /**
@@ -2869,46 +2869,46 @@  discard block
 block discarded – undo
2869 2869
 class EE_Events_Archive_Config extends EE_Config_Base
2870 2870
 {
2871 2871
 
2872
-    public $display_status_banner;
2872
+	public $display_status_banner;
2873 2873
 
2874
-    public $display_description;
2874
+	public $display_description;
2875 2875
 
2876
-    public $display_ticket_selector;
2876
+	public $display_ticket_selector;
2877 2877
 
2878
-    public $display_datetimes;
2878
+	public $display_datetimes;
2879 2879
 
2880
-    public $display_venue;
2880
+	public $display_venue;
2881 2881
 
2882
-    public $display_expired_events;
2882
+	public $display_expired_events;
2883 2883
 
2884
-    public $use_sortable_display_order;
2884
+	public $use_sortable_display_order;
2885 2885
 
2886
-    public $display_order_tickets;
2886
+	public $display_order_tickets;
2887 2887
 
2888
-    public $display_order_datetimes;
2888
+	public $display_order_datetimes;
2889 2889
 
2890
-    public $display_order_event;
2890
+	public $display_order_event;
2891 2891
 
2892
-    public $display_order_venue;
2892
+	public $display_order_venue;
2893 2893
 
2894 2894
 
2895
-    /**
2896
-     *    class constructor
2897
-     */
2898
-    public function __construct()
2899
-    {
2900
-        $this->display_status_banner = 0;
2901
-        $this->display_description = 1;
2902
-        $this->display_ticket_selector = 0;
2903
-        $this->display_datetimes = 1;
2904
-        $this->display_venue = 0;
2905
-        $this->display_expired_events = 0;
2906
-        $this->use_sortable_display_order = false;
2907
-        $this->display_order_tickets = 100;
2908
-        $this->display_order_datetimes = 110;
2909
-        $this->display_order_event = 120;
2910
-        $this->display_order_venue = 130;
2911
-    }
2895
+	/**
2896
+	 *    class constructor
2897
+	 */
2898
+	public function __construct()
2899
+	{
2900
+		$this->display_status_banner = 0;
2901
+		$this->display_description = 1;
2902
+		$this->display_ticket_selector = 0;
2903
+		$this->display_datetimes = 1;
2904
+		$this->display_venue = 0;
2905
+		$this->display_expired_events = 0;
2906
+		$this->use_sortable_display_order = false;
2907
+		$this->display_order_tickets = 100;
2908
+		$this->display_order_datetimes = 110;
2909
+		$this->display_order_event = 120;
2910
+		$this->display_order_venue = 130;
2911
+	}
2912 2912
 }
2913 2913
 
2914 2914
 /**
@@ -2917,34 +2917,34 @@  discard block
 block discarded – undo
2917 2917
 class EE_Event_Single_Config extends EE_Config_Base
2918 2918
 {
2919 2919
 
2920
-    public $display_status_banner_single;
2920
+	public $display_status_banner_single;
2921 2921
 
2922
-    public $display_venue;
2922
+	public $display_venue;
2923 2923
 
2924
-    public $use_sortable_display_order;
2924
+	public $use_sortable_display_order;
2925 2925
 
2926
-    public $display_order_tickets;
2926
+	public $display_order_tickets;
2927 2927
 
2928
-    public $display_order_datetimes;
2928
+	public $display_order_datetimes;
2929 2929
 
2930
-    public $display_order_event;
2930
+	public $display_order_event;
2931 2931
 
2932
-    public $display_order_venue;
2932
+	public $display_order_venue;
2933 2933
 
2934 2934
 
2935
-    /**
2936
-     *    class constructor
2937
-     */
2938
-    public function __construct()
2939
-    {
2940
-        $this->display_status_banner_single = 0;
2941
-        $this->display_venue = 1;
2942
-        $this->use_sortable_display_order = false;
2943
-        $this->display_order_tickets = 100;
2944
-        $this->display_order_datetimes = 110;
2945
-        $this->display_order_event = 120;
2946
-        $this->display_order_venue = 130;
2947
-    }
2935
+	/**
2936
+	 *    class constructor
2937
+	 */
2938
+	public function __construct()
2939
+	{
2940
+		$this->display_status_banner_single = 0;
2941
+		$this->display_venue = 1;
2942
+		$this->use_sortable_display_order = false;
2943
+		$this->display_order_tickets = 100;
2944
+		$this->display_order_datetimes = 110;
2945
+		$this->display_order_event = 120;
2946
+		$this->display_order_venue = 130;
2947
+	}
2948 2948
 }
2949 2949
 
2950 2950
 /**
@@ -2953,172 +2953,172 @@  discard block
 block discarded – undo
2953 2953
 class EE_Ticket_Selector_Config extends EE_Config_Base
2954 2954
 {
2955 2955
 
2956
-    /**
2957
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2958
-     */
2959
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2960
-
2961
-    /**
2962
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2963
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2964
-     */
2965
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2966
-
2967
-    /**
2968
-     * @var boolean $show_ticket_sale_columns
2969
-     */
2970
-    public $show_ticket_sale_columns;
2971
-
2972
-    /**
2973
-     * @var boolean $show_ticket_details
2974
-     */
2975
-    public $show_ticket_details;
2976
-
2977
-    /**
2978
-     * @var boolean $show_expired_tickets
2979
-     */
2980
-    public $show_expired_tickets;
2981
-
2982
-    /**
2983
-     * whether or not to display a dropdown box populated with event datetimes
2984
-     * that toggles which tickets are displayed for a ticket selector.
2985
-     * uses one of the *_DATETIME_SELECTOR constants defined above
2986
-     *
2987
-     * @var string $show_datetime_selector
2988
-     */
2989
-    private $show_datetime_selector = 'no_datetime_selector';
2990
-
2991
-    /**
2992
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
2993
-     *
2994
-     * @var int $datetime_selector_threshold
2995
-     */
2996
-    private $datetime_selector_threshold = 3;
2997
-
2998
-    /**
2999
-     * determines the maximum number of "checked" dates in the date and time filter
3000
-     *
3001
-     * @var int $datetime_selector_checked
3002
-     */
3003
-    private $datetime_selector_max_checked = 10;
3004
-
3005
-
3006
-    /**
3007
-     *    class constructor
3008
-     */
3009
-    public function __construct()
3010
-    {
3011
-        $this->show_ticket_sale_columns = true;
3012
-        $this->show_ticket_details = true;
3013
-        $this->show_expired_tickets = true;
3014
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3015
-        $this->datetime_selector_threshold = 3;
3016
-        $this->datetime_selector_max_checked = 10;
3017
-    }
3018
-
3019
-
3020
-    /**
3021
-     * returns true if a datetime selector should be displayed
3022
-     *
3023
-     * @param array $datetimes
3024
-     * @return bool
3025
-     */
3026
-    public function showDatetimeSelector(array $datetimes)
3027
-    {
3028
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3029
-        return ! (
3030
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3031
-            || (
3032
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3033
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3034
-            )
3035
-        );
3036
-    }
3037
-
3038
-
3039
-    /**
3040
-     * @return string
3041
-     */
3042
-    public function getShowDatetimeSelector()
3043
-    {
3044
-        return $this->show_datetime_selector;
3045
-    }
3046
-
3047
-
3048
-    /**
3049
-     * @param bool $keys_only
3050
-     * @return array
3051
-     */
3052
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3053
-    {
3054
-        return $keys_only
3055
-            ? array(
3056
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3057
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3058
-            )
3059
-            : array(
3060
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3061
-                    'Do not show date & time filter',
3062
-                    'event_espresso'
3063
-                ),
3064
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3065
-                    'Maybe show date & time filter',
3066
-                    'event_espresso'
3067
-                ),
3068
-            );
3069
-    }
3070
-
3071
-
3072
-    /**
3073
-     * @param string $show_datetime_selector
3074
-     */
3075
-    public function setShowDatetimeSelector($show_datetime_selector)
3076
-    {
3077
-        $this->show_datetime_selector = in_array(
3078
-            $show_datetime_selector,
3079
-            $this->getShowDatetimeSelectorOptions(),
3080
-            true
3081
-        )
3082
-            ? $show_datetime_selector
3083
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3084
-    }
3085
-
3086
-
3087
-    /**
3088
-     * @return int
3089
-     */
3090
-    public function getDatetimeSelectorThreshold()
3091
-    {
3092
-        return $this->datetime_selector_threshold;
3093
-    }
3094
-
3095
-
3096
-    /**
3097
-     * @param int $datetime_selector_threshold
3098
-     */
3099
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3100
-    {
3101
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3102
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3103
-    }
3104
-
3105
-
3106
-    /**
3107
-     * @return int
3108
-     */
3109
-    public function getDatetimeSelectorMaxChecked()
3110
-    {
3111
-        return $this->datetime_selector_max_checked;
3112
-    }
3113
-
3114
-
3115
-    /**
3116
-     * @param int $datetime_selector_max_checked
3117
-     */
3118
-    public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3119
-    {
3120
-        $this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3121
-    }
2956
+	/**
2957
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2958
+	 */
2959
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2960
+
2961
+	/**
2962
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2963
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2964
+	 */
2965
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2966
+
2967
+	/**
2968
+	 * @var boolean $show_ticket_sale_columns
2969
+	 */
2970
+	public $show_ticket_sale_columns;
2971
+
2972
+	/**
2973
+	 * @var boolean $show_ticket_details
2974
+	 */
2975
+	public $show_ticket_details;
2976
+
2977
+	/**
2978
+	 * @var boolean $show_expired_tickets
2979
+	 */
2980
+	public $show_expired_tickets;
2981
+
2982
+	/**
2983
+	 * whether or not to display a dropdown box populated with event datetimes
2984
+	 * that toggles which tickets are displayed for a ticket selector.
2985
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
2986
+	 *
2987
+	 * @var string $show_datetime_selector
2988
+	 */
2989
+	private $show_datetime_selector = 'no_datetime_selector';
2990
+
2991
+	/**
2992
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
2993
+	 *
2994
+	 * @var int $datetime_selector_threshold
2995
+	 */
2996
+	private $datetime_selector_threshold = 3;
2997
+
2998
+	/**
2999
+	 * determines the maximum number of "checked" dates in the date and time filter
3000
+	 *
3001
+	 * @var int $datetime_selector_checked
3002
+	 */
3003
+	private $datetime_selector_max_checked = 10;
3004
+
3005
+
3006
+	/**
3007
+	 *    class constructor
3008
+	 */
3009
+	public function __construct()
3010
+	{
3011
+		$this->show_ticket_sale_columns = true;
3012
+		$this->show_ticket_details = true;
3013
+		$this->show_expired_tickets = true;
3014
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3015
+		$this->datetime_selector_threshold = 3;
3016
+		$this->datetime_selector_max_checked = 10;
3017
+	}
3018
+
3019
+
3020
+	/**
3021
+	 * returns true if a datetime selector should be displayed
3022
+	 *
3023
+	 * @param array $datetimes
3024
+	 * @return bool
3025
+	 */
3026
+	public function showDatetimeSelector(array $datetimes)
3027
+	{
3028
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3029
+		return ! (
3030
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3031
+			|| (
3032
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3033
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3034
+			)
3035
+		);
3036
+	}
3037
+
3038
+
3039
+	/**
3040
+	 * @return string
3041
+	 */
3042
+	public function getShowDatetimeSelector()
3043
+	{
3044
+		return $this->show_datetime_selector;
3045
+	}
3046
+
3047
+
3048
+	/**
3049
+	 * @param bool $keys_only
3050
+	 * @return array
3051
+	 */
3052
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3053
+	{
3054
+		return $keys_only
3055
+			? array(
3056
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3057
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3058
+			)
3059
+			: array(
3060
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3061
+					'Do not show date & time filter',
3062
+					'event_espresso'
3063
+				),
3064
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3065
+					'Maybe show date & time filter',
3066
+					'event_espresso'
3067
+				),
3068
+			);
3069
+	}
3070
+
3071
+
3072
+	/**
3073
+	 * @param string $show_datetime_selector
3074
+	 */
3075
+	public function setShowDatetimeSelector($show_datetime_selector)
3076
+	{
3077
+		$this->show_datetime_selector = in_array(
3078
+			$show_datetime_selector,
3079
+			$this->getShowDatetimeSelectorOptions(),
3080
+			true
3081
+		)
3082
+			? $show_datetime_selector
3083
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3084
+	}
3085
+
3086
+
3087
+	/**
3088
+	 * @return int
3089
+	 */
3090
+	public function getDatetimeSelectorThreshold()
3091
+	{
3092
+		return $this->datetime_selector_threshold;
3093
+	}
3094
+
3095
+
3096
+	/**
3097
+	 * @param int $datetime_selector_threshold
3098
+	 */
3099
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3100
+	{
3101
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3102
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3103
+	}
3104
+
3105
+
3106
+	/**
3107
+	 * @return int
3108
+	 */
3109
+	public function getDatetimeSelectorMaxChecked()
3110
+	{
3111
+		return $this->datetime_selector_max_checked;
3112
+	}
3113
+
3114
+
3115
+	/**
3116
+	 * @param int $datetime_selector_max_checked
3117
+	 */
3118
+	public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3119
+	{
3120
+		$this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3121
+	}
3122 3122
 }
3123 3123
 
3124 3124
 /**
@@ -3131,86 +3131,86 @@  discard block
 block discarded – undo
3131 3131
 class EE_Environment_Config extends EE_Config_Base
3132 3132
 {
3133 3133
 
3134
-    /**
3135
-     * Hold any php environment variables that we want to track.
3136
-     *
3137
-     * @var stdClass;
3138
-     */
3139
-    public $php;
3140
-
3141
-
3142
-    /**
3143
-     *    constructor
3144
-     */
3145
-    public function __construct()
3146
-    {
3147
-        $this->php = new stdClass();
3148
-        $this->_set_php_values();
3149
-    }
3150
-
3151
-
3152
-    /**
3153
-     * This sets the php environment variables.
3154
-     *
3155
-     * @since 4.4.0
3156
-     * @return void
3157
-     */
3158
-    protected function _set_php_values()
3159
-    {
3160
-        $this->php->max_input_vars = ini_get('max_input_vars');
3161
-        $this->php->version = phpversion();
3162
-    }
3163
-
3164
-
3165
-    /**
3166
-     * helper method for determining whether input_count is
3167
-     * reaching the potential maximum the server can handle
3168
-     * according to max_input_vars
3169
-     *
3170
-     * @param int   $input_count the count of input vars.
3171
-     * @return array {
3172
-     *                           An array that represents whether available space and if no available space the error
3173
-     *                           message.
3174
-     * @type bool   $has_space   whether more inputs can be added.
3175
-     * @type string $msg         Any message to be displayed.
3176
-     *                           }
3177
-     */
3178
-    public function max_input_vars_limit_check($input_count = 0)
3179
-    {
3180
-        if (! empty($this->php->max_input_vars)
3181
-            && ($input_count >= $this->php->max_input_vars)
3182
-        ) {
3183
-            // check the server setting because the config value could be stale
3184
-            $max_input_vars = ini_get('max_input_vars');
3185
-            if ($input_count >= $max_input_vars) {
3186
-                return sprintf(
3187
-                    esc_html__(
3188
-                        'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3189
-                        'event_espresso'
3190
-                    ),
3191
-                    '<br>',
3192
-                    $input_count,
3193
-                    $max_input_vars
3194
-                );
3195
-            } else {
3196
-                return '';
3197
-            }
3198
-        } else {
3199
-            return '';
3200
-        }
3201
-    }
3202
-
3203
-
3204
-    /**
3205
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3206
-     *
3207
-     * @since 4.4.1
3208
-     * @return void
3209
-     */
3210
-    public function recheck_values()
3211
-    {
3212
-        $this->_set_php_values();
3213
-    }
3134
+	/**
3135
+	 * Hold any php environment variables that we want to track.
3136
+	 *
3137
+	 * @var stdClass;
3138
+	 */
3139
+	public $php;
3140
+
3141
+
3142
+	/**
3143
+	 *    constructor
3144
+	 */
3145
+	public function __construct()
3146
+	{
3147
+		$this->php = new stdClass();
3148
+		$this->_set_php_values();
3149
+	}
3150
+
3151
+
3152
+	/**
3153
+	 * This sets the php environment variables.
3154
+	 *
3155
+	 * @since 4.4.0
3156
+	 * @return void
3157
+	 */
3158
+	protected function _set_php_values()
3159
+	{
3160
+		$this->php->max_input_vars = ini_get('max_input_vars');
3161
+		$this->php->version = phpversion();
3162
+	}
3163
+
3164
+
3165
+	/**
3166
+	 * helper method for determining whether input_count is
3167
+	 * reaching the potential maximum the server can handle
3168
+	 * according to max_input_vars
3169
+	 *
3170
+	 * @param int   $input_count the count of input vars.
3171
+	 * @return array {
3172
+	 *                           An array that represents whether available space and if no available space the error
3173
+	 *                           message.
3174
+	 * @type bool   $has_space   whether more inputs can be added.
3175
+	 * @type string $msg         Any message to be displayed.
3176
+	 *                           }
3177
+	 */
3178
+	public function max_input_vars_limit_check($input_count = 0)
3179
+	{
3180
+		if (! empty($this->php->max_input_vars)
3181
+			&& ($input_count >= $this->php->max_input_vars)
3182
+		) {
3183
+			// check the server setting because the config value could be stale
3184
+			$max_input_vars = ini_get('max_input_vars');
3185
+			if ($input_count >= $max_input_vars) {
3186
+				return sprintf(
3187
+					esc_html__(
3188
+						'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3189
+						'event_espresso'
3190
+					),
3191
+					'<br>',
3192
+					$input_count,
3193
+					$max_input_vars
3194
+				);
3195
+			} else {
3196
+				return '';
3197
+			}
3198
+		} else {
3199
+			return '';
3200
+		}
3201
+	}
3202
+
3203
+
3204
+	/**
3205
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3206
+	 *
3207
+	 * @since 4.4.1
3208
+	 * @return void
3209
+	 */
3210
+	public function recheck_values()
3211
+	{
3212
+		$this->_set_php_values();
3213
+	}
3214 3214
 }
3215 3215
 
3216 3216
 /**
@@ -3223,21 +3223,21 @@  discard block
 block discarded – undo
3223 3223
 class EE_Tax_Config extends EE_Config_Base
3224 3224
 {
3225 3225
 
3226
-    /*
3226
+	/*
3227 3227
      * flag to indicate whether or not to display ticket prices with the taxes included
3228 3228
      *
3229 3229
      * @var boolean $prices_displayed_including_taxes
3230 3230
      */
3231
-    public $prices_displayed_including_taxes;
3231
+	public $prices_displayed_including_taxes;
3232 3232
 
3233 3233
 
3234
-    /**
3235
-     *    class constructor
3236
-     */
3237
-    public function __construct()
3238
-    {
3239
-        $this->prices_displayed_including_taxes = true;
3240
-    }
3234
+	/**
3235
+	 *    class constructor
3236
+	 */
3237
+	public function __construct()
3238
+	{
3239
+		$this->prices_displayed_including_taxes = true;
3240
+	}
3241 3241
 }
3242 3242
 
3243 3243
 /**
@@ -3251,19 +3251,19 @@  discard block
 block discarded – undo
3251 3251
 class EE_Messages_Config extends EE_Config_Base
3252 3252
 {
3253 3253
 
3254
-    /**
3255
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3256
-     * A value of 0 represents never deleting.  Default is 0.
3257
-     *
3258
-     * @var integer
3259
-     */
3260
-    public $delete_threshold;
3254
+	/**
3255
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3256
+	 * A value of 0 represents never deleting.  Default is 0.
3257
+	 *
3258
+	 * @var integer
3259
+	 */
3260
+	public $delete_threshold;
3261 3261
 
3262 3262
 
3263
-    public function __construct()
3264
-    {
3265
-        $this->delete_threshold = 0;
3266
-    }
3263
+	public function __construct()
3264
+	{
3265
+		$this->delete_threshold = 0;
3266
+	}
3267 3267
 }
3268 3268
 
3269 3269
 /**
@@ -3274,31 +3274,31 @@  discard block
 block discarded – undo
3274 3274
 class EE_Gateway_Config extends EE_Config_Base
3275 3275
 {
3276 3276
 
3277
-    /**
3278
-     * Array with keys that are payment gateways slugs, and values are arrays
3279
-     * with any config info the gateway wants to store
3280
-     *
3281
-     * @var array
3282
-     */
3283
-    public $payment_settings;
3284
-
3285
-    /**
3286
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3287
-     * the gateway is stored in the uploads directory
3288
-     *
3289
-     * @var array
3290
-     */
3291
-    public $active_gateways;
3292
-
3293
-
3294
-    /**
3295
-     *    class constructor
3296
-     *
3297
-     * @deprecated
3298
-     */
3299
-    public function __construct()
3300
-    {
3301
-        $this->payment_settings = array();
3302
-        $this->active_gateways = array('Invoice' => false);
3303
-    }
3277
+	/**
3278
+	 * Array with keys that are payment gateways slugs, and values are arrays
3279
+	 * with any config info the gateway wants to store
3280
+	 *
3281
+	 * @var array
3282
+	 */
3283
+	public $payment_settings;
3284
+
3285
+	/**
3286
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3287
+	 * the gateway is stored in the uploads directory
3288
+	 *
3289
+	 * @var array
3290
+	 */
3291
+	public $active_gateways;
3292
+
3293
+
3294
+	/**
3295
+	 *    class constructor
3296
+	 *
3297
+	 * @deprecated
3298
+	 */
3299
+	public function __construct()
3300
+	{
3301
+		$this->payment_settings = array();
3302
+		$this->active_gateways = array('Invoice' => false);
3303
+	}
3304 3304
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Registration.class.php 1 patch
Indentation   +2062 added lines, -2062 removed lines patch added patch discarded remove patch
@@ -17,2066 +17,2066 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Used to reference when a registration has never been checked in.
22
-     *
23
-     * @deprecated use \EE_Checkin::status_checked_never instead
24
-     * @type int
25
-     */
26
-    const checkin_status_never = 2;
27
-
28
-    /**
29
-     * Used to reference when a registration has been checked in.
30
-     *
31
-     * @deprecated use \EE_Checkin::status_checked_in instead
32
-     * @type int
33
-     */
34
-    const checkin_status_in = 1;
35
-
36
-
37
-    /**
38
-     * Used to reference when a registration has been checked out.
39
-     *
40
-     * @deprecated use \EE_Checkin::status_checked_out instead
41
-     * @type int
42
-     */
43
-    const checkin_status_out = 0;
44
-
45
-
46
-    /**
47
-     * extra meta key for tracking reg status os trashed registrations
48
-     *
49
-     * @type string
50
-     */
51
-    const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
52
-
53
-
54
-    /**
55
-     * extra meta key for tracking if registration has reserved ticket
56
-     *
57
-     * @type string
58
-     */
59
-    const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
60
-
61
-
62
-    /**
63
-     * @param array  $props_n_values          incoming values
64
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
65
-     *                                        used.)
66
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
67
-     *                                        date_format and the second value is the time format
68
-     * @return EE_Registration
69
-     * @throws EE_Error
70
-     */
71
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
72
-    {
73
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
74
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
75
-    }
76
-
77
-
78
-    /**
79
-     * @param array  $props_n_values  incoming values from the database
80
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
81
-     *                                the website will be used.
82
-     * @return EE_Registration
83
-     */
84
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
85
-    {
86
-        return new self($props_n_values, true, $timezone);
87
-    }
88
-
89
-
90
-    /**
91
-     *        Set Event ID
92
-     *
93
-     * @param        int $EVT_ID Event ID
94
-     * @throws EE_Error
95
-     * @throws RuntimeException
96
-     */
97
-    public function set_event($EVT_ID = 0)
98
-    {
99
-        $this->set('EVT_ID', $EVT_ID);
100
-    }
101
-
102
-
103
-    /**
104
-     * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
105
-     * be routed to internal methods
106
-     *
107
-     * @param string $field_name
108
-     * @param mixed  $field_value
109
-     * @param bool   $use_default
110
-     * @throws EE_Error
111
-     * @throws EntityNotFoundException
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     * @throws ReflectionException
116
-     * @throws RuntimeException
117
-     */
118
-    public function set($field_name, $field_value, $use_default = false)
119
-    {
120
-        switch ($field_name) {
121
-            case 'REG_code':
122
-                if (! empty($field_value) && $this->reg_code() === null) {
123
-                    $this->set_reg_code($field_value, $use_default);
124
-                }
125
-                break;
126
-            case 'STS_ID':
127
-                $this->set_status($field_value, $use_default);
128
-                break;
129
-            default:
130
-                parent::set($field_name, $field_value, $use_default);
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     * Set Status ID
137
-     * updates the registration status and ALSO...
138
-     * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
139
-     * calls release_registration_space() if the reg status changes FROM approved to any other reg status
140
-     *
141
-     * @param string                $new_STS_ID
142
-     * @param boolean               $use_default
143
-     * @param ContextInterface|null $context
144
-     * @return bool
145
-     * @throws EE_Error
146
-     * @throws EntityNotFoundException
147
-     * @throws InvalidArgumentException
148
-     * @throws ReflectionException
149
-     * @throws RuntimeException
150
-     * @throws InvalidDataTypeException
151
-     * @throws InvalidInterfaceException
152
-     */
153
-    public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null)
154
-    {
155
-        // get current REG_Status
156
-        $old_STS_ID = $this->status_ID();
157
-        // if status has changed
158
-        if ($old_STS_ID !== $new_STS_ID // and that status has actually changed
159
-            && ! empty($old_STS_ID) // and that old status is actually set
160
-            && ! empty($new_STS_ID) // as well as the new status
161
-            && $this->ID() // ensure registration is in the db
162
-        ) {
163
-            // update internal status first
164
-            parent::set('STS_ID', $new_STS_ID, $use_default);
165
-            // THEN handle other changes that occur when reg status changes
166
-            // TO approved
167
-            if ($new_STS_ID === EEM_Registration::status_id_approved) {
168
-                // reserve a space by incrementing ticket and datetime sold values
169
-                $this->_reserve_registration_space();
170
-                do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context);
171
-                // OR FROM  approved
172
-            } elseif ($old_STS_ID === EEM_Registration::status_id_approved) {
173
-                // release a space by decrementing ticket and datetime sold values
174
-                $this->_release_registration_space();
175
-                do_action(
176
-                    'AHEE__EE_Registration__set_status__from_approved',
177
-                    $this,
178
-                    $old_STS_ID,
179
-                    $new_STS_ID,
180
-                    $context
181
-                );
182
-            }
183
-            $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context);
184
-            if ($this->statusChangeUpdatesTransaction($context)) {
185
-                $this->updateTransactionAfterStatusChange();
186
-            }
187
-            do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context);
188
-            return true;
189
-        }
190
-        // even though the old value matches the new value, it's still good to
191
-        // allow the parent set method to have a say
192
-        parent::set('STS_ID', $new_STS_ID, $use_default);
193
-        return true;
194
-    }
195
-
196
-
197
-    /**
198
-     * update REGs and TXN when cancelled or declined registrations involved
199
-     *
200
-     * @param string                $new_STS_ID
201
-     * @param string                $old_STS_ID
202
-     * @param ContextInterface|null $context
203
-     * @throws EE_Error
204
-     * @throws InvalidArgumentException
205
-     * @throws InvalidDataTypeException
206
-     * @throws InvalidInterfaceException
207
-     * @throws ReflectionException
208
-     */
209
-    private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, ContextInterface $context = null)
210
-    {
211
-        // these reg statuses should not be considered in any calculations involving monies owing
212
-        $closed_reg_statuses = EEM_Registration::closed_reg_statuses();
213
-        // true if registration has been cancelled or declined
214
-        $this->updateIfCanceled(
215
-            $closed_reg_statuses,
216
-            $new_STS_ID,
217
-            $old_STS_ID,
218
-            $context
219
-        );
220
-        $this->updateIfDeclined(
221
-            $closed_reg_statuses,
222
-            $new_STS_ID,
223
-            $old_STS_ID,
224
-            $context
225
-        );
226
-    }
227
-
228
-
229
-    /**
230
-     * update REGs and TXN when cancelled or declined registrations involved
231
-     *
232
-     * @param array                 $closed_reg_statuses
233
-     * @param string                $new_STS_ID
234
-     * @param string                $old_STS_ID
235
-     * @param ContextInterface|null $context
236
-     * @throws EE_Error
237
-     * @throws InvalidArgumentException
238
-     * @throws InvalidDataTypeException
239
-     * @throws InvalidInterfaceException
240
-     * @throws ReflectionException
241
-     */
242
-    private function updateIfCanceled(
243
-        array $closed_reg_statuses,
244
-        $new_STS_ID,
245
-        $old_STS_ID,
246
-        ContextInterface $context = null
247
-    ) {
248
-        // true if registration has been cancelled or declined
249
-        if (in_array($new_STS_ID, $closed_reg_statuses, true)
250
-            && ! in_array($old_STS_ID, $closed_reg_statuses, true)
251
-        ) {
252
-            /** @type EE_Registration_Processor $registration_processor */
253
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
254
-            /** @type EE_Transaction_Processor $transaction_processor */
255
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
256
-            // cancelled or declined registration
257
-            $registration_processor->update_registration_after_being_canceled_or_declined(
258
-                $this,
259
-                $closed_reg_statuses
260
-            );
261
-            $transaction_processor->update_transaction_after_canceled_or_declined_registration(
262
-                $this,
263
-                $closed_reg_statuses,
264
-                false
265
-            );
266
-            do_action(
267
-                'AHEE__EE_Registration__set_status__canceled_or_declined',
268
-                $this,
269
-                $old_STS_ID,
270
-                $new_STS_ID,
271
-                $context
272
-            );
273
-            return;
274
-        }
275
-    }
276
-
277
-
278
-    /**
279
-     * update REGs and TXN when cancelled or declined registrations involved
280
-     *
281
-     * @param array                 $closed_reg_statuses
282
-     * @param string                $new_STS_ID
283
-     * @param string                $old_STS_ID
284
-     * @param ContextInterface|null $context
285
-     * @throws EE_Error
286
-     * @throws InvalidArgumentException
287
-     * @throws InvalidDataTypeException
288
-     * @throws InvalidInterfaceException
289
-     * @throws ReflectionException
290
-     */
291
-    private function updateIfDeclined(
292
-        array $closed_reg_statuses,
293
-        $new_STS_ID,
294
-        $old_STS_ID,
295
-        ContextInterface $context = null
296
-    ) {
297
-        // true if reinstating cancelled or declined registration
298
-        if (in_array($old_STS_ID, $closed_reg_statuses, true)
299
-            && ! in_array($new_STS_ID, $closed_reg_statuses, true)
300
-        ) {
301
-            /** @type EE_Registration_Processor $registration_processor */
302
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
303
-            /** @type EE_Transaction_Processor $transaction_processor */
304
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
305
-            // reinstating cancelled or declined registration
306
-            $registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
307
-                $this,
308
-                $closed_reg_statuses
309
-            );
310
-            $transaction_processor->update_transaction_after_reinstating_canceled_registration(
311
-                $this,
312
-                $closed_reg_statuses,
313
-                false
314
-            );
315
-            do_action(
316
-                'AHEE__EE_Registration__set_status__after_reinstated',
317
-                $this,
318
-                $old_STS_ID,
319
-                $new_STS_ID,
320
-                $context
321
-            );
322
-        }
323
-    }
324
-
325
-
326
-    /**
327
-     * @param ContextInterface|null $context
328
-     * @return bool
329
-     */
330
-    private function statusChangeUpdatesTransaction(ContextInterface $context = null)
331
-    {
332
-        $contexts_that_do_not_update_transaction = (array) apply_filters(
333
-            'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction',
334
-            array('spco_reg_step_attendee_information_process_registrations'),
335
-            $context,
336
-            $this
337
-        );
338
-        return ! (
339
-            $context instanceof ContextInterface
340
-            && in_array($context->slug(), $contexts_that_do_not_update_transaction, true)
341
-        );
342
-    }
343
-
344
-
345
-    /**
346
-     * @throws EE_Error
347
-     * @throws EntityNotFoundException
348
-     * @throws InvalidArgumentException
349
-     * @throws InvalidDataTypeException
350
-     * @throws InvalidInterfaceException
351
-     * @throws ReflectionException
352
-     * @throws RuntimeException
353
-     */
354
-    private function updateTransactionAfterStatusChange()
355
-    {
356
-        /** @type EE_Transaction_Payments $transaction_payments */
357
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
358
-        $transaction_payments->recalculate_transaction_total($this->transaction(), false);
359
-        $this->transaction()->update_status_based_on_total_paid(true);
360
-    }
361
-
362
-
363
-    /**
364
-     *        get Status ID
365
-     */
366
-    public function status_ID()
367
-    {
368
-        return $this->get('STS_ID');
369
-    }
370
-
371
-
372
-    /**
373
-     * Gets the ticket this registration is for
374
-     *
375
-     * @param boolean $include_archived whether to include archived tickets or not.
376
-     *
377
-     * @return EE_Ticket|EE_Base_Class
378
-     * @throws EE_Error
379
-     */
380
-    public function ticket($include_archived = true)
381
-    {
382
-        $query_params = array();
383
-        if ($include_archived) {
384
-            $query_params['default_where_conditions'] = 'none';
385
-        }
386
-        return $this->get_first_related('Ticket', $query_params);
387
-    }
388
-
389
-
390
-    /**
391
-     * Gets the event this registration is for
392
-     *
393
-     * @return EE_Event
394
-     * @throws EE_Error
395
-     * @throws EntityNotFoundException
396
-     */
397
-    public function event()
398
-    {
399
-        $event = $this->get_first_related('Event');
400
-        if (! $event instanceof \EE_Event) {
401
-            throw new EntityNotFoundException('Event ID', $this->event_ID());
402
-        }
403
-        return $event;
404
-    }
405
-
406
-
407
-    /**
408
-     * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
409
-     * with the author of the event this registration is for.
410
-     *
411
-     * @since 4.5.0
412
-     * @return int
413
-     * @throws EE_Error
414
-     * @throws EntityNotFoundException
415
-     */
416
-    public function wp_user()
417
-    {
418
-        $event = $this->event();
419
-        if ($event instanceof EE_Event) {
420
-            return $event->wp_user();
421
-        }
422
-        return 0;
423
-    }
424
-
425
-
426
-    /**
427
-     * increments this registration's related ticket sold and corresponding datetime sold values
428
-     *
429
-     * @return void
430
-     * @throws DomainException
431
-     * @throws EE_Error
432
-     * @throws EntityNotFoundException
433
-     * @throws InvalidArgumentException
434
-     * @throws InvalidDataTypeException
435
-     * @throws InvalidInterfaceException
436
-     * @throws ReflectionException
437
-     * @throws UnexpectedEntityException
438
-     */
439
-    private function _reserve_registration_space()
440
-    {
441
-        // reserved ticket and datetime counts will be decremented as sold counts are incremented
442
-        // so stop tracking that this reg has a ticket reserved
443
-        $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
444
-        $ticket = $this->ticket();
445
-        $ticket->increase_sold();
446
-        $ticket->save();
447
-        // possibly set event status to sold out
448
-        $this->event()->perform_sold_out_status_check();
449
-    }
450
-
451
-
452
-    /**
453
-     * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
454
-     *
455
-     * @return void
456
-     * @throws DomainException
457
-     * @throws EE_Error
458
-     * @throws EntityNotFoundException
459
-     * @throws InvalidArgumentException
460
-     * @throws InvalidDataTypeException
461
-     * @throws InvalidInterfaceException
462
-     * @throws ReflectionException
463
-     * @throws UnexpectedEntityException
464
-     */
465
-    private function _release_registration_space()
466
-    {
467
-        $ticket = $this->ticket();
468
-        $ticket->decrease_sold();
469
-        $ticket->save();
470
-        // possibly change event status from sold out back to previous status
471
-        $this->event()->perform_sold_out_status_check();
472
-    }
473
-
474
-
475
-    /**
476
-     * tracks this registration's ticket reservation in extra meta
477
-     * and can increment related ticket reserved and corresponding datetime reserved values
478
-     *
479
-     * @param bool $update_ticket if true, will increment ticket and datetime reserved count
480
-     * @return void
481
-     * @throws EE_Error
482
-     * @throws InvalidArgumentException
483
-     * @throws InvalidDataTypeException
484
-     * @throws InvalidInterfaceException
485
-     * @throws ReflectionException
486
-     */
487
-    public function reserve_ticket($update_ticket = false, $source = 'unknown')
488
-    {
489
-        // only reserve ticket if space is not currently reserved
490
-        if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) {
491
-            $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}");
492
-            // IMPORTANT !!!
493
-            // although checking $update_ticket first would be more efficient,
494
-            // we NEED to ALWAYS call update_extra_meta(), which is why that is done first
495
-            if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true)
496
-                && $update_ticket
497
-            ) {
498
-                $ticket = $this->ticket();
499
-                $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
500
-                $ticket->save();
501
-            }
502
-        }
503
-    }
504
-
505
-
506
-    /**
507
-     * stops tracking this registration's ticket reservation in extra meta
508
-     * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
509
-     *
510
-     * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
511
-     * @return void
512
-     * @throws EE_Error
513
-     * @throws InvalidArgumentException
514
-     * @throws InvalidDataTypeException
515
-     * @throws InvalidInterfaceException
516
-     * @throws ReflectionException
517
-     */
518
-    public function release_reserved_ticket($update_ticket = false, $source = 'unknown')
519
-    {
520
-        // only release ticket if space is currently reserved
521
-        if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) {
522
-            $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}");
523
-            // IMPORTANT !!!
524
-            // although checking $update_ticket first would be more efficient,
525
-            // we NEED to ALWAYS call update_extra_meta(), which is why that is done first
526
-            if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false)
527
-                && $update_ticket
528
-            ) {
529
-                $ticket = $this->ticket();
530
-                $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
531
-                $ticket->save();
532
-            }
533
-        }
534
-    }
535
-
536
-
537
-    /**
538
-     * Set Attendee ID
539
-     *
540
-     * @param        int $ATT_ID Attendee ID
541
-     * @throws EE_Error
542
-     * @throws RuntimeException
543
-     */
544
-    public function set_attendee_id($ATT_ID = 0)
545
-    {
546
-        $this->set('ATT_ID', $ATT_ID);
547
-    }
548
-
549
-
550
-    /**
551
-     *        Set Transaction ID
552
-     *
553
-     * @param        int $TXN_ID Transaction ID
554
-     * @throws EE_Error
555
-     * @throws RuntimeException
556
-     */
557
-    public function set_transaction_id($TXN_ID = 0)
558
-    {
559
-        $this->set('TXN_ID', $TXN_ID);
560
-    }
561
-
562
-
563
-    /**
564
-     *        Set Session
565
-     *
566
-     * @param    string $REG_session PHP Session ID
567
-     * @throws EE_Error
568
-     * @throws RuntimeException
569
-     */
570
-    public function set_session($REG_session = '')
571
-    {
572
-        $this->set('REG_session', $REG_session);
573
-    }
574
-
575
-
576
-    /**
577
-     *        Set Registration URL Link
578
-     *
579
-     * @param    string $REG_url_link Registration URL Link
580
-     * @throws EE_Error
581
-     * @throws RuntimeException
582
-     */
583
-    public function set_reg_url_link($REG_url_link = '')
584
-    {
585
-        $this->set('REG_url_link', $REG_url_link);
586
-    }
587
-
588
-
589
-    /**
590
-     *        Set Attendee Counter
591
-     *
592
-     * @param        int $REG_count Primary Attendee
593
-     * @throws EE_Error
594
-     * @throws RuntimeException
595
-     */
596
-    public function set_count($REG_count = 1)
597
-    {
598
-        $this->set('REG_count', $REG_count);
599
-    }
600
-
601
-
602
-    /**
603
-     *        Set Group Size
604
-     *
605
-     * @param        boolean $REG_group_size Group Registration
606
-     * @throws EE_Error
607
-     * @throws RuntimeException
608
-     */
609
-    public function set_group_size($REG_group_size = false)
610
-    {
611
-        $this->set('REG_group_size', $REG_group_size);
612
-    }
613
-
614
-
615
-    /**
616
-     *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
617
-     *    EEM_Registration::status_id_not_approved
618
-     *
619
-     * @return        boolean
620
-     */
621
-    public function is_not_approved()
622
-    {
623
-        return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
624
-    }
625
-
626
-
627
-    /**
628
-     *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
629
-     *    EEM_Registration::status_id_pending_payment
630
-     *
631
-     * @return        boolean
632
-     */
633
-    public function is_pending_payment()
634
-    {
635
-        return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
636
-    }
637
-
638
-
639
-    /**
640
-     *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
641
-     *
642
-     * @return        boolean
643
-     */
644
-    public function is_approved()
645
-    {
646
-        return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
647
-    }
648
-
649
-
650
-    /**
651
-     *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
652
-     *
653
-     * @return        boolean
654
-     */
655
-    public function is_cancelled()
656
-    {
657
-        return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
658
-    }
659
-
660
-
661
-    /**
662
-     *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
663
-     *
664
-     * @return        boolean
665
-     */
666
-    public function is_declined()
667
-    {
668
-        return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
669
-    }
670
-
671
-
672
-    /**
673
-     *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
674
-     *    EEM_Registration::status_id_incomplete
675
-     *
676
-     * @return        boolean
677
-     */
678
-    public function is_incomplete()
679
-    {
680
-        return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
681
-    }
682
-
683
-
684
-    /**
685
-     *        Set Registration Date
686
-     *
687
-     * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
688
-     *                                                 Date
689
-     * @throws EE_Error
690
-     * @throws RuntimeException
691
-     */
692
-    public function set_reg_date($REG_date = false)
693
-    {
694
-        $this->set('REG_date', $REG_date);
695
-    }
696
-
697
-
698
-    /**
699
-     *    Set final price owing for this registration after all ticket/price modifications
700
-     *
701
-     * @access    public
702
-     * @param    float $REG_final_price
703
-     * @throws EE_Error
704
-     * @throws RuntimeException
705
-     */
706
-    public function set_final_price($REG_final_price = 0.00)
707
-    {
708
-        $this->set('REG_final_price', $REG_final_price);
709
-    }
710
-
711
-
712
-    /**
713
-     *    Set amount paid towards this registration's final price
714
-     *
715
-     * @access    public
716
-     * @param    float $REG_paid
717
-     * @throws EE_Error
718
-     * @throws RuntimeException
719
-     */
720
-    public function set_paid($REG_paid = 0.00)
721
-    {
722
-        $this->set('REG_paid', $REG_paid);
723
-    }
724
-
725
-
726
-    /**
727
-     *        Attendee Is Going
728
-     *
729
-     * @param        boolean $REG_att_is_going Attendee Is Going
730
-     * @throws EE_Error
731
-     * @throws RuntimeException
732
-     */
733
-    public function set_att_is_going($REG_att_is_going = false)
734
-    {
735
-        $this->set('REG_att_is_going', $REG_att_is_going);
736
-    }
737
-
738
-
739
-    /**
740
-     * Gets the related attendee
741
-     *
742
-     * @return EE_Attendee
743
-     * @throws EE_Error
744
-     */
745
-    public function attendee()
746
-    {
747
-        return $this->get_first_related('Attendee');
748
-    }
749
-
750
-
751
-    /**
752
-     *        get Event ID
753
-     */
754
-    public function event_ID()
755
-    {
756
-        return $this->get('EVT_ID');
757
-    }
758
-
759
-
760
-    /**
761
-     *        get Event ID
762
-     */
763
-    public function event_name()
764
-    {
765
-        $event = $this->event_obj();
766
-        if ($event) {
767
-            return $event->name();
768
-        } else {
769
-            return null;
770
-        }
771
-    }
772
-
773
-
774
-    /**
775
-     * Fetches the event this registration is for
776
-     *
777
-     * @return EE_Event
778
-     * @throws EE_Error
779
-     */
780
-    public function event_obj()
781
-    {
782
-        return $this->get_first_related('Event');
783
-    }
784
-
785
-
786
-    /**
787
-     *        get Attendee ID
788
-     */
789
-    public function attendee_ID()
790
-    {
791
-        return $this->get('ATT_ID');
792
-    }
793
-
794
-
795
-    /**
796
-     *        get PHP Session ID
797
-     */
798
-    public function session_ID()
799
-    {
800
-        return $this->get('REG_session');
801
-    }
802
-
803
-
804
-    /**
805
-     * Gets the string which represents the URL trigger for the receipt template in the message template system.
806
-     *
807
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
808
-     * @return string
809
-     */
810
-    public function receipt_url($messenger = 'html')
811
-    {
812
-
813
-        /**
814
-         * The below will be deprecated one version after this.  We check first if there is a custom receipt template
815
-         * already in use on old system.  If there is then we just return the standard url for it.
816
-         *
817
-         * @since 4.5.0
818
-         */
819
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
820
-        $has_custom = EEH_Template::locate_template(
821
-            $template_relative_path,
822
-            array(),
823
-            true,
824
-            true,
825
-            true
826
-        );
827
-
828
-        if ($has_custom) {
829
-            return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
830
-        }
831
-        return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
832
-    }
833
-
834
-
835
-    /**
836
-     * Gets the string which represents the URL trigger for the invoice template in the message template system.
837
-     *
838
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
839
-     * @return string
840
-     * @throws EE_Error
841
-     */
842
-    public function invoice_url($messenger = 'html')
843
-    {
844
-        /**
845
-         * The below will be deprecated one version after this.  We check first if there is a custom invoice template
846
-         * already in use on old system.  If there is then we just return the standard url for it.
847
-         *
848
-         * @since 4.5.0
849
-         */
850
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
851
-        $has_custom = EEH_Template::locate_template(
852
-            $template_relative_path,
853
-            array(),
854
-            true,
855
-            true,
856
-            true
857
-        );
858
-
859
-        if ($has_custom) {
860
-            if ($messenger == 'html') {
861
-                return $this->invoice_url('launch');
862
-            }
863
-            $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
864
-
865
-            $query_args = array('ee' => $route, 'id' => $this->reg_url_link());
866
-            if ($messenger == 'html') {
867
-                $query_args['html'] = true;
868
-            }
869
-            return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
870
-        }
871
-        return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
872
-    }
873
-
874
-
875
-    /**
876
-     * get Registration URL Link
877
-     *
878
-     * @access public
879
-     * @return string
880
-     * @throws EE_Error
881
-     */
882
-    public function reg_url_link()
883
-    {
884
-        return (string) $this->get('REG_url_link');
885
-    }
886
-
887
-
888
-    /**
889
-     * Echoes out invoice_url()
890
-     *
891
-     * @param string $type 'download','launch', or 'html' (default is 'launch')
892
-     * @return void
893
-     * @throws EE_Error
894
-     */
895
-    public function e_invoice_url($type = 'launch')
896
-    {
897
-        echo $this->invoice_url($type);
898
-    }
899
-
900
-
901
-    /**
902
-     * Echoes out payment_overview_url
903
-     */
904
-    public function e_payment_overview_url()
905
-    {
906
-        echo $this->payment_overview_url();
907
-    }
908
-
909
-
910
-    /**
911
-     * Gets the URL for the checkout payment options reg step
912
-     * with this registration's REG_url_link added as a query parameter
913
-     *
914
-     * @param bool $clear_session Set to true when you want to clear the session on revisiting the
915
-     *                            payment overview url.
916
-     * @return string
917
-     * @throws InvalidInterfaceException
918
-     * @throws InvalidDataTypeException
919
-     * @throws EE_Error
920
-     * @throws InvalidArgumentException
921
-     */
922
-    public function payment_overview_url($clear_session = false)
923
-    {
924
-        return add_query_arg(
925
-            (array) apply_filters(
926
-                'FHEE__EE_Registration__payment_overview_url__query_args',
927
-                array(
928
-                    'e_reg_url_link' => $this->reg_url_link(),
929
-                    'step'           => 'payment_options',
930
-                    'revisit'        => true,
931
-                    'clear_session'  => (bool) $clear_session,
932
-                ),
933
-                $this
934
-            ),
935
-            EE_Registry::instance()->CFG->core->reg_page_url()
936
-        );
937
-    }
938
-
939
-
940
-    /**
941
-     * Gets the URL for the checkout attendee information reg step
942
-     * with this registration's REG_url_link added as a query parameter
943
-     *
944
-     * @return string
945
-     * @throws InvalidInterfaceException
946
-     * @throws InvalidDataTypeException
947
-     * @throws EE_Error
948
-     * @throws InvalidArgumentException
949
-     */
950
-    public function edit_attendee_information_url()
951
-    {
952
-        return add_query_arg(
953
-            (array) apply_filters(
954
-                'FHEE__EE_Registration__edit_attendee_information_url__query_args',
955
-                array(
956
-                    'e_reg_url_link' => $this->reg_url_link(),
957
-                    'step'           => 'attendee_information',
958
-                    'revisit'        => true,
959
-                ),
960
-                $this
961
-            ),
962
-            EE_Registry::instance()->CFG->core->reg_page_url()
963
-        );
964
-    }
965
-
966
-
967
-    /**
968
-     * Simply generates and returns the appropriate admin_url link to edit this registration
969
-     *
970
-     * @return string
971
-     * @throws EE_Error
972
-     */
973
-    public function get_admin_edit_url()
974
-    {
975
-        return EEH_URL::add_query_args_and_nonce(
976
-            array(
977
-                'page'    => 'espresso_registrations',
978
-                'action'  => 'view_registration',
979
-                '_REG_ID' => $this->ID(),
980
-            ),
981
-            admin_url('admin.php')
982
-        );
983
-    }
984
-
985
-
986
-    /**
987
-     *    is_primary_registrant?
988
-     */
989
-    public function is_primary_registrant()
990
-    {
991
-        return $this->get('REG_count') === 1 ? true : false;
992
-    }
993
-
994
-
995
-    /**
996
-     * This returns the primary registration object for this registration group (which may be this object).
997
-     *
998
-     * @return EE_Registration
999
-     * @throws EE_Error
1000
-     */
1001
-    public function get_primary_registration()
1002
-    {
1003
-        if ($this->is_primary_registrant()) {
1004
-            return $this;
1005
-        }
1006
-
1007
-        // k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
1008
-        /** @var EE_Registration $primary_registrant */
1009
-        $primary_registrant = EEM_Registration::instance()->get_one(
1010
-            array(
1011
-                array(
1012
-                    'TXN_ID'    => $this->transaction_ID(),
1013
-                    'REG_count' => 1,
1014
-                ),
1015
-            )
1016
-        );
1017
-        return $primary_registrant;
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     *        get  Attendee Number
1023
-     *
1024
-     * @access        public
1025
-     */
1026
-    public function count()
1027
-    {
1028
-        return $this->get('REG_count');
1029
-    }
1030
-
1031
-
1032
-    /**
1033
-     *        get Group Size
1034
-     */
1035
-    public function group_size()
1036
-    {
1037
-        return $this->get('REG_group_size');
1038
-    }
1039
-
1040
-
1041
-    /**
1042
-     *        get Registration Date
1043
-     */
1044
-    public function date()
1045
-    {
1046
-        return $this->get('REG_date');
1047
-    }
1048
-
1049
-
1050
-    /**
1051
-     * gets a pretty date
1052
-     *
1053
-     * @param string $date_format
1054
-     * @param string $time_format
1055
-     * @return string
1056
-     * @throws EE_Error
1057
-     */
1058
-    public function pretty_date($date_format = null, $time_format = null)
1059
-    {
1060
-        return $this->get_datetime('REG_date', $date_format, $time_format);
1061
-    }
1062
-
1063
-
1064
-    /**
1065
-     * final_price
1066
-     * the registration's share of the transaction total, so that the
1067
-     * sum of all the transaction's REG_final_prices equal the transaction's total
1068
-     *
1069
-     * @return float
1070
-     * @throws EE_Error
1071
-     */
1072
-    public function final_price()
1073
-    {
1074
-        return $this->get('REG_final_price');
1075
-    }
1076
-
1077
-
1078
-    /**
1079
-     * pretty_final_price
1080
-     *  final price as formatted string, with correct decimal places and currency symbol
1081
-     *
1082
-     * @return string
1083
-     * @throws EE_Error
1084
-     */
1085
-    public function pretty_final_price()
1086
-    {
1087
-        return $this->get_pretty('REG_final_price');
1088
-    }
1089
-
1090
-
1091
-    /**
1092
-     * get paid (yeah)
1093
-     *
1094
-     * @return float
1095
-     * @throws EE_Error
1096
-     */
1097
-    public function paid()
1098
-    {
1099
-        return $this->get('REG_paid');
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * pretty_paid
1105
-     *
1106
-     * @return float
1107
-     * @throws EE_Error
1108
-     */
1109
-    public function pretty_paid()
1110
-    {
1111
-        return $this->get_pretty('REG_paid');
1112
-    }
1113
-
1114
-
1115
-    /**
1116
-     * owes_monies_and_can_pay
1117
-     * whether or not this registration has monies owing and it's' status allows payment
1118
-     *
1119
-     * @param array $requires_payment
1120
-     * @return bool
1121
-     * @throws EE_Error
1122
-     */
1123
-    public function owes_monies_and_can_pay($requires_payment = array())
1124
-    {
1125
-        // these reg statuses require payment (if event is not free)
1126
-        $requires_payment = ! empty($requires_payment)
1127
-            ? $requires_payment
1128
-            : EEM_Registration::reg_statuses_that_allow_payment();
1129
-        if (in_array($this->status_ID(), $requires_payment) &&
1130
-            $this->final_price() != 0 &&
1131
-            $this->final_price() != $this->paid()
1132
-        ) {
1133
-            return true;
1134
-        } else {
1135
-            return false;
1136
-        }
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * Prints out the return value of $this->pretty_status()
1142
-     *
1143
-     * @param bool $show_icons
1144
-     * @return void
1145
-     * @throws EE_Error
1146
-     */
1147
-    public function e_pretty_status($show_icons = false)
1148
-    {
1149
-        echo $this->pretty_status($show_icons);
1150
-    }
1151
-
1152
-
1153
-    /**
1154
-     * Returns a nice version of the status for displaying to customers
1155
-     *
1156
-     * @param bool $show_icons
1157
-     * @return string
1158
-     * @throws EE_Error
1159
-     */
1160
-    public function pretty_status($show_icons = false)
1161
-    {
1162
-        $status = EEM_Status::instance()->localized_status(
1163
-            array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
1164
-            false,
1165
-            'sentence'
1166
-        );
1167
-        $icon = '';
1168
-        switch ($this->status_ID()) {
1169
-            case EEM_Registration::status_id_approved:
1170
-                $icon = $show_icons
1171
-                    ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>'
1172
-                    : '';
1173
-                break;
1174
-            case EEM_Registration::status_id_pending_payment:
1175
-                $icon = $show_icons
1176
-                    ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>'
1177
-                    : '';
1178
-                break;
1179
-            case EEM_Registration::status_id_not_approved:
1180
-                $icon = $show_icons
1181
-                    ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>'
1182
-                    : '';
1183
-                break;
1184
-            case EEM_Registration::status_id_cancelled:
1185
-                $icon = $show_icons
1186
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
1187
-                    : '';
1188
-                break;
1189
-            case EEM_Registration::status_id_incomplete:
1190
-                $icon = $show_icons
1191
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>'
1192
-                    : '';
1193
-                break;
1194
-            case EEM_Registration::status_id_declined:
1195
-                $icon = $show_icons
1196
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
1197
-                    : '';
1198
-                break;
1199
-            case EEM_Registration::status_id_wait_list:
1200
-                $icon = $show_icons
1201
-                    ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>'
1202
-                    : '';
1203
-                break;
1204
-        }
1205
-        return $icon . $status[ $this->status_ID() ];
1206
-    }
1207
-
1208
-
1209
-    /**
1210
-     *        get Attendee Is Going
1211
-     */
1212
-    public function att_is_going()
1213
-    {
1214
-        return $this->get('REG_att_is_going');
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * Gets related answers
1220
-     *
1221
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1222
-     * @return EE_Answer[]
1223
-     * @throws EE_Error
1224
-     */
1225
-    public function answers($query_params = null)
1226
-    {
1227
-        return $this->get_many_related('Answer', $query_params);
1228
-    }
1229
-
1230
-
1231
-    /**
1232
-     * Gets the registration's answer value to the specified question
1233
-     * (either the question's ID or a question object)
1234
-     *
1235
-     * @param EE_Question|int $question
1236
-     * @param bool            $pretty_value
1237
-     * @return array|string if pretty_value= true, the result will always be a string
1238
-     * (because the answer might be an array of answer values, so passing pretty_value=true
1239
-     * will convert it into some kind of string)
1240
-     * @throws EE_Error
1241
-     */
1242
-    public function answer_value_to_question($question, $pretty_value = true)
1243
-    {
1244
-        $question_id = EEM_Question::instance()->ensure_is_ID($question);
1245
-        return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
1246
-    }
1247
-
1248
-
1249
-    /**
1250
-     * question_groups
1251
-     * returns an array of EE_Question_Group objects for this registration
1252
-     *
1253
-     * @return EE_Question_Group[]
1254
-     * @throws EE_Error
1255
-     * @throws InvalidArgumentException
1256
-     * @throws InvalidDataTypeException
1257
-     * @throws InvalidInterfaceException
1258
-     * @throws ReflectionException
1259
-     */
1260
-    public function question_groups()
1261
-    {
1262
-        return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this);
1263
-    }
1264
-
1265
-
1266
-    /**
1267
-     * count_question_groups
1268
-     * returns a count of the number of EE_Question_Group objects for this registration
1269
-     *
1270
-     * @return int
1271
-     * @throws EE_Error
1272
-     * @throws EntityNotFoundException
1273
-     * @throws InvalidArgumentException
1274
-     * @throws InvalidDataTypeException
1275
-     * @throws InvalidInterfaceException
1276
-     * @throws ReflectionException
1277
-     */
1278
-    public function count_question_groups()
1279
-    {
1280
-        return EEM_Event::instance()->count_related(
1281
-            $this->event_ID(),
1282
-            'Question_Group',
1283
-            [
1284
-                [
1285
-                    'Event_Question_Group.'
1286
-                    . EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true,
1287
-                ]
1288
-            ]
1289
-        );
1290
-    }
1291
-
1292
-
1293
-    /**
1294
-     * Returns the registration date in the 'standard' string format
1295
-     * (function may be improved in the future to allow for different formats and timezones)
1296
-     *
1297
-     * @return string
1298
-     * @throws EE_Error
1299
-     */
1300
-    public function reg_date()
1301
-    {
1302
-        return $this->get_datetime('REG_date');
1303
-    }
1304
-
1305
-
1306
-    /**
1307
-     * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1308
-     * the ticket this registration purchased, or the datetime they have registered
1309
-     * to attend)
1310
-     *
1311
-     * @return EE_Datetime_Ticket
1312
-     * @throws EE_Error
1313
-     */
1314
-    public function datetime_ticket()
1315
-    {
1316
-        return $this->get_first_related('Datetime_Ticket');
1317
-    }
1318
-
1319
-
1320
-    /**
1321
-     * Sets the registration's datetime_ticket.
1322
-     *
1323
-     * @param EE_Datetime_Ticket $datetime_ticket
1324
-     * @return EE_Datetime_Ticket
1325
-     * @throws EE_Error
1326
-     */
1327
-    public function set_datetime_ticket($datetime_ticket)
1328
-    {
1329
-        return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1330
-    }
1331
-
1332
-    /**
1333
-     * Gets deleted
1334
-     *
1335
-     * @return bool
1336
-     * @throws EE_Error
1337
-     */
1338
-    public function deleted()
1339
-    {
1340
-        return $this->get('REG_deleted');
1341
-    }
1342
-
1343
-    /**
1344
-     * Sets deleted
1345
-     *
1346
-     * @param boolean $deleted
1347
-     * @return bool
1348
-     * @throws EE_Error
1349
-     * @throws RuntimeException
1350
-     */
1351
-    public function set_deleted($deleted)
1352
-    {
1353
-        if ($deleted) {
1354
-            $this->delete();
1355
-        } else {
1356
-            $this->restore();
1357
-        }
1358
-    }
1359
-
1360
-
1361
-    /**
1362
-     * Get the status object of this object
1363
-     *
1364
-     * @return EE_Status
1365
-     * @throws EE_Error
1366
-     */
1367
-    public function status_obj()
1368
-    {
1369
-        return $this->get_first_related('Status');
1370
-    }
1371
-
1372
-
1373
-    /**
1374
-     * Returns the number of times this registration has checked into any of the datetimes
1375
-     * its available for
1376
-     *
1377
-     * @return int
1378
-     * @throws EE_Error
1379
-     */
1380
-    public function count_checkins()
1381
-    {
1382
-        return $this->get_model()->count_related($this, 'Checkin');
1383
-    }
1384
-
1385
-
1386
-    /**
1387
-     * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1388
-     * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1389
-     *
1390
-     * @return int
1391
-     * @throws EE_Error
1392
-     */
1393
-    public function count_checkins_not_checkedout()
1394
-    {
1395
-        return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1396
-    }
1397
-
1398
-
1399
-    /**
1400
-     * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1401
-     *
1402
-     * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1403
-     * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1404
-     *                                          consider registration status as well as datetime access.
1405
-     * @return bool
1406
-     * @throws EE_Error
1407
-     */
1408
-    public function can_checkin($DTT_OR_ID, $check_approved = true)
1409
-    {
1410
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1411
-
1412
-        // first check registration status
1413
-        if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1414
-            return false;
1415
-        }
1416
-        // is there a datetime ticket that matches this dtt_ID?
1417
-        if (! (EEM_Datetime_Ticket::instance()->exists(
1418
-            array(
1419
-                array(
1420
-                    'TKT_ID' => $this->get('TKT_ID'),
1421
-                    'DTT_ID' => $DTT_ID,
1422
-                ),
1423
-            )
1424
-        ))
1425
-        ) {
1426
-            return false;
1427
-        }
1428
-
1429
-        // final check is against TKT_uses
1430
-        return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1431
-    }
1432
-
1433
-
1434
-    /**
1435
-     * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1436
-     * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1437
-     * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1438
-     * then return false.  Otherwise return true.
1439
-     *
1440
-     * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1441
-     * @return bool true means can checkin.  false means cannot checkin.
1442
-     * @throws EE_Error
1443
-     */
1444
-    public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1445
-    {
1446
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1447
-
1448
-        if (! $DTT_ID) {
1449
-            return false;
1450
-        }
1451
-
1452
-        $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1453
-
1454
-        // if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1455
-        // check-in or not.
1456
-        if (! $max_uses || $max_uses === EE_INF) {
1457
-            return true;
1458
-        }
1459
-
1460
-        // does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1461
-        // go ahead and toggle.
1462
-        if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1463
-            return true;
1464
-        }
1465
-
1466
-        // made it here so the last check is whether the number of checkins per unique datetime on this registration
1467
-        // disallows further check-ins.
1468
-        $count_unique_dtt_checkins = EEM_Checkin::instance()->count(
1469
-            array(
1470
-                array(
1471
-                    'REG_ID' => $this->ID(),
1472
-                    'CHK_in' => true,
1473
-                ),
1474
-            ),
1475
-            'DTT_ID',
1476
-            true
1477
-        );
1478
-        // checkins have already reached their max number of uses
1479
-        // so registrant can NOT checkin
1480
-        if ($count_unique_dtt_checkins >= $max_uses) {
1481
-            EE_Error::add_error(
1482
-                esc_html__(
1483
-                    'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1484
-                    'event_espresso'
1485
-                ),
1486
-                __FILE__,
1487
-                __FUNCTION__,
1488
-                __LINE__
1489
-            );
1490
-            return false;
1491
-        }
1492
-        return true;
1493
-    }
1494
-
1495
-
1496
-    /**
1497
-     * toggle Check-in status for this registration
1498
-     * Check-ins are toggled in the following order:
1499
-     * never checked in -> checked in
1500
-     * checked in -> checked out
1501
-     * checked out -> checked in
1502
-     *
1503
-     * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1504
-     *                      If not included or null, then it is assumed latest datetime is being toggled.
1505
-     * @param bool $verify  If true then can_checkin() is used to verify whether the person
1506
-     *                      can be checked in or not.  Otherwise this forces change in checkin status.
1507
-     * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1508
-     * @throws EE_Error
1509
-     */
1510
-    public function toggle_checkin_status($DTT_ID = null, $verify = false)
1511
-    {
1512
-        if (empty($DTT_ID)) {
1513
-            $datetime = $this->get_latest_related_datetime();
1514
-            $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1515
-            // verify the registration can checkin for the given DTT_ID
1516
-        } elseif (! $this->can_checkin($DTT_ID, $verify)) {
1517
-            EE_Error::add_error(
1518
-                sprintf(
1519
-                    esc_html__(
1520
-                        'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1521
-                        'event_espresso'
1522
-                    ),
1523
-                    $this->ID(),
1524
-                    $DTT_ID
1525
-                ),
1526
-                __FILE__,
1527
-                __FUNCTION__,
1528
-                __LINE__
1529
-            );
1530
-            return false;
1531
-        }
1532
-        $status_paths = array(
1533
-            EE_Checkin::status_checked_never => EE_Checkin::status_checked_in,
1534
-            EE_Checkin::status_checked_in    => EE_Checkin::status_checked_out,
1535
-            EE_Checkin::status_checked_out   => EE_Checkin::status_checked_in,
1536
-        );
1537
-        // start by getting the current status so we know what status we'll be changing to.
1538
-        $cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1539
-        $status_to = $status_paths[ $cur_status ];
1540
-        // database only records true for checked IN or false for checked OUT
1541
-        // no record ( null ) means checked in NEVER, but we obviously don't save that
1542
-        $new_status = $status_to === EE_Checkin::status_checked_in ? true : false;
1543
-        // add relation - note Check-ins are always creating new rows
1544
-        // because we are keeping track of Check-ins over time.
1545
-        // Eventually we'll probably want to show a list table
1546
-        // for the individual Check-ins so that they can be managed.
1547
-        $checkin = EE_Checkin::new_instance(
1548
-            array(
1549
-                'REG_ID' => $this->ID(),
1550
-                'DTT_ID' => $DTT_ID,
1551
-                'CHK_in' => $new_status,
1552
-            )
1553
-        );
1554
-        // if the record could not be saved then return false
1555
-        if ($checkin->save() === 0) {
1556
-            if (WP_DEBUG) {
1557
-                global $wpdb;
1558
-                $error = sprintf(
1559
-                    esc_html__(
1560
-                        'Registration check in update failed because of the following database error: %1$s%2$s',
1561
-                        'event_espresso'
1562
-                    ),
1563
-                    '<br />',
1564
-                    $wpdb->last_error
1565
-                );
1566
-            } else {
1567
-                $error = esc_html__(
1568
-                    'Registration check in update failed because of an unknown database error',
1569
-                    'event_espresso'
1570
-                );
1571
-            }
1572
-            EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1573
-            return false;
1574
-        }
1575
-        return $status_to;
1576
-    }
1577
-
1578
-
1579
-    /**
1580
-     * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1581
-     * "Latest" is defined by the `DTT_EVT_start` column.
1582
-     *
1583
-     * @return EE_Datetime|null
1584
-     * @throws EE_Error
1585
-     */
1586
-    public function get_latest_related_datetime()
1587
-    {
1588
-        return EEM_Datetime::instance()->get_one(
1589
-            array(
1590
-                array(
1591
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1592
-                ),
1593
-                'order_by' => array('DTT_EVT_start' => 'DESC'),
1594
-            )
1595
-        );
1596
-    }
1597
-
1598
-
1599
-    /**
1600
-     * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1601
-     * "Earliest" is defined by the `DTT_EVT_start` column.
1602
-     *
1603
-     * @throws EE_Error
1604
-     */
1605
-    public function get_earliest_related_datetime()
1606
-    {
1607
-        return EEM_Datetime::instance()->get_one(
1608
-            array(
1609
-                array(
1610
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1611
-                ),
1612
-                'order_by' => array('DTT_EVT_start' => 'ASC'),
1613
-            )
1614
-        );
1615
-    }
1616
-
1617
-
1618
-    /**
1619
-     * This method simply returns the check-in status for this registration and the given datetime.
1620
-     * If neither the datetime nor the checkin values are provided as arguments,
1621
-     * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1622
-     *
1623
-     * @param  int       $DTT_ID  The ID of the datetime we're checking against
1624
-     *                            (if empty we'll get the primary datetime for
1625
-     *                            this registration (via event) and use it's ID);
1626
-     * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1627
-     *
1628
-     * @return int                Integer representing Check-in status.
1629
-     * @throws EE_Error
1630
-     */
1631
-    public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1632
-    {
1633
-        $checkin_query_params = array(
1634
-            'order_by' => array('CHK_timestamp' => 'DESC'),
1635
-        );
1636
-
1637
-        if ($DTT_ID > 0) {
1638
-            $checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1639
-        }
1640
-
1641
-        // get checkin object (if exists)
1642
-        $checkin = $checkin instanceof EE_Checkin
1643
-            ? $checkin
1644
-            : $this->get_first_related('Checkin', $checkin_query_params);
1645
-        if ($checkin instanceof EE_Checkin) {
1646
-            if ($checkin->get('CHK_in')) {
1647
-                return EE_Checkin::status_checked_in; // checked in
1648
-            }
1649
-            return EE_Checkin::status_checked_out; // had checked in but is now checked out.
1650
-        }
1651
-        return EE_Checkin::status_checked_never; // never been checked in
1652
-    }
1653
-
1654
-
1655
-    /**
1656
-     * This method returns a localized message for the toggled Check-in message.
1657
-     *
1658
-     * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1659
-     *                     then it is assumed Check-in for primary datetime was toggled.
1660
-     * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1661
-     *                     message can be customized with the attendee name.
1662
-     * @return string internationalized message
1663
-     * @throws EE_Error
1664
-     */
1665
-    public function get_checkin_msg($DTT_ID, $error = false)
1666
-    {
1667
-        // let's get the attendee first so we can include the name of the attendee
1668
-        $attendee = $this->get_first_related('Attendee');
1669
-        if ($attendee instanceof EE_Attendee) {
1670
-            if ($error) {
1671
-                return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1672
-            }
1673
-            $cur_status = $this->check_in_status_for_datetime($DTT_ID);
1674
-            // what is the status message going to be?
1675
-            switch ($cur_status) {
1676
-                case EE_Checkin::status_checked_never:
1677
-                    return sprintf(
1678
-                        __("%s has been removed from Check-in records", "event_espresso"),
1679
-                        $attendee->full_name()
1680
-                    );
1681
-                    break;
1682
-                case EE_Checkin::status_checked_in:
1683
-                    return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1684
-                    break;
1685
-                case EE_Checkin::status_checked_out:
1686
-                    return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1687
-                    break;
1688
-            }
1689
-        }
1690
-        return esc_html__("The check-in status could not be determined.", "event_espresso");
1691
-    }
1692
-
1693
-
1694
-    /**
1695
-     * Returns the related EE_Transaction to this registration
1696
-     *
1697
-     * @return EE_Transaction
1698
-     * @throws EE_Error
1699
-     * @throws EntityNotFoundException
1700
-     */
1701
-    public function transaction()
1702
-    {
1703
-        $transaction = $this->get_first_related('Transaction');
1704
-        if (! $transaction instanceof \EE_Transaction) {
1705
-            throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1706
-        }
1707
-        return $transaction;
1708
-    }
1709
-
1710
-
1711
-    /**
1712
-     *        get Registration Code
1713
-     */
1714
-    public function reg_code()
1715
-    {
1716
-        return $this->get('REG_code');
1717
-    }
1718
-
1719
-
1720
-    /**
1721
-     *        get Transaction ID
1722
-     */
1723
-    public function transaction_ID()
1724
-    {
1725
-        return $this->get('TXN_ID');
1726
-    }
1727
-
1728
-
1729
-    /**
1730
-     * @return int
1731
-     * @throws EE_Error
1732
-     */
1733
-    public function ticket_ID()
1734
-    {
1735
-        return $this->get('TKT_ID');
1736
-    }
1737
-
1738
-
1739
-    /**
1740
-     *        Set Registration Code
1741
-     *
1742
-     * @access    public
1743
-     * @param    string  $REG_code Registration Code
1744
-     * @param    boolean $use_default
1745
-     * @throws EE_Error
1746
-     */
1747
-    public function set_reg_code($REG_code, $use_default = false)
1748
-    {
1749
-        if (empty($REG_code)) {
1750
-            EE_Error::add_error(
1751
-                esc_html__('REG_code can not be empty.', 'event_espresso'),
1752
-                __FILE__,
1753
-                __FUNCTION__,
1754
-                __LINE__
1755
-            );
1756
-            return;
1757
-        }
1758
-        if (! $this->reg_code()) {
1759
-            parent::set('REG_code', $REG_code, $use_default);
1760
-        } else {
1761
-            EE_Error::doing_it_wrong(
1762
-                __CLASS__ . '::' . __FUNCTION__,
1763
-                esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1764
-                '4.6.0'
1765
-            );
1766
-        }
1767
-    }
1768
-
1769
-
1770
-    /**
1771
-     * Returns all other registrations in the same group as this registrant who have the same ticket option.
1772
-     * Note, if you want to just get all registrations in the same transaction (group), use:
1773
-     *    $registration->transaction()->registrations();
1774
-     *
1775
-     * @since 4.5.0
1776
-     * @return EE_Registration[] or empty array if this isn't a group registration.
1777
-     * @throws EE_Error
1778
-     */
1779
-    public function get_all_other_registrations_in_group()
1780
-    {
1781
-        if ($this->group_size() < 2) {
1782
-            return array();
1783
-        }
1784
-
1785
-        $query[0] = array(
1786
-            'TXN_ID' => $this->transaction_ID(),
1787
-            'REG_ID' => array('!=', $this->ID()),
1788
-            'TKT_ID' => $this->ticket_ID(),
1789
-        );
1790
-        /** @var EE_Registration[] $registrations */
1791
-        $registrations = $this->get_model()->get_all($query);
1792
-        return $registrations;
1793
-    }
1794
-
1795
-    /**
1796
-     * Return the link to the admin details for the object.
1797
-     *
1798
-     * @return string
1799
-     * @throws EE_Error
1800
-     */
1801
-    public function get_admin_details_link()
1802
-    {
1803
-        EE_Registry::instance()->load_helper('URL');
1804
-        return EEH_URL::add_query_args_and_nonce(
1805
-            array(
1806
-                'page'    => 'espresso_registrations',
1807
-                'action'  => 'view_registration',
1808
-                '_REG_ID' => $this->ID(),
1809
-            ),
1810
-            admin_url('admin.php')
1811
-        );
1812
-    }
1813
-
1814
-    /**
1815
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1816
-     *
1817
-     * @return string
1818
-     * @throws EE_Error
1819
-     */
1820
-    public function get_admin_edit_link()
1821
-    {
1822
-        return $this->get_admin_details_link();
1823
-    }
1824
-
1825
-    /**
1826
-     * Returns the link to a settings page for the object.
1827
-     *
1828
-     * @return string
1829
-     * @throws EE_Error
1830
-     */
1831
-    public function get_admin_settings_link()
1832
-    {
1833
-        return $this->get_admin_details_link();
1834
-    }
1835
-
1836
-    /**
1837
-     * Returns the link to the "overview" for the object (typically the "list table" view).
1838
-     *
1839
-     * @return string
1840
-     */
1841
-    public function get_admin_overview_link()
1842
-    {
1843
-        EE_Registry::instance()->load_helper('URL');
1844
-        return EEH_URL::add_query_args_and_nonce(
1845
-            array(
1846
-                'page' => 'espresso_registrations',
1847
-            ),
1848
-            admin_url('admin.php')
1849
-        );
1850
-    }
1851
-
1852
-
1853
-    /**
1854
-     * @param array $query_params
1855
-     *
1856
-     * @return \EE_Registration[]
1857
-     * @throws EE_Error
1858
-     */
1859
-    public function payments($query_params = array())
1860
-    {
1861
-        return $this->get_many_related('Payment', $query_params);
1862
-    }
1863
-
1864
-
1865
-    /**
1866
-     * @param array $query_params
1867
-     *
1868
-     * @return \EE_Registration_Payment[]
1869
-     * @throws EE_Error
1870
-     */
1871
-    public function registration_payments($query_params = array())
1872
-    {
1873
-        return $this->get_many_related('Registration_Payment', $query_params);
1874
-    }
1875
-
1876
-
1877
-    /**
1878
-     * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1879
-     * Note: if there are no payments on the registration there will be no payment method returned.
1880
-     *
1881
-     * @return EE_Payment_Method|null
1882
-     */
1883
-    public function payment_method()
1884
-    {
1885
-        return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1886
-    }
1887
-
1888
-
1889
-    /**
1890
-     * @return \EE_Line_Item
1891
-     * @throws EntityNotFoundException
1892
-     * @throws EE_Error
1893
-     */
1894
-    public function ticket_line_item()
1895
-    {
1896
-        $ticket = $this->ticket();
1897
-        $transaction = $this->transaction();
1898
-        $line_item = null;
1899
-        $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1900
-            $transaction->total_line_item(),
1901
-            'Ticket',
1902
-            array($ticket->ID())
1903
-        );
1904
-        foreach ($ticket_line_items as $ticket_line_item) {
1905
-            if ($ticket_line_item instanceof \EE_Line_Item
1906
-                && $ticket_line_item->OBJ_type() === 'Ticket'
1907
-                && $ticket_line_item->OBJ_ID() === $ticket->ID()
1908
-            ) {
1909
-                $line_item = $ticket_line_item;
1910
-                break;
1911
-            }
1912
-        }
1913
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1914
-            throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1915
-        }
1916
-        return $line_item;
1917
-    }
1918
-
1919
-
1920
-    /**
1921
-     * Soft Deletes this model object.
1922
-     *
1923
-     * @return boolean | int
1924
-     * @throws RuntimeException
1925
-     * @throws EE_Error
1926
-     */
1927
-    public function delete()
1928
-    {
1929
-        if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1930
-            $this->set_status(EEM_Registration::status_id_cancelled);
1931
-        }
1932
-        return parent::delete();
1933
-    }
1934
-
1935
-
1936
-    /**
1937
-     * Restores whatever the previous status was on a registration before it was trashed (if possible)
1938
-     *
1939
-     * @throws EE_Error
1940
-     * @throws RuntimeException
1941
-     */
1942
-    public function restore()
1943
-    {
1944
-        $previous_status = $this->get_extra_meta(
1945
-            EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1946
-            true,
1947
-            EEM_Registration::status_id_cancelled
1948
-        );
1949
-        if ($previous_status) {
1950
-            $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1951
-            $this->set_status($previous_status);
1952
-        }
1953
-        return parent::restore();
1954
-    }
1955
-
1956
-
1957
-    /**
1958
-     * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price
1959
-     *
1960
-     * @param  boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic
1961
-     *                                           depending on whether the reg status changes to or from "Approved"
1962
-     * @return boolean whether the Registration status was updated
1963
-     * @throws EE_Error
1964
-     * @throws RuntimeException
1965
-     */
1966
-    public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true)
1967
-    {
1968
-        $paid = $this->paid();
1969
-        $price = $this->final_price();
1970
-        switch (true) {
1971
-            // overpaid or paid
1972
-            case EEH_Money::compare_floats($paid, $price, '>'):
1973
-            case EEH_Money::compare_floats($paid, $price):
1974
-                $new_status = EEM_Registration::status_id_approved;
1975
-                break;
1976
-            //  underpaid
1977
-            case EEH_Money::compare_floats($paid, $price, '<'):
1978
-                $new_status = EEM_Registration::status_id_pending_payment;
1979
-                break;
1980
-            // uhhh Houston...
1981
-            default:
1982
-                throw new RuntimeException(
1983
-                    esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso')
1984
-                );
1985
-        }
1986
-        if ($new_status !== $this->status_ID()) {
1987
-            if ($trigger_set_status_logic) {
1988
-                return $this->set_status($new_status);
1989
-            }
1990
-            parent::set('STS_ID', $new_status);
1991
-            return true;
1992
-        }
1993
-        return false;
1994
-    }
1995
-
1996
-
1997
-    /*************************** DEPRECATED ***************************/
1998
-
1999
-
2000
-    /**
2001
-     * @deprecated
2002
-     * @since     4.7.0
2003
-     * @access    public
2004
-     */
2005
-    public function price_paid()
2006
-    {
2007
-        EE_Error::doing_it_wrong(
2008
-            'EE_Registration::price_paid()',
2009
-            esc_html__(
2010
-                'This method is deprecated, please use EE_Registration::final_price() instead.',
2011
-                'event_espresso'
2012
-            ),
2013
-            '4.7.0'
2014
-        );
2015
-        return $this->final_price();
2016
-    }
2017
-
2018
-
2019
-    /**
2020
-     * @deprecated
2021
-     * @since     4.7.0
2022
-     * @access    public
2023
-     * @param    float $REG_final_price
2024
-     * @throws EE_Error
2025
-     * @throws RuntimeException
2026
-     */
2027
-    public function set_price_paid($REG_final_price = 0.00)
2028
-    {
2029
-        EE_Error::doing_it_wrong(
2030
-            'EE_Registration::set_price_paid()',
2031
-            esc_html__(
2032
-                'This method is deprecated, please use EE_Registration::set_final_price() instead.',
2033
-                'event_espresso'
2034
-            ),
2035
-            '4.7.0'
2036
-        );
2037
-        $this->set_final_price($REG_final_price);
2038
-    }
2039
-
2040
-
2041
-    /**
2042
-     * @deprecated
2043
-     * @since 4.7.0
2044
-     * @return string
2045
-     * @throws EE_Error
2046
-     */
2047
-    public function pretty_price_paid()
2048
-    {
2049
-        EE_Error::doing_it_wrong(
2050
-            'EE_Registration::pretty_price_paid()',
2051
-            esc_html__(
2052
-                'This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
2053
-                'event_espresso'
2054
-            ),
2055
-            '4.7.0'
2056
-        );
2057
-        return $this->pretty_final_price();
2058
-    }
2059
-
2060
-
2061
-    /**
2062
-     * Gets the primary datetime related to this registration via the related Event to this registration
2063
-     *
2064
-     * @deprecated 4.9.17
2065
-     * @return EE_Datetime
2066
-     * @throws EE_Error
2067
-     * @throws EntityNotFoundException
2068
-     */
2069
-    public function get_related_primary_datetime()
2070
-    {
2071
-        EE_Error::doing_it_wrong(
2072
-            __METHOD__,
2073
-            esc_html__(
2074
-                'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
2075
-                'event_espresso'
2076
-            ),
2077
-            '4.9.17',
2078
-            '5.0.0'
2079
-        );
2080
-        return $this->event()->primary_datetime();
2081
-    }
20
+	/**
21
+	 * Used to reference when a registration has never been checked in.
22
+	 *
23
+	 * @deprecated use \EE_Checkin::status_checked_never instead
24
+	 * @type int
25
+	 */
26
+	const checkin_status_never = 2;
27
+
28
+	/**
29
+	 * Used to reference when a registration has been checked in.
30
+	 *
31
+	 * @deprecated use \EE_Checkin::status_checked_in instead
32
+	 * @type int
33
+	 */
34
+	const checkin_status_in = 1;
35
+
36
+
37
+	/**
38
+	 * Used to reference when a registration has been checked out.
39
+	 *
40
+	 * @deprecated use \EE_Checkin::status_checked_out instead
41
+	 * @type int
42
+	 */
43
+	const checkin_status_out = 0;
44
+
45
+
46
+	/**
47
+	 * extra meta key for tracking reg status os trashed registrations
48
+	 *
49
+	 * @type string
50
+	 */
51
+	const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
52
+
53
+
54
+	/**
55
+	 * extra meta key for tracking if registration has reserved ticket
56
+	 *
57
+	 * @type string
58
+	 */
59
+	const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
60
+
61
+
62
+	/**
63
+	 * @param array  $props_n_values          incoming values
64
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
65
+	 *                                        used.)
66
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
67
+	 *                                        date_format and the second value is the time format
68
+	 * @return EE_Registration
69
+	 * @throws EE_Error
70
+	 */
71
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
72
+	{
73
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
74
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param array  $props_n_values  incoming values from the database
80
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
81
+	 *                                the website will be used.
82
+	 * @return EE_Registration
83
+	 */
84
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
85
+	{
86
+		return new self($props_n_values, true, $timezone);
87
+	}
88
+
89
+
90
+	/**
91
+	 *        Set Event ID
92
+	 *
93
+	 * @param        int $EVT_ID Event ID
94
+	 * @throws EE_Error
95
+	 * @throws RuntimeException
96
+	 */
97
+	public function set_event($EVT_ID = 0)
98
+	{
99
+		$this->set('EVT_ID', $EVT_ID);
100
+	}
101
+
102
+
103
+	/**
104
+	 * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
105
+	 * be routed to internal methods
106
+	 *
107
+	 * @param string $field_name
108
+	 * @param mixed  $field_value
109
+	 * @param bool   $use_default
110
+	 * @throws EE_Error
111
+	 * @throws EntityNotFoundException
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws ReflectionException
116
+	 * @throws RuntimeException
117
+	 */
118
+	public function set($field_name, $field_value, $use_default = false)
119
+	{
120
+		switch ($field_name) {
121
+			case 'REG_code':
122
+				if (! empty($field_value) && $this->reg_code() === null) {
123
+					$this->set_reg_code($field_value, $use_default);
124
+				}
125
+				break;
126
+			case 'STS_ID':
127
+				$this->set_status($field_value, $use_default);
128
+				break;
129
+			default:
130
+				parent::set($field_name, $field_value, $use_default);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 * Set Status ID
137
+	 * updates the registration status and ALSO...
138
+	 * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
139
+	 * calls release_registration_space() if the reg status changes FROM approved to any other reg status
140
+	 *
141
+	 * @param string                $new_STS_ID
142
+	 * @param boolean               $use_default
143
+	 * @param ContextInterface|null $context
144
+	 * @return bool
145
+	 * @throws EE_Error
146
+	 * @throws EntityNotFoundException
147
+	 * @throws InvalidArgumentException
148
+	 * @throws ReflectionException
149
+	 * @throws RuntimeException
150
+	 * @throws InvalidDataTypeException
151
+	 * @throws InvalidInterfaceException
152
+	 */
153
+	public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null)
154
+	{
155
+		// get current REG_Status
156
+		$old_STS_ID = $this->status_ID();
157
+		// if status has changed
158
+		if ($old_STS_ID !== $new_STS_ID // and that status has actually changed
159
+			&& ! empty($old_STS_ID) // and that old status is actually set
160
+			&& ! empty($new_STS_ID) // as well as the new status
161
+			&& $this->ID() // ensure registration is in the db
162
+		) {
163
+			// update internal status first
164
+			parent::set('STS_ID', $new_STS_ID, $use_default);
165
+			// THEN handle other changes that occur when reg status changes
166
+			// TO approved
167
+			if ($new_STS_ID === EEM_Registration::status_id_approved) {
168
+				// reserve a space by incrementing ticket and datetime sold values
169
+				$this->_reserve_registration_space();
170
+				do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context);
171
+				// OR FROM  approved
172
+			} elseif ($old_STS_ID === EEM_Registration::status_id_approved) {
173
+				// release a space by decrementing ticket and datetime sold values
174
+				$this->_release_registration_space();
175
+				do_action(
176
+					'AHEE__EE_Registration__set_status__from_approved',
177
+					$this,
178
+					$old_STS_ID,
179
+					$new_STS_ID,
180
+					$context
181
+				);
182
+			}
183
+			$this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context);
184
+			if ($this->statusChangeUpdatesTransaction($context)) {
185
+				$this->updateTransactionAfterStatusChange();
186
+			}
187
+			do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context);
188
+			return true;
189
+		}
190
+		// even though the old value matches the new value, it's still good to
191
+		// allow the parent set method to have a say
192
+		parent::set('STS_ID', $new_STS_ID, $use_default);
193
+		return true;
194
+	}
195
+
196
+
197
+	/**
198
+	 * update REGs and TXN when cancelled or declined registrations involved
199
+	 *
200
+	 * @param string                $new_STS_ID
201
+	 * @param string                $old_STS_ID
202
+	 * @param ContextInterface|null $context
203
+	 * @throws EE_Error
204
+	 * @throws InvalidArgumentException
205
+	 * @throws InvalidDataTypeException
206
+	 * @throws InvalidInterfaceException
207
+	 * @throws ReflectionException
208
+	 */
209
+	private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, ContextInterface $context = null)
210
+	{
211
+		// these reg statuses should not be considered in any calculations involving monies owing
212
+		$closed_reg_statuses = EEM_Registration::closed_reg_statuses();
213
+		// true if registration has been cancelled or declined
214
+		$this->updateIfCanceled(
215
+			$closed_reg_statuses,
216
+			$new_STS_ID,
217
+			$old_STS_ID,
218
+			$context
219
+		);
220
+		$this->updateIfDeclined(
221
+			$closed_reg_statuses,
222
+			$new_STS_ID,
223
+			$old_STS_ID,
224
+			$context
225
+		);
226
+	}
227
+
228
+
229
+	/**
230
+	 * update REGs and TXN when cancelled or declined registrations involved
231
+	 *
232
+	 * @param array                 $closed_reg_statuses
233
+	 * @param string                $new_STS_ID
234
+	 * @param string                $old_STS_ID
235
+	 * @param ContextInterface|null $context
236
+	 * @throws EE_Error
237
+	 * @throws InvalidArgumentException
238
+	 * @throws InvalidDataTypeException
239
+	 * @throws InvalidInterfaceException
240
+	 * @throws ReflectionException
241
+	 */
242
+	private function updateIfCanceled(
243
+		array $closed_reg_statuses,
244
+		$new_STS_ID,
245
+		$old_STS_ID,
246
+		ContextInterface $context = null
247
+	) {
248
+		// true if registration has been cancelled or declined
249
+		if (in_array($new_STS_ID, $closed_reg_statuses, true)
250
+			&& ! in_array($old_STS_ID, $closed_reg_statuses, true)
251
+		) {
252
+			/** @type EE_Registration_Processor $registration_processor */
253
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
254
+			/** @type EE_Transaction_Processor $transaction_processor */
255
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
256
+			// cancelled or declined registration
257
+			$registration_processor->update_registration_after_being_canceled_or_declined(
258
+				$this,
259
+				$closed_reg_statuses
260
+			);
261
+			$transaction_processor->update_transaction_after_canceled_or_declined_registration(
262
+				$this,
263
+				$closed_reg_statuses,
264
+				false
265
+			);
266
+			do_action(
267
+				'AHEE__EE_Registration__set_status__canceled_or_declined',
268
+				$this,
269
+				$old_STS_ID,
270
+				$new_STS_ID,
271
+				$context
272
+			);
273
+			return;
274
+		}
275
+	}
276
+
277
+
278
+	/**
279
+	 * update REGs and TXN when cancelled or declined registrations involved
280
+	 *
281
+	 * @param array                 $closed_reg_statuses
282
+	 * @param string                $new_STS_ID
283
+	 * @param string                $old_STS_ID
284
+	 * @param ContextInterface|null $context
285
+	 * @throws EE_Error
286
+	 * @throws InvalidArgumentException
287
+	 * @throws InvalidDataTypeException
288
+	 * @throws InvalidInterfaceException
289
+	 * @throws ReflectionException
290
+	 */
291
+	private function updateIfDeclined(
292
+		array $closed_reg_statuses,
293
+		$new_STS_ID,
294
+		$old_STS_ID,
295
+		ContextInterface $context = null
296
+	) {
297
+		// true if reinstating cancelled or declined registration
298
+		if (in_array($old_STS_ID, $closed_reg_statuses, true)
299
+			&& ! in_array($new_STS_ID, $closed_reg_statuses, true)
300
+		) {
301
+			/** @type EE_Registration_Processor $registration_processor */
302
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
303
+			/** @type EE_Transaction_Processor $transaction_processor */
304
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
305
+			// reinstating cancelled or declined registration
306
+			$registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
307
+				$this,
308
+				$closed_reg_statuses
309
+			);
310
+			$transaction_processor->update_transaction_after_reinstating_canceled_registration(
311
+				$this,
312
+				$closed_reg_statuses,
313
+				false
314
+			);
315
+			do_action(
316
+				'AHEE__EE_Registration__set_status__after_reinstated',
317
+				$this,
318
+				$old_STS_ID,
319
+				$new_STS_ID,
320
+				$context
321
+			);
322
+		}
323
+	}
324
+
325
+
326
+	/**
327
+	 * @param ContextInterface|null $context
328
+	 * @return bool
329
+	 */
330
+	private function statusChangeUpdatesTransaction(ContextInterface $context = null)
331
+	{
332
+		$contexts_that_do_not_update_transaction = (array) apply_filters(
333
+			'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction',
334
+			array('spco_reg_step_attendee_information_process_registrations'),
335
+			$context,
336
+			$this
337
+		);
338
+		return ! (
339
+			$context instanceof ContextInterface
340
+			&& in_array($context->slug(), $contexts_that_do_not_update_transaction, true)
341
+		);
342
+	}
343
+
344
+
345
+	/**
346
+	 * @throws EE_Error
347
+	 * @throws EntityNotFoundException
348
+	 * @throws InvalidArgumentException
349
+	 * @throws InvalidDataTypeException
350
+	 * @throws InvalidInterfaceException
351
+	 * @throws ReflectionException
352
+	 * @throws RuntimeException
353
+	 */
354
+	private function updateTransactionAfterStatusChange()
355
+	{
356
+		/** @type EE_Transaction_Payments $transaction_payments */
357
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
358
+		$transaction_payments->recalculate_transaction_total($this->transaction(), false);
359
+		$this->transaction()->update_status_based_on_total_paid(true);
360
+	}
361
+
362
+
363
+	/**
364
+	 *        get Status ID
365
+	 */
366
+	public function status_ID()
367
+	{
368
+		return $this->get('STS_ID');
369
+	}
370
+
371
+
372
+	/**
373
+	 * Gets the ticket this registration is for
374
+	 *
375
+	 * @param boolean $include_archived whether to include archived tickets or not.
376
+	 *
377
+	 * @return EE_Ticket|EE_Base_Class
378
+	 * @throws EE_Error
379
+	 */
380
+	public function ticket($include_archived = true)
381
+	{
382
+		$query_params = array();
383
+		if ($include_archived) {
384
+			$query_params['default_where_conditions'] = 'none';
385
+		}
386
+		return $this->get_first_related('Ticket', $query_params);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Gets the event this registration is for
392
+	 *
393
+	 * @return EE_Event
394
+	 * @throws EE_Error
395
+	 * @throws EntityNotFoundException
396
+	 */
397
+	public function event()
398
+	{
399
+		$event = $this->get_first_related('Event');
400
+		if (! $event instanceof \EE_Event) {
401
+			throw new EntityNotFoundException('Event ID', $this->event_ID());
402
+		}
403
+		return $event;
404
+	}
405
+
406
+
407
+	/**
408
+	 * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
409
+	 * with the author of the event this registration is for.
410
+	 *
411
+	 * @since 4.5.0
412
+	 * @return int
413
+	 * @throws EE_Error
414
+	 * @throws EntityNotFoundException
415
+	 */
416
+	public function wp_user()
417
+	{
418
+		$event = $this->event();
419
+		if ($event instanceof EE_Event) {
420
+			return $event->wp_user();
421
+		}
422
+		return 0;
423
+	}
424
+
425
+
426
+	/**
427
+	 * increments this registration's related ticket sold and corresponding datetime sold values
428
+	 *
429
+	 * @return void
430
+	 * @throws DomainException
431
+	 * @throws EE_Error
432
+	 * @throws EntityNotFoundException
433
+	 * @throws InvalidArgumentException
434
+	 * @throws InvalidDataTypeException
435
+	 * @throws InvalidInterfaceException
436
+	 * @throws ReflectionException
437
+	 * @throws UnexpectedEntityException
438
+	 */
439
+	private function _reserve_registration_space()
440
+	{
441
+		// reserved ticket and datetime counts will be decremented as sold counts are incremented
442
+		// so stop tracking that this reg has a ticket reserved
443
+		$this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
444
+		$ticket = $this->ticket();
445
+		$ticket->increase_sold();
446
+		$ticket->save();
447
+		// possibly set event status to sold out
448
+		$this->event()->perform_sold_out_status_check();
449
+	}
450
+
451
+
452
+	/**
453
+	 * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
454
+	 *
455
+	 * @return void
456
+	 * @throws DomainException
457
+	 * @throws EE_Error
458
+	 * @throws EntityNotFoundException
459
+	 * @throws InvalidArgumentException
460
+	 * @throws InvalidDataTypeException
461
+	 * @throws InvalidInterfaceException
462
+	 * @throws ReflectionException
463
+	 * @throws UnexpectedEntityException
464
+	 */
465
+	private function _release_registration_space()
466
+	{
467
+		$ticket = $this->ticket();
468
+		$ticket->decrease_sold();
469
+		$ticket->save();
470
+		// possibly change event status from sold out back to previous status
471
+		$this->event()->perform_sold_out_status_check();
472
+	}
473
+
474
+
475
+	/**
476
+	 * tracks this registration's ticket reservation in extra meta
477
+	 * and can increment related ticket reserved and corresponding datetime reserved values
478
+	 *
479
+	 * @param bool $update_ticket if true, will increment ticket and datetime reserved count
480
+	 * @return void
481
+	 * @throws EE_Error
482
+	 * @throws InvalidArgumentException
483
+	 * @throws InvalidDataTypeException
484
+	 * @throws InvalidInterfaceException
485
+	 * @throws ReflectionException
486
+	 */
487
+	public function reserve_ticket($update_ticket = false, $source = 'unknown')
488
+	{
489
+		// only reserve ticket if space is not currently reserved
490
+		if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) {
491
+			$this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}");
492
+			// IMPORTANT !!!
493
+			// although checking $update_ticket first would be more efficient,
494
+			// we NEED to ALWAYS call update_extra_meta(), which is why that is done first
495
+			if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true)
496
+				&& $update_ticket
497
+			) {
498
+				$ticket = $this->ticket();
499
+				$ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
500
+				$ticket->save();
501
+			}
502
+		}
503
+	}
504
+
505
+
506
+	/**
507
+	 * stops tracking this registration's ticket reservation in extra meta
508
+	 * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
509
+	 *
510
+	 * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
511
+	 * @return void
512
+	 * @throws EE_Error
513
+	 * @throws InvalidArgumentException
514
+	 * @throws InvalidDataTypeException
515
+	 * @throws InvalidInterfaceException
516
+	 * @throws ReflectionException
517
+	 */
518
+	public function release_reserved_ticket($update_ticket = false, $source = 'unknown')
519
+	{
520
+		// only release ticket if space is currently reserved
521
+		if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) {
522
+			$this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}");
523
+			// IMPORTANT !!!
524
+			// although checking $update_ticket first would be more efficient,
525
+			// we NEED to ALWAYS call update_extra_meta(), which is why that is done first
526
+			if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false)
527
+				&& $update_ticket
528
+			) {
529
+				$ticket = $this->ticket();
530
+				$ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
531
+				$ticket->save();
532
+			}
533
+		}
534
+	}
535
+
536
+
537
+	/**
538
+	 * Set Attendee ID
539
+	 *
540
+	 * @param        int $ATT_ID Attendee ID
541
+	 * @throws EE_Error
542
+	 * @throws RuntimeException
543
+	 */
544
+	public function set_attendee_id($ATT_ID = 0)
545
+	{
546
+		$this->set('ATT_ID', $ATT_ID);
547
+	}
548
+
549
+
550
+	/**
551
+	 *        Set Transaction ID
552
+	 *
553
+	 * @param        int $TXN_ID Transaction ID
554
+	 * @throws EE_Error
555
+	 * @throws RuntimeException
556
+	 */
557
+	public function set_transaction_id($TXN_ID = 0)
558
+	{
559
+		$this->set('TXN_ID', $TXN_ID);
560
+	}
561
+
562
+
563
+	/**
564
+	 *        Set Session
565
+	 *
566
+	 * @param    string $REG_session PHP Session ID
567
+	 * @throws EE_Error
568
+	 * @throws RuntimeException
569
+	 */
570
+	public function set_session($REG_session = '')
571
+	{
572
+		$this->set('REG_session', $REG_session);
573
+	}
574
+
575
+
576
+	/**
577
+	 *        Set Registration URL Link
578
+	 *
579
+	 * @param    string $REG_url_link Registration URL Link
580
+	 * @throws EE_Error
581
+	 * @throws RuntimeException
582
+	 */
583
+	public function set_reg_url_link($REG_url_link = '')
584
+	{
585
+		$this->set('REG_url_link', $REG_url_link);
586
+	}
587
+
588
+
589
+	/**
590
+	 *        Set Attendee Counter
591
+	 *
592
+	 * @param        int $REG_count Primary Attendee
593
+	 * @throws EE_Error
594
+	 * @throws RuntimeException
595
+	 */
596
+	public function set_count($REG_count = 1)
597
+	{
598
+		$this->set('REG_count', $REG_count);
599
+	}
600
+
601
+
602
+	/**
603
+	 *        Set Group Size
604
+	 *
605
+	 * @param        boolean $REG_group_size Group Registration
606
+	 * @throws EE_Error
607
+	 * @throws RuntimeException
608
+	 */
609
+	public function set_group_size($REG_group_size = false)
610
+	{
611
+		$this->set('REG_group_size', $REG_group_size);
612
+	}
613
+
614
+
615
+	/**
616
+	 *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
617
+	 *    EEM_Registration::status_id_not_approved
618
+	 *
619
+	 * @return        boolean
620
+	 */
621
+	public function is_not_approved()
622
+	{
623
+		return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
624
+	}
625
+
626
+
627
+	/**
628
+	 *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
629
+	 *    EEM_Registration::status_id_pending_payment
630
+	 *
631
+	 * @return        boolean
632
+	 */
633
+	public function is_pending_payment()
634
+	{
635
+		return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
636
+	}
637
+
638
+
639
+	/**
640
+	 *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
641
+	 *
642
+	 * @return        boolean
643
+	 */
644
+	public function is_approved()
645
+	{
646
+		return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
647
+	}
648
+
649
+
650
+	/**
651
+	 *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
652
+	 *
653
+	 * @return        boolean
654
+	 */
655
+	public function is_cancelled()
656
+	{
657
+		return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
658
+	}
659
+
660
+
661
+	/**
662
+	 *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
663
+	 *
664
+	 * @return        boolean
665
+	 */
666
+	public function is_declined()
667
+	{
668
+		return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
669
+	}
670
+
671
+
672
+	/**
673
+	 *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
674
+	 *    EEM_Registration::status_id_incomplete
675
+	 *
676
+	 * @return        boolean
677
+	 */
678
+	public function is_incomplete()
679
+	{
680
+		return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
681
+	}
682
+
683
+
684
+	/**
685
+	 *        Set Registration Date
686
+	 *
687
+	 * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
688
+	 *                                                 Date
689
+	 * @throws EE_Error
690
+	 * @throws RuntimeException
691
+	 */
692
+	public function set_reg_date($REG_date = false)
693
+	{
694
+		$this->set('REG_date', $REG_date);
695
+	}
696
+
697
+
698
+	/**
699
+	 *    Set final price owing for this registration after all ticket/price modifications
700
+	 *
701
+	 * @access    public
702
+	 * @param    float $REG_final_price
703
+	 * @throws EE_Error
704
+	 * @throws RuntimeException
705
+	 */
706
+	public function set_final_price($REG_final_price = 0.00)
707
+	{
708
+		$this->set('REG_final_price', $REG_final_price);
709
+	}
710
+
711
+
712
+	/**
713
+	 *    Set amount paid towards this registration's final price
714
+	 *
715
+	 * @access    public
716
+	 * @param    float $REG_paid
717
+	 * @throws EE_Error
718
+	 * @throws RuntimeException
719
+	 */
720
+	public function set_paid($REG_paid = 0.00)
721
+	{
722
+		$this->set('REG_paid', $REG_paid);
723
+	}
724
+
725
+
726
+	/**
727
+	 *        Attendee Is Going
728
+	 *
729
+	 * @param        boolean $REG_att_is_going Attendee Is Going
730
+	 * @throws EE_Error
731
+	 * @throws RuntimeException
732
+	 */
733
+	public function set_att_is_going($REG_att_is_going = false)
734
+	{
735
+		$this->set('REG_att_is_going', $REG_att_is_going);
736
+	}
737
+
738
+
739
+	/**
740
+	 * Gets the related attendee
741
+	 *
742
+	 * @return EE_Attendee
743
+	 * @throws EE_Error
744
+	 */
745
+	public function attendee()
746
+	{
747
+		return $this->get_first_related('Attendee');
748
+	}
749
+
750
+
751
+	/**
752
+	 *        get Event ID
753
+	 */
754
+	public function event_ID()
755
+	{
756
+		return $this->get('EVT_ID');
757
+	}
758
+
759
+
760
+	/**
761
+	 *        get Event ID
762
+	 */
763
+	public function event_name()
764
+	{
765
+		$event = $this->event_obj();
766
+		if ($event) {
767
+			return $event->name();
768
+		} else {
769
+			return null;
770
+		}
771
+	}
772
+
773
+
774
+	/**
775
+	 * Fetches the event this registration is for
776
+	 *
777
+	 * @return EE_Event
778
+	 * @throws EE_Error
779
+	 */
780
+	public function event_obj()
781
+	{
782
+		return $this->get_first_related('Event');
783
+	}
784
+
785
+
786
+	/**
787
+	 *        get Attendee ID
788
+	 */
789
+	public function attendee_ID()
790
+	{
791
+		return $this->get('ATT_ID');
792
+	}
793
+
794
+
795
+	/**
796
+	 *        get PHP Session ID
797
+	 */
798
+	public function session_ID()
799
+	{
800
+		return $this->get('REG_session');
801
+	}
802
+
803
+
804
+	/**
805
+	 * Gets the string which represents the URL trigger for the receipt template in the message template system.
806
+	 *
807
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
808
+	 * @return string
809
+	 */
810
+	public function receipt_url($messenger = 'html')
811
+	{
812
+
813
+		/**
814
+		 * The below will be deprecated one version after this.  We check first if there is a custom receipt template
815
+		 * already in use on old system.  If there is then we just return the standard url for it.
816
+		 *
817
+		 * @since 4.5.0
818
+		 */
819
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
820
+		$has_custom = EEH_Template::locate_template(
821
+			$template_relative_path,
822
+			array(),
823
+			true,
824
+			true,
825
+			true
826
+		);
827
+
828
+		if ($has_custom) {
829
+			return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
830
+		}
831
+		return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
832
+	}
833
+
834
+
835
+	/**
836
+	 * Gets the string which represents the URL trigger for the invoice template in the message template system.
837
+	 *
838
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
839
+	 * @return string
840
+	 * @throws EE_Error
841
+	 */
842
+	public function invoice_url($messenger = 'html')
843
+	{
844
+		/**
845
+		 * The below will be deprecated one version after this.  We check first if there is a custom invoice template
846
+		 * already in use on old system.  If there is then we just return the standard url for it.
847
+		 *
848
+		 * @since 4.5.0
849
+		 */
850
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
851
+		$has_custom = EEH_Template::locate_template(
852
+			$template_relative_path,
853
+			array(),
854
+			true,
855
+			true,
856
+			true
857
+		);
858
+
859
+		if ($has_custom) {
860
+			if ($messenger == 'html') {
861
+				return $this->invoice_url('launch');
862
+			}
863
+			$route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
864
+
865
+			$query_args = array('ee' => $route, 'id' => $this->reg_url_link());
866
+			if ($messenger == 'html') {
867
+				$query_args['html'] = true;
868
+			}
869
+			return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
870
+		}
871
+		return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
872
+	}
873
+
874
+
875
+	/**
876
+	 * get Registration URL Link
877
+	 *
878
+	 * @access public
879
+	 * @return string
880
+	 * @throws EE_Error
881
+	 */
882
+	public function reg_url_link()
883
+	{
884
+		return (string) $this->get('REG_url_link');
885
+	}
886
+
887
+
888
+	/**
889
+	 * Echoes out invoice_url()
890
+	 *
891
+	 * @param string $type 'download','launch', or 'html' (default is 'launch')
892
+	 * @return void
893
+	 * @throws EE_Error
894
+	 */
895
+	public function e_invoice_url($type = 'launch')
896
+	{
897
+		echo $this->invoice_url($type);
898
+	}
899
+
900
+
901
+	/**
902
+	 * Echoes out payment_overview_url
903
+	 */
904
+	public function e_payment_overview_url()
905
+	{
906
+		echo $this->payment_overview_url();
907
+	}
908
+
909
+
910
+	/**
911
+	 * Gets the URL for the checkout payment options reg step
912
+	 * with this registration's REG_url_link added as a query parameter
913
+	 *
914
+	 * @param bool $clear_session Set to true when you want to clear the session on revisiting the
915
+	 *                            payment overview url.
916
+	 * @return string
917
+	 * @throws InvalidInterfaceException
918
+	 * @throws InvalidDataTypeException
919
+	 * @throws EE_Error
920
+	 * @throws InvalidArgumentException
921
+	 */
922
+	public function payment_overview_url($clear_session = false)
923
+	{
924
+		return add_query_arg(
925
+			(array) apply_filters(
926
+				'FHEE__EE_Registration__payment_overview_url__query_args',
927
+				array(
928
+					'e_reg_url_link' => $this->reg_url_link(),
929
+					'step'           => 'payment_options',
930
+					'revisit'        => true,
931
+					'clear_session'  => (bool) $clear_session,
932
+				),
933
+				$this
934
+			),
935
+			EE_Registry::instance()->CFG->core->reg_page_url()
936
+		);
937
+	}
938
+
939
+
940
+	/**
941
+	 * Gets the URL for the checkout attendee information reg step
942
+	 * with this registration's REG_url_link added as a query parameter
943
+	 *
944
+	 * @return string
945
+	 * @throws InvalidInterfaceException
946
+	 * @throws InvalidDataTypeException
947
+	 * @throws EE_Error
948
+	 * @throws InvalidArgumentException
949
+	 */
950
+	public function edit_attendee_information_url()
951
+	{
952
+		return add_query_arg(
953
+			(array) apply_filters(
954
+				'FHEE__EE_Registration__edit_attendee_information_url__query_args',
955
+				array(
956
+					'e_reg_url_link' => $this->reg_url_link(),
957
+					'step'           => 'attendee_information',
958
+					'revisit'        => true,
959
+				),
960
+				$this
961
+			),
962
+			EE_Registry::instance()->CFG->core->reg_page_url()
963
+		);
964
+	}
965
+
966
+
967
+	/**
968
+	 * Simply generates and returns the appropriate admin_url link to edit this registration
969
+	 *
970
+	 * @return string
971
+	 * @throws EE_Error
972
+	 */
973
+	public function get_admin_edit_url()
974
+	{
975
+		return EEH_URL::add_query_args_and_nonce(
976
+			array(
977
+				'page'    => 'espresso_registrations',
978
+				'action'  => 'view_registration',
979
+				'_REG_ID' => $this->ID(),
980
+			),
981
+			admin_url('admin.php')
982
+		);
983
+	}
984
+
985
+
986
+	/**
987
+	 *    is_primary_registrant?
988
+	 */
989
+	public function is_primary_registrant()
990
+	{
991
+		return $this->get('REG_count') === 1 ? true : false;
992
+	}
993
+
994
+
995
+	/**
996
+	 * This returns the primary registration object for this registration group (which may be this object).
997
+	 *
998
+	 * @return EE_Registration
999
+	 * @throws EE_Error
1000
+	 */
1001
+	public function get_primary_registration()
1002
+	{
1003
+		if ($this->is_primary_registrant()) {
1004
+			return $this;
1005
+		}
1006
+
1007
+		// k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
1008
+		/** @var EE_Registration $primary_registrant */
1009
+		$primary_registrant = EEM_Registration::instance()->get_one(
1010
+			array(
1011
+				array(
1012
+					'TXN_ID'    => $this->transaction_ID(),
1013
+					'REG_count' => 1,
1014
+				),
1015
+			)
1016
+		);
1017
+		return $primary_registrant;
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 *        get  Attendee Number
1023
+	 *
1024
+	 * @access        public
1025
+	 */
1026
+	public function count()
1027
+	{
1028
+		return $this->get('REG_count');
1029
+	}
1030
+
1031
+
1032
+	/**
1033
+	 *        get Group Size
1034
+	 */
1035
+	public function group_size()
1036
+	{
1037
+		return $this->get('REG_group_size');
1038
+	}
1039
+
1040
+
1041
+	/**
1042
+	 *        get Registration Date
1043
+	 */
1044
+	public function date()
1045
+	{
1046
+		return $this->get('REG_date');
1047
+	}
1048
+
1049
+
1050
+	/**
1051
+	 * gets a pretty date
1052
+	 *
1053
+	 * @param string $date_format
1054
+	 * @param string $time_format
1055
+	 * @return string
1056
+	 * @throws EE_Error
1057
+	 */
1058
+	public function pretty_date($date_format = null, $time_format = null)
1059
+	{
1060
+		return $this->get_datetime('REG_date', $date_format, $time_format);
1061
+	}
1062
+
1063
+
1064
+	/**
1065
+	 * final_price
1066
+	 * the registration's share of the transaction total, so that the
1067
+	 * sum of all the transaction's REG_final_prices equal the transaction's total
1068
+	 *
1069
+	 * @return float
1070
+	 * @throws EE_Error
1071
+	 */
1072
+	public function final_price()
1073
+	{
1074
+		return $this->get('REG_final_price');
1075
+	}
1076
+
1077
+
1078
+	/**
1079
+	 * pretty_final_price
1080
+	 *  final price as formatted string, with correct decimal places and currency symbol
1081
+	 *
1082
+	 * @return string
1083
+	 * @throws EE_Error
1084
+	 */
1085
+	public function pretty_final_price()
1086
+	{
1087
+		return $this->get_pretty('REG_final_price');
1088
+	}
1089
+
1090
+
1091
+	/**
1092
+	 * get paid (yeah)
1093
+	 *
1094
+	 * @return float
1095
+	 * @throws EE_Error
1096
+	 */
1097
+	public function paid()
1098
+	{
1099
+		return $this->get('REG_paid');
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * pretty_paid
1105
+	 *
1106
+	 * @return float
1107
+	 * @throws EE_Error
1108
+	 */
1109
+	public function pretty_paid()
1110
+	{
1111
+		return $this->get_pretty('REG_paid');
1112
+	}
1113
+
1114
+
1115
+	/**
1116
+	 * owes_monies_and_can_pay
1117
+	 * whether or not this registration has monies owing and it's' status allows payment
1118
+	 *
1119
+	 * @param array $requires_payment
1120
+	 * @return bool
1121
+	 * @throws EE_Error
1122
+	 */
1123
+	public function owes_monies_and_can_pay($requires_payment = array())
1124
+	{
1125
+		// these reg statuses require payment (if event is not free)
1126
+		$requires_payment = ! empty($requires_payment)
1127
+			? $requires_payment
1128
+			: EEM_Registration::reg_statuses_that_allow_payment();
1129
+		if (in_array($this->status_ID(), $requires_payment) &&
1130
+			$this->final_price() != 0 &&
1131
+			$this->final_price() != $this->paid()
1132
+		) {
1133
+			return true;
1134
+		} else {
1135
+			return false;
1136
+		}
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * Prints out the return value of $this->pretty_status()
1142
+	 *
1143
+	 * @param bool $show_icons
1144
+	 * @return void
1145
+	 * @throws EE_Error
1146
+	 */
1147
+	public function e_pretty_status($show_icons = false)
1148
+	{
1149
+		echo $this->pretty_status($show_icons);
1150
+	}
1151
+
1152
+
1153
+	/**
1154
+	 * Returns a nice version of the status for displaying to customers
1155
+	 *
1156
+	 * @param bool $show_icons
1157
+	 * @return string
1158
+	 * @throws EE_Error
1159
+	 */
1160
+	public function pretty_status($show_icons = false)
1161
+	{
1162
+		$status = EEM_Status::instance()->localized_status(
1163
+			array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
1164
+			false,
1165
+			'sentence'
1166
+		);
1167
+		$icon = '';
1168
+		switch ($this->status_ID()) {
1169
+			case EEM_Registration::status_id_approved:
1170
+				$icon = $show_icons
1171
+					? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>'
1172
+					: '';
1173
+				break;
1174
+			case EEM_Registration::status_id_pending_payment:
1175
+				$icon = $show_icons
1176
+					? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>'
1177
+					: '';
1178
+				break;
1179
+			case EEM_Registration::status_id_not_approved:
1180
+				$icon = $show_icons
1181
+					? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>'
1182
+					: '';
1183
+				break;
1184
+			case EEM_Registration::status_id_cancelled:
1185
+				$icon = $show_icons
1186
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
1187
+					: '';
1188
+				break;
1189
+			case EEM_Registration::status_id_incomplete:
1190
+				$icon = $show_icons
1191
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>'
1192
+					: '';
1193
+				break;
1194
+			case EEM_Registration::status_id_declined:
1195
+				$icon = $show_icons
1196
+					? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
1197
+					: '';
1198
+				break;
1199
+			case EEM_Registration::status_id_wait_list:
1200
+				$icon = $show_icons
1201
+					? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>'
1202
+					: '';
1203
+				break;
1204
+		}
1205
+		return $icon . $status[ $this->status_ID() ];
1206
+	}
1207
+
1208
+
1209
+	/**
1210
+	 *        get Attendee Is Going
1211
+	 */
1212
+	public function att_is_going()
1213
+	{
1214
+		return $this->get('REG_att_is_going');
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * Gets related answers
1220
+	 *
1221
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1222
+	 * @return EE_Answer[]
1223
+	 * @throws EE_Error
1224
+	 */
1225
+	public function answers($query_params = null)
1226
+	{
1227
+		return $this->get_many_related('Answer', $query_params);
1228
+	}
1229
+
1230
+
1231
+	/**
1232
+	 * Gets the registration's answer value to the specified question
1233
+	 * (either the question's ID or a question object)
1234
+	 *
1235
+	 * @param EE_Question|int $question
1236
+	 * @param bool            $pretty_value
1237
+	 * @return array|string if pretty_value= true, the result will always be a string
1238
+	 * (because the answer might be an array of answer values, so passing pretty_value=true
1239
+	 * will convert it into some kind of string)
1240
+	 * @throws EE_Error
1241
+	 */
1242
+	public function answer_value_to_question($question, $pretty_value = true)
1243
+	{
1244
+		$question_id = EEM_Question::instance()->ensure_is_ID($question);
1245
+		return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
1246
+	}
1247
+
1248
+
1249
+	/**
1250
+	 * question_groups
1251
+	 * returns an array of EE_Question_Group objects for this registration
1252
+	 *
1253
+	 * @return EE_Question_Group[]
1254
+	 * @throws EE_Error
1255
+	 * @throws InvalidArgumentException
1256
+	 * @throws InvalidDataTypeException
1257
+	 * @throws InvalidInterfaceException
1258
+	 * @throws ReflectionException
1259
+	 */
1260
+	public function question_groups()
1261
+	{
1262
+		return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this);
1263
+	}
1264
+
1265
+
1266
+	/**
1267
+	 * count_question_groups
1268
+	 * returns a count of the number of EE_Question_Group objects for this registration
1269
+	 *
1270
+	 * @return int
1271
+	 * @throws EE_Error
1272
+	 * @throws EntityNotFoundException
1273
+	 * @throws InvalidArgumentException
1274
+	 * @throws InvalidDataTypeException
1275
+	 * @throws InvalidInterfaceException
1276
+	 * @throws ReflectionException
1277
+	 */
1278
+	public function count_question_groups()
1279
+	{
1280
+		return EEM_Event::instance()->count_related(
1281
+			$this->event_ID(),
1282
+			'Question_Group',
1283
+			[
1284
+				[
1285
+					'Event_Question_Group.'
1286
+					. EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true,
1287
+				]
1288
+			]
1289
+		);
1290
+	}
1291
+
1292
+
1293
+	/**
1294
+	 * Returns the registration date in the 'standard' string format
1295
+	 * (function may be improved in the future to allow for different formats and timezones)
1296
+	 *
1297
+	 * @return string
1298
+	 * @throws EE_Error
1299
+	 */
1300
+	public function reg_date()
1301
+	{
1302
+		return $this->get_datetime('REG_date');
1303
+	}
1304
+
1305
+
1306
+	/**
1307
+	 * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1308
+	 * the ticket this registration purchased, or the datetime they have registered
1309
+	 * to attend)
1310
+	 *
1311
+	 * @return EE_Datetime_Ticket
1312
+	 * @throws EE_Error
1313
+	 */
1314
+	public function datetime_ticket()
1315
+	{
1316
+		return $this->get_first_related('Datetime_Ticket');
1317
+	}
1318
+
1319
+
1320
+	/**
1321
+	 * Sets the registration's datetime_ticket.
1322
+	 *
1323
+	 * @param EE_Datetime_Ticket $datetime_ticket
1324
+	 * @return EE_Datetime_Ticket
1325
+	 * @throws EE_Error
1326
+	 */
1327
+	public function set_datetime_ticket($datetime_ticket)
1328
+	{
1329
+		return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1330
+	}
1331
+
1332
+	/**
1333
+	 * Gets deleted
1334
+	 *
1335
+	 * @return bool
1336
+	 * @throws EE_Error
1337
+	 */
1338
+	public function deleted()
1339
+	{
1340
+		return $this->get('REG_deleted');
1341
+	}
1342
+
1343
+	/**
1344
+	 * Sets deleted
1345
+	 *
1346
+	 * @param boolean $deleted
1347
+	 * @return bool
1348
+	 * @throws EE_Error
1349
+	 * @throws RuntimeException
1350
+	 */
1351
+	public function set_deleted($deleted)
1352
+	{
1353
+		if ($deleted) {
1354
+			$this->delete();
1355
+		} else {
1356
+			$this->restore();
1357
+		}
1358
+	}
1359
+
1360
+
1361
+	/**
1362
+	 * Get the status object of this object
1363
+	 *
1364
+	 * @return EE_Status
1365
+	 * @throws EE_Error
1366
+	 */
1367
+	public function status_obj()
1368
+	{
1369
+		return $this->get_first_related('Status');
1370
+	}
1371
+
1372
+
1373
+	/**
1374
+	 * Returns the number of times this registration has checked into any of the datetimes
1375
+	 * its available for
1376
+	 *
1377
+	 * @return int
1378
+	 * @throws EE_Error
1379
+	 */
1380
+	public function count_checkins()
1381
+	{
1382
+		return $this->get_model()->count_related($this, 'Checkin');
1383
+	}
1384
+
1385
+
1386
+	/**
1387
+	 * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1388
+	 * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1389
+	 *
1390
+	 * @return int
1391
+	 * @throws EE_Error
1392
+	 */
1393
+	public function count_checkins_not_checkedout()
1394
+	{
1395
+		return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1396
+	}
1397
+
1398
+
1399
+	/**
1400
+	 * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1401
+	 *
1402
+	 * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1403
+	 * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1404
+	 *                                          consider registration status as well as datetime access.
1405
+	 * @return bool
1406
+	 * @throws EE_Error
1407
+	 */
1408
+	public function can_checkin($DTT_OR_ID, $check_approved = true)
1409
+	{
1410
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1411
+
1412
+		// first check registration status
1413
+		if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1414
+			return false;
1415
+		}
1416
+		// is there a datetime ticket that matches this dtt_ID?
1417
+		if (! (EEM_Datetime_Ticket::instance()->exists(
1418
+			array(
1419
+				array(
1420
+					'TKT_ID' => $this->get('TKT_ID'),
1421
+					'DTT_ID' => $DTT_ID,
1422
+				),
1423
+			)
1424
+		))
1425
+		) {
1426
+			return false;
1427
+		}
1428
+
1429
+		// final check is against TKT_uses
1430
+		return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1431
+	}
1432
+
1433
+
1434
+	/**
1435
+	 * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1436
+	 * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1437
+	 * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1438
+	 * then return false.  Otherwise return true.
1439
+	 *
1440
+	 * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1441
+	 * @return bool true means can checkin.  false means cannot checkin.
1442
+	 * @throws EE_Error
1443
+	 */
1444
+	public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1445
+	{
1446
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1447
+
1448
+		if (! $DTT_ID) {
1449
+			return false;
1450
+		}
1451
+
1452
+		$max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1453
+
1454
+		// if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1455
+		// check-in or not.
1456
+		if (! $max_uses || $max_uses === EE_INF) {
1457
+			return true;
1458
+		}
1459
+
1460
+		// does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1461
+		// go ahead and toggle.
1462
+		if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1463
+			return true;
1464
+		}
1465
+
1466
+		// made it here so the last check is whether the number of checkins per unique datetime on this registration
1467
+		// disallows further check-ins.
1468
+		$count_unique_dtt_checkins = EEM_Checkin::instance()->count(
1469
+			array(
1470
+				array(
1471
+					'REG_ID' => $this->ID(),
1472
+					'CHK_in' => true,
1473
+				),
1474
+			),
1475
+			'DTT_ID',
1476
+			true
1477
+		);
1478
+		// checkins have already reached their max number of uses
1479
+		// so registrant can NOT checkin
1480
+		if ($count_unique_dtt_checkins >= $max_uses) {
1481
+			EE_Error::add_error(
1482
+				esc_html__(
1483
+					'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1484
+					'event_espresso'
1485
+				),
1486
+				__FILE__,
1487
+				__FUNCTION__,
1488
+				__LINE__
1489
+			);
1490
+			return false;
1491
+		}
1492
+		return true;
1493
+	}
1494
+
1495
+
1496
+	/**
1497
+	 * toggle Check-in status for this registration
1498
+	 * Check-ins are toggled in the following order:
1499
+	 * never checked in -> checked in
1500
+	 * checked in -> checked out
1501
+	 * checked out -> checked in
1502
+	 *
1503
+	 * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1504
+	 *                      If not included or null, then it is assumed latest datetime is being toggled.
1505
+	 * @param bool $verify  If true then can_checkin() is used to verify whether the person
1506
+	 *                      can be checked in or not.  Otherwise this forces change in checkin status.
1507
+	 * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1508
+	 * @throws EE_Error
1509
+	 */
1510
+	public function toggle_checkin_status($DTT_ID = null, $verify = false)
1511
+	{
1512
+		if (empty($DTT_ID)) {
1513
+			$datetime = $this->get_latest_related_datetime();
1514
+			$DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1515
+			// verify the registration can checkin for the given DTT_ID
1516
+		} elseif (! $this->can_checkin($DTT_ID, $verify)) {
1517
+			EE_Error::add_error(
1518
+				sprintf(
1519
+					esc_html__(
1520
+						'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1521
+						'event_espresso'
1522
+					),
1523
+					$this->ID(),
1524
+					$DTT_ID
1525
+				),
1526
+				__FILE__,
1527
+				__FUNCTION__,
1528
+				__LINE__
1529
+			);
1530
+			return false;
1531
+		}
1532
+		$status_paths = array(
1533
+			EE_Checkin::status_checked_never => EE_Checkin::status_checked_in,
1534
+			EE_Checkin::status_checked_in    => EE_Checkin::status_checked_out,
1535
+			EE_Checkin::status_checked_out   => EE_Checkin::status_checked_in,
1536
+		);
1537
+		// start by getting the current status so we know what status we'll be changing to.
1538
+		$cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1539
+		$status_to = $status_paths[ $cur_status ];
1540
+		// database only records true for checked IN or false for checked OUT
1541
+		// no record ( null ) means checked in NEVER, but we obviously don't save that
1542
+		$new_status = $status_to === EE_Checkin::status_checked_in ? true : false;
1543
+		// add relation - note Check-ins are always creating new rows
1544
+		// because we are keeping track of Check-ins over time.
1545
+		// Eventually we'll probably want to show a list table
1546
+		// for the individual Check-ins so that they can be managed.
1547
+		$checkin = EE_Checkin::new_instance(
1548
+			array(
1549
+				'REG_ID' => $this->ID(),
1550
+				'DTT_ID' => $DTT_ID,
1551
+				'CHK_in' => $new_status,
1552
+			)
1553
+		);
1554
+		// if the record could not be saved then return false
1555
+		if ($checkin->save() === 0) {
1556
+			if (WP_DEBUG) {
1557
+				global $wpdb;
1558
+				$error = sprintf(
1559
+					esc_html__(
1560
+						'Registration check in update failed because of the following database error: %1$s%2$s',
1561
+						'event_espresso'
1562
+					),
1563
+					'<br />',
1564
+					$wpdb->last_error
1565
+				);
1566
+			} else {
1567
+				$error = esc_html__(
1568
+					'Registration check in update failed because of an unknown database error',
1569
+					'event_espresso'
1570
+				);
1571
+			}
1572
+			EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1573
+			return false;
1574
+		}
1575
+		return $status_to;
1576
+	}
1577
+
1578
+
1579
+	/**
1580
+	 * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1581
+	 * "Latest" is defined by the `DTT_EVT_start` column.
1582
+	 *
1583
+	 * @return EE_Datetime|null
1584
+	 * @throws EE_Error
1585
+	 */
1586
+	public function get_latest_related_datetime()
1587
+	{
1588
+		return EEM_Datetime::instance()->get_one(
1589
+			array(
1590
+				array(
1591
+					'Ticket.Registration.REG_ID' => $this->ID(),
1592
+				),
1593
+				'order_by' => array('DTT_EVT_start' => 'DESC'),
1594
+			)
1595
+		);
1596
+	}
1597
+
1598
+
1599
+	/**
1600
+	 * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1601
+	 * "Earliest" is defined by the `DTT_EVT_start` column.
1602
+	 *
1603
+	 * @throws EE_Error
1604
+	 */
1605
+	public function get_earliest_related_datetime()
1606
+	{
1607
+		return EEM_Datetime::instance()->get_one(
1608
+			array(
1609
+				array(
1610
+					'Ticket.Registration.REG_ID' => $this->ID(),
1611
+				),
1612
+				'order_by' => array('DTT_EVT_start' => 'ASC'),
1613
+			)
1614
+		);
1615
+	}
1616
+
1617
+
1618
+	/**
1619
+	 * This method simply returns the check-in status for this registration and the given datetime.
1620
+	 * If neither the datetime nor the checkin values are provided as arguments,
1621
+	 * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1622
+	 *
1623
+	 * @param  int       $DTT_ID  The ID of the datetime we're checking against
1624
+	 *                            (if empty we'll get the primary datetime for
1625
+	 *                            this registration (via event) and use it's ID);
1626
+	 * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1627
+	 *
1628
+	 * @return int                Integer representing Check-in status.
1629
+	 * @throws EE_Error
1630
+	 */
1631
+	public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1632
+	{
1633
+		$checkin_query_params = array(
1634
+			'order_by' => array('CHK_timestamp' => 'DESC'),
1635
+		);
1636
+
1637
+		if ($DTT_ID > 0) {
1638
+			$checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1639
+		}
1640
+
1641
+		// get checkin object (if exists)
1642
+		$checkin = $checkin instanceof EE_Checkin
1643
+			? $checkin
1644
+			: $this->get_first_related('Checkin', $checkin_query_params);
1645
+		if ($checkin instanceof EE_Checkin) {
1646
+			if ($checkin->get('CHK_in')) {
1647
+				return EE_Checkin::status_checked_in; // checked in
1648
+			}
1649
+			return EE_Checkin::status_checked_out; // had checked in but is now checked out.
1650
+		}
1651
+		return EE_Checkin::status_checked_never; // never been checked in
1652
+	}
1653
+
1654
+
1655
+	/**
1656
+	 * This method returns a localized message for the toggled Check-in message.
1657
+	 *
1658
+	 * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1659
+	 *                     then it is assumed Check-in for primary datetime was toggled.
1660
+	 * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1661
+	 *                     message can be customized with the attendee name.
1662
+	 * @return string internationalized message
1663
+	 * @throws EE_Error
1664
+	 */
1665
+	public function get_checkin_msg($DTT_ID, $error = false)
1666
+	{
1667
+		// let's get the attendee first so we can include the name of the attendee
1668
+		$attendee = $this->get_first_related('Attendee');
1669
+		if ($attendee instanceof EE_Attendee) {
1670
+			if ($error) {
1671
+				return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1672
+			}
1673
+			$cur_status = $this->check_in_status_for_datetime($DTT_ID);
1674
+			// what is the status message going to be?
1675
+			switch ($cur_status) {
1676
+				case EE_Checkin::status_checked_never:
1677
+					return sprintf(
1678
+						__("%s has been removed from Check-in records", "event_espresso"),
1679
+						$attendee->full_name()
1680
+					);
1681
+					break;
1682
+				case EE_Checkin::status_checked_in:
1683
+					return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1684
+					break;
1685
+				case EE_Checkin::status_checked_out:
1686
+					return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1687
+					break;
1688
+			}
1689
+		}
1690
+		return esc_html__("The check-in status could not be determined.", "event_espresso");
1691
+	}
1692
+
1693
+
1694
+	/**
1695
+	 * Returns the related EE_Transaction to this registration
1696
+	 *
1697
+	 * @return EE_Transaction
1698
+	 * @throws EE_Error
1699
+	 * @throws EntityNotFoundException
1700
+	 */
1701
+	public function transaction()
1702
+	{
1703
+		$transaction = $this->get_first_related('Transaction');
1704
+		if (! $transaction instanceof \EE_Transaction) {
1705
+			throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1706
+		}
1707
+		return $transaction;
1708
+	}
1709
+
1710
+
1711
+	/**
1712
+	 *        get Registration Code
1713
+	 */
1714
+	public function reg_code()
1715
+	{
1716
+		return $this->get('REG_code');
1717
+	}
1718
+
1719
+
1720
+	/**
1721
+	 *        get Transaction ID
1722
+	 */
1723
+	public function transaction_ID()
1724
+	{
1725
+		return $this->get('TXN_ID');
1726
+	}
1727
+
1728
+
1729
+	/**
1730
+	 * @return int
1731
+	 * @throws EE_Error
1732
+	 */
1733
+	public function ticket_ID()
1734
+	{
1735
+		return $this->get('TKT_ID');
1736
+	}
1737
+
1738
+
1739
+	/**
1740
+	 *        Set Registration Code
1741
+	 *
1742
+	 * @access    public
1743
+	 * @param    string  $REG_code Registration Code
1744
+	 * @param    boolean $use_default
1745
+	 * @throws EE_Error
1746
+	 */
1747
+	public function set_reg_code($REG_code, $use_default = false)
1748
+	{
1749
+		if (empty($REG_code)) {
1750
+			EE_Error::add_error(
1751
+				esc_html__('REG_code can not be empty.', 'event_espresso'),
1752
+				__FILE__,
1753
+				__FUNCTION__,
1754
+				__LINE__
1755
+			);
1756
+			return;
1757
+		}
1758
+		if (! $this->reg_code()) {
1759
+			parent::set('REG_code', $REG_code, $use_default);
1760
+		} else {
1761
+			EE_Error::doing_it_wrong(
1762
+				__CLASS__ . '::' . __FUNCTION__,
1763
+				esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1764
+				'4.6.0'
1765
+			);
1766
+		}
1767
+	}
1768
+
1769
+
1770
+	/**
1771
+	 * Returns all other registrations in the same group as this registrant who have the same ticket option.
1772
+	 * Note, if you want to just get all registrations in the same transaction (group), use:
1773
+	 *    $registration->transaction()->registrations();
1774
+	 *
1775
+	 * @since 4.5.0
1776
+	 * @return EE_Registration[] or empty array if this isn't a group registration.
1777
+	 * @throws EE_Error
1778
+	 */
1779
+	public function get_all_other_registrations_in_group()
1780
+	{
1781
+		if ($this->group_size() < 2) {
1782
+			return array();
1783
+		}
1784
+
1785
+		$query[0] = array(
1786
+			'TXN_ID' => $this->transaction_ID(),
1787
+			'REG_ID' => array('!=', $this->ID()),
1788
+			'TKT_ID' => $this->ticket_ID(),
1789
+		);
1790
+		/** @var EE_Registration[] $registrations */
1791
+		$registrations = $this->get_model()->get_all($query);
1792
+		return $registrations;
1793
+	}
1794
+
1795
+	/**
1796
+	 * Return the link to the admin details for the object.
1797
+	 *
1798
+	 * @return string
1799
+	 * @throws EE_Error
1800
+	 */
1801
+	public function get_admin_details_link()
1802
+	{
1803
+		EE_Registry::instance()->load_helper('URL');
1804
+		return EEH_URL::add_query_args_and_nonce(
1805
+			array(
1806
+				'page'    => 'espresso_registrations',
1807
+				'action'  => 'view_registration',
1808
+				'_REG_ID' => $this->ID(),
1809
+			),
1810
+			admin_url('admin.php')
1811
+		);
1812
+	}
1813
+
1814
+	/**
1815
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1816
+	 *
1817
+	 * @return string
1818
+	 * @throws EE_Error
1819
+	 */
1820
+	public function get_admin_edit_link()
1821
+	{
1822
+		return $this->get_admin_details_link();
1823
+	}
1824
+
1825
+	/**
1826
+	 * Returns the link to a settings page for the object.
1827
+	 *
1828
+	 * @return string
1829
+	 * @throws EE_Error
1830
+	 */
1831
+	public function get_admin_settings_link()
1832
+	{
1833
+		return $this->get_admin_details_link();
1834
+	}
1835
+
1836
+	/**
1837
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
1838
+	 *
1839
+	 * @return string
1840
+	 */
1841
+	public function get_admin_overview_link()
1842
+	{
1843
+		EE_Registry::instance()->load_helper('URL');
1844
+		return EEH_URL::add_query_args_and_nonce(
1845
+			array(
1846
+				'page' => 'espresso_registrations',
1847
+			),
1848
+			admin_url('admin.php')
1849
+		);
1850
+	}
1851
+
1852
+
1853
+	/**
1854
+	 * @param array $query_params
1855
+	 *
1856
+	 * @return \EE_Registration[]
1857
+	 * @throws EE_Error
1858
+	 */
1859
+	public function payments($query_params = array())
1860
+	{
1861
+		return $this->get_many_related('Payment', $query_params);
1862
+	}
1863
+
1864
+
1865
+	/**
1866
+	 * @param array $query_params
1867
+	 *
1868
+	 * @return \EE_Registration_Payment[]
1869
+	 * @throws EE_Error
1870
+	 */
1871
+	public function registration_payments($query_params = array())
1872
+	{
1873
+		return $this->get_many_related('Registration_Payment', $query_params);
1874
+	}
1875
+
1876
+
1877
+	/**
1878
+	 * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1879
+	 * Note: if there are no payments on the registration there will be no payment method returned.
1880
+	 *
1881
+	 * @return EE_Payment_Method|null
1882
+	 */
1883
+	public function payment_method()
1884
+	{
1885
+		return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1886
+	}
1887
+
1888
+
1889
+	/**
1890
+	 * @return \EE_Line_Item
1891
+	 * @throws EntityNotFoundException
1892
+	 * @throws EE_Error
1893
+	 */
1894
+	public function ticket_line_item()
1895
+	{
1896
+		$ticket = $this->ticket();
1897
+		$transaction = $this->transaction();
1898
+		$line_item = null;
1899
+		$ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1900
+			$transaction->total_line_item(),
1901
+			'Ticket',
1902
+			array($ticket->ID())
1903
+		);
1904
+		foreach ($ticket_line_items as $ticket_line_item) {
1905
+			if ($ticket_line_item instanceof \EE_Line_Item
1906
+				&& $ticket_line_item->OBJ_type() === 'Ticket'
1907
+				&& $ticket_line_item->OBJ_ID() === $ticket->ID()
1908
+			) {
1909
+				$line_item = $ticket_line_item;
1910
+				break;
1911
+			}
1912
+		}
1913
+		if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1914
+			throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1915
+		}
1916
+		return $line_item;
1917
+	}
1918
+
1919
+
1920
+	/**
1921
+	 * Soft Deletes this model object.
1922
+	 *
1923
+	 * @return boolean | int
1924
+	 * @throws RuntimeException
1925
+	 * @throws EE_Error
1926
+	 */
1927
+	public function delete()
1928
+	{
1929
+		if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1930
+			$this->set_status(EEM_Registration::status_id_cancelled);
1931
+		}
1932
+		return parent::delete();
1933
+	}
1934
+
1935
+
1936
+	/**
1937
+	 * Restores whatever the previous status was on a registration before it was trashed (if possible)
1938
+	 *
1939
+	 * @throws EE_Error
1940
+	 * @throws RuntimeException
1941
+	 */
1942
+	public function restore()
1943
+	{
1944
+		$previous_status = $this->get_extra_meta(
1945
+			EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1946
+			true,
1947
+			EEM_Registration::status_id_cancelled
1948
+		);
1949
+		if ($previous_status) {
1950
+			$this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1951
+			$this->set_status($previous_status);
1952
+		}
1953
+		return parent::restore();
1954
+	}
1955
+
1956
+
1957
+	/**
1958
+	 * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price
1959
+	 *
1960
+	 * @param  boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic
1961
+	 *                                           depending on whether the reg status changes to or from "Approved"
1962
+	 * @return boolean whether the Registration status was updated
1963
+	 * @throws EE_Error
1964
+	 * @throws RuntimeException
1965
+	 */
1966
+	public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true)
1967
+	{
1968
+		$paid = $this->paid();
1969
+		$price = $this->final_price();
1970
+		switch (true) {
1971
+			// overpaid or paid
1972
+			case EEH_Money::compare_floats($paid, $price, '>'):
1973
+			case EEH_Money::compare_floats($paid, $price):
1974
+				$new_status = EEM_Registration::status_id_approved;
1975
+				break;
1976
+			//  underpaid
1977
+			case EEH_Money::compare_floats($paid, $price, '<'):
1978
+				$new_status = EEM_Registration::status_id_pending_payment;
1979
+				break;
1980
+			// uhhh Houston...
1981
+			default:
1982
+				throw new RuntimeException(
1983
+					esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso')
1984
+				);
1985
+		}
1986
+		if ($new_status !== $this->status_ID()) {
1987
+			if ($trigger_set_status_logic) {
1988
+				return $this->set_status($new_status);
1989
+			}
1990
+			parent::set('STS_ID', $new_status);
1991
+			return true;
1992
+		}
1993
+		return false;
1994
+	}
1995
+
1996
+
1997
+	/*************************** DEPRECATED ***************************/
1998
+
1999
+
2000
+	/**
2001
+	 * @deprecated
2002
+	 * @since     4.7.0
2003
+	 * @access    public
2004
+	 */
2005
+	public function price_paid()
2006
+	{
2007
+		EE_Error::doing_it_wrong(
2008
+			'EE_Registration::price_paid()',
2009
+			esc_html__(
2010
+				'This method is deprecated, please use EE_Registration::final_price() instead.',
2011
+				'event_espresso'
2012
+			),
2013
+			'4.7.0'
2014
+		);
2015
+		return $this->final_price();
2016
+	}
2017
+
2018
+
2019
+	/**
2020
+	 * @deprecated
2021
+	 * @since     4.7.0
2022
+	 * @access    public
2023
+	 * @param    float $REG_final_price
2024
+	 * @throws EE_Error
2025
+	 * @throws RuntimeException
2026
+	 */
2027
+	public function set_price_paid($REG_final_price = 0.00)
2028
+	{
2029
+		EE_Error::doing_it_wrong(
2030
+			'EE_Registration::set_price_paid()',
2031
+			esc_html__(
2032
+				'This method is deprecated, please use EE_Registration::set_final_price() instead.',
2033
+				'event_espresso'
2034
+			),
2035
+			'4.7.0'
2036
+		);
2037
+		$this->set_final_price($REG_final_price);
2038
+	}
2039
+
2040
+
2041
+	/**
2042
+	 * @deprecated
2043
+	 * @since 4.7.0
2044
+	 * @return string
2045
+	 * @throws EE_Error
2046
+	 */
2047
+	public function pretty_price_paid()
2048
+	{
2049
+		EE_Error::doing_it_wrong(
2050
+			'EE_Registration::pretty_price_paid()',
2051
+			esc_html__(
2052
+				'This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
2053
+				'event_espresso'
2054
+			),
2055
+			'4.7.0'
2056
+		);
2057
+		return $this->pretty_final_price();
2058
+	}
2059
+
2060
+
2061
+	/**
2062
+	 * Gets the primary datetime related to this registration via the related Event to this registration
2063
+	 *
2064
+	 * @deprecated 4.9.17
2065
+	 * @return EE_Datetime
2066
+	 * @throws EE_Error
2067
+	 * @throws EntityNotFoundException
2068
+	 */
2069
+	public function get_related_primary_datetime()
2070
+	{
2071
+		EE_Error::doing_it_wrong(
2072
+			__METHOD__,
2073
+			esc_html__(
2074
+				'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
2075
+				'event_espresso'
2076
+			),
2077
+			'4.9.17',
2078
+			'5.0.0'
2079
+		);
2080
+		return $this->event()->primary_datetime();
2081
+	}
2082 2082
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_Data_Migration_Script_Base.core.php 1 patch
Indentation   +882 added lines, -882 removed lines patch added patch discarded remove patch
@@ -15,886 +15,886 @@
 block discarded – undo
15 15
 abstract class EE_Data_Migration_Script_Base extends EE_Data_Migration_Class_Base
16 16
 {
17 17
 
18
-    /**
19
-     * Set by client code to indicate this DMS is being ran as part of a proper migration,
20
-     * instead of being used to merely setup (or verify) the database structure.
21
-     * Defaults to TRUE, so client code that's NOT using this DMS as part of a proper migration
22
-     * should call EE_Data_Migration_Script_Base::set_migrating( FALSE )
23
-     *
24
-     * @var boolean
25
-     */
26
-    protected $_migrating = true;
27
-
28
-    /**
29
-     * numerically-indexed array where each value is EE_Data_Migration_Script_Stage object
30
-     *
31
-     * @var EE_Data_Migration_Script_Stage[] $migration_functions
32
-     */
33
-    protected $_migration_stages = array();
34
-
35
-    /**
36
-     * Indicates we've already ran the schema changes that needed to happen BEFORE the data migration
37
-     *
38
-     * @var boolean
39
-     */
40
-    protected $_schema_changes_before_migration_ran = null;
41
-
42
-    /**
43
-     * Indicates we've already ran the schema changes that needed to happen AFTER the data migration
44
-     *
45
-     * @var boolean
46
-     */
47
-    protected $_schema_changes_after_migration_ran = null;
48
-
49
-    /**
50
-     * String which describes what's currently happening in this migration
51
-     *
52
-     * @var string
53
-     */
54
-    protected $_feedback_message;
55
-
56
-    /**
57
-     * Indicates the script's priority. Like wp's add_action and add_filter, lower numbers
58
-     * correspond to earlier execution
59
-     *
60
-     * @var int
61
-     */
62
-    protected $_priority = 5;
63
-
64
-    /**
65
-     * Multi-dimensional array that defines the mapping from OLD table Primary Keys
66
-     * to NEW table Primary Keys.
67
-     * Top-level array keys are OLD table names (minus the "wp_" part),
68
-     * 2nd-level array keys are NEW table names (again, minus the "wp_" part),
69
-     * 3rd-level array keys are the OLD table primary keys
70
-     * and 3rd-level array values are the NEW table primary keys
71
-     *
72
-     * @var array
73
-     */
74
-    protected $_mappings = array();
75
-
76
-    /**
77
-     * @var EE_Data_Migration_Script_Base
78
-     */
79
-    protected $previous_dms;
80
-
81
-
82
-    /**
83
-     * Returns whether or not this data migration script can operate on the given version of the database.
84
-     * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and
85
-     * it's passed a string like '3.1.38B', it should return true.
86
-     * If this DMS is to migrate data from an EE3 addon, you will probably want to use
87
-     * EventEspresso\core\services\database\TableAnalysis::tableExists() to check for old EE3 tables, and
88
-     * EE_Data_Migration_Manager::get_migration_ran() to check that core was already
89
-     * migrated from EE3 to EE4 (ie, this DMS probably relies on some migration data generated
90
-     * during the Core 4.1.0 DMS. If core didn't run that DMS, you probably don't want
91
-     * to run this DMS).
92
-     * If this DMS migrates data from a previous version of this EE4 addon, just
93
-     * comparing $current_database_state_of[ $this->slug() ] will probably suffice.
94
-     * If this DMS should never migrate data, because it's only used to define the initial
95
-     * database state, just return FALSE (and core's activation process will take care
96
-     * of calling its schema_changes_before_migration() and
97
-     * schema_changes_after_migration() for you. )
98
-     *
99
-     * @param array $current_database_state_of keys are EE plugin slugs (eg 'Core', 'Calendar', 'Mailchimp', etc)
100
-     * @return boolean
101
-     */
102
-    abstract public function can_migrate_from_version($current_database_state_of);
103
-
104
-
105
-    /**
106
-     * Performs database schema changes that need to occur BEFORE the data is migrated.
107
-     * Eg, if we were going to change user passwords from plaintext to encoded versions
108
-     * during this migration, this would probably add a new column called something like
109
-     * "encoded_password".
110
-     *
111
-     * @return boolean of success
112
-     */
113
-    abstract public function schema_changes_before_migration();
114
-
115
-
116
-    /**
117
-     * Performs the database schema changes that need to occur AFTER the data has been migrated.
118
-     * Usually this will mean we'll be removing old columns. Eg, if we were changing passwords
119
-     * from plaintext to encoded versions, and we had added a column called "encoded_password",
120
-     * this function would probably remove the old column "password" (which still holds the plaintext password)
121
-     * and possibly rename "encoded_password" to "password"
122
-     *
123
-     * @return boolean of success
124
-     */
125
-    abstract public function schema_changes_after_migration();
126
-
127
-
128
-    /**
129
-     * All children of this must call parent::__construct()
130
-     * at the end of their constructor or suffer the consequences!
131
-     *
132
-     * @param TableManager  $table_manager
133
-     * @param TableAnalysis $table_analysis
134
-     */
135
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
136
-    {
137
-        $this->_migration_stages = (array) apply_filters(
138
-            'FHEE__' . get_class($this) . '__construct__migration_stages',
139
-            $this->_migration_stages
140
-        );
141
-        foreach ($this->_migration_stages as $migration_stage) {
142
-            if ($migration_stage instanceof EE_Data_Migration_Script_Stage) {
143
-                $migration_stage->_construct_finalize($this);
144
-            }
145
-        }
146
-        parent::__construct($table_manager, $table_analysis);
147
-    }
148
-
149
-
150
-    /**
151
-     * Place to add hooks and filters for tweaking the migrations page, in order
152
-     * to customize it
153
-     */
154
-    public function migration_page_hooks()
155
-    {
156
-        // by default none are added because we normally like the default look of the migration page
157
-    }
158
-
159
-
160
-    /**
161
-     * Sets the mapping from old table primary keys to new table primary keys.
162
-     * This mapping is automatically persisted as a property on the migration
163
-     *
164
-     * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
165
-     * @param int|string $old_pk    old primary key. Eg events_detail.id's value
166
-     * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
167
-     * @param int|string $new_pk    eg posts.ID
168
-     * @return void
169
-     */
170
-    public function set_mapping($old_table, $old_pk, $new_table, $new_pk)
171
-    {
172
-        // make sure it has the needed keys
173
-        if (! isset($this->_mappings[ $old_table ]) || ! isset($this->_mappings[ $old_table ][ $new_table ])) {
174
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
175
-        }
176
-        $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] = $new_pk;
177
-    }
178
-
179
-
180
-    /**
181
-     * Gets the new primary key, if provided with the OLD table and the primary key
182
-     * of an item in the old table, and the new table
183
-     *
184
-     * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
185
-     * @param int|string $old_pk    old primary key. Eg events_detail.id's value
186
-     * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
187
-     * @return mixed the primary key on the new table
188
-     */
189
-    public function get_mapping_new_pk($old_table, $old_pk, $new_table)
190
-    {
191
-        if (! isset($this->_mappings[ $old_table ]) ||
192
-            ! isset($this->_mappings[ $old_table ][ $new_table ])) {
193
-            // try fetching the option
194
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
195
-        }
196
-        return isset($this->_mappings[ $old_table ][ $new_table ][ $old_pk ])
197
-            ? $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] : null;
198
-    }
199
-
200
-
201
-    /**
202
-     * Gets the old primary key, if provided with the OLD table,
203
-     * and the new table and the primary key of an item in the new table
204
-     *
205
-     * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail
206
-     * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts
207
-     * @param mixed  $new_pk
208
-     * @return mixed
209
-     */
210
-    public function get_mapping_old_pk($old_table, $new_table, $new_pk)
211
-    {
212
-        if (! isset($this->_mappings[ $old_table ]) ||
213
-            ! isset($this->_mappings[ $old_table ][ $new_table ])) {
214
-            // try fetching the option
215
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
216
-        }
217
-        if (isset($this->_mappings[ $old_table ][ $new_table ])) {
218
-            $new_pk_to_old_pk = array_flip($this->_mappings[ $old_table ][ $new_table ]);
219
-            if (isset($new_pk_to_old_pk[ $new_pk ])) {
220
-                return $new_pk_to_old_pk[ $new_pk ];
221
-            }
222
-        }
223
-        return null;
224
-    }
225
-
226
-
227
-    /**
228
-     * Gets the mapping array option specified by the table names
229
-     *
230
-     * @param string $old_table_name
231
-     * @param string $new_table_name
232
-     * @return array
233
-     */
234
-    protected function _get_mapping_option($old_table_name, $new_table_name)
235
-    {
236
-        $option = get_option($this->_get_mapping_option_name($old_table_name, $new_table_name), array());
237
-        return $option;
238
-    }
239
-
240
-
241
-    /**
242
-     * Updates the mapping option specified by the table names with the array provided
243
-     *
244
-     * @param string $old_table_name
245
-     * @param string $new_table_name
246
-     * @param array  $mapping_array
247
-     * @return boolean success of updating option
248
-     */
249
-    protected function _set_mapping_option($old_table_name, $new_table_name, $mapping_array)
250
-    {
251
-        $success = update_option($this->_get_mapping_option_name($old_table_name, $new_table_name), $mapping_array);
252
-        return $success;
253
-    }
254
-
255
-
256
-    /**
257
-     * Gets the option name for this script to map from $old_table_name to $new_table_name
258
-     *
259
-     * @param string $old_table_name
260
-     * @param string $new_table_name
261
-     * @return string
262
-     */
263
-    protected function _get_mapping_option_name($old_table_name, $new_table_name)
264
-    {
265
-        global $wpdb;
266
-        $old_table_name_sans_wp = str_replace($wpdb->prefix, "", $old_table_name);
267
-        $new_table_name_sans_wp = str_replace($wpdb->prefix, "", $new_table_name);
268
-        $migrates_to = EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
269
-        return substr(
270
-            EE_Data_Migration_Manager::data_migration_script_mapping_option_prefix . $migrates_to ['slug'] . '_' . $migrates_to['version'] . '_' . $old_table_name_sans_wp . '_' . $new_table_name_sans_wp,
271
-            0,
272
-            64
273
-        );
274
-    }
275
-
276
-
277
-    /**
278
-     * Counts all the records that will be migrated during this data migration.
279
-     * For example, if we were changing old user passwords from plaintext to encoded versions,
280
-     * this would be a count of all users who have passwords. If we were going to also split
281
-     * attendee records into transactions, registrations, and attendee records, this would include
282
-     * the count of all attendees currently in existence in the DB (ie, users + attendees).
283
-     * If you can't determine how many records there are to migrate, just provide a guess: this
284
-     * number will only be used in calculating the percent complete. If you estimate there to be
285
-     * 100 records to migrate, and it turns out there's 120, we'll just show the migration as being at
286
-     * 99% until the function "migration_step" returns EE_Data_Migration_Script_Base::status_complete.
287
-     *
288
-     * @return int
289
-     */
290
-    protected function _count_records_to_migrate()
291
-    {
292
-        $count = 0;
293
-        foreach ($this->stages() as $stage) {
294
-            $count += $stage->count_records_to_migrate();
295
-        }
296
-        return $count;
297
-    }
298
-
299
-
300
-    /**
301
-     * Returns the number of records updated so far. Usually this is easiest to do
302
-     * by just setting a transient and updating it after each migration_step
303
-     *
304
-     * @return int
305
-     */
306
-    public function count_records_migrated()
307
-    {
308
-        $count = 0;
309
-        foreach ($this->stages() as $stage) {
310
-            $count += $stage->count_records_migrated();
311
-        }
312
-        $this->_records_migrated = $count;
313
-        return $count;
314
-    }
315
-
316
-
317
-    /**
318
-     * @param int $num_records_to_migrate_limit
319
-     * @return int
320
-     * @throws EE_Error
321
-     * @throws Exception
322
-     */
323
-    public function migration_step($num_records_to_migrate_limit)
324
-    {
325
-        // reset the feedback message
326
-        $this->_feedback_message = '';
327
-        // if we haven't yet done the 1st schema changes, do them now. buffer any output
328
-        $this->_maybe_do_schema_changes(true);
329
-
330
-        $num_records_actually_migrated = 0;
331
-        $records_migrated_per_stage = array();
332
-        // setup the 'stage' variable, which should hold the last run stage of the migration  (or none at all if nothing runs)
333
-        $stage = null;
334
-        // get the next stage that isn't complete
335
-        foreach ($this->stages() as $stage) {
336
-            if ($stage->get_status() == EE_Data_Migration_Manager::status_continue) {
337
-                try {
338
-                    $records_migrated_during_stage = $stage->migration_step(
339
-                        $num_records_to_migrate_limit - $num_records_actually_migrated
340
-                    );
341
-                    $num_records_actually_migrated += $records_migrated_during_stage;
342
-                    $records_migrated_per_stage[ $stage->pretty_name() ] = $records_migrated_during_stage;
343
-                } catch (Exception $e) {
344
-                    // yes if we catch an exception here, we consider that migration stage borked.
345
-                    $stage->set_status(EE_Data_Migration_Manager::status_fatal_error);
346
-                    $this->set_status(EE_Data_Migration_Manager::status_fatal_error);
347
-                    $stage->add_error($e->getMessage() . ". Stack-trace:" . $e->getTraceAsString());
348
-                    throw $e;
349
-                }
350
-                // check that the migration stage didn't mark itself as having a fatal error
351
-                if ($stage->is_broken()) {
352
-                    $this->set_broken();
353
-                    throw new EE_Error($stage->get_last_error());
354
-                }
355
-            }
356
-            // once we've migrated all the number we intended to (possibly from different stages), stop migrating
357
-            // or if we had a fatal error
358
-            // or if the current script stopped early- its not done, but it's done all it thinks we should do on this step
359
-            if ($num_records_actually_migrated >= $num_records_to_migrate_limit
360
-                || $stage->is_broken()
361
-                || $stage->has_more_to_do()
362
-            ) {
363
-                break;
364
-            }
365
-        }
366
-        // check if we're all done this data migration...
367
-        // which is indicated by being done early AND the last stage claims to be done
368
-        if ($stage == null) {
369
-            // this migration script apparently has NO stages... which is super weird, but whatever
370
-            $this->set_completed();
371
-            $this->_maybe_do_schema_changes(false);
372
-        } elseif ($num_records_actually_migrated < $num_records_to_migrate_limit && ! $stage->has_more_to_do()) {
373
-            // apparently we're done, because we couldn't migrate the number we intended to
374
-            $this->set_completed();
375
-            $this->_update_feedback_message(array_reverse($records_migrated_per_stage));
376
-            // do schema changes for after the migration now
377
-            // first double-check we haven't already done this
378
-            $this->_maybe_do_schema_changes(false);
379
-        } else {
380
-            // update feedback message, keeping in mind that we show them with the most recent at the top
381
-            $this->_update_feedback_message(array_reverse($records_migrated_per_stage));
382
-        }
383
-        return $num_records_actually_migrated;
384
-    }
385
-
386
-
387
-    /**
388
-     * Updates the feedback message according to what was done during this migration stage.
389
-     *
390
-     * @param array $records_migrated_per_stage KEYS are pretty names for each stage; values are the count of records
391
-     *                                          migrated from that stage
392
-     * @return void
393
-     */
394
-    private function _update_feedback_message($records_migrated_per_stage)
395
-    {
396
-        $feedback_message_array = array();
397
-        foreach ($records_migrated_per_stage as $migration_stage_name => $num_records_migrated) {
398
-            $feedback_message_array[] = sprintf(
399
-                __("Migrated %d records successfully during %s", "event_espresso"),
400
-                $num_records_migrated,
401
-                $migration_stage_name
402
-            );
403
-        }
404
-        $this->_feedback_message .= implode("<br>", $feedback_message_array);
405
-    }
406
-
407
-
408
-    /**
409
-     * Calls either schema_changes_before_migration() (if $before==true) or schema_changes_after_migration
410
-     * (if $before==false). Buffers their outputs and stores them on the class.
411
-     *
412
-     * @param boolean $before
413
-     * @throws Exception
414
-     * @return void
415
-     */
416
-    private function _maybe_do_schema_changes($before = true)
417
-    {
418
-        // so this property will be either _schema_changes_after_migration_ran or _schema_changes_before_migration_ran
419
-        $property_name = '_schema_changes_' . ($before ? 'before' : 'after') . '_migration_ran';
420
-        if (! $this->{$property_name}) {
421
-            try {
422
-                ob_start();
423
-                if ($before) {
424
-                    $this->schema_changes_before_migration();
425
-                } else {
426
-                    $this->schema_changes_after_migration();
427
-                }
428
-                $output = ob_get_contents();
429
-                ob_end_clean();
430
-            } catch (Exception $e) {
431
-                $this->set_status(EE_Data_Migration_Manager::status_fatal_error);
432
-                throw $e;
433
-            }
434
-            // record that we've done these schema changes
435
-            $this->{$property_name} = true;
436
-            // if there were any warnings etc, record them as non-fatal errors
437
-            if ($output) {
438
-                // there were some warnings
439
-                $this->_errors[] = $output;
440
-            }
441
-        }
442
-    }
443
-
444
-
445
-    /**
446
-     * Wrapper for EEH_Activation::create_table. However, takes into account the request type when
447
-     * deciding what to pass for its 4th arg, $drop_pre_existing_tables. Using this function, instead
448
-     * of _table_should_exist_previously, indicates that this table should be new to the EE version being migrated to
449
-     * or
450
-     * activated currently. If this is a brand new activation or a migration, and we're indicating this table should
451
-     * not
452
-     * previously exist, then we want to set $drop_pre_existing_tables to TRUE (ie, we shouldn't discover that this
453
-     * table exists in the DB in EEH_Activation::create_table- if it DOES exist, something's wrong and the old table
454
-     * should be nuked.
455
-     *
456
-     * Just for a bit of context, the migration script's db_schema_changes_* methods
457
-     * are called basically in 3 cases: on brand new activation of EE4 (ie no previous version of EE existed and the
458
-     * plugin is being activated and we want to add all the brand new tables), upon reactivation of EE4 (it was
459
-     * deactivated and then reactivated, in which case we want to just verify the DB structure is ok) that table should
460
-     * be dropped), and during a migration when we're moving the DB to the state of the migration script
461
-     *
462
-     * @param string $table_name
463
-     * @param string $table_definition_sql
464
-     * @param string $engine_string
465
-     */
466
-    protected function _table_is_new_in_this_version(
467
-        $table_name,
468
-        $table_definition_sql,
469
-        $engine_string = 'ENGINE=InnoDB '
470
-    ) {
471
-        $this->_create_table_and_catch_errors(
472
-            $table_name,
473
-            $table_definition_sql,
474
-            $engine_string,
475
-            $this->_pre_existing_table_should_be_dropped(true)
476
-        );
477
-    }
478
-
479
-    /**
480
-     * Like _table_is_new_in_this_version and _table_should_exist_previously, this function verifies the given table
481
-     * exists. But we understand that this table has CHANGED in this version since the previous version. So it's not
482
-     * completely new, but it's different. So we need to treat it like a new table in terms of verifying it's schema is
483
-     * correct on activations, migrations, upgrades; but if it exists when it shouldn't, we need to be as lenient as
484
-     * _table_should_exist_previously.
485
-     * 8656]{Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the
486
-     * table shouldn't exist).
487
-     *
488
-     * @param string $table_name
489
-     * @param string $table_definition_sql
490
-     * @param string $engine_string
491
-     */
492
-    protected function _table_is_changed_in_this_version(
493
-        $table_name,
494
-        $table_definition_sql,
495
-        $engine_string = 'ENGINE=MyISAM'
496
-    ) {
497
-        $this->_create_table_and_catch_errors(
498
-            $table_name,
499
-            $table_definition_sql,
500
-            $engine_string,
501
-            $this->_pre_existing_table_should_be_dropped(false)
502
-        );
503
-    }
504
-
505
-
506
-    /**
507
-     * _old_table_exists
508
-     * returns TRUE if the requested table exists in the current database
509
-     *
510
-     * @param string $table_name
511
-     * @return boolean
512
-     */
513
-    protected function _old_table_exists($table_name)
514
-    {
515
-        return $this->_get_table_analysis()->tableExists($table_name);
516
-    }
517
-
518
-
519
-    /**
520
-     * _delete_table_if_empty
521
-     * returns TRUE if the requested table was empty and successfully empty
522
-     *
523
-     * @param string $table_name
524
-     * @return boolean
525
-     */
526
-    protected function _delete_table_if_empty($table_name)
527
-    {
528
-        return EEH_Activation::delete_db_table_if_empty($table_name);
529
-    }
530
-
531
-
532
-    /**
533
-     * It is preferred to use _table_has_not_changed_since_previous or _table_is_changed_in_this_version
534
-     * as these are significantly more efficient or explicit.
535
-     * Please see description of _table_is_new_in_this_version. This function will only set
536
-     * EEH_Activation::create_table's $drop_pre_existing_tables to TRUE if it's a brand
537
-     * new activation. ie, a more accurate name for this method would be "_table_added_previously_by_this_plugin"
538
-     * because the table will be cleared out if this is a new activation (ie, if its a new activation, it actually
539
-     * should exist previously). Otherwise, we'll always set $drop_pre_existing_tables to FALSE because the table
540
-     * should have existed. Note, if the table is being MODIFIED in this version being activated or migrated to, then
541
-     * you want _table_is_changed_in_this_version NOT this one. We don't check this table's structure during migrations
542
-     * because apparently it hasn't changed since the previous one, right?
543
-     *
544
-     * @param string $table_name
545
-     * @param string $table_definition_sql
546
-     * @param string $engine_string
547
-     */
548
-    protected function _table_should_exist_previously(
549
-        $table_name,
550
-        $table_definition_sql,
551
-        $engine_string = 'ENGINE=MyISAM'
552
-    ) {
553
-        $this->_create_table_and_catch_errors(
554
-            $table_name,
555
-            $table_definition_sql,
556
-            $engine_string,
557
-            $this->_pre_existing_table_should_be_dropped(false)
558
-        );
559
-    }
560
-
561
-    /**
562
-     * Exactly the same as _table_should_exist_previously(), except if this migration script is currently doing
563
-     * a migration, we skip checking this table's structure in the database and just assume it's correct.
564
-     * So this is useful only to improve efficiency when doing migrations (not a big deal for single site installs,
565
-     * but important for multisite where migrations can take a very long time otherwise).
566
-     * If the table is known to have changed since previous version, use _table_is_changed_in_this_version().
567
-     * Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the table
568
-     * shouldn't exist).
569
-     *
570
-     * @param string $table_name
571
-     * @param string $table_definition_sql
572
-     * @param string $engine_string
573
-     */
574
-    protected function _table_has_not_changed_since_previous(
575
-        $table_name,
576
-        $table_definition_sql,
577
-        $engine_string = 'ENGINE=MyISAM'
578
-    ) {
579
-        if ($this->_currently_migrating()) {
580
-            // if we're doing a migration, and this table apparently already exists, then we don't need do anything right?
581
-            return;
582
-        }
583
-        $this->_create_table_and_catch_errors(
584
-            $table_name,
585
-            $table_definition_sql,
586
-            $engine_string,
587
-            $this->_pre_existing_table_should_be_dropped(false)
588
-        );
589
-    }
590
-
591
-    /**
592
-     * Returns whether or not this migration script is being used as part of an actual migration
593
-     *
594
-     * @return boolean
595
-     */
596
-    protected function _currently_migrating()
597
-    {
598
-        // we want to know if we are currently performing a migration. We could just believe what was set on the _migrating property, but let's double-check (ie the script should apply and we should be in MM)
599
-        return $this->_migrating &&
600
-               $this->can_migrate_from_version(
601
-                   EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set()
602
-               ) &&
603
-               EE_Maintenance_Mode::instance()->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance;
604
-    }
605
-
606
-    /**
607
-     * Determines if a table should be dropped, based on whether it's reported to be new in $table_is_new,
608
-     * and the plugin's request type.
609
-     * Assumes only this plugin could have added the table (ie, if its a new activation of this plugin, the table
610
-     * shouldn't exist no matter what).
611
-     *
612
-     * @param boolean $table_is_new
613
-     * @return boolean
614
-     */
615
-    protected function _pre_existing_table_should_be_dropped($table_is_new)
616
-    {
617
-        if ($table_is_new) {
618
-            if ($this->_get_req_type_for_plugin_corresponding_to_this_dms() == EE_System::req_type_new_activation
619
-                || $this->_currently_migrating()
620
-            ) {
621
-                return true;
622
-            } else {
623
-                return false;
624
-            }
625
-        } else {
626
-            if (in_array(
627
-                $this->_get_req_type_for_plugin_corresponding_to_this_dms(),
628
-                array(EE_System::req_type_new_activation)
629
-            )) {
630
-                return true;
631
-            } else {
632
-                return false;
633
-            }
634
-        }
635
-    }
636
-
637
-    /**
638
-     * Just wraps EEH_Activation::create_table, but catches any errors it may throw and adds them as errors on the DMS
639
-     *
640
-     * @param string  $table_name
641
-     * @param string  $table_definition_sql
642
-     * @param string  $engine_string
643
-     * @param boolean $drop_pre_existing_tables
644
-     */
645
-    private function _create_table_and_catch_errors(
646
-        $table_name,
647
-        $table_definition_sql,
648
-        $engine_string = 'ENGINE=MyISAM',
649
-        $drop_pre_existing_tables = false
650
-    ) {
651
-        try {
652
-            EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables);
653
-        } catch (EE_Error $e) {
654
-            $message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString();
655
-            $this->add_error($message);
656
-            $this->_feedback_message .= $message;
657
-        }
658
-    }
659
-
660
-
661
-    /**
662
-     * Gets the request type for the plugin (core or addon) that corresponds to this DMS
663
-     *
664
-     * @return int one of EE_System::_req_type_* constants
665
-     * @throws EE_Error
666
-     */
667
-    private function _get_req_type_for_plugin_corresponding_to_this_dms()
668
-    {
669
-        if ($this->slug() == 'Core') {
670
-            return EE_System::instance()->detect_req_type();
671
-        } else {// it must be for an addon
672
-            $addon_name = $this->slug();
673
-            if (EE_Registry::instance()->get_addon_by_name($addon_name)) {
674
-                return EE_Registry::instance()->get_addon_by_name($addon_name)->detect_req_type();
675
-            } else {
676
-                throw new EE_Error(
677
-                    sprintf(
678
-                        __(
679
-                            "The DMS slug '%s' should correspond to the addon's name, which should also be '%s', but no such addon was registered. These are the registered addons' names: %s",
680
-                            "event_espresso"
681
-                        ),
682
-                        $this->slug(),
683
-                        $addon_name,
684
-                        implode(",", array_keys(EE_Registry::instance()->get_addons_by_name()))
685
-                    )
686
-                );
687
-            }
688
-        }
689
-    }
690
-
691
-
692
-    /**
693
-     * returns an array of strings describing errors by all the script's stages
694
-     *
695
-     * @return array
696
-     */
697
-    public function get_errors()
698
-    {
699
-        $all_errors = $this->_errors;
700
-        if (! is_array($all_errors)) {
701
-            $all_errors = array();
702
-        }
703
-        foreach ($this->stages() as $stage) {
704
-            $all_errors = array_merge($stage->get_errors(), $all_errors);
705
-        }
706
-        return $all_errors;
707
-    }
708
-
709
-
710
-    /**
711
-     * Indicates whether or not this migration script should continue
712
-     *
713
-     * @return boolean
714
-     */
715
-    public function can_continue()
716
-    {
717
-        return in_array(
718
-            $this->get_status(),
719
-            EE_Data_Migration_Manager::instance()->stati_that_indicate_to_continue_single_migration_script
720
-        );
721
-    }
722
-
723
-
724
-    /**
725
-     * Gets all the data migration stages associated with this script. Note:
726
-     * addons can filter this list to add their own stages, and because the list is
727
-     * numerically-indexed, they can insert their stage wherever they like and it will
728
-     * get ordered by the indexes
729
-     *
730
-     * @return EE_Data_Migration_Script_Stage[]
731
-     */
732
-    protected function stages()
733
-    {
734
-        $stages = apply_filters('FHEE__' . get_class($this) . '__stages', $this->_migration_stages);
735
-        ksort($stages);
736
-        return $stages;
737
-    }
738
-
739
-
740
-    /**
741
-     * Gets a string which should describe what's going on currently with this migration, which
742
-     * can be displayed to the user
743
-     *
744
-     * @return string
745
-     */
746
-    public function get_feedback_message()
747
-    {
748
-        return $this->_feedback_message;
749
-    }
750
-
751
-
752
-    /**
753
-     * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
754
-     * properties to the DB. However, we don't want to use __sleep() because its quite
755
-     * possible that this class is defined when it goes to sleep, but NOT available when it
756
-     * awakes (eg, this class is part of an addon that is deactivated at some point).
757
-     */
758
-    public function properties_as_array()
759
-    {
760
-        $properties = parent::properties_as_array();
761
-        $properties['_migration_stages'] = array();
762
-        foreach ($this->_migration_stages as $migration_stage_priority => $migration_stage_class) {
763
-            $properties['_migration_stages'][ $migration_stage_priority ] = $migration_stage_class->properties_as_array(
764
-            );
765
-        }
766
-        unset($properties['_mappings']);
767
-        unset($properties['previous_dms']);
768
-
769
-        foreach ($this->_mappings as $old_table_name => $mapping_to_new_table) {
770
-            foreach ($mapping_to_new_table as $new_table_name => $mapping) {
771
-                $this->_set_mapping_option($old_table_name, $new_table_name, $mapping);
772
-            }
773
-        }
774
-        return $properties;
775
-    }
776
-
777
-
778
-    /**
779
-     * Sets all of the properties of this script stage to match what's in the array, which is assumed
780
-     * to have been made from the properties_as_array() function.
781
-     *
782
-     * @param array $array_of_properties like what's produced from properties_as_array() method
783
-     * @return void
784
-     */
785
-    public function instantiate_from_array_of_properties($array_of_properties)
786
-    {
787
-        $stages_properties_arrays = $array_of_properties['_migration_stages'];
788
-        unset($array_of_properties['_migration_stages']);
789
-        unset($array_of_properties['class']);
790
-        foreach ($array_of_properties as $property_name => $property_value) {
791
-            $this->{$property_name} = $property_value;
792
-        }
793
-        // _migration_stages are already instantiated, but have only default data
794
-        foreach ($this->_migration_stages as $stage) {
795
-            $stage_data = $this->_find_migration_stage_data_with_classname(
796
-                get_class($stage),
797
-                $stages_properties_arrays
798
-            );
799
-            // SO, if we found the stage data that was saved, use it. Otherwise, I guess the stage is new? (maybe added by
800
-            // an addon? Unlikely... not sure why it wouldn't exist, but if it doesn't just treat it like it was never started yet)
801
-            if ($stage_data) {
802
-                $stage->instantiate_from_array_of_properties($stage_data);
803
-            }
804
-        }
805
-    }
806
-
807
-
808
-    /**
809
-     * Gets the migration data from the array $migration_stage_data_arrays (which is an array of arrays, each of which
810
-     * is pretty well identical to EE_Data_Migration_Stage objects except all their properties are array indexes)
811
-     * for the given classname
812
-     *
813
-     * @param string $classname
814
-     * @param array  $migration_stage_data_arrays
815
-     * @return null
816
-     */
817
-    private function _find_migration_stage_data_with_classname($classname, $migration_stage_data_arrays)
818
-    {
819
-        foreach ($migration_stage_data_arrays as $migration_stage_data_array) {
820
-            if (isset($migration_stage_data_array['class']) && $migration_stage_data_array['class'] == $classname) {
821
-                return $migration_stage_data_array;
822
-            }
823
-        }
824
-        return null;
825
-    }
826
-
827
-
828
-    /**
829
-     * Returns the version that this script migrates to, based on the script's name.
830
-     * Cannot be overwritten because lots of code needs to know which version a script
831
-     * migrates to knowing only its name.
832
-     *
833
-     * @return array where the first key is the plugin's slug, the 2nd is the version of that plugin
834
-     * that will be updated to. Eg array('Core','4.1.0')
835
-     */
836
-    final public function migrates_to_version()
837
-    {
838
-        return EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
839
-    }
840
-
841
-
842
-    /**
843
-     * Gets this addon's slug as it would appear in the current_db_state wp option,
844
-     * and if this migration script is for an addon, it SHOULD match the addon's slug
845
-     * (and also the addon's classname, minus the 'EE_' prefix.). Eg, 'Calendar' for the EE_Calendar addon.
846
-     * Or 'Core' for core (non-addon).
847
-     *
848
-     * @return string
849
-     */
850
-    public function slug()
851
-    {
852
-        $migrates_to_version_info = $this->migrates_to_version();
853
-        // the slug is the first part of the array
854
-        return $migrates_to_version_info['slug'];
855
-    }
856
-
857
-
858
-    /**
859
-     * Returns the script's priority relative to DMSs from other addons. However, when
860
-     * two DMSs from the same addon/core apply, this is ignored (and instead the version that
861
-     * the script migrates to is used to determine which to run first). The default is 5, but all core DMSs
862
-     * normally have priority 10. (So if you want a DMS "A" to run before DMS "B", both of which are from addons,
863
-     * and both of which CAN run at the same time (ie, "B" doesn't depend on "A" to set
864
-     * the database up so it can run), then you can set "A" to priority 3 or something.
865
-     *
866
-     * @return int
867
-     */
868
-    public function priority()
869
-    {
870
-        return $this->_priority;
871
-    }
872
-
873
-
874
-    /**
875
-     * Sets whether or not this DMS is being ran as part of a migration, instead of
876
-     * just being used to setup (or verify) the current database structure matches
877
-     * what the latest DMS indicates it should be
878
-     *
879
-     * @param boolean $migrating
880
-     * @return void
881
-     */
882
-    public function set_migrating($migrating = true)
883
-    {
884
-        $this->_migrating = $migrating;
885
-    }
886
-
887
-    /**
888
-     * Marks that we think this migration class can continue to migrate
889
-     */
890
-    public function reattempt()
891
-    {
892
-        parent::reattempt();
893
-        // also, we want to reattempt any stages that were marked as borked
894
-        foreach ($this->stages() as $stage) {
895
-            if ($stage->is_broken()) {
896
-                $stage->reattempt();
897
-            }
898
-        }
899
-    }
18
+	/**
19
+	 * Set by client code to indicate this DMS is being ran as part of a proper migration,
20
+	 * instead of being used to merely setup (or verify) the database structure.
21
+	 * Defaults to TRUE, so client code that's NOT using this DMS as part of a proper migration
22
+	 * should call EE_Data_Migration_Script_Base::set_migrating( FALSE )
23
+	 *
24
+	 * @var boolean
25
+	 */
26
+	protected $_migrating = true;
27
+
28
+	/**
29
+	 * numerically-indexed array where each value is EE_Data_Migration_Script_Stage object
30
+	 *
31
+	 * @var EE_Data_Migration_Script_Stage[] $migration_functions
32
+	 */
33
+	protected $_migration_stages = array();
34
+
35
+	/**
36
+	 * Indicates we've already ran the schema changes that needed to happen BEFORE the data migration
37
+	 *
38
+	 * @var boolean
39
+	 */
40
+	protected $_schema_changes_before_migration_ran = null;
41
+
42
+	/**
43
+	 * Indicates we've already ran the schema changes that needed to happen AFTER the data migration
44
+	 *
45
+	 * @var boolean
46
+	 */
47
+	protected $_schema_changes_after_migration_ran = null;
48
+
49
+	/**
50
+	 * String which describes what's currently happening in this migration
51
+	 *
52
+	 * @var string
53
+	 */
54
+	protected $_feedback_message;
55
+
56
+	/**
57
+	 * Indicates the script's priority. Like wp's add_action and add_filter, lower numbers
58
+	 * correspond to earlier execution
59
+	 *
60
+	 * @var int
61
+	 */
62
+	protected $_priority = 5;
63
+
64
+	/**
65
+	 * Multi-dimensional array that defines the mapping from OLD table Primary Keys
66
+	 * to NEW table Primary Keys.
67
+	 * Top-level array keys are OLD table names (minus the "wp_" part),
68
+	 * 2nd-level array keys are NEW table names (again, minus the "wp_" part),
69
+	 * 3rd-level array keys are the OLD table primary keys
70
+	 * and 3rd-level array values are the NEW table primary keys
71
+	 *
72
+	 * @var array
73
+	 */
74
+	protected $_mappings = array();
75
+
76
+	/**
77
+	 * @var EE_Data_Migration_Script_Base
78
+	 */
79
+	protected $previous_dms;
80
+
81
+
82
+	/**
83
+	 * Returns whether or not this data migration script can operate on the given version of the database.
84
+	 * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and
85
+	 * it's passed a string like '3.1.38B', it should return true.
86
+	 * If this DMS is to migrate data from an EE3 addon, you will probably want to use
87
+	 * EventEspresso\core\services\database\TableAnalysis::tableExists() to check for old EE3 tables, and
88
+	 * EE_Data_Migration_Manager::get_migration_ran() to check that core was already
89
+	 * migrated from EE3 to EE4 (ie, this DMS probably relies on some migration data generated
90
+	 * during the Core 4.1.0 DMS. If core didn't run that DMS, you probably don't want
91
+	 * to run this DMS).
92
+	 * If this DMS migrates data from a previous version of this EE4 addon, just
93
+	 * comparing $current_database_state_of[ $this->slug() ] will probably suffice.
94
+	 * If this DMS should never migrate data, because it's only used to define the initial
95
+	 * database state, just return FALSE (and core's activation process will take care
96
+	 * of calling its schema_changes_before_migration() and
97
+	 * schema_changes_after_migration() for you. )
98
+	 *
99
+	 * @param array $current_database_state_of keys are EE plugin slugs (eg 'Core', 'Calendar', 'Mailchimp', etc)
100
+	 * @return boolean
101
+	 */
102
+	abstract public function can_migrate_from_version($current_database_state_of);
103
+
104
+
105
+	/**
106
+	 * Performs database schema changes that need to occur BEFORE the data is migrated.
107
+	 * Eg, if we were going to change user passwords from plaintext to encoded versions
108
+	 * during this migration, this would probably add a new column called something like
109
+	 * "encoded_password".
110
+	 *
111
+	 * @return boolean of success
112
+	 */
113
+	abstract public function schema_changes_before_migration();
114
+
115
+
116
+	/**
117
+	 * Performs the database schema changes that need to occur AFTER the data has been migrated.
118
+	 * Usually this will mean we'll be removing old columns. Eg, if we were changing passwords
119
+	 * from plaintext to encoded versions, and we had added a column called "encoded_password",
120
+	 * this function would probably remove the old column "password" (which still holds the plaintext password)
121
+	 * and possibly rename "encoded_password" to "password"
122
+	 *
123
+	 * @return boolean of success
124
+	 */
125
+	abstract public function schema_changes_after_migration();
126
+
127
+
128
+	/**
129
+	 * All children of this must call parent::__construct()
130
+	 * at the end of their constructor or suffer the consequences!
131
+	 *
132
+	 * @param TableManager  $table_manager
133
+	 * @param TableAnalysis $table_analysis
134
+	 */
135
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
136
+	{
137
+		$this->_migration_stages = (array) apply_filters(
138
+			'FHEE__' . get_class($this) . '__construct__migration_stages',
139
+			$this->_migration_stages
140
+		);
141
+		foreach ($this->_migration_stages as $migration_stage) {
142
+			if ($migration_stage instanceof EE_Data_Migration_Script_Stage) {
143
+				$migration_stage->_construct_finalize($this);
144
+			}
145
+		}
146
+		parent::__construct($table_manager, $table_analysis);
147
+	}
148
+
149
+
150
+	/**
151
+	 * Place to add hooks and filters for tweaking the migrations page, in order
152
+	 * to customize it
153
+	 */
154
+	public function migration_page_hooks()
155
+	{
156
+		// by default none are added because we normally like the default look of the migration page
157
+	}
158
+
159
+
160
+	/**
161
+	 * Sets the mapping from old table primary keys to new table primary keys.
162
+	 * This mapping is automatically persisted as a property on the migration
163
+	 *
164
+	 * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
165
+	 * @param int|string $old_pk    old primary key. Eg events_detail.id's value
166
+	 * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
167
+	 * @param int|string $new_pk    eg posts.ID
168
+	 * @return void
169
+	 */
170
+	public function set_mapping($old_table, $old_pk, $new_table, $new_pk)
171
+	{
172
+		// make sure it has the needed keys
173
+		if (! isset($this->_mappings[ $old_table ]) || ! isset($this->_mappings[ $old_table ][ $new_table ])) {
174
+			$this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
175
+		}
176
+		$this->_mappings[ $old_table ][ $new_table ][ $old_pk ] = $new_pk;
177
+	}
178
+
179
+
180
+	/**
181
+	 * Gets the new primary key, if provided with the OLD table and the primary key
182
+	 * of an item in the old table, and the new table
183
+	 *
184
+	 * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
185
+	 * @param int|string $old_pk    old primary key. Eg events_detail.id's value
186
+	 * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
187
+	 * @return mixed the primary key on the new table
188
+	 */
189
+	public function get_mapping_new_pk($old_table, $old_pk, $new_table)
190
+	{
191
+		if (! isset($this->_mappings[ $old_table ]) ||
192
+			! isset($this->_mappings[ $old_table ][ $new_table ])) {
193
+			// try fetching the option
194
+			$this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
195
+		}
196
+		return isset($this->_mappings[ $old_table ][ $new_table ][ $old_pk ])
197
+			? $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] : null;
198
+	}
199
+
200
+
201
+	/**
202
+	 * Gets the old primary key, if provided with the OLD table,
203
+	 * and the new table and the primary key of an item in the new table
204
+	 *
205
+	 * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail
206
+	 * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts
207
+	 * @param mixed  $new_pk
208
+	 * @return mixed
209
+	 */
210
+	public function get_mapping_old_pk($old_table, $new_table, $new_pk)
211
+	{
212
+		if (! isset($this->_mappings[ $old_table ]) ||
213
+			! isset($this->_mappings[ $old_table ][ $new_table ])) {
214
+			// try fetching the option
215
+			$this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
216
+		}
217
+		if (isset($this->_mappings[ $old_table ][ $new_table ])) {
218
+			$new_pk_to_old_pk = array_flip($this->_mappings[ $old_table ][ $new_table ]);
219
+			if (isset($new_pk_to_old_pk[ $new_pk ])) {
220
+				return $new_pk_to_old_pk[ $new_pk ];
221
+			}
222
+		}
223
+		return null;
224
+	}
225
+
226
+
227
+	/**
228
+	 * Gets the mapping array option specified by the table names
229
+	 *
230
+	 * @param string $old_table_name
231
+	 * @param string $new_table_name
232
+	 * @return array
233
+	 */
234
+	protected function _get_mapping_option($old_table_name, $new_table_name)
235
+	{
236
+		$option = get_option($this->_get_mapping_option_name($old_table_name, $new_table_name), array());
237
+		return $option;
238
+	}
239
+
240
+
241
+	/**
242
+	 * Updates the mapping option specified by the table names with the array provided
243
+	 *
244
+	 * @param string $old_table_name
245
+	 * @param string $new_table_name
246
+	 * @param array  $mapping_array
247
+	 * @return boolean success of updating option
248
+	 */
249
+	protected function _set_mapping_option($old_table_name, $new_table_name, $mapping_array)
250
+	{
251
+		$success = update_option($this->_get_mapping_option_name($old_table_name, $new_table_name), $mapping_array);
252
+		return $success;
253
+	}
254
+
255
+
256
+	/**
257
+	 * Gets the option name for this script to map from $old_table_name to $new_table_name
258
+	 *
259
+	 * @param string $old_table_name
260
+	 * @param string $new_table_name
261
+	 * @return string
262
+	 */
263
+	protected function _get_mapping_option_name($old_table_name, $new_table_name)
264
+	{
265
+		global $wpdb;
266
+		$old_table_name_sans_wp = str_replace($wpdb->prefix, "", $old_table_name);
267
+		$new_table_name_sans_wp = str_replace($wpdb->prefix, "", $new_table_name);
268
+		$migrates_to = EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
269
+		return substr(
270
+			EE_Data_Migration_Manager::data_migration_script_mapping_option_prefix . $migrates_to ['slug'] . '_' . $migrates_to['version'] . '_' . $old_table_name_sans_wp . '_' . $new_table_name_sans_wp,
271
+			0,
272
+			64
273
+		);
274
+	}
275
+
276
+
277
+	/**
278
+	 * Counts all the records that will be migrated during this data migration.
279
+	 * For example, if we were changing old user passwords from plaintext to encoded versions,
280
+	 * this would be a count of all users who have passwords. If we were going to also split
281
+	 * attendee records into transactions, registrations, and attendee records, this would include
282
+	 * the count of all attendees currently in existence in the DB (ie, users + attendees).
283
+	 * If you can't determine how many records there are to migrate, just provide a guess: this
284
+	 * number will only be used in calculating the percent complete. If you estimate there to be
285
+	 * 100 records to migrate, and it turns out there's 120, we'll just show the migration as being at
286
+	 * 99% until the function "migration_step" returns EE_Data_Migration_Script_Base::status_complete.
287
+	 *
288
+	 * @return int
289
+	 */
290
+	protected function _count_records_to_migrate()
291
+	{
292
+		$count = 0;
293
+		foreach ($this->stages() as $stage) {
294
+			$count += $stage->count_records_to_migrate();
295
+		}
296
+		return $count;
297
+	}
298
+
299
+
300
+	/**
301
+	 * Returns the number of records updated so far. Usually this is easiest to do
302
+	 * by just setting a transient and updating it after each migration_step
303
+	 *
304
+	 * @return int
305
+	 */
306
+	public function count_records_migrated()
307
+	{
308
+		$count = 0;
309
+		foreach ($this->stages() as $stage) {
310
+			$count += $stage->count_records_migrated();
311
+		}
312
+		$this->_records_migrated = $count;
313
+		return $count;
314
+	}
315
+
316
+
317
+	/**
318
+	 * @param int $num_records_to_migrate_limit
319
+	 * @return int
320
+	 * @throws EE_Error
321
+	 * @throws Exception
322
+	 */
323
+	public function migration_step($num_records_to_migrate_limit)
324
+	{
325
+		// reset the feedback message
326
+		$this->_feedback_message = '';
327
+		// if we haven't yet done the 1st schema changes, do them now. buffer any output
328
+		$this->_maybe_do_schema_changes(true);
329
+
330
+		$num_records_actually_migrated = 0;
331
+		$records_migrated_per_stage = array();
332
+		// setup the 'stage' variable, which should hold the last run stage of the migration  (or none at all if nothing runs)
333
+		$stage = null;
334
+		// get the next stage that isn't complete
335
+		foreach ($this->stages() as $stage) {
336
+			if ($stage->get_status() == EE_Data_Migration_Manager::status_continue) {
337
+				try {
338
+					$records_migrated_during_stage = $stage->migration_step(
339
+						$num_records_to_migrate_limit - $num_records_actually_migrated
340
+					);
341
+					$num_records_actually_migrated += $records_migrated_during_stage;
342
+					$records_migrated_per_stage[ $stage->pretty_name() ] = $records_migrated_during_stage;
343
+				} catch (Exception $e) {
344
+					// yes if we catch an exception here, we consider that migration stage borked.
345
+					$stage->set_status(EE_Data_Migration_Manager::status_fatal_error);
346
+					$this->set_status(EE_Data_Migration_Manager::status_fatal_error);
347
+					$stage->add_error($e->getMessage() . ". Stack-trace:" . $e->getTraceAsString());
348
+					throw $e;
349
+				}
350
+				// check that the migration stage didn't mark itself as having a fatal error
351
+				if ($stage->is_broken()) {
352
+					$this->set_broken();
353
+					throw new EE_Error($stage->get_last_error());
354
+				}
355
+			}
356
+			// once we've migrated all the number we intended to (possibly from different stages), stop migrating
357
+			// or if we had a fatal error
358
+			// or if the current script stopped early- its not done, but it's done all it thinks we should do on this step
359
+			if ($num_records_actually_migrated >= $num_records_to_migrate_limit
360
+				|| $stage->is_broken()
361
+				|| $stage->has_more_to_do()
362
+			) {
363
+				break;
364
+			}
365
+		}
366
+		// check if we're all done this data migration...
367
+		// which is indicated by being done early AND the last stage claims to be done
368
+		if ($stage == null) {
369
+			// this migration script apparently has NO stages... which is super weird, but whatever
370
+			$this->set_completed();
371
+			$this->_maybe_do_schema_changes(false);
372
+		} elseif ($num_records_actually_migrated < $num_records_to_migrate_limit && ! $stage->has_more_to_do()) {
373
+			// apparently we're done, because we couldn't migrate the number we intended to
374
+			$this->set_completed();
375
+			$this->_update_feedback_message(array_reverse($records_migrated_per_stage));
376
+			// do schema changes for after the migration now
377
+			// first double-check we haven't already done this
378
+			$this->_maybe_do_schema_changes(false);
379
+		} else {
380
+			// update feedback message, keeping in mind that we show them with the most recent at the top
381
+			$this->_update_feedback_message(array_reverse($records_migrated_per_stage));
382
+		}
383
+		return $num_records_actually_migrated;
384
+	}
385
+
386
+
387
+	/**
388
+	 * Updates the feedback message according to what was done during this migration stage.
389
+	 *
390
+	 * @param array $records_migrated_per_stage KEYS are pretty names for each stage; values are the count of records
391
+	 *                                          migrated from that stage
392
+	 * @return void
393
+	 */
394
+	private function _update_feedback_message($records_migrated_per_stage)
395
+	{
396
+		$feedback_message_array = array();
397
+		foreach ($records_migrated_per_stage as $migration_stage_name => $num_records_migrated) {
398
+			$feedback_message_array[] = sprintf(
399
+				__("Migrated %d records successfully during %s", "event_espresso"),
400
+				$num_records_migrated,
401
+				$migration_stage_name
402
+			);
403
+		}
404
+		$this->_feedback_message .= implode("<br>", $feedback_message_array);
405
+	}
406
+
407
+
408
+	/**
409
+	 * Calls either schema_changes_before_migration() (if $before==true) or schema_changes_after_migration
410
+	 * (if $before==false). Buffers their outputs and stores them on the class.
411
+	 *
412
+	 * @param boolean $before
413
+	 * @throws Exception
414
+	 * @return void
415
+	 */
416
+	private function _maybe_do_schema_changes($before = true)
417
+	{
418
+		// so this property will be either _schema_changes_after_migration_ran or _schema_changes_before_migration_ran
419
+		$property_name = '_schema_changes_' . ($before ? 'before' : 'after') . '_migration_ran';
420
+		if (! $this->{$property_name}) {
421
+			try {
422
+				ob_start();
423
+				if ($before) {
424
+					$this->schema_changes_before_migration();
425
+				} else {
426
+					$this->schema_changes_after_migration();
427
+				}
428
+				$output = ob_get_contents();
429
+				ob_end_clean();
430
+			} catch (Exception $e) {
431
+				$this->set_status(EE_Data_Migration_Manager::status_fatal_error);
432
+				throw $e;
433
+			}
434
+			// record that we've done these schema changes
435
+			$this->{$property_name} = true;
436
+			// if there were any warnings etc, record them as non-fatal errors
437
+			if ($output) {
438
+				// there were some warnings
439
+				$this->_errors[] = $output;
440
+			}
441
+		}
442
+	}
443
+
444
+
445
+	/**
446
+	 * Wrapper for EEH_Activation::create_table. However, takes into account the request type when
447
+	 * deciding what to pass for its 4th arg, $drop_pre_existing_tables. Using this function, instead
448
+	 * of _table_should_exist_previously, indicates that this table should be new to the EE version being migrated to
449
+	 * or
450
+	 * activated currently. If this is a brand new activation or a migration, and we're indicating this table should
451
+	 * not
452
+	 * previously exist, then we want to set $drop_pre_existing_tables to TRUE (ie, we shouldn't discover that this
453
+	 * table exists in the DB in EEH_Activation::create_table- if it DOES exist, something's wrong and the old table
454
+	 * should be nuked.
455
+	 *
456
+	 * Just for a bit of context, the migration script's db_schema_changes_* methods
457
+	 * are called basically in 3 cases: on brand new activation of EE4 (ie no previous version of EE existed and the
458
+	 * plugin is being activated and we want to add all the brand new tables), upon reactivation of EE4 (it was
459
+	 * deactivated and then reactivated, in which case we want to just verify the DB structure is ok) that table should
460
+	 * be dropped), and during a migration when we're moving the DB to the state of the migration script
461
+	 *
462
+	 * @param string $table_name
463
+	 * @param string $table_definition_sql
464
+	 * @param string $engine_string
465
+	 */
466
+	protected function _table_is_new_in_this_version(
467
+		$table_name,
468
+		$table_definition_sql,
469
+		$engine_string = 'ENGINE=InnoDB '
470
+	) {
471
+		$this->_create_table_and_catch_errors(
472
+			$table_name,
473
+			$table_definition_sql,
474
+			$engine_string,
475
+			$this->_pre_existing_table_should_be_dropped(true)
476
+		);
477
+	}
478
+
479
+	/**
480
+	 * Like _table_is_new_in_this_version and _table_should_exist_previously, this function verifies the given table
481
+	 * exists. But we understand that this table has CHANGED in this version since the previous version. So it's not
482
+	 * completely new, but it's different. So we need to treat it like a new table in terms of verifying it's schema is
483
+	 * correct on activations, migrations, upgrades; but if it exists when it shouldn't, we need to be as lenient as
484
+	 * _table_should_exist_previously.
485
+	 * 8656]{Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the
486
+	 * table shouldn't exist).
487
+	 *
488
+	 * @param string $table_name
489
+	 * @param string $table_definition_sql
490
+	 * @param string $engine_string
491
+	 */
492
+	protected function _table_is_changed_in_this_version(
493
+		$table_name,
494
+		$table_definition_sql,
495
+		$engine_string = 'ENGINE=MyISAM'
496
+	) {
497
+		$this->_create_table_and_catch_errors(
498
+			$table_name,
499
+			$table_definition_sql,
500
+			$engine_string,
501
+			$this->_pre_existing_table_should_be_dropped(false)
502
+		);
503
+	}
504
+
505
+
506
+	/**
507
+	 * _old_table_exists
508
+	 * returns TRUE if the requested table exists in the current database
509
+	 *
510
+	 * @param string $table_name
511
+	 * @return boolean
512
+	 */
513
+	protected function _old_table_exists($table_name)
514
+	{
515
+		return $this->_get_table_analysis()->tableExists($table_name);
516
+	}
517
+
518
+
519
+	/**
520
+	 * _delete_table_if_empty
521
+	 * returns TRUE if the requested table was empty and successfully empty
522
+	 *
523
+	 * @param string $table_name
524
+	 * @return boolean
525
+	 */
526
+	protected function _delete_table_if_empty($table_name)
527
+	{
528
+		return EEH_Activation::delete_db_table_if_empty($table_name);
529
+	}
530
+
531
+
532
+	/**
533
+	 * It is preferred to use _table_has_not_changed_since_previous or _table_is_changed_in_this_version
534
+	 * as these are significantly more efficient or explicit.
535
+	 * Please see description of _table_is_new_in_this_version. This function will only set
536
+	 * EEH_Activation::create_table's $drop_pre_existing_tables to TRUE if it's a brand
537
+	 * new activation. ie, a more accurate name for this method would be "_table_added_previously_by_this_plugin"
538
+	 * because the table will be cleared out if this is a new activation (ie, if its a new activation, it actually
539
+	 * should exist previously). Otherwise, we'll always set $drop_pre_existing_tables to FALSE because the table
540
+	 * should have existed. Note, if the table is being MODIFIED in this version being activated or migrated to, then
541
+	 * you want _table_is_changed_in_this_version NOT this one. We don't check this table's structure during migrations
542
+	 * because apparently it hasn't changed since the previous one, right?
543
+	 *
544
+	 * @param string $table_name
545
+	 * @param string $table_definition_sql
546
+	 * @param string $engine_string
547
+	 */
548
+	protected function _table_should_exist_previously(
549
+		$table_name,
550
+		$table_definition_sql,
551
+		$engine_string = 'ENGINE=MyISAM'
552
+	) {
553
+		$this->_create_table_and_catch_errors(
554
+			$table_name,
555
+			$table_definition_sql,
556
+			$engine_string,
557
+			$this->_pre_existing_table_should_be_dropped(false)
558
+		);
559
+	}
560
+
561
+	/**
562
+	 * Exactly the same as _table_should_exist_previously(), except if this migration script is currently doing
563
+	 * a migration, we skip checking this table's structure in the database and just assume it's correct.
564
+	 * So this is useful only to improve efficiency when doing migrations (not a big deal for single site installs,
565
+	 * but important for multisite where migrations can take a very long time otherwise).
566
+	 * If the table is known to have changed since previous version, use _table_is_changed_in_this_version().
567
+	 * Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the table
568
+	 * shouldn't exist).
569
+	 *
570
+	 * @param string $table_name
571
+	 * @param string $table_definition_sql
572
+	 * @param string $engine_string
573
+	 */
574
+	protected function _table_has_not_changed_since_previous(
575
+		$table_name,
576
+		$table_definition_sql,
577
+		$engine_string = 'ENGINE=MyISAM'
578
+	) {
579
+		if ($this->_currently_migrating()) {
580
+			// if we're doing a migration, and this table apparently already exists, then we don't need do anything right?
581
+			return;
582
+		}
583
+		$this->_create_table_and_catch_errors(
584
+			$table_name,
585
+			$table_definition_sql,
586
+			$engine_string,
587
+			$this->_pre_existing_table_should_be_dropped(false)
588
+		);
589
+	}
590
+
591
+	/**
592
+	 * Returns whether or not this migration script is being used as part of an actual migration
593
+	 *
594
+	 * @return boolean
595
+	 */
596
+	protected function _currently_migrating()
597
+	{
598
+		// we want to know if we are currently performing a migration. We could just believe what was set on the _migrating property, but let's double-check (ie the script should apply and we should be in MM)
599
+		return $this->_migrating &&
600
+			   $this->can_migrate_from_version(
601
+				   EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set()
602
+			   ) &&
603
+			   EE_Maintenance_Mode::instance()->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance;
604
+	}
605
+
606
+	/**
607
+	 * Determines if a table should be dropped, based on whether it's reported to be new in $table_is_new,
608
+	 * and the plugin's request type.
609
+	 * Assumes only this plugin could have added the table (ie, if its a new activation of this plugin, the table
610
+	 * shouldn't exist no matter what).
611
+	 *
612
+	 * @param boolean $table_is_new
613
+	 * @return boolean
614
+	 */
615
+	protected function _pre_existing_table_should_be_dropped($table_is_new)
616
+	{
617
+		if ($table_is_new) {
618
+			if ($this->_get_req_type_for_plugin_corresponding_to_this_dms() == EE_System::req_type_new_activation
619
+				|| $this->_currently_migrating()
620
+			) {
621
+				return true;
622
+			} else {
623
+				return false;
624
+			}
625
+		} else {
626
+			if (in_array(
627
+				$this->_get_req_type_for_plugin_corresponding_to_this_dms(),
628
+				array(EE_System::req_type_new_activation)
629
+			)) {
630
+				return true;
631
+			} else {
632
+				return false;
633
+			}
634
+		}
635
+	}
636
+
637
+	/**
638
+	 * Just wraps EEH_Activation::create_table, but catches any errors it may throw and adds them as errors on the DMS
639
+	 *
640
+	 * @param string  $table_name
641
+	 * @param string  $table_definition_sql
642
+	 * @param string  $engine_string
643
+	 * @param boolean $drop_pre_existing_tables
644
+	 */
645
+	private function _create_table_and_catch_errors(
646
+		$table_name,
647
+		$table_definition_sql,
648
+		$engine_string = 'ENGINE=MyISAM',
649
+		$drop_pre_existing_tables = false
650
+	) {
651
+		try {
652
+			EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables);
653
+		} catch (EE_Error $e) {
654
+			$message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString();
655
+			$this->add_error($message);
656
+			$this->_feedback_message .= $message;
657
+		}
658
+	}
659
+
660
+
661
+	/**
662
+	 * Gets the request type for the plugin (core or addon) that corresponds to this DMS
663
+	 *
664
+	 * @return int one of EE_System::_req_type_* constants
665
+	 * @throws EE_Error
666
+	 */
667
+	private function _get_req_type_for_plugin_corresponding_to_this_dms()
668
+	{
669
+		if ($this->slug() == 'Core') {
670
+			return EE_System::instance()->detect_req_type();
671
+		} else {// it must be for an addon
672
+			$addon_name = $this->slug();
673
+			if (EE_Registry::instance()->get_addon_by_name($addon_name)) {
674
+				return EE_Registry::instance()->get_addon_by_name($addon_name)->detect_req_type();
675
+			} else {
676
+				throw new EE_Error(
677
+					sprintf(
678
+						__(
679
+							"The DMS slug '%s' should correspond to the addon's name, which should also be '%s', but no such addon was registered. These are the registered addons' names: %s",
680
+							"event_espresso"
681
+						),
682
+						$this->slug(),
683
+						$addon_name,
684
+						implode(",", array_keys(EE_Registry::instance()->get_addons_by_name()))
685
+					)
686
+				);
687
+			}
688
+		}
689
+	}
690
+
691
+
692
+	/**
693
+	 * returns an array of strings describing errors by all the script's stages
694
+	 *
695
+	 * @return array
696
+	 */
697
+	public function get_errors()
698
+	{
699
+		$all_errors = $this->_errors;
700
+		if (! is_array($all_errors)) {
701
+			$all_errors = array();
702
+		}
703
+		foreach ($this->stages() as $stage) {
704
+			$all_errors = array_merge($stage->get_errors(), $all_errors);
705
+		}
706
+		return $all_errors;
707
+	}
708
+
709
+
710
+	/**
711
+	 * Indicates whether or not this migration script should continue
712
+	 *
713
+	 * @return boolean
714
+	 */
715
+	public function can_continue()
716
+	{
717
+		return in_array(
718
+			$this->get_status(),
719
+			EE_Data_Migration_Manager::instance()->stati_that_indicate_to_continue_single_migration_script
720
+		);
721
+	}
722
+
723
+
724
+	/**
725
+	 * Gets all the data migration stages associated with this script. Note:
726
+	 * addons can filter this list to add their own stages, and because the list is
727
+	 * numerically-indexed, they can insert their stage wherever they like and it will
728
+	 * get ordered by the indexes
729
+	 *
730
+	 * @return EE_Data_Migration_Script_Stage[]
731
+	 */
732
+	protected function stages()
733
+	{
734
+		$stages = apply_filters('FHEE__' . get_class($this) . '__stages', $this->_migration_stages);
735
+		ksort($stages);
736
+		return $stages;
737
+	}
738
+
739
+
740
+	/**
741
+	 * Gets a string which should describe what's going on currently with this migration, which
742
+	 * can be displayed to the user
743
+	 *
744
+	 * @return string
745
+	 */
746
+	public function get_feedback_message()
747
+	{
748
+		return $this->_feedback_message;
749
+	}
750
+
751
+
752
+	/**
753
+	 * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
754
+	 * properties to the DB. However, we don't want to use __sleep() because its quite
755
+	 * possible that this class is defined when it goes to sleep, but NOT available when it
756
+	 * awakes (eg, this class is part of an addon that is deactivated at some point).
757
+	 */
758
+	public function properties_as_array()
759
+	{
760
+		$properties = parent::properties_as_array();
761
+		$properties['_migration_stages'] = array();
762
+		foreach ($this->_migration_stages as $migration_stage_priority => $migration_stage_class) {
763
+			$properties['_migration_stages'][ $migration_stage_priority ] = $migration_stage_class->properties_as_array(
764
+			);
765
+		}
766
+		unset($properties['_mappings']);
767
+		unset($properties['previous_dms']);
768
+
769
+		foreach ($this->_mappings as $old_table_name => $mapping_to_new_table) {
770
+			foreach ($mapping_to_new_table as $new_table_name => $mapping) {
771
+				$this->_set_mapping_option($old_table_name, $new_table_name, $mapping);
772
+			}
773
+		}
774
+		return $properties;
775
+	}
776
+
777
+
778
+	/**
779
+	 * Sets all of the properties of this script stage to match what's in the array, which is assumed
780
+	 * to have been made from the properties_as_array() function.
781
+	 *
782
+	 * @param array $array_of_properties like what's produced from properties_as_array() method
783
+	 * @return void
784
+	 */
785
+	public function instantiate_from_array_of_properties($array_of_properties)
786
+	{
787
+		$stages_properties_arrays = $array_of_properties['_migration_stages'];
788
+		unset($array_of_properties['_migration_stages']);
789
+		unset($array_of_properties['class']);
790
+		foreach ($array_of_properties as $property_name => $property_value) {
791
+			$this->{$property_name} = $property_value;
792
+		}
793
+		// _migration_stages are already instantiated, but have only default data
794
+		foreach ($this->_migration_stages as $stage) {
795
+			$stage_data = $this->_find_migration_stage_data_with_classname(
796
+				get_class($stage),
797
+				$stages_properties_arrays
798
+			);
799
+			// SO, if we found the stage data that was saved, use it. Otherwise, I guess the stage is new? (maybe added by
800
+			// an addon? Unlikely... not sure why it wouldn't exist, but if it doesn't just treat it like it was never started yet)
801
+			if ($stage_data) {
802
+				$stage->instantiate_from_array_of_properties($stage_data);
803
+			}
804
+		}
805
+	}
806
+
807
+
808
+	/**
809
+	 * Gets the migration data from the array $migration_stage_data_arrays (which is an array of arrays, each of which
810
+	 * is pretty well identical to EE_Data_Migration_Stage objects except all their properties are array indexes)
811
+	 * for the given classname
812
+	 *
813
+	 * @param string $classname
814
+	 * @param array  $migration_stage_data_arrays
815
+	 * @return null
816
+	 */
817
+	private function _find_migration_stage_data_with_classname($classname, $migration_stage_data_arrays)
818
+	{
819
+		foreach ($migration_stage_data_arrays as $migration_stage_data_array) {
820
+			if (isset($migration_stage_data_array['class']) && $migration_stage_data_array['class'] == $classname) {
821
+				return $migration_stage_data_array;
822
+			}
823
+		}
824
+		return null;
825
+	}
826
+
827
+
828
+	/**
829
+	 * Returns the version that this script migrates to, based on the script's name.
830
+	 * Cannot be overwritten because lots of code needs to know which version a script
831
+	 * migrates to knowing only its name.
832
+	 *
833
+	 * @return array where the first key is the plugin's slug, the 2nd is the version of that plugin
834
+	 * that will be updated to. Eg array('Core','4.1.0')
835
+	 */
836
+	final public function migrates_to_version()
837
+	{
838
+		return EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
839
+	}
840
+
841
+
842
+	/**
843
+	 * Gets this addon's slug as it would appear in the current_db_state wp option,
844
+	 * and if this migration script is for an addon, it SHOULD match the addon's slug
845
+	 * (and also the addon's classname, minus the 'EE_' prefix.). Eg, 'Calendar' for the EE_Calendar addon.
846
+	 * Or 'Core' for core (non-addon).
847
+	 *
848
+	 * @return string
849
+	 */
850
+	public function slug()
851
+	{
852
+		$migrates_to_version_info = $this->migrates_to_version();
853
+		// the slug is the first part of the array
854
+		return $migrates_to_version_info['slug'];
855
+	}
856
+
857
+
858
+	/**
859
+	 * Returns the script's priority relative to DMSs from other addons. However, when
860
+	 * two DMSs from the same addon/core apply, this is ignored (and instead the version that
861
+	 * the script migrates to is used to determine which to run first). The default is 5, but all core DMSs
862
+	 * normally have priority 10. (So if you want a DMS "A" to run before DMS "B", both of which are from addons,
863
+	 * and both of which CAN run at the same time (ie, "B" doesn't depend on "A" to set
864
+	 * the database up so it can run), then you can set "A" to priority 3 or something.
865
+	 *
866
+	 * @return int
867
+	 */
868
+	public function priority()
869
+	{
870
+		return $this->_priority;
871
+	}
872
+
873
+
874
+	/**
875
+	 * Sets whether or not this DMS is being ran as part of a migration, instead of
876
+	 * just being used to setup (or verify) the current database structure matches
877
+	 * what the latest DMS indicates it should be
878
+	 *
879
+	 * @param boolean $migrating
880
+	 * @return void
881
+	 */
882
+	public function set_migrating($migrating = true)
883
+	{
884
+		$this->_migrating = $migrating;
885
+	}
886
+
887
+	/**
888
+	 * Marks that we think this migration class can continue to migrate
889
+	 */
890
+	public function reattempt()
891
+	{
892
+		parent::reattempt();
893
+		// also, we want to reattempt any stages that were marked as borked
894
+		foreach ($this->stages() as $stage) {
895
+			if ($stage->is_broken()) {
896
+				$stage->reattempt();
897
+			}
898
+		}
899
+	}
900 900
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_Data_Migration_Class_Base.core.php 1 patch
Indentation   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -17,408 +17,408 @@
 block discarded – undo
17 17
 abstract class EE_Data_Migration_Class_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var $records_to_migrate int count of all that have been migrated
22
-     */
23
-    protected $_records_to_migrate = 0;
24
-
25
-    /**
26
-     *
27
-     * @var $records_migrated int
28
-     */
29
-    protected $_records_migrated = 0;
30
-
31
-    /**
32
-     * Whether this migration script is done or not. This COULD be deduced by
33
-     * _records_to_migrate and _records_migrated, but that might nto be accurate
34
-     *
35
-     * @var string one of EE_Data_migration_Manager::status_* constants
36
-     */
37
-    protected $_status = null;
38
-
39
-    /**
40
-     * internationalized name of this class. Convention is to NOT restate that
41
-     * this class if a migration script or a migration script stage
42
-     *
43
-     * @var string (i18ned)
44
-     */
45
-    protected $_pretty_name = null;
46
-
47
-    /**
48
-     * @var array
49
-     */
50
-    protected $_errors = array();
51
-
52
-    /**
53
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
54
-     */
55
-    protected $_table_manager;
56
-
57
-    /**
58
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
59
-     */
60
-    protected $_table_analysis;
61
-
62
-
63
-    /**
64
-     * Just initializes the status of the migration
65
-     *
66
-     * @param TableManager  $table_manager
67
-     * @param TableAnalysis $table_analysis
68
-     */
69
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
70
-    {
71
-        $this->_table_manager = $table_manager;
72
-        $this->_table_analysis = $table_analysis;
73
-        $this->set_status(EE_Data_Migration_Manager::status_continue);
74
-    }
75
-
76
-
77
-    /**
78
-     * Just gets the pretty name for this migration script or stage
79
-     *
80
-     * @throws EE_Error
81
-     * @return string
82
-     */
83
-    public function pretty_name()
84
-    {
85
-        if ($this->_pretty_name === null) {
86
-            throw new EE_Error(
87
-                sprintf(
88
-                    __(
89
-                        "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor",
90
-                        "event_espresso"
91
-                    ),
92
-                    get_class($this)
93
-                )
94
-            );
95
-        }
96
-        return $this->_pretty_name;
97
-    }
98
-
99
-    /**
100
-     *
101
-     * @return int
102
-     */
103
-    public function count_records_to_migrate()
104
-    {
105
-        if ($this->_records_to_migrate == null) {
106
-            $this->_records_to_migrate = $this->_count_records_to_migrate();
107
-        }
108
-        return $this->_records_to_migrate;
109
-    }
110
-
111
-    /**
112
-     * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and
113
-     * EE_Data_migration_Script_Stage
114
-     *
115
-     * @return int
116
-     */
117
-    abstract public function count_records_migrated();
118
-
119
-    /**
120
-     * Counts the records to migrate; the public version may cache it
121
-     *
122
-     * @return int
123
-     */
124
-    abstract protected function _count_records_to_migrate();
125
-
126
-    /**
127
-     * Returns a string indicating the migration script's status.
128
-     *
129
-     * @return string one of EE_Data_Migration_Manager::status_* constants
130
-     * @throws EE_Error
131
-     */
132
-    public function get_status()
133
-    {
134
-        if ($this->_status === null) {
135
-            throw new EE_Error(
136
-                sprintf(
137
-                    __(
138
-                        "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.",
139
-                        "event_espresso"
140
-                    ),
141
-                    get_class($this)
142
-                )
143
-            );
144
-        }
145
-        return $this->_status;
146
-    }
147
-
148
-    /**
149
-     *
150
-     * @param string $status
151
-     * @return void
152
-     */
153
-    protected function set_status($status)
154
-    {
155
-        $this->_status = $status;
156
-    }
157
-
158
-    /**
159
-     * @return array of strings
160
-     */
161
-    abstract public function get_errors();
162
-
163
-    /**
164
-     * Returns the last error that occurred. If none occurred, returns null
165
-     *
166
-     * @return string
167
-     */
168
-    public function get_last_error()
169
-    {
170
-        $errors = $this->get_errors();
171
-        if ($errors) {
172
-            return end($errors);
173
-        } else {
174
-            return null;
175
-        }
176
-    }
177
-
178
-    /**
179
-     * Adds an error to the array of errors on this class.
180
-     *
181
-     * @param string  $error a string describing the error that will be useful for debugging. Consider including all
182
-     *                       the data that led to the error, and a stack trace etc.
183
-     * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are
184
-     *                       already at their limit, we will purposefully forget the first half
185
-     */
186
-    public function add_error($error, $force = false)
187
-    {
188
-        if (! defined('EE_DMS_ERROR_LIMIT')) {
189
-            $limit = 50;
190
-        } else {
191
-            $limit = EE_DMS_ERROR_LIMIT;
192
-        }
193
-        // make sure errors is an array, see ticket #8261
194
-        if (is_string($this->_errors)) {
195
-            $this->_errors = array($this->_errors);
196
-        }
197
-        if (count($this->_errors) >= $limit) {
198
-            if ($force) {
199
-                // get rid of the first half of the errors and any above the limit
200
-                $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2);
201
-                $this->_errors[] = "Limit reached; removed first half of errors to save space";
202
-                $this->_errors[] = $error;
203
-            } else {
204
-                $this->_errors[ $limit ] = 'More, but limit reached...';
205
-            }
206
-        } else {
207
-            $this->_errors[] = $error;
208
-        }
209
-    }
210
-
211
-    /**
212
-     * Indicates there was a fatal error and the migration cannot possibly continue
213
-     *
214
-     * @return boolean
215
-     */
216
-    public function is_broken()
217
-    {
218
-        return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error;
219
-    }
220
-
221
-    /**
222
-     * @deprecated since 4.6.12
223
-     */
224
-    public function is_borked()
225
-    {
226
-        EE_Error::doing_it_wrong(
227
-            'is_borked',
228
-            __(
229
-                'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
230
-                'event_espresso'
231
-            ),
232
-            '4.6.12'
233
-        );
234
-        return $this->is_broken();
235
-    }
236
-
237
-    /**
238
-     * Sets the status to as having a fatal error
239
-     */
240
-    public function set_broken()
241
-    {
242
-        $this->_status = EE_Data_Migration_Manager::status_fatal_error;
243
-    }
244
-
245
-    /**
246
-     *
247
-     * @deprecated since 4.6.12
248
-     */
249
-    public function set_borked()
250
-    {
251
-        EE_Error::doing_it_wrong(
252
-            'is_borked',
253
-            __(
254
-                'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
255
-                'event_espresso'
256
-            ),
257
-            '4.6.12'
258
-        );
259
-        return $this->set_broken();
260
-    }
261
-
262
-    /**
263
-     * Checks if this thing believes it is completed
264
-     *
265
-     * @return boolean
266
-     */
267
-    public function is_completed()
268
-    {
269
-        return $this->get_status() == EE_Data_Migration_Manager::status_completed;
270
-    }
271
-
272
-    /**
273
-     * Checks if the current script has more to do or not (ie, if it's status is CONTINUE)
274
-     *
275
-     * @return boolean
276
-     */
277
-    public function has_more_to_do()
278
-    {
279
-        return $this->get_status() == EE_Data_Migration_Manager::status_continue;
280
-    }
281
-
282
-    /**
283
-     * Marks that we believe this migration thing is completed
284
-     */
285
-    public function set_completed()
286
-    {
287
-        $this->_status = EE_Data_Migration_Manager::status_completed;
288
-    }
289
-
290
-    /**
291
-     * Marks that we think this migration class can continue to migrate
292
-     */
293
-    public function reattempt()
294
-    {
295
-        $this->_status = EE_Data_Migration_Manager::status_continue;
296
-        $this->add_error(__('Reattempt migration', 'event_espresso'), true);
297
-    }
298
-
299
-    /**
300
-     * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
301
-     * properties to the DB. However, we don't want to use __sleep() because its quite
302
-     * possible that this class is defined when it goes to sleep, but NOT available when it
303
-     * awakes (eg, this class is part of an addon that is deactivated at some point).
304
-     */
305
-    public function properties_as_array()
306
-    {
307
-        $properties = get_object_vars($this);
308
-        $properties['class'] = get_class($this);
309
-        unset($properties['_migration_script']);
310
-        unset($properties['_table_manager']);
311
-        unset($properties['_table_analysis']);
312
-        return $properties;
313
-    }
314
-
315
-    /**
316
-     * Sets all of the properties of this script stage to match what's in the array, which is assumed
317
-     * to have been made from the properties_as_array() function.
318
-     *
319
-     * @param array $array_of_properties like what's produced from properties_as_array() method
320
-     */
321
-    abstract public function instantiate_from_array_of_properties($array_of_properties);
322
-
323
-    /**
324
-     * Convenience method for showing a database insertion error
325
-     *
326
-     * @param string $old_table
327
-     * @param array  $old_row_as_array
328
-     * @param string $new_table
329
-     * @param array  $new_row_as_array columns=>values like used in wpdb->insert
330
-     * @param array  $data_types       numerically indexed
331
-     * @return string
332
-     */
333
-    protected function _create_error_message_for_db_insertion(
334
-        $old_table,
335
-        $old_row_as_array,
336
-        $new_table,
337
-        $new_row_as_array,
338
-        $data_types
339
-    ) {
340
-        global $wpdb;
341
-        $old_columns_and_values_for_string = array();
342
-        foreach ($old_row_as_array as $column => $value) {
343
-            $old_columns_and_values_for_string[] = "$column => $value";
344
-        }
345
-        $new_columns_and_values_for_string = array();
346
-        $count = 0;
347
-        foreach ($new_row_as_array as $column => $value) {
348
-            $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
349
-        }
350
-        return sprintf(
351
-            __(
352
-                'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.',
353
-                'event_espresso'
354
-            ),
355
-            implode(", ", $new_columns_and_values_for_string),
356
-            $new_table,
357
-            implode(", ", $old_columns_and_values_for_string),
358
-            $old_table,
359
-            '<br/>',
360
-            $wpdb->last_error
361
-        );
362
-    }
363
-
364
-
365
-    /**
366
-     * Same as json_encode, just avoids putting
367
-     * serialized arrays into the http build query, as that would
368
-     *
369
-     * @param array $array_of_data
370
-     * @return string
371
-     */
372
-    protected function _json_encode($array_of_data)
373
-    {
374
-        // we'd rather NOT serialize the transaction details
375
-        $fields_to_include = array();
376
-        foreach ($array_of_data as $name => $value) {
377
-            $unserialized_data = @unserialize($value);
378
-            if ($unserialized_data === false) {
379
-                $fields_to_include[ $name ] = $value;
380
-            }
381
-        }
382
-        return wp_json_encode($fields_to_include);
383
-    }
384
-
385
-    /**
386
-     * Gets the table manager (or throws an exception if it cannot be retrieved)
387
-     *
388
-     * @return TableManager
389
-     * @throws EE_Error
390
-     */
391
-    protected function _get_table_manager()
392
-    {
393
-        if ($this->_table_manager instanceof TableManager) {
394
-            return $this->_table_manager;
395
-        } else {
396
-            throw new EE_Error(
397
-                sprintf(
398
-                    __('Table manager on migration class %1$s is not set properly.', 'event_espresso'),
399
-                    get_class($this)
400
-                )
401
-            );
402
-        }
403
-    }
404
-
405
-    /**
406
-     * Gets the injected table analyzer, or throws an exception
407
-     *
408
-     * @return TableAnalysis
409
-     * @throws EE_Error
410
-     */
411
-    protected function _get_table_analysis()
412
-    {
413
-        if ($this->_table_analysis instanceof TableAnalysis) {
414
-            return $this->_table_analysis;
415
-        } else {
416
-            throw new EE_Error(
417
-                sprintf(
418
-                    __('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'),
419
-                    get_class($this)
420
-                )
421
-            );
422
-        }
423
-    }
20
+	/**
21
+	 * @var $records_to_migrate int count of all that have been migrated
22
+	 */
23
+	protected $_records_to_migrate = 0;
24
+
25
+	/**
26
+	 *
27
+	 * @var $records_migrated int
28
+	 */
29
+	protected $_records_migrated = 0;
30
+
31
+	/**
32
+	 * Whether this migration script is done or not. This COULD be deduced by
33
+	 * _records_to_migrate and _records_migrated, but that might nto be accurate
34
+	 *
35
+	 * @var string one of EE_Data_migration_Manager::status_* constants
36
+	 */
37
+	protected $_status = null;
38
+
39
+	/**
40
+	 * internationalized name of this class. Convention is to NOT restate that
41
+	 * this class if a migration script or a migration script stage
42
+	 *
43
+	 * @var string (i18ned)
44
+	 */
45
+	protected $_pretty_name = null;
46
+
47
+	/**
48
+	 * @var array
49
+	 */
50
+	protected $_errors = array();
51
+
52
+	/**
53
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
54
+	 */
55
+	protected $_table_manager;
56
+
57
+	/**
58
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
59
+	 */
60
+	protected $_table_analysis;
61
+
62
+
63
+	/**
64
+	 * Just initializes the status of the migration
65
+	 *
66
+	 * @param TableManager  $table_manager
67
+	 * @param TableAnalysis $table_analysis
68
+	 */
69
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
70
+	{
71
+		$this->_table_manager = $table_manager;
72
+		$this->_table_analysis = $table_analysis;
73
+		$this->set_status(EE_Data_Migration_Manager::status_continue);
74
+	}
75
+
76
+
77
+	/**
78
+	 * Just gets the pretty name for this migration script or stage
79
+	 *
80
+	 * @throws EE_Error
81
+	 * @return string
82
+	 */
83
+	public function pretty_name()
84
+	{
85
+		if ($this->_pretty_name === null) {
86
+			throw new EE_Error(
87
+				sprintf(
88
+					__(
89
+						"Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor",
90
+						"event_espresso"
91
+					),
92
+					get_class($this)
93
+				)
94
+			);
95
+		}
96
+		return $this->_pretty_name;
97
+	}
98
+
99
+	/**
100
+	 *
101
+	 * @return int
102
+	 */
103
+	public function count_records_to_migrate()
104
+	{
105
+		if ($this->_records_to_migrate == null) {
106
+			$this->_records_to_migrate = $this->_count_records_to_migrate();
107
+		}
108
+		return $this->_records_to_migrate;
109
+	}
110
+
111
+	/**
112
+	 * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and
113
+	 * EE_Data_migration_Script_Stage
114
+	 *
115
+	 * @return int
116
+	 */
117
+	abstract public function count_records_migrated();
118
+
119
+	/**
120
+	 * Counts the records to migrate; the public version may cache it
121
+	 *
122
+	 * @return int
123
+	 */
124
+	abstract protected function _count_records_to_migrate();
125
+
126
+	/**
127
+	 * Returns a string indicating the migration script's status.
128
+	 *
129
+	 * @return string one of EE_Data_Migration_Manager::status_* constants
130
+	 * @throws EE_Error
131
+	 */
132
+	public function get_status()
133
+	{
134
+		if ($this->_status === null) {
135
+			throw new EE_Error(
136
+				sprintf(
137
+					__(
138
+						"Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.",
139
+						"event_espresso"
140
+					),
141
+					get_class($this)
142
+				)
143
+			);
144
+		}
145
+		return $this->_status;
146
+	}
147
+
148
+	/**
149
+	 *
150
+	 * @param string $status
151
+	 * @return void
152
+	 */
153
+	protected function set_status($status)
154
+	{
155
+		$this->_status = $status;
156
+	}
157
+
158
+	/**
159
+	 * @return array of strings
160
+	 */
161
+	abstract public function get_errors();
162
+
163
+	/**
164
+	 * Returns the last error that occurred. If none occurred, returns null
165
+	 *
166
+	 * @return string
167
+	 */
168
+	public function get_last_error()
169
+	{
170
+		$errors = $this->get_errors();
171
+		if ($errors) {
172
+			return end($errors);
173
+		} else {
174
+			return null;
175
+		}
176
+	}
177
+
178
+	/**
179
+	 * Adds an error to the array of errors on this class.
180
+	 *
181
+	 * @param string  $error a string describing the error that will be useful for debugging. Consider including all
182
+	 *                       the data that led to the error, and a stack trace etc.
183
+	 * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are
184
+	 *                       already at their limit, we will purposefully forget the first half
185
+	 */
186
+	public function add_error($error, $force = false)
187
+	{
188
+		if (! defined('EE_DMS_ERROR_LIMIT')) {
189
+			$limit = 50;
190
+		} else {
191
+			$limit = EE_DMS_ERROR_LIMIT;
192
+		}
193
+		// make sure errors is an array, see ticket #8261
194
+		if (is_string($this->_errors)) {
195
+			$this->_errors = array($this->_errors);
196
+		}
197
+		if (count($this->_errors) >= $limit) {
198
+			if ($force) {
199
+				// get rid of the first half of the errors and any above the limit
200
+				$this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2);
201
+				$this->_errors[] = "Limit reached; removed first half of errors to save space";
202
+				$this->_errors[] = $error;
203
+			} else {
204
+				$this->_errors[ $limit ] = 'More, but limit reached...';
205
+			}
206
+		} else {
207
+			$this->_errors[] = $error;
208
+		}
209
+	}
210
+
211
+	/**
212
+	 * Indicates there was a fatal error and the migration cannot possibly continue
213
+	 *
214
+	 * @return boolean
215
+	 */
216
+	public function is_broken()
217
+	{
218
+		return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error;
219
+	}
220
+
221
+	/**
222
+	 * @deprecated since 4.6.12
223
+	 */
224
+	public function is_borked()
225
+	{
226
+		EE_Error::doing_it_wrong(
227
+			'is_borked',
228
+			__(
229
+				'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
230
+				'event_espresso'
231
+			),
232
+			'4.6.12'
233
+		);
234
+		return $this->is_broken();
235
+	}
236
+
237
+	/**
238
+	 * Sets the status to as having a fatal error
239
+	 */
240
+	public function set_broken()
241
+	{
242
+		$this->_status = EE_Data_Migration_Manager::status_fatal_error;
243
+	}
244
+
245
+	/**
246
+	 *
247
+	 * @deprecated since 4.6.12
248
+	 */
249
+	public function set_borked()
250
+	{
251
+		EE_Error::doing_it_wrong(
252
+			'is_borked',
253
+			__(
254
+				'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
255
+				'event_espresso'
256
+			),
257
+			'4.6.12'
258
+		);
259
+		return $this->set_broken();
260
+	}
261
+
262
+	/**
263
+	 * Checks if this thing believes it is completed
264
+	 *
265
+	 * @return boolean
266
+	 */
267
+	public function is_completed()
268
+	{
269
+		return $this->get_status() == EE_Data_Migration_Manager::status_completed;
270
+	}
271
+
272
+	/**
273
+	 * Checks if the current script has more to do or not (ie, if it's status is CONTINUE)
274
+	 *
275
+	 * @return boolean
276
+	 */
277
+	public function has_more_to_do()
278
+	{
279
+		return $this->get_status() == EE_Data_Migration_Manager::status_continue;
280
+	}
281
+
282
+	/**
283
+	 * Marks that we believe this migration thing is completed
284
+	 */
285
+	public function set_completed()
286
+	{
287
+		$this->_status = EE_Data_Migration_Manager::status_completed;
288
+	}
289
+
290
+	/**
291
+	 * Marks that we think this migration class can continue to migrate
292
+	 */
293
+	public function reattempt()
294
+	{
295
+		$this->_status = EE_Data_Migration_Manager::status_continue;
296
+		$this->add_error(__('Reattempt migration', 'event_espresso'), true);
297
+	}
298
+
299
+	/**
300
+	 * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
301
+	 * properties to the DB. However, we don't want to use __sleep() because its quite
302
+	 * possible that this class is defined when it goes to sleep, but NOT available when it
303
+	 * awakes (eg, this class is part of an addon that is deactivated at some point).
304
+	 */
305
+	public function properties_as_array()
306
+	{
307
+		$properties = get_object_vars($this);
308
+		$properties['class'] = get_class($this);
309
+		unset($properties['_migration_script']);
310
+		unset($properties['_table_manager']);
311
+		unset($properties['_table_analysis']);
312
+		return $properties;
313
+	}
314
+
315
+	/**
316
+	 * Sets all of the properties of this script stage to match what's in the array, which is assumed
317
+	 * to have been made from the properties_as_array() function.
318
+	 *
319
+	 * @param array $array_of_properties like what's produced from properties_as_array() method
320
+	 */
321
+	abstract public function instantiate_from_array_of_properties($array_of_properties);
322
+
323
+	/**
324
+	 * Convenience method for showing a database insertion error
325
+	 *
326
+	 * @param string $old_table
327
+	 * @param array  $old_row_as_array
328
+	 * @param string $new_table
329
+	 * @param array  $new_row_as_array columns=>values like used in wpdb->insert
330
+	 * @param array  $data_types       numerically indexed
331
+	 * @return string
332
+	 */
333
+	protected function _create_error_message_for_db_insertion(
334
+		$old_table,
335
+		$old_row_as_array,
336
+		$new_table,
337
+		$new_row_as_array,
338
+		$data_types
339
+	) {
340
+		global $wpdb;
341
+		$old_columns_and_values_for_string = array();
342
+		foreach ($old_row_as_array as $column => $value) {
343
+			$old_columns_and_values_for_string[] = "$column => $value";
344
+		}
345
+		$new_columns_and_values_for_string = array();
346
+		$count = 0;
347
+		foreach ($new_row_as_array as $column => $value) {
348
+			$new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
349
+		}
350
+		return sprintf(
351
+			__(
352
+				'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.',
353
+				'event_espresso'
354
+			),
355
+			implode(", ", $new_columns_and_values_for_string),
356
+			$new_table,
357
+			implode(", ", $old_columns_and_values_for_string),
358
+			$old_table,
359
+			'<br/>',
360
+			$wpdb->last_error
361
+		);
362
+	}
363
+
364
+
365
+	/**
366
+	 * Same as json_encode, just avoids putting
367
+	 * serialized arrays into the http build query, as that would
368
+	 *
369
+	 * @param array $array_of_data
370
+	 * @return string
371
+	 */
372
+	protected function _json_encode($array_of_data)
373
+	{
374
+		// we'd rather NOT serialize the transaction details
375
+		$fields_to_include = array();
376
+		foreach ($array_of_data as $name => $value) {
377
+			$unserialized_data = @unserialize($value);
378
+			if ($unserialized_data === false) {
379
+				$fields_to_include[ $name ] = $value;
380
+			}
381
+		}
382
+		return wp_json_encode($fields_to_include);
383
+	}
384
+
385
+	/**
386
+	 * Gets the table manager (or throws an exception if it cannot be retrieved)
387
+	 *
388
+	 * @return TableManager
389
+	 * @throws EE_Error
390
+	 */
391
+	protected function _get_table_manager()
392
+	{
393
+		if ($this->_table_manager instanceof TableManager) {
394
+			return $this->_table_manager;
395
+		} else {
396
+			throw new EE_Error(
397
+				sprintf(
398
+					__('Table manager on migration class %1$s is not set properly.', 'event_espresso'),
399
+					get_class($this)
400
+				)
401
+			);
402
+		}
403
+	}
404
+
405
+	/**
406
+	 * Gets the injected table analyzer, or throws an exception
407
+	 *
408
+	 * @return TableAnalysis
409
+	 * @throws EE_Error
410
+	 */
411
+	protected function _get_table_analysis()
412
+	{
413
+		if ($this->_table_analysis instanceof TableAnalysis) {
414
+			return $this->_table_analysis;
415
+		} else {
416
+			throw new EE_Error(
417
+				sprintf(
418
+					__('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'),
419
+					get_class($this)
420
+				)
421
+			);
422
+		}
423
+	}
424 424
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Core_4_10_0.dms.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
 $stages = glob(EE_CORE . 'data_migration_scripts/4_10_0_stages/*');
17 17
 $class_to_filepath = [];
18 18
 foreach ($stages as $filepath) {
19
-    $matches = [];
20
-    preg_match('~4_10_0_stages/(.*).dmsstage.php~', $filepath, $matches);
21
-    $class_to_filepath[ $matches[1] ] = $filepath;
19
+	$matches = [];
20
+	preg_match('~4_10_0_stages/(.*).dmsstage.php~', $filepath, $matches);
21
+	$class_to_filepath[ $matches[1] ] = $filepath;
22 22
 }
23 23
 // give addons a chance to autoload their stages too
24 24
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_10_0__autoloaded_stages', $class_to_filepath);
@@ -36,72 +36,72 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class EE_DMS_Core_4_10_0 extends EE_Data_Migration_Script_Base
38 38
 {
39
-    /**
40
-     *
41
-     * @param TableManager  $table_manager
42
-     * @param TableAnalysis $table_analysis
43
-     */
44
-    public function __construct(
45
-        TableManager $table_manager = null,
46
-        TableAnalysis $table_analysis = null,
47
-        EE_DMS_Core_4_9_0 $dms_4_9
48
-    ) {
49
-        if (! $dms_4_9 instanceof EE_DMS_Core_4_9_0) {
50
-            $dms_4_9 = LoaderFactory::getLoader()->getShared('EE_DMS_Core_4_9_0');
51
-        }
52
-        $this->previous_dms = $dms_4_9;
53
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.10.0", "event_espresso");
54
-        $this->_priority = 10;
55
-        $this->_migration_stages = array(
56
-            new EE_DMS_4_10_0_Event_Question_Group(),
57
-        );
58
-        parent::__construct($table_manager, $table_analysis);
59
-    }
39
+	/**
40
+	 *
41
+	 * @param TableManager  $table_manager
42
+	 * @param TableAnalysis $table_analysis
43
+	 */
44
+	public function __construct(
45
+		TableManager $table_manager = null,
46
+		TableAnalysis $table_analysis = null,
47
+		EE_DMS_Core_4_9_0 $dms_4_9
48
+	) {
49
+		if (! $dms_4_9 instanceof EE_DMS_Core_4_9_0) {
50
+			$dms_4_9 = LoaderFactory::getLoader()->getShared('EE_DMS_Core_4_9_0');
51
+		}
52
+		$this->previous_dms = $dms_4_9;
53
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.10.0", "event_espresso");
54
+		$this->_priority = 10;
55
+		$this->_migration_stages = array(
56
+			new EE_DMS_4_10_0_Event_Question_Group(),
57
+		);
58
+		parent::__construct($table_manager, $table_analysis);
59
+	}
60 60
 
61 61
 
62 62
 
63
-    /**
64
-     * Whether to migrate or not.
65
-     *
66
-     * @param array $version_array
67
-     * @return bool
68
-     */
69
-    public function can_migrate_from_version($version_array)
70
-    {
71
-        $version_string = $version_array['Core'];
72
-        if (version_compare($version_string, '4.10.0.rc.000', '<') && version_compare($version_string, '4.9.0', '>=')) {
73
-            //          echo "$version_string can be migrated from";
74
-            return true;
75
-        } elseif (! $version_string) {
76
-            //          echo "no version string provided: $version_string";
77
-            // no version string provided... this must be pre 4.3
78
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
79
-        } else {
80
-            //          echo "$version_string doesnt apply";
81
-            return false;
82
-        }
83
-    }
63
+	/**
64
+	 * Whether to migrate or not.
65
+	 *
66
+	 * @param array $version_array
67
+	 * @return bool
68
+	 */
69
+	public function can_migrate_from_version($version_array)
70
+	{
71
+		$version_string = $version_array['Core'];
72
+		if (version_compare($version_string, '4.10.0.rc.000', '<') && version_compare($version_string, '4.9.0', '>=')) {
73
+			//          echo "$version_string can be migrated from";
74
+			return true;
75
+		} elseif (! $version_string) {
76
+			//          echo "no version string provided: $version_string";
77
+			// no version string provided... this must be pre 4.3
78
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
79
+		} else {
80
+			//          echo "$version_string doesnt apply";
81
+			return false;
82
+		}
83
+	}
84 84
 
85 85
 
86 86
 
87
-    /**
88
-     * @return bool
89
-     */
90
-    public function schema_changes_before_migration()
91
-    {
92
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
93
-        $now_in_mysql = current_time('mysql', true);
94
-        $table_name = 'esp_answer';
95
-        $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
87
+	/**
88
+	 * @return bool
89
+	 */
90
+	public function schema_changes_before_migration()
91
+	{
92
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
93
+		$now_in_mysql = current_time('mysql', true);
94
+		$table_name = 'esp_answer';
95
+		$sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
96 96
 					REG_ID int(10) unsigned NOT NULL,
97 97
 					QST_ID int(10) unsigned NOT NULL,
98 98
 					ANS_value text NOT NULL,
99 99
 					PRIMARY KEY  (ANS_ID),
100 100
 					KEY REG_ID (REG_ID),
101 101
 					KEY QST_ID (QST_ID)";
102
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
103
-        $table_name = 'esp_attendee_meta';
104
-        $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
102
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
103
+		$table_name = 'esp_attendee_meta';
104
+		$sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
105 105
 				ATT_ID bigint(20) unsigned NOT NULL,
106 106
 				ATT_fname varchar(45) NOT NULL,
107 107
 				ATT_lname varchar(45) NOT NULL,
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
 				KEY ATT_email (ATT_email(191)),
119 119
 				KEY ATT_lname (ATT_lname),
120 120
 				KEY ATT_fname (ATT_fname)";
121
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
122
-        $table_name = 'esp_checkin';
123
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
121
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
122
+		$table_name = 'esp_checkin';
123
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
124 124
 				REG_ID int(10) unsigned NOT NULL,
125 125
 				DTT_ID int(10) unsigned NOT NULL,
126 126
 				CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 				PRIMARY KEY  (CHK_ID),
129 129
 				KEY REG_ID (REG_ID),
130 130
 				KEY DTT_ID (DTT_ID)";
131
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
132
-        $table_name = 'esp_country';
133
-        $sql = "CNT_ISO varchar(2) NOT NULL,
131
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
132
+		$table_name = 'esp_country';
133
+		$sql = "CNT_ISO varchar(2) NOT NULL,
134 134
 				CNT_ISO3 varchar(3) NOT NULL,
135 135
 				RGN_ID tinyint(3) unsigned DEFAULT NULL,
136 136
 				CNT_name varchar(45) NOT NULL,
@@ -146,29 +146,29 @@  discard block
 block discarded – undo
146 146
 				CNT_is_EU tinyint(1) DEFAULT '0',
147 147
 				CNT_active tinyint(1) DEFAULT '0',
148 148
 				PRIMARY KEY  (CNT_ISO)";
149
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
150
-        $table_name = 'esp_currency';
151
-        $sql = "CUR_code varchar(6) NOT NULL,
149
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
150
+		$table_name = 'esp_currency';
151
+		$sql = "CUR_code varchar(6) NOT NULL,
152 152
 				CUR_single varchar(45) DEFAULT 'dollar',
153 153
 				CUR_plural varchar(45) DEFAULT 'dollars',
154 154
 				CUR_sign varchar(45) DEFAULT '$',
155 155
 				CUR_dec_plc varchar(1) NOT NULL DEFAULT '2',
156 156
 				CUR_active tinyint(1) DEFAULT '0',
157 157
 				PRIMARY KEY  (CUR_code)";
158
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
159
-        // note: although this table is no longer in use,
160
-        // it hasn't been removed because then queries to the model will have errors.
161
-        // but you should expect this table and its corresponding model to be removed in
162
-        // the next few months
163
-        $table_name = 'esp_currency_payment_method';
164
-        $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
158
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
159
+		// note: although this table is no longer in use,
160
+		// it hasn't been removed because then queries to the model will have errors.
161
+		// but you should expect this table and its corresponding model to be removed in
162
+		// the next few months
163
+		$table_name = 'esp_currency_payment_method';
164
+		$sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
165 165
 				CUR_code varchar(6) NOT NULL,
166 166
 				PMD_ID int(11) NOT NULL,
167 167
 				PRIMARY KEY  (CPM_ID),
168 168
 				KEY PMD_ID (PMD_ID)";
169
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
170
-        $table_name = 'esp_datetime';
171
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
169
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
170
+		$table_name = 'esp_datetime';
171
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
172 172
 				EVT_ID bigint(20) unsigned NOT NULL,
173 173
 				DTT_name varchar(255) NOT NULL DEFAULT '',
174 174
 				DTT_description text NOT NULL,
@@ -185,25 +185,25 @@  discard block
 block discarded – undo
185 185
 				KEY DTT_EVT_start (DTT_EVT_start),
186 186
 				KEY EVT_ID (EVT_ID),
187 187
 				KEY DTT_is_primary (DTT_is_primary)";
188
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
189
-        $table_name = "esp_datetime_ticket";
190
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
188
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
189
+		$table_name = "esp_datetime_ticket";
190
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
191 191
 				DTT_ID int(10) unsigned NOT NULL,
192 192
 				TKT_ID int(10) unsigned NOT NULL,
193 193
 				PRIMARY KEY  (DTK_ID),
194 194
 				KEY DTT_ID (DTT_ID),
195 195
 				KEY TKT_ID (TKT_ID)";
196
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
197
-        $table_name = 'esp_event_message_template';
198
-        $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
196
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
197
+		$table_name = 'esp_event_message_template';
198
+		$sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
199 199
 				EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
200 200
 				GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
201 201
 				PRIMARY KEY  (EMT_ID),
202 202
 				KEY EVT_ID (EVT_ID),
203 203
 				KEY GRP_ID (GRP_ID)";
204
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
205
-        $table_name = 'esp_event_meta';
206
-        $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
204
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
205
+		$table_name = 'esp_event_meta';
206
+		$sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
207 207
 				EVT_ID bigint(20) unsigned NOT NULL,
208 208
 				EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
209 209
 				EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
 				EVT_donations tinyint(1) NULL,
219 219
 				PRIMARY KEY  (EVTM_ID),
220 220
 				KEY EVT_ID (EVT_ID)";
221
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
222
-        $table_name = 'esp_event_question_group';
223
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
221
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
222
+		$table_name = 'esp_event_question_group';
223
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
224 224
 				EVT_ID bigint(20) unsigned NOT NULL,
225 225
 				QSG_ID int(10) unsigned NOT NULL,
226 226
 				EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
@@ -228,25 +228,25 @@  discard block
 block discarded – undo
228 228
 				PRIMARY KEY  (EQG_ID),
229 229
 				KEY EVT_ID (EVT_ID),
230 230
 				KEY QSG_ID (QSG_ID)";
231
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
232
-        $table_name = 'esp_event_venue';
233
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
231
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
232
+		$table_name = 'esp_event_venue';
233
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
234 234
 				EVT_ID bigint(20) unsigned NOT NULL,
235 235
 				VNU_ID bigint(20) unsigned NOT NULL,
236 236
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
237 237
 				PRIMARY KEY  (EVV_ID)";
238
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
239
-        $table_name = 'esp_extra_meta';
240
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
238
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
239
+		$table_name = 'esp_extra_meta';
240
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
241 241
 				OBJ_ID int(11) DEFAULT NULL,
242 242
 				EXM_type varchar(45) DEFAULT NULL,
243 243
 				EXM_key varchar(45) DEFAULT NULL,
244 244
 				EXM_value text,
245 245
 				PRIMARY KEY  (EXM_ID),
246 246
 				KEY EXM_type (EXM_type,OBJ_ID,EXM_key)";
247
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
248
-        $table_name = 'esp_extra_join';
249
-        $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
247
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
248
+		$table_name = 'esp_extra_join';
249
+		$sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
250 250
 				EXJ_first_model_id varchar(6) NOT NULL,
251 251
 				EXJ_first_model_name varchar(20) NOT NULL,
252 252
 				EXJ_second_model_id varchar(6) NOT NULL,
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 				PRIMARY KEY  (EXJ_ID),
255 255
 				KEY first_model (EXJ_first_model_name,EXJ_first_model_id),
256 256
 				KEY second_model (EXJ_second_model_name,EXJ_second_model_id)";
257
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
258
-        $table_name = 'esp_line_item';
259
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
257
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
258
+		$table_name = 'esp_line_item';
259
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
260 260
 				LIN_code varchar(245) NOT NULL DEFAULT '',
261 261
 				TXN_ID int(11) DEFAULT NULL,
262 262
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
 				KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp),
278 278
 				KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type),
279 279
 				KEY obj_id_obj_type (OBJ_ID,OBJ_type)";
280
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
281
-        $table_name = 'esp_log';
282
-        $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
280
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
281
+		$table_name = 'esp_log';
282
+		$sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
283 283
 				LOG_time datetime DEFAULT NULL,
284 284
 				OBJ_ID varchar(45) DEFAULT NULL,
285 285
 				OBJ_type varchar(45) DEFAULT NULL,
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
 				KEY LOG_time (LOG_time),
291 291
 				KEY OBJ (OBJ_type,OBJ_ID),
292 292
 				KEY LOG_type (LOG_type)";
293
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
294
-        $table_name = 'esp_message';
295
-        $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
293
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
294
+		$table_name = 'esp_message';
295
+		$sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
296 296
 				GRP_ID int(10) unsigned NULL,
297 297
 				MSG_token varchar(255) NULL,
298 298
 				TXN_ID int(10) unsigned NULL,
@@ -324,18 +324,18 @@  discard block
 block discarded – undo
324 324
 				KEY STS_ID (STS_ID),
325 325
 				KEY MSG_created (MSG_created),
326 326
 				KEY MSG_modified (MSG_modified)";
327
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
328
-        $table_name = 'esp_message_template';
329
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
327
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
328
+		$table_name = 'esp_message_template';
329
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
330 330
 				GRP_ID int(10) unsigned NOT NULL,
331 331
 				MTP_context varchar(50) NOT NULL,
332 332
 				MTP_template_field varchar(30) NOT NULL,
333 333
 				MTP_content text NOT NULL,
334 334
 				PRIMARY KEY  (MTP_ID),
335 335
 				KEY GRP_ID (GRP_ID)";
336
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
337
-        $table_name = 'esp_message_template_group';
338
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
336
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
337
+		$table_name = 'esp_message_template_group';
338
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
339 339
 				MTP_user_id int(10) NOT NULL DEFAULT '1',
340 340
 				MTP_name varchar(245) NOT NULL DEFAULT '',
341 341
 				MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -347,9 +347,9 @@  discard block
 block discarded – undo
347 347
 				MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
348 348
 				PRIMARY KEY  (GRP_ID),
349 349
 				KEY MTP_user_id (MTP_user_id)";
350
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
351
-        $table_name = 'esp_payment';
352
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
350
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
351
+		$table_name = 'esp_payment';
352
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
353 353
 				TXN_ID int(10) unsigned DEFAULT NULL,
354 354
 				STS_ID varchar(3) DEFAULT NULL,
355 355
 				PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
 				PRIMARY KEY  (PAY_ID),
367 367
 				KEY PAY_timestamp (PAY_timestamp),
368 368
 				KEY TXN_ID (TXN_ID)";
369
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
370
-        $table_name = 'esp_payment_method';
371
-        $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
369
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
370
+		$table_name = 'esp_payment_method';
371
+		$sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
372 372
 				PMD_type varchar(124) DEFAULT NULL,
373 373
 				PMD_name varchar(255) DEFAULT NULL,
374 374
 				PMD_desc text,
@@ -384,24 +384,24 @@  discard block
 block discarded – undo
384 384
 				PRIMARY KEY  (PMD_ID),
385 385
 				UNIQUE KEY PMD_slug_UNIQUE (PMD_slug),
386 386
 				KEY PMD_type (PMD_type)";
387
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
388
-        $table_name = "esp_ticket_price";
389
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
387
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
388
+		$table_name = "esp_ticket_price";
389
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
390 390
 				TKT_ID int(10) unsigned NOT NULL,
391 391
 				PRC_ID int(10) unsigned NOT NULL,
392 392
 				PRIMARY KEY  (TKP_ID),
393 393
 				KEY TKT_ID (TKT_ID),
394 394
 				KEY PRC_ID (PRC_ID)";
395
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
396
-        $table_name = "esp_ticket_template";
397
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
395
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
396
+		$table_name = "esp_ticket_template";
397
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
398 398
 				TTM_name varchar(45) NOT NULL,
399 399
 				TTM_description text,
400 400
 				TTM_file varchar(45),
401 401
 				PRIMARY KEY  (TTM_ID)";
402
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
403
-        $table_name = 'esp_question';
404
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
402
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
403
+		$table_name = 'esp_question';
404
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
405 405
 				QST_display_text text NOT NULL,
406 406
 				QST_admin_label varchar(255) NOT NULL,
407 407
 				QST_system varchar(25) DEFAULT NULL,
@@ -415,18 +415,18 @@  discard block
 block discarded – undo
415 415
 				QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0,
416 416
 				PRIMARY KEY  (QST_ID),
417 417
 				KEY QST_order (QST_order)';
418
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
419
-        $table_name = 'esp_question_group_question';
420
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
418
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
419
+		$table_name = 'esp_question_group_question';
420
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
421 421
 				QSG_ID int(10) unsigned NOT NULL,
422 422
 				QST_ID int(10) unsigned NOT NULL,
423 423
 				QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
424 424
 				PRIMARY KEY  (QGQ_ID),
425 425
 				KEY QST_ID (QST_ID),
426 426
 				KEY QSG_ID_order (QSG_ID,QGQ_order)";
427
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
428
-        $table_name = 'esp_question_option';
429
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
427
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
428
+		$table_name = 'esp_question_option';
429
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
430 430
 				QSO_value varchar(255) NOT NULL,
431 431
 				QSO_desc text NOT NULL,
432 432
 				QST_ID int(10) unsigned NOT NULL,
@@ -436,9 +436,9 @@  discard block
 block discarded – undo
436 436
 				PRIMARY KEY  (QSO_ID),
437 437
 				KEY QST_ID (QST_ID),
438 438
 				KEY QSO_order (QSO_order)";
439
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
440
-        $table_name = 'esp_registration';
441
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
439
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
440
+		$table_name = 'esp_registration';
441
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
442 442
 				EVT_ID bigint(20) unsigned NOT NULL,
443 443
 				ATT_ID bigint(20) unsigned NOT NULL,
444 444
 				TXN_ID int(10) unsigned NOT NULL,
@@ -462,18 +462,18 @@  discard block
 block discarded – undo
462 462
 				KEY TKT_ID (TKT_ID),
463 463
 				KEY EVT_ID (EVT_ID),
464 464
 				KEY STS_ID (STS_ID)";
465
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
466
-        $table_name = 'esp_registration_payment';
467
-        $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
465
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
466
+		$table_name = 'esp_registration_payment';
467
+		$sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
468 468
 					  REG_ID int(10) unsigned NOT NULL,
469 469
 					  PAY_ID int(10) unsigned NULL,
470 470
 					  RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00',
471 471
 					  PRIMARY KEY  (RPY_ID),
472 472
 					  KEY REG_ID (REG_ID),
473 473
 					  KEY PAY_ID (PAY_ID)";
474
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
475
-        $table_name = 'esp_state';
476
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
474
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
475
+		$table_name = 'esp_state';
476
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
477 477
 				CNT_ISO varchar(2) NOT NULL,
478 478
 				STA_abbrev varchar(24) NOT NULL,
479 479
 				STA_name varchar(100) NOT NULL,
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
 				PRIMARY KEY  (STA_ID),
482 482
 				KEY STA_abbrev (STA_abbrev),
483 483
 				KEY CNT_ISO (CNT_ISO)";
484
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
485
-        $table_name = 'esp_status';
486
-        $sql = "STS_ID varchar(3) NOT NULL,
484
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
485
+		$table_name = 'esp_status';
486
+		$sql = "STS_ID varchar(3) NOT NULL,
487 487
 				STS_code varchar(45) NOT NULL,
488 488
 				STS_type varchar(45) NOT NULL,
489 489
 				STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 				STS_open tinyint(1) NOT NULL DEFAULT 1,
492 492
 				UNIQUE KEY STS_ID_UNIQUE (STS_ID),
493 493
 				KEY STS_type (STS_type)";
494
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
495
-        $table_name = 'esp_transaction';
496
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
494
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
495
+		$table_name = 'esp_transaction';
496
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
497 497
 				TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
498 498
 				TXN_total decimal(12,3) DEFAULT '0.00',
499 499
 				TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00',
@@ -505,9 +505,9 @@  discard block
 block discarded – undo
505 505
 				PRIMARY KEY  (TXN_ID),
506 506
 				KEY TXN_timestamp (TXN_timestamp),
507 507
 				KEY STS_ID (STS_ID)";
508
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
509
-        $table_name = 'esp_venue_meta';
510
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
508
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
509
+		$table_name = 'esp_venue_meta';
510
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
511 511
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
512 512
 			VNU_address varchar(255) DEFAULT NULL,
513 513
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -526,10 +526,10 @@  discard block
 block discarded – undo
526 526
 			KEY VNU_ID (VNU_ID),
527 527
 			KEY STA_ID (STA_ID),
528 528
 			KEY CNT_ISO (CNT_ISO)";
529
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
530
-        // modified tables
531
-        $table_name = "esp_price";
532
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
529
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
530
+		// modified tables
531
+		$table_name = "esp_price";
532
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
533 533
 				PRT_ID tinyint(3) unsigned NOT NULL,
534 534
 				PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00',
535 535
 				PRC_name varchar(245) NOT NULL,
@@ -542,9 +542,9 @@  discard block
 block discarded – undo
542 542
 				PRC_parent int(10) unsigned DEFAULT 0,
543 543
 				PRIMARY KEY  (PRC_ID),
544 544
 				KEY PRT_ID (PRT_ID)";
545
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
546
-        $table_name = "esp_price_type";
547
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
545
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
546
+		$table_name = "esp_price_type";
547
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
548 548
 				PRT_name varchar(45) NOT NULL,
549 549
 				PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
550 550
 				PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -553,9 +553,9 @@  discard block
 block discarded – undo
553 553
 				PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
554 554
 				UNIQUE KEY PRT_name_UNIQUE (PRT_name),
555 555
 				PRIMARY KEY  (PRT_ID)";
556
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
557
-        $table_name = "esp_ticket";
558
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
556
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
557
+		$table_name = "esp_ticket";
558
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
559 559
 				TTM_ID int(10) unsigned NOT NULL,
560 560
 				TKT_name varchar(245) NOT NULL DEFAULT '',
561 561
 				TKT_description text NOT NULL,
@@ -578,9 +578,9 @@  discard block
 block discarded – undo
578 578
 				TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
579 579
 				PRIMARY KEY  (TKT_ID),
580 580
 				KEY TKT_start_date (TKT_start_date)";
581
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
582
-        $table_name = 'esp_question_group';
583
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
581
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
582
+		$table_name = 'esp_question_group';
583
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
584 584
 				QSG_name varchar(255) NOT NULL,
585 585
 				QSG_identifier varchar(100) NOT NULL,
586 586
 				QSG_desc text NULL,
@@ -593,38 +593,38 @@  discard block
 block discarded – undo
593 593
 				PRIMARY KEY  (QSG_ID),
594 594
 				UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier),
595 595
 				KEY QSG_order (QSG_order)';
596
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
597
-        $this->insert_default_data();
598
-        return true;
599
-    }
596
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
597
+		$this->insert_default_data();
598
+		return true;
599
+	}
600 600
 
601
-    /**
602
-     * Inserts default data on new installs
603
-     * @since $VID:$
604
-     * @throws EE_Error
605
-     * @throws InvalidArgumentException
606
-     * @throws ReflectionException
607
-     * @throws InvalidDataTypeException
608
-     * @throws InvalidInterfaceException
609
-     */
610
-    public function insert_default_data()
611
-    {
612
-        $this->previous_dms->insert_default_data();
613
-    }
601
+	/**
602
+	 * Inserts default data on new installs
603
+	 * @since $VID:$
604
+	 * @throws EE_Error
605
+	 * @throws InvalidArgumentException
606
+	 * @throws ReflectionException
607
+	 * @throws InvalidDataTypeException
608
+	 * @throws InvalidInterfaceException
609
+	 */
610
+	public function insert_default_data()
611
+	{
612
+		$this->previous_dms->insert_default_data();
613
+	}
614 614
 
615 615
 
616 616
 
617
-    /**
618
-     * @return boolean
619
-     */
620
-    public function schema_changes_after_migration()
621
-    {
622
-        return true;
623
-    }
617
+	/**
618
+	 * @return boolean
619
+	 */
620
+	public function schema_changes_after_migration()
621
+	{
622
+		return true;
623
+	}
624 624
 
625 625
 
626 626
 
627
-    public function migration_page_hooks()
628
-    {
629
-    }
627
+	public function migration_page_hooks()
628
+	{
629
+	}
630 630
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
 // unfortunately, this needs to be done upon INCLUSION of this file,
14 14
 // instead of construction, because it only gets constructed on first page load
15 15
 // (all other times it gets resurrected from a wordpress option)
16
-$stages = glob(EE_CORE . 'data_migration_scripts/4_10_0_stages/*');
16
+$stages = glob(EE_CORE.'data_migration_scripts/4_10_0_stages/*');
17 17
 $class_to_filepath = [];
18 18
 foreach ($stages as $filepath) {
19 19
     $matches = [];
20 20
     preg_match('~4_10_0_stages/(.*).dmsstage.php~', $filepath, $matches);
21
-    $class_to_filepath[ $matches[1] ] = $filepath;
21
+    $class_to_filepath[$matches[1]] = $filepath;
22 22
 }
23 23
 // give addons a chance to autoload their stages too
24 24
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_10_0__autoloaded_stages', $class_to_filepath);
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
         TableAnalysis $table_analysis = null,
47 47
         EE_DMS_Core_4_9_0 $dms_4_9
48 48
     ) {
49
-        if (! $dms_4_9 instanceof EE_DMS_Core_4_9_0) {
49
+        if ( ! $dms_4_9 instanceof EE_DMS_Core_4_9_0) {
50 50
             $dms_4_9 = LoaderFactory::getLoader()->getShared('EE_DMS_Core_4_9_0');
51 51
         }
52 52
         $this->previous_dms = $dms_4_9;
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
         if (version_compare($version_string, '4.10.0.rc.000', '<') && version_compare($version_string, '4.9.0', '>=')) {
73 73
             //          echo "$version_string can be migrated from";
74 74
             return true;
75
-        } elseif (! $version_string) {
75
+        } elseif ( ! $version_string) {
76 76
             //          echo "no version string provided: $version_string";
77 77
             // no version string provided... this must be pre 4.3
78
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
78
+            return false; // changed mind. dont want people thinking they should migrate yet because they cant
79 79
         } else {
80 80
             //          echo "$version_string doesnt apply";
81 81
             return false;
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     public function schema_changes_before_migration()
91 91
     {
92
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
92
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
93 93
         $now_in_mysql = current_time('mysql', true);
94 94
         $table_name = 'esp_answer';
95 95
         $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
Please login to merge, or discard this patch.
core/db_classes/EE_Event.class.php 1 patch
Indentation   +1384 added lines, -1384 removed lines patch added patch discarded remove patch
@@ -15,1388 +15,1388 @@
 block discarded – undo
15 15
 class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event
16 16
 {
17 17
 
18
-    /**
19
-     * cached value for the the logical active status for the event
20
-     *
21
-     * @see get_active_status()
22
-     * @var string
23
-     */
24
-    protected $_active_status = '';
25
-
26
-    /**
27
-     * This is just used for caching the Primary Datetime for the Event on initial retrieval
28
-     *
29
-     * @var EE_Datetime
30
-     */
31
-    protected $_Primary_Datetime;
32
-
33
-    /**
34
-     * @var EventSpacesCalculator $available_spaces_calculator
35
-     */
36
-    protected $available_spaces_calculator;
37
-
38
-
39
-    /**
40
-     * @param array  $props_n_values          incoming values
41
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
42
-     *                                        used.)
43
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
44
-     *                                        date_format and the second value is the time format
45
-     * @return EE_Event
46
-     * @throws EE_Error
47
-     */
48
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
49
-    {
50
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
51
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
52
-    }
53
-
54
-
55
-    /**
56
-     * @param array  $props_n_values  incoming values from the database
57
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
58
-     *                                the website will be used.
59
-     * @return EE_Event
60
-     * @throws EE_Error
61
-     */
62
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
63
-    {
64
-        return new self($props_n_values, true, $timezone);
65
-    }
66
-
67
-
68
-    /**
69
-     * @return EventSpacesCalculator
70
-     * @throws \EE_Error
71
-     */
72
-    public function getAvailableSpacesCalculator()
73
-    {
74
-        if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
75
-            $this->available_spaces_calculator = new EventSpacesCalculator($this);
76
-        }
77
-        return $this->available_spaces_calculator;
78
-    }
79
-
80
-
81
-    /**
82
-     * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
83
-     *
84
-     * @param string $field_name
85
-     * @param mixed  $field_value
86
-     * @param bool   $use_default
87
-     * @throws EE_Error
88
-     */
89
-    public function set($field_name, $field_value, $use_default = false)
90
-    {
91
-        switch ($field_name) {
92
-            case 'status':
93
-                $this->set_status($field_value, $use_default);
94
-                break;
95
-            default:
96
-                parent::set($field_name, $field_value, $use_default);
97
-        }
98
-    }
99
-
100
-
101
-    /**
102
-     *    set_status
103
-     * Checks if event status is being changed to SOLD OUT
104
-     * and updates event meta data with previous event status
105
-     * so that we can revert things if/when the event is no longer sold out
106
-     *
107
-     * @access public
108
-     * @param string $new_status
109
-     * @param bool   $use_default
110
-     * @return void
111
-     * @throws EE_Error
112
-     */
113
-    public function set_status($new_status = null, $use_default = false)
114
-    {
115
-        // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
116
-        if (empty($new_status) && ! $use_default) {
117
-            return;
118
-        }
119
-        // get current Event status
120
-        $old_status = $this->status();
121
-        // if status has changed
122
-        if ($old_status !== $new_status) {
123
-            // TO sold_out
124
-            if ($new_status === EEM_Event::sold_out) {
125
-                // save the previous event status so that we can revert if the event is no longer sold out
126
-                $this->add_post_meta('_previous_event_status', $old_status);
127
-                do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
128
-                // OR FROM  sold_out
129
-            } elseif ($old_status === EEM_Event::sold_out) {
130
-                $this->delete_post_meta('_previous_event_status');
131
-                do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
132
-            }
133
-            // clear out the active status so that it gets reset the next time it is requested
134
-            $this->_active_status = null;
135
-            // update status
136
-            parent::set('status', $new_status, $use_default);
137
-            do_action('AHEE__EE_Event__set_status__after_update', $this);
138
-            return;
139
-        }
140
-        // even though the old value matches the new value, it's still good to
141
-        // allow the parent set method to have a say
142
-        parent::set('status', $new_status, $use_default);
143
-    }
144
-
145
-
146
-    /**
147
-     * Gets all the datetimes for this event
148
-     *
149
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
150
-     * @return EE_Base_Class[]|EE_Datetime[]
151
-     * @throws EE_Error
152
-     */
153
-    public function datetimes($query_params = array())
154
-    {
155
-        return $this->get_many_related('Datetime', $query_params);
156
-    }
157
-
158
-
159
-    /**
160
-     * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
161
-     *
162
-     * @return EE_Base_Class[]|EE_Datetime[]
163
-     * @throws EE_Error
164
-     */
165
-    public function datetimes_in_chronological_order()
166
-    {
167
-        return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
168
-    }
169
-
170
-
171
-    /**
172
-     * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
173
-     * @darren, we should probably UNSET timezone on the EEM_Datetime model
174
-     * after running our query, so that this timezone isn't set for EVERY query
175
-     * on EEM_Datetime for the rest of the request, no?
176
-     *
177
-     * @param boolean $show_expired whether or not to include expired events
178
-     * @param boolean $show_deleted whether or not to include deleted events
179
-     * @param null    $limit
180
-     * @return EE_Datetime[]
181
-     * @throws EE_Error
182
-     */
183
-    public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
184
-    {
185
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
186
-            $this->ID(),
187
-            $show_expired,
188
-            $show_deleted,
189
-            $limit
190
-        );
191
-    }
192
-
193
-
194
-    /**
195
-     * Returns one related datetime. Mostly only used by some legacy code.
196
-     *
197
-     * @return EE_Base_Class|EE_Datetime
198
-     * @throws EE_Error
199
-     */
200
-    public function first_datetime()
201
-    {
202
-        return $this->get_first_related('Datetime');
203
-    }
204
-
205
-
206
-    /**
207
-     * Returns the 'primary' datetime for the event
208
-     *
209
-     * @param bool $try_to_exclude_expired
210
-     * @param bool $try_to_exclude_deleted
211
-     * @return EE_Datetime
212
-     * @throws EE_Error
213
-     */
214
-    public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
215
-    {
216
-        if (! empty($this->_Primary_Datetime)) {
217
-            return $this->_Primary_Datetime;
218
-        }
219
-        $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
220
-            $this->ID(),
221
-            $try_to_exclude_expired,
222
-            $try_to_exclude_deleted
223
-        );
224
-        return $this->_Primary_Datetime;
225
-    }
226
-
227
-
228
-    /**
229
-     * Gets all the tickets available for purchase of this event
230
-     *
231
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
232
-     * @return EE_Base_Class[]|EE_Ticket[]
233
-     * @throws EE_Error
234
-     */
235
-    public function tickets($query_params = array())
236
-    {
237
-        // first get all datetimes
238
-        $datetimes = $this->datetimes_ordered();
239
-        if (! $datetimes) {
240
-            return array();
241
-        }
242
-        $datetime_ids = array();
243
-        foreach ($datetimes as $datetime) {
244
-            $datetime_ids[] = $datetime->ID();
245
-        }
246
-        $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
247
-        // if incoming $query_params has where conditions let's merge but not override existing.
248
-        if (is_array($query_params) && isset($query_params[0])) {
249
-            $where_params = array_merge($query_params[0], $where_params);
250
-            unset($query_params[0]);
251
-        }
252
-        // now add $where_params to $query_params
253
-        $query_params[0] = $where_params;
254
-        return EEM_Ticket::instance()->get_all($query_params);
255
-    }
256
-
257
-
258
-    /**
259
-     * get all unexpired untrashed tickets
260
-     *
261
-     * @return EE_Ticket[]
262
-     * @throws EE_Error
263
-     */
264
-    public function active_tickets()
265
-    {
266
-        return $this->tickets(
267
-            array(
268
-                array(
269
-                    'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
270
-                    'TKT_deleted'  => false,
271
-                ),
272
-            )
273
-        );
274
-    }
275
-
276
-
277
-    /**
278
-     * @return bool
279
-     * @throws EE_Error
280
-     */
281
-    public function additional_limit()
282
-    {
283
-        return $this->get('EVT_additional_limit');
284
-    }
285
-
286
-
287
-    /**
288
-     * @return bool
289
-     * @throws EE_Error
290
-     */
291
-    public function allow_overflow()
292
-    {
293
-        return $this->get('EVT_allow_overflow');
294
-    }
295
-
296
-
297
-    /**
298
-     * @return bool
299
-     * @throws EE_Error
300
-     */
301
-    public function created()
302
-    {
303
-        return $this->get('EVT_created');
304
-    }
305
-
306
-
307
-    /**
308
-     * @return bool
309
-     * @throws EE_Error
310
-     */
311
-    public function description()
312
-    {
313
-        return $this->get('EVT_desc');
314
-    }
315
-
316
-
317
-    /**
318
-     * Runs do_shortcode and wpautop on the description
319
-     *
320
-     * @return string of html
321
-     * @throws EE_Error
322
-     */
323
-    public function description_filtered()
324
-    {
325
-        return $this->get_pretty('EVT_desc');
326
-    }
327
-
328
-
329
-    /**
330
-     * @return bool
331
-     * @throws EE_Error
332
-     */
333
-    public function display_description()
334
-    {
335
-        return $this->get('EVT_display_desc');
336
-    }
337
-
338
-
339
-    /**
340
-     * @return bool
341
-     * @throws EE_Error
342
-     */
343
-    public function display_ticket_selector()
344
-    {
345
-        return (bool) $this->get('EVT_display_ticket_selector');
346
-    }
347
-
348
-
349
-    /**
350
-     * @return bool
351
-     * @throws EE_Error
352
-     */
353
-    public function external_url()
354
-    {
355
-        return $this->get('EVT_external_URL');
356
-    }
357
-
358
-
359
-    /**
360
-     * @return bool
361
-     * @throws EE_Error
362
-     */
363
-    public function member_only()
364
-    {
365
-        return $this->get('EVT_member_only');
366
-    }
367
-
368
-
369
-    /**
370
-     * @return bool
371
-     * @throws EE_Error
372
-     */
373
-    public function phone()
374
-    {
375
-        return $this->get('EVT_phone');
376
-    }
377
-
378
-
379
-    /**
380
-     * @return bool
381
-     * @throws EE_Error
382
-     */
383
-    public function modified()
384
-    {
385
-        return $this->get('EVT_modified');
386
-    }
387
-
388
-
389
-    /**
390
-     * @return bool
391
-     * @throws EE_Error
392
-     */
393
-    public function name()
394
-    {
395
-        return $this->get('EVT_name');
396
-    }
397
-
398
-
399
-    /**
400
-     * @return bool
401
-     * @throws EE_Error
402
-     */
403
-    public function order()
404
-    {
405
-        return $this->get('EVT_order');
406
-    }
407
-
408
-
409
-    /**
410
-     * @return bool|string
411
-     * @throws EE_Error
412
-     */
413
-    public function default_registration_status()
414
-    {
415
-        $event_default_registration_status = $this->get('EVT_default_registration_status');
416
-        return ! empty($event_default_registration_status)
417
-            ? $event_default_registration_status
418
-            : EE_Registry::instance()->CFG->registration->default_STS_ID;
419
-    }
420
-
421
-
422
-    /**
423
-     * @param int  $num_words
424
-     * @param null $more
425
-     * @param bool $not_full_desc
426
-     * @return bool|string
427
-     * @throws EE_Error
428
-     */
429
-    public function short_description($num_words = 55, $more = null, $not_full_desc = false)
430
-    {
431
-        $short_desc = $this->get('EVT_short_desc');
432
-        if (! empty($short_desc) || $not_full_desc) {
433
-            return $short_desc;
434
-        }
435
-        $full_desc = $this->get('EVT_desc');
436
-        return wp_trim_words($full_desc, $num_words, $more);
437
-    }
438
-
439
-
440
-    /**
441
-     * @return bool
442
-     * @throws EE_Error
443
-     */
444
-    public function slug()
445
-    {
446
-        return $this->get('EVT_slug');
447
-    }
448
-
449
-
450
-    /**
451
-     * @return bool
452
-     * @throws EE_Error
453
-     */
454
-    public function timezone_string()
455
-    {
456
-        return $this->get('EVT_timezone_string');
457
-    }
458
-
459
-
460
-    /**
461
-     * @return bool
462
-     * @throws EE_Error
463
-     */
464
-    public function visible_on()
465
-    {
466
-        return $this->get('EVT_visible_on');
467
-    }
468
-
469
-
470
-    /**
471
-     * @return int
472
-     * @throws EE_Error
473
-     */
474
-    public function wp_user()
475
-    {
476
-        return $this->get('EVT_wp_user');
477
-    }
478
-
479
-
480
-    /**
481
-     * @return bool
482
-     * @throws EE_Error
483
-     */
484
-    public function donations()
485
-    {
486
-        return $this->get('EVT_donations');
487
-    }
488
-
489
-
490
-    /**
491
-     * @param $limit
492
-     * @throws EE_Error
493
-     */
494
-    public function set_additional_limit($limit)
495
-    {
496
-        $this->set('EVT_additional_limit', $limit);
497
-    }
498
-
499
-
500
-    /**
501
-     * @param $created
502
-     * @throws EE_Error
503
-     */
504
-    public function set_created($created)
505
-    {
506
-        $this->set('EVT_created', $created);
507
-    }
508
-
509
-
510
-    /**
511
-     * @param $desc
512
-     * @throws EE_Error
513
-     */
514
-    public function set_description($desc)
515
-    {
516
-        $this->set('EVT_desc', $desc);
517
-    }
518
-
519
-
520
-    /**
521
-     * @param $display_desc
522
-     * @throws EE_Error
523
-     */
524
-    public function set_display_description($display_desc)
525
-    {
526
-        $this->set('EVT_display_desc', $display_desc);
527
-    }
528
-
529
-
530
-    /**
531
-     * @param $display_ticket_selector
532
-     * @throws EE_Error
533
-     */
534
-    public function set_display_ticket_selector($display_ticket_selector)
535
-    {
536
-        $this->set('EVT_display_ticket_selector', $display_ticket_selector);
537
-    }
538
-
539
-
540
-    /**
541
-     * @param $external_url
542
-     * @throws EE_Error
543
-     */
544
-    public function set_external_url($external_url)
545
-    {
546
-        $this->set('EVT_external_URL', $external_url);
547
-    }
548
-
549
-
550
-    /**
551
-     * @param $member_only
552
-     * @throws EE_Error
553
-     */
554
-    public function set_member_only($member_only)
555
-    {
556
-        $this->set('EVT_member_only', $member_only);
557
-    }
558
-
559
-
560
-    /**
561
-     * @param $event_phone
562
-     * @throws EE_Error
563
-     */
564
-    public function set_event_phone($event_phone)
565
-    {
566
-        $this->set('EVT_phone', $event_phone);
567
-    }
568
-
569
-
570
-    /**
571
-     * @param $modified
572
-     * @throws EE_Error
573
-     */
574
-    public function set_modified($modified)
575
-    {
576
-        $this->set('EVT_modified', $modified);
577
-    }
578
-
579
-
580
-    /**
581
-     * @param $name
582
-     * @throws EE_Error
583
-     */
584
-    public function set_name($name)
585
-    {
586
-        $this->set('EVT_name', $name);
587
-    }
588
-
589
-
590
-    /**
591
-     * @param $order
592
-     * @throws EE_Error
593
-     */
594
-    public function set_order($order)
595
-    {
596
-        $this->set('EVT_order', $order);
597
-    }
598
-
599
-
600
-    /**
601
-     * @param $short_desc
602
-     * @throws EE_Error
603
-     */
604
-    public function set_short_description($short_desc)
605
-    {
606
-        $this->set('EVT_short_desc', $short_desc);
607
-    }
608
-
609
-
610
-    /**
611
-     * @param $slug
612
-     * @throws EE_Error
613
-     */
614
-    public function set_slug($slug)
615
-    {
616
-        $this->set('EVT_slug', $slug);
617
-    }
618
-
619
-
620
-    /**
621
-     * @param $timezone_string
622
-     * @throws EE_Error
623
-     */
624
-    public function set_timezone_string($timezone_string)
625
-    {
626
-        $this->set('EVT_timezone_string', $timezone_string);
627
-    }
628
-
629
-
630
-    /**
631
-     * @param $visible_on
632
-     * @throws EE_Error
633
-     */
634
-    public function set_visible_on($visible_on)
635
-    {
636
-        $this->set('EVT_visible_on', $visible_on);
637
-    }
638
-
639
-
640
-    /**
641
-     * @param $wp_user
642
-     * @throws EE_Error
643
-     */
644
-    public function set_wp_user($wp_user)
645
-    {
646
-        $this->set('EVT_wp_user', $wp_user);
647
-    }
648
-
649
-
650
-    /**
651
-     * @param $default_registration_status
652
-     * @throws EE_Error
653
-     */
654
-    public function set_default_registration_status($default_registration_status)
655
-    {
656
-        $this->set('EVT_default_registration_status', $default_registration_status);
657
-    }
658
-
659
-
660
-    /**
661
-     * @param $donations
662
-     * @throws EE_Error
663
-     */
664
-    public function set_donations($donations)
665
-    {
666
-        $this->set('EVT_donations', $donations);
667
-    }
668
-
669
-
670
-    /**
671
-     * Adds a venue to this event
672
-     *
673
-     * @param EE_Venue /int $venue_id_or_obj
674
-     * @return EE_Base_Class|EE_Venue
675
-     * @throws EE_Error
676
-     */
677
-    public function add_venue($venue_id_or_obj)
678
-    {
679
-        return $this->_add_relation_to($venue_id_or_obj, 'Venue');
680
-    }
681
-
682
-
683
-    /**
684
-     * Removes a venue from the event
685
-     *
686
-     * @param EE_Venue /int $venue_id_or_obj
687
-     * @return EE_Base_Class|EE_Venue
688
-     * @throws EE_Error
689
-     */
690
-    public function remove_venue($venue_id_or_obj)
691
-    {
692
-        return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
693
-    }
694
-
695
-
696
-    /**
697
-     * Gets all the venues related ot the event. May provide additional $query_params if desired
698
-     *
699
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
700
-     * @return EE_Base_Class[]|EE_Venue[]
701
-     * @throws EE_Error
702
-     */
703
-    public function venues($query_params = array())
704
-    {
705
-        return $this->get_many_related('Venue', $query_params);
706
-    }
707
-
708
-
709
-    /**
710
-     * check if event id is present and if event is published
711
-     *
712
-     * @access public
713
-     * @return boolean true yes, false no
714
-     * @throws EE_Error
715
-     */
716
-    private function _has_ID_and_is_published()
717
-    {
718
-        // first check if event id is present and not NULL,
719
-        // then check if this event is published (or any of the equivalent "published" statuses)
720
-        return
721
-            $this->ID() && $this->ID() !== null
722
-            && (
723
-                $this->status() === 'publish'
724
-                || $this->status() === EEM_Event::sold_out
725
-                || $this->status() === EEM_Event::postponed
726
-                || $this->status() === EEM_Event::cancelled
727
-            );
728
-    }
729
-
730
-
731
-    /**
732
-     * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
733
-     *
734
-     * @access public
735
-     * @return boolean true yes, false no
736
-     * @throws EE_Error
737
-     */
738
-    public function is_upcoming()
739
-    {
740
-        // check if event id is present and if this event is published
741
-        if ($this->is_inactive()) {
742
-            return false;
743
-        }
744
-        // set initial value
745
-        $upcoming = false;
746
-        // next let's get all datetimes and loop through them
747
-        $datetimes = $this->datetimes_in_chronological_order();
748
-        foreach ($datetimes as $datetime) {
749
-            if ($datetime instanceof EE_Datetime) {
750
-                // if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
751
-                if ($datetime->is_expired()) {
752
-                    continue;
753
-                }
754
-                // if this dtt is active then we return false.
755
-                if ($datetime->is_active()) {
756
-                    return false;
757
-                }
758
-                // otherwise let's check upcoming status
759
-                $upcoming = $datetime->is_upcoming();
760
-            }
761
-        }
762
-        return $upcoming;
763
-    }
764
-
765
-
766
-    /**
767
-     * @return bool
768
-     * @throws EE_Error
769
-     */
770
-    public function is_active()
771
-    {
772
-        // check if event id is present and if this event is published
773
-        if ($this->is_inactive()) {
774
-            return false;
775
-        }
776
-        // set initial value
777
-        $active = false;
778
-        // next let's get all datetimes and loop through them
779
-        $datetimes = $this->datetimes_in_chronological_order();
780
-        foreach ($datetimes as $datetime) {
781
-            if ($datetime instanceof EE_Datetime) {
782
-                // if this dtt is expired then we continue cause one of the other datetimes might be active.
783
-                if ($datetime->is_expired()) {
784
-                    continue;
785
-                }
786
-                // if this dtt is upcoming then we return false.
787
-                if ($datetime->is_upcoming()) {
788
-                    return false;
789
-                }
790
-                // otherwise let's check active status
791
-                $active = $datetime->is_active();
792
-            }
793
-        }
794
-        return $active;
795
-    }
796
-
797
-
798
-    /**
799
-     * @return bool
800
-     * @throws EE_Error
801
-     */
802
-    public function is_expired()
803
-    {
804
-        // check if event id is present and if this event is published
805
-        if ($this->is_inactive()) {
806
-            return false;
807
-        }
808
-        // set initial value
809
-        $expired = false;
810
-        // first let's get all datetimes and loop through them
811
-        $datetimes = $this->datetimes_in_chronological_order();
812
-        foreach ($datetimes as $datetime) {
813
-            if ($datetime instanceof EE_Datetime) {
814
-                // if this dtt is upcoming or active then we return false.
815
-                if ($datetime->is_upcoming() || $datetime->is_active()) {
816
-                    return false;
817
-                }
818
-                // otherwise let's check active status
819
-                $expired = $datetime->is_expired();
820
-            }
821
-        }
822
-        return $expired;
823
-    }
824
-
825
-
826
-    /**
827
-     * @return bool
828
-     * @throws EE_Error
829
-     */
830
-    public function is_inactive()
831
-    {
832
-        // check if event id is present and if this event is published
833
-        if ($this->_has_ID_and_is_published()) {
834
-            return false;
835
-        }
836
-        return true;
837
-    }
838
-
839
-
840
-    /**
841
-     * calculate spaces remaining based on "saleable" tickets
842
-     *
843
-     * @param array $tickets
844
-     * @param bool  $filtered
845
-     * @return int|float
846
-     * @throws EE_Error
847
-     * @throws DomainException
848
-     * @throws UnexpectedEntityException
849
-     */
850
-    public function spaces_remaining($tickets = array(), $filtered = true)
851
-    {
852
-        $this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
853
-        $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
854
-        return $filtered
855
-            ? apply_filters(
856
-                'FHEE_EE_Event__spaces_remaining',
857
-                $spaces_remaining,
858
-                $this,
859
-                $tickets
860
-            )
861
-            : $spaces_remaining;
862
-    }
863
-
864
-
865
-    /**
866
-     *    perform_sold_out_status_check
867
-     *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
868
-     *    available... if NOT, then the event status will get toggled to 'sold_out'
869
-     *
870
-     * @return bool    return the ACTUAL sold out state.
871
-     * @throws EE_Error
872
-     * @throws DomainException
873
-     * @throws UnexpectedEntityException
874
-     */
875
-    public function perform_sold_out_status_check()
876
-    {
877
-        // get all unexpired untrashed tickets
878
-        $tickets = $this->tickets(
879
-            array(
880
-                array('TKT_deleted' => false),
881
-                'order_by' => array('TKT_qty' => 'ASC'),
882
-            )
883
-        );
884
-        $all_expired = true;
885
-        foreach ($tickets as $ticket) {
886
-            if (! $ticket->is_expired()) {
887
-                $all_expired = false;
888
-                break;
889
-            }
890
-        }
891
-        // if all the tickets are just expired, then don't update the event status to sold out
892
-        if ($all_expired) {
893
-            return true;
894
-        }
895
-        $spaces_remaining = $this->spaces_remaining($tickets);
896
-        if ($spaces_remaining < 1) {
897
-            if ($this->status() !== EEM_Event::post_status_private) {
898
-                $this->set_status(EEM_Event::sold_out);
899
-                $this->save();
900
-            }
901
-            $sold_out = true;
902
-        } else {
903
-            $sold_out = false;
904
-            // was event previously marked as sold out ?
905
-            if ($this->status() === EEM_Event::sold_out) {
906
-                // revert status to previous value, if it was set
907
-                $previous_event_status = $this->get_post_meta('_previous_event_status', true);
908
-                if ($previous_event_status) {
909
-                    $this->set_status($previous_event_status);
910
-                    $this->save();
911
-                }
912
-            }
913
-        }
914
-        do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
915
-        return $sold_out;
916
-    }
917
-
918
-
919
-    /**
920
-     * This returns the total remaining spaces for sale on this event.
921
-     *
922
-     * @uses EE_Event::total_available_spaces()
923
-     * @return float|int
924
-     * @throws EE_Error
925
-     * @throws DomainException
926
-     * @throws UnexpectedEntityException
927
-     */
928
-    public function spaces_remaining_for_sale()
929
-    {
930
-        return $this->total_available_spaces(true);
931
-    }
932
-
933
-
934
-    /**
935
-     * This returns the total spaces available for an event
936
-     * while considering all the qtys on the tickets and the reg limits
937
-     * on the datetimes attached to this event.
938
-     *
939
-     * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
940
-     *                              If this is false, then we return the most tickets that could ever be sold
941
-     *                              for this event with the datetime and tickets setup on the event under optimal
942
-     *                              selling conditions.  Otherwise we return a live calculation of spaces available
943
-     *                              based on tickets sold.  Depending on setup and stage of sales, this
944
-     *                              may appear to equal remaining tickets.  However, the more tickets are
945
-     *                              sold out, the more accurate the "live" total is.
946
-     * @return float|int
947
-     * @throws EE_Error
948
-     * @throws DomainException
949
-     * @throws UnexpectedEntityException
950
-     */
951
-    public function total_available_spaces($consider_sold = false)
952
-    {
953
-        $spaces_available = $consider_sold
954
-            ? $this->getAvailableSpacesCalculator()->spacesRemaining()
955
-            : $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
956
-        return apply_filters(
957
-            'FHEE_EE_Event__total_available_spaces__spaces_available',
958
-            $spaces_available,
959
-            $this,
960
-            $this->getAvailableSpacesCalculator()->getDatetimes(),
961
-            $this->getAvailableSpacesCalculator()->getActiveTickets()
962
-        );
963
-    }
964
-
965
-
966
-    /**
967
-     * Checks if the event is set to sold out
968
-     *
969
-     * @param  bool $actual whether or not to perform calculations to not only figure the
970
-     *                      actual status but also to flip the status if necessary to sold
971
-     *                      out If false, we just check the existing status of the event
972
-     * @return boolean
973
-     * @throws EE_Error
974
-     */
975
-    public function is_sold_out($actual = false)
976
-    {
977
-        if (! $actual) {
978
-            return $this->status() === EEM_Event::sold_out;
979
-        }
980
-        return $this->perform_sold_out_status_check();
981
-    }
982
-
983
-
984
-    /**
985
-     * Checks if the event is marked as postponed
986
-     *
987
-     * @return boolean
988
-     */
989
-    public function is_postponed()
990
-    {
991
-        return $this->status() === EEM_Event::postponed;
992
-    }
993
-
994
-
995
-    /**
996
-     * Checks if the event is marked as cancelled
997
-     *
998
-     * @return boolean
999
-     */
1000
-    public function is_cancelled()
1001
-    {
1002
-        return $this->status() === EEM_Event::cancelled;
1003
-    }
1004
-
1005
-
1006
-    /**
1007
-     * Get the logical active status in a hierarchical order for all the datetimes.  Note
1008
-     * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1009
-     * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1010
-     * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1011
-     * the event is considered expired.
1012
-     * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1013
-     * status set on the EVENT when it is not published and thus is done
1014
-     *
1015
-     * @param bool $reset
1016
-     * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1017
-     * @throws EE_Error
1018
-     */
1019
-    public function get_active_status($reset = false)
1020
-    {
1021
-        // if the active status has already been set, then just use that value (unless we are resetting it)
1022
-        if (! empty($this->_active_status) && ! $reset) {
1023
-            return $this->_active_status;
1024
-        }
1025
-        // first check if event id is present on this object
1026
-        if (! $this->ID()) {
1027
-            return false;
1028
-        }
1029
-        $where_params_for_event = array(array('EVT_ID' => $this->ID()));
1030
-        // if event is published:
1031
-        if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1032
-            // active?
1033
-            if (EEM_Datetime::instance()->get_datetime_count_for_status(
1034
-                EE_Datetime::active,
1035
-                $where_params_for_event
1036
-            ) > 0) {
1037
-                $this->_active_status = EE_Datetime::active;
1038
-            } else {
1039
-                // upcoming?
1040
-                if (EEM_Datetime::instance()->get_datetime_count_for_status(
1041
-                    EE_Datetime::upcoming,
1042
-                    $where_params_for_event
1043
-                ) > 0) {
1044
-                    $this->_active_status = EE_Datetime::upcoming;
1045
-                } else {
1046
-                    // expired?
1047
-                    if (EEM_Datetime::instance()->get_datetime_count_for_status(
1048
-                        EE_Datetime::expired,
1049
-                        $where_params_for_event
1050
-                    ) > 0
1051
-                    ) {
1052
-                        $this->_active_status = EE_Datetime::expired;
1053
-                    } else {
1054
-                        // it would be odd if things make it this far because it basically means there are no datetime's
1055
-                        // attached to the event.  So in this case it will just be considered inactive.
1056
-                        $this->_active_status = EE_Datetime::inactive;
1057
-                    }
1058
-                }
1059
-            }
1060
-        } else {
1061
-            // the event is not published, so let's just set it's active status according to its' post status
1062
-            switch ($this->status()) {
1063
-                case EEM_Event::sold_out:
1064
-                    $this->_active_status = EE_Datetime::sold_out;
1065
-                    break;
1066
-                case EEM_Event::cancelled:
1067
-                    $this->_active_status = EE_Datetime::cancelled;
1068
-                    break;
1069
-                case EEM_Event::postponed:
1070
-                    $this->_active_status = EE_Datetime::postponed;
1071
-                    break;
1072
-                default:
1073
-                    $this->_active_status = EE_Datetime::inactive;
1074
-            }
1075
-        }
1076
-        return $this->_active_status;
1077
-    }
1078
-
1079
-
1080
-    /**
1081
-     *    pretty_active_status
1082
-     *
1083
-     * @access public
1084
-     * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1085
-     * @return mixed void|string
1086
-     * @throws EE_Error
1087
-     */
1088
-    public function pretty_active_status($echo = true)
1089
-    {
1090
-        $active_status = $this->get_active_status();
1091
-        $status = '<span class="ee-status event-active-status-'
1092
-                  . $active_status
1093
-                  . '">'
1094
-                  . EEH_Template::pretty_status($active_status, false, 'sentence')
1095
-                  . '</span>';
1096
-        if ($echo) {
1097
-            echo $status;
1098
-            return '';
1099
-        }
1100
-        return $status;
1101
-    }
1102
-
1103
-
1104
-    /**
1105
-     * @return bool|int
1106
-     * @throws EE_Error
1107
-     */
1108
-    public function get_number_of_tickets_sold()
1109
-    {
1110
-        $tkt_sold = 0;
1111
-        if (! $this->ID()) {
1112
-            return 0;
1113
-        }
1114
-        $datetimes = $this->datetimes();
1115
-        foreach ($datetimes as $datetime) {
1116
-            if ($datetime instanceof EE_Datetime) {
1117
-                $tkt_sold += $datetime->sold();
1118
-            }
1119
-        }
1120
-        return $tkt_sold;
1121
-    }
1122
-
1123
-
1124
-    /**
1125
-     * This just returns a count of all the registrations for this event
1126
-     *
1127
-     * @access  public
1128
-     * @return int
1129
-     * @throws EE_Error
1130
-     */
1131
-    public function get_count_of_all_registrations()
1132
-    {
1133
-        return EEM_Event::instance()->count_related($this, 'Registration');
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * This returns the ticket with the earliest start time that is
1139
-     * available for this event (across all datetimes attached to the event)
1140
-     *
1141
-     * @return EE_Base_Class|EE_Ticket|null
1142
-     * @throws EE_Error
1143
-     */
1144
-    public function get_ticket_with_earliest_start_time()
1145
-    {
1146
-        $where['Datetime.EVT_ID'] = $this->ID();
1147
-        $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1148
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1149
-    }
1150
-
1151
-
1152
-    /**
1153
-     * This returns the ticket with the latest end time that is available
1154
-     * for this event (across all datetimes attached to the event)
1155
-     *
1156
-     * @return EE_Base_Class|EE_Ticket|null
1157
-     * @throws EE_Error
1158
-     */
1159
-    public function get_ticket_with_latest_end_time()
1160
-    {
1161
-        $where['Datetime.EVT_ID'] = $this->ID();
1162
-        $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1163
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1164
-    }
1165
-
1166
-
1167
-    /**
1168
-     * This returns the number of different ticket types currently on sale for this event.
1169
-     *
1170
-     * @return int
1171
-     * @throws EE_Error
1172
-     */
1173
-    public function countTicketsOnSale()
1174
-    {
1175
-        $where = array(
1176
-            'Datetime.EVT_ID' => $this->ID(),
1177
-            'TKT_start_date'  => array('<', time()),
1178
-            'TKT_end_date'    => array('>', time()),
1179
-        );
1180
-        return EEM_Ticket::instance()->count(array($where));
1181
-    }
1182
-
1183
-
1184
-    /**
1185
-     * This returns whether there are any tickets on sale for this event.
1186
-     *
1187
-     * @return bool true = YES tickets on sale.
1188
-     * @throws EE_Error
1189
-     */
1190
-    public function tickets_on_sale()
1191
-    {
1192
-        return $this->countTicketsOnSale() > 0;
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * Gets the URL for viewing this event on the front-end. Overrides parent
1198
-     * to check for an external URL first
1199
-     *
1200
-     * @return string
1201
-     * @throws EE_Error
1202
-     */
1203
-    public function get_permalink()
1204
-    {
1205
-        if ($this->external_url()) {
1206
-            return $this->external_url();
1207
-        }
1208
-        return parent::get_permalink();
1209
-    }
1210
-
1211
-
1212
-    /**
1213
-     * Gets the first term for 'espresso_event_categories' we can find
1214
-     *
1215
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1216
-     * @return EE_Base_Class|EE_Term|null
1217
-     * @throws EE_Error
1218
-     */
1219
-    public function first_event_category($query_params = array())
1220
-    {
1221
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1222
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1223
-        return EEM_Term::instance()->get_one($query_params);
1224
-    }
1225
-
1226
-
1227
-    /**
1228
-     * Gets all terms for 'espresso_event_categories' we can find
1229
-     *
1230
-     * @param array $query_params
1231
-     * @return EE_Base_Class[]|EE_Term[]
1232
-     * @throws EE_Error
1233
-     */
1234
-    public function get_all_event_categories($query_params = array())
1235
-    {
1236
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1237
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1238
-        return EEM_Term::instance()->get_all($query_params);
1239
-    }
1240
-
1241
-
1242
-    /**
1243
-     * Adds a question group to this event
1244
-     *
1245
-     * @param EE_Question_Group|int $question_group_id_or_obj
1246
-     * @param bool $for_primary if true, the question group will be added for the primary
1247
-     *                                           registrant, if false will be added for others. default: false
1248
-     * @return EE_Base_Class|EE_Question_Group
1249
-     * @throws EE_Error
1250
-     * @throws InvalidArgumentException
1251
-     * @throws InvalidDataTypeException
1252
-     * @throws InvalidInterfaceException
1253
-     * @throws ReflectionException
1254
-     */
1255
-    public function add_question_group($question_group_id_or_obj, $for_primary = false)
1256
-    {
1257
-        // If the row already exists, it will be updated. If it doesn't, it will be inserted.
1258
-        // That's in EE_HABTM_Relation::add_relation_to().
1259
-        return $this->_add_relation_to(
1260
-            $question_group_id_or_obj,
1261
-            'Question_Group',
1262
-            [
1263
-                EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true
1264
-            ]
1265
-        );
1266
-    }
1267
-
1268
-
1269
-    /**
1270
-     * Removes a question group from the event
1271
-     *
1272
-     * @param EE_Question_Group|int $question_group_id_or_obj
1273
-     * @param bool $for_primary if true, the question group will be removed from the primary
1274
-     *                                           registrant, if false will be removed from others. default: false
1275
-     * @return EE_Base_Class|EE_Question_Group
1276
-     * @throws EE_Error
1277
-     * @throws InvalidArgumentException
1278
-     * @throws ReflectionException
1279
-     * @throws InvalidDataTypeException
1280
-     * @throws InvalidInterfaceException
1281
-     */
1282
-    public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1283
-    {
1284
-        // If the question group is used for the other type (primary or additional)
1285
-        // then just update it. If not, delete it outright.
1286
-        $existing_relation = $this->get_first_related(
1287
-            'Event_Question_Group',
1288
-            [
1289
-                [
1290
-                    'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj)
1291
-                ]
1292
-            ]
1293
-        );
1294
-        $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary);
1295
-        $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary);
1296
-        if ($existing_relation->get($other_field) === false) {
1297
-            // Delete it. It's now no longer for primary or additional question groups.
1298
-            return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group');
1299
-        }
1300
-        // Just update it. They'll still use this question group for the other category
1301
-        $existing_relation->save(
1302
-            [
1303
-                $field_to_update => false
1304
-            ]
1305
-        );
1306
-    }
1307
-
1308
-
1309
-    /**
1310
-     * Gets all the question groups, ordering them by QSG_order ascending
1311
-     *
1312
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1313
-     * @return EE_Base_Class[]|EE_Question_Group[]
1314
-     * @throws EE_Error
1315
-     */
1316
-    public function question_groups($query_params = array())
1317
-    {
1318
-        $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1319
-        return $this->get_many_related('Question_Group', $query_params);
1320
-    }
1321
-
1322
-
1323
-    /**
1324
-     * Implementation for EEI_Has_Icon interface method.
1325
-     *
1326
-     * @see EEI_Visual_Representation for comments
1327
-     * @return string
1328
-     */
1329
-    public function get_icon()
1330
-    {
1331
-        return '<span class="dashicons dashicons-flag"></span>';
1332
-    }
1333
-
1334
-
1335
-    /**
1336
-     * Implementation for EEI_Admin_Links interface method.
1337
-     *
1338
-     * @see EEI_Admin_Links for comments
1339
-     * @return string
1340
-     * @throws EE_Error
1341
-     */
1342
-    public function get_admin_details_link()
1343
-    {
1344
-        return $this->get_admin_edit_link();
1345
-    }
1346
-
1347
-
1348
-    /**
1349
-     * Implementation for EEI_Admin_Links interface method.
1350
-     *
1351
-     * @see EEI_Admin_Links for comments
1352
-     * @return string
1353
-     * @throws EE_Error
1354
-     */
1355
-    public function get_admin_edit_link()
1356
-    {
1357
-        return EEH_URL::add_query_args_and_nonce(
1358
-            array(
1359
-                'page'   => 'espresso_events',
1360
-                'action' => 'edit',
1361
-                'post'   => $this->ID(),
1362
-            ),
1363
-            admin_url('admin.php')
1364
-        );
1365
-    }
1366
-
1367
-
1368
-    /**
1369
-     * Implementation for EEI_Admin_Links interface method.
1370
-     *
1371
-     * @see EEI_Admin_Links for comments
1372
-     * @return string
1373
-     */
1374
-    public function get_admin_settings_link()
1375
-    {
1376
-        return EEH_URL::add_query_args_and_nonce(
1377
-            array(
1378
-                'page'   => 'espresso_events',
1379
-                'action' => 'default_event_settings',
1380
-            ),
1381
-            admin_url('admin.php')
1382
-        );
1383
-    }
1384
-
1385
-
1386
-    /**
1387
-     * Implementation for EEI_Admin_Links interface method.
1388
-     *
1389
-     * @see EEI_Admin_Links for comments
1390
-     * @return string
1391
-     */
1392
-    public function get_admin_overview_link()
1393
-    {
1394
-        return EEH_URL::add_query_args_and_nonce(
1395
-            array(
1396
-                'page'   => 'espresso_events',
1397
-                'action' => 'default',
1398
-            ),
1399
-            admin_url('admin.php')
1400
-        );
1401
-    }
18
+	/**
19
+	 * cached value for the the logical active status for the event
20
+	 *
21
+	 * @see get_active_status()
22
+	 * @var string
23
+	 */
24
+	protected $_active_status = '';
25
+
26
+	/**
27
+	 * This is just used for caching the Primary Datetime for the Event on initial retrieval
28
+	 *
29
+	 * @var EE_Datetime
30
+	 */
31
+	protected $_Primary_Datetime;
32
+
33
+	/**
34
+	 * @var EventSpacesCalculator $available_spaces_calculator
35
+	 */
36
+	protected $available_spaces_calculator;
37
+
38
+
39
+	/**
40
+	 * @param array  $props_n_values          incoming values
41
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
42
+	 *                                        used.)
43
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
44
+	 *                                        date_format and the second value is the time format
45
+	 * @return EE_Event
46
+	 * @throws EE_Error
47
+	 */
48
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
49
+	{
50
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
51
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @param array  $props_n_values  incoming values from the database
57
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
58
+	 *                                the website will be used.
59
+	 * @return EE_Event
60
+	 * @throws EE_Error
61
+	 */
62
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
63
+	{
64
+		return new self($props_n_values, true, $timezone);
65
+	}
66
+
67
+
68
+	/**
69
+	 * @return EventSpacesCalculator
70
+	 * @throws \EE_Error
71
+	 */
72
+	public function getAvailableSpacesCalculator()
73
+	{
74
+		if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
75
+			$this->available_spaces_calculator = new EventSpacesCalculator($this);
76
+		}
77
+		return $this->available_spaces_calculator;
78
+	}
79
+
80
+
81
+	/**
82
+	 * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
83
+	 *
84
+	 * @param string $field_name
85
+	 * @param mixed  $field_value
86
+	 * @param bool   $use_default
87
+	 * @throws EE_Error
88
+	 */
89
+	public function set($field_name, $field_value, $use_default = false)
90
+	{
91
+		switch ($field_name) {
92
+			case 'status':
93
+				$this->set_status($field_value, $use_default);
94
+				break;
95
+			default:
96
+				parent::set($field_name, $field_value, $use_default);
97
+		}
98
+	}
99
+
100
+
101
+	/**
102
+	 *    set_status
103
+	 * Checks if event status is being changed to SOLD OUT
104
+	 * and updates event meta data with previous event status
105
+	 * so that we can revert things if/when the event is no longer sold out
106
+	 *
107
+	 * @access public
108
+	 * @param string $new_status
109
+	 * @param bool   $use_default
110
+	 * @return void
111
+	 * @throws EE_Error
112
+	 */
113
+	public function set_status($new_status = null, $use_default = false)
114
+	{
115
+		// if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
116
+		if (empty($new_status) && ! $use_default) {
117
+			return;
118
+		}
119
+		// get current Event status
120
+		$old_status = $this->status();
121
+		// if status has changed
122
+		if ($old_status !== $new_status) {
123
+			// TO sold_out
124
+			if ($new_status === EEM_Event::sold_out) {
125
+				// save the previous event status so that we can revert if the event is no longer sold out
126
+				$this->add_post_meta('_previous_event_status', $old_status);
127
+				do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
128
+				// OR FROM  sold_out
129
+			} elseif ($old_status === EEM_Event::sold_out) {
130
+				$this->delete_post_meta('_previous_event_status');
131
+				do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
132
+			}
133
+			// clear out the active status so that it gets reset the next time it is requested
134
+			$this->_active_status = null;
135
+			// update status
136
+			parent::set('status', $new_status, $use_default);
137
+			do_action('AHEE__EE_Event__set_status__after_update', $this);
138
+			return;
139
+		}
140
+		// even though the old value matches the new value, it's still good to
141
+		// allow the parent set method to have a say
142
+		parent::set('status', $new_status, $use_default);
143
+	}
144
+
145
+
146
+	/**
147
+	 * Gets all the datetimes for this event
148
+	 *
149
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
150
+	 * @return EE_Base_Class[]|EE_Datetime[]
151
+	 * @throws EE_Error
152
+	 */
153
+	public function datetimes($query_params = array())
154
+	{
155
+		return $this->get_many_related('Datetime', $query_params);
156
+	}
157
+
158
+
159
+	/**
160
+	 * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
161
+	 *
162
+	 * @return EE_Base_Class[]|EE_Datetime[]
163
+	 * @throws EE_Error
164
+	 */
165
+	public function datetimes_in_chronological_order()
166
+	{
167
+		return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
168
+	}
169
+
170
+
171
+	/**
172
+	 * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
173
+	 * @darren, we should probably UNSET timezone on the EEM_Datetime model
174
+	 * after running our query, so that this timezone isn't set for EVERY query
175
+	 * on EEM_Datetime for the rest of the request, no?
176
+	 *
177
+	 * @param boolean $show_expired whether or not to include expired events
178
+	 * @param boolean $show_deleted whether or not to include deleted events
179
+	 * @param null    $limit
180
+	 * @return EE_Datetime[]
181
+	 * @throws EE_Error
182
+	 */
183
+	public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
184
+	{
185
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
186
+			$this->ID(),
187
+			$show_expired,
188
+			$show_deleted,
189
+			$limit
190
+		);
191
+	}
192
+
193
+
194
+	/**
195
+	 * Returns one related datetime. Mostly only used by some legacy code.
196
+	 *
197
+	 * @return EE_Base_Class|EE_Datetime
198
+	 * @throws EE_Error
199
+	 */
200
+	public function first_datetime()
201
+	{
202
+		return $this->get_first_related('Datetime');
203
+	}
204
+
205
+
206
+	/**
207
+	 * Returns the 'primary' datetime for the event
208
+	 *
209
+	 * @param bool $try_to_exclude_expired
210
+	 * @param bool $try_to_exclude_deleted
211
+	 * @return EE_Datetime
212
+	 * @throws EE_Error
213
+	 */
214
+	public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
215
+	{
216
+		if (! empty($this->_Primary_Datetime)) {
217
+			return $this->_Primary_Datetime;
218
+		}
219
+		$this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
220
+			$this->ID(),
221
+			$try_to_exclude_expired,
222
+			$try_to_exclude_deleted
223
+		);
224
+		return $this->_Primary_Datetime;
225
+	}
226
+
227
+
228
+	/**
229
+	 * Gets all the tickets available for purchase of this event
230
+	 *
231
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
232
+	 * @return EE_Base_Class[]|EE_Ticket[]
233
+	 * @throws EE_Error
234
+	 */
235
+	public function tickets($query_params = array())
236
+	{
237
+		// first get all datetimes
238
+		$datetimes = $this->datetimes_ordered();
239
+		if (! $datetimes) {
240
+			return array();
241
+		}
242
+		$datetime_ids = array();
243
+		foreach ($datetimes as $datetime) {
244
+			$datetime_ids[] = $datetime->ID();
245
+		}
246
+		$where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
247
+		// if incoming $query_params has where conditions let's merge but not override existing.
248
+		if (is_array($query_params) && isset($query_params[0])) {
249
+			$where_params = array_merge($query_params[0], $where_params);
250
+			unset($query_params[0]);
251
+		}
252
+		// now add $where_params to $query_params
253
+		$query_params[0] = $where_params;
254
+		return EEM_Ticket::instance()->get_all($query_params);
255
+	}
256
+
257
+
258
+	/**
259
+	 * get all unexpired untrashed tickets
260
+	 *
261
+	 * @return EE_Ticket[]
262
+	 * @throws EE_Error
263
+	 */
264
+	public function active_tickets()
265
+	{
266
+		return $this->tickets(
267
+			array(
268
+				array(
269
+					'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
270
+					'TKT_deleted'  => false,
271
+				),
272
+			)
273
+		);
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return bool
279
+	 * @throws EE_Error
280
+	 */
281
+	public function additional_limit()
282
+	{
283
+		return $this->get('EVT_additional_limit');
284
+	}
285
+
286
+
287
+	/**
288
+	 * @return bool
289
+	 * @throws EE_Error
290
+	 */
291
+	public function allow_overflow()
292
+	{
293
+		return $this->get('EVT_allow_overflow');
294
+	}
295
+
296
+
297
+	/**
298
+	 * @return bool
299
+	 * @throws EE_Error
300
+	 */
301
+	public function created()
302
+	{
303
+		return $this->get('EVT_created');
304
+	}
305
+
306
+
307
+	/**
308
+	 * @return bool
309
+	 * @throws EE_Error
310
+	 */
311
+	public function description()
312
+	{
313
+		return $this->get('EVT_desc');
314
+	}
315
+
316
+
317
+	/**
318
+	 * Runs do_shortcode and wpautop on the description
319
+	 *
320
+	 * @return string of html
321
+	 * @throws EE_Error
322
+	 */
323
+	public function description_filtered()
324
+	{
325
+		return $this->get_pretty('EVT_desc');
326
+	}
327
+
328
+
329
+	/**
330
+	 * @return bool
331
+	 * @throws EE_Error
332
+	 */
333
+	public function display_description()
334
+	{
335
+		return $this->get('EVT_display_desc');
336
+	}
337
+
338
+
339
+	/**
340
+	 * @return bool
341
+	 * @throws EE_Error
342
+	 */
343
+	public function display_ticket_selector()
344
+	{
345
+		return (bool) $this->get('EVT_display_ticket_selector');
346
+	}
347
+
348
+
349
+	/**
350
+	 * @return bool
351
+	 * @throws EE_Error
352
+	 */
353
+	public function external_url()
354
+	{
355
+		return $this->get('EVT_external_URL');
356
+	}
357
+
358
+
359
+	/**
360
+	 * @return bool
361
+	 * @throws EE_Error
362
+	 */
363
+	public function member_only()
364
+	{
365
+		return $this->get('EVT_member_only');
366
+	}
367
+
368
+
369
+	/**
370
+	 * @return bool
371
+	 * @throws EE_Error
372
+	 */
373
+	public function phone()
374
+	{
375
+		return $this->get('EVT_phone');
376
+	}
377
+
378
+
379
+	/**
380
+	 * @return bool
381
+	 * @throws EE_Error
382
+	 */
383
+	public function modified()
384
+	{
385
+		return $this->get('EVT_modified');
386
+	}
387
+
388
+
389
+	/**
390
+	 * @return bool
391
+	 * @throws EE_Error
392
+	 */
393
+	public function name()
394
+	{
395
+		return $this->get('EVT_name');
396
+	}
397
+
398
+
399
+	/**
400
+	 * @return bool
401
+	 * @throws EE_Error
402
+	 */
403
+	public function order()
404
+	{
405
+		return $this->get('EVT_order');
406
+	}
407
+
408
+
409
+	/**
410
+	 * @return bool|string
411
+	 * @throws EE_Error
412
+	 */
413
+	public function default_registration_status()
414
+	{
415
+		$event_default_registration_status = $this->get('EVT_default_registration_status');
416
+		return ! empty($event_default_registration_status)
417
+			? $event_default_registration_status
418
+			: EE_Registry::instance()->CFG->registration->default_STS_ID;
419
+	}
420
+
421
+
422
+	/**
423
+	 * @param int  $num_words
424
+	 * @param null $more
425
+	 * @param bool $not_full_desc
426
+	 * @return bool|string
427
+	 * @throws EE_Error
428
+	 */
429
+	public function short_description($num_words = 55, $more = null, $not_full_desc = false)
430
+	{
431
+		$short_desc = $this->get('EVT_short_desc');
432
+		if (! empty($short_desc) || $not_full_desc) {
433
+			return $short_desc;
434
+		}
435
+		$full_desc = $this->get('EVT_desc');
436
+		return wp_trim_words($full_desc, $num_words, $more);
437
+	}
438
+
439
+
440
+	/**
441
+	 * @return bool
442
+	 * @throws EE_Error
443
+	 */
444
+	public function slug()
445
+	{
446
+		return $this->get('EVT_slug');
447
+	}
448
+
449
+
450
+	/**
451
+	 * @return bool
452
+	 * @throws EE_Error
453
+	 */
454
+	public function timezone_string()
455
+	{
456
+		return $this->get('EVT_timezone_string');
457
+	}
458
+
459
+
460
+	/**
461
+	 * @return bool
462
+	 * @throws EE_Error
463
+	 */
464
+	public function visible_on()
465
+	{
466
+		return $this->get('EVT_visible_on');
467
+	}
468
+
469
+
470
+	/**
471
+	 * @return int
472
+	 * @throws EE_Error
473
+	 */
474
+	public function wp_user()
475
+	{
476
+		return $this->get('EVT_wp_user');
477
+	}
478
+
479
+
480
+	/**
481
+	 * @return bool
482
+	 * @throws EE_Error
483
+	 */
484
+	public function donations()
485
+	{
486
+		return $this->get('EVT_donations');
487
+	}
488
+
489
+
490
+	/**
491
+	 * @param $limit
492
+	 * @throws EE_Error
493
+	 */
494
+	public function set_additional_limit($limit)
495
+	{
496
+		$this->set('EVT_additional_limit', $limit);
497
+	}
498
+
499
+
500
+	/**
501
+	 * @param $created
502
+	 * @throws EE_Error
503
+	 */
504
+	public function set_created($created)
505
+	{
506
+		$this->set('EVT_created', $created);
507
+	}
508
+
509
+
510
+	/**
511
+	 * @param $desc
512
+	 * @throws EE_Error
513
+	 */
514
+	public function set_description($desc)
515
+	{
516
+		$this->set('EVT_desc', $desc);
517
+	}
518
+
519
+
520
+	/**
521
+	 * @param $display_desc
522
+	 * @throws EE_Error
523
+	 */
524
+	public function set_display_description($display_desc)
525
+	{
526
+		$this->set('EVT_display_desc', $display_desc);
527
+	}
528
+
529
+
530
+	/**
531
+	 * @param $display_ticket_selector
532
+	 * @throws EE_Error
533
+	 */
534
+	public function set_display_ticket_selector($display_ticket_selector)
535
+	{
536
+		$this->set('EVT_display_ticket_selector', $display_ticket_selector);
537
+	}
538
+
539
+
540
+	/**
541
+	 * @param $external_url
542
+	 * @throws EE_Error
543
+	 */
544
+	public function set_external_url($external_url)
545
+	{
546
+		$this->set('EVT_external_URL', $external_url);
547
+	}
548
+
549
+
550
+	/**
551
+	 * @param $member_only
552
+	 * @throws EE_Error
553
+	 */
554
+	public function set_member_only($member_only)
555
+	{
556
+		$this->set('EVT_member_only', $member_only);
557
+	}
558
+
559
+
560
+	/**
561
+	 * @param $event_phone
562
+	 * @throws EE_Error
563
+	 */
564
+	public function set_event_phone($event_phone)
565
+	{
566
+		$this->set('EVT_phone', $event_phone);
567
+	}
568
+
569
+
570
+	/**
571
+	 * @param $modified
572
+	 * @throws EE_Error
573
+	 */
574
+	public function set_modified($modified)
575
+	{
576
+		$this->set('EVT_modified', $modified);
577
+	}
578
+
579
+
580
+	/**
581
+	 * @param $name
582
+	 * @throws EE_Error
583
+	 */
584
+	public function set_name($name)
585
+	{
586
+		$this->set('EVT_name', $name);
587
+	}
588
+
589
+
590
+	/**
591
+	 * @param $order
592
+	 * @throws EE_Error
593
+	 */
594
+	public function set_order($order)
595
+	{
596
+		$this->set('EVT_order', $order);
597
+	}
598
+
599
+
600
+	/**
601
+	 * @param $short_desc
602
+	 * @throws EE_Error
603
+	 */
604
+	public function set_short_description($short_desc)
605
+	{
606
+		$this->set('EVT_short_desc', $short_desc);
607
+	}
608
+
609
+
610
+	/**
611
+	 * @param $slug
612
+	 * @throws EE_Error
613
+	 */
614
+	public function set_slug($slug)
615
+	{
616
+		$this->set('EVT_slug', $slug);
617
+	}
618
+
619
+
620
+	/**
621
+	 * @param $timezone_string
622
+	 * @throws EE_Error
623
+	 */
624
+	public function set_timezone_string($timezone_string)
625
+	{
626
+		$this->set('EVT_timezone_string', $timezone_string);
627
+	}
628
+
629
+
630
+	/**
631
+	 * @param $visible_on
632
+	 * @throws EE_Error
633
+	 */
634
+	public function set_visible_on($visible_on)
635
+	{
636
+		$this->set('EVT_visible_on', $visible_on);
637
+	}
638
+
639
+
640
+	/**
641
+	 * @param $wp_user
642
+	 * @throws EE_Error
643
+	 */
644
+	public function set_wp_user($wp_user)
645
+	{
646
+		$this->set('EVT_wp_user', $wp_user);
647
+	}
648
+
649
+
650
+	/**
651
+	 * @param $default_registration_status
652
+	 * @throws EE_Error
653
+	 */
654
+	public function set_default_registration_status($default_registration_status)
655
+	{
656
+		$this->set('EVT_default_registration_status', $default_registration_status);
657
+	}
658
+
659
+
660
+	/**
661
+	 * @param $donations
662
+	 * @throws EE_Error
663
+	 */
664
+	public function set_donations($donations)
665
+	{
666
+		$this->set('EVT_donations', $donations);
667
+	}
668
+
669
+
670
+	/**
671
+	 * Adds a venue to this event
672
+	 *
673
+	 * @param EE_Venue /int $venue_id_or_obj
674
+	 * @return EE_Base_Class|EE_Venue
675
+	 * @throws EE_Error
676
+	 */
677
+	public function add_venue($venue_id_or_obj)
678
+	{
679
+		return $this->_add_relation_to($venue_id_or_obj, 'Venue');
680
+	}
681
+
682
+
683
+	/**
684
+	 * Removes a venue from the event
685
+	 *
686
+	 * @param EE_Venue /int $venue_id_or_obj
687
+	 * @return EE_Base_Class|EE_Venue
688
+	 * @throws EE_Error
689
+	 */
690
+	public function remove_venue($venue_id_or_obj)
691
+	{
692
+		return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
693
+	}
694
+
695
+
696
+	/**
697
+	 * Gets all the venues related ot the event. May provide additional $query_params if desired
698
+	 *
699
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
700
+	 * @return EE_Base_Class[]|EE_Venue[]
701
+	 * @throws EE_Error
702
+	 */
703
+	public function venues($query_params = array())
704
+	{
705
+		return $this->get_many_related('Venue', $query_params);
706
+	}
707
+
708
+
709
+	/**
710
+	 * check if event id is present and if event is published
711
+	 *
712
+	 * @access public
713
+	 * @return boolean true yes, false no
714
+	 * @throws EE_Error
715
+	 */
716
+	private function _has_ID_and_is_published()
717
+	{
718
+		// first check if event id is present and not NULL,
719
+		// then check if this event is published (or any of the equivalent "published" statuses)
720
+		return
721
+			$this->ID() && $this->ID() !== null
722
+			&& (
723
+				$this->status() === 'publish'
724
+				|| $this->status() === EEM_Event::sold_out
725
+				|| $this->status() === EEM_Event::postponed
726
+				|| $this->status() === EEM_Event::cancelled
727
+			);
728
+	}
729
+
730
+
731
+	/**
732
+	 * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
733
+	 *
734
+	 * @access public
735
+	 * @return boolean true yes, false no
736
+	 * @throws EE_Error
737
+	 */
738
+	public function is_upcoming()
739
+	{
740
+		// check if event id is present and if this event is published
741
+		if ($this->is_inactive()) {
742
+			return false;
743
+		}
744
+		// set initial value
745
+		$upcoming = false;
746
+		// next let's get all datetimes and loop through them
747
+		$datetimes = $this->datetimes_in_chronological_order();
748
+		foreach ($datetimes as $datetime) {
749
+			if ($datetime instanceof EE_Datetime) {
750
+				// if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
751
+				if ($datetime->is_expired()) {
752
+					continue;
753
+				}
754
+				// if this dtt is active then we return false.
755
+				if ($datetime->is_active()) {
756
+					return false;
757
+				}
758
+				// otherwise let's check upcoming status
759
+				$upcoming = $datetime->is_upcoming();
760
+			}
761
+		}
762
+		return $upcoming;
763
+	}
764
+
765
+
766
+	/**
767
+	 * @return bool
768
+	 * @throws EE_Error
769
+	 */
770
+	public function is_active()
771
+	{
772
+		// check if event id is present and if this event is published
773
+		if ($this->is_inactive()) {
774
+			return false;
775
+		}
776
+		// set initial value
777
+		$active = false;
778
+		// next let's get all datetimes and loop through them
779
+		$datetimes = $this->datetimes_in_chronological_order();
780
+		foreach ($datetimes as $datetime) {
781
+			if ($datetime instanceof EE_Datetime) {
782
+				// if this dtt is expired then we continue cause one of the other datetimes might be active.
783
+				if ($datetime->is_expired()) {
784
+					continue;
785
+				}
786
+				// if this dtt is upcoming then we return false.
787
+				if ($datetime->is_upcoming()) {
788
+					return false;
789
+				}
790
+				// otherwise let's check active status
791
+				$active = $datetime->is_active();
792
+			}
793
+		}
794
+		return $active;
795
+	}
796
+
797
+
798
+	/**
799
+	 * @return bool
800
+	 * @throws EE_Error
801
+	 */
802
+	public function is_expired()
803
+	{
804
+		// check if event id is present and if this event is published
805
+		if ($this->is_inactive()) {
806
+			return false;
807
+		}
808
+		// set initial value
809
+		$expired = false;
810
+		// first let's get all datetimes and loop through them
811
+		$datetimes = $this->datetimes_in_chronological_order();
812
+		foreach ($datetimes as $datetime) {
813
+			if ($datetime instanceof EE_Datetime) {
814
+				// if this dtt is upcoming or active then we return false.
815
+				if ($datetime->is_upcoming() || $datetime->is_active()) {
816
+					return false;
817
+				}
818
+				// otherwise let's check active status
819
+				$expired = $datetime->is_expired();
820
+			}
821
+		}
822
+		return $expired;
823
+	}
824
+
825
+
826
+	/**
827
+	 * @return bool
828
+	 * @throws EE_Error
829
+	 */
830
+	public function is_inactive()
831
+	{
832
+		// check if event id is present and if this event is published
833
+		if ($this->_has_ID_and_is_published()) {
834
+			return false;
835
+		}
836
+		return true;
837
+	}
838
+
839
+
840
+	/**
841
+	 * calculate spaces remaining based on "saleable" tickets
842
+	 *
843
+	 * @param array $tickets
844
+	 * @param bool  $filtered
845
+	 * @return int|float
846
+	 * @throws EE_Error
847
+	 * @throws DomainException
848
+	 * @throws UnexpectedEntityException
849
+	 */
850
+	public function spaces_remaining($tickets = array(), $filtered = true)
851
+	{
852
+		$this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
853
+		$spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
854
+		return $filtered
855
+			? apply_filters(
856
+				'FHEE_EE_Event__spaces_remaining',
857
+				$spaces_remaining,
858
+				$this,
859
+				$tickets
860
+			)
861
+			: $spaces_remaining;
862
+	}
863
+
864
+
865
+	/**
866
+	 *    perform_sold_out_status_check
867
+	 *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
868
+	 *    available... if NOT, then the event status will get toggled to 'sold_out'
869
+	 *
870
+	 * @return bool    return the ACTUAL sold out state.
871
+	 * @throws EE_Error
872
+	 * @throws DomainException
873
+	 * @throws UnexpectedEntityException
874
+	 */
875
+	public function perform_sold_out_status_check()
876
+	{
877
+		// get all unexpired untrashed tickets
878
+		$tickets = $this->tickets(
879
+			array(
880
+				array('TKT_deleted' => false),
881
+				'order_by' => array('TKT_qty' => 'ASC'),
882
+			)
883
+		);
884
+		$all_expired = true;
885
+		foreach ($tickets as $ticket) {
886
+			if (! $ticket->is_expired()) {
887
+				$all_expired = false;
888
+				break;
889
+			}
890
+		}
891
+		// if all the tickets are just expired, then don't update the event status to sold out
892
+		if ($all_expired) {
893
+			return true;
894
+		}
895
+		$spaces_remaining = $this->spaces_remaining($tickets);
896
+		if ($spaces_remaining < 1) {
897
+			if ($this->status() !== EEM_Event::post_status_private) {
898
+				$this->set_status(EEM_Event::sold_out);
899
+				$this->save();
900
+			}
901
+			$sold_out = true;
902
+		} else {
903
+			$sold_out = false;
904
+			// was event previously marked as sold out ?
905
+			if ($this->status() === EEM_Event::sold_out) {
906
+				// revert status to previous value, if it was set
907
+				$previous_event_status = $this->get_post_meta('_previous_event_status', true);
908
+				if ($previous_event_status) {
909
+					$this->set_status($previous_event_status);
910
+					$this->save();
911
+				}
912
+			}
913
+		}
914
+		do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
915
+		return $sold_out;
916
+	}
917
+
918
+
919
+	/**
920
+	 * This returns the total remaining spaces for sale on this event.
921
+	 *
922
+	 * @uses EE_Event::total_available_spaces()
923
+	 * @return float|int
924
+	 * @throws EE_Error
925
+	 * @throws DomainException
926
+	 * @throws UnexpectedEntityException
927
+	 */
928
+	public function spaces_remaining_for_sale()
929
+	{
930
+		return $this->total_available_spaces(true);
931
+	}
932
+
933
+
934
+	/**
935
+	 * This returns the total spaces available for an event
936
+	 * while considering all the qtys on the tickets and the reg limits
937
+	 * on the datetimes attached to this event.
938
+	 *
939
+	 * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
940
+	 *                              If this is false, then we return the most tickets that could ever be sold
941
+	 *                              for this event with the datetime and tickets setup on the event under optimal
942
+	 *                              selling conditions.  Otherwise we return a live calculation of spaces available
943
+	 *                              based on tickets sold.  Depending on setup and stage of sales, this
944
+	 *                              may appear to equal remaining tickets.  However, the more tickets are
945
+	 *                              sold out, the more accurate the "live" total is.
946
+	 * @return float|int
947
+	 * @throws EE_Error
948
+	 * @throws DomainException
949
+	 * @throws UnexpectedEntityException
950
+	 */
951
+	public function total_available_spaces($consider_sold = false)
952
+	{
953
+		$spaces_available = $consider_sold
954
+			? $this->getAvailableSpacesCalculator()->spacesRemaining()
955
+			: $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
956
+		return apply_filters(
957
+			'FHEE_EE_Event__total_available_spaces__spaces_available',
958
+			$spaces_available,
959
+			$this,
960
+			$this->getAvailableSpacesCalculator()->getDatetimes(),
961
+			$this->getAvailableSpacesCalculator()->getActiveTickets()
962
+		);
963
+	}
964
+
965
+
966
+	/**
967
+	 * Checks if the event is set to sold out
968
+	 *
969
+	 * @param  bool $actual whether or not to perform calculations to not only figure the
970
+	 *                      actual status but also to flip the status if necessary to sold
971
+	 *                      out If false, we just check the existing status of the event
972
+	 * @return boolean
973
+	 * @throws EE_Error
974
+	 */
975
+	public function is_sold_out($actual = false)
976
+	{
977
+		if (! $actual) {
978
+			return $this->status() === EEM_Event::sold_out;
979
+		}
980
+		return $this->perform_sold_out_status_check();
981
+	}
982
+
983
+
984
+	/**
985
+	 * Checks if the event is marked as postponed
986
+	 *
987
+	 * @return boolean
988
+	 */
989
+	public function is_postponed()
990
+	{
991
+		return $this->status() === EEM_Event::postponed;
992
+	}
993
+
994
+
995
+	/**
996
+	 * Checks if the event is marked as cancelled
997
+	 *
998
+	 * @return boolean
999
+	 */
1000
+	public function is_cancelled()
1001
+	{
1002
+		return $this->status() === EEM_Event::cancelled;
1003
+	}
1004
+
1005
+
1006
+	/**
1007
+	 * Get the logical active status in a hierarchical order for all the datetimes.  Note
1008
+	 * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1009
+	 * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1010
+	 * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1011
+	 * the event is considered expired.
1012
+	 * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1013
+	 * status set on the EVENT when it is not published and thus is done
1014
+	 *
1015
+	 * @param bool $reset
1016
+	 * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1017
+	 * @throws EE_Error
1018
+	 */
1019
+	public function get_active_status($reset = false)
1020
+	{
1021
+		// if the active status has already been set, then just use that value (unless we are resetting it)
1022
+		if (! empty($this->_active_status) && ! $reset) {
1023
+			return $this->_active_status;
1024
+		}
1025
+		// first check if event id is present on this object
1026
+		if (! $this->ID()) {
1027
+			return false;
1028
+		}
1029
+		$where_params_for_event = array(array('EVT_ID' => $this->ID()));
1030
+		// if event is published:
1031
+		if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1032
+			// active?
1033
+			if (EEM_Datetime::instance()->get_datetime_count_for_status(
1034
+				EE_Datetime::active,
1035
+				$where_params_for_event
1036
+			) > 0) {
1037
+				$this->_active_status = EE_Datetime::active;
1038
+			} else {
1039
+				// upcoming?
1040
+				if (EEM_Datetime::instance()->get_datetime_count_for_status(
1041
+					EE_Datetime::upcoming,
1042
+					$where_params_for_event
1043
+				) > 0) {
1044
+					$this->_active_status = EE_Datetime::upcoming;
1045
+				} else {
1046
+					// expired?
1047
+					if (EEM_Datetime::instance()->get_datetime_count_for_status(
1048
+						EE_Datetime::expired,
1049
+						$where_params_for_event
1050
+					) > 0
1051
+					) {
1052
+						$this->_active_status = EE_Datetime::expired;
1053
+					} else {
1054
+						// it would be odd if things make it this far because it basically means there are no datetime's
1055
+						// attached to the event.  So in this case it will just be considered inactive.
1056
+						$this->_active_status = EE_Datetime::inactive;
1057
+					}
1058
+				}
1059
+			}
1060
+		} else {
1061
+			// the event is not published, so let's just set it's active status according to its' post status
1062
+			switch ($this->status()) {
1063
+				case EEM_Event::sold_out:
1064
+					$this->_active_status = EE_Datetime::sold_out;
1065
+					break;
1066
+				case EEM_Event::cancelled:
1067
+					$this->_active_status = EE_Datetime::cancelled;
1068
+					break;
1069
+				case EEM_Event::postponed:
1070
+					$this->_active_status = EE_Datetime::postponed;
1071
+					break;
1072
+				default:
1073
+					$this->_active_status = EE_Datetime::inactive;
1074
+			}
1075
+		}
1076
+		return $this->_active_status;
1077
+	}
1078
+
1079
+
1080
+	/**
1081
+	 *    pretty_active_status
1082
+	 *
1083
+	 * @access public
1084
+	 * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1085
+	 * @return mixed void|string
1086
+	 * @throws EE_Error
1087
+	 */
1088
+	public function pretty_active_status($echo = true)
1089
+	{
1090
+		$active_status = $this->get_active_status();
1091
+		$status = '<span class="ee-status event-active-status-'
1092
+				  . $active_status
1093
+				  . '">'
1094
+				  . EEH_Template::pretty_status($active_status, false, 'sentence')
1095
+				  . '</span>';
1096
+		if ($echo) {
1097
+			echo $status;
1098
+			return '';
1099
+		}
1100
+		return $status;
1101
+	}
1102
+
1103
+
1104
+	/**
1105
+	 * @return bool|int
1106
+	 * @throws EE_Error
1107
+	 */
1108
+	public function get_number_of_tickets_sold()
1109
+	{
1110
+		$tkt_sold = 0;
1111
+		if (! $this->ID()) {
1112
+			return 0;
1113
+		}
1114
+		$datetimes = $this->datetimes();
1115
+		foreach ($datetimes as $datetime) {
1116
+			if ($datetime instanceof EE_Datetime) {
1117
+				$tkt_sold += $datetime->sold();
1118
+			}
1119
+		}
1120
+		return $tkt_sold;
1121
+	}
1122
+
1123
+
1124
+	/**
1125
+	 * This just returns a count of all the registrations for this event
1126
+	 *
1127
+	 * @access  public
1128
+	 * @return int
1129
+	 * @throws EE_Error
1130
+	 */
1131
+	public function get_count_of_all_registrations()
1132
+	{
1133
+		return EEM_Event::instance()->count_related($this, 'Registration');
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * This returns the ticket with the earliest start time that is
1139
+	 * available for this event (across all datetimes attached to the event)
1140
+	 *
1141
+	 * @return EE_Base_Class|EE_Ticket|null
1142
+	 * @throws EE_Error
1143
+	 */
1144
+	public function get_ticket_with_earliest_start_time()
1145
+	{
1146
+		$where['Datetime.EVT_ID'] = $this->ID();
1147
+		$query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1148
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1149
+	}
1150
+
1151
+
1152
+	/**
1153
+	 * This returns the ticket with the latest end time that is available
1154
+	 * for this event (across all datetimes attached to the event)
1155
+	 *
1156
+	 * @return EE_Base_Class|EE_Ticket|null
1157
+	 * @throws EE_Error
1158
+	 */
1159
+	public function get_ticket_with_latest_end_time()
1160
+	{
1161
+		$where['Datetime.EVT_ID'] = $this->ID();
1162
+		$query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1163
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1164
+	}
1165
+
1166
+
1167
+	/**
1168
+	 * This returns the number of different ticket types currently on sale for this event.
1169
+	 *
1170
+	 * @return int
1171
+	 * @throws EE_Error
1172
+	 */
1173
+	public function countTicketsOnSale()
1174
+	{
1175
+		$where = array(
1176
+			'Datetime.EVT_ID' => $this->ID(),
1177
+			'TKT_start_date'  => array('<', time()),
1178
+			'TKT_end_date'    => array('>', time()),
1179
+		);
1180
+		return EEM_Ticket::instance()->count(array($where));
1181
+	}
1182
+
1183
+
1184
+	/**
1185
+	 * This returns whether there are any tickets on sale for this event.
1186
+	 *
1187
+	 * @return bool true = YES tickets on sale.
1188
+	 * @throws EE_Error
1189
+	 */
1190
+	public function tickets_on_sale()
1191
+	{
1192
+		return $this->countTicketsOnSale() > 0;
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * Gets the URL for viewing this event on the front-end. Overrides parent
1198
+	 * to check for an external URL first
1199
+	 *
1200
+	 * @return string
1201
+	 * @throws EE_Error
1202
+	 */
1203
+	public function get_permalink()
1204
+	{
1205
+		if ($this->external_url()) {
1206
+			return $this->external_url();
1207
+		}
1208
+		return parent::get_permalink();
1209
+	}
1210
+
1211
+
1212
+	/**
1213
+	 * Gets the first term for 'espresso_event_categories' we can find
1214
+	 *
1215
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1216
+	 * @return EE_Base_Class|EE_Term|null
1217
+	 * @throws EE_Error
1218
+	 */
1219
+	public function first_event_category($query_params = array())
1220
+	{
1221
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1222
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1223
+		return EEM_Term::instance()->get_one($query_params);
1224
+	}
1225
+
1226
+
1227
+	/**
1228
+	 * Gets all terms for 'espresso_event_categories' we can find
1229
+	 *
1230
+	 * @param array $query_params
1231
+	 * @return EE_Base_Class[]|EE_Term[]
1232
+	 * @throws EE_Error
1233
+	 */
1234
+	public function get_all_event_categories($query_params = array())
1235
+	{
1236
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1237
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1238
+		return EEM_Term::instance()->get_all($query_params);
1239
+	}
1240
+
1241
+
1242
+	/**
1243
+	 * Adds a question group to this event
1244
+	 *
1245
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1246
+	 * @param bool $for_primary if true, the question group will be added for the primary
1247
+	 *                                           registrant, if false will be added for others. default: false
1248
+	 * @return EE_Base_Class|EE_Question_Group
1249
+	 * @throws EE_Error
1250
+	 * @throws InvalidArgumentException
1251
+	 * @throws InvalidDataTypeException
1252
+	 * @throws InvalidInterfaceException
1253
+	 * @throws ReflectionException
1254
+	 */
1255
+	public function add_question_group($question_group_id_or_obj, $for_primary = false)
1256
+	{
1257
+		// If the row already exists, it will be updated. If it doesn't, it will be inserted.
1258
+		// That's in EE_HABTM_Relation::add_relation_to().
1259
+		return $this->_add_relation_to(
1260
+			$question_group_id_or_obj,
1261
+			'Question_Group',
1262
+			[
1263
+				EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true
1264
+			]
1265
+		);
1266
+	}
1267
+
1268
+
1269
+	/**
1270
+	 * Removes a question group from the event
1271
+	 *
1272
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1273
+	 * @param bool $for_primary if true, the question group will be removed from the primary
1274
+	 *                                           registrant, if false will be removed from others. default: false
1275
+	 * @return EE_Base_Class|EE_Question_Group
1276
+	 * @throws EE_Error
1277
+	 * @throws InvalidArgumentException
1278
+	 * @throws ReflectionException
1279
+	 * @throws InvalidDataTypeException
1280
+	 * @throws InvalidInterfaceException
1281
+	 */
1282
+	public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1283
+	{
1284
+		// If the question group is used for the other type (primary or additional)
1285
+		// then just update it. If not, delete it outright.
1286
+		$existing_relation = $this->get_first_related(
1287
+			'Event_Question_Group',
1288
+			[
1289
+				[
1290
+					'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj)
1291
+				]
1292
+			]
1293
+		);
1294
+		$field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary);
1295
+		$other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary);
1296
+		if ($existing_relation->get($other_field) === false) {
1297
+			// Delete it. It's now no longer for primary or additional question groups.
1298
+			return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group');
1299
+		}
1300
+		// Just update it. They'll still use this question group for the other category
1301
+		$existing_relation->save(
1302
+			[
1303
+				$field_to_update => false
1304
+			]
1305
+		);
1306
+	}
1307
+
1308
+
1309
+	/**
1310
+	 * Gets all the question groups, ordering them by QSG_order ascending
1311
+	 *
1312
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1313
+	 * @return EE_Base_Class[]|EE_Question_Group[]
1314
+	 * @throws EE_Error
1315
+	 */
1316
+	public function question_groups($query_params = array())
1317
+	{
1318
+		$query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1319
+		return $this->get_many_related('Question_Group', $query_params);
1320
+	}
1321
+
1322
+
1323
+	/**
1324
+	 * Implementation for EEI_Has_Icon interface method.
1325
+	 *
1326
+	 * @see EEI_Visual_Representation for comments
1327
+	 * @return string
1328
+	 */
1329
+	public function get_icon()
1330
+	{
1331
+		return '<span class="dashicons dashicons-flag"></span>';
1332
+	}
1333
+
1334
+
1335
+	/**
1336
+	 * Implementation for EEI_Admin_Links interface method.
1337
+	 *
1338
+	 * @see EEI_Admin_Links for comments
1339
+	 * @return string
1340
+	 * @throws EE_Error
1341
+	 */
1342
+	public function get_admin_details_link()
1343
+	{
1344
+		return $this->get_admin_edit_link();
1345
+	}
1346
+
1347
+
1348
+	/**
1349
+	 * Implementation for EEI_Admin_Links interface method.
1350
+	 *
1351
+	 * @see EEI_Admin_Links for comments
1352
+	 * @return string
1353
+	 * @throws EE_Error
1354
+	 */
1355
+	public function get_admin_edit_link()
1356
+	{
1357
+		return EEH_URL::add_query_args_and_nonce(
1358
+			array(
1359
+				'page'   => 'espresso_events',
1360
+				'action' => 'edit',
1361
+				'post'   => $this->ID(),
1362
+			),
1363
+			admin_url('admin.php')
1364
+		);
1365
+	}
1366
+
1367
+
1368
+	/**
1369
+	 * Implementation for EEI_Admin_Links interface method.
1370
+	 *
1371
+	 * @see EEI_Admin_Links for comments
1372
+	 * @return string
1373
+	 */
1374
+	public function get_admin_settings_link()
1375
+	{
1376
+		return EEH_URL::add_query_args_and_nonce(
1377
+			array(
1378
+				'page'   => 'espresso_events',
1379
+				'action' => 'default_event_settings',
1380
+			),
1381
+			admin_url('admin.php')
1382
+		);
1383
+	}
1384
+
1385
+
1386
+	/**
1387
+	 * Implementation for EEI_Admin_Links interface method.
1388
+	 *
1389
+	 * @see EEI_Admin_Links for comments
1390
+	 * @return string
1391
+	 */
1392
+	public function get_admin_overview_link()
1393
+	{
1394
+		return EEH_URL::add_query_args_and_nonce(
1395
+			array(
1396
+				'page'   => 'espresso_events',
1397
+				'action' => 'default',
1398
+			),
1399
+			admin_url('admin.php')
1400
+		);
1401
+	}
1402 1402
 }
Please login to merge, or discard this patch.
4_10_0_stages/EE_DMS_4_10_0_Event_Question_Group.dmsstage.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -14,110 +14,110 @@
 block discarded – undo
14 14
 
15 15
 
16 16
 
17
-    /**
18
-     * Just initializes the status of the migration
19
-     */
20
-    public function __construct()
21
-    {
22
-        global $wpdb;
23
-        $this->_pretty_name = __('Event-Question Group Relations', 'event_espresso');
24
-        $this->_old_table = $wpdb->prefix.'esp_event_question_group';
25
-        $this->_extra_where_sql = "WHERE EQG_primary = 0 AND EQG_additional=0";
26
-        parent::__construct();
27
-    }
17
+	/**
18
+	 * Just initializes the status of the migration
19
+	 */
20
+	public function __construct()
21
+	{
22
+		global $wpdb;
23
+		$this->_pretty_name = __('Event-Question Group Relations', 'event_espresso');
24
+		$this->_old_table = $wpdb->prefix.'esp_event_question_group';
25
+		$this->_extra_where_sql = "WHERE EQG_primary = 0 AND EQG_additional=0";
26
+		parent::__construct();
27
+	}
28 28
 
29 29
 
30
-    /**
31
-     * Removes the duplicate event_question_group rows that only had EQG_primary=0. Now we just have one row
32
-     * joining event-to-question-groups with two columns: EQG_primary and EQG_additional, indicating which question
33
-     * groups apply to which category of registrant.
34
-     * @param array $event_question_group an associative array where keys are column names and values are their values.
35
-     * @return null
36
-     */
37
-    protected function _migrate_old_row($event_question_group)
38
-    {
39
-        if (isset($event_question_group['EVT_ID'], $event_question_group['QSG_ID'])) {
40
-            global $wpdb;
41
-            $success = $wpdb->update(
42
-                $this->_old_table,
43
-                ['EQG_additional' => true],  // data
44
-                [
45
-                    'EVT_ID' => $event_question_group['EVT_ID'],
46
-                    'QSG_ID' => $event_question_group['QSG_ID']
47
-                ],  // where
48
-                array( '%d' ),   // data format
49
-                array( '%d', '%d' )  // where format
50
-            );
51
-            if (! $success) {
52
-                $this->add_error(
53
-                    sprintf(
54
-                        __('Could not update event-question group relation for event "%1$s" and question group "%2$s" because "%3$s"', 'event_espresso'),
55
-                        $event_question_group['EVT_ID'],
56
-                        $event_question_group['QSG_ID'],
57
-                        $wpdb->last_error
58
-                    )
59
-                );
60
-            }
61
-            // and delete the old row
62
-            $successful_delete = $wpdb->delete(
63
-                $this->_old_table,
64
-                [
65
-                    'EQG_ID' => $event_question_group['EQG_ID']
66
-                ],
67
-                ['%d']
68
-            );
69
-            if (! $successful_delete) {
70
-                $this->add_error(
71
-                    sprintf(
72
-                        __('Could not delete old event-question group relation row "%1$s" because "%2$s"', 'event_espresso'),
73
-                        wp_json_encode($event_question_group),
74
-                        $wpdb->last_error
75
-                    )
76
-                );
77
-            }
78
-        }
79
-    }
30
+	/**
31
+	 * Removes the duplicate event_question_group rows that only had EQG_primary=0. Now we just have one row
32
+	 * joining event-to-question-groups with two columns: EQG_primary and EQG_additional, indicating which question
33
+	 * groups apply to which category of registrant.
34
+	 * @param array $event_question_group an associative array where keys are column names and values are their values.
35
+	 * @return null
36
+	 */
37
+	protected function _migrate_old_row($event_question_group)
38
+	{
39
+		if (isset($event_question_group['EVT_ID'], $event_question_group['QSG_ID'])) {
40
+			global $wpdb;
41
+			$success = $wpdb->update(
42
+				$this->_old_table,
43
+				['EQG_additional' => true],  // data
44
+				[
45
+					'EVT_ID' => $event_question_group['EVT_ID'],
46
+					'QSG_ID' => $event_question_group['QSG_ID']
47
+				],  // where
48
+				array( '%d' ),   // data format
49
+				array( '%d', '%d' )  // where format
50
+			);
51
+			if (! $success) {
52
+				$this->add_error(
53
+					sprintf(
54
+						__('Could not update event-question group relation for event "%1$s" and question group "%2$s" because "%3$s"', 'event_espresso'),
55
+						$event_question_group['EVT_ID'],
56
+						$event_question_group['QSG_ID'],
57
+						$wpdb->last_error
58
+					)
59
+				);
60
+			}
61
+			// and delete the old row
62
+			$successful_delete = $wpdb->delete(
63
+				$this->_old_table,
64
+				[
65
+					'EQG_ID' => $event_question_group['EQG_ID']
66
+				],
67
+				['%d']
68
+			);
69
+			if (! $successful_delete) {
70
+				$this->add_error(
71
+					sprintf(
72
+						__('Could not delete old event-question group relation row "%1$s" because "%2$s"', 'event_espresso'),
73
+						wp_json_encode($event_question_group),
74
+						$wpdb->last_error
75
+					)
76
+				);
77
+			}
78
+		}
79
+	}
80 80
 
81
-    /**
82
-     * Gets the rows for the existing table that shouldn't exist in 4.10.
83
-     * Specifically the rows where EQG_primary=false and EQG_additional=false.
84
-     * Gotcha: because the migration is REMOVING rows as it goes, we shouldn't use the offset.
85
-     *
86
-     * @global wpdb $wpdb
87
-     * @param int   $limit
88
-     * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
89
-     */
90
-    protected function _get_rows($limit)
91
-    {
92
-        global $wpdb;
93
-        $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
94
-            "LIMIT %d",
95
-            $limit
96
-        );
97
-        return $wpdb->get_results($query, ARRAY_A);
98
-    }
81
+	/**
82
+	 * Gets the rows for the existing table that shouldn't exist in 4.10.
83
+	 * Specifically the rows where EQG_primary=false and EQG_additional=false.
84
+	 * Gotcha: because the migration is REMOVING rows as it goes, we shouldn't use the offset.
85
+	 *
86
+	 * @global wpdb $wpdb
87
+	 * @param int   $limit
88
+	 * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
89
+	 */
90
+	protected function _get_rows($limit)
91
+	{
92
+		global $wpdb;
93
+		$query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
94
+			"LIMIT %d",
95
+			$limit
96
+		);
97
+		return $wpdb->get_results($query, ARRAY_A);
98
+	}
99 99
 
100
-    /**
101
-     * Slight departure from the normal procedure here: because this removes rows from the DB, we need to ensure
102
-     * we count the records first, then do the migration.
103
-     *
104
-     * @param int $num_items
105
-     * @return int number of items ACTUALLY migrated
106
-     */
107
-    public function _migration_step($num_items = 50)
108
-    {
109
-        // Count the items right away. This migration step will be removing those rows, so we need to count them
110
-        // right away to get an accurate count.
111
-        $this->count_records_to_migrate();
112
-        $rows = $this->_get_rows($num_items);
113
-        $items_actually_migrated = 0;
114
-        foreach ($rows as $old_row) {
115
-            $this->_migrate_old_row($old_row);
116
-            $items_actually_migrated++;
117
-        }
118
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
119
-            $this->set_completed();
120
-        }
121
-        return $items_actually_migrated;
122
-    }
100
+	/**
101
+	 * Slight departure from the normal procedure here: because this removes rows from the DB, we need to ensure
102
+	 * we count the records first, then do the migration.
103
+	 *
104
+	 * @param int $num_items
105
+	 * @return int number of items ACTUALLY migrated
106
+	 */
107
+	public function _migration_step($num_items = 50)
108
+	{
109
+		// Count the items right away. This migration step will be removing those rows, so we need to count them
110
+		// right away to get an accurate count.
111
+		$this->count_records_to_migrate();
112
+		$rows = $this->_get_rows($num_items);
113
+		$items_actually_migrated = 0;
114
+		foreach ($rows as $old_row) {
115
+			$this->_migrate_old_row($old_row);
116
+			$items_actually_migrated++;
117
+		}
118
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
119
+			$this->set_completed();
120
+		}
121
+		return $items_actually_migrated;
122
+	}
123 123
 }
Please login to merge, or discard this patch.