Completed
Pull Request — Gutenberg/master (#745)
by
unknown
11:20 queued 38s
created
core/domain/services/assets/CoreAssetManager.php 1 patch
Indentation   +440 added lines, -440 removed lines patch added patch discarded remove patch
@@ -29,460 +29,460 @@
 block discarded – undo
29 29
 class CoreAssetManager extends AssetManager
30 30
 {
31 31
 
32
-    // WordPress core / Third party JS asset handles
33
-    const JS_HANDLE_JQUERY = 'jquery';
32
+	// WordPress core / Third party JS asset handles
33
+	const JS_HANDLE_JQUERY = 'jquery';
34 34
 
35
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
35
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
36 36
 
37
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
37
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
38 38
 
39
-    const JS_HANDLE_UNDERSCORE = 'underscore';
39
+	const JS_HANDLE_UNDERSCORE = 'underscore';
40 40
 
41
-    const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
41
+	const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
42 42
 
43
-    // EE JS assets handles
44
-    const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
43
+	// EE JS assets handles
44
+	const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
45 45
 
46
-    const JS_HANDLE_EE_JS_CORE = 'eejs-core';
46
+	const JS_HANDLE_EE_JS_CORE = 'eejs-core';
47 47
 
48
-    const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
48
+	const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
49 49
 
50
-    const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
50
+	const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
51 51
 
52
-    const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
52
+	const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
53 53
 
54
-    const JS_HANDLE_EE_MODEL = 'eventespresso-model';
54
+	const JS_HANDLE_EE_MODEL = 'eventespresso-model';
55 55
 
56
-    const JS_HANDLE_EE_VALUE_OBJECTS = 'eventespresso-value-objects';
56
+	const JS_HANDLE_EE_VALUE_OBJECTS = 'eventespresso-value-objects';
57 57
 
58
-    const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
58
+	const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
59 59
 
60
-    const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
60
+	const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
61 61
 
62
-    const JS_HANDLE_EE_JS_API = 'eejs-api';
62
+	const JS_HANDLE_EE_JS_API = 'eejs-api';
63 63
 
64
-    const JS_HANDLE_EE_CORE = 'espresso_core';
64
+	const JS_HANDLE_EE_CORE = 'espresso_core';
65 65
 
66
-    const JS_HANDLE_EE_I18N = 'eei18n';
67
-
68
-    const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
69
-
70
-    const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
71
-
72
-    // EE CSS assets handles
73
-    const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
74
-
75
-    const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
76
-
77
-    const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
78
-
79
-    /**
80
-     * @var EE_Currency_Config $currency_config
81
-     */
82
-    protected $currency_config;
83
-
84
-    /**
85
-     * @var EE_Template_Config $template_config
86
-     */
87
-    protected $template_config;
88
-
89
-
90
-    /**
91
-     * CoreAssetRegister constructor.
92
-     *
93
-     * @param AssetCollection    $assets
94
-     * @param EE_Currency_Config $currency_config
95
-     * @param EE_Template_Config $template_config
96
-     * @param DomainInterface    $domain
97
-     * @param Registry           $registry
98
-     */
99
-    public function __construct(
100
-        AssetCollection $assets,
101
-        EE_Currency_Config $currency_config,
102
-        EE_Template_Config $template_config,
103
-        DomainInterface $domain,
104
-        Registry $registry
105
-    ) {
106
-        $this->currency_config = $currency_config;
107
-        $this->template_config = $template_config;
108
-        parent::__construct($domain, $assets, $registry);
109
-    }
110
-
111
-
112
-    /**
113
-     * @since 4.9.62.p
114
-     * @throws DuplicateCollectionIdentifierException
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidDataTypeException
117
-     * @throws InvalidEntityException
118
-     */
119
-    public function addAssets()
120
-    {
121
-        $this->addJavascriptFiles();
122
-        $this->addStylesheetFiles();
123
-    }
124
-
125
-
126
-    /**
127
-     * @since 4.9.62.p
128
-     * @throws DuplicateCollectionIdentifierException
129
-     * @throws InvalidArgumentException
130
-     * @throws InvalidDataTypeException
131
-     * @throws InvalidEntityException
132
-     */
133
-    public function addJavascriptFiles()
134
-    {
135
-        $this->loadCoreJs();
136
-        $this->loadJqueryValidate();
137
-        $this->loadAccountingJs();
138
-        add_action(
139
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
-            array($this, 'loadQtipJs')
141
-        );
142
-        $this->registerAdminAssets();
143
-    }
144
-
145
-
146
-    /**
147
-     * @since 4.9.62.p
148
-     * @throws DuplicateCollectionIdentifierException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     */
152
-    public function addStylesheetFiles()
153
-    {
154
-        $this->loadCoreCss();
155
-    }
156
-
157
-
158
-    /**
159
-     * core default javascript
160
-     *
161
-     * @since 4.9.62.p
162
-     * @throws DuplicateCollectionIdentifierException
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidEntityException
166
-     */
167
-    private function loadCoreJs()
168
-    {
169
-        $this->addJavascript(
170
-            CoreAssetManager::JS_HANDLE_EE_MANIFEST,
171
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
172
-        );
173
-
174
-        $this->addJavascript(
175
-            CoreAssetManager::JS_HANDLE_EE_JS_CORE,
176
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
177
-            array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
178
-        )
179
-        ->setHasInlineData();
180
-
181
-        $this->addJavascript(
182
-            CoreAssetManager::JS_HANDLE_EE_VENDOR,
183
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
184
-            array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
185
-        );
186
-
187
-        $this->addJavascript(
188
-            CoreAssetManager::JS_HANDLE_EE_HELPERS,
189
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
190
-        )->setRequiresTranslation();
191
-
192
-        $this->addJavascript(
193
-            CoreAssetManager::JS_HANDLE_EE_MODEL,
194
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
195
-            array(
196
-                CoreAssetManager::JS_HANDLE_EE_HELPERS
197
-            )
198
-        )->setRequiresTranslation();
199
-
200
-        $this->addJavascript(
201
-            CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
202
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
203
-            array(
204
-                CoreAssetManager::JS_HANDLE_EE_MODEL
205
-            )
206
-        )->setRequiresTranslation();
207
-
208
-        $this->addJavascript(
209
-            CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
210
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
211
-            array(
212
-                CoreAssetManager::JS_HANDLE_EE_VENDOR,
213
-                'wp-data',
214
-                'wp-api-request',
215
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS
216
-            )
217
-        )
218
-             ->setRequiresTranslation();
219
-
220
-        $this->addJavascript(
221
-            CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
222
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
223
-            array(
224
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
225
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
226
-                'wp-components',
227
-            )
228
-        )->setRequiresTranslation();
229
-
230
-        $this->addJavascript(
231
-            CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
232
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
233
-            array(
234
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
235
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
236
-                'wp-components',
237
-            )
238
-        )
239
-        ->setRequiresTranslation();
240
-
241
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
242
-        $this->registry->addData(
243
-            'paths',
244
-            array(
245
-                'rest_route' => rest_url('ee/v4.8.36/'),
246
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
247
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
248
-                'site_url' => site_url('/'),
249
-                'admin_url' => admin_url('/'),
250
-            )
251
-        );
252
-        /** site formatting values **/
253
-        $this->registry->addData(
254
-            'site_formats',
255
-            array(
256
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
257
-            )
258
-        );
259
-        /** currency data **/
260
-        $this->registry->addData(
261
-            'currency_config',
262
-            $this->getCurrencySettings()
263
-        );
264
-        /** site timezone */
265
-        $this->registry->addData(
266
-            'default_timezone',
267
-            array(
268
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
269
-                'string' => get_option('timezone_string'),
270
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
271
-            )
272
-        );
273
-        /** site locale (user locale if user logged in) */
274
-        $this->registry->addData(
275
-            'locale',
276
-            array(
277
-                'user' => get_user_locale(),
278
-                'site' => get_locale()
279
-            )
280
-        );
281
-
282
-        $this->addJavascript(
283
-            CoreAssetManager::JS_HANDLE_EE_CORE,
284
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
285
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
286
-        )
287
-        ->setInlineDataCallback(
288
-            function () {
289
-                wp_localize_script(
290
-                    CoreAssetManager::JS_HANDLE_EE_CORE,
291
-                    CoreAssetManager::JS_HANDLE_EE_I18N,
292
-                    EE_Registry::$i18n_js_strings
293
-                );
294
-            }
295
-        );
296
-    }
297
-
298
-
299
-    /**
300
-     * Returns configuration data for the accounting-js library.
301
-     * @since $VID:$
302
-     * @return array
303
-     */
304
-    private function getAccountingSettings() {
305
-        return array(
306
-            'currency' => array(
307
-                'symbol'    => $this->currency_config->sign,
308
-                'format'    => array(
309
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
310
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
311
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
312
-                ),
313
-                'decimal'   => $this->currency_config->dec_mrk,
314
-                'thousand'  => $this->currency_config->thsnds,
315
-                'precision' => $this->currency_config->dec_plc,
316
-            ),
317
-            'number'   => array(
318
-                'precision' => $this->currency_config->dec_plc,
319
-                'thousand'  => $this->currency_config->thsnds,
320
-                'decimal'   => $this->currency_config->dec_mrk,
321
-            ),
322
-        );
323
-    }
324
-
325
-
326
-    /**
327
-     * Returns configuration data for the js Currency VO.
328
-     * @sinc $VID:$
329
-     * @return array
330
-     */
331
-    private function getCurrencySettings()
332
-    {
333
-        return array(
334
-            'code' => $this->currency_config->code,
335
-            'singularLabel' => $this->currency_config->name,
336
-            'pluralLabel' => $this->currency_config->plural,
337
-            'sign' => $this->currency_config->sign,
338
-            'signB4' => $this->currency_config->sign_b4,
339
-            'decimalPlaces' => $this->currency_config->dec_plc,
340
-            'decimalMark' => $this->currency_config->dec_mrk,
341
-            'thousandsSeparator' => $this->currency_config->thsnds,
342
-        );
343
-    }
344
-
345
-
346
-    /**
347
-     * @since 4.9.62.p
348
-     * @throws DuplicateCollectionIdentifierException
349
-     * @throws InvalidDataTypeException
350
-     * @throws InvalidEntityException
351
-     */
352
-    private function loadCoreCss()
353
-    {
354
-        if ($this->template_config->enable_default_style && ! is_admin()) {
355
-            $this->addStylesheet(
356
-                CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
357
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
358
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
359
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
360
-                array('dashicons')
361
-            );
362
-            //Load custom style sheet if available
363
-            if ($this->template_config->custom_style_sheet !== null) {
364
-                $this->addStylesheet(
365
-                    CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
366
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
367
-                    array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
368
-                );
369
-            }
370
-        }
371
-        $this->addStylesheet(
372
-            CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
373
-            $this->registry->getCssUrl(
374
-                $this->domain->assetNamespace(),
375
-                'components'
376
-            ),
377
-            ['wp-components']
378
-        );
379
-    }
380
-
381
-
382
-    /**
383
-     * jQuery Validate for form validation
384
-     *
385
-     * @since 4.9.62.p
386
-     * @throws DuplicateCollectionIdentifierException
387
-     * @throws InvalidDataTypeException
388
-     * @throws InvalidEntityException
389
-     */
390
-    private function loadJqueryValidate()
391
-    {
392
-        $this->addJavascript(
393
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
394
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
395
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
396
-        )
397
-        ->setVersion('1.15.0');
398
-
399
-        $this->addJavascript(
400
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
401
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
402
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
403
-        )
404
-        ->setVersion('1.15.0');
405
-    }
406
-
407
-
408
-    /**
409
-     * accounting.js for performing client-side calculations
410
-     *
411
-     * @since 4.9.62.p
412
-     * @throws DuplicateCollectionIdentifierException
413
-     * @throws InvalidDataTypeException
414
-     * @throws InvalidEntityException
415
-     */
416
-    private function loadAccountingJs()
417
-    {
418
-        //accounting.js library
419
-        // @link http://josscrowcroft.github.io/accounting.js/
420
-        $this->addJavascript(
421
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
422
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
423
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
424
-        )
425
-        ->setVersion('0.3.2');
426
-
427
-        $this->addJavascript(
428
-            CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
429
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
430
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
431
-        )
432
-        ->setInlineDataCallback(
433
-            function () {
434
-                 wp_localize_script(
435
-                     CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
436
-                     'EE_ACCOUNTING_CFG',
437
-                     $this->getAccountingSettings()
438
-                 );
439
-            }
440
-        )
441
-        ->setVersion();
442
-    }
443
-
444
-
445
-    /**
446
-     * registers assets for cleaning your ears
447
-     *
448
-     * @param JavascriptAsset $script
449
-     */
450
-    public function loadQtipJs(JavascriptAsset $script)
451
-    {
452
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
453
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
454
-        if (
455
-            $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
456
-            && apply_filters('FHEE_load_qtip', false)
457
-        ) {
458
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
459
-        }
460
-    }
461
-
462
-
463
-    /**
464
-     * assets that are used in the WordPress admin
465
-     *
466
-     * @since 4.9.62.p
467
-     * @throws DuplicateCollectionIdentifierException
468
-     * @throws InvalidDataTypeException
469
-     * @throws InvalidEntityException
470
-     */
471
-    private function registerAdminAssets()
472
-    {
473
-        $this->addJavascript(
474
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
475
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
476
-            array(
477
-                CoreAssetManager::JS_HANDLE_JQUERY,
478
-                CoreAssetManager::JS_HANDLE_EE_VENDOR,
479
-            )
480
-        )
481
-        ->setRequiresTranslation();
482
-
483
-        $this->addStylesheet(
484
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
485
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
486
-        );
487
-    }
66
+	const JS_HANDLE_EE_I18N = 'eei18n';
67
+
68
+	const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
69
+
70
+	const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
71
+
72
+	// EE CSS assets handles
73
+	const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
74
+
75
+	const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
76
+
77
+	const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
78
+
79
+	/**
80
+	 * @var EE_Currency_Config $currency_config
81
+	 */
82
+	protected $currency_config;
83
+
84
+	/**
85
+	 * @var EE_Template_Config $template_config
86
+	 */
87
+	protected $template_config;
88
+
89
+
90
+	/**
91
+	 * CoreAssetRegister constructor.
92
+	 *
93
+	 * @param AssetCollection    $assets
94
+	 * @param EE_Currency_Config $currency_config
95
+	 * @param EE_Template_Config $template_config
96
+	 * @param DomainInterface    $domain
97
+	 * @param Registry           $registry
98
+	 */
99
+	public function __construct(
100
+		AssetCollection $assets,
101
+		EE_Currency_Config $currency_config,
102
+		EE_Template_Config $template_config,
103
+		DomainInterface $domain,
104
+		Registry $registry
105
+	) {
106
+		$this->currency_config = $currency_config;
107
+		$this->template_config = $template_config;
108
+		parent::__construct($domain, $assets, $registry);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @since 4.9.62.p
114
+	 * @throws DuplicateCollectionIdentifierException
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws InvalidEntityException
118
+	 */
119
+	public function addAssets()
120
+	{
121
+		$this->addJavascriptFiles();
122
+		$this->addStylesheetFiles();
123
+	}
124
+
125
+
126
+	/**
127
+	 * @since 4.9.62.p
128
+	 * @throws DuplicateCollectionIdentifierException
129
+	 * @throws InvalidArgumentException
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws InvalidEntityException
132
+	 */
133
+	public function addJavascriptFiles()
134
+	{
135
+		$this->loadCoreJs();
136
+		$this->loadJqueryValidate();
137
+		$this->loadAccountingJs();
138
+		add_action(
139
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
+			array($this, 'loadQtipJs')
141
+		);
142
+		$this->registerAdminAssets();
143
+	}
144
+
145
+
146
+	/**
147
+	 * @since 4.9.62.p
148
+	 * @throws DuplicateCollectionIdentifierException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 */
152
+	public function addStylesheetFiles()
153
+	{
154
+		$this->loadCoreCss();
155
+	}
156
+
157
+
158
+	/**
159
+	 * core default javascript
160
+	 *
161
+	 * @since 4.9.62.p
162
+	 * @throws DuplicateCollectionIdentifierException
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidEntityException
166
+	 */
167
+	private function loadCoreJs()
168
+	{
169
+		$this->addJavascript(
170
+			CoreAssetManager::JS_HANDLE_EE_MANIFEST,
171
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
172
+		);
173
+
174
+		$this->addJavascript(
175
+			CoreAssetManager::JS_HANDLE_EE_JS_CORE,
176
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
177
+			array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
178
+		)
179
+		->setHasInlineData();
180
+
181
+		$this->addJavascript(
182
+			CoreAssetManager::JS_HANDLE_EE_VENDOR,
183
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
184
+			array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
185
+		);
186
+
187
+		$this->addJavascript(
188
+			CoreAssetManager::JS_HANDLE_EE_HELPERS,
189
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
190
+		)->setRequiresTranslation();
191
+
192
+		$this->addJavascript(
193
+			CoreAssetManager::JS_HANDLE_EE_MODEL,
194
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
195
+			array(
196
+				CoreAssetManager::JS_HANDLE_EE_HELPERS
197
+			)
198
+		)->setRequiresTranslation();
199
+
200
+		$this->addJavascript(
201
+			CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
202
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
203
+			array(
204
+				CoreAssetManager::JS_HANDLE_EE_MODEL
205
+			)
206
+		)->setRequiresTranslation();
207
+
208
+		$this->addJavascript(
209
+			CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
210
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
211
+			array(
212
+				CoreAssetManager::JS_HANDLE_EE_VENDOR,
213
+				'wp-data',
214
+				'wp-api-request',
215
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS
216
+			)
217
+		)
218
+			 ->setRequiresTranslation();
219
+
220
+		$this->addJavascript(
221
+			CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
222
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
223
+			array(
224
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
225
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
226
+				'wp-components',
227
+			)
228
+		)->setRequiresTranslation();
229
+
230
+		$this->addJavascript(
231
+			CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
232
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
233
+			array(
234
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
235
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
236
+				'wp-components',
237
+			)
238
+		)
239
+		->setRequiresTranslation();
240
+
241
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
242
+		$this->registry->addData(
243
+			'paths',
244
+			array(
245
+				'rest_route' => rest_url('ee/v4.8.36/'),
246
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
247
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
248
+				'site_url' => site_url('/'),
249
+				'admin_url' => admin_url('/'),
250
+			)
251
+		);
252
+		/** site formatting values **/
253
+		$this->registry->addData(
254
+			'site_formats',
255
+			array(
256
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
257
+			)
258
+		);
259
+		/** currency data **/
260
+		$this->registry->addData(
261
+			'currency_config',
262
+			$this->getCurrencySettings()
263
+		);
264
+		/** site timezone */
265
+		$this->registry->addData(
266
+			'default_timezone',
267
+			array(
268
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
269
+				'string' => get_option('timezone_string'),
270
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
271
+			)
272
+		);
273
+		/** site locale (user locale if user logged in) */
274
+		$this->registry->addData(
275
+			'locale',
276
+			array(
277
+				'user' => get_user_locale(),
278
+				'site' => get_locale()
279
+			)
280
+		);
281
+
282
+		$this->addJavascript(
283
+			CoreAssetManager::JS_HANDLE_EE_CORE,
284
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
285
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
286
+		)
287
+		->setInlineDataCallback(
288
+			function () {
289
+				wp_localize_script(
290
+					CoreAssetManager::JS_HANDLE_EE_CORE,
291
+					CoreAssetManager::JS_HANDLE_EE_I18N,
292
+					EE_Registry::$i18n_js_strings
293
+				);
294
+			}
295
+		);
296
+	}
297
+
298
+
299
+	/**
300
+	 * Returns configuration data for the accounting-js library.
301
+	 * @since $VID:$
302
+	 * @return array
303
+	 */
304
+	private function getAccountingSettings() {
305
+		return array(
306
+			'currency' => array(
307
+				'symbol'    => $this->currency_config->sign,
308
+				'format'    => array(
309
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
310
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
311
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
312
+				),
313
+				'decimal'   => $this->currency_config->dec_mrk,
314
+				'thousand'  => $this->currency_config->thsnds,
315
+				'precision' => $this->currency_config->dec_plc,
316
+			),
317
+			'number'   => array(
318
+				'precision' => $this->currency_config->dec_plc,
319
+				'thousand'  => $this->currency_config->thsnds,
320
+				'decimal'   => $this->currency_config->dec_mrk,
321
+			),
322
+		);
323
+	}
324
+
325
+
326
+	/**
327
+	 * Returns configuration data for the js Currency VO.
328
+	 * @sinc $VID:$
329
+	 * @return array
330
+	 */
331
+	private function getCurrencySettings()
332
+	{
333
+		return array(
334
+			'code' => $this->currency_config->code,
335
+			'singularLabel' => $this->currency_config->name,
336
+			'pluralLabel' => $this->currency_config->plural,
337
+			'sign' => $this->currency_config->sign,
338
+			'signB4' => $this->currency_config->sign_b4,
339
+			'decimalPlaces' => $this->currency_config->dec_plc,
340
+			'decimalMark' => $this->currency_config->dec_mrk,
341
+			'thousandsSeparator' => $this->currency_config->thsnds,
342
+		);
343
+	}
344
+
345
+
346
+	/**
347
+	 * @since 4.9.62.p
348
+	 * @throws DuplicateCollectionIdentifierException
349
+	 * @throws InvalidDataTypeException
350
+	 * @throws InvalidEntityException
351
+	 */
352
+	private function loadCoreCss()
353
+	{
354
+		if ($this->template_config->enable_default_style && ! is_admin()) {
355
+			$this->addStylesheet(
356
+				CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
357
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
358
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
359
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
360
+				array('dashicons')
361
+			);
362
+			//Load custom style sheet if available
363
+			if ($this->template_config->custom_style_sheet !== null) {
364
+				$this->addStylesheet(
365
+					CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
366
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
367
+					array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
368
+				);
369
+			}
370
+		}
371
+		$this->addStylesheet(
372
+			CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
373
+			$this->registry->getCssUrl(
374
+				$this->domain->assetNamespace(),
375
+				'components'
376
+			),
377
+			['wp-components']
378
+		);
379
+	}
380
+
381
+
382
+	/**
383
+	 * jQuery Validate for form validation
384
+	 *
385
+	 * @since 4.9.62.p
386
+	 * @throws DuplicateCollectionIdentifierException
387
+	 * @throws InvalidDataTypeException
388
+	 * @throws InvalidEntityException
389
+	 */
390
+	private function loadJqueryValidate()
391
+	{
392
+		$this->addJavascript(
393
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
394
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
395
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
396
+		)
397
+		->setVersion('1.15.0');
398
+
399
+		$this->addJavascript(
400
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
401
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
402
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
403
+		)
404
+		->setVersion('1.15.0');
405
+	}
406
+
407
+
408
+	/**
409
+	 * accounting.js for performing client-side calculations
410
+	 *
411
+	 * @since 4.9.62.p
412
+	 * @throws DuplicateCollectionIdentifierException
413
+	 * @throws InvalidDataTypeException
414
+	 * @throws InvalidEntityException
415
+	 */
416
+	private function loadAccountingJs()
417
+	{
418
+		//accounting.js library
419
+		// @link http://josscrowcroft.github.io/accounting.js/
420
+		$this->addJavascript(
421
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
422
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
423
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
424
+		)
425
+		->setVersion('0.3.2');
426
+
427
+		$this->addJavascript(
428
+			CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
429
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
430
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
431
+		)
432
+		->setInlineDataCallback(
433
+			function () {
434
+				 wp_localize_script(
435
+					 CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
436
+					 'EE_ACCOUNTING_CFG',
437
+					 $this->getAccountingSettings()
438
+				 );
439
+			}
440
+		)
441
+		->setVersion();
442
+	}
443
+
444
+
445
+	/**
446
+	 * registers assets for cleaning your ears
447
+	 *
448
+	 * @param JavascriptAsset $script
449
+	 */
450
+	public function loadQtipJs(JavascriptAsset $script)
451
+	{
452
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
453
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
454
+		if (
455
+			$script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
456
+			&& apply_filters('FHEE_load_qtip', false)
457
+		) {
458
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
459
+		}
460
+	}
461
+
462
+
463
+	/**
464
+	 * assets that are used in the WordPress admin
465
+	 *
466
+	 * @since 4.9.62.p
467
+	 * @throws DuplicateCollectionIdentifierException
468
+	 * @throws InvalidDataTypeException
469
+	 * @throws InvalidEntityException
470
+	 */
471
+	private function registerAdminAssets()
472
+	{
473
+		$this->addJavascript(
474
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
475
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
476
+			array(
477
+				CoreAssetManager::JS_HANDLE_JQUERY,
478
+				CoreAssetManager::JS_HANDLE_EE_VENDOR,
479
+			)
480
+		)
481
+		->setRequiresTranslation();
482
+
483
+		$this->addStylesheet(
484
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
485
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
486
+		);
487
+	}
488 488
 }
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 patch
Indentation   +2142 added lines, -2142 removed lines patch added patch discarded remove patch
@@ -15,2203 +15,2203 @@
 block discarded – undo
15 15
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * This property is just used to hold the status of whether an event is currently being
20
-     * created (true) or edited (false)
21
-     *
22
-     * @access protected
23
-     * @var bool
24
-     */
25
-    protected $_is_creating_event;
18
+	/**
19
+	 * This property is just used to hold the status of whether an event is currently being
20
+	 * created (true) or edited (false)
21
+	 *
22
+	 * @access protected
23
+	 * @var bool
24
+	 */
25
+	protected $_is_creating_event;
26 26
 
27
-    /**
28
-     * Used to contain the format strings for date and time that will be used for php date and
29
-     * time.
30
-     * Is set in the _set_hooks_properties() method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_date_format_strings;
27
+	/**
28
+	 * Used to contain the format strings for date and time that will be used for php date and
29
+	 * time.
30
+	 * Is set in the _set_hooks_properties() method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_date_format_strings;
35 35
 
36
-    /**
37
-     * @var string $_date_time_format
38
-     */
39
-    protected $_date_time_format;
36
+	/**
37
+	 * @var string $_date_time_format
38
+	 */
39
+	protected $_date_time_format;
40 40
 
41 41
 
42
-    /**
43
-     * @throws InvalidArgumentException
44
-     * @throws InvalidInterfaceException
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    protected function _set_hooks_properties()
48
-    {
49
-        $this->_name = 'pricing';
50
-        // capability check
51
-        if (! EE_Registry::instance()->CAP->current_user_can(
52
-            'ee_read_default_prices',
53
-            'advanced_ticket_datetime_metabox'
54
-        )) {
55
-            return;
56
-        }
57
-        $this->_setup_metaboxes();
58
-        $this->_set_date_time_formats();
59
-        $this->_validate_format_strings();
60
-        $this->_set_scripts_styles();
61
-        // commented out temporarily until logic is implemented in callback
62
-        // add_action(
63
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
64
-        //     array($this, 'autosave_handling')
65
-        // );
66
-        add_filter(
67
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
68
-            array($this, 'caf_updates')
69
-        );
70
-    }
42
+	/**
43
+	 * @throws InvalidArgumentException
44
+	 * @throws InvalidInterfaceException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	protected function _set_hooks_properties()
48
+	{
49
+		$this->_name = 'pricing';
50
+		// capability check
51
+		if (! EE_Registry::instance()->CAP->current_user_can(
52
+			'ee_read_default_prices',
53
+			'advanced_ticket_datetime_metabox'
54
+		)) {
55
+			return;
56
+		}
57
+		$this->_setup_metaboxes();
58
+		$this->_set_date_time_formats();
59
+		$this->_validate_format_strings();
60
+		$this->_set_scripts_styles();
61
+		// commented out temporarily until logic is implemented in callback
62
+		// add_action(
63
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
64
+		//     array($this, 'autosave_handling')
65
+		// );
66
+		add_filter(
67
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
68
+			array($this, 'caf_updates')
69
+		);
70
+	}
71 71
 
72 72
 
73
-    /**
74
-     * @return void
75
-     */
76
-    protected function _setup_metaboxes()
77
-    {
78
-        // if we were going to add our own metaboxes we'd use the below.
79
-        $this->_metaboxes = array(
80
-            0 => array(
81
-                'page_route' => array('edit', 'create_new'),
82
-                'func'       => 'pricing_metabox',
83
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
84
-                'priority'   => 'high',
85
-                'context'    => 'normal',
86
-            ),
87
-        );
88
-        $this->_remove_metaboxes = array(
89
-            0 => array(
90
-                'page_route' => array('edit', 'create_new'),
91
-                'id'         => 'espresso_event_editor_tickets',
92
-                'context'    => 'normal',
93
-            ),
94
-        );
95
-    }
73
+	/**
74
+	 * @return void
75
+	 */
76
+	protected function _setup_metaboxes()
77
+	{
78
+		// if we were going to add our own metaboxes we'd use the below.
79
+		$this->_metaboxes = array(
80
+			0 => array(
81
+				'page_route' => array('edit', 'create_new'),
82
+				'func'       => 'pricing_metabox',
83
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
84
+				'priority'   => 'high',
85
+				'context'    => 'normal',
86
+			),
87
+		);
88
+		$this->_remove_metaboxes = array(
89
+			0 => array(
90
+				'page_route' => array('edit', 'create_new'),
91
+				'id'         => 'espresso_event_editor_tickets',
92
+				'context'    => 'normal',
93
+			),
94
+		);
95
+	}
96 96
 
97 97
 
98
-    /**
99
-     * @return void
100
-     */
101
-    protected function _set_date_time_formats()
102
-    {
103
-        /**
104
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
105
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
106
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
107
-         *
108
-         * @since 4.6.7
109
-         * @var array  Expected an array returned with 'date' and 'time' keys.
110
-         */
111
-        $this->_date_format_strings = apply_filters(
112
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
113
-            array(
114
-                'date' => 'Y-m-d',
115
-                'time' => 'h:i a',
116
-            )
117
-        );
118
-        // validate
119
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
120
-            ? $this->_date_format_strings['date']
121
-            : null;
122
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
123
-            ? $this->_date_format_strings['time']
124
-            : null;
125
-        $this->_date_time_format = $this->_date_format_strings['date']
126
-                                   . ' '
127
-                                   . $this->_date_format_strings['time'];
128
-    }
98
+	/**
99
+	 * @return void
100
+	 */
101
+	protected function _set_date_time_formats()
102
+	{
103
+		/**
104
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
105
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
106
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
107
+		 *
108
+		 * @since 4.6.7
109
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
110
+		 */
111
+		$this->_date_format_strings = apply_filters(
112
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
113
+			array(
114
+				'date' => 'Y-m-d',
115
+				'time' => 'h:i a',
116
+			)
117
+		);
118
+		// validate
119
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
120
+			? $this->_date_format_strings['date']
121
+			: null;
122
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
123
+			? $this->_date_format_strings['time']
124
+			: null;
125
+		$this->_date_time_format = $this->_date_format_strings['date']
126
+								   . ' '
127
+								   . $this->_date_format_strings['time'];
128
+	}
129 129
 
130 130
 
131
-    /**
132
-     * @return void
133
-     */
134
-    protected function _validate_format_strings()
135
-    {
136
-        // validate format strings
137
-        $format_validation = EEH_DTT_Helper::validate_format_string(
138
-            $this->_date_time_format
139
-        );
140
-        if (is_array($format_validation)) {
141
-            $msg = '<p>';
142
-            $msg .= sprintf(
143
-                esc_html__(
144
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
145
-                    'event_espresso'
146
-                ),
147
-                $this->_date_time_format
148
-            );
149
-            $msg .= '</p><ul>';
150
-            foreach ($format_validation as $error) {
151
-                $msg .= '<li>' . $error . '</li>';
152
-            }
153
-            $msg .= '</ul><p>';
154
-            $msg .= sprintf(
155
-                esc_html__(
156
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
157
-                    'event_espresso'
158
-                ),
159
-                '<span style="color:#D54E21;">',
160
-                '</span>'
161
-            );
162
-            $msg .= '</p>';
163
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
164
-            $this->_date_format_strings = array(
165
-                'date' => 'Y-m-d',
166
-                'time' => 'h:i a',
167
-            );
168
-        }
169
-    }
131
+	/**
132
+	 * @return void
133
+	 */
134
+	protected function _validate_format_strings()
135
+	{
136
+		// validate format strings
137
+		$format_validation = EEH_DTT_Helper::validate_format_string(
138
+			$this->_date_time_format
139
+		);
140
+		if (is_array($format_validation)) {
141
+			$msg = '<p>';
142
+			$msg .= sprintf(
143
+				esc_html__(
144
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
145
+					'event_espresso'
146
+				),
147
+				$this->_date_time_format
148
+			);
149
+			$msg .= '</p><ul>';
150
+			foreach ($format_validation as $error) {
151
+				$msg .= '<li>' . $error . '</li>';
152
+			}
153
+			$msg .= '</ul><p>';
154
+			$msg .= sprintf(
155
+				esc_html__(
156
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
157
+					'event_espresso'
158
+				),
159
+				'<span style="color:#D54E21;">',
160
+				'</span>'
161
+			);
162
+			$msg .= '</p>';
163
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
164
+			$this->_date_format_strings = array(
165
+				'date' => 'Y-m-d',
166
+				'time' => 'h:i a',
167
+			);
168
+		}
169
+	}
170 170
 
171 171
 
172
-    /**
173
-     * @return void
174
-     */
175
-    protected function _set_scripts_styles()
176
-    {
177
-        $this->_scripts_styles = array(
178
-            'registers'   => array(
179
-                'ee-tickets-datetimes-css' => array(
180
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
181
-                    'type' => 'css',
182
-                ),
183
-                'ee-dtt-ticket-metabox'    => array(
184
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
185
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
186
-                ),
187
-            ),
188
-            'deregisters' => array(
189
-                'event-editor-css'       => array('type' => 'css'),
190
-                'event-datetime-metabox' => array('type' => 'js'),
191
-            ),
192
-            'enqueues'    => array(
193
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
194
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
195
-            ),
196
-            'localize'    => array(
197
-                'ee-dtt-ticket-metabox' => array(
198
-                    'DTT_TRASH_BLOCK'       => array(
199
-                        'main_warning'            => esc_html__(
200
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
201
-                            'event_espresso'
202
-                        ),
203
-                        'after_warning'           => esc_html__(
204
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
205
-                            'event_espresso'
206
-                        ),
207
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
208
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
209
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
210
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
211
-                        'single_warning_from_tkt' => esc_html__(
212
-                            'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
213
-                            'event_espresso'
214
-                        ),
215
-                        'single_warning_from_dtt' => esc_html__(
216
-                            'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
217
-                            'event_espresso'
218
-                        ),
219
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
220
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
221
-                    ),
222
-                    'DTT_ERROR_MSG'         => array(
223
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
224
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
225
-                                            . '<button class="button-secondary ee-modal-cancel">'
226
-                                            . esc_html__('Dismiss', 'event_espresso')
227
-                                            . '</button></div>',
228
-                    ),
229
-                    'DTT_OVERSELL_WARNING'  => array(
230
-                        'datetime_ticket' => esc_html__(
231
-                            'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
232
-                            'event_espresso'
233
-                        ),
234
-                        'ticket_datetime' => esc_html__(
235
-                            'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
236
-                            'event_espresso'
237
-                        ),
238
-                    ),
239
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
240
-                        $this->_date_format_strings['date'],
241
-                        $this->_date_format_strings['time']
242
-                    ),
243
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
244
-                ),
245
-            ),
246
-        );
247
-    }
172
+	/**
173
+	 * @return void
174
+	 */
175
+	protected function _set_scripts_styles()
176
+	{
177
+		$this->_scripts_styles = array(
178
+			'registers'   => array(
179
+				'ee-tickets-datetimes-css' => array(
180
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
181
+					'type' => 'css',
182
+				),
183
+				'ee-dtt-ticket-metabox'    => array(
184
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
185
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
186
+				),
187
+			),
188
+			'deregisters' => array(
189
+				'event-editor-css'       => array('type' => 'css'),
190
+				'event-datetime-metabox' => array('type' => 'js'),
191
+			),
192
+			'enqueues'    => array(
193
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
194
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
195
+			),
196
+			'localize'    => array(
197
+				'ee-dtt-ticket-metabox' => array(
198
+					'DTT_TRASH_BLOCK'       => array(
199
+						'main_warning'            => esc_html__(
200
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
201
+							'event_espresso'
202
+						),
203
+						'after_warning'           => esc_html__(
204
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
205
+							'event_espresso'
206
+						),
207
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
208
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
209
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
210
+													 . esc_html__('Close', 'event_espresso') . '</button>',
211
+						'single_warning_from_tkt' => esc_html__(
212
+							'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
213
+							'event_espresso'
214
+						),
215
+						'single_warning_from_dtt' => esc_html__(
216
+							'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
217
+							'event_espresso'
218
+						),
219
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
220
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
221
+					),
222
+					'DTT_ERROR_MSG'         => array(
223
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
224
+						'dismiss_button' => '<div class="save-cancel-button-container">'
225
+											. '<button class="button-secondary ee-modal-cancel">'
226
+											. esc_html__('Dismiss', 'event_espresso')
227
+											. '</button></div>',
228
+					),
229
+					'DTT_OVERSELL_WARNING'  => array(
230
+						'datetime_ticket' => esc_html__(
231
+							'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
232
+							'event_espresso'
233
+						),
234
+						'ticket_datetime' => esc_html__(
235
+							'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
236
+							'event_espresso'
237
+						),
238
+					),
239
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
240
+						$this->_date_format_strings['date'],
241
+						$this->_date_format_strings['time']
242
+					),
243
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
244
+				),
245
+			),
246
+		);
247
+	}
248 248
 
