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