Completed
Branch BUG-10504-spco-submit-lock (c0988b)
by
unknown
12:11 queued 11s
created
modules/ticket_selector/TicketSelector.php 2 patches
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -16,115 +16,115 @@
 block discarded – undo
16 16
 abstract class TicketSelector
17 17
 {
18 18
 
19
-    /**
20
-     * @var \EE_Event $event
21
-     */
22
-    protected $event;
23
-
24
-    /**
25
-     * @var \EE_Ticket[] $tickets
26
-     */
27
-    protected $tickets;
28
-
29
-    /**
30
-     * @var int max_attendees
31
-     */
32
-    protected $max_attendees;
33
-
34
-    /**
35
-     * @var array $template_args
36
-     */
37
-    protected $template_args;
38
-
39
-
40
-
41
-    /**
42
-     * TicketSelectorSimple constructor.
43
-     *
44
-     * @param \EE_Event    $event
45
-     * @param \EE_Ticket[] $tickets
46
-     * @param int          $max_attendees
47
-     * @param array        $template_args
48
-     * @throws \EE_Error
49
-     */
50
-    public function __construct(\EE_Event $event, array $tickets, $max_attendees, array $template_args)
51
-    {
52
-        $this->event         = $event;
53
-        $this->tickets       = $tickets;
54
-        $this->max_attendees = $max_attendees;
55
-        $this->template_args = $template_args;
56
-        $this->template_args['hidden_inputs'] = $this->getHiddenInputs();
57
-        $this->addTemplateArgs();
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * sets any and all template args that are required for this Ticket Selector
64
-     *
65
-     * @return void
66
-     */
67
-    abstract protected function addTemplateArgs();
68
-
69
-
70
-
71
-    /**
72
-     * loadTicketSelectorTemplate
73
-     *
74
-     * @return string
75
-     */
76
-    protected function loadTicketSelectorTemplate()
77
-    {
78
-        try {
79
-            return \EEH_Template::locate_template(
80
-                apply_filters(
81
-                    'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path',
82
-                    $this->template_args['template_path'],
83
-                    $this->event
84
-                ),
85
-                $this->template_args
86
-            );
87
-        } catch (\Exception $e) {
88
-            \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
89
-        }
90
-        return '';
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     * The __toString method allows a class to decide how it will react when it is converted to a string.
97
-     *
98
-     * @return string
99
-     * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring
100
-     */
101
-    public function __toString()
102
-    {
103
-        return $this->loadTicketSelectorTemplate();
104
-    }
105
-
106
-
107
-
108
-
109
-    /**
110
-     * getHiddenInputs
111
-     *
112
-     * @return string
113
-     * @throws \EE_Error
114
-     */
115
-    public function getHiddenInputs()
116
-    {
117
-        // $rows = count($this->tickets);
118
-        $html = '<input type="hidden" name="noheader" value="true"/>';
119
-        $html .= '<input type="hidden" name="tkt-slctr-return-url-' . $this->event->ID() . '"';
120
-        $html .= ' value="' . \EEH_URL::current_url() . $this->template_args['anchor_id'] . '"/>';
121
-        $html .= '<input type="hidden" name="tkt-slctr-rows-' . $this->event->ID();
122
-        $html .= '" value="' . count($this->tickets) . '"/>';
123
-        $html .= '<input type="hidden" name="tkt-slctr-max-atndz-' . $this->event->ID();
124
-        $html .= '" value="' . $this->template_args['max_atndz'] . '"/>';
125
-        $html .= '<input type="hidden" name="tkt-slctr-event-id" value="' . $this->event->ID() . '"/>';
126
-        return $html;
127
-    }
19
+	/**
20
+	 * @var \EE_Event $event
21
+	 */
22
+	protected $event;
23
+
24
+	/**
25
+	 * @var \EE_Ticket[] $tickets
26
+	 */
27
+	protected $tickets;
28
+
29
+	/**
30
+	 * @var int max_attendees
31
+	 */
32
+	protected $max_attendees;
33
+
34
+	/**
35
+	 * @var array $template_args
36
+	 */
37
+	protected $template_args;
38
+
39
+
40
+
41
+	/**
42
+	 * TicketSelectorSimple constructor.
43
+	 *
44
+	 * @param \EE_Event    $event
45
+	 * @param \EE_Ticket[] $tickets
46
+	 * @param int          $max_attendees
47
+	 * @param array        $template_args
48
+	 * @throws \EE_Error
49
+	 */
50
+	public function __construct(\EE_Event $event, array $tickets, $max_attendees, array $template_args)
51
+	{
52
+		$this->event         = $event;
53
+		$this->tickets       = $tickets;
54
+		$this->max_attendees = $max_attendees;
55
+		$this->template_args = $template_args;
56
+		$this->template_args['hidden_inputs'] = $this->getHiddenInputs();
57
+		$this->addTemplateArgs();
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * sets any and all template args that are required for this Ticket Selector
64
+	 *
65
+	 * @return void
66
+	 */
67
+	abstract protected function addTemplateArgs();
68
+
69
+
70
+
71
+	/**
72
+	 * loadTicketSelectorTemplate
73
+	 *
74
+	 * @return string
75
+	 */
76
+	protected function loadTicketSelectorTemplate()
77
+	{
78
+		try {
79
+			return \EEH_Template::locate_template(
80
+				apply_filters(
81
+					'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path',
82
+					$this->template_args['template_path'],
83
+					$this->event
84
+				),
85
+				$this->template_args
86
+			);
87
+		} catch (\Exception $e) {
88
+			\EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
89
+		}
90
+		return '';
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 * The __toString method allows a class to decide how it will react when it is converted to a string.
97
+	 *
98
+	 * @return string
99
+	 * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring
100
+	 */
101
+	public function __toString()
102
+	{
103
+		return $this->loadTicketSelectorTemplate();
104
+	}
105
+
106
+
107
+
108
+
109
+	/**
110
+	 * getHiddenInputs
111
+	 *
112
+	 * @return string
113
+	 * @throws \EE_Error
114
+	 */
115
+	public function getHiddenInputs()
116
+	{
117
+		// $rows = count($this->tickets);
118
+		$html = '<input type="hidden" name="noheader" value="true"/>';
119
+		$html .= '<input type="hidden" name="tkt-slctr-return-url-' . $this->event->ID() . '"';
120
+		$html .= ' value="' . \EEH_URL::current_url() . $this->template_args['anchor_id'] . '"/>';
121
+		$html .= '<input type="hidden" name="tkt-slctr-rows-' . $this->event->ID();
122
+		$html .= '" value="' . count($this->tickets) . '"/>';
123
+		$html .= '<input type="hidden" name="tkt-slctr-max-atndz-' . $this->event->ID();
124
+		$html .= '" value="' . $this->template_args['max_atndz'] . '"/>';
125
+		$html .= '<input type="hidden" name="tkt-slctr-event-id" value="' . $this->event->ID() . '"/>';
126
+		return $html;
127
+	}
128 128
 
129 129
 }
130 130
 // End of file TicketSelector.php
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -116,13 +116,13 @@
 block discarded – undo
116 116
     {
117 117
         // $rows = count($this->tickets);
118 118
         $html = '<input type="hidden" name="noheader" value="true"/>';
119
-        $html .= '<input type="hidden" name="tkt-slctr-return-url-' . $this->event->ID() . '"';
120
-        $html .= ' value="' . \EEH_URL::current_url() . $this->template_args['anchor_id'] . '"/>';
121
-        $html .= '<input type="hidden" name="tkt-slctr-rows-' . $this->event->ID();
122
-        $html .= '" value="' . count($this->tickets) . '"/>';
123
-        $html .= '<input type="hidden" name="tkt-slctr-max-atndz-' . $this->event->ID();
124
-        $html .= '" value="' . $this->template_args['max_atndz'] . '"/>';
125
-        $html .= '<input type="hidden" name="tkt-slctr-event-id" value="' . $this->event->ID() . '"/>';
119
+        $html .= '<input type="hidden" name="tkt-slctr-return-url-'.$this->event->ID().'"';
120
+        $html .= ' value="'.\EEH_URL::current_url().$this->template_args['anchor_id'].'"/>';
121
+        $html .= '<input type="hidden" name="tkt-slctr-rows-'.$this->event->ID();
122
+        $html .= '" value="'.count($this->tickets).'"/>';
123
+        $html .= '<input type="hidden" name="tkt-slctr-max-atndz-'.$this->event->ID();
124
+        $html .= '" value="'.$this->template_args['max_atndz'].'"/>';
125
+        $html .= '<input type="hidden" name="tkt-slctr-event-id" value="'.$this->event->ID().'"/>';
126 126
         return $html;
127 127
     }
128 128
 
Please login to merge, or discard this patch.
core/services/formatters/AsciiOnly.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
 
37 37
     /**
38 38
      * Taken from https://gist.github.com/jaywilliams/119517
39
-     * @param $string
39
+     * @param string $string
40 40
      * @return string
41 41
      */
42 42
     protected function convertAscii($string)
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -1,8 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\services\formatters;
3 3
 
4
-use EventEspresso\core\exceptions\InvalidDataTypeException;
5
-
6 4
 defined('EVENT_ESPRESSO_VERSION') || exit;
7 5
 
8 6
 
Please login to merge, or discard this patch.
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -18,60 +18,60 @@
 block discarded – undo
18 18
 class AsciiOnly extends FormatterBase
19 19
 {
20 20
 
21
-    /**
22
-     * Removes all non Ascii characters from string
23
-     *
24
-     * @param string|int|float $input anything easily cast into a string
25
-     * @return string
26
-     */
27
-    public function format($input)
28
-    {
29
-        //in case an int or float etc was passed in
30
-        $input = (string)$input;
31
-        $input = $this->convertAscii($input);
32
-        return $input;
33
-    }
21
+	/**
22
+	 * Removes all non Ascii characters from string
23
+	 *
24
+	 * @param string|int|float $input anything easily cast into a string
25
+	 * @return string
26
+	 */
27
+	public function format($input)
28
+	{
29
+		//in case an int or float etc was passed in
30
+		$input = (string)$input;
31
+		$input = $this->convertAscii($input);
32
+		return $input;
33
+	}
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * Taken from https://gist.github.com/jaywilliams/119517
39
-     * @param $string
40
-     * @return string
41
-     */
42
-    protected function convertAscii($string)
43
-    {
44
-        // Replace Single Curly Quotes
45
-        $search[]  = chr(226).chr(128).chr(152);
46
-        $replace[] = "'";
47
-        $search[]  = chr(226).chr(128).chr(153);
48
-        $replace[] = "'";
49
-        // Replace Smart Double Curly Quotes
50
-        $search[]  = chr(226).chr(128).chr(156);
51
-        $replace[] = '"';
52
-        $search[]  = chr(226).chr(128).chr(157);
53
-        $replace[] = '"';
54
-        // Replace En Dash
55
-        $search[]  = chr(226).chr(128).chr(147);
56
-        $replace[] = '--';
57
-        // Replace Em Dash
58
-        $search[]  = chr(226).chr(128).chr(148);
59
-        $replace[] = '---';
60
-        // Replace Bullet
61
-        $search[]  = chr(226).chr(128).chr(162);
62
-        $replace[] = '*';
63
-        // Replace Middle Dot
64
-        $search[]  = chr(194).chr(183);
65
-        $replace[] = '*';
66
-        // Replace Ellipsis with three consecutive dots
67
-        $search[]  = chr(226).chr(128).chr(166);
68
-        $replace[] = '...';
69
-        // Apply Replacements
70
-        $string = str_replace($search, $replace, $string);
71
-        // Remove any non-ASCII Characters
72
-        $string = preg_replace("/[^\x01-\x7F]/","", $string);
73
-        return $string;
74
-    }
37
+	/**
38
+	 * Taken from https://gist.github.com/jaywilliams/119517
39
+	 * @param $string
40
+	 * @return string
41
+	 */
42
+	protected function convertAscii($string)
43
+	{
44
+		// Replace Single Curly Quotes
45
+		$search[]  = chr(226).chr(128).chr(152);
46
+		$replace[] = "'";
47
+		$search[]  = chr(226).chr(128).chr(153);
48
+		$replace[] = "'";
49
+		// Replace Smart Double Curly Quotes
50
+		$search[]  = chr(226).chr(128).chr(156);
51
+		$replace[] = '"';
52
+		$search[]  = chr(226).chr(128).chr(157);
53
+		$replace[] = '"';
54
+		// Replace En Dash
55
+		$search[]  = chr(226).chr(128).chr(147);
56
+		$replace[] = '--';
57
+		// Replace Em Dash
58
+		$search[]  = chr(226).chr(128).chr(148);
59
+		$replace[] = '---';
60
+		// Replace Bullet
61
+		$search[]  = chr(226).chr(128).chr(162);
62
+		$replace[] = '*';
63
+		// Replace Middle Dot
64
+		$search[]  = chr(194).chr(183);
65
+		$replace[] = '*';
66
+		// Replace Ellipsis with three consecutive dots
67
+		$search[]  = chr(226).chr(128).chr(166);
68
+		$replace[] = '...';
69
+		// Apply Replacements
70
+		$string = str_replace($search, $replace, $string);
71
+		// Remove any non-ASCII Characters
72
+		$string = preg_replace("/[^\x01-\x7F]/","", $string);
73
+		return $string;
74
+	}
75 75
 }
76 76
 // End of file EmojiRemoval.php
77 77
 // Location: core\services\formatters/EmojiRemoval.php
78 78
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     public function format($input)
28 28
     {
29 29
         //in case an int or float etc was passed in
30
-        $input = (string)$input;
30
+        $input = (string) $input;
31 31
         $input = $this->convertAscii($input);
32 32
         return $input;
33 33
     }
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         // Apply Replacements
70 70
         $string = str_replace($search, $replace, $string);
71 71
         // Remove any non-ASCII Characters
72
-        $string = preg_replace("/[^\x01-\x7F]/","", $string);
72
+        $string = preg_replace("/[^\x01-\x7F]/", "", $string);
73 73
         return $string;
74 74
     }
75 75
 }
Please login to merge, or discard this patch.
core/services/formatters/LeaveAlone.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -18,28 +18,28 @@
 block discarded – undo
18 18
 class LeaveAlone extends FormatterBase
19 19
 {
20 20
 
21
-    /**
22
-     * Removes the emojis from the inputted string
23
-     *
24
-     * @param string|int|float $input anything easily cast into a string
25
-     * @return string
26
-     * @throws InvalidDataTypeException if $input is not a string
27
-     */
28
-    public function format($input)
29
-    {
30
-        return $input;
31
-    }
21
+	/**
22
+	 * Removes the emojis from the inputted string
23
+	 *
24
+	 * @param string|int|float $input anything easily cast into a string
25
+	 * @return string
26
+	 * @throws InvalidDataTypeException if $input is not a string
27
+	 */
28
+	public function format($input)
29
+	{
30
+		return $input;
31
+	}
32 32
 
33
-    /**
34
-     * Just returns the inputted $input array
35
-     *
36
-     * @param array $input
37
-     * @return array
38
-     */
39
-    public function formatArray($input)
40
-    {
41
-        return $input;
42
-    }
33
+	/**
34
+	 * Just returns the inputted $input array
35
+	 *
36
+	 * @param array $input
37
+	 * @return array
38
+	 */
39
+	public function formatArray($input)
40
+	{
41
+		return $input;
42
+	}
43 43
 }
44 44
 // End of file LeaveAlonel.php
45 45
 // Location: core\services\formatters/LeaveAlonel.php
46 46
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_classes/EE_Transaction.class.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 	 * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event function
428 428
 	 * for getting attendees and how many registrations they each have for an event)
429 429
 	 *
430
-	 * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT'
430
+	 * @return EE_Base_Class[] EE_Attendee[] by default, int if $output is set to 'COUNT'
431 431
 	 * @throws \EE_Error
432 432
 	 */
433 433
 	public function attendees() {
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 
465 465
     /**
466 466
      * Gets all payments which have not been approved
467
-     * @return \EEI_Payment[]
467
+     * @return EE_Base_Class[]
468 468
      * @throws EE_Error if a model is misconfigured somehow
469 469
      */
470 470
 	public function pending_payments()
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 	 * Gets all the extra meta info on this payment
710 710
 	 *
711 711
 	 * @param array $query_params like EEM_Base::get_all
712
-	 * @return EE_Extra_Meta
712
+	 * @return EE_Base_Class[]
713 713
 	 * @throws \EE_Error
714 714
 	 */
715 715
 	public function extra_meta( $query_params = array() ) {
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 	 * Sets PMD_ID
887 887
 	 *
888 888
 	 * @param int $PMD_ID
889
-	 * @return boolean
889
+	 * @return boolean|null
890 890
 	 * @throws \EE_Error
891 891
 	 */
892 892
 	public function set_payment_method_ID($PMD_ID) {
Please login to merge, or discard this patch.
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -462,29 +462,29 @@  discard block
 block discarded – undo
462 462
 
463 463
 
464 464
 
465
-    /**
466
-     * Gets all payments which have not been approved
467
-     * @return \EEI_Payment[]
468
-     * @throws EE_Error if a model is misconfigured somehow
469
-     */
465
+	/**
466
+	 * Gets all payments which have not been approved
467
+	 * @return \EEI_Payment[]
468
+	 * @throws EE_Error if a model is misconfigured somehow
469
+	 */
470 470
 	public function pending_payments()
471
-    {
472
-        return $this->get_many_related(
473
-            'Payment',
474
-            array(
475
-                array(
476
-                    'STS_ID' => EEM_Payment::status_id_pending
477
-                ),
478
-                'order_by' => array(
479
-                    'PAY_timestamp' => 'DESC'
480
-                )
481
-            )
482
-        );
483
-    }
484
-
485
-
486
-
487
-    /**
471
+	{
472
+		return $this->get_many_related(
473
+			'Payment',
474
+			array(
475
+				array(
476
+					'STS_ID' => EEM_Payment::status_id_pending
477
+				),
478
+				'order_by' => array(
479
+					'PAY_timestamp' => 'DESC'
480
+				)
481
+			)
482
+		);
483
+	}
484
+
485
+
486
+
487
+	/**
488 488
 	 * echoes $this->pretty_status()
489 489
 	 *
490 490
 	 * @param bool $show_icons
@@ -645,20 +645,20 @@  discard block
 block discarded – undo
645 645
 	 * @throws \EE_Error
646 646
 	 */
647 647
 	public function primary_registration() {
648
-        $registrations = (array) $this->get_many_related(
649
-            'Registration', array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT))
650
-        );
651
-        foreach ($registrations as $registration) {
652
-            // valid registration that is NOT cancelled or declined ?
653
-            if(
654
-                $registration instanceof EE_Registration
655
-                && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true)
656
-            ) {
657
-                return $registration;
658
-            }
659
-        }
660
-        // nothing valid found, so just return first thing from array of results
661
-        return reset($registrations);
648
+		$registrations = (array) $this->get_many_related(
649
+			'Registration', array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT))
650
+		);
651
+		foreach ($registrations as $registration) {
652
+			// valid registration that is NOT cancelled or declined ?
653
+			if(
654
+				$registration instanceof EE_Registration
655
+				&& ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true)
656
+			) {
657
+				return $registration;
658
+			}
659
+		}
660
+		// nothing valid found, so just return first thing from array of results
661
+		return reset($registrations);
662 662
 	}
663 663
 
664 664
 
Please login to merge, or discard this patch.
Spacing   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * EE_Transaction class
@@ -34,13 +34,13 @@  discard block
 block discarded – undo
34 34
 	 * @return EE_Transaction
35 35
 	 * @throws \EE_Error
36 36
 	 */
37
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
38
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
37
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
38
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
39 39
 		$txn = $has_object
40 40
 			? $has_object
41
-			: new self( $props_n_values, false, $timezone, $date_formats );
42
-		if ( ! $has_object ) {
43
-			$txn->set_old_txn_status( $txn->status_ID() );
41
+			: new self($props_n_values, false, $timezone, $date_formats);
42
+		if ( ! $has_object) {
43
+			$txn->set_old_txn_status($txn->status_ID());
44 44
 		}
45 45
 		return $txn;
46 46
 	}
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
 	 * @return EE_Transaction
55 55
 	 * @throws \EE_Error
56 56
 	 */
57
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
58
-		$txn = new self( $props_n_values, TRUE, $timezone );
59
-		$txn->set_old_txn_status( $txn->status_ID() );
57
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
58
+		$txn = new self($props_n_values, TRUE, $timezone);
59
+		$txn->set_old_txn_status($txn->status_ID());
60 60
 		return $txn;
61 61
 	}
62 62
 