249 249
 
250
-    /**
251
-     * @param array $update_callbacks
252
-     * @return array
253
-     */
254
-    public function caf_updates(array $update_callbacks)
255
-    {
256
-        foreach ($update_callbacks as $key => $callback) {
257
-            if ($callback[1] === '_default_tickets_update') {
258
-                unset($update_callbacks[ $key ]);
259
-            }
260
-        }
261
-        $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
262
-        return $update_callbacks;
263
-    }
250
+	/**
251
+	 * @param array $update_callbacks
252
+	 * @return array
253
+	 */
254
+	public function caf_updates(array $update_callbacks)
255
+	{
256
+		foreach ($update_callbacks as $key => $callback) {
257
+			if ($callback[1] === '_default_tickets_update') {
258
+				unset($update_callbacks[ $key ]);
259
+			}
260
+		}
261
+		$update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
262
+		return $update_callbacks;
263
+	}
264 264
 
265 265
 
266
-    /**
267
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
268
-     *
269
-     * @param  EE_Event $event The Event object we're attaching data to
270
-     * @param  array    $data  The request data from the form
271
-     * @throws ReflectionException
272
-     * @throws Exception
273
-     * @throws InvalidInterfaceException
274
-     * @throws InvalidDataTypeException
275
-     * @throws EE_Error
276
-     * @throws InvalidArgumentException
277
-     */
278
-    public function datetime_and_tickets_caf_update($event, $data)
279
-    {
280
-        // first we need to start with datetimes cause they are the "root" items attached to events.
281
-        $saved_datetimes = $this->_update_datetimes($event, $data);
282
-        // next tackle the tickets (and prices?)
283
-        $this->_update_tickets($event, $saved_datetimes, $data);
284
-    }
266
+	/**
267
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
268
+	 *
269
+	 * @param  EE_Event $event The Event object we're attaching data to
270
+	 * @param  array    $data  The request data from the form
271
+	 * @throws ReflectionException
272
+	 * @throws Exception
273
+	 * @throws InvalidInterfaceException
274
+	 * @throws InvalidDataTypeException
275
+	 * @throws EE_Error
276
+	 * @throws InvalidArgumentException
277
+	 */
278
+	public function datetime_and_tickets_caf_update($event, $data)
279
+	{
280
+		// first we need to start with datetimes cause they are the "root" items attached to events.
281
+		$saved_datetimes = $this->_update_datetimes($event, $data);
282
+		// next tackle the tickets (and prices?)
283
+		$this->_update_tickets($event, $saved_datetimes, $data);
284
+	}
285 285
 
