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