@@ -73,16 +73,16 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	public function lock() {
75 75
 		// attempt to set lock, but if that fails...
76
-		if ( ! $this->add_extra_meta( 'lock', time(), true )  ) {
76
+		if ( ! $this->add_extra_meta('lock', time(), true)) {
77 77
 			// then attempt to remove the lock in case it is expired
78
-			if ( $this->_remove_expired_lock() ) {
78
+			if ($this->_remove_expired_lock()) {
79 79
 				// if removal was successful, then try setting lock again
80 80
 				$this->lock();
81 81
 			} else {
82 82
 				// but if the lock can not be removed, then throw an exception
83 83
 				throw new EE_Error(
84 84
 					sprintf(
85
-						__( 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', 'event_espresso' ),
85
+						__('Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', 'event_espresso'),
86 86
 						$this->ID()
87 87
 					)
88 88
 				);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	 * @throws \EE_Error
102 102
 	 */
103 103
 	public function unlock() {
104
-		return $this->delete_extra_meta( 'lock' );
104
+		return $this->delete_extra_meta('lock');
105 105
 	}
106 106
 
107 107
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function is_locked() {
124 124
 		// if TXN is not locked, then return false immediately
125
-		if ( ! $this->_get_lock() ) {
125
+		if ( ! $this->_get_lock()) {
126 126
 			return false;
127 127
 		}
128 128
 		// if not, then let's try and remove the lock in case it's expired...
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * @throws \EE_Error
144 144
 	 */
145 145
 	protected function _get_lock() {
146
-		return (int)$this->get_extra_meta( 'lock', true, 0 );
146
+		return (int) $this->get_extra_meta('lock', true, 0);
147 147
 	}
148 148
 
149 149
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 */
159 159
 	protected function _remove_expired_lock() {
160 160
 		$locked = $this->_get_lock();
161
-		if ( $locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked ) {
161
+		if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) {
162 162
 			return $this->unlock();
163 163
 		}
164 164
 		return 0;
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 	 * @param        float $total total value of transaction
174 174
 	 * @throws \EE_Error
175 175
 	 */
176
-	public function set_total( $total = 0.00 ) {
177
-		$this->set( 'TXN_total', (float)$total );
176
+	public function set_total($total = 0.00) {
177
+		$this->set('TXN_total', (float) $total);
178 178
 	}
179 179
 
180 180
 
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 	 * @param        float $total_paid total amount paid to date (sum of all payments)
187 187
 	 * @throws \EE_Error
188 188
 	 */
189
-	public function set_paid( $total_paid = 0.00 ) {
190
-		$this->set( 'TXN_paid', (float)$total_paid );
189
+	public function set_paid($total_paid = 0.00) {
190
+		$this->set('TXN_paid', (float) $total_paid);
191 191
 	}
192 192
 
193 193
 
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	 * @param        string $status whether the transaction is open, declined, accepted, or any number of custom values that can be set
200 200
 	 * @throws \EE_Error
201 201
 	 */
202
-	public function set_status( $status = '' ) {
203
-		$this->set( 'STS_ID', $status );
202
+	public function set_status($status = '') {
203
+		$this->set('STS_ID', $status);
204 204
 	}
205 205
 
206 206
 
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
 	 * @param        string $hash_salt required for some payment gateways
213 213
 	 * @throws \EE_Error
214 214
 	 */
215
-	public function set_hash_salt( $hash_salt = '' ) {
216
-		$this->set( 'TXN_hash_salt', $hash_salt );
215
+	public function set_hash_salt($hash_salt = '') {
216
+		$this->set('TXN_hash_salt', $hash_salt);
217 217
 	}
218 218
 
219 219
 
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
 	 * @param array $txn_reg_steps
225 225
 	 * @throws \EE_Error
226 226
 	 */
227
-	public function set_reg_steps( array $txn_reg_steps ) {
228
-		$this->set( 'TXN_reg_steps', $txn_reg_steps );
227
+	public function set_reg_steps(array $txn_reg_steps) {
228
+		$this->set('TXN_reg_steps', $txn_reg_steps);
229 229
 	}
230 230
 
231 231
 
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 	 * @throws \EE_Error
238 238
 	 */
239 239
 	public function reg_steps() {
240
-		$TXN_reg_steps = $this->get( 'TXN_reg_steps' );
241
-		return is_array( $TXN_reg_steps ) ? (array)$TXN_reg_steps : array();
240
+		$TXN_reg_steps = $this->get('TXN_reg_steps');
241
+		return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array();
242 242
 	}
243 243
 
244 244
 
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 	 * @throws \EE_Error
249 249
 	 */
250 250
 	public function pretty_total() {
251
-		return $this->get_pretty( 'TXN_total' );
251
+		return $this->get_pretty('TXN_total');
252 252
 	}
253 253
 
254 254
 
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 * @throws \EE_Error
261 261
 	 */
262 262
 	public function pretty_paid() {
263
-		return $this->get_pretty( 'TXN_paid' );
263
+		return $this->get_pretty('TXN_paid');
264 264
 	}
265 265
 
266 266
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	 * @throws \EE_Error
274 274
 	 */
275 275
 	public function remaining() {
276
-		return (float)( $this->total() - $this->paid() );
276
+		return (float) ($this->total() - $this->paid());
277 277
 	}
278 278
 
279 279
 
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 * @throws \EE_Error
287 287
 	 */
288 288
 	public function total() {
289
-		return (float)$this->get( 'TXN_total' );
289
+		return (float) $this->get('TXN_total');
290 290
 	}
291 291
 
292 292
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 * @throws \EE_Error
300 300
 	 */
301 301
 	public function paid() {
302
-		return (float)$this->get( 'TXN_paid' );
302
+		return (float) $this->get('TXN_paid');
303 303
 	}
304 304
 
305 305
 
@@ -311,9 +311,9 @@  discard block
 block discarded – undo
311 311
 	 * @throws \EE_Error
312 312
 	 */
313 313
 	public function get_cart_session() {
314
-		$session_data = (array)$this->get( 'TXN_session_data' );
315
-		return isset( $session_data[ 'cart' ] ) && $session_data[ 'cart' ] instanceof EE_Cart
316
-			? $session_data[ 'cart' ]
314
+		$session_data = (array) $this->get('TXN_session_data');
315
+		return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart
316
+			? $session_data['cart']
317 317
 			: null;
318 318
 	}
319 319
 
@@ -326,8 +326,8 @@  discard block
 block discarded – undo
326 326
 	 * @throws \EE_Error
327 327
 	 */
328 328
 	public function session_data() {
329
-		$session_data = $this->get( 'TXN_session_data' );
330
-		if ( empty( $session_data ) ) {
329
+		$session_data = $this->get('TXN_session_data');
330
+		if (empty($session_data)) {
331 331
 			$session_data = array(
332 332
 				'id'            => null,
333 333
 				'user_id'       => null,
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
 	 * @param        EE_Session|array $session_data
351 351
 	 * @throws \EE_Error
352 352
 	 */
353
-	public function set_txn_session_data( $session_data ) {
354
-		if ( $session_data instanceof EE_Session ) {
355
-			$this->set( 'TXN_session_data', $session_data->get_session_data( NULL, TRUE ));
353
+	public function set_txn_session_data($session_data) {
354
+		if ($session_data instanceof EE_Session) {
355
+			$this->set('TXN_session_data', $session_data->get_session_data(NULL, TRUE));
356 356
 		} else {
357
-			$this->set( 'TXN_session_data', $session_data );
357
+			$this->set('TXN_session_data', $session_data);
358 358
 		}
359 359
 	}
360 360
 
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 	 * @throws \EE_Error
368 368
 	 */
369 369
 	public function hash_salt_() {
370
-		return $this->get( 'TXN_hash_salt' );
370
+		return $this->get('TXN_hash_salt');
371 371
 	}
372 372
 
373 373
 
@@ -387,13 +387,13 @@  discard block
 block discarded – undo
387 387
 	 * @return    string | int
388 388
 	 * @throws \EE_Error
389 389
 	 */
390
-	public function datetime( $format = FALSE, $gmt = FALSE ) {
391
-		if ( $format ) {
392
-			return $this->get_pretty( 'TXN_timestamp' );
393
-		} else if ( $gmt ) {
394
-			return $this->get_raw( 'TXN_timestamp' );
390
+	public function datetime($format = FALSE, $gmt = FALSE) {
391
+		if ($format) {
392
+			return $this->get_pretty('TXN_timestamp');
393
+		} else if ($gmt) {
394
+			return $this->get_raw('TXN_timestamp');
395 395
 		} else {
396
-			return $this->get( 'TXN_timestamp' );
396
+			return $this->get('TXN_timestamp');
397 397
 		}
398 398
 	}
399 399
 
@@ -407,8 +407,8 @@  discard block
 block discarded – undo
407 407
 	 * @return EE_Registration[]
408 408
 	 * @throws \EE_Error
409 409
 	 */
410
-	public function registrations( $query_params = array(), $get_cached = FALSE ) {
411
-		$query_params = ( empty( $query_params ) || ! is_array( $query_params ) )
410
+	public function registrations($query_params = array(), $get_cached = FALSE) {
411
+		$query_params = (empty($query_params) || ! is_array($query_params))
412 412
 			? array(
413 413
 				'order_by' => array(
414 414
 					'Event.EVT_name' => 'ASC',
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 			)
419 419
 			: $query_params;
420 420
 		$query_params = $get_cached ? array() : $query_params;
421
-		return $this->get_many_related( 'Registration', $query_params );
421
+		return $this->get_many_related('Registration', $query_params);
422 422
 	}
423 423
 
424 424
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 	 * @throws \EE_Error
432 432
 	 */
433 433
 	public function attendees() {
434
-		return $this->get_many_related( 'Attendee', array( array( 'Registration.Transaction.TXN_ID' => $this->ID() ) ) );
434
+		return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID())));
435 435
 	}
436 436
 
437 437
 
@@ -443,8 +443,8 @@  discard block
 block discarded – undo
443 443
 	 * @return EE_Payment[]
444 444
 	 * @throws \EE_Error
445 445
 	 */
446
-	public function payments( $query_params = array() ) {
447
-		return $this->get_many_related( 'Payment', $query_params );
446
+	public function payments($query_params = array()) {
447
+		return $this->get_many_related('Payment', $query_params);
448 448
 	}
449 449
 
450 450
 
@@ -456,8 +456,8 @@  discard block
 block discarded – undo
456 456
 	 * @throws \EE_Error
457 457
 	 */
458 458
 	public function approved_payments() {
459
-		EE_Registry::instance()->load_model( 'Payment' );
460
-		return $this->get_many_related( 'Payment', array( array( 'STS_ID' => EEM_Payment::status_id_approved ), 'order_by' => array( 'PAY_timestamp' => 'DESC' ) ) );
459
+		EE_Registry::instance()->load_model('Payment');
460
+		return $this->get_many_related('Payment', array(array('STS_ID' => EEM_Payment::status_id_approved), 'order_by' => array('PAY_timestamp' => 'DESC')));
461 461
 	}
462 462
 
463 463
 
@@ -491,8 +491,8 @@  discard block
 block discarded – undo
491 491
 	 * @return string
492 492
 	 * @throws \EE_Error
493 493
 	 */
494
-	public function e_pretty_status( $show_icons = FALSE ) {
495
-		echo $this->pretty_status( $show_icons );
494
+	public function e_pretty_status($show_icons = FALSE) {
495
+		echo $this->pretty_status($show_icons);
496 496
 	}
497 497
 
498 498
 
@@ -504,10 +504,10 @@  discard block
 block discarded – undo
504 504
 	 * @return string
505 505
 	 * @throws \EE_Error
506 506
 	 */
507
-	public function pretty_status( $show_icons = FALSE ) {
508
-		$status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' );
507
+	public function pretty_status($show_icons = FALSE) {
508
+		$status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence');
509 509
 		$icon = '';
510
-		switch ( $this->status_ID() ) {
510
+		switch ($this->status_ID()) {
511 511
 			case EEM_Transaction::complete_status_code:
512 512
 				$icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : '';
513 513
 				break;
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
 				$icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : '';
525 525
 				break;
526 526
 		}
527
-		return $icon . $status[ $this->status_ID() ];
527
+		return $icon.$status[$this->status_ID()];
528 528
 	}
529 529
 
530 530
 
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 	 * @throws \EE_Error
537 537
 	 */
538 538
 	public function status_ID() {
539
-		return $this->get( 'STS_ID' );
539
+		return $this->get('STS_ID');
540 540
 	}
541 541
 
542 542
 
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
 	 * @throws \EE_Error
549 549
 	 */
550 550
 	public function is_free() {
551
-		return EEH_Money::compare_floats( $this->get( 'TXN_total' ), 0, '==' );
551
+		return EEH_Money::compare_floats($this->get('TXN_total'), 0, '==');
552 552
 	}
553 553
 
554 554
 
@@ -628,12 +628,12 @@  discard block
 block discarded – undo
628 628
 	 * @return string
629 629
 	 * @throws \EE_Error
630 630
 	 */
631
-	public function invoice_url( $type = 'html' ) {
631
+	public function invoice_url($type = 'html') {
632 632
 		$REG = $this->primary_registration();
633
-		if ( ! $REG instanceof EE_Registration ) {
633
+		if ( ! $REG instanceof EE_Registration) {
634 634
 			return '';
635 635
 		}
636
-		return $REG->invoice_url( $type );
636
+		return $REG->invoice_url($type);
637 637
 	}
638 638
 
639 639
 
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
         );
651 651
         foreach ($registrations as $registration) {
652 652
             // valid registration that is NOT cancelled or declined ?
653
-            if(
653
+            if (
654 654
                 $registration instanceof EE_Registration
655 655
                 && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true)
656 656
             ) {
@@ -670,12 +670,12 @@  discard block
 block discarded – undo
670 670
 	 * @return string
671 671
 	 * @throws \EE_Error
672 672
 	 */
673
-	public function receipt_url( $type = 'html' ) {
673
+	public function receipt_url($type = 'html') {
674 674
 		$REG = $this->primary_registration();
675
-		if ( ! $REG instanceof EE_Registration ) {
675
+		if ( ! $REG instanceof EE_Registration) {
676 676
 			return '';
677 677
 		}
678
-		return $REG->receipt_url( $type );
678
+		return $REG->receipt_url($type);
679 679
 	}
680 680
 
681 681
 
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 	 * @throws \EE_Error
701 701
 	 */
702 702
 	public function gateway_response_on_transaction() {
703
-		$payment = $this->get_first_related( 'Payment' );
703
+		$payment = $this->get_first_related('Payment');
704 704
 		return $payment instanceof EE_Payment ? $payment->gateway_response() : '';
705 705
 	}
706 706
 
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
 	 * @throws \EE_Error
714 714
 	 */
715 715
 	public function status_obj() {
716
-		return $this->get_first_related( 'Status' );
716
+		return $this->get_first_related('Status');
717 717
 	}
718 718
 
719 719
 
@@ -725,8 +725,8 @@  discard block
 block discarded – undo
725 725
 	 * @return EE_Extra_Meta
726 726
 	 * @throws \EE_Error
727 727
 	 */
728
-	public function extra_meta( $query_params = array() ) {
729
-		return $this->get_many_related( 'Extra_Meta', $query_params );
728
+	public function extra_meta($query_params = array()) {
729
+		return $this->get_many_related('Extra_Meta', $query_params);
730 730
 	}
731 731
 
732 732
 
@@ -738,8 +738,8 @@  discard block
 block discarded – undo
738 738
 	 * @return EE_Base_Class the relation was added to
739 739
 	 * @throws \EE_Error
740 740
 	 */
741
-	public function add_registration( EE_Registration $registration ) {
742
-		return $this->_add_relation_to( $registration, 'Registration' );
741
+	public function add_registration(EE_Registration $registration) {
742
+		return $this->_add_relation_to($registration, 'Registration');
743 743
 	}
744 744
 
745 745
 
@@ -752,8 +752,8 @@  discard block
 block discarded – undo
752 752
 	 * @return EE_Base_Class that was removed from being related
753 753
 	 * @throws \EE_Error
754 754
 	 */
755
-	public function remove_registration_with_id( $registration_or_id ) {
756
-		return $this->_remove_relation_to( $registration_or_id, 'Registration' );
755
+	public function remove_registration_with_id($registration_or_id) {
756
+		return $this->_remove_relation_to($registration_or_id, 'Registration');
757 757
 	}
758 758
 
759 759
 
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 	 * @throws \EE_Error
766 766
 	 */
767 767
 	public function items_purchased() {
768
-		return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_line_item ) ) );
768
+		return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item)));
769 769
 	}
770 770
 
771 771
 
@@ -777,8 +777,8 @@  discard block
 block discarded – undo
777 777
 	 * @return EE_Base_Class the relation was added to
778 778
 	 * @throws \EE_Error
779 779
 	 */
780
-	public function add_line_item( EE_Line_Item $line_item ) {
781
-		return $this->_add_relation_to( $line_item, 'Line_Item' );
780
+	public function add_line_item(EE_Line_Item $line_item) {
781
+		return $this->_add_relation_to($line_item, 'Line_Item');
782 782
 	}
783 783
 
784 784
 
@@ -790,8 +790,8 @@  discard block
 block discarded – undo
790 790
 	 * @return EE_Line_Item[]
791 791
 	 * @throws \EE_Error
792 792
 	 */
793
-	public function line_items( $query_params = array() ) {
794
-		return $this->get_many_related( 'Line_Item', $query_params );
793
+	public function line_items($query_params = array()) {
794
+		return $this->get_many_related('Line_Item', $query_params);
795 795
 	}
796 796
 
797 797
 
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
 	 * @throws \EE_Error
804 804
 	 */
805 805
 	public function tax_items() {
806
-		return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_tax ) ) );
806
+		return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax)));
807 807
 	}
808 808
 
809 809
 
@@ -816,10 +816,10 @@  discard block
 block discarded – undo
816 816
 	 * @return \EE_Line_Item
817 817
 	 * @throws \EE_Error
818 818
 	 */
819
-	public function total_line_item( $create_if_not_found = true ) {
820
-		$item =  $this->get_first_related( 'Line_Item', array( array( 'LIN_type' => EEM_Line_Item::type_total ) ) );
821
-		if( ! $item && $create_if_not_found ){
822
-			$item = EEH_Line_Item::create_total_line_item( $this );
819
+	public function total_line_item($create_if_not_found = true) {
820
+		$item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total)));
821
+		if ( ! $item && $create_if_not_found) {
822
+			$item = EEH_Line_Item::create_total_line_item($this);
823 823
 		}
824 824
 		return $item;
825 825
 	}
@@ -835,10 +835,10 @@  discard block
 block discarded – undo
835 835
 	 */
836 836
 	public function tax_total() {
837 837
 		$tax_line_item = $this->tax_total_line_item();
838
-		if ( $tax_line_item ) {
839
-			return (float)$tax_line_item->total();
838
+		if ($tax_line_item) {
839
+			return (float) $tax_line_item->total();
840 840
 		} else {
841
-			return (float)0;
841
+			return (float) 0;
842 842
 		}
843 843
 	}
844 844
 
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 	 * @throws \EE_Error
852 852
 	 */
853 853
 	public function tax_total_line_item() {
854
-		return EEH_Line_Item::get_taxes_subtotal( $this->total_line_item() );
854
+		return EEH_Line_Item::get_taxes_subtotal($this->total_line_item());
855 855
 	}
856 856
 
857 857
 
@@ -862,20 +862,20 @@  discard block
 block discarded – undo
862 862
 	 * @return EE_Form_Section_Proper
863 863
 	 * @throws \EE_Error
864 864
 	 */
865
-	public function billing_info(){
865
+	public function billing_info() {
866 866
 		$payment_method = $this->payment_method();
867
-		if ( !$payment_method){
867
+		if ( ! $payment_method) {
868 868
 			EE_Error::add_error(__("Could not find billing info for transaction because no gateway has been used for it yet", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
869 869
 			return false;
870 870
 		}
871 871
 		$primary_reg = $this->primary_registration();
872
-		if ( ! $primary_reg ) {
873
-			EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ );
872
+		if ( ! $primary_reg) {
873
+			EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
874 874
 			return FALSE;
875 875
 		}
876 876
 		$attendee = $primary_reg->attendee();
877
-		if ( ! $attendee ) {
878
-			EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ );
877
+		if ( ! $attendee) {
878
+			EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
879 879
 			return FALSE;
880 880
 		}
881 881
 		return $attendee->billing_info_for_payment_method($payment_method);
@@ -916,15 +916,15 @@  discard block
 block discarded – undo
916 916
 	 * @return EE_Payment_Method
917 917
 	 * @throws \EE_Error
918 918
 	 */
919
-	public function payment_method(){
919
+	public function payment_method() {
920 920
 		$pm = $this->get_first_related('Payment_Method');
921
-		if( $pm instanceof EE_Payment_Method ){
921
+		if ($pm instanceof EE_Payment_Method) {
922 922
 			return $pm;
923
-		}else{
923
+		} else {
924 924
 			$last_payment = $this->last_payment();
925
-			if( $last_payment instanceof EE_Payment && $last_payment->payment_method() ){
925
+			if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) {
926 926
 				return $last_payment->payment_method();
927
-			}else{
927
+			} else {
928 928
 				return NULL;
929 929
 			}
930 930
 		}
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
 	 * @throws \EE_Error
940 940
 	 */
941 941
 	public function last_payment() {
942
-		return $this->get_first_related( 'Payment', array( 'order_by' => array( 'PAY_ID' => 'desc' ) ) );
942
+		return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc')));
943 943
 	}
944 944
 
945 945
 
@@ -950,8 +950,8 @@  discard block
 block discarded – undo
950 950
 	 * @return EE_Line_Item[]
951 951
 	 * @throws \EE_Error
952 952
 	 */
953
-	public function non_ticket_line_items(){
954
-		return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction( $this->ID() );
953
+	public function non_ticket_line_items() {
954
+		return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID());
955 955
 	}
956 956
 
957 957
 
@@ -999,7 +999,7 @@  discard block
 block discarded – undo
999 999
 	public function update_based_on_payments()
1000 1000
 	{
1001 1001
 		EE_Error::doing_it_wrong(
1002
-			__CLASS__ . '::' . __FUNCTION__,
1002
+			__CLASS__.'::'.__FUNCTION__,
1003 1003
 			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
1004 1004
 				'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
1005 1005
 			'4.6.0'
@@ -1023,9 +1023,9 @@  discard block
 block discarded – undo
1023 1023
 	/**
1024 1024
 	 * @param string $old_txn_status
1025 1025
 	 */
1026
-	public function set_old_txn_status( $old_txn_status ) {
1026
+	public function set_old_txn_status($old_txn_status) {
1027 1027
 		// only set the first time
1028
-		if ( $this->_old_txn_status === null ) {
1028
+		if ($this->_old_txn_status === null) {
1029 1029
 			$this->_old_txn_status = $old_txn_status;
1030 1030
 		}
1031 1031
 	}
@@ -1054,17 +1054,17 @@  discard block
 block discarded – undo
1054 1054
 	 * @param bool           $check_all
1055 1055
 	 * @return boolean | int
1056 1056
 	 */
1057
-	private function _reg_steps_completed( $reg_step_slug = '', $check_all = true ) {
1057
+	private function _reg_steps_completed($reg_step_slug = '', $check_all = true) {
1058 1058
 		$reg_steps = $this->reg_steps();
1059
-		if ( ! is_array( $reg_steps ) || empty( $reg_steps ) ) {
1059
+		if ( ! is_array($reg_steps) || empty($reg_steps)) {
1060 1060
 			return false;
1061 1061
 		}
1062 1062
 		// loop thru reg steps array)
1063
-		foreach ( $reg_steps as $slug => $reg_step_completed ) {
1063
+		foreach ($reg_steps as $slug => $reg_step_completed) {
1064 1064
 			// if NOT checking ALL steps (only checking one step)
1065
-			if ( ! $check_all ) {
1065
+			if ( ! $check_all) {
1066 1066
 				// and this is the one
1067
-				if ( $slug === $reg_step_slug ) {
1067
+				if ($slug === $reg_step_slug) {
1068 1068
 					return $reg_step_completed;
1069 1069
 				} else {
1070 1070
 					// skip to next reg step in loop
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
 				}
1073 1073
 			}
1074 1074
 			// $check_all must be true, else we would never have gotten to this point
1075
-			if ( $slug === $reg_step_slug ) {
1075
+			if ($slug === $reg_step_slug) {
1076 1076
 				// if we reach this point, then we are testing either:
1077 1077
 				// all_reg_steps_completed_except() or
1078 1078
 				// all_reg_steps_completed_except_final_step(),
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
 				// ie: "is everything completed except the final step?"
1082 1082
 				// "that is correct... the final step is not completed, but all others are."
1083 1083
 				return $reg_step_completed !== true ? true : false;
1084
-			} else if ( $reg_step_completed !== true ) {
1084
+			} else if ($reg_step_completed !== true) {
1085 1085
 				// if any reg step is NOT completed, then ALL steps are not completed
1086 1086
 				return false;
1087 1087
 			}
@@ -1115,8 +1115,8 @@  discard block
 block discarded – undo
1115 1115
 	 * @param string         $exception
1116 1116
 	 * @return boolean
1117 1117
 	 */
1118
-	public function all_reg_steps_completed_except( $exception = '' ) {
1119
-		return $this->_reg_steps_completed( $exception );
1118
+	public function all_reg_steps_completed_except($exception = '') {
1119
+		return $this->_reg_steps_completed($exception);
1120 1120
 	}
1121 1121
 
1122 1122
 
@@ -1131,7 +1131,7 @@  discard block
 block discarded – undo
1131 1131
 	 * @return boolean
1132 1132
 	 */
1133 1133
 	public function all_reg_steps_completed_except_final_step() {
1134
-		return $this->_reg_steps_completed( 'finalize_registration' );
1134
+		return $this->_reg_steps_completed('finalize_registration');
1135 1135
 	}
1136 1136
 
1137 1137
 
@@ -1146,8 +1146,8 @@  discard block
 block discarded – undo
1146 1146
 	 * @param string         $reg_step_slug
1147 1147
 	 * @return boolean | int
1148 1148
 	 */
1149
-	public function reg_step_completed( $reg_step_slug ) {
1150
-		return $this->_reg_steps_completed( $reg_step_slug, false );
1149
+	public function reg_step_completed($reg_step_slug) {
1150
+		return $this->_reg_steps_completed($reg_step_slug, false);
1151 1151
 	}
1152 1152
 
1153 1153
 
@@ -1162,7 +1162,7 @@  discard block
 block discarded – undo
1162 1162
 	 * @return boolean | int
1163 1163
 	 */
1164 1164
 	public function final_reg_step_completed() {
1165
-		return $this->_reg_steps_completed( 'finalize_registration', false );
1165
+		return $this->_reg_steps_completed('finalize_registration', false);
1166 1166
 	}
1167 1167
 
1168 1168
 
@@ -1176,8 +1176,8 @@  discard block
 block discarded – undo
1176 1176
 	 * @return boolean
1177 1177
 	 * @throws \EE_Error
1178 1178
 	 */
1179
-	public function set_reg_step_initiated( $reg_step_slug ) {
1180
-		return $this->_set_reg_step_completed_status( $reg_step_slug, time() );
1179
+	public function set_reg_step_initiated($reg_step_slug) {
1180
+		return $this->_set_reg_step_completed_status($reg_step_slug, time());
1181 1181
 	}
1182 1182
 
1183 1183
 
@@ -1191,8 +1191,8 @@  discard block
 block discarded – undo
1191 1191
 	 * @return boolean
1192 1192
 	 * @throws \EE_Error
1193 1193
 	 */
1194
-	public function set_reg_step_completed( $reg_step_slug ) {
1195
-		return $this->_set_reg_step_completed_status( $reg_step_slug, true );
1194
+	public function set_reg_step_completed($reg_step_slug) {
1195
+		return $this->_set_reg_step_completed_status($reg_step_slug, true);
1196 1196
 	}
1197 1197
 
1198 1198
 
@@ -1206,8 +1206,8 @@  discard block
 block discarded – undo
1206 1206
 	 * @return boolean
1207 1207
 	 * @throws \EE_Error
1208 1208
 	 */
1209
-	public function set_reg_step_not_completed( $reg_step_slug ) {
1210
-		return $this->_set_reg_step_completed_status( $reg_step_slug, false );
1209
+	public function set_reg_step_not_completed($reg_step_slug) {
1210
+		return $this->_set_reg_step_completed_status($reg_step_slug, false);
1211 1211
 	}
1212 1212
 
1213 1213
 
@@ -1222,37 +1222,37 @@  discard block
 block discarded – undo
1222 1222
 	 * @return boolean
1223 1223
 	 * @throws \EE_Error
1224 1224
 	 */
1225
-	private function _set_reg_step_completed_status( $reg_step_slug, $status ) {
1225
+	private function _set_reg_step_completed_status($reg_step_slug, $status) {
1226 1226
 		// validate status
1227
-		$status = is_bool( $status ) || is_int( $status ) ? $status : false;
1227
+		$status = is_bool($status) || is_int($status) ? $status : false;
1228 1228
 		// get reg steps array
1229 1229
 		$txn_reg_steps = $this->reg_steps();
1230 1230
 		// if reg step does NOT exist
1231
-		if ( ! isset( $txn_reg_steps[ $reg_step_slug ] ) ) {
1231
+		if ( ! isset($txn_reg_steps[$reg_step_slug])) {
1232 1232
 			return false;
1233 1233
 		}
1234 1234
 		// if  we're trying to complete a step that is already completed
1235
-		if ( $txn_reg_steps[ $reg_step_slug ] === true ) {
1235
+		if ($txn_reg_steps[$reg_step_slug] === true) {
1236 1236
 			return true;
1237 1237
 		}
1238 1238
 		// if  we're trying to complete a step that hasn't even started
1239
-		if ( $status === true && $txn_reg_steps[ $reg_step_slug ] === false ) {
1239
+		if ($status === true && $txn_reg_steps[$reg_step_slug] === false) {
1240 1240
 			return false;
1241 1241
 		}
1242 1242
 		// if current status value matches the incoming value (no change)
1243 1243
 		// type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890
1244
-		if ( (int) $txn_reg_steps[ $reg_step_slug ] === (int) $status ) {
1244
+		if ((int) $txn_reg_steps[$reg_step_slug] === (int) $status) {
1245 1245
 			// this will happen in cases where multiple AJAX requests occur during the same step
1246 1246
 			return true;
1247 1247
 		}
1248 1248
 		// if we're trying to set a start time, but it has already been set...
1249
-		if ( is_numeric( $status ) && is_numeric( $txn_reg_steps[ $reg_step_slug ] ) ) {
1249
+		if (is_numeric($status) && is_numeric($txn_reg_steps[$reg_step_slug])) {
1250 1250
 			// skip the update below, but don't return FALSE so that errors won't be displayed
1251 1251
 			return true;
1252 1252
 		}
1253 1253
 		// update completed status
1254
-		$txn_reg_steps[ $reg_step_slug ] = $status;
1255
-		$this->set_reg_steps( $txn_reg_steps );
1254
+		$txn_reg_steps[$reg_step_slug] = $status;
1255
+		$this->set_reg_steps($txn_reg_steps);
1256 1256
 		$this->save();
1257 1257
 		return true;
1258 1258
 	}
@@ -1268,11 +1268,11 @@  discard block
 block discarded – undo
1268 1268
 	 * @param string          $reg_step_slug
1269 1269
 	 * @return void
1270 1270
 	 */
1271
-	public function remove_reg_step( $reg_step_slug ) {
1271
+	public function remove_reg_step($reg_step_slug) {
1272 1272
 		// get reg steps array
1273 1273
 		$txn_reg_steps = $this->reg_steps();
1274
-		unset( $txn_reg_steps[ $reg_step_slug ] );
1275
-		$this->set_reg_steps( $txn_reg_steps );
1274
+		unset($txn_reg_steps[$reg_step_slug]);
1275
+		$this->set_reg_steps($txn_reg_steps);
1276 1276
 	}
1277 1277
 
1278 1278
 
@@ -1286,11 +1286,11 @@  discard block
 block discarded – undo
1286 1286
 	 * @param bool $save
1287 1287
 	 * @return bool
1288 1288
 	 */
1289
-	public function toggle_failed_transaction_status( $save = true ) {
1289
+	public function toggle_failed_transaction_status($save = true) {
1290 1290
 		// if TXN status is still set as "failed"...
1291
-		if ( $this->status_ID() === EEM_Transaction::failed_status_code ) {
1292
-			$this->set_status( EEM_Transaction::abandoned_status_code );
1293
-			if ( $save ) {
1291
+		if ($this->status_ID() === EEM_Transaction::failed_status_code) {
1292
+			$this->set_status(EEM_Transaction::abandoned_status_code);
1293
+			if ($save) {
1294 1294
 				$this->save();
1295 1295
 			}
1296 1296
 			return true;
@@ -1319,10 +1319,10 @@  discard block
 block discarded – undo
1319 1319
 				$this->primary_registration() instanceof EE_Registration
1320 1320
 				&& $this->primary_registration()->attendee() instanceof EE_Attendee
1321 1321
 			) {
1322
-				$this->set_status( EEM_Transaction::incomplete_status_code );
1322
+				$this->set_status(EEM_Transaction::incomplete_status_code);
1323 1323
 			} else {
1324 1324
 				// no contact record? yer abandoned!
1325
-				$this->set_status( EEM_Transaction::abandoned_status_code );
1325
+				$this->set_status(EEM_Transaction::abandoned_status_code);
1326 1326
 			}
1327 1327
 			return true;
1328 1328
 		}
@@ -1336,16 +1336,16 @@  discard block
 block discarded – undo
1336 1336
 	 * updates the TXN status based on the amount paid
1337 1337
 	 */
1338 1338
 	public function verify_abandoned_transaction_status() {
1339
-		if ( $this->status_ID() !== EEM_Transaction::abandoned_status_code ) {
1339
+		if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) {
1340 1340
 			return;
1341 1341
 		}
1342
-		$payments = $this->get_many_related( 'Payment' );
1343
-		if ( ! empty( $payments ) ) {
1344
-			foreach ( $payments as $payment ) {
1345
-				if ( $payment instanceof EE_Payment ) {
1342
+		$payments = $this->get_many_related('Payment');
1343
+		if ( ! empty($payments)) {
1344
+			foreach ($payments as $payment) {
1345
+				if ($payment instanceof EE_Payment) {
1346 1346
 					// kk this TXN should NOT be abandoned
1347 1347
 					$this->update_status_based_on_total_paid();
1348
-					if ( is_admin() && ! ( defined('DOING_AJAX') && DOING_AJAX ) ) {
1348
+					if (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX)) {
1349 1349
 						EE_Error::add_attention(
1350 1350
 							sprintf(
1351 1351
 								esc_html__(
@@ -1361,8 +1361,8 @@  discard block
 block discarded – undo
1361 1361
 					$finalized = $this->final_reg_step_completed();
1362 1362
 					// if the 'finalize_registration' step has been initiated (has a timestamp)
1363 1363
 					// but has not yet been fully completed (TRUE)
1364
-					if ( is_int( $finalized ) && $finalized !== false && $finalized !== true ) {
1365
-						$this->set_reg_step_completed( 'finalize_registration' );
1364
+					if (is_int($finalized) && $finalized !== false && $finalized !== true) {
1365
+						$this->set_reg_step_completed('finalize_registration');
1366 1366
 						$this->save();
1367 1367
 					}
1368 1368
 				}
Please login to merge, or discard this patch.
modules/mijireh_payment_checker/EED_Mijireh_Payment_Checker.module.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -45,23 +45,23 @@
 block discarded – undo
45 45
 
46 46
 
47 47
 
48
-    /**
49
-     * If the transaction has pending mijireh payments, we check with mijireh to see if they've been completed.
50
-     * @param EE_Transaction $transaction
51
-     * @throws EE_Error if a model is misconfigured
52
-     */
48
+	/**
49
+	 * If the transaction has pending mijireh payments, we check with mijireh to see if they've been completed.
50
+	 * @param EE_Transaction $transaction
51
+	 * @throws EE_Error if a model is misconfigured
52
+	 */
53 53
 	public static function check_for_payment_update_on_transaction( $transaction ) {
54 54
 		if( $transaction instanceof EE_Transaction ) {
55 55
 			//are there pending Mijireh payments on this transaction?
56
-            $a_mijireh_payment = EEM_Payment::instance()->get_one(
57
-                array(
58
-                    array(
59
-                        'TXN_ID' => $transaction->ID(),
60
-                        'STS_ID' => EEM_Payment::status_id_pending,
61
-                        'Payment_Method.PMD_type' => 'Mijireh',
62
-                    )
63
-                )
64
-            );
56
+			$a_mijireh_payment = EEM_Payment::instance()->get_one(
57
+				array(
58
+					array(
59
+						'TXN_ID' => $transaction->ID(),
60
+						'STS_ID' => EEM_Payment::status_id_pending,
61
+						'Payment_Method.PMD_type' => 'Mijireh',
62
+					)
63
+				)
64
+			);
65 65
 			if($a_mijireh_payment instanceof EE_Payment) {
66 66
 				add_action(
67 67
 					'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
3
-	exit( 'No direct script access allowed' );
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  * @author				Mike Nelson
20 20
  *
21 21
  */
22
-class EED_Mijireh_Payment_Checker extends EED_Module{
22
+class EED_Mijireh_Payment_Checker extends EED_Module {
23 23
 
24 24
 	/**
25 25
 	 * 	set_hooks - for hooking into EE Core, other modules, etc
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 *  @return 	void
41 41
 	 */
42 42
 	public static function set_hooks_admin() {
43
-		add_action( 'AHEE__Transactions_Admin_Page__transaction_details__start', array( 'EED_Mijireh_Payment_Checker', 'check_for_payment_update_on_transaction' ), 10, 1 );
43
+		add_action('AHEE__Transactions_Admin_Page__transaction_details__start', array('EED_Mijireh_Payment_Checker', 'check_for_payment_update_on_transaction'), 10, 1);
44 44
 	}
45 45
 
46 46
 
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
      * @param EE_Transaction $transaction
51 51
      * @throws EE_Error if a model is misconfigured
52 52
      */
53
-	public static function check_for_payment_update_on_transaction( $transaction ) {
54
-		if( $transaction instanceof EE_Transaction ) {
53
+	public static function check_for_payment_update_on_transaction($transaction) {
54
+		if ($transaction instanceof EE_Transaction) {
55 55
 			//are there pending Mijireh payments on this transaction?
56 56
             $a_mijireh_payment = EEM_Payment::instance()->get_one(
57 57
                 array(
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
                     )
63 63
                 )
64 64
             );
65
-			if($a_mijireh_payment instanceof EE_Payment) {
65
+			if ($a_mijireh_payment instanceof EE_Payment) {
66 66
 				add_action(
67 67
 					'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
68
-					array( 'EED_Mijireh_Payment_Checker', 'send_notifications_after_mijireh_ipn' ),
68
+					array('EED_Mijireh_Payment_Checker', 'send_notifications_after_mijireh_ipn'),
69 69
 					5, 2
70 70
 				);
71
-				EE_Payment_Processor::instance()->process_ipn( array(), $transaction, $a_mijireh_payment->payment_method() );
71
+				EE_Payment_Processor::instance()->process_ipn(array(), $transaction, $a_mijireh_payment->payment_method());
72 72
 			}
73 73
 		}
74 74
 	}
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
 	 * @param EE_Registration $registration
85 85
 	 * @param array $additional_details
86 86
 	 */
87
-	public static function send_notifications_after_mijireh_ipn( $registration, $additional_details ) {
88
-		$last_payment = isset( $additional_details[ 'last_payment' ] ) ? $additional_details[ 'last_payment' ] : null;
89
-		if ( ! $last_payment instanceof EE_Payment || $last_payment->status() != EEM_Payment::status_id_approved ) {
90
-			add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15 );
87
+	public static function send_notifications_after_mijireh_ipn($registration, $additional_details) {
88
+		$last_payment = isset($additional_details['last_payment']) ? $additional_details['last_payment'] : null;
89
+		if ( ! $last_payment instanceof EE_Payment || $last_payment->status() != EEM_Payment::status_id_approved) {
90
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
91 91
 		}
92 92
 	}
93 93
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 * @access    public
100 100
 	 * @param WP_Query $WP_Query
101 101
 	 */
102
-	public function run( $WP_Query = null ) {
102
+	public function run($WP_Query = null) {
103 103
 	}
104 104
 }
105 105
 
Please login to merge, or discard this patch.
core/libraries/iframe_display/EventListIframeEmbedButton.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -15,21 +15,21 @@  discard block
 block discarded – undo
15 15
 class EventListIframeEmbedButton extends IframeEmbedButton
16 16
 {
17 17
 
18
-    /**
19
-     * EventListIframeEmbedButton constructor.
20
-     */
21
-    public function __construct()
22
-    {
23
-        parent::__construct(
24
-            esc_html__( 'Upcoming Event List', 'event_espresso' ),
25
-            'event_list'
26
-        );
27
-    }
18
+	/**
19
+	 * EventListIframeEmbedButton constructor.
20
+	 */
21
+	public function __construct()
22
+	{
23
+		parent::__construct(
24
+			esc_html__( 'Upcoming Event List', 'event_espresso' ),
25
+			'event_list'
26
+		);
27
+	}
28 28
 
29 29
 
30 30
 
31 31
 	public function addEmbedButton() {
32
-        add_filter(
32
+		add_filter(
33 33
 			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
34 34
 			array( $this, 'addEventListIframeEmbedButtonSection' )
35 35
 		);
@@ -49,18 +49,18 @@  discard block
 block discarded – undo
49 49
 	 * @param array $after_list_table
50 50
 	 * @return array
51 51
 	 */
52
-    public function addEventListIframeEmbedButtonSection( array $after_list_table )
53
-    {
54
-        return \EEH_Array::insert_into_array(
55
-    		$after_list_table,
56
-		    array(
57
-			    'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection(
58
-				    array( 'event_list' => $this->embedButtonHtml() )
59
-			    )
60
-		    ),
61
-		    'legend'
62
-	    );
63
-    }
52
+	public function addEventListIframeEmbedButtonSection( array $after_list_table )
53
+	{
54
+		return \EEH_Array::insert_into_array(
55
+			$after_list_table,
56
+			array(
57
+				'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection(
58
+					array( 'event_list' => $this->embedButtonHtml() )
59
+				)
60
+			),
61
+			'legend'
62
+		);
63
+	}
64 64
 
65 65
 
66 66
 
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\iframe_display;
3 3
 
4
-defined( 'ABSPATH' ) || exit;
4
+defined('ABSPATH') || exit;
5 5
 
6 6
 
7 7
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
     public function __construct()
22 22
     {
23 23
         parent::__construct(
24
-            esc_html__( 'Upcoming Event List', 'event_espresso' ),
24
+            esc_html__('Upcoming Event List', 'event_espresso'),
25 25
             'event_list'
26 26
         );
27 27
     }
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
 	public function addEmbedButton() {
32 32
         add_filter(
33 33
 			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
34
-			array( $this, 'addEventListIframeEmbedButtonSection' )
34
+			array($this, 'addEventListIframeEmbedButtonSection')
35 35
 		);
36 36
 		add_action(
37 37
 			'admin_enqueue_scripts',
38
-			array( $this, 'embedButtonAssets' ),
38
+			array($this, 'embedButtonAssets'),
39 39
 			10
40 40
 		);
41 41
 	}
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
 	 * @param array $after_list_table
50 50
 	 * @return array
51 51
 	 */
52
-    public function addEventListIframeEmbedButtonSection( array $after_list_table )
52
+    public function addEventListIframeEmbedButtonSection(array $after_list_table)
53 53
     {
54 54
         return \EEH_Array::insert_into_array(
55 55
     		$after_list_table,
56 56
 		    array(
57 57
 			    'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection(
58
-				    array( 'event_list' => $this->embedButtonHtml() )
58
+				    array('event_list' => $this->embedButtonHtml())
59 59
 			    )
60 60
 		    ),
61 61
 		    'legend'
Please login to merge, or discard this patch.
core/services/formatters/Windows1252.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@
 block discarded – undo
28 28
     public function format($input)
29 29
     {
30 30
         //in case an int or float etc was passed in
31
-        $input = (string)$input;
32
-        $input = iconv('utf-8','cp1252//TRANSLIT', $input);
31
+        $input = (string) $input;
32
+        $input = iconv('utf-8', 'cp1252//TRANSLIT', $input);
33 33
         return $input;
34 34
     }
35 35
 }
Please login to merge, or discard this patch.
Indentation   +13 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,7 +11,6 @@  discard block
 block discarded – undo
11 11
  * Class Windows1252
12 12
  * Converts from utf8 encoding to windows 1252 (aka cp1252, aka ISO-8859-1, see https://en.wikipedia.org/wiki/Windows-1252).
13 13
  * This is useful if you need to send a string to a site using windows 1252 character encoding
14
-
15 14
  *
16 15
 *@package        Event Espresso
17 16
  * @author         Mike Nelson
@@ -20,19 +19,19 @@  discard block
 block discarded – undo
20 19
 class Windows1252 extends FormatterBase
21 20
 {
22 21
 
23
-    /**
24
-     * Converts the string to windows-1252 encoding.
25
-     *
26
-     * @param string|int|float $input anything easily cast into a string
27
-     * @return string
28
-     */
29
-    public function format($input)
30
-    {
31
-        //in case an int or float etc was passed in
32
-        $input = (string)$input;
33
-        $input = iconv('utf-8','cp1252//TRANSLIT', $input);
34
-        return $input;
35
-    }
22
+	/**
23
+	 * Converts the string to windows-1252 encoding.
24
+	 *
25
+	 * @param string|int|float $input anything easily cast into a string
26
+	 * @return string
27
+	 */
28
+	public function format($input)
29
+	{
30
+		//in case an int or float etc was passed in
31
+		$input = (string)$input;
32
+		$input = iconv('utf-8','cp1252//TRANSLIT', $input);
33
+		return $input;
34
+	}
36 35
 }
37 36
 // End of file EmojiRemoval.php
38 37
 // Location: core\services\formatters/EmojiRemoval.php
39 38
\ No newline at end of file
Please login to merge, or discard this patch.
admin/new/pricing/templates/event_tickets_datetime_ticket_row.template.php 2 patches
Braces   +40 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,24 +6,33 @@  discard block
 block discarded – undo
6 6
 		<?php if ( $disabled ) : ?>
7 7
 			<input type="hidden" id="edit-ticket-TKT_start_date-<?php echo $tkt_row; ?>"  name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp" value="<?php echo $TKT_start_date; ?>" >
8 8
 			<input type="text" name="archived_ticket[TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp" value="<?php echo $TKT_start_date; ?>" disabled>
9
-		<?php else : ?>
10
-			<input id="edit-ticket-TKT_start_date-<?php echo $tkt_row; ?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp ee-datepicker" value="<?php echo $TKT_start_date; ?>" data-context="start-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_end_date" data-next-field=".edit-ticket-TKT_end_date">
9
+		<?php else {
10
+	: ?>
11
+			<input id="edit-ticket-TKT_start_date-<?php echo $tkt_row;
12
+}
13
+?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp ee-datepicker" value="<?php echo $TKT_start_date; ?>" data-context="start-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_end_date" data-next-field=".edit-ticket-TKT_end_date">
11 14
 		<?php endif; ?>
12 15
 	</td>
13 16
 	<td>
14 17
 		<?php if ( $disabled ) : ?>
15 18
 			<input type="hidden" id="edit-ticket-TKT_end_date-<?php echo $tkt_row; ?>"  name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp" value="<?php echo $TKT_end_date; ?>" >
16 19
 			<input type="text" name="archived_ticket[TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp" value="<?php echo $TKT_end_date; ?>" disabled>
17
-		<?php else : ?>
18
-			<input id="edit-ticket-TKT_end_date-<?php echo $tkt_row; ?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp ee-datepicker" value="<?php echo $TKT_end_date; ?>" data-context="end-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_start_date" data-next-field=".edit-ticket-TKT_qty">
20
+		<?php else {
21
+	: ?>
22
+			<input id="edit-ticket-TKT_end_date-<?php echo $tkt_row;
23
+}
24
+?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp ee-datepicker" value="<?php echo $TKT_end_date; ?>" data-context="end-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_start_date" data-next-field=".edit-ticket-TKT_qty">
19 25
 		<?php endif; ?>
20 26
 	</td>
21 27
 	<td>
22 28
 		<?php if ( $disabled ) : ?>
23 29
 			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row; ?>" type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
24 30
 			<input type="text" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>" disabled>
25
-		<?php else : ?>
26
-			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row; ?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
31
+		<?php else {
32
+	: ?>
33
+			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row;
34
+}
35
+?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
27 36
 		<?php endif; ?>
28 37
 		<input type="hidden" id="edit-ticket-TKT_base_price_ID-<?php echo $tkt_row; ?>" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price_ID]" value="<?php echo $TKT_base_price_ID; ?>">
29 38
 	</td>
@@ -31,8 +40,11 @@  discard block
 block discarded – undo
31 40
 		<?php if ( $disabled ) : ?>
32 41
 			<input type="hidden" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
33 42
 			<input type="text" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>" disabled>
34
-		<?php else : ?>
35
-			<input type="text" id="edit-ticket-TKT_qty-<?php echo $tkt_row; ?>"class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
43
+		<?php else {
44
+	: ?>
45
+			<input type="text" id="edit-ticket-TKT_qty-<?php echo $tkt_row;
46
+}
47
+?>"class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
36 48
 		<?php endif; ?>
37 49
 	</td>
38 50
 	<!--<td><span class="ticket-display-row-TKT_price"><?php //echo $TKT_price; ?></span></td>-->
@@ -79,24 +91,33 @@  discard block
 block discarded – undo
79 91
 								<?php if ( $disabled ) : ?>
80 92
 									<input type="hidden" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
81 93
 									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>" disabled>
82
-								<?php else : ?>
83
-									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
94
+								<?php else {
95
+	: ?>
96
+									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name;
97
+}
98
+?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
84 99
 								<?php endif; ?>
85 100
 							</td>
86 101
 							<td>
87 102
 								<?php if ( $disabled ) : ?>
88 103
 									<input type="hidden" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
89 104
 									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>" disabled>
90
-								<?php else: ?>
91
-									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
105
+								<?php else {
106
+	: ?>
107
+									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name;
108
+}
109
+?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
92 110
 								<?php endif; ?>
93 111
 							</td>
94 112
 							<td>
95 113
 								<?php if ( $disabled ) : ?>
96 114
 									<input type="hidden" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
97 115
 									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>" disabled>
98
-								<?php else : ?>
99
-									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
116
+								<?php else {
117
+	: ?>
118
+									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name;
119
+}
120
+?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
100 121
 								<?php endif; ?>
101 122
 							</td>
102 123
 						</tr>
@@ -117,8 +138,11 @@  discard block
 block discarded – undo
117 138
 							?>
118 139
 							<input class="TKT-taxable-checkbox" type="hidden" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="<?php echo $tax_value; ?>">
119 140
 							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?> disabled>
120
-						<?php else : ?>
121
-							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?>>
141
+						<?php else {
142
+	: ?>
143
+							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row;
144
+}
145
+?>" type="checkbox" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?>>
122 146
 						<?php endif; ?>
123 147
 						<label for="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>"> <?php esc_html_e('This ticket is taxable.', 'event_espresso'); ?>
124 148
 					<?php } //end tax_rows check ?>
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1
-    <tr valign="top" class="ee-ticket-sortable ticket-row<?php echo $ticket_archive_class; if(WP_DEBUG){ echo ' ee-wp-debug'; } ?>" id="display-ticketrow-<?php echo $tkt_row; ?>">
1
+    <tr valign="top" class="ee-ticket-sortable ticket-row<?php echo $ticket_archive_class; if (WP_DEBUG) { echo ' ee-wp-debug'; } ?>" id="display-ticketrow-<?php echo $tkt_row; ?>">
2 2
 	<!--<td class="ee-tkt-order-field"><span class="dashicons dashicons-sort<?php echo $tkt_status_class; ?>"><input type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_order]" class="edit-ticket-TKT_order" value ="<?php echo $TKT_order; ?>" ></span></td>-->
3 3
 	<td class="ee-tkt-order-field"><span class="ee-status-strip-td ee-status-strip<?php echo $tkt_status_class; ?>"></span><input type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_order]" class="edit-ticket-TKT_order" value ="<?php echo $TKT_order; ?>"></td>
4 4
 	<td><input maxlength="245" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_name]" class="edit-ticket-TKT_name ee-large-text-inp" placeholder="Ticket Title" value="<?php echo $TKT_name; ?>"></td>
5 5
 	<td>
6
-		<?php if ( $disabled ) : ?>
6
+		<?php if ($disabled) : ?>
7 7
 			<input type="hidden" id="edit-ticket-TKT_start_date-<?php echo $tkt_row; ?>"  name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp" value="<?php echo $TKT_start_date; ?>" >
8 8
 			<input type="text" name="archived_ticket[TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp" value="<?php echo $TKT_start_date; ?>" disabled>
9 9
 		<?php else : ?>
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 		<?php endif; ?>
12 12
 	</td>
13 13
 	<td>
14
-		<?php if ( $disabled ) : ?>
14
+		<?php if ($disabled) : ?>
15 15
 			<input type="hidden" id="edit-ticket-TKT_end_date-<?php echo $tkt_row; ?>"  name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp" value="<?php echo $TKT_end_date; ?>" >
16 16
 			<input type="text" name="archived_ticket[TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp" value="<?php echo $TKT_end_date; ?>" disabled>
17 17
 		<?php else : ?>
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 		<?php endif; ?>
20 20
 	</td>
21 21
 	<td>
22
-		<?php if ( $disabled ) : ?>
22
+		<?php if ($disabled) : ?>
23 23
 			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row; ?>" type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
24 24
 			<input type="text" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>" disabled>
25 25
 		<?php else : ?>
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		<input type="hidden" id="edit-ticket-TKT_base_price_ID-<?php echo $tkt_row; ?>" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price_ID]" value="<?php echo $TKT_base_price_ID; ?>">
29 29
 	</td>
30 30
 	<td>
31
-		<?php if ( $disabled ) : ?>
31
+		<?php if ($disabled) : ?>
32 32
 			<input type="hidden" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
33 33
 			<input type="text" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>" disabled>
34 34
 		<?php else : ?>
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 			<input type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_ID]" class="edit-ticket-TKT_ID" value="<?php echo $TKT_ID; ?>">
57 57
 			<input type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_row]" class="edit-ticket-TKT_row" value="<?php echo $tkt_row; ?>">
58 58
 
59
-			<!--<div class="total-price-container"><?php printf( esc_html__('Total Final Price: %s', 'event_espresso'), '<span class="ticket-price-amount">' . $TKT_price . '</span>'); ?> </div>-->
59
+			<!--<div class="total-price-container"><?php printf(esc_html__('Total Final Price: %s', 'event_espresso'), '<span class="ticket-price-amount">'.$TKT_price.'</span>'); ?> </div>-->
60 60
 			<textarea name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_description]" class="edit-ticket-TKT_description ee-full-textarea-inp" placeholder="Ticket Description"><?php echo $TKT_description; ?></textarea>
61 61
 
62
-			<?php do_action( 'AHEE__event_tickets_datetime_ticket_row_template_after_desc', $tkt_row, $TKT_ID ); ?>
62
+			<?php do_action('AHEE__event_tickets_datetime_ticket_row_template_after_desc', $tkt_row, $TKT_ID); ?>
63 63
 
64 64
 			<div class="basic-ticket-container">
65 65
 				<h4 class="tickets-heading"><?php esc_html_e('Ticket Details', 'event_espresso'); ?></h4>
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 					<tbody>
76 76
 						<tr>
77 77
 							<td>
78
-								<?php if ( $disabled ) : ?>
78
+								<?php if ($disabled) : ?>
79 79
 									<input type="hidden" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
80 80
 									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>" disabled>
81 81
 								<?php else : ?>
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 								<?php endif; ?>
84 84
 							</td>
85 85
 							<td>
86
-								<?php if ( $disabled ) : ?>
86
+								<?php if ($disabled) : ?>
87 87
 									<input type="hidden" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
88 88
 									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>" disabled>
89 89
 								<?php else: ?>
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 								<?php endif; ?>
92 92
 							</td>
93 93
 							<td>
94
-								<?php if ( $disabled ) : ?>
94
+								<?php if ($disabled) : ?>
95 95
 									<input type="hidden" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
96 96
 									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>" disabled>
97 97
 								<?php else : ?>
@@ -109,15 +109,15 @@  discard block
 block discarded – undo
109 109
 					<label for="edit-ticket-TKT_required"><?php esc_html_e('This ticket is required (will appear first in frontend ticket lists).', 'event_espresso'); ?></label>
110 110
 				</div>
111 111
 				<div class="ticket-is-taxable-container">
112
-					<?php if ( !empty($tax_rows) ) { ?>
113
-						<?php if ( $disabled ) : ?>
112
+					<?php if ( ! empty($tax_rows)) { ?>
113
+						<?php if ($disabled) : ?>
114 114
 							<?php
115
-								$tax_value = !empty( $TKT_taxable ) ? 1 : 0;
115
+								$tax_value = ! empty($TKT_taxable) ? 1 : 0;
116 116
 							?>
117
-							<input class="TKT-taxable-checkbox" type="hidden" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="<?php echo $tax_value; ?>">
117
+							<input class="TKT-taxable-checkbox" type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="<?php echo $tax_value; ?>">
118 118
 							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?> disabled>
119 119
 						<?php else : ?>
120
-							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?>>
120
+							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?>>
121 121
 						<?php endif; ?>
122 122
 						<label for="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>"> <?php esc_html_e('This ticket is taxable.', 'event_espresso'); ?>
123 123
 					<?php } //end tax_rows check ?>
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 				<?php echo $ticket_datetimes_list; ?>
175 175
 			</ul>
176 176
 
177
-			<?php do_action( 'AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', $tkt_row, $TKT_ID ); ?>
177
+			<?php do_action('AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', $tkt_row, $TKT_ID); ?>
178 178
 			<div class="ee-editor-footer-container">
179 179
 				<div class="ee-editor-id-container">
180
-					<span class="ee-item-id"><?php echo $TKT_ID ? sprintf( esc_html__( 'Ticket ID: %d', 'event_espresso' ), $TKT_ID ) : ''; ?></span>
180
+					<span class="ee-item-id"><?php echo $TKT_ID ? sprintf(esc_html__('Ticket ID: %d', 'event_espresso'), $TKT_ID) : ''; ?></span>
181 181
 				</div>
182 182
 				<div class="save-cancel-button-container">
183 183
 					<label for="edit-ticket-TKT_is_default_selector"><?php esc_html_e('use this new ticket as a default ticket for any new events', 'event_espresso'); ?></label>
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 patch
Indentation   +1530 added lines, -1530 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -31,1535 +31,1535 @@  discard block
 block discarded – undo
31 31
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
32 32
 {
33 33
 
34
-    /**
35
-     * This property is just used to hold the status of whether an event is currently being
36
-     * created (true) or edited (false)
37
-     * @access protected
38
-     * @var bool
39
-     */
40
-    protected $_is_creating_event;
41
-
42
-
43
-    /**
44
-     * Used to contain the format strings for date and time that will be used for php date and
45
-     * time.
46
-     *
47
-     * Is set in the _set_hooks_properties() method.
48
-     *
49
-     * @var array
50
-     */
51
-    protected $_date_format_strings;
52
-
53
-
54
-    protected function _set_hooks_properties()
55
-    {
56
-        $this->_name = 'pricing';
57
-
58
-        //capability check
59
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices',
60
-            'advanced_ticket_datetime_metabox')
61
-        ) {
62
-            return;
63
-        }
64
-
65
-
66
-        //if we were going to add our own metaboxes we'd use the below.
67
-        $this->_metaboxes = array(
68
-            0 => array(
69
-                'page_route' => array('edit', 'create_new'),
70
-                'func'       => 'pricing_metabox',
71
-                'label'      => __('Event Tickets & Datetimes', 'event_espresso'),
72
-                'priority'   => 'high',
73
-                'context'    => 'normal'
74
-            ),
75
-
76
-        );/**/
77
-
78
-        $this->_remove_metaboxes = array(
79
-            0 => array(
80
-                'page_route' => array('edit', 'create_new'),
81
-                'id'         => 'espresso_event_editor_tickets',
82
-                'context'    => 'normal'
83
-            )
84
-        );
85
-
86
-        /**
87
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
88
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
89
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
90
-         *
91
-         * @since 4.6.7
92
-         *
93
-         * @var array  Expected an array returned with 'date' and 'time' keys.
94
-         */
95
-        $this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
96
-            array(
97
-                'date' => 'Y-m-d',
98
-                'time' => 'h:i a'
99
-            ));
100
-
101
-        //validate
102
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null;
103
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null;
104
-
105
-        //validate format strings
106
-        $format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
107
-        if (is_array($format_validation)) {
108
-            $msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:',
109
-                    'event_espresso'),
110
-                    $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>';
111
-            foreach ($format_validation as $error) {
112
-                $msg .= '<li>' . $error . '</li>';
113
-            }
114
-            $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
115
-                    'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>';
116
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
117
-            $this->_date_format_strings = array(
118
-                'date' => 'Y-m-d',
119
-                'time' => 'h:i a'
120
-            );
121
-        }
122
-
123
-
124
-        $this->_scripts_styles = array(
125
-            'registers'   => array(
126
-                'ee-tickets-datetimes-css' => array(
127
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
128
-                    'type' => 'css'
129
-                ),
130
-                'ee-dtt-ticket-metabox'    => array(
131
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
132
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore')
133
-                )
134
-            ),
135
-            'deregisters' => array(
136
-                'event-editor-css'       => array('type' => 'css'),
137
-                'event-datetime-metabox' => array('type' => 'js')
138
-            ),
139
-            'enqueues'    => array(
140
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
141
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new')
142
-            ),
143
-            'localize'    => array(
144
-                'ee-dtt-ticket-metabox' => array(
145
-                    'DTT_TRASH_BLOCK'       => array(
146
-                        'main_warning'            => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
147
-                            'event_espresso'),
148
-                        'after_warning'           => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
149
-                            'event_espresso'),
150
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">' . __('Cancel',
151
-                                'event_espresso') . '</button>',
152
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">' . __('Close',
153
-                                'event_espresso') . '</button>',
154
-                        'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
155
-                            'event_espresso'),
156
-                        'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
157
-                            'event_espresso'),
158
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss',
159
-                                'event_espresso') . '</button>'
160
-                    ),
161
-                    'DTT_ERROR_MSG'         => array(
162
-                        'no_ticket_name' => __('General Admission', 'event_espresso'),
163
-                        'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss',
164
-                                'event_espresso') . '</button></div>'
165
-                    ),
166
-                    'DTT_OVERSELL_WARNING'  => array(
167
-                        'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
168
-                            'event_espresso'),
169
-                        'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
170
-                            'event_espresso')
171
-                    ),
172
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'],
173
-                        $this->_date_format_strings['time']),
174
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int)get_option('start_of_week'))
175
-                )
176
-            )
177
-        );
178
-
179
-
180
-        add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
181
-            array($this, 'autosave_handling'), 10);
182
-        add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
183
-            array($this, 'caf_updates'), 10);
184
-    }
185
-
186
-
187
-    public function caf_updates($update_callbacks)
188
-    {
189
-        foreach ($update_callbacks as $key => $callback) {
190
-            if ($callback[1] == '_default_tickets_update') {
191
-                unset($update_callbacks[$key]);
192
-            }
193
-        }
194
-
195
-        $update_callbacks[] = array($this, 'dtt_and_tickets_caf_update');
196
-
197
-        return $update_callbacks;
198
-    }
199
-
200
-
201
-    /**
202
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
203
-     *
204
-     * @param  EE_Event $evtobj The Event object we're attaching data to
205
-     * @param  array    $data   The request data from the form
206
-     *
207
-     * @return bool             success or fail
208
-     */
209
-    public function dtt_and_tickets_caf_update($evtobj, $data)
210
-    {
211
-        //first we need to start with datetimes cause they are the "root" items attached to events.
212
-        $saved_dtts = $this->_update_dtts($evtobj, $data);
213
-        //next tackle the tickets (and prices?)
214
-        $this->_update_tkts($evtobj, $saved_dtts, $data);
215
-    }
216
-
217
-
218
-    /**
219
-     * update event_datetimes
220
-     *
221
-     * @param  EE_Event $evt_obj Event being updated
222
-     * @param  array    $data    the request data from the form
223
-     *
224
-     * @return EE_Datetime[]
225
-     */
226
-    protected function _update_dtts($evt_obj, $data)
227
-    {
228
-        $timezone       = isset($data['timezone_string']) ? $data['timezone_string'] : null;
229
-        $saved_dtt_ids  = array();
230
-        $saved_dtt_objs = array();
231
-
232
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
233
-            //trim all values to ensure any excess whitespace is removed.
234
-            $dtt                = array_map(
235
-                function ($datetime_data) {
236
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
237
-                },
238
-                $dtt
239
-            );
240
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start'];
241
-            $datetime_values    = array(
242
-                'DTT_ID'          => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
243
-                'DTT_name'        => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '',
244
-                'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '',
245
-                'DTT_EVT_start'   => $dtt['DTT_EVT_start'],
246
-                'DTT_EVT_end'     => $dtt['DTT_EVT_end'],
247
-                'DTT_reg_limit'   => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
248
-                'DTT_order'       => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'],
249
-            );
250
-
251
-            //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.
252
-
253
-            if ( ! empty($dtt['DTT_ID'])) {
254
-                $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']);
255
-
256
-                //set date and time format according to what is set in this class.
257
-                $DTM->set_date_format($this->_date_format_strings['date']);
258
-                $DTM->set_time_format($this->_date_format_strings['time']);
259
-
260
-                foreach ($datetime_values as $field => $value) {
261
-                    $DTM->set($field, $value);
262
-                }
263
-
264
-                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.
265
-                // We need to do this so we dont' TRASH the parent DTT.(save the ID for both key and value to avoid duplications)
266
-                $saved_dtt_ids[$DTM->ID()] = $DTM->ID();
267
-
268
-            } else {
269
-                $DTM = EE_Registry::instance()->load_class(
270
-                    'Datetime',
271
-                    array(
272
-                        $datetime_values,
273
-                        $timezone,
274
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
275
-                    ),
276
-                    false,
277
-                    false
278
-                );
279
-
280
-                foreach ($datetime_values as $field => $value) {
281
-                    $DTM->set($field, $value);
282
-                }
283
-            }
284
-
285
-
286
-            $DTM->save();
287
-            $DTM = $evt_obj->_add_relation_to($DTM, 'Datetime');
288
-            $evt_obj->save();
289
-
290
-            //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.
291
-            if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) {
292
-                $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start'));
293
-                $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days');
294
-                $DTM->save();
295
-            }
296
-
297
-            //	now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
298
-            // because it is possible there was a new one created for the autosave.
299
-            // (save the ID for both key and value to avoid duplications)
300
-            $saved_dtt_ids[$DTM->ID()] = $DTM->ID();
301
-            $saved_dtt_objs[$row]      = $DTM;
302
-
303
-            //todo if ANY of these updates fail then we want the appropriate global error message.
304
-        }
305
-
306
-        //now we need to REMOVE any dtts that got deleted.  Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point.
307
-        $old_datetimes = explode(',', $data['datetime_IDs']);
308
-        $old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes;
309
-
310
-        if (is_array($old_datetimes)) {
311
-            $dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
312
-            foreach ($dtts_to_delete as $id) {
313
-                $id = absint($id);
314
-                if (empty($id)) {
315
-                    continue;
316
-                }
317
-
318
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
319
-
320
-                //remove tkt relationships.
321
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
322
-                foreach ($related_tickets as $tkt) {
323
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
324
-                }
325
-
326
-                $evt_obj->_remove_relation_to($id, 'Datetime');
327
-                $dtt_to_remove->refresh_cache_of_related_objects();
328
-
329
-            }
330
-        }
331
-
332
-        return $saved_dtt_objs;
333
-    }
334
-
335
-
336
-    /**
337
-     * update tickets
338
-     *
339
-     * @param  EE_Event      $evtobj     Event object being updated
340
-     * @param  EE_Datetime[] $saved_dtts an array of datetime ids being updated
341
-     * @param  array         $data       incoming request data
342
-     *
343
-     * @return EE_Ticket[]
344
-     */
345
-    protected function _update_tkts($evtobj, $saved_dtts, $data)
346
-    {
347
-
348
-        $new_tkt     = null;
349
-        $new_default = null;
350
-        //stripslashes because WP filtered the $_POST ($data) array to add slashes
351
-        $data          = stripslashes_deep($data);
352
-        $timezone      = isset($data['timezone_string']) ? $data['timezone_string'] : null;
353
-        $saved_tickets = $dtts_on_existing = array();
354
-        $old_tickets   = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
355
-
356
-        //load money helper
357
-
358
-        foreach ($data['edit_tickets'] as $row => $tkt) {
359
-
360
-            $update_prices = $create_new_TKT = false;
361
-
362
-            //figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session.
363
-
364
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
365
-            $tkt_dtt_rows          = explode(',', $data['ticket_datetime_rows'][$row]);
366
-            $dtts_added            = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
367
-            $dtts_removed          = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
368
-
369
-            // trim inputs to ensure any excess whitespace is removed.
370
-            $tkt = array_map(
371
-                function ($ticket_data) {
372
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
373
-                },
374
-                $tkt
375
-            );
376
-
377
-            //note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models.
378
-            //note incoming ['TKT_price'] value is already in standard notation (via js).
379
-            $ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0;
380
-
381
-            //note incoming base price needs converted from localized value.
382
-            $base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0;
383
-            //if ticket price == 0 and $base_price != 0 then ticket price == base_price
384
-            $ticket_price  = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price;
385
-            $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0;
386
-
387
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array();
388
-
389
-            $now = null;
390
-            if (empty($tkt['TKT_start_date'])) {
391
-                //lets' use now in the set timezone.
392
-                $now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
393
-                $tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
394
-            }
395
-
396
-            if (empty($tkt['TKT_end_date'])) {
397
-                /**
398
-                 * set the TKT_end_date to the first datetime attached to the ticket.
399
-                 */
400
-                $first_dtt           = $saved_dtts[reset($tkt_dtt_rows)];
401
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']);
402
-            }
403
-
404
-            $TKT_values = array(
405
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
406
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
407
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
408
-                'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description',
409
-                    'event_espresso') ? $tkt['TKT_description'] : '',
410
-                'TKT_start_date'  => $tkt['TKT_start_date'],
411
-                'TKT_end_date'    => $tkt['TKT_end_date'],
412
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
413
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
414
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
415
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
416
-                'TKT_row'         => $row,
417
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
418
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
419
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
420
-                'TKT_price'       => $ticket_price
421
-            );
422
-
423
-
424
-            //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.
425
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
426
-                $TKT_values['TKT_ID']         = 0;
427
-                $TKT_values['TKT_is_default'] = 0;
428
-                $update_prices                = true;
429
-            }
430
-
431
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
432
-            // we actually do our saves ahead of doing any add_relations to
433
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
434
-            // but DID have it's items modified.
435
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
436
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
437
-            if (absint($TKT_values['TKT_ID'])) {
438
-                $TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']);
439
-                if ($TKT instanceof EE_Ticket) {
440
-
441
-                    $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
442
-                    // are there any registrations using this ticket ?
443
-                    $tickets_sold = $TKT->count_related(
444
-                        'Registration',
445
-                        array(
446
-                            array(
447
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete))
448
-                            )
449
-                        )
450
-                    );
451
-                    //set ticket formats
452
-                    $TKT->set_date_format($this->_date_format_strings['date']);
453
-                    $TKT->set_time_format($this->_date_format_strings['time']);
454
-
455
-                    // let's just check the total price for the existing ticket
456
-                    // and determine if it matches the new total price.
457
-                    // if they are different then we create a new ticket (if tkts sold)
458
-                    // if they aren't different then we go ahead and modify existing ticket.
459
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price != $TKT->price() && ! $TKT->deleted()
460
-                        ? true : false;
461
-
462
-                    //set new values
463
-                    foreach ($TKT_values as $field => $value) {
464
-                        if ($field === 'TKT_qty') {
465
-                            $TKT->set_qty($value);
466
-                        } else {
467
-                            $TKT->set($field, $value);
468
-                        }
469
-                    }
470
-
471
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
472
-                    if ($create_new_TKT) {
473
-                        $new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price,
474
-                            $base_price_id);
475
-                    }
476
-                }
477
-
478
-            } else {
479
-                // no TKT_id so a new TKT
480
-                $TKT = EE_Ticket::new_instance(
481
-                    $TKT_values,
482
-                    $timezone,
483
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
484
-                );
485
-                if ($TKT instanceof EE_Ticket) {
486
-                    // make sure ticket has an ID of setting relations won't work
487
-                    $TKT->save();
488
-                    $TKT           = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
489
-                    $update_prices = true;
490
-                }
491
-            }
492
-            //make sure any current values have been saved.
493
-            //$TKT->save();
494
-
495
-            //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.
496
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
497
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
498
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
499
-            }
500
-
501
-            //let's make sure the base price is handled
502
-            $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price,
503
-                $base_price_id) : $TKT;
504
-
505
-            //add/update price_modifiers
506
-            $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT;
507
-
508
-            //need to make sue that the TKT_price is accurate after saving the prices.
509
-            $TKT->ensure_TKT_Price_correct();
510
-
511
-            //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
512
-            if ( ! defined('DOING_AUTOSAVE')) {
513
-                if ( ! empty($tkt['TKT_is_default_selector'])) {
514
-                    $update_prices = true;
515
-                    $new_default   = clone $TKT;
516
-                    $new_default->set('TKT_ID', 0);
517
-                    $new_default->set('TKT_is_default', 1);
518
-                    $new_default->set('TKT_row', 1);
519
-                    $new_default->set('TKT_price', $ticket_price);
520
-                    //remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object)
521
-                    $new_default->_remove_relations('Datetime');
522
-                    //todo we need to add the current attached prices as new prices to the new default ticket.
523
-                    $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices);
524
-                    //don't forget the base price!
525
-                    $new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price,
526
-                        $base_price_id);
527
-                    $new_default->save();
528
-                    do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default,
529
-                        $row, $TKT, $data);
530
-                }
531
-            }
532
-
533
-
534
-            //DO ALL dtt relationships for both current tickets and any archived tickets for the given dtt that are related to the current ticket. TODO... not sure exactly how we're going to do this considering we don't know what current ticket the archived tickets are related to (and TKT_parent is used for autosaves so that's not a field we can reliably use).
535
-
536
-
537
-            //let's assign any tickets that have been setup to the saved_tickets tracker
538
-            //save existing TKT
539
-            $TKT->save();
540
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
541
-                //save new TKT
542
-                $new_tkt->save();
543
-                //add new ticket to array
544
-                $saved_tickets[$new_tkt->ID()] = $new_tkt;
545
-
546
-                do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data);
547
-
548
-            } else {
549
-                //add tkt to saved tkts
550
-                $saved_tickets[$TKT->ID()] = $TKT;
551
-
552
-                do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data);
553
-            }
554
-
555
-        }
556
-
557
-        // now we need to handle tickets actually "deleted permanently".
558
-        // There are cases where we'd want this to happen
559
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
560
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
561
-        // No sense in keeping all the related data in the db!
562
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
563
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
564
-
565
-        foreach ($tickets_removed as $id) {
566
-            $id = absint($id);
567
-
568
-            //get the ticket for this id
569
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
570
-
571
-            //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
572
-            if ($tkt_to_remove->get('TKT_is_default')) {
573
-                continue;
574
-            }
575
-
576
-            // if this tkt has any registrations attached so then we just ARCHIVE
577
-            // because we don't actually permanently delete these tickets.
578
-            if ($tkt_to_remove->count_related('Registration') > 0) {
579
-                $tkt_to_remove->delete();
580
-                continue;
581
-            }
582
-
583
-            // need to get all the related datetimes on this ticket and remove from every single one of them
584
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
585
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
586
-
587
-            foreach ($dtts as $dtt) {
588
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
589
-            }
590
-
591
-            // need to do the same for prices (except these prices can also be deleted because again,
592
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
593
-            $tkt_to_remove->delete_related_permanently('Price');
594
-
595
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
596
-
597
-            // finally let's delete this ticket
598
-            // (which should not be blocked at this point b/c we've removed all our relationships)
599
-            $tkt_to_remove->delete_permanently();
600
-        }
601
-
602
-        return $saved_tickets;
603
-    }
604
-
605
-
606
-    /**
607
-     *
608
-     * @access  protected
609
-     *
610
-     * @param \EE_Ticket     $ticket
611
-     * @param \EE_Datetime[] $saved_datetimes
612
-     * @param \EE_Datetime[] $added_datetimes
613
-     * @param \EE_Datetime[] $removed_datetimes
614
-     *
615
-     * @return \EE_Ticket
616
-     * @throws \EE_Error
617
-     */
618
-    protected function _update_ticket_datetimes(
619
-        EE_Ticket $ticket,
620
-        $saved_datetimes = array(),
621
-        $added_datetimes = array(),
622
-        $removed_datetimes = array()
623
-    ) {
624
-
625
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
626
-        // and removing the ticket from datetimes it got removed from.
627
-
628
-        // first let's add datetimes
629
-        if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
630
-            foreach ($added_datetimes as $row_id) {
631
-                $row_id = (int)$row_id;
632
-                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
633
-                    $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
634
-                    // Is this an existing ticket (has an ID) and does it have any sold?
635
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
636
-                    if ($ticket->ID() && $ticket->sold() > 0) {
637
-                        $saved_datetimes[$row_id]->increase_sold($ticket->sold());
638
-                        $saved_datetimes[$row_id]->save();
639
-                    }
640
-                }
641
-            }
642
-        }
643
-        // then remove datetimes
644
-        if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
645
-            foreach ($removed_datetimes as $row_id) {
646
-                $row_id = (int)$row_id;
647
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
648
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
649
-                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
650
-                    $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
651
-                    // Is this an existing ticket (has an ID) and does it have any sold?
652
-                    // If so, then we need to remove it's sold from the DTT_sold.
653
-                    if ($ticket->ID() && $ticket->sold() > 0) {
654
-                        $saved_datetimes[$row_id]->decrease_sold($ticket->sold());
655
-                        $saved_datetimes[$row_id]->save();
656
-                    }
657
-                }
658
-            }
659
-        }
660
-        // cap ticket qty by datetime reg limits
661
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
662
-
663
-        return $ticket;
664
-    }
665
-
666
-
667
-    /**
668
-     *
669
-     * @access  protected
670
-     *
671
-     * @param \EE_Ticket $ticket
672
-     * @param array      $price_rows
673
-     * @param int        $ticket_price
674
-     * @param int        $base_price
675
-     * @param int        $base_price_id
676
-     *
677
-     * @return \EE_Ticket
678
-     * @throws \EE_Error
679
-     */
680
-    protected function _duplicate_ticket(
681
-        EE_Ticket $ticket,
682
-        $price_rows = array(),
683
-        $ticket_price = 0,
684
-        $base_price = 0,
685
-        $base_price_id = 0
686
-    ) {
687
-
688
-        // create new ticket that's a copy of the existing
689
-        // except a new id of course (and not archived)
690
-        // AND has the new TKT_price associated with it.
691
-        $new_ticket = clone $ticket;
692
-        $new_ticket->set('TKT_ID', 0);
693
-        $new_ticket->set('TKT_deleted', 0);
694
-        $new_ticket->set('TKT_price', $ticket_price);
695
-        $new_ticket->set('TKT_sold', 0);
696
-        // let's get a new ID for this ticket
697
-        $new_ticket->save();
698
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
699
-        $datetimes_on_existing = $ticket->get_many_related('Datetime');
700
-        $new_ticket            = $this->_update_ticket_datetimes(
701
-            $new_ticket,
702
-            $datetimes_on_existing,
703
-            array_keys($datetimes_on_existing)
704
-        );
705
-
706
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
707
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
708
-        // available.
709
-        if ($ticket->sold() > 0) {
710
-            $new_qty = $ticket->qty() - $ticket->sold();
711
-            $new_ticket->set_qty($new_qty);
712
-        }
713
-        //now we update the prices just for this ticket
714
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
715
-        //and we update the base price
716
-        $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id);
717
-
718
-        return $new_ticket;
719
-    }
720
-
721
-
722
-    /**
723
-     * This attaches a list of given prices to a ticket.
724
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
725
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
726
-     * price info and prices are automatically "archived" via the ticket.
727
-     *
728
-     * @access  private
729
-     *
730
-     * @param array     $prices        Array of prices from the form.
731
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
732
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
733
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
734
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
735
-     *
736
-     * @return EE_Ticket
737
-     */
738
-    protected function _add_prices_to_ticket(
739
-        $prices = array(),
740
-        EE_Ticket $ticket,
741
-        $new_prices = false,
742
-        $base_price = false,
743
-        $base_price_id = false
744
-    ) {
745
-
746
-        //let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session.
747
-        $current_prices_on_ticket = $base_price !== false ? $ticket->base_price(true) : $ticket->price_modifiers();
748
-
749
-        $updated_prices = array();
750
-
751
-        // if $base_price ! FALSE then updating a base price.
752
-        if ($base_price !== false) {
753
-            $prices[1] = array(
754
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
755
-                'PRT_ID'     => 1,
756
-                'PRC_amount' => $base_price,
757
-                'PRC_name'   => $ticket->get('TKT_name'),
758
-                'PRC_desc'   => $ticket->get('TKT_description')
759
-            );
760
-        }
761
-
762
-        //possibly need to save tkt
763
-        if ( ! $ticket->ID()) {
764
-            $ticket->save();
765
-        }
766
-
767
-        foreach ($prices as $row => $prc) {
768
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
769
-            if (empty($prt_id)) {
770
-                continue;
771
-            } //prices MUST have a price type id.
772
-            $PRC_values = array(
773
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
774
-                'PRT_ID'         => $prt_id,
775
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
776
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
777
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
778
-                'PRC_is_default' => false,
779
-                //make sure we set PRC_is_default to false for all ticket saves from event_editor
780
-                'PRC_order'      => $row
781
-            );
782
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
783
-                $PRC_values['PRC_ID'] = 0;
784
-                $PRC                  = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
785
-            } else {
786
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
787
-                //update this price with new values
788
-                foreach ($PRC_values as $field => $newprc) {
789
-                    $PRC->set($field, $newprc);
790
-                }
791
-            }
792
-            $PRC->save();
793
-            $prcid                  = $PRC->ID();
794
-            $updated_prices[$prcid] = $PRC;
795
-            $ticket->_add_relation_to($PRC, 'Price');
796
-        }
797
-
798
-        //now let's remove any prices that got removed from the ticket
799
-        if ( ! empty ($current_prices_on_ticket)) {
800
-            $current          = array_keys($current_prices_on_ticket);
801
-            $updated          = array_keys($updated_prices);
802
-            $prices_to_remove = array_diff($current, $updated);
803
-            if ( ! empty($prices_to_remove)) {
804
-                foreach ($prices_to_remove as $prc_id) {
805
-                    $p = $current_prices_on_ticket[$prc_id];
806
-                    $ticket->_remove_relation_to($p, 'Price');
807
-
808
-                    //delete permanently the price
809
-                    $p->delete_permanently();
810
-                }
811
-            }
812
-        }
813
-
814
-        return $ticket;
815
-    }
816
-
817
-
818
-    public function autosave_handling($event_admin_obj)
819
-    {
820
-        return $event_admin_obj; //doing nothing for the moment.
821
-        //todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method)
822
-
823
-        /**
824
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
825
-         *
826
-         * 1. TKT_is_default_selector (visible)
827
-         * 2. TKT_is_default (hidden)
828
-         *
829
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want this ticket to be saved as a default.
830
-         *
831
-         * The tricky part is, on an initial display on create or edit (or after manually updating), the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true if this is a create.  However, after an autosave, users will want some sort of indicator that the TKT HAS been saved as a default.. in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
832
-         * On Autosave:
833
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, then set the TKT_is_default to false.
834
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
835
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
836
-         */
837
-    }
838
-
839
-
840
-    public function pricing_metabox()
841
-    {
842
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
843
-
844
-        $evtobj = $this->_adminpage_obj->get_cpt_model_obj();
845
-
846
-        //set is_creating_event property.
847
-        $evtID                    = $evtobj->ID();
848
-        $this->_is_creating_event = absint($evtID) != 0 ? false : true;
849
-
850
-        //default main template args
851
-        $main_template_args = array(
852
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab',
853
-                $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
854
-            //todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help
855
-            'existing_datetime_ids'    => '',
856
-            'total_dtt_rows'           => 1,
857
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link('add_new_dtt_info',
858
-                $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
859
-            //todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
860
-            'datetime_rows'            => '',
861
-            'show_tickets_container'   => '',
862
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
863
-            'ticket_rows'              => '',
864
-            'existing_ticket_ids'      => '',
865
-            'total_ticket_rows'        => 1,
866
-            'ticket_js_structure'      => '',
867
-            'ee_collapsible_status'    => ' ee-collapsible-open'
868
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
869
-        );
870
-
871
-        $timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : null;
872
-
873
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
874
-
875
-        /**
876
-         * 1. Start with retrieving Datetimes
877
-         * 2. For each datetime get related tickets
878
-         * 3. For each ticket get related prices
879
-         */
880
-
881
-        $DTM   = EE_Registry::instance()->load_model('Datetime', array($timezone));
882
-        $times = $DTM->get_all_event_dates($evtID);
883
-
884
-
885
-        $main_template_args['total_dtt_rows'] = count($times);
886
-
887
-        /** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */
888
-        $dttrow = 1;
889
-        foreach ($times as $time) {
890
-            $dttid = $time->get('DTT_ID');
891
-            $time->set('DTT_order', $dttrow);
892
-            $existing_datetime_ids[] = $dttid;
893
-
894
-            //tickets attached
895
-            $related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array(
896
-                array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
897
-                'default_where_conditions' => 'none',
898
-                'order_by'                 => array('TKT_order' => 'ASC')
899
-            )) : array();
900
-
901
-            //if there are no related tickets this is likely a new event OR autodraft
902
-            // event so we need to generate the default tickets because dtts
903
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
904
-            // datetime on the event.
905
-            if (empty ($related_tickets) && count($times) < 2) {
906
-                $related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
907
-
908
-                //this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
909
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
910
-
911
-                $main_default_ticket = reset($related_tickets);
912
-                if ($main_default_ticket instanceof EE_Ticket) {
913
-                    foreach ($default_prices as $default_price) {
914
-                        if ($default_price->is_base_price()) {
915
-                            continue;
916
-                        }
917
-                        $main_default_ticket->cache('Price', $default_price);
918
-                    }
919
-                }
920
-            }
921
-
922
-
923
-            //we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information.
924
-
925
-            //loop through and setup the ticket rows and make sure the order is set.
926
-            foreach ($related_tickets as $ticket) {
927
-                $tktid  = $ticket->get('TKT_ID');
928
-                $tktrow = $ticket->get('TKT_row');
929
-                //we only want unique tickets in our final display!!
930
-                if ( ! in_array($tktid, $existing_ticket_ids)) {
931
-                    $existing_ticket_ids[] = $tktid;
932
-                    $all_tickets[]         = $ticket;
933
-                }
934
-
935
-                //temporary cache of this ticket info for this datetime for later processing of datetime rows.
936
-                $datetime_tickets[$dttid][] = $tktrow;
937
-
938
-                //temporary cache of this datetime info for this ticket for later processing of ticket rows.
939
-                if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) {
940
-                    $ticket_datetimes[$tktid][] = $dttrow;
941
-                }
942
-            }
943
-            $dttrow++;
944
-        }
945
-
946
-        $main_template_args['total_ticket_rows']     = count($existing_ticket_ids);
947
-        $main_template_args['existing_ticket_ids']   = implode(',', $existing_ticket_ids);
948
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
949
-
950
-        //sort $all_tickets by order
951
-        usort($all_tickets, function ($a, $b) {
952
-            $a_order = (int)$a->get('TKT_order');
953
-            $b_order = (int)$b->get('TKT_order');
954
-            if ($a_order == $b_order) {
955
-                return 0;
956
-            }
957
-
958
-            return ($a_order < $b_order) ? -1 : 1;
959
-        });
960
-
961
-        //k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again.
962
-        $dttrow = 1;
963
-        foreach ($times as $time) {
964
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets,
965
-                $all_tickets, false, $times);
966
-            $dttrow++;
967
-        }
968
-
969
-        //then loop through all tickets for the ticket rows.
970
-        $tktrow = 1;
971
-        foreach ($all_tickets as $ticket) {
972
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times,
973
-                false, $all_tickets);
974
-            $tktrow++;
975
-        }
976
-
977
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets);
978
-        $template                                  = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php';
979
-        EEH_Template::display_template($template, $main_template_args);
980
-
981
-        return;
982
-    }
983
-
984
-
985
-    protected function _get_datetime_row(
986
-        $dttrow,
987
-        EE_Datetime $dtt,
988
-        $datetime_tickets,
989
-        $all_tickets,
990
-        $default = false,
991
-        $all_dtts = array()
992
-    ) {
993
-
994
-        $dtt_display_template_args = array(
995
-            'dtt_edit_row'             => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts),
996
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets,
997
-                $all_tickets, $default),
998
-            'dtt_row'                  => $default ? 'DTTNUM' : $dttrow
999
-        );
1000
-        $template                  = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php';
1001
-
1002
-        return EEH_Template::display_template($template, $dtt_display_template_args, true);
1003
-    }
1004
-
1005
-
1006
-    /**
1007
-     * This method is used to generate a dtt fields  edit row.
1008
-     * The same row is used to generate a row with valid DTT objects and the default row that is used as the
1009
-     * skeleton by the js.
1010
-     *
1011
-     * @param int           $dttrow                         The row number for the row being generated.
1012
-     * @param               mixed                           EE_Datetime|null $dtt      If not default row being
1013
-     *                                                                       generated, this must be a EE_Datetime
1014
-     *                                                                       object.
1015
-     * @param bool          $default                        Whether a default row is being generated or not.
1016
-     * @param EE_Datetime[] $all_dtts                       This is the array of all datetimes used in the editor.
1017
-     *
1018
-     * @return string Generated edit row.
1019
-     */
1020
-    protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts)
1021
-    {
1022
-
1023
-        // if the incoming $dtt object is NOT an instance of EE_Datetime then force default to true.
1024
-        $default = ! $dtt instanceof EE_Datetime ? true : false;
1025
-
1026
-        $template_args = array(
1027
-            'dtt_row'              => $default ? 'DTTNUM' : $dttrow,
1028
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1029
-            'edit_dtt_expanded'    => '',
1030
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing',
1031
-            'DTT_ID'               => $default ? '' : $dtt->ID(),
1032
-            'DTT_name'             => $default ? '' : $dtt->name(),
1033
-            'DTT_description'      => $default ? '' : $dtt->description(),
1034
-            'DTT_EVT_start'        => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1035
-            'DTT_EVT_end'          => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1036
-            'DTT_reg_limit'        => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'),
1037
-            'DTT_order'            => $default ? 'DTTNUM' : $dttrow,
1038
-            'dtt_sold'             => $default ? '0' : $dtt->get('DTT_sold'),
1039
-            'dtt_reserved'         => $default ? '0' : $dtt->reserved(),
1040
-            'clone_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable',
1041
-            'trash_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable',
1042
-            'reg_list_url'         => $default || ! $dtt->event() instanceof \EE_Event
1043
-                ? ''
1044
-                : EE_Admin_Page::add_query_args_and_nonce(
1045
-                    array('event_id' => $dtt->event()->ID(), 'datetime_id' => $dtt->ID()),
1046
-                    REG_ADMIN_URL
1047
-                )
1048
-        );
1049
-
1050
-        $template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : '';
1051
-
1052
-        //allow filtering of template args at this point.
1053
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1054
-            $template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event);
1055
-
1056
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php';
1057
-
1058
-        return EEH_Template::display_template($template, $template_args, true);
1059
-    }
1060
-
1061
-
1062
-    protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default)
1063
-    {
1064
-
1065
-        $template_args = array(
1066
-            'dtt_row'                           => $default ? 'DTTNUM' : $dttrow,
1067
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1068
-            'DTT_description'                   => $default ? '' : $dtt->description(),
1069
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1070
-            'show_tickets_row'                  => ' style="display:none;"',
1071
-            //$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '',
1072
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime',
1073
-                $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
1074
-            //todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1075
-            'DTT_ID'                            => $default ? '' : $dtt->ID()
1076
-        );
1077
-
1078
-        //need to setup the list items (but only if this isnt' a default skeleton setup)
1079
-        if ( ! $default) {
1080
-            $tktrow = 1;
1081
-            foreach ($all_tickets as $ticket) {
1082
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow,
1083
-                    $dtt, $ticket, $datetime_tickets, $default);
1084
-                $tktrow++;
1085
-            }
1086
-        }
1087
-
1088
-        //filter template args at this point
1089
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1090
-            $template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event);
1091
-
1092
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php';
1093
-
1094
-        return EEH_Template::display_template($template, $template_args, true);
1095
-    }
1096
-
1097
-
1098
-    protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default)
1099
-    {
1100
-        $tktid    = ! empty($ticket) ? $ticket->ID() : 0;
1101
-        $dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array();
1102
-
1103
-        $displayrow    = ! empty($ticket) ? $ticket->get('TKT_row') : 0;
1104
-        $template_args = array(
1105
-            'dtt_row'                 => $default ? 'DTTNUM' : $dttrow,
1106
-            'tkt_row'                 => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1107
-            'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '',
1108
-            'ticket_selected'         => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '',
1109
-            'TKT_name'                => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'),
1110
-            'tkt_status_class'        => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(),
1111
-        );
1112
-
1113
-        //filter template args
1114
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1115
-            $template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event);
1116
-
1117
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php';
1118
-
1119
-        return EEH_Template::display_template($template, $template_args, true);
1120
-    }
1121
-
1122
-
1123
-    /**
1124
-     * This generates the ticket row for tickets.
1125
-     * This same method is used to generate both the actual rows and the js skeleton row (when default ==
1126
-     * true)
1127
-     *
1128
-     * @param int           $tktrow                          Represents the row number being generated.
1129
-     * @param               mixed                            null|EE_Ticket $ticket           If default then this will
1130
-     *                                                                      be null.
1131
-     * @param EE_Datetime[] $ticket_datetimes                Either an array of all datetimes on all tickets indexed by
1132
-     *                                                       each ticket or empty for  default
1133
-     * @param EE_Datetime[] $all_dtts                        All Datetimes on the event or empty for default.
1134
-     * @param bool          $default                         Whether default row being generated or not.
1135
-     * @param EE_Ticket[]   $all_tickets                     This is an array of all tickets attached to the event (or
1136
-     *                                                       empty in the case of defaults)
1137
-     *
1138
-     * @return [type] [description]
1139
-     */
1140
-    protected function _get_ticket_row(
1141
-        $tktrow,
1142
-        $ticket,
1143
-        $ticket_datetimes,
1144
-        $all_dtts,
1145
-        $default = false,
1146
-        $all_tickets = array()
1147
-    ) {
1148
-
1149
-        //if $ticket is not an instance of EE_Ticket then force default to true.
1150
-        $default = ! $ticket instanceof EE_Ticket ? true : false;
1151
-
1152
-        $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price',
1153
-            array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array();
1154
-
1155
-        //if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on
1156
-        //the object.  This is done by not including any query_params.
1157
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1158
-            $prices = $ticket->get_many_related('Price');
1159
-        }
1160
-
1161
-        // check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket).  This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1162
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? true : false;
1163
-
1164
-        $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1165
-
1166
-        $ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1167
-        $base_price       = $default ? null : $ticket->base_price();
1168
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1169
-
1170
-        //breaking out complicated condition for ticket_status
1171
-        if ($default) {
1172
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1173
-        } else {
1174
-            $ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status();
1175
-        }
1176
-
1177
-        //breaking out complicated condition for TKT_taxable
1178
-        if ($default) {
1179
-            $TKT_taxable = '';
1180
-        } else {
1181
-            $TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : '';
1182
-        }
1183
-
1184
-
1185
-        $template_args = array(
1186
-            'tkt_row'                       => $default ? 'TICKETNUM' : $tktrow,
1187
-            'TKT_order'                     => $default ? 'TICKETNUM' : $tktrow,
1188
-            //on initial page load this will always be the correct order.
1189
-            'tkt_status_class'              => $ticket_status_class,
1190
-            'display_edit_tkt_row'          => ' style="display:none;"',
1191
-            'edit_tkt_expanded'             => '',
1192
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1193
-            'TKT_name'                      => $default ? '' : $ticket->get('TKT_name'),
1194
-            'TKT_start_date'                => $default ? '' : $ticket->get_date('TKT_start_date',
1195
-                $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1196
-            'TKT_end_date'                  => $default ? '' : $ticket->get_date('TKT_end_date',
1197
-                $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1198
-            'TKT_status'                    => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1199
-                'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1200
-                'sentence') : $ticket->ticket_status(true),
1201
-            'TKT_price'                     => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(),
1202
-                false, false),
1203
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1204
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1205
-            'TKT_qty'                       => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'),
1206
-            'TKT_qty_for_input'             => $default ? '' : $ticket->get_pretty('TKT_qty', 'input'),
1207
-            'TKT_uses'                      => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'),
1208
-            'TKT_min'                       => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')),
1209
-            'TKT_max'                       => $default ? '' : $ticket->get_pretty('TKT_max', 'input'),
1210
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1211
-            'TKT_reserved'                      => $default ? 0 : $ticket->reserved(),
1212
-            'TKT_registrations'             => $default ? 0 : $ticket->count_registrations(array(
1213
-                array(
1214
-                    'STS_ID' => array(
1215
-                        '!=',
1216
-                        EEM_Registration::status_id_incomplete
1217
-                    )
1218
-                )
1219
-            )),
1220
-            'TKT_ID'                        => $default ? 0 : $ticket->get('TKT_ID'),
1221
-            'TKT_description'               => $default ? '' : $ticket->get('TKT_description'),
1222
-            'TKT_is_default'                => $default ? 0 : $ticket->get('TKT_is_default'),
1223
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1224
-            'TKT_is_default_selector'       => '',
1225
-            'ticket_price_rows'             => '',
1226
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount',
1227
-                'localized_float'),
1228
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1229
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"',
1230
-            'show_price_mod_button'         => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '',
1231
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1232
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1233
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts),
1234
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_dtts),
1235
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1236
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1237
-            'TKT_taxable'                   => $TKT_taxable,
1238
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"',
1239
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1240
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency($ticket_subtotal, false, false),
1241
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1242
-            'tax_rows'                      => $this->_get_tax_rows($tktrow, $ticket),
1243
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? true : false,
1244
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '',
1245
-            'trash_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable',
1246
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable'
1247
-        );
1248
-
1249
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : '';
1250
-
1251
-        //handle rows that should NOT be empty
1252
-        if (empty($template_args['TKT_start_date'])) {
1253
-            //if empty then the start date will be now.
1254
-            $template_args['TKT_start_date']   = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1255
-                current_time('timestamp'));
1256
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1257
-        }
1258
-
1259
-        if (empty($template_args['TKT_end_date'])) {
1260
-
1261
-            //get the earliest datetime (if present);
1262
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime',
1263
-                array('order_by' => array('DTT_EVT_start' => 'ASC'))) : null;
1264
-
1265
-            if ( ! empty($earliest_dtt)) {
1266
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start',
1267
-                    $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
1268
-            } else {
1269
-                //default so let's just use what's been set for the default date-time which is 30 days from now.
1270
-                $template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1271
-                    mktime(24, 0, 0, date("m"), date("d") + 29, date("Y")));
1272
-            }
1273
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1274
-        }
1275
-
1276
-        //generate ticket_datetime items
1277
-        if ( ! $default) {
1278
-            $dttrow = 1;
1279
-            foreach ($all_dtts as $dtt) {
1280
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt,
1281
-                    $ticket, $ticket_datetimes, $default);
1282
-                $dttrow++;
1283
-            }
1284
-        }
1285
-
1286
-        $prcrow = 1;
1287
-        foreach ($prices as $price) {
1288
-            if ($price->is_base_price()) {
1289
-                $prcrow++;
1290
-                continue;
1291
-            }
1292
-            $show_trash  = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? false : true;
1293
-            $show_create = count($prices) > 1 && count($prices) !== $prcrow ? false : true;
1294
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default,
1295
-                $ticket, $show_trash, $show_create);
1296
-            $prcrow++;
1297
-        }
1298
-
1299
-        //filter $template_args
1300
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1301
-            $template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets,
1302
-            $this->_is_creating_event);
1303
-
1304
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php';
1305
-
1306
-        return EEH_Template::display_template($template, $template_args, true);
1307
-    }
1308
-
1309
-
1310
-    protected function _get_tax_rows($tktrow, $ticket)
1311
-    {
1312
-        $tax_rows      = '';
1313
-        $template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php';
1314
-        $template_args = array();
1315
-        $taxes         = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1316
-        foreach ($taxes as $tax) {
1317
-            $tax_added     = $this->_get_tax_added($tax, $ticket);
1318
-            $template_args = array(
1319
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"',
1320
-                'tax_id'            => $tax->ID(),
1321
-                'tkt_row'           => $tktrow,
1322
-                'tax_label'         => $tax->get('PRC_name'),
1323
-                'tax_added'         => $tax_added,
1324
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1325
-                'tax_amount'        => $tax->get('PRC_amount')
1326
-            );
1327
-            $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1328
-                $template_args, $tktrow, $ticket, $this->_is_creating_event);
1329
-            $tax_rows .= EEH_Template::display_template($template, $template_args, true);
1330
-        }
1331
-
1332
-
1333
-        return $tax_rows;
1334
-    }
1335
-
1336
-
1337
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1338
-    {
1339
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1340
-
1341
-        return $subtotal * $tax->get('PRC_amount') / 100;
1342
-    }
1343
-
1344
-
1345
-    protected function _get_ticket_price_row(
1346
-        $tktrow,
1347
-        $prcrow,
1348
-        $price,
1349
-        $default,
1350
-        $ticket,
1351
-        $show_trash = true,
1352
-        $show_create = true
1353
-    ) {
1354
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false;
1355
-        $template_args = array(
1356
-            'tkt_row'               => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1357
-            'PRC_order'             => $default && empty($price) ? 'PRICENUM' : $prcrow,
1358
-            'edit_prices_name'      => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices',
1359
-            'price_type_selector'   => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow,
1360
-                $price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled),
1361
-            'PRC_ID'                => $default && empty($price) ? 0 : $price->ID(),
1362
-            'PRC_is_default'        => $default && empty($price) ? 0 : $price->get('PRC_is_default'),
1363
-            'PRC_name'              => $default && empty($price) ? '' : $price->get('PRC_name'),
1364
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1365
-            'show_plus_or_minus'    => $default && empty($price) ? '' : ' style="display:none;"',
1366
-            'show_plus'             => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''),
1367
-            'show_minus'            => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'),
1368
-            'show_currency_symbol'  => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''),
1369
-            'PRC_amount'            => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount',
1370
-                'localized_float'),
1371
-            'show_percentage'       => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'),
1372
-            'show_trash_icon'       => $show_trash ? '' : ' style="display:none;"',
1373
-            'show_create_button'    => $show_create ? '' : ' style="display:none;"',
1374
-            'PRC_desc'              => $default && empty($price) ? '' : $price->get('PRC_desc'),
1375
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false
1376
-        );
1377
-
1378
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1379
-            $template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create,
1380
-            $this->_is_creating_event);
1381
-
1382
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php';
1383
-
1384
-        return EEH_Template::display_template($template, $template_args, true);
1385
-    }
1386
-
1387
-
1388
-    protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = false)
1389
-    {
1390
-        if ($price->is_base_price()) {
1391
-            return $this->_get_base_price_template($tktrow, $prcrow, $price, $default);
1392
-        } else {
1393
-            return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled);
1394
-        }
1395
-
1396
-    }
1397
-
1398
-
1399
-    protected function _get_base_price_template($tktrow, $prcrow, $price, $default)
1400
-    {
1401
-        $template_args = array(
1402
-            'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1403
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1404
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1405
-            'PRT_name'                  => __('Price', 'event_espresso'),
1406
-            'price_selected_operator'   => '+',
1407
-            'price_selected_is_percent' => 0
1408
-        );
1409
-        $template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php';
1410
-
1411
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1412
-            $template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event);
1413
-
1414
-        return EEH_Template::display_template($template, $template_args, true);
1415
-    }
1416
-
1417
-
1418
-    protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false)
1419
-    {
1420
-        $select_name                = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]';
1421
-        $price_types                = EE_Registry::instance()->load_model('Price_Type')->get_all(array(
1422
-            array(
1423
-                'OR' => array(
1424
-                    'PBT_ID'  => '2',
1425
-                    'PBT_ID*' => '3'
1426
-                )
1427
-            )
1428
-        ));
1429
-        $price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php';
1430
-        $all_price_types            = $default && empty($price) ? array(
1431
-            array(
1432
-                'id'   => 0,
1433
-                'text' => __('Select Modifier', 'event_espresso')
1434
-            )
1435
-        ) : array();
1436
-        $selected_price_type_id     = $default && empty($price) ? 0 : $price->type();
1437
-        $price_option_spans         = '';
1438
-        //setup pricetypes for selector
1439
-        foreach ($price_types as $price_type) {
1440
-            $all_price_types[] = array(
1441
-                'id'   => $price_type->ID(),
1442
-                'text' => $price_type->get('PRT_name'),
1443
-            );
1444
-
1445
-            //while we're in the loop let's setup the option spans used by js
1446
-            $spanargs = array(
1447
-                'PRT_ID'         => $price_type->ID(),
1448
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1449
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0
1450
-            );
1451
-            $price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, true);
1452
-        }
1453
-
1454
-        $select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"';
1455
-        $main_name     = $select_name;
1456
-        $select_name   = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name;
1457
-
1458
-        $template_args = array(
1459
-            'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1460
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1461
-            'price_modifier_selector'   => EEH_Form_Fields::select_input($select_name, $all_price_types,
1462
-                $selected_price_type_id, $select_params, 'edit-price-PRT_ID'),
1463
-            'main_name'                 => $main_name,
1464
-            'selected_price_type_id'    => $selected_price_type_id,
1465
-            'price_option_spans'        => $price_option_spans,
1466
-            'price_selected_operator'   => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'),
1467
-            'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0),
1468
-            'disabled'                  => $disabled
1469
-        );
1470
-
1471
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1472
-            $template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event);
1473
-
1474
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php';
1475
-
1476
-        return EEH_Template::display_template($template, $template_args, true);
1477
-    }
1478
-
1479
-
1480
-    protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default)
1481
-    {
1482
-        $tkt_dtts      = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1483
-        $template_args = array(
1484
-            'dtt_row'                  => $default && ! $dtt instanceof EE_Datetime ? 'DTTNUM' : $dttrow,
1485
-            'tkt_row'                  => $default ? 'TICKETNUM' : $tktrow,
1486
-            'ticket_datetime_selected' => in_array($dttrow, $tkt_dtts) ? ' ticket-selected' : '',
1487
-            'ticket_datetime_checked'  => in_array($dttrow, $tkt_dtts) ? ' checked="checked"' : '',
1488
-            'DTT_name'                 => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(true),
1489
-            'tkt_status_class'         => '',
1490
-        );
1491
-
1492
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
1493
-            $template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event);
1494
-        $template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php';
1495
-
1496
-        return EEH_Template::display_template($template, $template_args, true);
1497
-    }
1498
-
1499
-
1500
-    protected function _get_ticket_js_structure($all_dtts, $all_tickets)
1501
-    {
1502
-        $template_args = array(
1503
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row('DTTNUM', null, true, $all_dtts),
1504
-            'default_ticket_row'                       => $this->_get_ticket_row('TICKETNUM', null, array(), array(),
1505
-                true),
1506
-            'default_price_row'                        => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', null,
1507
-                true, null),
1508
-            'default_price_rows'                       => '',
1509
-            'default_base_price_amount'                => 0,
1510
-            'default_base_price_name'                  => '',
1511
-            'default_base_price_description'           => '',
1512
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM',
1513
-                null, true),
1514
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row('DTTNUM', null, array(),
1515
-                array(), true),
1516
-            'existing_available_datetime_tickets_list' => '',
1517
-            'existing_available_ticket_datetimes_list' => '',
1518
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM',
1519
-                null, null, array(), true),
1520
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM',
1521
-                null, null, array(), true)
1522
-        );
1523
-
1524
-        $tktrow = 1;
1525
-        foreach ($all_tickets as $ticket) {
1526
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM',
1527
-                $tktrow, null, $ticket, array(), true);
1528
-            $tktrow++;
1529
-        }
1530
-
1531
-
1532
-        $dttrow = 1;
1533
-        foreach ($all_dtts as $dtt) {
1534
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow,
1535
-                'TICKETNUM', $dtt, null, array(), true);
1536
-            $dttrow++;
1537
-        }
1538
-
1539
-        $default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices();
1540
-        $prcrow         = 1;
1541
-        foreach ($default_prices as $price) {
1542
-            if ($price->is_base_price()) {
1543
-                $template_args['default_base_price_amount']      = $price->get_pretty('PRC_amount', 'localized_float');
1544
-                $template_args['default_base_price_name']        = $price->get('PRC_name');
1545
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
1546
-                $prcrow++;
1547
-                continue;
1548
-            }
1549
-            $show_trash  = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? false : true;
1550
-            $show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? false : true;
1551
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, true,
1552
-                null, $show_trash, $show_create);
1553
-            $prcrow++;
1554
-        }
1555
-
1556
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
1557
-            $template_args, $all_dtts, $all_tickets, $this->_is_creating_event);
1558
-
1559
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php';
1560
-
1561
-        return EEH_Template::display_template($template, $template_args, true);
1562
-    }
34
+	/**
35
+	 * This property is just used to hold the status of whether an event is currently being
36
+	 * created (true) or edited (false)
37
+	 * @access protected
38
+	 * @var bool
39
+	 */
40
+	protected $_is_creating_event;
41
+
42
+
43
+	/**
44
+	 * Used to contain the format strings for date and time that will be used for php date and
45
+	 * time.
46
+	 *
47
+	 * Is set in the _set_hooks_properties() method.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	protected $_date_format_strings;
52
+
53
+
54
+	protected function _set_hooks_properties()
55
+	{
56
+		$this->_name = 'pricing';
57
+
58
+		//capability check
59
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices',
60
+			'advanced_ticket_datetime_metabox')
61
+		) {
62
+			return;
63
+		}
64
+
65
+
66
+		//if we were going to add our own metaboxes we'd use the below.
67
+		$this->_metaboxes = array(
68
+			0 => array(
69
+				'page_route' => array('edit', 'create_new'),
70
+				'func'       => 'pricing_metabox',
71
+				'label'      => __('Event Tickets & Datetimes', 'event_espresso'),
72
+				'priority'   => 'high',
73
+				'context'    => 'normal'
74
+			),
75
+
76
+		);/**/
77
+
78
+		$this->_remove_metaboxes = array(
79
+			0 => array(
80
+				'page_route' => array('edit', 'create_new'),
81
+				'id'         => 'espresso_event_editor_tickets',
82
+				'context'    => 'normal'
83
+			)
84
+		);
85
+
86
+		/**
87
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
88
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
89
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
90
+		 *
91
+		 * @since 4.6.7
92
+		 *
93
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
94
+		 */
95
+		$this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
96
+			array(
97
+				'date' => 'Y-m-d',
98
+				'time' => 'h:i a'
99
+			));
100
+
101
+		//validate
102
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null;
103
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null;
104
+
105
+		//validate format strings
106
+		$format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
107
+		if (is_array($format_validation)) {
108
+			$msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:',
109
+					'event_espresso'),
110
+					$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>';
111
+			foreach ($format_validation as $error) {
112
+				$msg .= '<li>' . $error . '</li>';
113
+			}
114
+			$msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
115
+					'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>';
116
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
117
+			$this->_date_format_strings = array(
118
+				'date' => 'Y-m-d',
119
+				'time' => 'h:i a'
120
+			);
121
+		}
122
+
123
+
124
+		$this->_scripts_styles = array(
125
+			'registers'   => array(
126
+				'ee-tickets-datetimes-css' => array(
127
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
128
+					'type' => 'css'
129
+				),
130
+				'ee-dtt-ticket-metabox'    => array(
131
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
132
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore')
133
+				)
134
+			),
135
+			'deregisters' => array(
136
+				'event-editor-css'       => array('type' => 'css'),
137
+				'event-datetime-metabox' => array('type' => 'js')
138
+			),
139
+			'enqueues'    => array(
140
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
141
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new')
142
+			),
143
+			'localize'    => array(
144
+				'ee-dtt-ticket-metabox' => array(
145
+					'DTT_TRASH_BLOCK'       => array(
146
+						'main_warning'            => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
147
+							'event_espresso'),
148
+						'after_warning'           => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
149
+							'event_espresso'),
150
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">' . __('Cancel',
151
+								'event_espresso') . '</button>',
152
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">' . __('Close',
153
+								'event_espresso') . '</button>',
154
+						'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
155
+							'event_espresso'),
156
+						'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
157
+							'event_espresso'),
158
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss',
159
+								'event_espresso') . '</button>'
160
+					),
161
+					'DTT_ERROR_MSG'         => array(
162
+						'no_ticket_name' => __('General Admission', 'event_espresso'),
163
+						'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss',
164
+								'event_espresso') . '</button></div>'
165
+					),
166
+					'DTT_OVERSELL_WARNING'  => array(
167
+						'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
168
+							'event_espresso'),
169
+						'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
170
+							'event_espresso')
171
+					),
172
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'],
173
+						$this->_date_format_strings['time']),
174
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int)get_option('start_of_week'))
175
+				)
176
+			)
177
+		);
178
+
179
+
180
+		add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
181
+			array($this, 'autosave_handling'), 10);
182
+		add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
183
+			array($this, 'caf_updates'), 10);
184
+	}
185
+
186
+
187
+	public function caf_updates($update_callbacks)
188
+	{
189
+		foreach ($update_callbacks as $key => $callback) {
190
+			if ($callback[1] == '_default_tickets_update') {
191
+				unset($update_callbacks[$key]);
192
+			}
193
+		}
194
+
195
+		$update_callbacks[] = array($this, 'dtt_and_tickets_caf_update');
196
+
197
+		return $update_callbacks;
198
+	}
199
+
200
+
201
+	/**
202
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
203
+	 *
204
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
205
+	 * @param  array    $data   The request data from the form
206
+	 *
207
+	 * @return bool             success or fail
208
+	 */
209
+	public function dtt_and_tickets_caf_update($evtobj, $data)
210
+	{
211
+		//first we need to start with datetimes cause they are the "root" items attached to events.
212
+		$saved_dtts = $this->_update_dtts($evtobj, $data);
213
+		//next tackle the tickets (and prices?)
214
+		$this->_update_tkts($evtobj, $saved_dtts, $data);
215
+	}
216
+
217
+
218
+	/**
219
+	 * update event_datetimes
220
+	 *
221
+	 * @param  EE_Event $evt_obj Event being updated
222
+	 * @param  array    $data    the request data from the form
223
+	 *
224
+	 * @return EE_Datetime[]
225
+	 */
226
+	protected function _update_dtts($evt_obj, $data)
227
+	{
228
+		$timezone       = isset($data['timezone_string']) ? $data['timezone_string'] : null;
229
+		$saved_dtt_ids  = array();
230
+		$saved_dtt_objs = array();
231
+
232
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
233
+			//trim all values to ensure any excess whitespace is removed.
234
+			$dtt                = array_map(
235
+				function ($datetime_data) {
236
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
237
+				},
238
+				$dtt
239
+			);
240
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start'];
241
+			$datetime_values    = array(
242
+				'DTT_ID'          => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
243
+				'DTT_name'        => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '',
244
+				'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '',
245
+				'DTT_EVT_start'   => $dtt['DTT_EVT_start'],
246
+				'DTT_EVT_end'     => $dtt['DTT_EVT_end'],
247
+				'DTT_reg_limit'   => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
248
+				'DTT_order'       => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'],
249
+			);
250
+
251
+			//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.
252
+
253
+			if ( ! empty($dtt['DTT_ID'])) {
254
+				$DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']);
255
+
256
+				//set date and time format according to what is set in this class.
257
+				$DTM->set_date_format($this->_date_format_strings['date']);
258
+				$DTM->set_time_format($this->_date_format_strings['time']);
259
+
260
+				foreach ($datetime_values as $field => $value) {
261
+					$DTM->set($field, $value);
262
+				}
263
+
264
+				// make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.
265
+				// We need to do this so we dont' TRASH the parent DTT.(save the ID for both key and value to avoid duplications)
266
+				$saved_dtt_ids[$DTM->ID()] = $DTM->ID();
267
+
268
+			} else {
269
+				$DTM = EE_Registry::instance()->load_class(
270
+					'Datetime',
271
+					array(
272
+						$datetime_values,
273
+						$timezone,
274
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
275
+					),
276
+					false,
277
+					false
278
+				);
279
+
280
+				foreach ($datetime_values as $field => $value) {
281
+					$DTM->set($field, $value);
282
+				}
283
+			}
284
+
285
+
286
+			$DTM->save();
287
+			$DTM = $evt_obj->_add_relation_to($DTM, 'Datetime');
288
+			$evt_obj->save();
289
+
290
+			//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.
291
+			if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) {
292
+				$DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start'));
293
+				$DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days');
294
+				$DTM->save();
295
+			}
296
+
297
+			//	now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
298
+			// because it is possible there was a new one created for the autosave.
299
+			// (save the ID for both key and value to avoid duplications)
300
+			$saved_dtt_ids[$DTM->ID()] = $DTM->ID();
301
+			$saved_dtt_objs[$row]      = $DTM;
302
+
303
+			//todo if ANY of these updates fail then we want the appropriate global error message.
304
+		}
305
+
306
+		//now we need to REMOVE any dtts that got deleted.  Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point.
307
+		$old_datetimes = explode(',', $data['datetime_IDs']);
308
+		$old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes;
309
+
310
+		if (is_array($old_datetimes)) {
311
+			$dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
312
+			foreach ($dtts_to_delete as $id) {
313
+				$id = absint($id);
314
+				if (empty($id)) {
315
+					continue;
316
+				}
317
+
318
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
319
+
320
+				//remove tkt relationships.
321
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
322
+				foreach ($related_tickets as $tkt) {
323
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
324
+				}
325
+
326
+				$evt_obj->_remove_relation_to($id, 'Datetime');
327
+				$dtt_to_remove->refresh_cache_of_related_objects();
328
+
329
+			}
330
+		}
331
+
332
+		return $saved_dtt_objs;
333
+	}
334
+
335
+
336
+	/**
337
+	 * update tickets
338
+	 *
339
+	 * @param  EE_Event      $evtobj     Event object being updated
340
+	 * @param  EE_Datetime[] $saved_dtts an array of datetime ids being updated
341
+	 * @param  array         $data       incoming request data
342
+	 *
343
+	 * @return EE_Ticket[]
344
+	 */
345
+	protected function _update_tkts($evtobj, $saved_dtts, $data)
346
+	{
347
+
348
+		$new_tkt     = null;
349
+		$new_default = null;
350
+		//stripslashes because WP filtered the $_POST ($data) array to add slashes
351
+		$data          = stripslashes_deep($data);
352
+		$timezone      = isset($data['timezone_string']) ? $data['timezone_string'] : null;
353
+		$saved_tickets = $dtts_on_existing = array();
354
+		$old_tickets   = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
355
+
356
+		//load money helper
357
+
358
+		foreach ($data['edit_tickets'] as $row => $tkt) {
359
+
360
+			$update_prices = $create_new_TKT = false;
361
+
362
+			//figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session.
363
+
364
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
365
+			$tkt_dtt_rows          = explode(',', $data['ticket_datetime_rows'][$row]);
366
+			$dtts_added            = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
367
+			$dtts_removed          = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
368
+
369
+			// trim inputs to ensure any excess whitespace is removed.
370
+			$tkt = array_map(
371
+				function ($ticket_data) {
372
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
373
+				},
374
+				$tkt
375
+			);
376
+
377
+			//note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models.
378
+			//note incoming ['TKT_price'] value is already in standard notation (via js).
379
+			$ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0;
380
+
381
+			//note incoming base price needs converted from localized value.
382
+			$base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0;
383
+			//if ticket price == 0 and $base_price != 0 then ticket price == base_price
384
+			$ticket_price  = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price;
385
+			$base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0;
386
+
387
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array();
388
+
389
+			$now = null;
390
+			if (empty($tkt['TKT_start_date'])) {
391
+				//lets' use now in the set timezone.
392
+				$now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
393
+				$tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
394
+			}
395
+
396
+			if (empty($tkt['TKT_end_date'])) {
397
+				/**
398
+				 * set the TKT_end_date to the first datetime attached to the ticket.
399
+				 */
400
+				$first_dtt           = $saved_dtts[reset($tkt_dtt_rows)];
401
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']);
402
+			}
403
+
404
+			$TKT_values = array(
405
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
406
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
407
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
408
+				'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description',
409
+					'event_espresso') ? $tkt['TKT_description'] : '',
410
+				'TKT_start_date'  => $tkt['TKT_start_date'],
411
+				'TKT_end_date'    => $tkt['TKT_end_date'],
412
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
413
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
414
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
415
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
416
+				'TKT_row'         => $row,
417
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
418
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
419
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
420
+				'TKT_price'       => $ticket_price
421
+			);
422
+
423
+
424
+			//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.
425
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
426
+				$TKT_values['TKT_ID']         = 0;
427
+				$TKT_values['TKT_is_default'] = 0;
428
+				$update_prices                = true;
429
+			}
430
+
431
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
432
+			// we actually do our saves ahead of doing any add_relations to
433
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
434
+			// but DID have it's items modified.
435
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
436
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
437
+			if (absint($TKT_values['TKT_ID'])) {
438
+				$TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']);
439
+				if ($TKT instanceof EE_Ticket) {
440
+
441
+					$TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
442
+					// are there any registrations using this ticket ?
443
+					$tickets_sold = $TKT->count_related(
444
+						'Registration',
445
+						array(
446
+							array(
447
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete))
448
+							)
449
+						)
450
+					);
451
+					//set ticket formats
452
+					$TKT->set_date_format($this->_date_format_strings['date']);
453
+					$TKT->set_time_format($this->_date_format_strings['time']);
454
+
455
+					// let's just check the total price for the existing ticket
456
+					// and determine if it matches the new total price.
457
+					// if they are different then we create a new ticket (if tkts sold)
458
+					// if they aren't different then we go ahead and modify existing ticket.
459
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price != $TKT->price() && ! $TKT->deleted()
460
+						? true : false;
461
+
462
+					//set new values
463
+					foreach ($TKT_values as $field => $value) {
464
+						if ($field === 'TKT_qty') {
465
+							$TKT->set_qty($value);
466
+						} else {
467
+							$TKT->set($field, $value);
468
+						}
469
+					}
470
+
471
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
472
+					if ($create_new_TKT) {
473
+						$new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price,
474
+							$base_price_id);
475
+					}
476
+				}
477
+
478
+			} else {
479
+				// no TKT_id so a new TKT
480
+				$TKT = EE_Ticket::new_instance(
481
+					$TKT_values,
482
+					$timezone,
483
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
484
+				);
485
+				if ($TKT instanceof EE_Ticket) {
486
+					// make sure ticket has an ID of setting relations won't work
487
+					$TKT->save();
488
+					$TKT           = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
489
+					$update_prices = true;
490
+				}
491
+			}
492
+			//make sure any current values have been saved.
493
+			//$TKT->save();
494
+
495
+			//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.
496
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
497
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
498
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
499
+			}
500
+
501
+			//let's make sure the base price is handled
502
+			$TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price,
503
+				$base_price_id) : $TKT;
504
+
505
+			//add/update price_modifiers
506
+			$TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT;
507
+
508
+			//need to make sue that the TKT_price is accurate after saving the prices.
509
+			$TKT->ensure_TKT_Price_correct();
510
+
511
+			//handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
512
+			if ( ! defined('DOING_AUTOSAVE')) {
513
+				if ( ! empty($tkt['TKT_is_default_selector'])) {
514
+					$update_prices = true;
515
+					$new_default   = clone $TKT;
516
+					$new_default->set('TKT_ID', 0);
517
+					$new_default->set('TKT_is_default', 1);
518
+					$new_default->set('TKT_row', 1);
519
+					$new_default->set('TKT_price', $ticket_price);
520
+					//remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object)
521
+					$new_default->_remove_relations('Datetime');
522
+					//todo we need to add the current attached prices as new prices to the new default ticket.
523
+					$new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices);
524
+					//don't forget the base price!
525
+					$new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price,
526
+						$base_price_id);
527
+					$new_default->save();
528
+					do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default,
529
+						$row, $TKT, $data);
530
+				}
531
+			}
532
+
533
+
534
+			//DO ALL dtt relationships for both current tickets and any archived tickets for the given dtt that are related to the current ticket. TODO... not sure exactly how we're going to do this considering we don't know what current ticket the archived tickets are related to (and TKT_parent is used for autosaves so that's not a field we can reliably use).
535
+
536
+
537
+			//let's assign any tickets that have been setup to the saved_tickets tracker
538
+			//save existing TKT
539
+			$TKT->save();
540
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
541
+				//save new TKT
542
+				$new_tkt->save();
543
+				//add new ticket to array
544
+				$saved_tickets[$new_tkt->ID()] = $new_tkt;
545
+
546
+				do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data);
547
+
548
+			} else {
549
+				//add tkt to saved tkts
550
+				$saved_tickets[$TKT->ID()] = $TKT;
551
+
552
+				do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data);
553
+			}
554
+
555
+		}
556
+
557
+		// now we need to handle tickets actually "deleted permanently".
558
+		// There are cases where we'd want this to happen
559
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
560
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
561
+		// No sense in keeping all the related data in the db!
562
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
563
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
564
+
565
+		foreach ($tickets_removed as $id) {
566
+			$id = absint($id);
567
+
568
+			//get the ticket for this id
569
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
570
+
571
+			//if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
572
+			if ($tkt_to_remove->get('TKT_is_default')) {
573
+				continue;
574
+			}
575
+
576
+			// if this tkt has any registrations attached so then we just ARCHIVE
577
+			// because we don't actually permanently delete these tickets.
578
+			if ($tkt_to_remove->count_related('Registration') > 0) {
579
+				$tkt_to_remove->delete();
580
+				continue;
581
+			}
582
+
583
+			// need to get all the related datetimes on this ticket and remove from every single one of them
584
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
585
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
586
+
587
+			foreach ($dtts as $dtt) {
588
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
589
+			}
590
+
591
+			// need to do the same for prices (except these prices can also be deleted because again,
592
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
593
+			$tkt_to_remove->delete_related_permanently('Price');
594
+
595
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
596
+
597
+			// finally let's delete this ticket
598
+			// (which should not be blocked at this point b/c we've removed all our relationships)
599
+			$tkt_to_remove->delete_permanently();
600
+		}
601
+
602
+		return $saved_tickets;
603
+	}
604
+
605
+
606
+	/**
607
+	 *
608
+	 * @access  protected
609
+	 *
610
+	 * @param \EE_Ticket     $ticket
611
+	 * @param \EE_Datetime[] $saved_datetimes
612
+	 * @param \EE_Datetime[] $added_datetimes
613
+	 * @param \EE_Datetime[] $removed_datetimes
614
+	 *
615
+	 * @return \EE_Ticket
616
+	 * @throws \EE_Error
617
+	 */
618
+	protected function _update_ticket_datetimes(
619
+		EE_Ticket $ticket,
620
+		$saved_datetimes = array(),
621
+		$added_datetimes = array(),
622
+		$removed_datetimes = array()
623
+	) {
624
+
625
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
626
+		// and removing the ticket from datetimes it got removed from.
627
+
628
+		// first let's add datetimes
629
+		if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
630
+			foreach ($added_datetimes as $row_id) {
631
+				$row_id = (int)$row_id;
632
+				if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
633
+					$ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
634
+					// Is this an existing ticket (has an ID) and does it have any sold?
635
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
636
+					if ($ticket->ID() && $ticket->sold() > 0) {
637
+						$saved_datetimes[$row_id]->increase_sold($ticket->sold());
638
+						$saved_datetimes[$row_id]->save();
639
+					}
640
+				}
641
+			}
642
+		}
643
+		// then remove datetimes
644
+		if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
645
+			foreach ($removed_datetimes as $row_id) {
646
+				$row_id = (int)$row_id;
647
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
648
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
649
+				if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
650
+					$ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
651
+					// Is this an existing ticket (has an ID) and does it have any sold?
652
+					// If so, then we need to remove it's sold from the DTT_sold.
653
+					if ($ticket->ID() && $ticket->sold() > 0) {
654
+						$saved_datetimes[$row_id]->decrease_sold($ticket->sold());
655
+						$saved_datetimes[$row_id]->save();
656
+					}
657
+				}
658
+			}
659
+		}
660
+		// cap ticket qty by datetime reg limits
661
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
662
+
663
+		return $ticket;
664
+	}
665
+
666
+
667
+	/**
668
+	 *
669
+	 * @access  protected
670
+	 *
671
+	 * @param \EE_Ticket $ticket
672
+	 * @param array      $price_rows
673
+	 * @param int        $ticket_price
674
+	 * @param int        $base_price
675
+	 * @param int        $base_price_id
676
+	 *
677
+	 * @return \EE_Ticket
678
+	 * @throws \EE_Error
679
+	 */
680
+	protected function _duplicate_ticket(
681
+		EE_Ticket $ticket,
682
+		$price_rows = array(),
683
+		$ticket_price = 0,
684
+		$base_price = 0,
685
+		$base_price_id = 0
686
+	) {
687
+
688
+		// create new ticket that's a copy of the existing
689
+		// except a new id of course (and not archived)
690
+		// AND has the new TKT_price associated with it.
691
+		$new_ticket = clone $ticket;
692
+		$new_ticket->set('TKT_ID', 0);
693
+		$new_ticket->set('TKT_deleted', 0);
694
+		$new_ticket->set('TKT_price', $ticket_price);
695
+		$new_ticket->set('TKT_sold', 0);
696
+		// let's get a new ID for this ticket
697
+		$new_ticket->save();
698
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
699
+		$datetimes_on_existing = $ticket->get_many_related('Datetime');
700
+		$new_ticket            = $this->_update_ticket_datetimes(
701
+			$new_ticket,
702
+			$datetimes_on_existing,
703
+			array_keys($datetimes_on_existing)
704
+		);
705
+
706
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
707
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
708
+		// available.
709
+		if ($ticket->sold() > 0) {
710
+			$new_qty = $ticket->qty() - $ticket->sold();
711
+			$new_ticket->set_qty($new_qty);
712
+		}
713
+		//now we update the prices just for this ticket
714
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
715
+		//and we update the base price
716
+		$new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id);
717
+
718
+		return $new_ticket;
719
+	}
720
+
721
+
722
+	/**
723
+	 * This attaches a list of given prices to a ticket.
724
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
725
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
726
+	 * price info and prices are automatically "archived" via the ticket.
727
+	 *
728
+	 * @access  private
729
+	 *
730
+	 * @param array     $prices        Array of prices from the form.
731
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
732
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
733
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
734
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
735
+	 *
736
+	 * @return EE_Ticket
737
+	 */
738
+	protected function _add_prices_to_ticket(
739
+		$prices = array(),
740
+		EE_Ticket $ticket,
741
+		$new_prices = false,
742
+		$base_price = false,
743
+		$base_price_id = false
744
+	) {
745
+
746
+		//let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session.
747
+		$current_prices_on_ticket = $base_price !== false ? $ticket->base_price(true) : $ticket->price_modifiers();
748
+
749
+		$updated_prices = array();
750
+
751
+		// if $base_price ! FALSE then updating a base price.
752
+		if ($base_price !== false) {
753
+			$prices[1] = array(
754
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
755
+				'PRT_ID'     => 1,
756
+				'PRC_amount' => $base_price,
757
+				'PRC_name'   => $ticket->get('TKT_name'),
758
+				'PRC_desc'   => $ticket->get('TKT_description')
759
+			);
760
+		}
761
+
762
+		//possibly need to save tkt
763
+		if ( ! $ticket->ID()) {
764
+			$ticket->save();
765
+		}
766
+
767
+		foreach ($prices as $row => $prc) {
768
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
769
+			if (empty($prt_id)) {
770
+				continue;
771
+			} //prices MUST have a price type id.
772
+			$PRC_values = array(
773
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
774
+				'PRT_ID'         => $prt_id,
775
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
776
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
777
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
778
+				'PRC_is_default' => false,
779
+				//make sure we set PRC_is_default to false for all ticket saves from event_editor
780
+				'PRC_order'      => $row
781
+			);
782
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
783
+				$PRC_values['PRC_ID'] = 0;
784
+				$PRC                  = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
785
+			} else {
786
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
787
+				//update this price with new values
788
+				foreach ($PRC_values as $field => $newprc) {
789
+					$PRC->set($field, $newprc);
790
+				}
791
+			}
792
+			$PRC->save();
793
+			$prcid                  = $PRC->ID();
794
+			$updated_prices[$prcid] = $PRC;
795
+			$ticket->_add_relation_to($PRC, 'Price');
796
+		}
797
+
798
+		//now let's remove any prices that got removed from the ticket
799
+		if ( ! empty ($current_prices_on_ticket)) {
800
+			$current          = array_keys($current_prices_on_ticket);
801
+			$updated          = array_keys($updated_prices);
802
+			$prices_to_remove = array_diff($current, $updated);
803
+			if ( ! empty($prices_to_remove)) {
804
+				foreach ($prices_to_remove as $prc_id) {
805
+					$p = $current_prices_on_ticket[$prc_id];
806
+					$ticket->_remove_relation_to($p, 'Price');
807
+
808
+					//delete permanently the price
809
+					$p->delete_permanently();
810
+				}
811
+			}
812
+		}
813
+
814
+		return $ticket;
815
+	}
816
+
817
+
818
+	public function autosave_handling($event_admin_obj)
819
+	{
820
+		return $event_admin_obj; //doing nothing for the moment.
821
+		//todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method)
822
+
823
+		/**
824
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
825
+		 *
826
+		 * 1. TKT_is_default_selector (visible)
827
+		 * 2. TKT_is_default (hidden)
828
+		 *
829
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want this ticket to be saved as a default.
830
+		 *
831
+		 * The tricky part is, on an initial display on create or edit (or after manually updating), the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true if this is a create.  However, after an autosave, users will want some sort of indicator that the TKT HAS been saved as a default.. in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
832
+		 * On Autosave:
833
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, then set the TKT_is_default to false.
834
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
835
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
836
+		 */
837
+	}
838
+
839
+
840
+	public function pricing_metabox()
841
+	{
842
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
843
+
844
+		$evtobj = $this->_adminpage_obj->get_cpt_model_obj();
845
+
846
+		//set is_creating_event property.
847
+		$evtID                    = $evtobj->ID();
848
+		$this->_is_creating_event = absint($evtID) != 0 ? false : true;
849
+
850
+		//default main template args
851
+		$main_template_args = array(
852
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab',
853
+				$this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
854
+			//todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help
855
+			'existing_datetime_ids'    => '',
856
+			'total_dtt_rows'           => 1,
857
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link('add_new_dtt_info',
858
+				$this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
859
+			//todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
860
+			'datetime_rows'            => '',
861
+			'show_tickets_container'   => '',
862
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
863
+			'ticket_rows'              => '',
864
+			'existing_ticket_ids'      => '',
865
+			'total_ticket_rows'        => 1,
866
+			'ticket_js_structure'      => '',
867
+			'ee_collapsible_status'    => ' ee-collapsible-open'
868
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
869
+		);
870
+
871
+		$timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : null;
872
+
873
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
874
+
875
+		/**
876
+		 * 1. Start with retrieving Datetimes
877
+		 * 2. For each datetime get related tickets
878
+		 * 3. For each ticket get related prices
879
+		 */
880
+
881
+		$DTM   = EE_Registry::instance()->load_model('Datetime', array($timezone));
882
+		$times = $DTM->get_all_event_dates($evtID);
883
+
884
+
885
+		$main_template_args['total_dtt_rows'] = count($times);
886
+
887
+		/** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */
888
+		$dttrow = 1;
889
+		foreach ($times as $time) {
890
+			$dttid = $time->get('DTT_ID');
891
+			$time->set('DTT_order', $dttrow);
892
+			$existing_datetime_ids[] = $dttid;
893
+
894
+			//tickets attached
895
+			$related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array(
896
+				array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
897
+				'default_where_conditions' => 'none',
898
+				'order_by'                 => array('TKT_order' => 'ASC')
899
+			)) : array();
900
+
901
+			//if there are no related tickets this is likely a new event OR autodraft
902
+			// event so we need to generate the default tickets because dtts
903
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
904
+			// datetime on the event.
905
+			if (empty ($related_tickets) && count($times) < 2) {
906
+				$related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
907
+
908
+				//this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
909
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
910
+
911
+				$main_default_ticket = reset($related_tickets);
912
+				if ($main_default_ticket instanceof EE_Ticket) {
913
+					foreach ($default_prices as $default_price) {
914
+						if ($default_price->is_base_price()) {
915
+							continue;
916
+						}
917
+						$main_default_ticket->cache('Price', $default_price);
918
+					}
919
+				}
920
+			}
921
+
922
+
923
+			//we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information.
924
+
925
+			//loop through and setup the ticket rows and make sure the order is set.
926
+			foreach ($related_tickets as $ticket) {
927
+				$tktid  = $ticket->get('TKT_ID');
928
+				$tktrow = $ticket->get('TKT_row');
929
+				//we only want unique tickets in our final display!!
930
+				if ( ! in_array($tktid, $existing_ticket_ids)) {
931
+					$existing_ticket_ids[] = $tktid;
932
+					$all_tickets[]         = $ticket;
933
+				}
934
+
935
+				//temporary cache of this ticket info for this datetime for later processing of datetime rows.
936
+				$datetime_tickets[$dttid][] = $tktrow;
937
+
938
+				//temporary cache of this datetime info for this ticket for later processing of ticket rows.
939
+				if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) {
940
+					$ticket_datetimes[$tktid][] = $dttrow;
941
+				}
942
+			}
943
+			$dttrow++;
944
+		}
945
+
946
+		$main_template_args['total_ticket_rows']     = count($existing_ticket_ids);
947
+		$main_template_args['existing_ticket_ids']   = implode(',', $existing_ticket_ids);
948
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
949
+
950
+		//sort $all_tickets by order
951
+		usort($all_tickets, function ($a, $b) {
952
+			$a_order = (int)$a->get('TKT_order');
953
+			$b_order = (int)$b->get('TKT_order');
954
+			if ($a_order == $b_order) {
955
+				return 0;
956
+			}
957
+
958
+			return ($a_order < $b_order) ? -1 : 1;
959
+		});
960
+
961
+		//k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again.
962
+		$dttrow = 1;
963
+		foreach ($times as $time) {
964
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets,
965
+				$all_tickets, false, $times);
966
+			$dttrow++;
967
+		}
968
+
969
+		//then loop through all tickets for the ticket rows.
970
+		$tktrow = 1;
971
+		foreach ($all_tickets as $ticket) {
972
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times,
973
+				false, $all_tickets);
974
+			$tktrow++;
975
+		}
976
+
977
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets);
978
+		$template                                  = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php';
979
+		EEH_Template::display_template($template, $main_template_args);
980
+
981
+		return;
982
+	}
983
+
984
+
985
+	protected function _get_datetime_row(
986
+		$dttrow,
987
+		EE_Datetime $dtt,
988
+		$datetime_tickets,
989
+		$all_tickets,
990
+		$default = false,
991
+		$all_dtts = array()
992
+	) {
993
+
994
+		$dtt_display_template_args = array(
995
+			'dtt_edit_row'             => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts),
996
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets,
997
+				$all_tickets, $default),
998
+			'dtt_row'                  => $default ? 'DTTNUM' : $dttrow
999
+		);
1000
+		$template                  = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php';
1001
+
1002
+		return EEH_Template::display_template($template, $dtt_display_template_args, true);
1003
+	}
1004
+
1005
+
1006
+	/**
1007
+	 * This method is used to generate a dtt fields  edit row.
1008
+	 * The same row is used to generate a row with valid DTT objects and the default row that is used as the
1009
+	 * skeleton by the js.
1010
+	 *
1011
+	 * @param int           $dttrow                         The row number for the row being generated.
1012
+	 * @param               mixed                           EE_Datetime|null $dtt      If not default row being
1013
+	 *                                                                       generated, this must be a EE_Datetime
1014
+	 *                                                                       object.
1015
+	 * @param bool          $default                        Whether a default row is being generated or not.
1016
+	 * @param EE_Datetime[] $all_dtts                       This is the array of all datetimes used in the editor.
1017
+	 *
1018
+	 * @return string Generated edit row.
1019
+	 */
1020
+	protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts)
1021
+	{
1022
+
1023
+		// if the incoming $dtt object is NOT an instance of EE_Datetime then force default to true.
1024
+		$default = ! $dtt instanceof EE_Datetime ? true : false;
1025
+
1026
+		$template_args = array(
1027
+			'dtt_row'              => $default ? 'DTTNUM' : $dttrow,
1028
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1029
+			'edit_dtt_expanded'    => '',
1030
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing',
1031
+			'DTT_ID'               => $default ? '' : $dtt->ID(),
1032
+			'DTT_name'             => $default ? '' : $dtt->name(),
1033
+			'DTT_description'      => $default ? '' : $dtt->description(),
1034
+			'DTT_EVT_start'        => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1035
+			'DTT_EVT_end'          => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1036
+			'DTT_reg_limit'        => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'),
1037
+			'DTT_order'            => $default ? 'DTTNUM' : $dttrow,
1038
+			'dtt_sold'             => $default ? '0' : $dtt->get('DTT_sold'),
1039
+			'dtt_reserved'         => $default ? '0' : $dtt->reserved(),
1040
+			'clone_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable',
1041
+			'trash_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable',
1042
+			'reg_list_url'         => $default || ! $dtt->event() instanceof \EE_Event
1043
+				? ''
1044
+				: EE_Admin_Page::add_query_args_and_nonce(
1045
+					array('event_id' => $dtt->event()->ID(), 'datetime_id' => $dtt->ID()),
1046
+					REG_ADMIN_URL
1047
+				)
1048
+		);
1049
+
1050
+		$template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : '';
1051
+
1052
+		//allow filtering of template args at this point.
1053
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1054
+			$template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event);
1055
+
1056
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php';
1057
+
1058
+		return EEH_Template::display_template($template, $template_args, true);
1059
+	}
1060
+
1061
+
1062
+	protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default)
1063
+	{
1064
+
1065
+		$template_args = array(
1066
+			'dtt_row'                           => $default ? 'DTTNUM' : $dttrow,
1067
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1068
+			'DTT_description'                   => $default ? '' : $dtt->description(),
1069
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1070
+			'show_tickets_row'                  => ' style="display:none;"',
1071
+			//$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '',
1072
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime',
1073
+				$this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
1074
+			//todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1075
+			'DTT_ID'                            => $default ? '' : $dtt->ID()
1076
+		);
1077
+
1078
+		//need to setup the list items (but only if this isnt' a default skeleton setup)
1079
+		if ( ! $default) {
1080
+			$tktrow = 1;
1081
+			foreach ($all_tickets as $ticket) {
1082
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow,
1083
+					$dtt, $ticket, $datetime_tickets, $default);
1084
+				$tktrow++;
1085
+			}
1086
+		}
1087
+
1088
+		//filter template args at this point
1089
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1090
+			$template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event);
1091
+
1092
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php';
1093
+
1094
+		return EEH_Template::display_template($template, $template_args, true);
1095
+	}
1096
+
1097
+
1098
+	protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default)
1099
+	{
1100
+		$tktid    = ! empty($ticket) ? $ticket->ID() : 0;
1101
+		$dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array();
1102
+
1103
+		$displayrow    = ! empty($ticket) ? $ticket->get('TKT_row') : 0;
1104
+		$template_args = array(
1105
+			'dtt_row'                 => $default ? 'DTTNUM' : $dttrow,
1106
+			'tkt_row'                 => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1107
+			'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '',
1108
+			'ticket_selected'         => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '',
1109
+			'TKT_name'                => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'),
1110
+			'tkt_status_class'        => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(),
1111
+		);
1112
+
1113
+		//filter template args
1114
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1115
+			$template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event);
1116
+
1117
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php';
1118
+
1119
+		return EEH_Template::display_template($template, $template_args, true);
1120
+	}
1121
+
1122
+
1123
+	/**
1124
+	 * This generates the ticket row for tickets.
1125
+	 * This same method is used to generate both the actual rows and the js skeleton row (when default ==
1126
+	 * true)
1127
+	 *
1128
+	 * @param int           $tktrow                          Represents the row number being generated.
1129
+	 * @param               mixed                            null|EE_Ticket $ticket           If default then this will
1130
+	 *                                                                      be null.
1131
+	 * @param EE_Datetime[] $ticket_datetimes                Either an array of all datetimes on all tickets indexed by
1132
+	 *                                                       each ticket or empty for  default
1133
+	 * @param EE_Datetime[] $all_dtts                        All Datetimes on the event or empty for default.
1134
+	 * @param bool          $default                         Whether default row being generated or not.
1135
+	 * @param EE_Ticket[]   $all_tickets                     This is an array of all tickets attached to the event (or
1136
+	 *                                                       empty in the case of defaults)
1137
+	 *
1138
+	 * @return [type] [description]
1139
+	 */
1140
+	protected function _get_ticket_row(
1141
+		$tktrow,
1142
+		$ticket,
1143
+		$ticket_datetimes,
1144
+		$all_dtts,
1145
+		$default = false,
1146
+		$all_tickets = array()
1147
+	) {
1148
+
1149
+		//if $ticket is not an instance of EE_Ticket then force default to true.
1150
+		$default = ! $ticket instanceof EE_Ticket ? true : false;
1151
+
1152
+		$prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price',
1153
+			array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array();
1154
+
1155
+		//if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on
1156
+		//the object.  This is done by not including any query_params.
1157
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1158
+			$prices = $ticket->get_many_related('Price');
1159
+		}
1160
+
1161
+		// check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket).  This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1162
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? true : false;
1163
+
1164
+		$tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1165
+
1166
+		$ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1167
+		$base_price       = $default ? null : $ticket->base_price();
1168
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1169
+
1170
+		//breaking out complicated condition for ticket_status
1171
+		if ($default) {
1172
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1173
+		} else {
1174
+			$ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status();
1175
+		}
1176
+
1177
+		//breaking out complicated condition for TKT_taxable
1178
+		if ($default) {
1179
+			$TKT_taxable = '';
1180
+		} else {
1181
+			$TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : '';
1182
+		}
1183
+
1184
+
1185
+		$template_args = array(
1186
+			'tkt_row'                       => $default ? 'TICKETNUM' : $tktrow,
1187
+			'TKT_order'                     => $default ? 'TICKETNUM' : $tktrow,
1188
+			//on initial page load this will always be the correct order.
1189
+			'tkt_status_class'              => $ticket_status_class,
1190
+			'display_edit_tkt_row'          => ' style="display:none;"',
1191
+			'edit_tkt_expanded'             => '',
1192
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1193
+			'TKT_name'                      => $default ? '' : $ticket->get('TKT_name'),
1194
+			'TKT_start_date'                => $default ? '' : $ticket->get_date('TKT_start_date',
1195
+				$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1196
+			'TKT_end_date'                  => $default ? '' : $ticket->get_date('TKT_end_date',
1197
+				$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1198
+			'TKT_status'                    => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1199
+				'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1200
+				'sentence') : $ticket->ticket_status(true),
1201
+			'TKT_price'                     => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(),
1202
+				false, false),
1203
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1204
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1205
+			'TKT_qty'                       => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'),
1206
+			'TKT_qty_for_input'             => $default ? '' : $ticket->get_pretty('TKT_qty', 'input'),
1207
+			'TKT_uses'                      => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'),
1208
+			'TKT_min'                       => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')),
1209
+			'TKT_max'                       => $default ? '' : $ticket->get_pretty('TKT_max', 'input'),
1210
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1211
+			'TKT_reserved'                      => $default ? 0 : $ticket->reserved(),
1212
+			'TKT_registrations'             => $default ? 0 : $ticket->count_registrations(array(
1213
+				array(
1214
+					'STS_ID' => array(
1215
+						'!=',
1216
+						EEM_Registration::status_id_incomplete
1217
+					)
1218
+				)
1219
+			)),
1220
+			'TKT_ID'                        => $default ? 0 : $ticket->get('TKT_ID'),
1221
+			'TKT_description'               => $default ? '' : $ticket->get('TKT_description'),
1222
+			'TKT_is_default'                => $default ? 0 : $ticket->get('TKT_is_default'),
1223
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1224
+			'TKT_is_default_selector'       => '',
1225
+			'ticket_price_rows'             => '',
1226
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount',
1227
+				'localized_float'),
1228
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1229
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"',
1230
+			'show_price_mod_button'         => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '',
1231
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1232
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1233
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts),
1234
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_dtts),
1235
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1236
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1237
+			'TKT_taxable'                   => $TKT_taxable,
1238
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"',
1239
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1240
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency($ticket_subtotal, false, false),
1241
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1242
+			'tax_rows'                      => $this->_get_tax_rows($tktrow, $ticket),
1243
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? true : false,
1244
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '',
1245
+			'trash_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable',
1246
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable'
1247
+		);
1248
+
1249
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : '';
1250
+
1251
+		//handle rows that should NOT be empty
1252
+		if (empty($template_args['TKT_start_date'])) {
1253
+			//if empty then the start date will be now.
1254
+			$template_args['TKT_start_date']   = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1255
+				current_time('timestamp'));
1256
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1257
+		}
1258
+
1259
+		if (empty($template_args['TKT_end_date'])) {
1260
+
1261
+			//get the earliest datetime (if present);
1262
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime',
1263
+				array('order_by' => array('DTT_EVT_start' => 'ASC'))) : null;
1264
+
1265
+			if ( ! empty($earliest_dtt)) {
1266
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start',
1267
+					$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
1268
+			} else {
1269
+				//default so let's just use what's been set for the default date-time which is 30 days from now.
1270
+				$template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1271
+					mktime(24, 0, 0, date("m"), date("d") + 29, date("Y")));
1272
+			}
1273
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1274
+		}
1275
+
1276
+		//generate ticket_datetime items
1277
+		if ( ! $default) {
1278
+			$dttrow = 1;
1279
+			foreach ($all_dtts as $dtt) {
1280
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt,
1281
+					$ticket, $ticket_datetimes, $default);
1282
+				$dttrow++;
1283
+			}
1284
+		}
1285
+
1286
+		$prcrow = 1;
1287
+		foreach ($prices as $price) {
1288
+			if ($price->is_base_price()) {
1289
+				$prcrow++;
1290
+				continue;
1291
+			}
1292
+			$show_trash  = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? false : true;
1293
+			$show_create = count($prices) > 1 && count($prices) !== $prcrow ? false : true;
1294
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default,
1295
+				$ticket, $show_trash, $show_create);
1296
+			$prcrow++;
1297
+		}
1298
+
1299
+		//filter $template_args
1300
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1301
+			$template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets,
1302
+			$this->_is_creating_event);
1303
+
1304
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php';
1305
+
1306
+		return EEH_Template::display_template($template, $template_args, true);
1307
+	}
1308
+
1309
+
1310
+	protected function _get_tax_rows($tktrow, $ticket)
1311
+	{
1312
+		$tax_rows      = '';
1313
+		$template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php';
1314
+		$template_args = array();
1315
+		$taxes         = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1316
+		foreach ($taxes as $tax) {
1317
+			$tax_added     = $this->_get_tax_added($tax, $ticket);
1318
+			$template_args = array(
1319
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"',
1320
+				'tax_id'            => $tax->ID(),
1321
+				'tkt_row'           => $tktrow,
1322
+				'tax_label'         => $tax->get('PRC_name'),
1323
+				'tax_added'         => $tax_added,
1324
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1325
+				'tax_amount'        => $tax->get('PRC_amount')
1326
+			);
1327
+			$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1328
+				$template_args, $tktrow, $ticket, $this->_is_creating_event);
1329
+			$tax_rows .= EEH_Template::display_template($template, $template_args, true);
1330
+		}
1331
+
1332
+
1333
+		return $tax_rows;
1334
+	}
1335
+
1336
+
1337
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1338
+	{
1339
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1340
+
1341
+		return $subtotal * $tax->get('PRC_amount') / 100;
1342
+	}
1343
+
1344
+
1345
+	protected function _get_ticket_price_row(
1346
+		$tktrow,
1347
+		$prcrow,
1348
+		$price,
1349
+		$default,
1350
+		$ticket,
1351
+		$show_trash = true,
1352
+		$show_create = true
1353
+	) {
1354
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false;
1355
+		$template_args = array(
1356
+			'tkt_row'               => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1357
+			'PRC_order'             => $default && empty($price) ? 'PRICENUM' : $prcrow,
1358
+			'edit_prices_name'      => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices',
1359
+			'price_type_selector'   => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow,
1360
+				$price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled),
1361
+			'PRC_ID'                => $default && empty($price) ? 0 : $price->ID(),
1362
+			'PRC_is_default'        => $default && empty($price) ? 0 : $price->get('PRC_is_default'),
1363
+			'PRC_name'              => $default && empty($price) ? '' : $price->get('PRC_name'),
1364
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1365
+			'show_plus_or_minus'    => $default && empty($price) ? '' : ' style="display:none;"',
1366
+			'show_plus'             => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''),
1367
+			'show_minus'            => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'),
1368
+			'show_currency_symbol'  => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''),
1369
+			'PRC_amount'            => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount',
1370
+				'localized_float'),
1371
+			'show_percentage'       => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'),
1372
+			'show_trash_icon'       => $show_trash ? '' : ' style="display:none;"',
1373
+			'show_create_button'    => $show_create ? '' : ' style="display:none;"',
1374
+			'PRC_desc'              => $default && empty($price) ? '' : $price->get('PRC_desc'),
1375
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false
1376
+		);
1377
+
1378
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1379
+			$template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create,
1380
+			$this->_is_creating_event);
1381
+
1382
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php';
1383
+
1384
+		return EEH_Template::display_template($template, $template_args, true);
1385
+	}
1386
+
1387
+
1388
+	protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = false)
1389
+	{
1390
+		if ($price->is_base_price()) {
1391
+			return $this->_get_base_price_template($tktrow, $prcrow, $price, $default);
1392
+		} else {
1393
+			return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled);
1394
+		}
1395
+
1396
+	}
1397
+
1398
+
1399
+	protected function _get_base_price_template($tktrow, $prcrow, $price, $default)
1400
+	{
1401
+		$template_args = array(
1402
+			'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1403
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1404
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1405
+			'PRT_name'                  => __('Price', 'event_espresso'),
1406
+			'price_selected_operator'   => '+',
1407
+			'price_selected_is_percent' => 0
1408
+		);
1409
+		$template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php';
1410
+
1411
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1412
+			$template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event);
1413
+
1414
+		return EEH_Template::display_template($template, $template_args, true);
1415
+	}
1416
+
1417
+
1418
+	protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false)
1419
+	{
1420
+		$select_name                = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]';
1421
+		$price_types                = EE_Registry::instance()->load_model('Price_Type')->get_all(array(
1422
+			array(
1423
+				'OR' => array(
1424
+					'PBT_ID'  => '2',
1425
+					'PBT_ID*' => '3'
1426
+				)
1427
+			)
1428
+		));
1429
+		$price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php';
1430
+		$all_price_types            = $default && empty($price) ? array(
1431
+			array(
1432
+				'id'   => 0,
1433
+				'text' => __('Select Modifier', 'event_espresso')
1434
+			)
1435
+		) : array();
1436
+		$selected_price_type_id     = $default && empty($price) ? 0 : $price->type();
1437
+		$price_option_spans         = '';
1438
+		//setup pricetypes for selector
1439
+		foreach ($price_types as $price_type) {
1440
+			$all_price_types[] = array(
1441
+				'id'   => $price_type->ID(),
1442
+				'text' => $price_type->get('PRT_name'),
1443
+			);
1444
+
1445
+			//while we're in the loop let's setup the option spans used by js
1446
+			$spanargs = array(
1447
+				'PRT_ID'         => $price_type->ID(),
1448
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1449
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0
1450
+			);
1451
+			$price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, true);
1452
+		}
1453
+
1454
+		$select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"';
1455
+		$main_name     = $select_name;
1456
+		$select_name   = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name;
1457
+
1458
+		$template_args = array(
1459
+			'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1460
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1461
+			'price_modifier_selector'   => EEH_Form_Fields::select_input($select_name, $all_price_types,
1462
+				$selected_price_type_id, $select_params, 'edit-price-PRT_ID'),
1463
+			'main_name'                 => $main_name,
1464
+			'selected_price_type_id'    => $selected_price_type_id,
1465
+			'price_option_spans'        => $price_option_spans,
1466
+			'price_selected_operator'   => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'),
1467
+			'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0),
1468
+			'disabled'                  => $disabled
1469
+		);
1470
+
1471
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1472
+			$template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event);
1473
+
1474
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php';
1475
+
1476
+		return EEH_Template::display_template($template, $template_args, true);
1477
+	}
1478
+
1479
+
1480
+	protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default)
1481
+	{
1482
+		$tkt_dtts      = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1483
+		$template_args = array(
1484
+			'dtt_row'                  => $default && ! $dtt instanceof EE_Datetime ? 'DTTNUM' : $dttrow,
1485
+			'tkt_row'                  => $default ? 'TICKETNUM' : $tktrow,
1486
+			'ticket_datetime_selected' => in_array($dttrow, $tkt_dtts) ? ' ticket-selected' : '',
1487
+			'ticket_datetime_checked'  => in_array($dttrow, $tkt_dtts) ? ' checked="checked"' : '',
1488
+			'DTT_name'                 => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(true),
1489
+			'tkt_status_class'         => '',
1490
+		);
1491
+
1492
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
1493
+			$template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event);
1494
+		$template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php';
1495
+
1496
+		return EEH_Template::display_template($template, $template_args, true);
1497
+	}
1498
+
1499
+
1500
+	protected function _get_ticket_js_structure($all_dtts, $all_tickets)
1501
+	{
1502
+		$template_args = array(
1503
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row('DTTNUM', null, true, $all_dtts),
1504
+			'default_ticket_row'                       => $this->_get_ticket_row('TICKETNUM', null, array(), array(),
1505
+				true),
1506
+			'default_price_row'                        => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', null,
1507
+				true, null),
1508
+			'default_price_rows'                       => '',
1509
+			'default_base_price_amount'                => 0,
1510
+			'default_base_price_name'                  => '',
1511
+			'default_base_price_description'           => '',
1512
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM',
1513
+				null, true),
1514
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row('DTTNUM', null, array(),
1515
+				array(), true),
1516
+			'existing_available_datetime_tickets_list' => '',
1517
+			'existing_available_ticket_datetimes_list' => '',
1518
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM',
1519
+				null, null, array(), true),
1520
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM',
1521
+				null, null, array(), true)
1522
+		);
1523
+
1524
+		$tktrow = 1;
1525
+		foreach ($all_tickets as $ticket) {
1526
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM',
1527
+				$tktrow, null, $ticket, array(), true);
1528
+			$tktrow++;
1529
+		}
1530
+
1531
+
1532
+		$dttrow = 1;
1533
+		foreach ($all_dtts as $dtt) {
1534
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow,
1535
+				'TICKETNUM', $dtt, null, array(), true);
1536
+			$dttrow++;
1537
+		}
1538
+
1539
+		$default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices();
1540
+		$prcrow         = 1;
1541
+		foreach ($default_prices as $price) {
1542
+			if ($price->is_base_price()) {
1543
+				$template_args['default_base_price_amount']      = $price->get_pretty('PRC_amount', 'localized_float');
1544
+				$template_args['default_base_price_name']        = $price->get('PRC_name');
1545
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
1546
+				$prcrow++;
1547
+				continue;
1548
+			}
1549
+			$show_trash  = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? false : true;
1550
+			$show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? false : true;
1551
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, true,
1552
+				null, $show_trash, $show_create);
1553
+			$prcrow++;
1554
+		}
1555
+
1556
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
1557
+			$template_args, $all_dtts, $all_tickets, $this->_is_creating_event);
1558
+
1559
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php';
1560
+
1561
+		return EEH_Template::display_template($template, $template_args, true);
1562
+	}
1563 1563
 
1564 1564
 
1565 1565
 } //end class espresso_events_Pricing_Hooks
Please login to merge, or discard this patch.