286 286
 
287
-    /**
288
-     * update event_datetimes
289
-     *
290
-     * @param  EE_Event $event Event being updated
291
-     * @param  array    $data  the request data from the form
292
-     * @return EE_Datetime[]
293
-     * @throws Exception
294
-     * @throws ReflectionException
295
-     * @throws InvalidInterfaceException
296
-     * @throws InvalidDataTypeException
297
-     * @throws InvalidArgumentException
298
-     * @throws EE_Error
299
-     */
300
-    protected function _update_datetimes($event, $data)
301
-    {
302
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
303
-        $saved_dtt_ids = array();
304
-        $saved_dtt_objs = array();
305
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
306
-            throw new InvalidArgumentException(
307
-                esc_html__(
308
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
309
-                    'event_espresso'
310
-                )
311
-            );
312
-        }
313
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
314
-            // trim all values to ensure any excess whitespace is removed.
315
-            $datetime_data = array_map(
316
-                function ($datetime_data) {
317
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
318
-                },
319
-                $datetime_data
320
-            );
321
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
322
-                                            && ! empty($datetime_data['DTT_EVT_end'])
323
-                ? $datetime_data['DTT_EVT_end']
324
-                : $datetime_data['DTT_EVT_start'];
325
-            $datetime_values = array(
326
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
327
-                    ? $datetime_data['DTT_ID']
328
-                    : null,
329
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
330
-                    ? $datetime_data['DTT_name']
331
-                    : '',
332
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
333
-                    ? $datetime_data['DTT_description']
334
-                    : '',
335
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
336
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
337
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
338
-                    ? EE_INF
339
-                    : $datetime_data['DTT_reg_limit'],
340
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
341
-                    ? $row
342
-                    : $datetime_data['DTT_order'],
343
-            );
344
-            // if we have an id then let's get existing object first and then set the new values.
345
-            // Otherwise we instantiate a new object for save.
346
-            if (! empty($datetime_data['DTT_ID'])) {
347
-                $datetime = EE_Registry::instance()
348
-                                       ->load_model('Datetime', array($timezone))
349
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
350
-                // set date and time format according to what is set in this class.
351
-                $datetime->set_date_format($this->_date_format_strings['date']);
352
-                $datetime->set_time_format($this->_date_format_strings['time']);
353
-                foreach ($datetime_values as $field => $value) {
354
-                    $datetime->set($field, $value);
355
-                }
356
-                // make sure the $dtt_id here is saved just in case
357
-                // after the add_relation_to() the autosave replaces it.
358
-                // We need to do this so we dont' TRASH the parent DTT.
359
-                // (save the ID for both key and value to avoid duplications)
360
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
361
-            } else {
362
-                $datetime = EE_Registry::instance()->load_class(
363
-                    'Datetime',
364
-                    array(
365
-                        $datetime_values,
366
-                        $timezone,
367
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
368
-                    ),
369
-                    false,
370
-                    false
371
-                );
372
-                foreach ($datetime_values as $field => $value) {
373
-                    $datetime->set($field, $value);
374
-                }
375
-            }
376
-            $datetime->save();
377
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
378
-            // before going any further make sure our dates are setup correctly
379
-            // so that the end date is always equal or greater than the start date.
380
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
381
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
382
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
383
-                $datetime->save();
384
-            }
385
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
386
-            // because it is possible there was a new one created for the autosave.
387
-            // (save the ID for both key and value to avoid duplications)
388
-            $DTT_ID = $datetime->ID();
389
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
390
-            $saved_dtt_objs[ $row ] = $datetime;
391
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
392
-        }
393
-        $event->save();
394
-        // now we need to REMOVE any datetimes that got deleted.
395
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
396
-        // So its safe to permanently delete at this point.
397
-        $old_datetimes = explode(',', $data['datetime_IDs']);
398
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
399
-        if (is_array($old_datetimes)) {
400
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
401
-            foreach ($datetimes_to_delete as $id) {
402
-                $id = absint($id);
403
-                if (empty($id)) {
404
-                    continue;
405
-                }
406
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
407
-                // remove tkt relationships.
408
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
409
-                foreach ($related_tickets as $tkt) {
410
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
411
-                }
412
-                $event->_remove_relation_to($id, 'Datetime');
413
-                $dtt_to_remove->refresh_cache_of_related_objects();
414
-            }
415
-        }
416
-        return $saved_dtt_objs;
417
-    }
287
+	/**
288
+	 * update event_datetimes
289
+	 *
290
+	 * @param  EE_Event $event Event being updated
291
+	 * @param  array    $data  the request data from the form
292
+	 * @return EE_Datetime[]
293
+	 * @throws Exception
294
+	 * @throws ReflectionException
295
+	 * @throws InvalidInterfaceException
296
+	 * @throws InvalidDataTypeException
297
+	 * @throws InvalidArgumentException
298
+	 * @throws EE_Error
299
+	 */
300
+	protected function _update_datetimes($event, $data)
301
+	{
302
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
303
+		$saved_dtt_ids = array();
304
+		$saved_dtt_objs = array();
305
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
306
+			throw new InvalidArgumentException(
307
+				esc_html__(
308
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
309
+					'event_espresso'
310
+				)
311
+			);
312
+		}
313
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
314
+			// trim all values to ensure any excess whitespace is removed.
315
+			$datetime_data = array_map(
316
+				function ($datetime_data) {
317
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
318
+				},
319
+				$datetime_data
320
+			);
321
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
322
+											&& ! empty($datetime_data['DTT_EVT_end'])
323
+				? $datetime_data['DTT_EVT_end']
324
+				: $datetime_data['DTT_EVT_start'];
325
+			$datetime_values = array(
326
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
327
+					? $datetime_data['DTT_ID']
328
+					: null,
329
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
330
+					? $datetime_data['DTT_name']
331
+					: '',
332
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
333
+					? $datetime_data['DTT_description']
334
+					: '',
335
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
336
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
337
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
338
+					? EE_INF
339
+					: $datetime_data['DTT_reg_limit'],
340
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
341
+					? $row
342
+					: $datetime_data['DTT_order'],
343
+			);
344
+			// if we have an id then let's get existing object first and then set the new values.
345
+			// Otherwise we instantiate a new object for save.
346
+			if (! empty($datetime_data['DTT_ID'])) {
347
+				$datetime = EE_Registry::instance()
348
+									   ->load_model('Datetime', array($timezone))
349
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
350
+				// set date and time format according to what is set in this class.
351
+				$datetime->set_date_format($this->_date_format_strings['date']);
352
+				$datetime->set_time_format($this->_date_format_strings['time']);
353
+				foreach ($datetime_values as $field => $value) {
354
+					$datetime->set($field, $value);
355
+				}
356
+				// make sure the $dtt_id here is saved just in case
357
+				// after the add_relation_to() the autosave replaces it.
358
+				// We need to do this so we dont' TRASH the parent DTT.
359
+				// (save the ID for both key and value to avoid duplications)
360
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
361
+			} else {
362
+				$datetime = EE_Registry::instance()->load_class(
363
+					'Datetime',
364
+					array(
365
+						$datetime_values,
366
+						$timezone,
367
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
368
+					),
369
+					false,
370
+					false
371
+				);
372
+				foreach ($datetime_values as $field => $value) {
373
+					$datetime->set($field, $value);
374
+				}
375
+			}
376
+			$datetime->save();
377
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
378
+			// before going any further make sure our dates are setup correctly
379
+			// so that the end date is always equal or greater than the start date.
380
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
381
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
382
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
383
+				$datetime->save();
384
+			}
385
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
386
+			// because it is possible there was a new one created for the autosave.
387
+			// (save the ID for both key and value to avoid duplications)
388
+			$DTT_ID = $datetime->ID();
389
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
390
+			$saved_dtt_objs[ $row ] = $datetime;
391
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
392
+		}
393
+		$event->save();
394
+		// now we need to REMOVE any datetimes that got deleted.
395
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
396
+		// So its safe to permanently delete at this point.
397
+		$old_datetimes = explode(',', $data['datetime_IDs']);
398
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
399
+		if (is_array($old_datetimes)) {
400
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
401
+			foreach ($datetimes_to_delete as $id) {
402
+				$id = absint($id);
403
+				if (empty($id)) {
404
+					continue;
405
+				}
406
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
407
+				// remove tkt relationships.
408
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
409
+				foreach ($related_tickets as $tkt) {
410
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
411
+				}
412
+				$event->_remove_relation_to($id, 'Datetime');
413
+				$dtt_to_remove->refresh_cache_of_related_objects();
414
+			}
415
+		}
416
+		return $saved_dtt_objs;
417
+	}
418 418
 
419 419
 
420
-    /**
421
-     * update tickets
422
-     *
423
-     * @param  EE_Event      $event           Event object being updated
424
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
425
-     * @param  array         $data            incoming request data
426
-     * @return EE_Ticket[]
427
-     * @throws Exception
428
-     * @throws ReflectionException
429
-     * @throws InvalidInterfaceException
430
-     * @throws InvalidDataTypeException
431
-     * @throws InvalidArgumentException
432
-     * @throws EE_Error
433
-     */
434
-    protected function _update_tickets($event, $saved_datetimes, $data)
435
-    {
436
-        $new_tkt = null;
437
-        $new_default = null;
438
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
439
-        $data = stripslashes_deep($data);
440
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
441
-        $saved_tickets = $datetimes_on_existing = array();
442
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
443
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
444
-            throw new InvalidArgumentException(
445
-                esc_html__(
446
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
447
-                    'event_espresso'
448
-                )
449
-            );
450
-        }
451
-        foreach ($data['edit_tickets'] as $row => $tkt) {
452
-            $update_prices = $create_new_TKT = false;
453
-            // figure out what datetimes were added to the ticket
454
-            // and what datetimes were removed from the ticket in the session.
455
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
456
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
457
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
458
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
459
-            // trim inputs to ensure any excess whitespace is removed.
460
-            $tkt = array_map(
461
-                function ($ticket_data) {
462
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
463
-                },
464
-                $tkt
465
-            );
466
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
467
-            // because we're doing calculations prior to using the models.
468
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
469
-            $ticket_price = isset($tkt['TKT_price'])
470
-                ? round((float) $tkt['TKT_price'], 3)
471
-                : 0;
472
-            // note incoming base price needs converted from localized value.
473
-            $base_price = isset($tkt['TKT_base_price'])
474
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
475
-                : 0;
476
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
477
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
478
-                ? $base_price
479
-                : $ticket_price;
480
-            $base_price_id = isset($tkt['TKT_base_price_ID'])
481
-                ? $tkt['TKT_base_price_ID']
482
-                : 0;
483
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
484
-                ? $data['edit_prices'][ $row ]
485
-                : array();
486
-            $now = null;
487
-            if (empty($tkt['TKT_start_date'])) {
488
-                // lets' use now in the set timezone.
489
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
490
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
491
-            }
492
-            if (empty($tkt['TKT_end_date'])) {
493
-                /**
494
-                 * set the TKT_end_date to the first datetime attached to the ticket.
495
-                 */
496
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
497
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
498
-            }
499
-            $TKT_values = array(
500
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
501
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
502
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
503
-                'TKT_description' => ! empty($tkt['TKT_description'])
504
-                                     && $tkt['TKT_description'] !== esc_html__(
505
-                                         'You can modify this description',
506
-                                         'event_espresso'
507
-                                     )
508
-                    ? $tkt['TKT_description']
509
-                    : '',
510
-                'TKT_start_date'  => $tkt['TKT_start_date'],
511
-                'TKT_end_date'    => $tkt['TKT_end_date'],
512
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
513
-                    ? EE_INF
514
-                    : $tkt['TKT_qty'],
515
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
516
-                    ? EE_INF
517
-                    : $tkt['TKT_uses'],
518
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
519
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
520
-                'TKT_row'         => $row,
521
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
522
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
523
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
524
-                'TKT_price'       => $ticket_price,
525
-            );
526
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
527
-            // which means in turn that the prices will become new prices as well.
528
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
529
-                $TKT_values['TKT_ID'] = 0;
530
-                $TKT_values['TKT_is_default'] = 0;
531
-                $update_prices = true;
532
-            }
533
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
534
-            // we actually do our saves ahead of doing any add_relations to
535
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
536
-            // but DID have it's items modified.
537
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
538
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
539
-            if (absint($TKT_values['TKT_ID'])) {
540
-                $ticket = EE_Registry::instance()
541
-                                     ->load_model('Ticket', array($timezone))
542
-                                     ->get_one_by_ID($tkt['TKT_ID']);
543
-                if ($ticket instanceof EE_Ticket) {
544
-                    $ticket = $this->_update_ticket_datetimes(
545
-                        $ticket,
546
-                        $saved_datetimes,
547
-                        $datetimes_added,
548
-                        $datetimes_removed
549
-                    );
550
-                    // are there any registrations using this ticket ?
551
-                    $tickets_sold = $ticket->count_related(
552
-                        'Registration',
553
-                        array(
554
-                            array(
555
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
556
-                            ),
557
-                        )
558
-                    );
559
-                    // set ticket formats
560
-                    $ticket->set_date_format($this->_date_format_strings['date']);
561
-                    $ticket->set_time_format($this->_date_format_strings['time']);
562
-                    // let's just check the total price for the existing ticket
563
-                    // and determine if it matches the new total price.
564
-                    // if they are different then we create a new ticket (if tickets sold)
565
-                    // if they aren't different then we go ahead and modify existing ticket.
566
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
567
-                    // set new values
568
-                    foreach ($TKT_values as $field => $value) {
569
-                        if ($field === 'TKT_qty') {
570
-                            $ticket->set_qty($value);
571
-                        } else {
572
-                            $ticket->set($field, $value);
573
-                        }
574
-                    }
575
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
576
-                    // Otherwise we have to create a new ticket.
577
-                    if ($create_new_TKT) {
578
-                        $new_tkt = $this->_duplicate_ticket(
579
-                            $ticket,
580
-                            $price_rows,
581
-                            $ticket_price,
582
-                            $base_price,
583
-                            $base_price_id
584
-                        );
585
-                    }
586
-                }
587
-            } else {
588
-                // no TKT_id so a new TKT
589
-                $ticket = EE_Ticket::new_instance(
590
-                    $TKT_values,
591
-                    $timezone,
592
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
593
-                );
594
-                if ($ticket instanceof EE_Ticket) {
595
-                    // make sure ticket has an ID of setting relations won't work
596
-                    $ticket->save();
597
-                    $ticket = $this->_update_ticket_datetimes(
598
-                        $ticket,
599
-                        $saved_datetimes,
600
-                        $datetimes_added,
601
-                        $datetimes_removed
602
-                    );
603
-                    $update_prices = true;
604
-                }
605
-            }
606
-            // make sure any current values have been saved.
607
-            // $ticket->save();
608
-            // before going any further make sure our dates are setup correctly
609
-            // so that the end date is always equal or greater than the start date.
610
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
611
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
612
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
613
-            }
614
-            // let's make sure the base price is handled
615
-            $ticket = ! $create_new_TKT
616
-                ? $this->_add_prices_to_ticket(
617
-                    array(),
618
-                    $ticket,
619
-                    $update_prices,
620
-                    $base_price,
621
-                    $base_price_id
622
-                )
623
-                : $ticket;
624
-            // add/update price_modifiers
625
-            $ticket = ! $create_new_TKT
626
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
627
-                : $ticket;
628
-            // need to make sue that the TKT_price is accurate after saving the prices.
629
-            $ticket->ensure_TKT_Price_correct();
630
-            // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
631
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
632
-                $update_prices = true;
633
-                $new_default = clone $ticket;
634
-                $new_default->set('TKT_ID', 0);
635
-                $new_default->set('TKT_is_default', 1);
636
-                $new_default->set('TKT_row', 1);
637
-                $new_default->set('TKT_price', $ticket_price);
638
-                // remove any dtt relations cause we DON'T want dtt relations attached
639
-                // (note this is just removing the cached relations in the object)
640
-                $new_default->_remove_relations('Datetime');
641
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
642
-                $new_default = $this->_add_prices_to_ticket(
643
-                    $price_rows,
644
-                    $new_default,
645
-                    $update_prices
646
-                );
647
-                // don't forget the base price!
648
-                $new_default = $this->_add_prices_to_ticket(
649
-                    array(),
650
-                    $new_default,
651
-                    $update_prices,
652
-                    $base_price,
653
-                    $base_price_id
654
-                );
655
-                $new_default->save();
656
-                do_action(
657
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
658
-                    $new_default,
659
-                    $row,
660
-                    $ticket,
661
-                    $data
662
-                );
663
-            }
664
-            // DO ALL dtt relationships for both current tickets and any archived tickets
665
-            // for the given dtt that are related to the current ticket.
666
-            // TODO... not sure exactly how we're going to do this considering we don't know
667
-            // what current ticket the archived tickets are related to
668
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
669
-            // let's assign any tickets that have been setup to the saved_tickets tracker
670
-            // save existing TKT
671
-            $ticket->save();
672
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
673
-                // save new TKT
674
-                $new_tkt->save();
675
-                // add new ticket to array
676
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
677
-                do_action(
678
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
679
-                    $new_tkt,
680
-                    $row,
681
-                    $tkt,
682
-                    $data
683
-                );
684
-            } else {
685
-                // add tkt to saved tkts
686
-                $saved_tickets[ $ticket->ID() ] = $ticket;
687
-                do_action(
688
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
689
-                    $ticket,
690
-                    $row,
691
-                    $tkt,
692
-                    $data
693
-                );
694
-            }
695
-        }
696
-        // now we need to handle tickets actually "deleted permanently".
697
-        // There are cases where we'd want this to happen
698
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
699
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
700
-        // No sense in keeping all the related data in the db!
701
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
702
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
703
-        foreach ($tickets_removed as $id) {
704
-            $id = absint($id);
705
-            // get the ticket for this id
706
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
707
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
708
-            if ($tkt_to_remove->get('TKT_is_default')) {
709
-                continue;
710
-            }
711
-            // if this tkt has any registrations attached so then we just ARCHIVE
712
-            // because we don't actually permanently delete these tickets.
713
-            if ($tkt_to_remove->count_related('Registration') > 0) {
714
-                $tkt_to_remove->delete();
715
-                continue;
716
-            }
717
-            // need to get all the related datetimes on this ticket and remove from every single one of them
718
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
719
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
720
-            foreach ($datetimes as $datetime) {
721
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
722
-            }
723
-            // need to do the same for prices (except these prices can also be deleted because again,
724
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
725
-            $tkt_to_remove->delete_related_permanently('Price');
726
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
727
-            // finally let's delete this ticket
728
-            // (which should not be blocked at this point b/c we've removed all our relationships)
729
-            $tkt_to_remove->delete_permanently();
730
-        }
731
-        return $saved_tickets;
732
-    }
420
+	/**
421
+	 * update tickets
422
+	 *
423
+	 * @param  EE_Event      $event           Event object being updated
424
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
425
+	 * @param  array         $data            incoming request data
426
+	 * @return EE_Ticket[]
427
+	 * @throws Exception
428
+	 * @throws ReflectionException
429
+	 * @throws InvalidInterfaceException
430
+	 * @throws InvalidDataTypeException
431
+	 * @throws InvalidArgumentException
432
+	 * @throws EE_Error
433
+	 */
434
+	protected function _update_tickets($event, $saved_datetimes, $data)
435
+	{
436
+		$new_tkt = null;
437
+		$new_default = null;
438
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
439
+		$data = stripslashes_deep($data);
440
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
441
+		$saved_tickets = $datetimes_on_existing = array();
442
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
443
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
444
+			throw new InvalidArgumentException(
445
+				esc_html__(
446
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
447
+					'event_espresso'
448
+				)
449
+			);
450
+		}
451
+		foreach ($data['edit_tickets'] as $row => $tkt) {
452
+			$update_prices = $create_new_TKT = false;
453
+			// figure out what datetimes were added to the ticket
454
+			// and what datetimes were removed from the ticket in the session.
455
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
456
+			$tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
457
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
458
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
459
+			// trim inputs to ensure any excess whitespace is removed.
460
+			$tkt = array_map(
461
+				function ($ticket_data) {
462
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
463
+				},
464
+				$tkt
465
+			);
466
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
467
+			// because we're doing calculations prior to using the models.
468
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
469
+			$ticket_price = isset($tkt['TKT_price'])
470
+				? round((float) $tkt['TKT_price'], 3)
471
+				: 0;
472
+			// note incoming base price needs converted from localized value.
473
+			$base_price = isset($tkt['TKT_base_price'])
474
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
475
+				: 0;
476
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
477
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
478
+				? $base_price
479
+				: $ticket_price;
480
+			$base_price_id = isset($tkt['TKT_base_price_ID'])
481
+				? $tkt['TKT_base_price_ID']
482
+				: 0;
483
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
484
+				? $data['edit_prices'][ $row ]
485
+				: array();
486
+			$now = null;
487
+			if (empty($tkt['TKT_start_date'])) {
488
+				// lets' use now in the set timezone.
489
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
490
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
491
+			}
492
+			if (empty($tkt['TKT_end_date'])) {
493
+				/**
494
+				 * set the TKT_end_date to the first datetime attached to the ticket.
495
+				 */
496
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
497
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
498
+			}
499
+			$TKT_values = array(
500
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
501
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
502
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
503
+				'TKT_description' => ! empty($tkt['TKT_description'])
504
+									 && $tkt['TKT_description'] !== esc_html__(
505
+										 'You can modify this description',
506
+										 'event_espresso'
507
+									 )
508
+					? $tkt['TKT_description']
509
+					: '',
510
+				'TKT_start_date'  => $tkt['TKT_start_date'],
511
+				'TKT_end_date'    => $tkt['TKT_end_date'],
512
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
513
+					? EE_INF
514
+					: $tkt['TKT_qty'],
515
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
516
+					? EE_INF
517
+					: $tkt['TKT_uses'],
518
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
519
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
520
+				'TKT_row'         => $row,
521
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
522
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
523
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
524
+				'TKT_price'       => $ticket_price,
525
+			);
526
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
527
+			// which means in turn that the prices will become new prices as well.
528
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
529
+				$TKT_values['TKT_ID'] = 0;
530
+				$TKT_values['TKT_is_default'] = 0;
531
+				$update_prices = true;
532
+			}
533
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
534
+			// we actually do our saves ahead of doing any add_relations to
535
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
536
+			// but DID have it's items modified.
537
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
538
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
539
+			if (absint($TKT_values['TKT_ID'])) {
540
+				$ticket = EE_Registry::instance()
541
+									 ->load_model('Ticket', array($timezone))
542
+									 ->get_one_by_ID($tkt['TKT_ID']);
543
+				if ($ticket instanceof EE_Ticket) {
544
+					$ticket = $this->_update_ticket_datetimes(
545
+						$ticket,
546
+						$saved_datetimes,
547
+						$datetimes_added,
548
+						$datetimes_removed
549
+					);
550
+					// are there any registrations using this ticket ?
551
+					$tickets_sold = $ticket->count_related(
552
+						'Registration',
553
+						array(
554
+							array(
555
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
556
+							),
557
+						)
558
+					);
559
+					// set ticket formats
560
+					$ticket->set_date_format($this->_date_format_strings['date']);
561
+					$ticket->set_time_format($this->_date_format_strings['time']);
562
+					// let's just check the total price for the existing ticket
563
+					// and determine if it matches the new total price.
564
+					// if they are different then we create a new ticket (if tickets sold)
565
+					// if they aren't different then we go ahead and modify existing ticket.
566
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
567
+					// set new values
568
+					foreach ($TKT_values as $field => $value) {
569
+						if ($field === 'TKT_qty') {
570
+							$ticket->set_qty($value);
571
+						} else {
572
+							$ticket->set($field, $value);
573
+						}
574
+					}
575
+					// if $create_new_TKT is false then we can safely update the existing ticket.
576
+					// Otherwise we have to create a new ticket.
577
+					if ($create_new_TKT) {
578
+						$new_tkt = $this->_duplicate_ticket(
579
+							$ticket,
580
+							$price_rows,
581
+							$ticket_price,
582
+							$base_price,
583
+							$base_price_id
584
+						);
585
+					}
586
+				}
587
+			} else {
588
+				// no TKT_id so a new TKT
589
+				$ticket = EE_Ticket::new_instance(
590
+					$TKT_values,
591
+					$timezone,
592
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
593
+				);
594
+				if ($ticket instanceof EE_Ticket) {
595
+					// make sure ticket has an ID of setting relations won't work
596
+					$ticket->save();
597
+					$ticket = $this->_update_ticket_datetimes(
598
+						$ticket,
599
+						$saved_datetimes,
600
+						$datetimes_added,
601
+						$datetimes_removed
602
+					);
603
+					$update_prices = true;
604
+				}
605
+			}
606
+			// make sure any current values have been saved.
607
+			// $ticket->save();
608
+			// before going any further make sure our dates are setup correctly
609
+			// so that the end date is always equal or greater than the start date.
610
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
611
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
612
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
613
+			}
614
+			// let's make sure the base price is handled
615
+			$ticket = ! $create_new_TKT
616
+				? $this->_add_prices_to_ticket(
617
+					array(),
618
+					$ticket,
619
+					$update_prices,
620
+					$base_price,
621
+					$base_price_id
622
+				)
623
+				: $ticket;
624
+			// add/update price_modifiers
625
+			$ticket = ! $create_new_TKT
626
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
627
+				: $ticket;
628
+			// need to make sue that the TKT_price is accurate after saving the prices.
629
+			$ticket->ensure_TKT_Price_correct();
630
+			// handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
631
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
632
+				$update_prices = true;
633
+				$new_default = clone $ticket;
634
+				$new_default->set('TKT_ID', 0);
635
+				$new_default->set('TKT_is_default', 1);
636
+				$new_default->set('TKT_row', 1);
637
+				$new_default->set('TKT_price', $ticket_price);
638
+				// remove any dtt relations cause we DON'T want dtt relations attached
639
+				// (note this is just removing the cached relations in the object)
640
+				$new_default->_remove_relations('Datetime');
641
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
642
+				$new_default = $this->_add_prices_to_ticket(
643
+					$price_rows,
644
+					$new_default,
645
+					$update_prices
646
+				);
647
+				// don't forget the base price!
648
+				$new_default = $this->_add_prices_to_ticket(
649
+					array(),
650
+					$new_default,
651
+					$update_prices,
652
+					$base_price,
653
+					$base_price_id
654
+				);
655
+				$new_default->save();
656
+				do_action(
657
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
658
+					$new_default,
659
+					$row,
660
+					$ticket,
661
+					$data
662
+				);
663
+			}
664
+			// DO ALL dtt relationships for both current tickets and any archived tickets
665
+			// for the given dtt that are related to the current ticket.
666
+			// TODO... not sure exactly how we're going to do this considering we don't know
667
+			// what current ticket the archived tickets are related to
668
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
669
+			// let's assign any tickets that have been setup to the saved_tickets tracker
670
+			// save existing TKT
671
+			$ticket->save();
672
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
673
+				// save new TKT
674
+				$new_tkt->save();
675
+				// add new ticket to array
676
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
677
+				do_action(
678
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
679
+					$new_tkt,
680
+					$row,
681
+					$tkt,
682
+					$data
683
+				);
684
+			} else {
685
+				// add tkt to saved tkts
686
+				$saved_tickets[ $ticket->ID() ] = $ticket;
687
+				do_action(
688
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
689
+					$ticket,
690
+					$row,
691
+					$tkt,
692
+					$data
693
+				);
694
+			}
695
+		}
696
+		// now we need to handle tickets actually "deleted permanently".
697
+		// There are cases where we'd want this to happen
698
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
699
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
700
+		// No sense in keeping all the related data in the db!
701
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
702
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
703
+		foreach ($tickets_removed as $id) {
704
+			$id = absint($id);
705
+			// get the ticket for this id
706
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
707
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
708
+			if ($tkt_to_remove->get('TKT_is_default')) {
709
+				continue;
710
+			}
711
+			// if this tkt has any registrations attached so then we just ARCHIVE
712
+			// because we don't actually permanently delete these tickets.
713
+			if ($tkt_to_remove->count_related('Registration') > 0) {
714
+				$tkt_to_remove->delete();
715
+				continue;
716
+			}
717
+			// need to get all the related datetimes on this ticket and remove from every single one of them
718
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
719
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
720
+			foreach ($datetimes as $datetime) {
721
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
722
+			}
723
+			// need to do the same for prices (except these prices can also be deleted because again,
724
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
725
+			$tkt_to_remove->delete_related_permanently('Price');
726
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
727
+			// finally let's delete this ticket
728
+			// (which should not be blocked at this point b/c we've removed all our relationships)
729
+			$tkt_to_remove->delete_permanently();
730
+		}
731
+		return $saved_tickets;
732
+	}
733 733
 
734 734
 
735
-    /**
736
-     * @access  protected
737
-     * @param EE_Ticket      $ticket
738
-     * @param \EE_Datetime[] $saved_datetimes
739
-     * @param \EE_Datetime[] $added_datetimes
740
-     * @param \EE_Datetime[] $removed_datetimes
741
-     * @return EE_Ticket
742
-     * @throws EE_Error
743
-     */
744
-    protected function _update_ticket_datetimes(
745
-        EE_Ticket $ticket,
746
-        $saved_datetimes = array(),
747
-        $added_datetimes = array(),
748
-        $removed_datetimes = array()
749
-    ) {
750
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
751
-        // and removing the ticket from datetimes it got removed from.
752
-        // first let's add datetimes
753
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
754
-            foreach ($added_datetimes as $row_id) {
755
-                $row_id = (int) $row_id;
756
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
757
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
758
-                    // Is this an existing ticket (has an ID) and does it have any sold?
759
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
760
-                    if ($ticket->ID() && $ticket->sold() > 0) {
761
-                        $saved_datetimes[ $row_id ]->increase_sold($ticket->sold());
762
-                        $saved_datetimes[ $row_id ]->save();
763
-                    }
764
-                }
765
-            }
766
-        }
767
-        // then remove datetimes
768
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
769
-            foreach ($removed_datetimes as $row_id) {
770
-                $row_id = (int) $row_id;
771
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
772
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
773
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
774
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
775
-                    // Is this an existing ticket (has an ID) and does it have any sold?
776
-                    // If so, then we need to remove it's sold from the DTT_sold.
777
-                    if ($ticket->ID() && $ticket->sold() > 0) {
778
-                        $saved_datetimes[ $row_id ]->decrease_sold($ticket->sold());
779
-                        $saved_datetimes[ $row_id ]->save();
780
-                    }
781
-                }
782
-            }
783
-        }
784
-        // cap ticket qty by datetime reg limits
785
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
786
-        return $ticket;
787
-    }
735
+	/**
736
+	 * @access  protected
737
+	 * @param EE_Ticket      $ticket
738
+	 * @param \EE_Datetime[] $saved_datetimes
739
+	 * @param \EE_Datetime[] $added_datetimes
740
+	 * @param \EE_Datetime[] $removed_datetimes
741
+	 * @return EE_Ticket
742
+	 * @throws EE_Error
743
+	 */
744
+	protected function _update_ticket_datetimes(
745
+		EE_Ticket $ticket,
746
+		$saved_datetimes = array(),
747
+		$added_datetimes = array(),
748
+		$removed_datetimes = array()
749
+	) {
750
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
751
+		// and removing the ticket from datetimes it got removed from.
752
+		// first let's add datetimes
753
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
754
+			foreach ($added_datetimes as $row_id) {
755
+				$row_id = (int) $row_id;
756
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
757
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
758
+					// Is this an existing ticket (has an ID) and does it have any sold?
759
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
760
+					if ($ticket->ID() && $ticket->sold() > 0) {
761
+						$saved_datetimes[ $row_id ]->increase_sold($ticket->sold());
762
+						$saved_datetimes[ $row_id ]->save();
763
+					}
764
+				}
765
+			}
766
+		}
767
+		// then remove datetimes
768
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
769
+			foreach ($removed_datetimes as $row_id) {
770
+				$row_id = (int) $row_id;
771
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
772
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
773
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
774
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
775
+					// Is this an existing ticket (has an ID) and does it have any sold?
776
+					// If so, then we need to remove it's sold from the DTT_sold.
777
+					if ($ticket->ID() && $ticket->sold() > 0) {
778
+						$saved_datetimes[ $row_id ]->decrease_sold($ticket->sold());
779
+						$saved_datetimes[ $row_id ]->save();
780
+					}
781
+				}
782
+			}
783
+		}
784
+		// cap ticket qty by datetime reg limits
785
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
786
+		return $ticket;
787
+	}
788 788
 
789 789
 
790
-    /**
791
-     * @access  protected
792
-     * @param EE_Ticket $ticket
793
-     * @param array     $price_rows
794
-     * @param int       $ticket_price
795
-     * @param int       $base_price
796
-     * @param int       $base_price_id
797
-     * @return EE_Ticket
798
-     * @throws ReflectionException
799
-     * @throws InvalidArgumentException
800
-     * @throws InvalidInterfaceException
801
-     * @throws InvalidDataTypeException
802
-     * @throws EE_Error
803
-     */
804
-    protected function _duplicate_ticket(
805
-        EE_Ticket $ticket,
806
-        $price_rows = array(),
807
-        $ticket_price = 0,
808
-        $base_price = 0,
809
-        $base_price_id = 0
810
-    ) {
811
-        // create new ticket that's a copy of the existing
812
-        // except a new id of course (and not archived)
813
-        // AND has the new TKT_price associated with it.
814
-        $new_ticket = clone $ticket;
815
-        $new_ticket->set('TKT_ID', 0);
816
-        $new_ticket->set_deleted(0);
817
-        $new_ticket->set_price($ticket_price);
818
-        $new_ticket->set_sold(0);
819
-        // let's get a new ID for this ticket
820
-        $new_ticket->save();
821
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
822
-        $datetimes_on_existing = $ticket->datetimes();
823
-        $new_ticket = $this->_update_ticket_datetimes(
824
-            $new_ticket,
825
-            $datetimes_on_existing,
826
-            array_keys($datetimes_on_existing)
827
-        );
828
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
829
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
830
-        // available.
831
-        if ($ticket->sold() > 0) {
832
-            $new_qty = $ticket->qty() - $ticket->sold();
833
-            $new_ticket->set_qty($new_qty);
834
-        }
835
-        // now we update the prices just for this ticket
836
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
837
-        // and we update the base price
838
-        $new_ticket = $this->_add_prices_to_ticket(
839
-            array(),
840
-            $new_ticket,
841
-            true,
842
-            $base_price,
843
-            $base_price_id
844
-        );
845
-        return $new_ticket;
846
-    }
790
+	/**
791
+	 * @access  protected
792
+	 * @param EE_Ticket $ticket
793
+	 * @param array     $price_rows
794
+	 * @param int       $ticket_price
795
+	 * @param int       $base_price
796
+	 * @param int       $base_price_id
797
+	 * @return EE_Ticket
798
+	 * @throws ReflectionException
799
+	 * @throws InvalidArgumentException
800
+	 * @throws InvalidInterfaceException
801
+	 * @throws InvalidDataTypeException
802
+	 * @throws EE_Error
803
+	 */
804
+	protected function _duplicate_ticket(
805
+		EE_Ticket $ticket,
806
+		$price_rows = array(),
807
+		$ticket_price = 0,
808
+		$base_price = 0,
809
+		$base_price_id = 0
810
+	) {
811
+		// create new ticket that's a copy of the existing
812
+		// except a new id of course (and not archived)
813
+		// AND has the new TKT_price associated with it.
814
+		$new_ticket = clone $ticket;
815
+		$new_ticket->set('TKT_ID', 0);
816
+		$new_ticket->set_deleted(0);
817
+		$new_ticket->set_price($ticket_price);
818
+		$new_ticket->set_sold(0);
819
+		// let's get a new ID for this ticket
820
+		$new_ticket->save();
821
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
822
+		$datetimes_on_existing = $ticket->datetimes();
823
+		$new_ticket = $this->_update_ticket_datetimes(
824
+			$new_ticket,
825
+			$datetimes_on_existing,
826
+			array_keys($datetimes_on_existing)
827
+		);
828
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
829
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
830
+		// available.
831
+		if ($ticket->sold() > 0) {
832
+			$new_qty = $ticket->qty() - $ticket->sold();
833
+			$new_ticket->set_qty($new_qty);
834
+		}
835
+		// now we update the prices just for this ticket
836
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
837
+		// and we update the base price
838
+		$new_ticket = $this->_add_prices_to_ticket(
839
+			array(),
840
+			$new_ticket,
841
+			true,
842
+			$base_price,
843
+			$base_price_id
844
+		);
845
+		return $new_ticket;
846
+	}
847 847
 
848 848
 
849
-    /**
850
-     * This attaches a list of given prices to a ticket.
851
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
852
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
853
-     * price info and prices are automatically "archived" via the ticket.
854
-     *
855
-     * @access  private
856
-     * @param array     $prices        Array of prices from the form.
857
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
858
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
859
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
860
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
861
-     * @return EE_Ticket
862
-     * @throws ReflectionException
863
-     * @throws InvalidArgumentException
864
-     * @throws InvalidInterfaceException
865
-     * @throws InvalidDataTypeException
866
-     * @throws EE_Error
867
-     */
868
-    protected function _add_prices_to_ticket(
869
-        $prices = array(),
870
-        EE_Ticket $ticket,
871
-        $new_prices = false,
872
-        $base_price = false,
873
-        $base_price_id = false
874
-    ) {
875
-        // let's just get any current prices that may exist on the given ticket
876
-        // so we can remove any prices that got trashed in this session.
877
-        $current_prices_on_ticket = $base_price !== false
878
-            ? $ticket->base_price(true)
879
-            : $ticket->price_modifiers();
880
-        $updated_prices = array();
881
-        // if $base_price ! FALSE then updating a base price.
882
-        if ($base_price !== false) {
883
-            $prices[1] = array(
884
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
885
-                'PRT_ID'     => 1,
886
-                'PRC_amount' => $base_price,
887
-                'PRC_name'   => $ticket->get('TKT_name'),
888
-                'PRC_desc'   => $ticket->get('TKT_description'),
889
-            );
890
-        }
891
-        // possibly need to save tkt
892
-        if (! $ticket->ID()) {
893
-            $ticket->save();
894
-        }
895
-        foreach ($prices as $row => $prc) {
896
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
897
-            if (empty($prt_id)) {
898
-                continue;
899
-            } //prices MUST have a price type id.
900
-            $PRC_values = array(
901
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
902
-                'PRT_ID'         => $prt_id,
903
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
904
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
905
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
906
-                'PRC_is_default' => false,
907
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
908
-                'PRC_order'      => $row,
909
-            );
910
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
911
-                $PRC_values['PRC_ID'] = 0;
912
-                $price = EE_Registry::instance()->load_class(
913
-                    'Price',
914
-                    array($PRC_values),
915
-                    false,
916
-                    false
917
-                );
918
-            } else {
919
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
920
-                // update this price with new values
921
-                foreach ($PRC_values as $field => $value) {
922
-                    $price->set($field, $value);
923
-                }
924
-            }
925
-            $price->save();
926
-            $updated_prices[ $price->ID() ] = $price;
927
-            $ticket->_add_relation_to($price, 'Price');
928
-        }
929
-        // now let's remove any prices that got removed from the ticket
930
-        if (! empty($current_prices_on_ticket)) {
931
-            $current = array_keys($current_prices_on_ticket);
932
-            $updated = array_keys($updated_prices);
933
-            $prices_to_remove = array_diff($current, $updated);
934
-            if (! empty($prices_to_remove)) {
935
-                foreach ($prices_to_remove as $prc_id) {
936
-                    $p = $current_prices_on_ticket[ $prc_id ];
937
-                    $ticket->_remove_relation_to($p, 'Price');
938
-                    // delete permanently the price
939
-                    $p->delete_permanently();
940
-                }
941
-            }
942
-        }
943
-        return $ticket;
944
-    }
849
+	/**
850
+	 * This attaches a list of given prices to a ticket.
851
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
852
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
853
+	 * price info and prices are automatically "archived" via the ticket.
854
+	 *
855
+	 * @access  private
856
+	 * @param array     $prices        Array of prices from the form.
857
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
858
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
859
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
860
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
861
+	 * @return EE_Ticket
862
+	 * @throws ReflectionException
863
+	 * @throws InvalidArgumentException
864
+	 * @throws InvalidInterfaceException
865
+	 * @throws InvalidDataTypeException
866
+	 * @throws EE_Error
867
+	 */
868
+	protected function _add_prices_to_ticket(
869
+		$prices = array(),
870
+		EE_Ticket $ticket,
871
+		$new_prices = false,
872
+		$base_price = false,
873
+		$base_price_id = false
874
+	) {
875
+		// let's just get any current prices that may exist on the given ticket
876
+		// so we can remove any prices that got trashed in this session.
877
+		$current_prices_on_ticket = $base_price !== false
878
+			? $ticket->base_price(true)
879
+			: $ticket->price_modifiers();
880
+		$updated_prices = array();
881
+		// if $base_price ! FALSE then updating a base price.
882
+		if ($base_price !== false) {
883
+			$prices[1] = array(
884
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
885
+				'PRT_ID'     => 1,
886
+				'PRC_amount' => $base_price,
887
+				'PRC_name'   => $ticket->get('TKT_name'),
888
+				'PRC_desc'   => $ticket->get('TKT_description'),
889
+			);
890
+		}
891
+		// possibly need to save tkt
892
+		if (! $ticket->ID()) {
893
+			$ticket->save();
894
+		}
895
+		foreach ($prices as $row => $prc) {
896
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
897
+			if (empty($prt_id)) {
898
+				continue;
899
+			} //prices MUST have a price type id.
900
+			$PRC_values = array(
901
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
902
+				'PRT_ID'         => $prt_id,
903
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
904
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
905
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
906
+				'PRC_is_default' => false,
907
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
908
+				'PRC_order'      => $row,
909
+			);
910
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
911
+				$PRC_values['PRC_ID'] = 0;
912
+				$price = EE_Registry::instance()->load_class(
913
+					'Price',
914
+					array($PRC_values),
915
+					false,
916
+					false
917
+				);
918
+			} else {
919
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
920
+				// update this price with new values
921
+				foreach ($PRC_values as $field => $value) {
922
+					$price->set($field, $value);
923
+				}
924
+			}
925
+			$price->save();
926
+			$updated_prices[ $price->ID() ] = $price;
927
+			$ticket->_add_relation_to($price, 'Price');
928
+		}
929
+		// now let's remove any prices that got removed from the ticket
930
+		if (! empty($current_prices_on_ticket)) {
931
+			$current = array_keys($current_prices_on_ticket);
932
+			$updated = array_keys($updated_prices);
933
+			$prices_to_remove = array_diff($current, $updated);
934
+			if (! empty($prices_to_remove)) {
935
+				foreach ($prices_to_remove as $prc_id) {
936
+					$p = $current_prices_on_ticket[ $prc_id ];
937
+					$ticket->_remove_relation_to($p, 'Price');
938
+					// delete permanently the price
939
+					$p->delete_permanently();
940
+				}
941
+			}
942
+		}
943
+		return $ticket;
944
+	}
945 945
 
946 946
 
947
-    /**
948
-     * @param Events_Admin_Page $event_admin_obj
949
-     * @return Events_Admin_Page
950
-     */
951
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
952
-    {
953
-        return $event_admin_obj;
954
-        // doing nothing for the moment.
955
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
956
-        // (use the set_template_args() method)
957
-        /**
958
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
959
-         * 1. TKT_is_default_selector (visible)
960
-         * 2. TKT_is_default (hidden)
961
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
962
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
963
-         * this ticket to be saved as a default.
964
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
965
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
966
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
967
-         * the TKT HAS been saved as a default..
968
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
969
-         * On Autosave:
970
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
971
-         * then set the TKT_is_default to false.
972
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
973
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
974
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
975
-         */
976
-    }
947
+	/**
948
+	 * @param Events_Admin_Page $event_admin_obj
949
+	 * @return Events_Admin_Page
950
+	 */
951
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
952
+	{
953
+		return $event_admin_obj;
954
+		// doing nothing for the moment.
955
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
956
+		// (use the set_template_args() method)
957
+		/**
958
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
959
+		 * 1. TKT_is_default_selector (visible)
960
+		 * 2. TKT_is_default (hidden)
961
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
962
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
963
+		 * this ticket to be saved as a default.
964
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
965
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
966
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
967
+		 * the TKT HAS been saved as a default..
968
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
969
+		 * On Autosave:
970
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
971
+		 * then set the TKT_is_default to false.
972
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
973
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
974
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
975
+		 */
976
+	}
977 977
 
978 978
 
979
-    /**
980
-     * @throws ReflectionException
981
-     * @throws InvalidArgumentException
982
-     * @throws InvalidInterfaceException
983
-     * @throws InvalidDataTypeException
984
-     * @throws DomainException
985
-     * @throws EE_Error
986
-     */
987
-    public function pricing_metabox()
988
-    {
989
-        /**
990
-         * Fires before any logic runs for the "Event Tickets and Datetimes" metabox in the Event Espresso Event Editor
991
-         *
992
-         * @since $VID:$
993
-         * @param espresso_events_Pricing_Hooks $this
994
-         */
995
-        do_action('AHEE__espresso_events_Pricing_Hooks___pricing_metabox__start', $this);
979
+	/**
980
+	 * @throws ReflectionException
981
+	 * @throws InvalidArgumentException
982
+	 * @throws InvalidInterfaceException
983
+	 * @throws InvalidDataTypeException
984
+	 * @throws DomainException
985
+	 * @throws EE_Error
986
+	 */
987
+	public function pricing_metabox()
988
+	{
989
+		/**
990
+		 * Fires before any logic runs for the "Event Tickets and Datetimes" metabox in the Event Espresso Event Editor
991
+		 *
992
+		 * @since $VID:$
993
+		 * @param espresso_events_Pricing_Hooks $this
994
+		 */
995
+		do_action('AHEE__espresso_events_Pricing_Hooks___pricing_metabox__start', $this);
996 996
 
997
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
998
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
999
-        // set is_creating_event property.
1000
-        $EVT_ID = $event->ID();
1001
-        $this->_is_creating_event = empty($this->_req_data['post']);
1002
-        // default main template args
1003
-        $main_template_args = array(
1004
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1005
-                'event_editor_event_datetimes_help_tab',
1006
-                $this->_adminpage_obj->page_slug,
1007
-                $this->_adminpage_obj->get_req_action(),
1008
-                false,
1009
-                false
1010
-            ),
1011
-            // todo need to add a filter to the template for the help text
1012
-            // in the Events_Admin_Page core file so we can add further help
1013
-            'existing_datetime_ids'    => '',
1014
-            'total_dtt_rows'           => 1,
1015
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1016
-                'add_new_dtt_info',
1017
-                $this->_adminpage_obj->page_slug,
1018
-                $this->_adminpage_obj->get_req_action(),
1019
-                false,
1020
-                false
1021
-            ),
1022
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1023
-            'datetime_rows'            => '',
1024
-            'show_tickets_container'   => '',
1025
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1026
-            'ticket_rows'              => '',
1027
-            'existing_ticket_ids'      => '',
1028
-            'total_ticket_rows'        => 1,
1029
-            'ticket_js_structure'      => '',
1030
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1031
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1032
-        );
1033
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1034
-        /**
1035
-         * 1. Start with retrieving Datetimes
1036
-         * 2. For each datetime get related tickets
1037
-         * 3. For each ticket get related prices
1038
-         */
1039
-        /** @var EEM_Datetime $datetime_model */
1040
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1041
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1042
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1043
-        /**
1044
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1045
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1046
-         */
1047
-        $datetime_row = 1;
1048
-        foreach ($datetimes as $datetime) {
1049
-            $DTT_ID = $datetime->get('DTT_ID');
1050
-            $datetime->set('DTT_order', $datetime_row);
1051
-            $existing_datetime_ids[] = $DTT_ID;
1052
-            // tickets attached
1053
-            $related_tickets = $datetime->ID() > 0
1054
-                ? $datetime->get_many_related(
1055
-                    'Ticket',
1056
-                    array(
1057
-                        array(
1058
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1059
-                        ),
1060
-                        'default_where_conditions' => 'none',
1061
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1062
-                    )
1063
-                )
1064
-                : array();
1065
-            // if there are no related tickets this is likely a new event OR autodraft
1066
-            // event so we need to generate the default tickets because datetimes
1067
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1068
-            // datetime on the event.
1069
-            if (empty($related_tickets) && count($datetimes) < 2) {
1070
-                /** @var EEM_Ticket $ticket_model */
1071
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1072
-                $related_tickets = $ticket_model->get_all_default_tickets();
1073
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1074
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1075
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1076
-                $main_default_ticket = reset($related_tickets);
1077
-                if ($main_default_ticket instanceof EE_Ticket) {
1078
-                    foreach ($default_prices as $default_price) {
1079
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1080
-                            continue;
1081
-                        }
1082
-                        $main_default_ticket->cache('Price', $default_price);
1083
-                    }
1084
-                }
1085
-            }
1086
-            // we can't actually setup rows in this loop yet cause we don't know all
1087
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1088
-            // So we're going to temporarily cache some of that information.
1089
-            // loop through and setup the ticket rows and make sure the order is set.
1090
-            foreach ($related_tickets as $ticket) {
1091
-                $TKT_ID = $ticket->get('TKT_ID');
1092
-                $ticket_row = $ticket->get('TKT_row');
1093
-                // we only want unique tickets in our final display!!
1094
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1095
-                    $existing_ticket_ids[] = $TKT_ID;
1096
-                    $all_tickets[] = $ticket;
1097
-                }
1098
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1099
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1100
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1101
-                if (! isset($ticket_datetimes[ $TKT_ID ])
1102
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1103
-                ) {
1104
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1105
-                }
1106
-            }
1107
-            $datetime_row++;
1108
-        }
1109
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1110
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1111
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1112
-        // sort $all_tickets by order
1113
-        usort(
1114
-            $all_tickets,
1115
-            function (EE_Ticket $a, EE_Ticket $b) {
1116
-                $a_order = (int) $a->get('TKT_order');
1117
-                $b_order = (int) $b->get('TKT_order');
1118
-                if ($a_order === $b_order) {
1119
-                    return 0;
1120
-                }
1121
-                return ($a_order < $b_order) ? -1 : 1;
1122
-            }
1123
-        );
1124
-        // k NOW we have all the data we need for setting up the dtt rows
1125
-        // and ticket rows so we start our dtt loop again.
1126
-        $datetime_row = 1;
1127
-        foreach ($datetimes as $datetime) {
1128
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1129
-                $datetime_row,
1130
-                $datetime,
1131
-                $datetime_tickets,
1132
-                $all_tickets,
1133
-                false,
1134
-                $datetimes
1135
-            );
1136
-            $datetime_row++;
1137
-        }
1138
-        // then loop through all tickets for the ticket rows.
1139
-        $ticket_row = 1;
1140
-        foreach ($all_tickets as $ticket) {
1141
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1142
-                $ticket_row,
1143
-                $ticket,
1144
-                $ticket_datetimes,
1145
-                $datetimes,
1146
-                false,
1147
-                $all_tickets
1148
-            );
1149
-            $ticket_row++;
1150
-        }
1151
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1152
-        EEH_Template::display_template(
1153
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1154
-            $main_template_args
1155
-        );
1156
-    }
997
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
998
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
999
+		// set is_creating_event property.
1000
+		$EVT_ID = $event->ID();
1001
+		$this->_is_creating_event = empty($this->_req_data['post']);
1002
+		// default main template args
1003
+		$main_template_args = array(
1004
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1005
+				'event_editor_event_datetimes_help_tab',
1006
+				$this->_adminpage_obj->page_slug,
1007
+				$this->_adminpage_obj->get_req_action(),
1008
+				false,
1009
+				false
1010
+			),
1011
+			// todo need to add a filter to the template for the help text
1012
+			// in the Events_Admin_Page core file so we can add further help
1013
+			'existing_datetime_ids'    => '',
1014
+			'total_dtt_rows'           => 1,
1015
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1016
+				'add_new_dtt_info',
1017
+				$this->_adminpage_obj->page_slug,
1018
+				$this->_adminpage_obj->get_req_action(),
1019
+				false,
1020
+				false
1021
+			),
1022
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1023
+			'datetime_rows'            => '',
1024
+			'show_tickets_container'   => '',
1025
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1026
+			'ticket_rows'              => '',
1027
+			'existing_ticket_ids'      => '',
1028
+			'total_ticket_rows'        => 1,
1029
+			'ticket_js_structure'      => '',
1030
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1031
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1032
+		);
1033
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1034
+		/**
1035
+		 * 1. Start with retrieving Datetimes
1036
+		 * 2. For each datetime get related tickets
1037
+		 * 3. For each ticket get related prices
1038
+		 */
1039
+		/** @var EEM_Datetime $datetime_model */
1040
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1041
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1042
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1043
+		/**
1044
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1045
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1046
+		 */
1047
+		$datetime_row = 1;
1048
+		foreach ($datetimes as $datetime) {
1049
+			$DTT_ID = $datetime->get('DTT_ID');
1050
+			$datetime->set('DTT_order', $datetime_row);
1051
+			$existing_datetime_ids[] = $DTT_ID;
1052
+			// tickets attached
1053
+			$related_tickets = $datetime->ID() > 0
1054
+				? $datetime->get_many_related(
1055
+					'Ticket',
1056
+					array(
1057
+						array(
1058
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1059
+						),
1060
+						'default_where_conditions' => 'none',
1061
+						'order_by'                 => array('TKT_order' => 'ASC'),
1062
+					)
1063
+				)
1064
+				: array();
1065
+			// if there are no related tickets this is likely a new event OR autodraft
1066
+			// event so we need to generate the default tickets because datetimes
1067
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1068
+			// datetime on the event.
1069
+			if (empty($related_tickets) && count($datetimes) < 2) {
1070
+				/** @var EEM_Ticket $ticket_model */
1071
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1072
+				$related_tickets = $ticket_model->get_all_default_tickets();
1073
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1074
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1075
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1076
+				$main_default_ticket = reset($related_tickets);
1077
+				if ($main_default_ticket instanceof EE_Ticket) {
1078
+					foreach ($default_prices as $default_price) {
1079
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1080
+							continue;
1081
+						}
1082
+						$main_default_ticket->cache('Price', $default_price);
1083
+					}
1084
+				}
1085
+			}
1086
+			// we can't actually setup rows in this loop yet cause we don't know all
1087
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1088
+			// So we're going to temporarily cache some of that information.
1089
+			// loop through and setup the ticket rows and make sure the order is set.
1090
+			foreach ($related_tickets as $ticket) {
1091
+				$TKT_ID = $ticket->get('TKT_ID');
1092
+				$ticket_row = $ticket->get('TKT_row');
1093
+				// we only want unique tickets in our final display!!
1094
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1095
+					$existing_ticket_ids[] = $TKT_ID;
1096
+					$all_tickets[] = $ticket;
1097
+				}
1098
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1099
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1100
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1101
+				if (! isset($ticket_datetimes[ $TKT_ID ])
1102
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1103
+				) {
1104
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1105
+				}
1106
+			}
1107
+			$datetime_row++;
1108
+		}
1109
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1110
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1111
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1112
+		// sort $all_tickets by order
1113
+		usort(
1114
+			$all_tickets,
1115
+			function (EE_Ticket $a, EE_Ticket $b) {
1116
+				$a_order = (int) $a->get('TKT_order');
1117
+				$b_order = (int) $b->get('TKT_order');
1118
+				if ($a_order === $b_order) {
1119
+					return 0;
1120
+				}
1121
+				return ($a_order < $b_order) ? -1 : 1;
1122
+			}
1123
+		);
1124
+		// k NOW we have all the data we need for setting up the dtt rows
1125
+		// and ticket rows so we start our dtt loop again.
1126
+		$datetime_row = 1;
1127
+		foreach ($datetimes as $datetime) {
1128
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1129
+				$datetime_row,
1130
+				$datetime,
1131
+				$datetime_tickets,
1132
+				$all_tickets,
1133
+				false,
1134
+				$datetimes
1135
+			);
1136
+			$datetime_row++;
1137
+		}
1138
+		// then loop through all tickets for the ticket rows.
1139
+		$ticket_row = 1;
1140
+		foreach ($all_tickets as $ticket) {
1141
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1142
+				$ticket_row,
1143
+				$ticket,
1144
+				$ticket_datetimes,
1145
+				$datetimes,
1146
+				false,
1147
+				$all_tickets
1148
+			);
1149
+			$ticket_row++;
1150
+		}
1151
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1152
+		EEH_Template::display_template(
1153
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1154
+			$main_template_args
1155
+		);
1156
+	}
1157 1157
 
1158 1158
 
1159
-    /**
1160
-     * @param int         $datetime_row
1161
-     * @param EE_Datetime $datetime
1162
-     * @param array       $datetime_tickets
1163
-     * @param array       $all_tickets
1164
-     * @param bool        $default
1165
-     * @param array       $all_datetimes
1166
-     * @return mixed
1167
-     * @throws DomainException
1168
-     * @throws EE_Error
1169
-     */
1170
-    protected function _get_datetime_row(
1171
-        $datetime_row,
1172
-        EE_Datetime $datetime,
1173
-        $datetime_tickets = array(),
1174
-        $all_tickets = array(),
1175
-        $default = false,
1176
-        $all_datetimes = array()
1177
-    ) {
1178
-        $dtt_display_template_args = array(
1179
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1180
-                $datetime_row,
1181
-                $datetime,
1182
-                $default,
1183
-                $all_datetimes
1184
-            ),
1185
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1186
-                $datetime_row,
1187
-                $datetime,
1188
-                $datetime_tickets,
1189
-                $all_tickets,
1190
-                $default
1191
-            ),
1192
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1193
-        );
1194
-        return EEH_Template::display_template(
1195
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1196
-            $dtt_display_template_args,
1197
-            true
1198
-        );
1199
-    }
1159
+	/**
1160
+	 * @param int         $datetime_row
1161
+	 * @param EE_Datetime $datetime
1162
+	 * @param array       $datetime_tickets
1163
+	 * @param array       $all_tickets
1164
+	 * @param bool        $default
1165
+	 * @param array       $all_datetimes
1166
+	 * @return mixed
1167
+	 * @throws DomainException
1168
+	 * @throws EE_Error
1169
+	 */
1170
+	protected function _get_datetime_row(
1171
+		$datetime_row,
1172
+		EE_Datetime $datetime,
1173
+		$datetime_tickets = array(),
1174
+		$all_tickets = array(),
1175
+		$default = false,
1176
+		$all_datetimes = array()
1177
+	) {
1178
+		$dtt_display_template_args = array(
1179
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1180
+				$datetime_row,
1181
+				$datetime,
1182
+				$default,
1183
+				$all_datetimes
1184
+			),
1185
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1186
+				$datetime_row,
1187
+				$datetime,
1188
+				$datetime_tickets,
1189
+				$all_tickets,
1190
+				$default
1191
+			),
1192
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1193
+		);
1194
+		return EEH_Template::display_template(
1195
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1196
+			$dtt_display_template_args,
1197
+			true
1198
+		);
1199
+	}
1200 1200
 
1201 1201
 
1202
-    /**
1203
-     * This method is used to generate a dtt fields  edit row.
1204
-     * The same row is used to generate a row with valid DTT objects
1205
-     * and the default row that is used as the skeleton by the js.
1206
-     *
1207
-     * @param int           $datetime_row  The row number for the row being generated.
1208
-     * @param EE_Datetime   $datetime
1209
-     * @param bool          $default       Whether a default row is being generated or not.
1210
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1211
-     * @return string
1212
-     * @throws DomainException
1213
-     * @throws EE_Error
1214
-     */
1215
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1216
-    {
1217
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1218
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1219
-        $template_args = array(
1220
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1221
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1222
-            'edit_dtt_expanded'    => '',
1223
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1224
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1225
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1226
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1227
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1228
-            'DTT_reg_limit'        => $default
1229
-                ? ''
1230
-                : $datetime->get_pretty(
1231
-                    'DTT_reg_limit',
1232
-                    'input'
1233
-                ),
1234
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1235
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1236
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1237
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1238
-                ? ''
1239
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1240
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1241
-                ? 'ee-lock-icon'
1242
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1243
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1244
-                ? ''
1245
-                : EE_Admin_Page::add_query_args_and_nonce(
1246
-                    array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1247
-                    REG_ADMIN_URL
1248
-                ),
1249
-        );
1250
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1251
-            ? ' style="display:none"'
1252
-            : '';
1253
-        // allow filtering of template args at this point.
1254
-        $template_args = apply_filters(
1255
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1256
-            $template_args,
1257
-            $datetime_row,
1258
-            $datetime,
1259
-            $default,
1260
-            $all_datetimes,
1261
-            $this->_is_creating_event
1262
-        );
1263
-        return EEH_Template::display_template(
1264
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1265
-            $template_args,
1266
-            true
1267
-        );
1268
-    }
1202
+	/**
1203
+	 * This method is used to generate a dtt fields  edit row.
1204
+	 * The same row is used to generate a row with valid DTT objects
1205
+	 * and the default row that is used as the skeleton by the js.
1206
+	 *
1207
+	 * @param int           $datetime_row  The row number for the row being generated.
1208
+	 * @param EE_Datetime   $datetime
1209
+	 * @param bool          $default       Whether a default row is being generated or not.
1210
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1211
+	 * @return string
1212
+	 * @throws DomainException
1213
+	 * @throws EE_Error
1214
+	 */
1215
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1216
+	{
1217
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1218
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1219
+		$template_args = array(
1220
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1221
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1222
+			'edit_dtt_expanded'    => '',
1223
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1224
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1225
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1226
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1227
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1228
+			'DTT_reg_limit'        => $default
1229
+				? ''
1230
+				: $datetime->get_pretty(
1231
+					'DTT_reg_limit',
1232
+					'input'
1233
+				),
1234
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1235
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1236
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1237
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1238
+				? ''
1239
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1240
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1241
+				? 'ee-lock-icon'
1242
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1243
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1244
+				? ''
1245
+				: EE_Admin_Page::add_query_args_and_nonce(
1246
+					array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1247
+					REG_ADMIN_URL
1248
+				),
1249
+		);
1250
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1251
+			? ' style="display:none"'
1252
+			: '';
1253
+		// allow filtering of template args at this point.
1254
+		$template_args = apply_filters(
1255
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1256
+			$template_args,
1257
+			$datetime_row,
1258
+			$datetime,
1259
+			$default,
1260
+			$all_datetimes,
1261
+			$this->_is_creating_event
1262
+		);
1263
+		return EEH_Template::display_template(
1264
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1265
+			$template_args,
1266
+			true
1267
+		);
1268
+	}
1269 1269
 
1270 1270
 
1271
-    /**
1272
-     * @param int         $datetime_row
1273
-     * @param EE_Datetime $datetime
1274
-     * @param array       $datetime_tickets
1275
-     * @param array       $all_tickets
1276
-     * @param bool        $default
1277
-     * @return mixed
1278
-     * @throws DomainException
1279
-     * @throws EE_Error
1280
-     */
1281
-    protected function _get_dtt_attached_tickets_row(
1282
-        $datetime_row,
1283
-        $datetime,
1284
-        $datetime_tickets = array(),
1285
-        $all_tickets = array(),
1286
-        $default
1287
-    ) {
1288
-        $template_args = array(
1289
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1290
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1291
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1292
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1293
-            'show_tickets_row'                  => ' style="display:none;"',
1294
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1295
-                'add_new_ticket_via_datetime',
1296
-                $this->_adminpage_obj->page_slug,
1297
-                $this->_adminpage_obj->get_req_action(),
1298
-                false,
1299
-                false
1300
-            ),
1301
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1302
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1303
-        );
1304
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1305
-        if (! $default) {
1306
-            $ticket_row = 1;
1307
-            foreach ($all_tickets as $ticket) {
1308
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1309
-                    $datetime_row,
1310
-                    $ticket_row,
1311
-                    $datetime,
1312
-                    $ticket,
1313
-                    $datetime_tickets,
1314
-                    $default
1315
-                );
1316
-                $ticket_row++;
1317
-            }
1318
-        }
1319
-        // filter template args at this point
1320
-        $template_args = apply_filters(
1321
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1322
-            $template_args,
1323
-            $datetime_row,
1324
-            $datetime,
1325
-            $datetime_tickets,
1326
-            $all_tickets,
1327
-            $default,
1328
-            $this->_is_creating_event
1329
-        );
1330
-        return EEH_Template::display_template(
1331
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1332
-            $template_args,
1333
-            true
1334
-        );
1335
-    }
1271
+	/**
1272
+	 * @param int         $datetime_row
1273
+	 * @param EE_Datetime $datetime
1274
+	 * @param array       $datetime_tickets
1275
+	 * @param array       $all_tickets
1276
+	 * @param bool        $default
1277
+	 * @return mixed
1278
+	 * @throws DomainException
1279
+	 * @throws EE_Error
1280
+	 */
1281
+	protected function _get_dtt_attached_tickets_row(
1282
+		$datetime_row,
1283
+		$datetime,
1284
+		$datetime_tickets = array(),
1285
+		$all_tickets = array(),
1286
+		$default
1287
+	) {
1288
+		$template_args = array(
1289
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1290
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1291
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1292
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1293
+			'show_tickets_row'                  => ' style="display:none;"',
1294
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1295
+				'add_new_ticket_via_datetime',
1296
+				$this->_adminpage_obj->page_slug,
1297
+				$this->_adminpage_obj->get_req_action(),
1298
+				false,
1299
+				false
1300
+			),
1301
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1302
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1303
+		);
1304
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1305
+		if (! $default) {
1306
+			$ticket_row = 1;
1307
+			foreach ($all_tickets as $ticket) {
1308
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1309
+					$datetime_row,
1310
+					$ticket_row,
1311
+					$datetime,
1312
+					$ticket,
1313
+					$datetime_tickets,
1314
+					$default
1315
+				);
1316
+				$ticket_row++;
1317
+			}
1318
+		}
1319
+		// filter template args at this point
1320
+		$template_args = apply_filters(
1321
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1322
+			$template_args,
1323
+			$datetime_row,
1324
+			$datetime,
1325
+			$datetime_tickets,
1326
+			$all_tickets,
1327
+			$default,
1328
+			$this->_is_creating_event
1329
+		);
1330
+		return EEH_Template::display_template(
1331
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1332
+			$template_args,
1333
+			true
1334
+		);
1335
+	}
1336 1336
 
1337 1337
 
1338
-    /**
1339
-     * @param int         $datetime_row
1340
-     * @param int         $ticket_row
1341
-     * @param EE_Datetime $datetime
1342
-     * @param EE_Ticket   $ticket
1343
-     * @param array       $datetime_tickets
1344
-     * @param bool        $default
1345
-     * @return mixed
1346
-     * @throws DomainException
1347
-     * @throws EE_Error
1348
-     */
1349
-    protected function _get_datetime_tickets_list_item(
1350
-        $datetime_row,
1351
-        $ticket_row,
1352
-        $datetime,
1353
-        $ticket,
1354
-        $datetime_tickets = array(),
1355
-        $default
1356
-    ) {
1357
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1358
-            ? $datetime_tickets[ $datetime->ID() ]
1359
-            : array();
1360
-        $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1361
-        $no_ticket = $default && empty($ticket);
1362
-        $template_args = array(
1363
-            'dtt_row'                 => $default
1364
-                ? 'DTTNUM'
1365
-                : $datetime_row,
1366
-            'tkt_row'                 => $no_ticket
1367
-                ? 'TICKETNUM'
1368
-                : $ticket_row,
1369
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1370
-                ? ' checked="checked"'
1371
-                : '',
1372
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1373
-                ? ' ticket-selected'
1374
-                : '',
1375
-            'TKT_name'                => $no_ticket
1376
-                ? 'TKTNAME'
1377
-                : $ticket->get('TKT_name'),
1378
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1379
-                ? ' tkt-status-' . EE_Ticket::onsale
1380
-                : ' tkt-status-' . $ticket->ticket_status(),
1381
-        );
1382
-        // filter template args
1383
-        $template_args = apply_filters(
1384
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1385
-            $template_args,
1386
-            $datetime_row,
1387
-            $ticket_row,
1388
-            $datetime,
1389
-            $ticket,
1390
-            $datetime_tickets,
1391
-            $default,
1392
-            $this->_is_creating_event
1393
-        );
1394
-        return EEH_Template::display_template(
1395
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1396
-            $template_args,
1397
-            true
1398
-        );
1399
-    }
1338
+	/**
1339
+	 * @param int         $datetime_row
1340
+	 * @param int         $ticket_row
1341
+	 * @param EE_Datetime $datetime
1342
+	 * @param EE_Ticket   $ticket
1343
+	 * @param array       $datetime_tickets
1344
+	 * @param bool        $default
1345
+	 * @return mixed
1346
+	 * @throws DomainException
1347
+	 * @throws EE_Error
1348
+	 */
1349
+	protected function _get_datetime_tickets_list_item(
1350
+		$datetime_row,
1351
+		$ticket_row,
1352
+		$datetime,
1353
+		$ticket,
1354
+		$datetime_tickets = array(),
1355
+		$default
1356
+	) {
1357
+		$dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1358
+			? $datetime_tickets[ $datetime->ID() ]
1359
+			: array();
1360
+		$display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1361
+		$no_ticket = $default && empty($ticket);
1362
+		$template_args = array(
1363
+			'dtt_row'                 => $default
1364
+				? 'DTTNUM'
1365
+				: $datetime_row,
1366
+			'tkt_row'                 => $no_ticket
1367
+				? 'TICKETNUM'
1368
+				: $ticket_row,
1369
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1370
+				? ' checked="checked"'
1371
+				: '',
1372
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1373
+				? ' ticket-selected'
1374
+				: '',
1375
+			'TKT_name'                => $no_ticket
1376
+				? 'TKTNAME'
1377
+				: $ticket->get('TKT_name'),
1378
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1379
+				? ' tkt-status-' . EE_Ticket::onsale
1380
+				: ' tkt-status-' . $ticket->ticket_status(),
1381
+		);
1382
+		// filter template args
1383
+		$template_args = apply_filters(
1384
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1385
+			$template_args,
1386
+			$datetime_row,
1387
+			$ticket_row,
1388
+			$datetime,
1389
+			$ticket,
1390
+			$datetime_tickets,
1391
+			$default,
1392
+			$this->_is_creating_event
1393
+		);
1394
+		return EEH_Template::display_template(
1395
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1396
+			$template_args,
1397
+			true
1398
+		);
1399
+	}
1400 1400
 
1401 1401
 
1402
-    /**
1403
-     * This generates the ticket row for tickets.
1404
-     * This same method is used to generate both the actual rows and the js skeleton row
1405
-     * (when default === true)
1406
-     *
1407
-     * @param int           $ticket_row       Represents the row number being generated.
1408
-     * @param               $ticket
1409
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1410
-     *                                        or empty for default
1411
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1412
-     * @param bool          $default          Whether default row being generated or not.
1413
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1414
-     *                                        (or empty in the case of defaults)
1415
-     * @return mixed
1416
-     * @throws InvalidArgumentException
1417
-     * @throws InvalidInterfaceException
1418
-     * @throws InvalidDataTypeException
1419
-     * @throws DomainException
1420
-     * @throws EE_Error
1421
-     * @throws ReflectionException
1422
-     */
1423
-    protected function _get_ticket_row(
1424
-        $ticket_row,
1425
-        $ticket,
1426
-        $ticket_datetimes,
1427
-        $all_datetimes,
1428
-        $default = false,
1429
-        $all_tickets = array()
1430
-    ) {
1431
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1432
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1433
-        $prices = ! empty($ticket) && ! $default
1434
-            ? $ticket->get_many_related(
1435
-                'Price',
1436
-                array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1437
-            )
1438
-            : array();
1439
-        // if there is only one price (which would be the base price)
1440
-        // or NO prices and this ticket is a default ticket,
1441
-        // let's just make sure there are no cached default prices on the object.
1442
-        // This is done by not including any query_params.
1443
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1444
-            $prices = $ticket->prices();
1445
-        }
1446
-        // check if we're dealing with a default ticket in which case
1447
-        // we don't want any starting_ticket_datetime_row values set
1448
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1449
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1450
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1451
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1452
-            ? $ticket_datetimes[ $ticket->ID() ]
1453
-            : array();
1454
-        $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1455
-        $base_price = $default ? null : $ticket->base_price();
1456
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1457
-        // breaking out complicated condition for ticket_status
1458
-        if ($default) {
1459
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1460
-        } else {
1461
-            $ticket_status_class = $ticket->is_default()
1462
-                ? ' tkt-status-' . EE_Ticket::onsale
1463
-                : ' tkt-status-' . $ticket->ticket_status();
1464
-        }
1465
-        // breaking out complicated condition for TKT_taxable
1466
-        if ($default) {
1467
-            $TKT_taxable = '';
1468
-        } else {
1469
-            $TKT_taxable = $ticket->taxable()
1470
-                ? ' checked="checked"'
1471
-                : '';
1472
-        }
1473
-        if ($default) {
1474
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1475
-        } elseif ($ticket->is_default()) {
1476
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1477
-        } else {
1478
-            $TKT_status = $ticket->ticket_status(true);
1479
-        }
1480
-        if ($default) {
1481
-            $TKT_min = '';
1482
-        } else {
1483
-            $TKT_min = $ticket->min();
1484
-            if ($TKT_min === -1 || $TKT_min === 0) {
1485
-                $TKT_min = '';
1486
-            }
1487
-        }
1488
-        $template_args = array(
1489
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1490
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1491
-            // on initial page load this will always be the correct order.
1492
-            'tkt_status_class'              => $ticket_status_class,
1493
-            'display_edit_tkt_row'          => ' style="display:none;"',
1494
-            'edit_tkt_expanded'             => '',
1495
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1496
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1497
-            'TKT_start_date'                => $default
1498
-                ? ''
1499
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1500
-            'TKT_end_date'                  => $default
1501
-                ? ''
1502
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1503
-            'TKT_status'                    => $TKT_status,
1504
-            'TKT_price'                     => $default
1505
-                ? ''
1506
-                : EEH_Template::format_currency(
1507
-                    $ticket->get_ticket_total_with_taxes(),
1508
-                    false,
1509
-                    false
1510
-                ),
1511
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1512
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1513
-            'TKT_qty'                       => $default
1514
-                ? ''
1515
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1516
-            'TKT_qty_for_input'             => $default
1517
-                ? ''
1518
-                : $ticket->get_pretty('TKT_qty', 'input'),
1519
-            'TKT_uses'                      => $default
1520
-                ? ''
1521
-                : $ticket->get_pretty('TKT_uses', 'input'),
1522
-            'TKT_min'                       => $TKT_min,
1523
-            'TKT_max'                       => $default
1524
-                ? ''
1525
-                : $ticket->get_pretty('TKT_max', 'input'),
1526
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1527
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1528
-            'TKT_registrations'             => $default
1529
-                ? 0
1530
-                : $ticket->count_registrations(
1531
-                    array(
1532
-                        array(
1533
-                            'STS_ID' => array(
1534
-                                '!=',
1535
-                                EEM_Registration::status_id_incomplete,
1536
-                            ),
1537
-                        ),
1538
-                    )
1539
-                ),
1540
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1541
-            'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1542
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1543
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1544
-            'TKT_is_default_selector'       => '',
1545
-            'ticket_price_rows'             => '',
1546
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1547
-                ? ''
1548
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1549
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1550
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1551
-                ? ''
1552
-                : ' style="display:none;"',
1553
-            'show_price_mod_button'         => count($prices) > 1
1554
-                                               || ($default && $count_price_mods > 0)
1555
-                                               || (! $default && $ticket->deleted())
1556
-                ? ' style="display:none;"'
1557
-                : '',
1558
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1559
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1560
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1561
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1562
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1563
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1564
-            'TKT_taxable'                   => $TKT_taxable,
1565
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1566
-                ? ''
1567
-                : ' style="display:none"',
1568
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1569
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1570
-                $ticket_subtotal,
1571
-                false,
1572
-                false
1573
-            ),
1574
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1575
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1576
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1577
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1578
-                ? ' ticket-archived'
1579
-                : '',
1580
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1581
-                                               && $ticket->deleted()
1582
-                                               && ! $ticket->is_permanently_deleteable()
1583
-                ? 'ee-lock-icon '
1584
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1585
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1586
-                ? ''
1587
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1588
-        );
1589
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1590
-            ? ' style="display:none"'
1591
-            : '';
1592
-        // handle rows that should NOT be empty
1593
-        if (empty($template_args['TKT_start_date'])) {
1594
-            // if empty then the start date will be now.
1595
-            $template_args['TKT_start_date'] = date(
1596
-                $this->_date_time_format,
1597
-                current_time('timestamp')
1598
-            );
1599
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1600
-        }
1601
-        if (empty($template_args['TKT_end_date'])) {
1602
-            // get the earliest datetime (if present);
1603
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1604
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1605
-                    'Datetime',
1606
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1607
-                )
1608
-                : null;
1609
-            if (! empty($earliest_dtt)) {
1610
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1611
-                    'DTT_EVT_start',
1612
-                    $this->_date_time_format
1613
-                );
1614
-            } else {
1615
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1616
-                $template_args['TKT_end_date'] = date(
1617
-                    $this->_date_time_format,
1618
-                    mktime(
1619
-                        24,
1620
-                        0,
1621
-                        0,
1622
-                        date('m'),
1623
-                        date('d') + 29,
1624
-                        date('Y')
1625
-                    )
1626
-                );
1627
-            }
1628
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1629
-        }
1630
-        // generate ticket_datetime items
1631
-        if (! $default) {
1632
-            $datetime_row = 1;
1633
-            foreach ($all_datetimes as $datetime) {
1634
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1635
-                    $datetime_row,
1636
-                    $ticket_row,
1637
-                    $datetime,
1638
-                    $ticket,
1639
-                    $ticket_datetimes,
1640
-                    $default
1641
-                );
1642
-                $datetime_row++;
1643
-            }
1644
-        }
1645
-        $price_row = 1;
1646
-        foreach ($prices as $price) {
1647
-            if (! $price instanceof EE_Price) {
1648
-                continue;
1649
-            }
1650
-            if ($price->is_base_price()) {
1651
-                $price_row++;
1652
-                continue;
1653
-            }
1654
-            $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1655
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1656
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1657
-                $ticket_row,
1658
-                $price_row,
1659
-                $price,
1660
-                $default,
1661
-                $ticket,
1662
-                $show_trash,
1663
-                $show_create
1664
-            );
1665
-            $price_row++;
1666
-        }
1667
-        // filter $template_args
1668
-        $template_args = apply_filters(
1669
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1670
-            $template_args,
1671
-            $ticket_row,
1672
-            $ticket,
1673
-            $ticket_datetimes,
1674
-            $all_datetimes,
1675
-            $default,
1676
-            $all_tickets,
1677
-            $this->_is_creating_event
1678
-        );
1679
-        return EEH_Template::display_template(
1680
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1681
-            $template_args,
1682
-            true
1683
-        );
1684
-    }
1402
+	/**
1403
+	 * This generates the ticket row for tickets.
1404
+	 * This same method is used to generate both the actual rows and the js skeleton row
1405
+	 * (when default === true)
1406
+	 *
1407
+	 * @param int           $ticket_row       Represents the row number being generated.
1408
+	 * @param               $ticket
1409
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1410
+	 *                                        or empty for default
1411
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1412
+	 * @param bool          $default          Whether default row being generated or not.
1413
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1414
+	 *                                        (or empty in the case of defaults)
1415
+	 * @return mixed
1416
+	 * @throws InvalidArgumentException
1417
+	 * @throws InvalidInterfaceException
1418
+	 * @throws InvalidDataTypeException
1419
+	 * @throws DomainException
1420
+	 * @throws EE_Error
1421
+	 * @throws ReflectionException
1422
+	 */
1423
+	protected function _get_ticket_row(
1424
+		$ticket_row,
1425
+		$ticket,
1426
+		$ticket_datetimes,
1427
+		$all_datetimes,
1428
+		$default = false,
1429
+		$all_tickets = array()
1430
+	) {
1431
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1432
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1433
+		$prices = ! empty($ticket) && ! $default
1434
+			? $ticket->get_many_related(
1435
+				'Price',
1436
+				array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1437
+			)
1438
+			: array();
1439
+		// if there is only one price (which would be the base price)
1440
+		// or NO prices and this ticket is a default ticket,
1441
+		// let's just make sure there are no cached default prices on the object.
1442
+		// This is done by not including any query_params.
1443
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1444
+			$prices = $ticket->prices();
1445
+		}
1446
+		// check if we're dealing with a default ticket in which case
1447
+		// we don't want any starting_ticket_datetime_row values set
1448
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1449
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1450
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1451
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1452
+			? $ticket_datetimes[ $ticket->ID() ]
1453
+			: array();
1454
+		$ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1455
+		$base_price = $default ? null : $ticket->base_price();
1456
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1457
+		// breaking out complicated condition for ticket_status
1458
+		if ($default) {
1459
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1460
+		} else {
1461
+			$ticket_status_class = $ticket->is_default()
1462
+				? ' tkt-status-' . EE_Ticket::onsale
1463
+				: ' tkt-status-' . $ticket->ticket_status();
1464
+		}
1465
+		// breaking out complicated condition for TKT_taxable
1466
+		if ($default) {
1467
+			$TKT_taxable = '';
1468
+		} else {
1469
+			$TKT_taxable = $ticket->taxable()
1470
+				? ' checked="checked"'
1471
+				: '';
1472
+		}
1473
+		if ($default) {
1474
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1475
+		} elseif ($ticket->is_default()) {
1476
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1477
+		} else {
1478
+			$TKT_status = $ticket->ticket_status(true);
1479
+		}
1480
+		if ($default) {
1481
+			$TKT_min = '';
1482
+		} else {
1483
+			$TKT_min = $ticket->min();
1484
+			if ($TKT_min === -1 || $TKT_min === 0) {
1485
+				$TKT_min = '';
1486
+			}
1487
+		}
1488
+		$template_args = array(
1489
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1490
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1491
+			// on initial page load this will always be the correct order.
1492
+			'tkt_status_class'              => $ticket_status_class,
1493
+			'display_edit_tkt_row'          => ' style="display:none;"',
1494
+			'edit_tkt_expanded'             => '',
1495
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1496
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1497
+			'TKT_start_date'                => $default
1498
+				? ''
1499
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1500
+			'TKT_end_date'                  => $default
1501
+				? ''
1502
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1503
+			'TKT_status'                    => $TKT_status,
1504
+			'TKT_price'                     => $default
1505
+				? ''
1506
+				: EEH_Template::format_currency(
1507
+					$ticket->get_ticket_total_with_taxes(),
1508
+					false,
1509
+					false
1510
+				),
1511
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1512
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1513
+			'TKT_qty'                       => $default
1514
+				? ''
1515
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1516
+			'TKT_qty_for_input'             => $default
1517
+				? ''
1518
+				: $ticket->get_pretty('TKT_qty', 'input'),
1519
+			'TKT_uses'                      => $default
1520
+				? ''
1521
+				: $ticket->get_pretty('TKT_uses', 'input'),
1522
+			'TKT_min'                       => $TKT_min,
1523
+			'TKT_max'                       => $default
1524
+				? ''
1525
+				: $ticket->get_pretty('TKT_max', 'input'),
1526
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1527
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1528
+			'TKT_registrations'             => $default
1529
+				? 0
1530
+				: $ticket->count_registrations(
1531
+					array(
1532
+						array(
1533
+							'STS_ID' => array(
1534
+								'!=',
1535
+								EEM_Registration::status_id_incomplete,
1536
+							),
1537
+						),
1538
+					)
1539
+				),
1540
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1541
+			'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1542
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1543
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1544
+			'TKT_is_default_selector'       => '',
1545
+			'ticket_price_rows'             => '',
1546
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1547
+				? ''
1548
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1549
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1550
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1551
+				? ''
1552
+				: ' style="display:none;"',
1553
+			'show_price_mod_button'         => count($prices) > 1
1554
+											   || ($default && $count_price_mods > 0)
1555
+											   || (! $default && $ticket->deleted())
1556
+				? ' style="display:none;"'
1557
+				: '',
1558
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1559
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1560
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1561
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1562
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1563
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1564
+			'TKT_taxable'                   => $TKT_taxable,
1565
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1566
+				? ''
1567
+				: ' style="display:none"',
1568
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1569
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1570
+				$ticket_subtotal,
1571
+				false,
1572
+				false
1573
+			),
1574
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1575
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1576
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1577
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1578
+				? ' ticket-archived'
1579
+				: '',
1580
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1581
+											   && $ticket->deleted()
1582
+											   && ! $ticket->is_permanently_deleteable()
1583
+				? 'ee-lock-icon '
1584
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1585
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1586
+				? ''
1587
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1588
+		);
1589
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1590
+			? ' style="display:none"'
1591
+			: '';
1592
+		// handle rows that should NOT be empty
1593
+		if (empty($template_args['TKT_start_date'])) {
1594
+			// if empty then the start date will be now.
1595
+			$template_args['TKT_start_date'] = date(
1596
+				$this->_date_time_format,
1597
+				current_time('timestamp')
1598
+			);
1599
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1600
+		}
1601
+		if (empty($template_args['TKT_end_date'])) {
1602
+			// get the earliest datetime (if present);
1603
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1604
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1605
+					'Datetime',
1606
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1607
+				)
1608
+				: null;
1609
+			if (! empty($earliest_dtt)) {
1610
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1611
+					'DTT_EVT_start',
1612
+					$this->_date_time_format
1613
+				);
1614
+			} else {
1615
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1616
+				$template_args['TKT_end_date'] = date(
1617
+					$this->_date_time_format,
1618
+					mktime(
1619
+						24,
1620
+						0,
1621
+						0,
1622
+						date('m'),
1623
+						date('d') + 29,
1624
+						date('Y')
1625
+					)
1626
+				);
1627
+			}
1628
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1629
+		}
1630
+		// generate ticket_datetime items
1631
+		if (! $default) {
1632
+			$datetime_row = 1;
1633
+			foreach ($all_datetimes as $datetime) {
1634
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1635
+					$datetime_row,
1636
+					$ticket_row,
1637
+					$datetime,
1638
+					$ticket,
1639
+					$ticket_datetimes,
1640
+					$default
1641
+				);
1642
+				$datetime_row++;
1643
+			}
1644
+		}
1645
+		$price_row = 1;
1646
+		foreach ($prices as $price) {
1647
+			if (! $price instanceof EE_Price) {
1648
+				continue;
1649
+			}
1650
+			if ($price->is_base_price()) {
1651
+				$price_row++;
1652
+				continue;
1653
+			}
1654
+			$show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1655
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1656
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1657
+				$ticket_row,
1658
+				$price_row,
1659
+				$price,
1660
+				$default,
1661
+				$ticket,
1662
+				$show_trash,
1663
+				$show_create
1664
+			);
1665
+			$price_row++;
1666
+		}
1667
+		// filter $template_args
1668
+		$template_args = apply_filters(
1669
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1670
+			$template_args,
1671
+			$ticket_row,
1672
+			$ticket,
1673
+			$ticket_datetimes,
1674
+			$all_datetimes,
1675
+			$default,
1676
+			$all_tickets,
1677
+			$this->_is_creating_event
1678
+		);
1679
+		return EEH_Template::display_template(
1680
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1681
+			$template_args,
1682
+			true
1683
+		);
1684
+	}
1685 1685
 
1686 1686
 
1687
-    /**
1688
-     * @param int            $ticket_row
1689
-     * @param EE_Ticket|null $ticket
1690
-     * @return string
1691
-     * @throws DomainException
1692
-     * @throws EE_Error
1693
-     */
1694
-    protected function _get_tax_rows($ticket_row, $ticket)
1695
-    {
1696
-        $tax_rows = '';
1697
-        /** @var EE_Price[] $taxes */
1698
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1699
-        foreach ($taxes as $tax) {
1700
-            $tax_added = $this->_get_tax_added($tax, $ticket);
1701
-            $template_args = array(
1702
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1703
-                    ? ''
1704
-                    : ' style="display:none;"',
1705
-                'tax_id'            => $tax->ID(),
1706
-                'tkt_row'           => $ticket_row,
1707
-                'tax_label'         => $tax->get('PRC_name'),
1708
-                'tax_added'         => $tax_added,
1709
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1710
-                'tax_amount'        => $tax->get('PRC_amount'),
1711
-            );
1712
-            $template_args = apply_filters(
1713
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1714
-                $template_args,
1715
-                $ticket_row,
1716
-                $ticket,
1717
-                $this->_is_creating_event
1718
-            );
1719
-            $tax_rows .= EEH_Template::display_template(
1720
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1721
-                $template_args,
1722
-                true
1723
-            );
1724
-        }
1725
-        return $tax_rows;
1726
-    }
1687
+	/**
1688
+	 * @param int            $ticket_row
1689
+	 * @param EE_Ticket|null $ticket
1690
+	 * @return string
1691
+	 * @throws DomainException
1692
+	 * @throws EE_Error
1693
+	 */
1694
+	protected function _get_tax_rows($ticket_row, $ticket)
1695
+	{
1696
+		$tax_rows = '';
1697
+		/** @var EE_Price[] $taxes */
1698
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1699
+		foreach ($taxes as $tax) {
1700
+			$tax_added = $this->_get_tax_added($tax, $ticket);
1701
+			$template_args = array(
1702
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1703
+					? ''
1704
+					: ' style="display:none;"',
1705
+				'tax_id'            => $tax->ID(),
1706
+				'tkt_row'           => $ticket_row,
1707
+				'tax_label'         => $tax->get('PRC_name'),
1708
+				'tax_added'         => $tax_added,
1709
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1710
+				'tax_amount'        => $tax->get('PRC_amount'),
1711
+			);
1712
+			$template_args = apply_filters(
1713
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1714
+				$template_args,
1715
+				$ticket_row,
1716
+				$ticket,
1717
+				$this->_is_creating_event
1718
+			);
1719
+			$tax_rows .= EEH_Template::display_template(
1720
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1721
+				$template_args,
1722
+				true
1723
+			);
1724
+		}
1725
+		return $tax_rows;
1726
+	}
1727 1727
 
1728 1728
 
1729
-    /**
1730
-     * @param EE_Price       $tax
1731
-     * @param EE_Ticket|null $ticket
1732
-     * @return float|int
1733
-     * @throws EE_Error
1734
-     */
1735
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1736
-    {
1737
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1738
-        return $subtotal * $tax->get('PRC_amount') / 100;
1739
-    }
1729
+	/**
1730
+	 * @param EE_Price       $tax
1731
+	 * @param EE_Ticket|null $ticket
1732
+	 * @return float|int
1733
+	 * @throws EE_Error
1734
+	 */
1735
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1736
+	{
1737
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1738
+		return $subtotal * $tax->get('PRC_amount') / 100;
1739
+	}
1740 1740
 
1741 1741
 
1742
-    /**
1743
-     * @param int            $ticket_row
1744
-     * @param int            $price_row
1745
-     * @param EE_Price|null  $price
1746
-     * @param bool           $default
1747
-     * @param EE_Ticket|null $ticket
1748
-     * @param bool           $show_trash
1749
-     * @param bool           $show_create
1750
-     * @return mixed
1751
-     * @throws InvalidArgumentException
1752
-     * @throws InvalidInterfaceException
1753
-     * @throws InvalidDataTypeException
1754
-     * @throws DomainException
1755
-     * @throws EE_Error
1756
-     * @throws ReflectionException
1757
-     */
1758
-    protected function _get_ticket_price_row(
1759
-        $ticket_row,
1760
-        $price_row,
1761
-        $price,
1762
-        $default,
1763
-        $ticket,
1764
-        $show_trash = true,
1765
-        $show_create = true
1766
-    ) {
1767
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1768
-        $template_args = array(
1769
-            'tkt_row'               => $default && empty($ticket)
1770
-                ? 'TICKETNUM'
1771
-                : $ticket_row,
1772
-            'PRC_order'             => $default && empty($price)
1773
-                ? 'PRICENUM'
1774
-                : $price_row,
1775
-            'edit_prices_name'      => $default && empty($price)
1776
-                ? 'PRICENAMEATTR'
1777
-                : 'edit_prices',
1778
-            'price_type_selector'   => $default && empty($price)
1779
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1780
-                : $this->_get_price_type_selector(
1781
-                    $ticket_row,
1782
-                    $price_row,
1783
-                    $price,
1784
-                    $default,
1785
-                    $send_disabled
1786
-                ),
1787
-            'PRC_ID'                => $default && empty($price)
1788
-                ? 0
1789
-                : $price->ID(),
1790
-            'PRC_is_default'        => $default && empty($price)
1791
-                ? 0
1792
-                : $price->get('PRC_is_default'),
1793
-            'PRC_name'              => $default && empty($price)
1794
-                ? ''
1795
-                : $price->get('PRC_name'),
1796
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1797
-            'show_plus_or_minus'    => $default && empty($price)
1798
-                ? ''
1799
-                : ' style="display:none;"',
1800
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1801
-                ? ' style="display:none;"'
1802
-                : '',
1803
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1804
-                ? ' style="display:none;"'
1805
-                : '',
1806
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1807
-                ? ' style="display:none"'
1808
-                : '',
1809
-            'PRC_amount'            => $default && empty($price)
1810
-                ? 0
1811
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1812
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1813
-                ? ' style="display:none;"'
1814
-                : '',
1815
-            'show_trash_icon'       => $show_trash
1816
-                ? ''
1817
-                : ' style="display:none;"',
1818
-            'show_create_button'    => $show_create
1819
-                ? ''
1820
-                : ' style="display:none;"',
1821
-            'PRC_desc'              => $default && empty($price)
1822
-                ? ''
1823
-                : $price->get('PRC_desc'),
1824
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1825
-        );
1826
-        $template_args = apply_filters(
1827
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1828
-            $template_args,
1829
-            $ticket_row,
1830
-            $price_row,
1831
-            $price,
1832
-            $default,
1833
-            $ticket,
1834
-            $show_trash,
1835
-            $show_create,
1836
-            $this->_is_creating_event
1837
-        );
1838
-        return EEH_Template::display_template(
1839
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1840
-            $template_args,
1841
-            true
1842
-        );
1843
-    }
1742
+	/**
1743
+	 * @param int            $ticket_row
1744
+	 * @param int            $price_row
1745
+	 * @param EE_Price|null  $price
1746
+	 * @param bool           $default
1747
+	 * @param EE_Ticket|null $ticket
1748
+	 * @param bool           $show_trash
1749
+	 * @param bool           $show_create
1750
+	 * @return mixed
1751
+	 * @throws InvalidArgumentException
1752
+	 * @throws InvalidInterfaceException
1753
+	 * @throws InvalidDataTypeException
1754
+	 * @throws DomainException
1755
+	 * @throws EE_Error
1756
+	 * @throws ReflectionException
1757
+	 */
1758
+	protected function _get_ticket_price_row(
1759
+		$ticket_row,
1760
+		$price_row,
1761
+		$price,
1762
+		$default,
1763
+		$ticket,
1764
+		$show_trash = true,
1765
+		$show_create = true
1766
+	) {
1767
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1768
+		$template_args = array(
1769
+			'tkt_row'               => $default && empty($ticket)
1770
+				? 'TICKETNUM'
1771
+				: $ticket_row,
1772
+			'PRC_order'             => $default && empty($price)
1773
+				? 'PRICENUM'
1774
+				: $price_row,
1775
+			'edit_prices_name'      => $default && empty($price)
1776
+				? 'PRICENAMEATTR'
1777
+				: 'edit_prices',
1778
+			'price_type_selector'   => $default && empty($price)
1779
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1780
+				: $this->_get_price_type_selector(
1781
+					$ticket_row,
1782
+					$price_row,
1783
+					$price,
1784
+					$default,
1785
+					$send_disabled
1786
+				),
1787
+			'PRC_ID'                => $default && empty($price)
1788
+				? 0
1789
+				: $price->ID(),
1790
+			'PRC_is_default'        => $default && empty($price)
1791
+				? 0
1792
+				: $price->get('PRC_is_default'),
1793
+			'PRC_name'              => $default && empty($price)
1794
+				? ''
1795
+				: $price->get('PRC_name'),
1796
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1797
+			'show_plus_or_minus'    => $default && empty($price)
1798
+				? ''
1799
+				: ' style="display:none;"',
1800
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1801
+				? ' style="display:none;"'
1802
+				: '',
1803
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1804
+				? ' style="display:none;"'
1805
+				: '',
1806
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1807
+				? ' style="display:none"'
1808
+				: '',
1809
+			'PRC_amount'            => $default && empty($price)
1810
+				? 0
1811
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1812
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1813
+				? ' style="display:none;"'
1814
+				: '',
1815
+			'show_trash_icon'       => $show_trash
1816
+				? ''
1817
+				: ' style="display:none;"',
1818
+			'show_create_button'    => $show_create
1819
+				? ''
1820
+				: ' style="display:none;"',
1821
+			'PRC_desc'              => $default && empty($price)
1822
+				? ''
1823
+				: $price->get('PRC_desc'),
1824
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1825
+		);
1826
+		$template_args = apply_filters(
1827
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1828
+			$template_args,
1829
+			$ticket_row,
1830
+			$price_row,
1831
+			$price,
1832
+			$default,
1833
+			$ticket,
1834
+			$show_trash,
1835
+			$show_create,
1836
+			$this->_is_creating_event
1837
+		);
1838
+		return EEH_Template::display_template(
1839
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1840
+			$template_args,
1841
+			true
1842
+		);
1843
+	}
1844 1844
 
1845 1845
 
1846
-    /**
1847
-     * @param int      $ticket_row
1848
-     * @param int      $price_row
1849
-     * @param EE_Price $price
1850
-     * @param bool     $default
1851
-     * @param bool     $disabled
1852
-     * @return mixed
1853
-     * @throws ReflectionException
1854
-     * @throws InvalidArgumentException
1855
-     * @throws InvalidInterfaceException
1856
-     * @throws InvalidDataTypeException
1857
-     * @throws DomainException
1858
-     * @throws EE_Error
1859
-     */
1860
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1861
-    {
1862
-        if ($price->is_base_price()) {
1863
-            return $this->_get_base_price_template(
1864
-                $ticket_row,
1865
-                $price_row,
1866
-                $price,
1867
-                $default
1868
-            );
1869
-        }
1870
-        return $this->_get_price_modifier_template(
1871
-            $ticket_row,
1872
-            $price_row,
1873
-            $price,
1874
-            $default,
1875
-            $disabled
1876
-        );
1877
-    }
1846
+	/**
1847
+	 * @param int      $ticket_row
1848
+	 * @param int      $price_row
1849
+	 * @param EE_Price $price
1850
+	 * @param bool     $default
1851
+	 * @param bool     $disabled
1852
+	 * @return mixed
1853
+	 * @throws ReflectionException
1854
+	 * @throws InvalidArgumentException
1855
+	 * @throws InvalidInterfaceException
1856
+	 * @throws InvalidDataTypeException
1857
+	 * @throws DomainException
1858
+	 * @throws EE_Error
1859
+	 */
1860
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1861
+	{
1862
+		if ($price->is_base_price()) {
1863
+			return $this->_get_base_price_template(
1864
+				$ticket_row,
1865
+				$price_row,
1866
+				$price,
1867
+				$default
1868
+			);
1869
+		}
1870
+		return $this->_get_price_modifier_template(
1871
+			$ticket_row,
1872
+			$price_row,
1873
+			$price,
1874
+			$default,
1875
+			$disabled
1876
+		);
1877
+	}
1878 1878
 
1879 1879
 
1880
-    /**
1881
-     * @param int      $ticket_row
1882
-     * @param int      $price_row
1883
-     * @param EE_Price $price
1884
-     * @param bool     $default
1885
-     * @return mixed
1886
-     * @throws DomainException
1887
-     * @throws EE_Error
1888
-     */
1889
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1890
-    {
1891
-        $template_args = array(
1892
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1893
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1894
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1895
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1896
-            'price_selected_operator'   => '+',
1897
-            'price_selected_is_percent' => 0,
1898
-        );
1899
-        $template_args = apply_filters(
1900
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1901
-            $template_args,
1902
-            $ticket_row,
1903
-            $price_row,
1904
-            $price,
1905
-            $default,
1906
-            $this->_is_creating_event
1907
-        );
1908
-        return EEH_Template::display_template(
1909
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1910
-            $template_args,
1911
-            true
1912
-        );
1913
-    }
1880
+	/**
1881
+	 * @param int      $ticket_row
1882
+	 * @param int      $price_row
1883
+	 * @param EE_Price $price
1884
+	 * @param bool     $default
1885
+	 * @return mixed
1886
+	 * @throws DomainException
1887
+	 * @throws EE_Error
1888
+	 */
1889
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1890
+	{
1891
+		$template_args = array(
1892
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1893
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1894
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1895
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1896
+			'price_selected_operator'   => '+',
1897
+			'price_selected_is_percent' => 0,
1898
+		);
1899
+		$template_args = apply_filters(
1900
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1901
+			$template_args,
1902
+			$ticket_row,
1903
+			$price_row,
1904
+			$price,
1905
+			$default,
1906
+			$this->_is_creating_event
1907
+		);
1908
+		return EEH_Template::display_template(
1909
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1910
+			$template_args,
1911
+			true
1912
+		);
1913
+	}
1914 1914
 
1915 1915
 
1916
-    /**
1917
-     * @param int      $ticket_row
1918
-     * @param int      $price_row
1919
-     * @param EE_Price $price
1920
-     * @param bool     $default
1921
-     * @param bool     $disabled
1922
-     * @return mixed
1923
-     * @throws ReflectionException
1924
-     * @throws InvalidArgumentException
1925
-     * @throws InvalidInterfaceException
1926
-     * @throws InvalidDataTypeException
1927
-     * @throws DomainException
1928
-     * @throws EE_Error
1929
-     */
1930
-    protected function _get_price_modifier_template(
1931
-        $ticket_row,
1932
-        $price_row,
1933
-        $price,
1934
-        $default,
1935
-        $disabled = false
1936
-    ) {
1937
-        $select_name = $default && ! $price instanceof EE_Price
1938
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1939
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1940
-        /** @var EEM_Price_Type $price_type_model */
1941
-        $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1942
-        $price_types = $price_type_model->get_all(array(
1943
-            array(
1944
-                'OR' => array(
1945
-                    'PBT_ID'  => '2',
1946
-                    'PBT_ID*' => '3',
1947
-                ),
1948
-            ),
1949
-        ));
1950
-        $all_price_types = $default && ! $price instanceof EE_Price
1951
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1952
-            : array();
1953
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1954
-        $price_option_spans = '';
1955
-        // setup price types for selector
1956
-        foreach ($price_types as $price_type) {
1957
-            if (! $price_type instanceof EE_Price_Type) {
1958
-                continue;
1959
-            }
1960
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1961
-            // while we're in the loop let's setup the option spans used by js
1962
-            $span_args = array(
1963
-                'PRT_ID'         => $price_type->ID(),
1964
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1965
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1966
-            );
1967
-            $price_option_spans .= EEH_Template::display_template(
1968
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1969
-                $span_args,
1970
-                true
1971
-            );
1972
-        }
1973
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1974
-            : $select_name;
1975
-        $select_input = new EE_Select_Input(
1976
-            $all_price_types,
1977
-            array(
1978
-                'default'               => $selected_price_type_id,
1979
-                'html_name'             => $select_name,
1980
-                'html_class'            => 'edit-price-PRT_ID',
1981
-                'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1982
-            )
1983
-        );
1984
-        $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1985
-        $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1986
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1987
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1988
-        $template_args = array(
1989
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1990
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1991
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1992
-            'main_name'                 => $select_name,
1993
-            'selected_price_type_id'    => $selected_price_type_id,
1994
-            'price_option_spans'        => $price_option_spans,
1995
-            'price_selected_operator'   => $price_selected_operator,
1996
-            'price_selected_is_percent' => $price_selected_is_percent,
1997
-            'disabled'                  => $disabled,
1998
-        );
1999
-        $template_args = apply_filters(
2000
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
2001
-            $template_args,
2002
-            $ticket_row,
2003
-            $price_row,
2004
-            $price,
2005
-            $default,
2006
-            $disabled,
2007
-            $this->_is_creating_event
2008
-        );
2009
-        return EEH_Template::display_template(
2010
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2011
-            $template_args,
2012
-            true
2013
-        );
2014
-    }
1916
+	/**
1917
+	 * @param int      $ticket_row
1918
+	 * @param int      $price_row
1919
+	 * @param EE_Price $price
1920
+	 * @param bool     $default
1921
+	 * @param bool     $disabled
1922
+	 * @return mixed
1923
+	 * @throws ReflectionException
1924
+	 * @throws InvalidArgumentException
1925
+	 * @throws InvalidInterfaceException
1926
+	 * @throws InvalidDataTypeException
1927
+	 * @throws DomainException
1928
+	 * @throws EE_Error
1929
+	 */
1930
+	protected function _get_price_modifier_template(
1931
+		$ticket_row,
1932
+		$price_row,
1933
+		$price,
1934
+		$default,
1935
+		$disabled = false
1936
+	) {
1937
+		$select_name = $default && ! $price instanceof EE_Price
1938
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1939
+			: 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1940
+		/** @var EEM_Price_Type $price_type_model */
1941
+		$price_type_model = EE_Registry::instance()->load_model('Price_Type');
1942
+		$price_types = $price_type_model->get_all(array(
1943
+			array(
1944
+				'OR' => array(
1945
+					'PBT_ID'  => '2',
1946
+					'PBT_ID*' => '3',
1947
+				),
1948
+			),
1949
+		));
1950
+		$all_price_types = $default && ! $price instanceof EE_Price
1951
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1952
+			: array();
1953
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1954
+		$price_option_spans = '';
1955
+		// setup price types for selector
1956
+		foreach ($price_types as $price_type) {
1957
+			if (! $price_type instanceof EE_Price_Type) {
1958
+				continue;
1959
+			}
1960
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1961
+			// while we're in the loop let's setup the option spans used by js
1962
+			$span_args = array(
1963
+				'PRT_ID'         => $price_type->ID(),
1964
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1965
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1966
+			);
1967
+			$price_option_spans .= EEH_Template::display_template(
1968
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1969
+				$span_args,
1970
+				true
1971
+			);
1972
+		}
1973
+		$select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1974
+			: $select_name;
1975
+		$select_input = new EE_Select_Input(
1976
+			$all_price_types,
1977
+			array(
1978
+				'default'               => $selected_price_type_id,
1979
+				'html_name'             => $select_name,
1980
+				'html_class'            => 'edit-price-PRT_ID',
1981
+				'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1982
+			)
1983
+		);
1984
+		$price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1985
+		$price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1986
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1987
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1988
+		$template_args = array(
1989
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1990
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1991
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1992
+			'main_name'                 => $select_name,
1993
+			'selected_price_type_id'    => $selected_price_type_id,
1994
+			'price_option_spans'        => $price_option_spans,
1995
+			'price_selected_operator'   => $price_selected_operator,
1996
+			'price_selected_is_percent' => $price_selected_is_percent,
1997
+			'disabled'                  => $disabled,
1998
+		);
1999
+		$template_args = apply_filters(
2000
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
2001
+			$template_args,
2002
+			$ticket_row,
2003
+			$price_row,
2004
+			$price,
2005
+			$default,
2006
+			$disabled,
2007
+			$this->_is_creating_event
2008
+		);
2009
+		return EEH_Template::display_template(
2010
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2011
+			$template_args,
2012
+			true
2013
+		);
2014
+	}
2015 2015
 
2016 2016
 
2017
-    /**
2018
-     * @param int              $datetime_row
2019
-     * @param int              $ticket_row
2020
-     * @param EE_Datetime|null $datetime
2021
-     * @param EE_Ticket|null   $ticket
2022
-     * @param array            $ticket_datetimes
2023
-     * @param bool             $default
2024
-     * @return mixed
2025
-     * @throws DomainException
2026
-     * @throws EE_Error
2027
-     */
2028
-    protected function _get_ticket_datetime_list_item(
2029
-        $datetime_row,
2030
-        $ticket_row,
2031
-        $datetime,
2032
-        $ticket,
2033
-        $ticket_datetimes = array(),
2034
-        $default
2035
-    ) {
2036
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2037
-            ? $ticket_datetimes[ $ticket->ID() ]
2038
-            : array();
2039
-        $template_args = array(
2040
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2041
-                ? 'DTTNUM'
2042
-                : $datetime_row,
2043
-            'tkt_row'                  => $default
2044
-                ? 'TICKETNUM'
2045
-                : $ticket_row,
2046
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2047
-                ? ' ticket-selected'
2048
-                : '',
2049
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2050
-                ? ' checked="checked"'
2051
-                : '',
2052
-            'DTT_name'                 => $default && empty($datetime)
2053
-                ? 'DTTNAME'
2054
-                : $datetime->get_dtt_display_name(true),
2055
-            'tkt_status_class'         => '',
2056
-        );
2057
-        $template_args = apply_filters(
2058
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2059
-            $template_args,
2060
-            $datetime_row,
2061
-            $ticket_row,
2062
-            $datetime,
2063
-            $ticket,
2064
-            $ticket_datetimes,
2065
-            $default,
2066
-            $this->_is_creating_event
2067
-        );
2068
-        return EEH_Template::display_template(
2069
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2070
-            $template_args,
2071
-            true
2072
-        );
2073
-    }
2017
+	/**
2018
+	 * @param int              $datetime_row
2019
+	 * @param int              $ticket_row
2020
+	 * @param EE_Datetime|null $datetime
2021
+	 * @param EE_Ticket|null   $ticket
2022
+	 * @param array            $ticket_datetimes
2023
+	 * @param bool             $default
2024
+	 * @return mixed
2025
+	 * @throws DomainException
2026
+	 * @throws EE_Error
2027
+	 */
2028
+	protected function _get_ticket_datetime_list_item(
2029
+		$datetime_row,
2030
+		$ticket_row,
2031
+		$datetime,
2032
+		$ticket,
2033
+		$ticket_datetimes = array(),
2034
+		$default
2035
+	) {
2036
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2037
+			? $ticket_datetimes[ $ticket->ID() ]
2038
+			: array();
2039
+		$template_args = array(
2040
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2041
+				? 'DTTNUM'
2042
+				: $datetime_row,
2043
+			'tkt_row'                  => $default
2044
+				? 'TICKETNUM'
2045
+				: $ticket_row,
2046
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2047
+				? ' ticket-selected'
2048
+				: '',
2049
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2050
+				? ' checked="checked"'
2051
+				: '',
2052
+			'DTT_name'                 => $default && empty($datetime)
2053
+				? 'DTTNAME'
2054
+				: $datetime->get_dtt_display_name(true),
2055
+			'tkt_status_class'         => '',
2056
+		);
2057
+		$template_args = apply_filters(
2058
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2059
+			$template_args,
2060
+			$datetime_row,
2061
+			$ticket_row,
2062
+			$datetime,
2063
+			$ticket,
2064
+			$ticket_datetimes,
2065
+			$default,
2066
+			$this->_is_creating_event
2067
+		);
2068
+		return EEH_Template::display_template(
2069
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2070
+			$template_args,
2071
+			true
2072
+		);
2073
+	}
2074 2074
 
2075 2075
 
2076
-    /**
2077
-     * @param array $all_datetimes
2078
-     * @param array $all_tickets
2079
-     * @return mixed
2080
-     * @throws ReflectionException
2081
-     * @throws InvalidArgumentException
2082
-     * @throws InvalidInterfaceException
2083
-     * @throws InvalidDataTypeException
2084
-     * @throws DomainException
2085
-     * @throws EE_Error
2086
-     */
2087
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2088
-    {
2089
-        $template_args = array(
2090
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2091
-                'DTTNUM',
2092
-                null,
2093
-                true,
2094
-                $all_datetimes
2095
-            ),
2096
-            'default_ticket_row'                       => $this->_get_ticket_row(
2097
-                'TICKETNUM',
2098
-                null,
2099
-                array(),
2100
-                array(),
2101
-                true
2102
-            ),
2103
-            'default_price_row'                        => $this->_get_ticket_price_row(
2104
-                'TICKETNUM',
2105
-                'PRICENUM',
2106
-                null,
2107
-                true,
2108
-                null
2109
-            ),
2110
-            'default_price_rows'                       => '',
2111
-            'default_base_price_amount'                => 0,
2112
-            'default_base_price_name'                  => '',
2113
-            'default_base_price_description'           => '',
2114
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2115
-                'TICKETNUM',
2116
-                'PRICENUM',
2117
-                null,
2118
-                true
2119
-            ),
2120
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2121
-                'DTTNUM',
2122
-                null,
2123
-                array(),
2124
-                array(),
2125
-                true
2126
-            ),
2127
-            'existing_available_datetime_tickets_list' => '',
2128
-            'existing_available_ticket_datetimes_list' => '',
2129
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2130
-                'DTTNUM',
2131
-                'TICKETNUM',
2132
-                null,
2133
-                null,
2134
-                array(),
2135
-                true
2136
-            ),
2137
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2138
-                'DTTNUM',
2139
-                'TICKETNUM',
2140
-                null,
2141
-                null,
2142
-                array(),
2143
-                true
2144
-            ),
2145
-        );
2146
-        $ticket_row = 1;
2147
-        foreach ($all_tickets as $ticket) {
2148
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2149
-                'DTTNUM',
2150
-                $ticket_row,
2151
-                null,
2152
-                $ticket,
2153
-                array(),
2154
-                true
2155
-            );
2156
-            $ticket_row++;
2157
-        }
2158
-        $datetime_row = 1;
2159
-        foreach ($all_datetimes as $datetime) {
2160
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2161
-                $datetime_row,
2162
-                'TICKETNUM',
2163
-                $datetime,
2164
-                null,
2165
-                array(),
2166
-                true
2167
-            );
2168
-            $datetime_row++;
2169
-        }
2170
-        /** @var EEM_Price $price_model */
2171
-        $price_model = EE_Registry::instance()->load_model('Price');
2172
-        $default_prices = $price_model->get_all_default_prices();
2173
-        $price_row = 1;
2174
-        foreach ($default_prices as $price) {
2175
-            if (! $price instanceof EE_Price) {
2176
-                continue;
2177
-            }
2178
-            if ($price->is_base_price()) {
2179
-                $template_args['default_base_price_amount'] = $price->get_pretty(
2180
-                    'PRC_amount',
2181
-                    'localized_float'
2182
-                );
2183
-                $template_args['default_base_price_name'] = $price->get('PRC_name');
2184
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2185
-                $price_row++;
2186
-                continue;
2187
-            }
2188
-            $show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2189
-                             || count($default_prices) === 1);
2190
-            $show_create = ! (count($default_prices) > 1
2191
-                              && count($default_prices)
2192
-                                 !== $price_row);
2193
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2194
-                'TICKETNUM',
2195
-                $price_row,
2196
-                $price,
2197
-                true,
2198
-                null,
2199
-                $show_trash,
2200
-                $show_create
2201
-            );
2202
-            $price_row++;
2203
-        }
2204
-        $template_args = apply_filters(
2205
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2206
-            $template_args,
2207
-            $all_datetimes,
2208
-            $all_tickets,
2209
-            $this->_is_creating_event
2210
-        );
2211
-        return EEH_Template::display_template(
2212
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2213
-            $template_args,
2214
-            true
2215
-        );
2216
-    }
2076
+	/**
2077
+	 * @param array $all_datetimes
2078
+	 * @param array $all_tickets
2079
+	 * @return mixed
2080
+	 * @throws ReflectionException
2081
+	 * @throws InvalidArgumentException
2082
+	 * @throws InvalidInterfaceException
2083
+	 * @throws InvalidDataTypeException
2084
+	 * @throws DomainException
2085
+	 * @throws EE_Error
2086
+	 */
2087
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2088
+	{
2089
+		$template_args = array(
2090
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2091
+				'DTTNUM',
2092
+				null,
2093
+				true,
2094
+				$all_datetimes
2095
+			),
2096
+			'default_ticket_row'                       => $this->_get_ticket_row(
2097
+				'TICKETNUM',
2098
+				null,
2099
+				array(),
2100
+				array(),
2101
+				true
2102
+			),
2103
+			'default_price_row'                        => $this->_get_ticket_price_row(
2104
+				'TICKETNUM',
2105
+				'PRICENUM',
2106
+				null,
2107
+				true,
2108
+				null
2109
+			),
2110
+			'default_price_rows'                       => '',
2111
+			'default_base_price_amount'                => 0,
2112
+			'default_base_price_name'                  => '',
2113
+			'default_base_price_description'           => '',
2114
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2115
+				'TICKETNUM',
2116
+				'PRICENUM',
2117
+				null,
2118
+				true
2119
+			),
2120
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2121
+				'DTTNUM',
2122
+				null,
2123
+				array(),
2124
+				array(),
2125
+				true
2126
+			),
2127
+			'existing_available_datetime_tickets_list' => '',
2128
+			'existing_available_ticket_datetimes_list' => '',
2129
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2130
+				'DTTNUM',
2131
+				'TICKETNUM',
2132
+				null,
2133
+				null,
2134
+				array(),
2135
+				true
2136
+			),
2137
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2138
+				'DTTNUM',
2139
+				'TICKETNUM',
2140
+				null,
2141
+				null,
2142
+				array(),
2143
+				true
2144
+			),
2145
+		);
2146
+		$ticket_row = 1;
2147
+		foreach ($all_tickets as $ticket) {
2148
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2149
+				'DTTNUM',
2150
+				$ticket_row,
2151
+				null,
2152
+				$ticket,
2153
+				array(),
2154
+				true
2155
+			);
2156
+			$ticket_row++;
2157
+		}
2158
+		$datetime_row = 1;
2159
+		foreach ($all_datetimes as $datetime) {
2160
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2161
+				$datetime_row,
2162
+				'TICKETNUM',
2163
+				$datetime,
2164
+				null,
2165
+				array(),
2166
+				true
2167
+			);
2168
+			$datetime_row++;
2169
+		}
2170
+		/** @var EEM_Price $price_model */
2171
+		$price_model = EE_Registry::instance()->load_model('Price');
2172
+		$default_prices = $price_model->get_all_default_prices();
2173
+		$price_row = 1;
2174
+		foreach ($default_prices as $price) {
2175
+			if (! $price instanceof EE_Price) {
2176
+				continue;
2177
+			}
2178
+			if ($price->is_base_price()) {
2179
+				$template_args['default_base_price_amount'] = $price->get_pretty(
2180
+					'PRC_amount',
2181
+					'localized_float'
2182
+				);
2183
+				$template_args['default_base_price_name'] = $price->get('PRC_name');
2184
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2185
+				$price_row++;
2186
+				continue;
2187
+			}
2188
+			$show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2189
+							 || count($default_prices) === 1);
2190
+			$show_create = ! (count($default_prices) > 1
2191
+							  && count($default_prices)
2192
+								 !== $price_row);
2193
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2194
+				'TICKETNUM',
2195
+				$price_row,
2196
+				$price,
2197
+				true,
2198
+				null,
2199
+				$show_trash,
2200
+				$show_create
2201
+			);
2202
+			$price_row++;
2203
+		}
2204
+		$template_args = apply_filters(
2205
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2206
+			$template_args,
2207
+			$all_datetimes,
2208
+			$all_tickets,
2209
+			$this->_is_creating_event
2210
+		);
2211
+		return EEH_Template::display_template(
2212
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2213
+			$template_args,
2214
+			true
2215
+		);
2216
+	}
2217 2217
 }
Please login to merge, or discard this patch.