Completed
Branch BUG-9951-10331-8793-pue-fixes (40e696)
by
unknown
27:52 queued 13:57
created
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.
admin/extend/registrations/EE_Event_Registrations_List_Table.class.php 2 patches
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 		$this->_columns = array_merge( $columns, $this->_columns );
88 88
 		$this->_primary_column = '_REG_att_checked_in';
89 89
 		if ( ! empty( $evt_id )
90
-		     && EE_Registry::instance()->CAP->current_user_can(
90
+			 && EE_Registry::instance()->CAP->current_user_can(
91 91
 				'ee_read_registrations',
92 92
 				'espresso_registrations_registrations_reports',
93 93
 				$evt_id
@@ -104,44 +104,44 @@  discard block
 block discarded – undo
104 104
 				),
105 105
 			);
106 106
 		}
107
-        $this->_bottom_buttons['report_filtered'] = array(
108
-            'route'         => 'registrations_checkin_report',
109
-            'extra_request' => array(
110
-                'use_filters' => true,
111
-                'filters'     => array_merge(
112
-                    array(
113
-                        'EVT_ID' => $evt_id,
114
-                    ),
115
-                    array_diff_key(
116
-                        $this->_req_data,
117
-                        array_flip(
118
-                            array(
119
-                                'page',
120
-                                'action',
121
-                                'default_nonce',
122
-                            )
123
-                        )
124
-                    )
125
-                ),
126
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
127
-            ),
128
-        );
107
+		$this->_bottom_buttons['report_filtered'] = array(
108
+			'route'         => 'registrations_checkin_report',
109
+			'extra_request' => array(
110
+				'use_filters' => true,
111
+				'filters'     => array_merge(
112
+					array(
113
+						'EVT_ID' => $evt_id,
114
+					),
115
+					array_diff_key(
116
+						$this->_req_data,
117
+						array_flip(
118
+							array(
119
+								'page',
120
+								'action',
121
+								'default_nonce',
122
+							)
123
+						)
124
+					)
125
+				),
126
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
127
+			),
128
+		);
129 129
 		$this->_sortable_columns = array(
130
-            /**
131
-             * Allows users to change the default sort if they wish.
132
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
133
-             *
134
-             * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
135
-             * change the sorts on any list table involving registration contacts.  If you want to only change the filter
136
-             * for a specific list table you can use the provided reference to this object instance.
137
-             */
130
+			/**
131
+			 * Allows users to change the default sort if they wish.
132
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
133
+			 *
134
+			 * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
135
+			 * change the sorts on any list table involving registration contacts.  If you want to only change the filter
136
+			 * for a specific list table you can use the provided reference to this object instance.
137
+			 */
138 138
 			'ATT_name' => array(
139
-                    'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
140
-                    true,
141
-                    $this
142
-                )
143
-                ? array( 'ATT_lname' => true )
144
-                : array( 'ATT_fname' => true ),
139
+					'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
140
+					true,
141
+					$this
142
+				)
143
+				? array( 'ATT_lname' => true )
144
+				: array( 'ATT_fname' => true ),
145 145
 			'Event'    => array( 'Event.EVT.Name' => false ),
146 146
 		);
147 147
 		$this->_hidden_columns = array();
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 				if ( ! $evt->get_count_of_all_registrations() ) {
201 201
 					continue;
202 202
 				}
203
-                                $evts[] = array(
203
+								$evts[] = array(
204 204
 					'id'    => $evt->ID(),
205 205
 					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt),
206 206
 					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
 			if ( count( $this->_dtts_for_event ) > 1 ) {
225 225
 				$dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' );
226 226
 				foreach ( $this->_dtts_for_event as $dtt ) {
227
-                    $datetime_string = $dtt->name();
228
-                    $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
227
+					$datetime_string = $dtt->name();
228
+					$datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
229 229
 					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
230 230
 					$dtts[ $dtt->ID() ] = $datetime_string;
231 231
 				}
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 		$checkinstatus = $item->check_in_status_for_datetime( $this->_cur_dtt_id );
320 320
 		$nonce = wp_create_nonce( 'checkin_nonce' );
321 321
 		$toggle_active = ! empty ( $this->_cur_dtt_id )
322
-		                 && EE_Registry::instance()->CAP->current_user_can(
322
+						 && EE_Registry::instance()->CAP->current_user_can(
323 323
 			'ee_edit_checkin',
324 324
 			'espresso_registrations_toggle_checkin_status',
325 325
 			$item->ID()
@@ -328,11 +328,11 @@  discard block
 block discarded – undo
328 328
 			: '';
329 329
 		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
330 330
 		return '<span class="checkin-icons checkedin-status-' . $checkinstatus . $toggle_active . '"'
331
-		       . ' data-_regid="' . $item->ID() . '"'
332
-		       . ' data-dttid="' . $this->_cur_dtt_id . '"'
333
-		       . ' data-nonce="' . $nonce . '">'
334
-		       . '</span>'
335
-		       . $mobile_view_content;
331
+			   . ' data-_regid="' . $item->ID() . '"'
332
+			   . ' data-dttid="' . $this->_cur_dtt_id . '"'
333
+			   . ' data-nonce="' . $nonce . '">'
334
+			   . '</span>'
335
+			   . $mobile_view_content;
336 336
 	}
337 337
 
338 338
 
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 			'espresso_registrations_edit_attendee'
358 358
 		)
359 359
 			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
360
-			    . $item->attendee()->full_name()
361
-			    . '</a>'
360
+				. $item->attendee()->full_name()
361
+				. '</a>'
362 362
 			: $item->attendee()->full_name();
363 363
 		$name_link .= $item->count() === 1
364 364
 			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 			? $latest_related_datetime->ID()
394 394
 			: $DTT_ID;
395 395
 		if ( ! empty( $DTT_ID )
396
-		     && EE_Registry::instance()->CAP->current_user_can(
396
+			 && EE_Registry::instance()->CAP->current_user_can(
397 397
 				'ee_read_checkins',
398 398
 				'espresso_registrations_registration_checkins'
399 399
 			)
@@ -493,15 +493,15 @@  discard block
 block discarded – undo
493 493
 				) ? '
494 494
 				<span class="reg-pad-rght">
495 495
 					<a class="status-'
496
-				    . $item->transaction()->status_ID()
497
-				    . '" href="'
498
-				    . $view_txn_lnk_url
499
-				    . '"  title="'
500
-				    . esc_attr__( 'View Transaction', 'event_espresso' )
501
-				    . '">
496
+					. $item->transaction()->status_ID()
497
+					. '" href="'
498
+					. $view_txn_lnk_url
499
+					. '"  title="'
500
+					. esc_attr__( 'View Transaction', 'event_espresso' )
501
+					. '">
502 502
 						'
503
-				    . $item->transaction()->pretty_paid()
504
-				    . '
503
+					. $item->transaction()->pretty_paid()
504
+					. '
505 505
 					</a>
506 506
 				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
507 507
 			}
@@ -534,12 +534,12 @@  discard block
 block discarded – undo
534 534
 				'ee_read_transaction',
535 535
 				'espresso_transactions_view_transaction'
536 536
 			) ? '<a href="'
537
-			    . $view_txn_url
538
-			    . '" title="'
539
-			    . esc_attr__( 'View Transaction', 'event_espresso' )
540
-			    . '"><span class="reg-pad-rght">'
541
-			    . $txn_total
542
-			    . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
537
+				. $view_txn_url
538
+				. '" title="'
539
+				. esc_attr__( 'View Transaction', 'event_espresso' )
540
+				. '"><span class="reg-pad-rght">'
541
+				. $txn_total
542
+				. '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
543 543
 		} else {
544 544
 			return '<span class="reg-pad-rght"></span>';
545 545
 		}
Please login to merge, or discard this patch.
Spacing   +111 added lines, -111 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
 
@@ -42,51 +42,51 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @param \Registrations_Admin_Page $admin_page
44 44
 	 */
45
-	public function __construct( $admin_page ) {
46
-		parent::__construct( $admin_page );
45
+	public function __construct($admin_page) {
46
+		parent::__construct($admin_page);
47 47
 		$this->_status = $this->_admin_page->get_registration_status_array();
48 48
 	}
49 49
 
50 50
 
51 51
 
52 52
 	protected function _setup_data() {
53
-		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( $this->_per_page )
54
-			: $this->_admin_page->get_event_attendees( $this->_per_page, false, true );
53
+		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
54
+			: $this->_admin_page->get_event_attendees($this->_per_page, false, true);
55 55
 		$this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
56 56
 			$this->_per_page,
57 57
 			true
58
-		) : $this->_admin_page->get_event_attendees( $this->_per_page, true, true );
58
+		) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
59 59
 	}
60 60
 
61 61
 
62 62
 
63 63
 	protected function _set_properties() {
64
-		$evt_id = isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : null;
64
+		$evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
65 65
 		$this->_wp_list_args = array(
66
-			'singular' => __( 'registrant', 'event_espresso' ),
67
-			'plural'   => __( 'registrants', 'event_espresso' ),
66
+			'singular' => __('registrant', 'event_espresso'),
67
+			'plural'   => __('registrants', 'event_espresso'),
68 68
 			'ajax'     => true,
69 69
 			'screen'   => $this->_admin_page->get_current_screen()->id,
70 70
 		);
71 71
 		$columns = array();
72 72
 		//$columns['_Reg_Status'] = '';
73
-		if ( ! empty( $evt_id ) ) {
73
+		if ( ! empty($evt_id)) {
74 74
 			$columns['cb'] = '<input type="checkbox" />'; //Render a checkbox instead of text
75 75
 			$this->_has_checkbox_column = true;
76 76
 		}
77 77
 		$this->_columns = array(
78 78
 			'_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
79
-			'ATT_name'            => __( 'Registrant', 'event_espresso' ),
80
-			'ATT_email'           => __( 'Email Address', 'event_espresso' ),
81
-			'Event'               => __( 'Event', 'event_espresso' ),
82
-			'PRC_name'            => __( 'TKT Option', 'event_espresso' ),
83
-			'_REG_final_price'    => __( 'Price', 'event_espresso' ),
84
-			'TXN_paid'            => __( 'Paid', 'event_espresso' ),
85
-			'TXN_total'           => __( 'Total', 'event_espresso' ),
79
+			'ATT_name'            => __('Registrant', 'event_espresso'),
80
+			'ATT_email'           => __('Email Address', 'event_espresso'),
81
+			'Event'               => __('Event', 'event_espresso'),
82
+			'PRC_name'            => __('TKT Option', 'event_espresso'),
83
+			'_REG_final_price'    => __('Price', 'event_espresso'),
84
+			'TXN_paid'            => __('Paid', 'event_espresso'),
85
+			'TXN_total'           => __('Total', 'event_espresso'),
86 86
 		);
87
-		$this->_columns = array_merge( $columns, $this->_columns );
87
+		$this->_columns = array_merge($columns, $this->_columns);
88 88
 		$this->_primary_column = '_REG_att_checked_in';
89
-		if ( ! empty( $evt_id )
89
+		if ( ! empty($evt_id)
90 90
 		     && EE_Registry::instance()->CAP->current_user_can(
91 91
 				'ee_read_registrations',
92 92
 				'espresso_registrations_registrations_reports',
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 					'extra_request' =>
100 100
 						array(
101 101
 							'EVT_ID'     => $evt_id,
102
-							'return_url' => urlencode( "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" ),
102
+							'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
103 103
 						),
104 104
 				),
105 105
 			);
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
                     true,
141 141
                     $this
142 142
                 )
143
-                ? array( 'ATT_lname' => true )
144
-                : array( 'ATT_fname' => true ),
145
-			'Event'    => array( 'Event.EVT.Name' => false ),
143
+                ? array('ATT_lname' => true)
144
+                : array('ATT_fname' => true),
145
+			'Event'    => array('Event.EVT.Name' => false),
146 146
 		);
147 147
 		$this->_hidden_columns = array();
148
-		$this->_evt = EEM_Event::instance()->get_one_by_ID( $evt_id );
148
+		$this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
149 149
 		$this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
150 150
 	}
151 151
 
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
 	 * @param \EE_Registration $item
156 156
 	 * @return string
157 157
 	 */
158
-	protected function _get_row_class( $item ) {
159
-		$class = parent::_get_row_class( $item );
158
+	protected function _get_row_class($item) {
159
+		$class = parent::_get_row_class($item);
160 160
 		//add status class
161
-		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
162
-		if ( $this->_has_checkbox_column ) {
161
+		$class .= ' ee-status-strip reg-status-'.$item->status_ID();
162
+		if ($this->_has_checkbox_column) {
163 163
 			$class .= ' has-checkbox-column';
164 164
 		}
165 165
 		return $class;
@@ -173,61 +173,61 @@  discard block
 block discarded – undo
173 173
 	 */
174 174
 	protected function _get_table_filters() {
175 175
 		$filters = $where = array();
176
-		$current_EVT_ID = isset( $this->_req_data['event_id'] ) ? (int) $this->_req_data['event_id'] : 0;
177
-		if ( empty( $this->_dtts_for_event ) || count( $this->_dtts_for_event ) === 1 ) {
176
+		$current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
177
+		if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
178 178
 			//this means we don't have an event so let's setup a filter dropdown for all the events to select
179 179
 			//note possible capability restrictions
180
-			if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_events', 'get_events' ) ) {
181
-				$where['status**'] = array( '!=', 'private' );
180
+			if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
181
+				$where['status**'] = array('!=', 'private');
182 182
 			}
183
-			if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) {
183
+			if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
184 184
 				$where['EVT_wp_user'] = get_current_user_id();
185 185
 			}
186 186
 			$events = EEM_Event::instance()->get_all(
187 187
 				array(
188 188
 					$where,
189
-					'order_by' => array( 'Datetime.DTT_EVT_start' => 'DESC' ),
189
+					'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
190 190
 				)
191 191
 			);
192 192
 			$evts[] = array(
193 193
 				'id'   => 0,
194
-				'text' => __( 'To toggle Check-in status, select an event', 'event_espresso' ),
194
+				'text' => __('To toggle Check-in status, select an event', 'event_espresso'),
195 195
 			);
196 196
 			$checked = 'checked';
197 197
 			/** @var EE_Event $evt */
198
-			foreach ( $events as $evt ) {
198
+			foreach ($events as $evt) {
199 199
 				//any registrations for this event?
200
-				if ( ! $evt->get_count_of_all_registrations() ) {
200
+				if ( ! $evt->get_count_of_all_registrations()) {
201 201
 					continue;
202 202
 				}
203 203
                                 $evts[] = array(
204 204
 					'id'    => $evt->ID(),
205
-					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt),
205
+					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get('EVT_name'), $evt),
206 206
 					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
207 207
 				);
208
-				if ( $evt->ID() === $current_EVT_ID && $evt->is_expired() ) {
208
+				if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
209 209
 					$checked = '';
210 210
 				}
211 211
 			}
212 212
 			$event_filter = '<div class="ee-event-filter">';
213
-			$event_filter .= EEH_Form_Fields::select_input( 'event_id', $evts, $current_EVT_ID );
213
+			$event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
214 214
 			$event_filter .= '<span class="ee-event-filter-toggle">';
215
-			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
216
-			$event_filter .= __( 'Hide Expired Events', 'event_espresso' );
215
+			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> ';
216
+			$event_filter .= __('Hide Expired Events', 'event_espresso');
217 217
 			$event_filter .= '</span>';
218 218
 			$event_filter .= '</div>';
219 219
 			$filters[] = $event_filter;
220 220
 		}
221
-		if ( ! empty( $this->_dtts_for_event ) ) {
221
+		if ( ! empty($this->_dtts_for_event)) {
222 222
 			//DTT datetimes filter
223
-			$this->_cur_dtt_id = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0;
224
-			if ( count( $this->_dtts_for_event ) > 1 ) {
225
-				$dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' );
226
-				foreach ( $this->_dtts_for_event as $dtt ) {
223
+			$this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
224
+			if (count($this->_dtts_for_event) > 1) {
225
+				$dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso');
226
+				foreach ($this->_dtts_for_event as $dtt) {
227 227
                     $datetime_string = $dtt->name();
228
-                    $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
229
-					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
230
-					$dtts[ $dtt->ID() ] = $datetime_string;
228
+                    $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : '';
229
+					$datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string;
230
+					$dtts[$dtt->ID()] = $datetime_string;
231 231
 				}
232 232
 				$input = new EE_Select_Input(
233 233
 					$dtts,
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 					)
239 239
 				);
240 240
 				$filters[] = $input->get_html_for_input();
241
-				$filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
241
+				$filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">';
242 242
 			}
243 243
 		}
244 244
 		return $filters;
@@ -257,22 +257,22 @@  discard block
 block discarded – undo
257 257
 	 * @throws \EE_Error
258 258
 	 */
259 259
 	protected function _get_total_event_attendees() {
260
-		$EVT_ID = isset( $this->_req_data['event_id'] ) ? absint( $this->_req_data['event_id'] ) : false;
260
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
261 261
 		$DTT_ID = $this->_cur_dtt_id;
262 262
 		$query_params = array();
263
-		if ( $EVT_ID ) {
263
+		if ($EVT_ID) {
264 264
 			$query_params[0]['EVT_ID'] = $EVT_ID;
265 265
 		}
266 266
 		//if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
267
-		if ( $DTT_ID ) {
267
+		if ($DTT_ID) {
268 268
 			$query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
269 269
 		}
270 270
 		$status_ids_array = apply_filters(
271 271
 			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
272
-			array( EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved )
272
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
273 273
 		);
274
-		$query_params[0]['STS_ID'] = array( 'IN', $status_ids_array );
275
-		return EEM_Registration::instance()->count( $query_params );
274
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
275
+		return EEM_Registration::instance()->count($query_params);
276 276
 	}
277 277
 
278 278
 
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 	 * @param \EE_Registration $item
282 282
 	 * @return string
283 283
 	 */
284
-	public function column__Reg_Status( EE_Registration $item ) {
285
-		return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
284
+	public function column__Reg_Status(EE_Registration $item) {
285
+		return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>';
286 286
 	}
287 287
 
288 288
 
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 	 * @return string
293 293
 	 * @throws \EE_Error
294 294
 	 */
295
-	public function column_cb( $item ) {
296
-		return sprintf( '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID() );
295
+	public function column_cb($item) {
296
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
297 297
 	}
298 298
 
299 299
 
@@ -305,20 +305,20 @@  discard block
 block discarded – undo
305 305
 	 * @return string
306 306
 	 * @throws \EE_Error
307 307
 	 */
308
-	public function column__REG_att_checked_in( EE_Registration $item ) {
308
+	public function column__REG_att_checked_in(EE_Registration $item) {
309 309
 		$attendee = $item->attendee();
310 310
 		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
311 311
 
312
-		if ( $this->_cur_dtt_id === 0 && count( $this->_dtts_for_event ) === 1 ) {
312
+		if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
313 313
 			$latest_related_datetime = $item->get_latest_related_datetime();
314
-			if ( $latest_related_datetime instanceof EE_Datetime ) {
314
+			if ($latest_related_datetime instanceof EE_Datetime) {
315 315
 				$this->_cur_dtt_id = $latest_related_datetime->ID();
316 316
 			}
317 317
 		}
318 318
 
319
-		$checkinstatus = $item->check_in_status_for_datetime( $this->_cur_dtt_id );
320
-		$nonce = wp_create_nonce( 'checkin_nonce' );
321
-		$toggle_active = ! empty ( $this->_cur_dtt_id )
319
+		$checkinstatus = $item->check_in_status_for_datetime($this->_cur_dtt_id);
320
+		$nonce = wp_create_nonce('checkin_nonce');
321
+		$toggle_active = ! empty ($this->_cur_dtt_id)
322 322
 		                 && EE_Registry::instance()->CAP->current_user_can(
323 323
 			'ee_edit_checkin',
324 324
 			'espresso_registrations_toggle_checkin_status',
@@ -326,11 +326,11 @@  discard block
 block discarded – undo
326 326
 		)
327 327
 			? ' clickable trigger-checkin'
328 328
 			: '';
329
-		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
330
-		return '<span class="checkin-icons checkedin-status-' . $checkinstatus . $toggle_active . '"'
331
-		       . ' data-_regid="' . $item->ID() . '"'
332
-		       . ' data-dttid="' . $this->_cur_dtt_id . '"'
333
-		       . ' data-nonce="' . $nonce . '">'
329
+		$mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>';
330
+		return '<span class="checkin-icons checkedin-status-'.$checkinstatus.$toggle_active.'"'
331
+		       . ' data-_regid="'.$item->ID().'"'
332
+		       . ' data-dttid="'.$this->_cur_dtt_id.'"'
333
+		       . ' data-nonce="'.$nonce.'">'
334 334
 		       . '</span>'
335 335
 		       . $mobile_view_content;
336 336
 	}
@@ -342,21 +342,21 @@  discard block
 block discarded – undo
342 342
 	 * @return mixed|string|void
343 343
 	 * @throws \EE_Error
344 344
 	 */
345
-	public function column_ATT_name( EE_Registration $item ) {
345
+	public function column_ATT_name(EE_Registration $item) {
346 346
 		$attendee = $item->attendee();
347
-		if ( ! $attendee instanceof EE_Attendee ) {
348
-			return __( 'No contact record for this registration.', 'event_espresso' );
347
+		if ( ! $attendee instanceof EE_Attendee) {
348
+			return __('No contact record for this registration.', 'event_espresso');
349 349
 		}
350 350
 		// edit attendee link
351 351
 		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
352
-			array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ),
352
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
353 353
 			REG_ADMIN_URL
354 354
 		);
355 355
 		$name_link = EE_Registry::instance()->CAP->current_user_can(
356 356
 			'ee_edit_contacts',
357 357
 			'espresso_registrations_edit_attendee'
358 358
 		)
359
-			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
359
+			? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
360 360
 			    . $item->attendee()->full_name()
361 361
 			    . '</a>'
362 362
 			: $item->attendee()->full_name();
@@ -364,10 +364,10 @@  discard block
 block discarded – undo
364 364
 			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
365 365
 			: '';
366 366
 		//add group details
367
-		$name_link .= '&nbsp;' . sprintf( __( '(%s of %s)', 'event_espresso' ), $item->count(), $item->group_size() );
367
+		$name_link .= '&nbsp;'.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
368 368
 		//add regcode
369 369
 		$link = EE_Admin_Page::add_query_args_and_nonce(
370
-			array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ),
370
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
371 371
 			REG_ADMIN_URL
372 372
 		);
373 373
 		$name_link .= '<br>';
@@ -376,37 +376,37 @@  discard block
 block discarded – undo
376 376
 			'view_registration',
377 377
 			$item->ID()
378 378
 		)
379
-			? '<a href="' . $link . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
379
+			? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
380 380
 			  . $item->reg_code()
381 381
 			  . '</a>'
382 382
 			: $item->reg_code();
383 383
 		//status
384 384
 		$name_link .= '<br><span class="ee-status-text-small">';
385
-		$name_link .= EEH_Template::pretty_status( $item->status_ID(), false, 'sentence' );
385
+		$name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
386 386
 		$name_link .= '</span>';
387 387
 		$actions = array();
388 388
 		$DTT_ID = $this->_cur_dtt_id;
389
-		$latest_related_datetime = empty( $DTT_ID ) && ! empty( $this->_req_data['event_id'] ) && $item instanceof EE_Registration
389
+		$latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
390 390
 			? $item->get_latest_related_datetime()
391 391
 			: null;
392 392
 		$DTT_ID = $latest_related_datetime instanceof EE_Datetime
393 393
 			? $latest_related_datetime->ID()
394 394
 			: $DTT_ID;
395
-		if ( ! empty( $DTT_ID )
395
+		if ( ! empty($DTT_ID)
396 396
 		     && EE_Registry::instance()->CAP->current_user_can(
397 397
 				'ee_read_checkins',
398 398
 				'espresso_registrations_registration_checkins'
399 399
 			)
400 400
 		) {
401 401
 			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
402
-				array( 'action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID )
402
+				array('action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID)
403 403
 			);
404
-			$actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' . esc_attr__(
404
+			$actions['checkin'] = '<a href="'.$checkin_list_url.'" title="'.esc_attr__(
405 405
 					'View all the check-ins/checkouts for this registrant',
406 406
 					'event_espresso'
407
-				) . '">' . __( 'View', 'event_espresso' ) . '</a>';
407
+				).'">'.__('View', 'event_espresso').'</a>';
408 408
 		}
409
-		return ! empty( $DTT_ID ) ? sprintf( '%1$s %2$s', $name_link, $this->row_actions( $actions ) ) : $name_link;
409
+		return ! empty($DTT_ID) ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions)) : $name_link;
410 410
 	}
411 411
 
412 412
 
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 	 * @param \EE_Registration $item
416 416
 	 * @return string
417 417
 	 */
418
-	public function column_ATT_email( EE_Registration $item ) {
418
+	public function column_ATT_email(EE_Registration $item) {
419 419
 		$attendee = $item->attendee();
420 420
 		return $attendee instanceof EE_Attendee ? $attendee->email() : '';
421 421
 	}
@@ -427,22 +427,22 @@  discard block
 block discarded – undo
427 427
 	 * @return bool|string
428 428
 	 * @throws \EE_Error
429 429
 	 */
430
-	public function column_Event( EE_Registration $item ) {
430
+	public function column_Event(EE_Registration $item) {
431 431
 		try {
432 432
 			$event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
433 433
 			$chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
434
-				array( 'action' => 'event_registrations', 'event_id' => $event->ID() ),
434
+				array('action' => 'event_registrations', 'event_id' => $event->ID()),
435 435
 				REG_ADMIN_URL
436 436
 			);
437 437
 			$event_label = EE_Registry::instance()->CAP->current_user_can(
438 438
 				'ee_read_checkins',
439 439
 				'espresso_registrations_registration_checkins'
440
-			) ? '<a href="' . $chkin_lnk_url . '" title="' . esc_attr__(
440
+			) ? '<a href="'.$chkin_lnk_url.'" title="'.esc_attr__(
441 441
 					'View Checkins for this Event',
442 442
 					'event_espresso'
443
-				) . '">' . $event->name() . '</a>' : $event->name();
444
-		} catch ( \EventEspresso\core\exceptions\EntityNotFoundException $e ) {
445
-			$event_label = esc_html__( 'Unknown', 'event_espresso' );
443
+				).'">'.$event->name().'</a>' : $event->name();
444
+		} catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
445
+			$event_label = esc_html__('Unknown', 'event_espresso');
446 446
 		}
447 447
 		return $event_label;
448 448
 	}
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 	 * @param \EE_Registration $item
454 454
 	 * @return mixed|string|void
455 455
 	 */
456
-	public function column_PRC_name( EE_Registration $item ) {
457
-		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __( "Unknown", "event_espresso" );
456
+	public function column_PRC_name(EE_Registration $item) {
457
+		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso");
458 458
 	}
459 459
 
460 460
 
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
 	 * @param \EE_Registration $item
466 466
 	 * @return string
467 467
 	 */
468
-	public function column__REG_final_price( EE_Registration $item ) {
469
-		return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
468
+	public function column__REG_final_price(EE_Registration $item) {
469
+		return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>';
470 470
 	}
471 471
 
472 472
 
@@ -478,13 +478,13 @@  discard block
 block discarded – undo
478 478
 	 * @return string
479 479
 	 * @throws \EE_Error
480 480
 	 */
481
-	public function column_TXN_paid( EE_Registration $item ) {
482
-		if ( $item->count() === 1 ) {
483
-			if ( $item->transaction()->paid() >= $item->transaction()->total() ) {
481
+	public function column_TXN_paid(EE_Registration $item) {
482
+		if ($item->count() === 1) {
483
+			if ($item->transaction()->paid() >= $item->transaction()->total()) {
484 484
 				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
485 485
 			} else {
486 486
 				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
487
-					array( 'action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID() ),
487
+					array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
488 488
 					TXN_ADMIN_URL
489 489
 				);
490 490
 				return EE_Registry::instance()->CAP->current_user_can(
@@ -497,13 +497,13 @@  discard block
 block discarded – undo
497 497
 				    . '" href="'
498 498
 				    . $view_txn_lnk_url
499 499
 				    . '"  title="'
500
-				    . esc_attr__( 'View Transaction', 'event_espresso' )
500
+				    . esc_attr__('View Transaction', 'event_espresso')
501 501
 				    . '">
502 502
 						'
503 503
 				    . $item->transaction()->pretty_paid()
504 504
 				    . '
505 505
 					</a>
506
-				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
506
+				<span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
507 507
 			}
508 508
 		} else {
509 509
 			return '<span class="reg-pad-rght"></span>';
@@ -519,13 +519,13 @@  discard block
 block discarded – undo
519 519
 	 * @return string
520 520
 	 * @throws \EE_Error
521 521
 	 */
522
-	public function column_TXN_total( EE_Registration $item ) {
522
+	public function column_TXN_total(EE_Registration $item) {
523 523
 		$txn = $item->transaction();
524
-		$view_txn_url = add_query_arg( array( 'action' => 'view_transaction', 'TXN_ID' => $txn->ID() ), TXN_ADMIN_URL );
525
-		if ( $item->get( 'REG_count' ) === 1 ) {
524
+		$view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
525
+		if ($item->get('REG_count') === 1) {
526 526
 			$line_total_obj = $txn->total_line_item();
527 527
 			$txn_total = $line_total_obj instanceof EE_Line_Item
528
-				? $line_total_obj->get_pretty( 'LIN_total' )
528
+				? $line_total_obj->get_pretty('LIN_total')
529 529
 				: __(
530 530
 					'View Transaction',
531 531
 					'event_espresso'
@@ -536,10 +536,10 @@  discard block
 block discarded – undo
536 536
 			) ? '<a href="'
537 537
 			    . $view_txn_url
538 538
 			    . '" title="'
539
-			    . esc_attr__( 'View Transaction', 'event_espresso' )
539
+			    . esc_attr__('View Transaction', 'event_espresso')
540 540
 			    . '"><span class="reg-pad-rght">'
541 541
 			    . $txn_total
542
-			    . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
542
+			    . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>';
543 543
 		} else {
544 544
 			return '<span class="reg-pad-rght"></span>';
545 545
 		}
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   +18 added lines, -18 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 : ?>
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	</td>
38 38
 	<!--<td><span class="ticket-display-row-TKT_price"><?php //echo $TKT_price; ?></span></td>-->
39 39
 	<td><span class="ticket-display-row-TKT_sold"><?php echo $TKT_sold; ?></span></td>
40
-    <?php if(WP_DEBUG):  // for now we are only showing reserved counts if WP_DEBUG is on?>
40
+    <?php if (WP_DEBUG):  // for now we are only showing reserved counts if WP_DEBUG is on?>
41 41
 	<td><span class="ticket-display-row-TKT_reserved"><?php echo $TKT_reserved; ?></span></td>
42 42
     <?php endif; ?>
43 43
     <td><span class="ticket-display-row-TKT_registrations"><?php echo $TKT_registrations; ?></span></td>
@@ -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.
core/business/EE_Registration_Processor.class.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 			}
216 216
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
217 217
 			if ( ! EE_Processor_Base::$IPN ) {
218
-                // otherwise, send out notifications
218
+				// otherwise, send out notifications
219 219
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
220 220
 			}
221 221
 			// DEBUG LOG
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 			}
263 263
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
264 264
 			if ( ! EE_Processor_Base::$IPN ) {
265
-                // otherwise, send out notifications
265
+				// otherwise, send out notifications
266 266
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
267 267
 			}
268 268
 			// DEBUG LOG
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 			}
350 350
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
351 351
 			if ( ! EE_Processor_Base::$IPN ) {
352
-                // otherwise, send out notifications
352
+				// otherwise, send out notifications
353 353
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
354 354
 			}
355 355
 			// DEBUG LOG
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
 			// 	false,
391 391
 			// 	'EE_Transaction: ' . $registration->transaction()->ID()
392 392
 			// );
393
-            if ( ! $registration->is_primary_registrant()) {
394
-                return;
395
-            }
396
-            do_action(
393
+			if ( ! $registration->is_primary_registrant()) {
394
+				return;
395
+			}
396
+			do_action(
397 397
 				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
398 398
 				$registration,
399 399
 				$additional_details
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 		// set new  REG_Status
429 429
 		$this->set_new_reg_status( $registration->ID(), $registration->status_ID() );
430 430
 		return $this->reg_status_updated( $registration->ID() )
431
-		       && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
431
+			   && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
432 432
 			? true
433 433
 			: false;
434 434
 	}
@@ -508,15 +508,15 @@  discard block
 block discarded – undo
508 508
 
509 509
 
510 510
 
511
-    /**
512
-     * update_registration_after_being_canceled_or_declined
513
-     *
514
-     * @param \EE_Registration $registration
515
-     * @param array            $closed_reg_statuses
516
-     * @param bool             $update_reg
517
-     * @return bool
518
-     * @throws \EE_Error
519
-     */
511
+	/**
512
+	 * update_registration_after_being_canceled_or_declined
513
+	 *
514
+	 * @param \EE_Registration $registration
515
+	 * @param array            $closed_reg_statuses
516
+	 * @param bool             $update_reg
517
+	 * @return bool
518
+	 * @throws \EE_Error
519
+	 */
520 520
 	public function update_registration_after_being_canceled_or_declined(
521 521
 		EE_Registration $registration,
522 522
 		$closed_reg_statuses = array(),
@@ -524,14 +524,14 @@  discard block
 block discarded – undo
524 524
 	) {
525 525
 		// these reg statuses should not be considered in any calculations involving monies owing
526 526
 		$closed_reg_statuses = ! empty( $closed_reg_statuses )
527
-            ? $closed_reg_statuses
527
+			? $closed_reg_statuses
528 528
 			: EEM_Registration::closed_reg_statuses();
529 529
 		if ( ! in_array( $registration->status_ID(), $closed_reg_statuses, true ) ) {
530 530
 			return false;
531 531
 		}
532
-        // release a reserved ticket by decrementing ticket and datetime reserved values
533
-        $registration->release_reserved_ticket(true);
534
-        $registration->set_final_price(0);
532
+		// release a reserved ticket by decrementing ticket and datetime reserved values
533
+		$registration->release_reserved_ticket(true);
534
+		$registration->set_final_price(0);
535 535
 		if ( $update_reg ) {
536 536
 			$registration->save();
537 537
 		}
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\domain\entities\RegUrlLink;
4 4
 use EventEspresso\core\domain\services\registration\CreateRegistrationService;
5 5
 
6
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
7
-EE_Registry::instance()->load_class( 'Processor_Base' );
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
7
+EE_Registry::instance()->load_class('Processor_Base');
8 8
 
9 9
 /**
10 10
  * Class EE_Registration_Processor
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public static function instance() {
68 68
 		// check if class object is instantiated
69
-		if ( ! self::$_instance instanceof EE_Registration_Processor ) {
69
+		if ( ! self::$_instance instanceof EE_Registration_Processor) {
70 70
 			self::$_instance = new self();
71 71
 		}
72 72
 		return self::$_instance;
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 * @param int $REG_ID
87 87
 	 * @return string
88 88
 	 */
89
-	public function old_reg_status( $REG_ID ) {
90
-		return isset( $this->_old_reg_status[ $REG_ID ] ) ? $this->_old_reg_status[ $REG_ID ] : null;
89
+	public function old_reg_status($REG_ID) {
90
+		return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null;
91 91
 	}
92 92
 
93 93
 
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 * @param int $REG_ID
97 97
 	 * @param string $old_reg_status
98 98
 	 */
99
-	public function set_old_reg_status( $REG_ID, $old_reg_status ) {
99
+	public function set_old_reg_status($REG_ID, $old_reg_status) {
100 100
 		// only set the first time
101
-		if ( ! isset( $this->_old_reg_status[ $REG_ID ] ) ) {
102
-			$this->_old_reg_status[ $REG_ID ] = $old_reg_status;
101
+		if ( ! isset($this->_old_reg_status[$REG_ID])) {
102
+			$this->_old_reg_status[$REG_ID] = $old_reg_status;
103 103
 		}
104 104
 	}
105 105
 
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	 * @param int $REG_ID
110 110
 	 * @return string
111 111
 	 */
112
-	public function new_reg_status( $REG_ID ) {
113
-		return isset( $this->_new_reg_status[ $REG_ID ] ) ? $this->_new_reg_status[ $REG_ID ] : null;
112
+	public function new_reg_status($REG_ID) {
113
+		return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null;
114 114
 	}
115 115
 
116 116
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 * @param int $REG_ID
120 120
 	 * @param string $new_reg_status
121 121
 	 */
122
-	public function set_new_reg_status( $REG_ID, $new_reg_status ) {
123
-		$this->_new_reg_status[ $REG_ID ] = $new_reg_status;
122
+	public function set_new_reg_status($REG_ID, $new_reg_status) {
123
+		$this->_new_reg_status[$REG_ID] = $new_reg_status;
124 124
 	}
125 125
 
126 126
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param int $REG_ID
132 132
 	 * @return bool
133 133
 	 */
134
-	public function reg_status_updated( $REG_ID ) {
135
-		return $this->new_reg_status( $REG_ID ) !== $this->old_reg_status( $REG_ID ) ? true : false;
134
+	public function reg_status_updated($REG_ID) {
135
+		return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID) ? true : false;
136 136
 	}
137 137
 
138 138
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 	 * @param \EE_Registration $registration
142 142
 	 * @throws \EE_Error
143 143
 	 */
144
-	public function update_registration_status_and_trigger_notifications( \EE_Registration $registration ) {
145
-		$this->toggle_incomplete_registration_status_to_default( $registration, false );
146
-		$this->toggle_registration_status_for_default_approved_events( $registration, false );
147
-		$this->toggle_registration_status_if_no_monies_owing( $registration, false );
144
+	public function update_registration_status_and_trigger_notifications(\EE_Registration $registration) {
145
+		$this->toggle_incomplete_registration_status_to_default($registration, false);
146
+		$this->toggle_registration_status_for_default_approved_events($registration, false);
147
+		$this->toggle_registration_status_if_no_monies_owing($registration, false);
148 148
 		$registration->save();
149 149
 		// trigger notifications
150
-		$this->trigger_registration_update_notifications( $registration );
150
+		$this->trigger_registration_update_notifications($registration);
151 151
 	}
152 152
 
153 153
 
@@ -162,18 +162,18 @@  discard block
 block discarded – undo
162 162
 	 * @return boolean
163 163
 	 * @throws \EE_Error
164 164
 	 */
165
-	public function manually_update_registration_status( EE_Registration $registration, $new_reg_status = '', $save = true ) {
165
+	public function manually_update_registration_status(EE_Registration $registration, $new_reg_status = '', $save = true) {
166 166
 		// set initial REG_Status
167
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
167
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
168 168
 		// set incoming REG_Status
169
-		$this->set_new_reg_status( $registration->ID(), $new_reg_status );
169
+		$this->set_new_reg_status($registration->ID(), $new_reg_status);
170 170
 		// toggle reg status but only if it has changed and the user can do so
171 171
 		if (
172
-			$this->reg_status_updated( $registration->ID() ) &&
173
-			EE_Registry::instance()->CAP->current_user_can( 'ee_edit_registration', 'toggle_registration_status', $registration->ID() )
172
+			$this->reg_status_updated($registration->ID()) &&
173
+			EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'toggle_registration_status', $registration->ID())
174 174
 		) {
175 175
 			// change status to new value
176
-			if ( $registration->set_status( $this->new_reg_status( $registration->ID() ) ) && $save ) {
176
+			if ($registration->set_status($this->new_reg_status($registration->ID())) && $save) {
177 177
 				$registration->save();
178 178
 			}
179 179
 			return TRUE;
@@ -193,30 +193,30 @@  discard block
 block discarded – undo
193 193
 	 * @return void
194 194
 	 * @throws \EE_Error
195 195
 	 */
196
-	public function toggle_incomplete_registration_status_to_default( EE_Registration $registration, $save = TRUE ) {
196
+	public function toggle_incomplete_registration_status_to_default(EE_Registration $registration, $save = TRUE) {
197 197
 		$existing_reg_status = $registration->status_ID();
198 198
 		// set initial REG_Status
199
-		$this->set_old_reg_status( $registration->ID(), $existing_reg_status );
199
+		$this->set_old_reg_status($registration->ID(), $existing_reg_status);
200 200
 		// is the registration currently incomplete ?
201
-		if ( $registration->status_ID() === EEM_Registration::status_id_incomplete ) {
201
+		if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
202 202
 			// grab default reg status for the event, if set
203 203
 			$event_default_registration_status = $registration->event()->default_registration_status();
204 204
 			// if no default reg status is set for the event, then use the global value
205
-			$STS_ID = ! empty( $event_default_registration_status )
205
+			$STS_ID = ! empty($event_default_registration_status)
206 206
 				? $event_default_registration_status
207 207
 				: EE_Registry::instance()->CFG->registration->default_STS_ID;
208 208
 			// if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
209 209
 			$STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment : $STS_ID;
210 210
 			// set incoming REG_Status
211
-			$this->set_new_reg_status( $registration->ID(), $STS_ID );
212
-			$registration->set_status( $STS_ID );
213
-			if ( $save ) {
211
+			$this->set_new_reg_status($registration->ID(), $STS_ID);
212
+			$registration->set_status($STS_ID);
213
+			if ($save) {
214 214
 				$registration->save();
215 215
 			}
216 216
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
217
-			if ( ! EE_Processor_Base::$IPN ) {
217
+			if ( ! EE_Processor_Base::$IPN) {
218 218
                 // otherwise, send out notifications
219
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
219
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
220 220
 			}
221 221
 			// DEBUG LOG
222 222
 			//$this->log(
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 	 * @return boolean
242 242
 	 * @throws \EE_Error
243 243
 	 */
244
-	public function toggle_registration_status_for_default_approved_events( EE_Registration $registration, $save = TRUE ) {
244
+	public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = TRUE) {
245 245
 		$reg_status = $registration->status_ID();
246 246
 		// set initial REG_Status
247
-		$this->set_old_reg_status( $registration->ID(), $reg_status );
247
+		$this->set_old_reg_status($registration->ID(), $reg_status);
248 248
 		// if not already, toggle reg status to approved IF the event default reg status is approved
249 249
 		// ( as long as the registration wasn't cancelled or declined at some point )
250 250
 		if (
@@ -254,16 +254,16 @@  discard block
 block discarded – undo
254 254
 			$registration->event()->default_registration_status() === EEM_Registration::status_id_approved
255 255
 		) {
256 256
 			// set incoming REG_Status
257
-			$this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved );
257
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
258 258
 			// toggle status to approved
259
-			$registration->set_status( EEM_Registration::status_id_approved );
260
-			if ( $save ) {
259
+			$registration->set_status(EEM_Registration::status_id_approved);
260
+			if ($save) {
261 261
 				$registration->save();
262 262
 			}
263 263
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
264
-			if ( ! EE_Processor_Base::$IPN ) {
264
+			if ( ! EE_Processor_Base::$IPN) {
265 265
                 // otherwise, send out notifications
266
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
266
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
267 267
 			}
268 268
 			// DEBUG LOG
269 269
 			//$this->log(
@@ -291,19 +291,19 @@  discard block
 block discarded – undo
291 291
 	 * @return bool
292 292
 	 * @throws \EE_Error
293 293
 	 */
294
-	public function toggle_registration_status_if_no_monies_owing( EE_Registration $registration, $save = TRUE, $additional_details = array() ) {
294
+	public function toggle_registration_status_if_no_monies_owing(EE_Registration $registration, $save = TRUE, $additional_details = array()) {
295 295
 		// set initial REG_Status
296
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
296
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
297 297
 		//EEH_Debug_Tools::printr( $additional_details, '$additional_details', __FILE__, __LINE__ );
298 298
 		// was a payment just made ?
299 299
 		if (
300
-			isset( $additional_details[ 'payment_updates' ], $additional_details[ 'last_payment' ] ) &&
301
-			$additional_details[ 'payment_updates' ] &&
302
-			$additional_details[ 'last_payment' ] instanceof EE_Payment
300
+			isset($additional_details['payment_updates'], $additional_details['last_payment']) &&
301
+			$additional_details['payment_updates'] &&
302
+			$additional_details['last_payment'] instanceof EE_Payment
303 303
 		) {
304
-			$payment = $additional_details[ 'last_payment' ];
304
+			$payment = $additional_details['last_payment'];
305 305
 			$total_paid = 0;
306
-			foreach ( self::$_amount_paid as $reg => $amount_paid ) {
306
+			foreach (self::$_amount_paid as $reg => $amount_paid) {
307 307
 				$total_paid += $amount_paid;
308 308
 			}
309 309
 		} else {
@@ -327,30 +327,30 @@  discard block
 block discarded – undo
327 327
 					$registration->transaction()->is_completed() ||
328 328
 					$registration->transaction()->is_overpaid() ||
329 329
 					$registration->transaction()->is_free() ||
330
-					apply_filters( 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration )
330
+					apply_filters('FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration)
331 331
 				) || (
332 332
 					$payment instanceof EE_Payment &&
333 333
 					$payment->is_approved() &&
334 334
 					// this specific registration has not yet been paid for
335
-					! isset( self::$_amount_paid[ $registration->ID() ] ) &&
335
+					! isset(self::$_amount_paid[$registration->ID()]) &&
336 336
 					// payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
337 337
 					$payment->amount() - $total_paid >= $registration->final_price()
338 338
 				)
339 339
 			)
340 340
 		) {
341 341
 			// mark as paid
342
-			self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
342
+			self::$_amount_paid[$registration->ID()] = $registration->final_price();
343 343
 			// track new REG_Status
344
-			$this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved );
344
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
345 345
 			// toggle status to approved
346
-			$registration->set_status( EEM_Registration::status_id_approved );
347
-			if ( $save ) {
346
+			$registration->set_status(EEM_Registration::status_id_approved);
347
+			if ($save) {
348 348
 				$registration->save();
349 349
 			}
350 350
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
351
-			if ( ! EE_Processor_Base::$IPN ) {
351
+			if ( ! EE_Processor_Base::$IPN) {
352 352
                 // otherwise, send out notifications
353
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
353
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
354 354
 			}
355 355
 			// DEBUG LOG
356 356
 			//$this->log(
@@ -376,10 +376,10 @@  discard block
 block discarded – undo
376 376
 	 * @param array 	$additional_details
377 377
 	 * @return void
378 378
 	 */
379
-	public function trigger_registration_update_notifications( $registration, $additional_details = array() ) {
379
+	public function trigger_registration_update_notifications($registration, $additional_details = array()) {
380 380
 		try {
381
-			if ( ! $registration instanceof EE_Registration ) {
382
-				throw new EE_Error( __( 'An invalid registration was received.', 'event_espresso' ) );
381
+			if ( ! $registration instanceof EE_Registration) {
382
+				throw new EE_Error(__('An invalid registration was received.', 'event_espresso'));
383 383
 			}
384 384
 			// EE_Registry::instance()->load_helper( 'Debug_Tools' );
385 385
 			// EEH_Debug_Tools::log(
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 				$registration,
399 399
 				$additional_details
400 400
 			);
401
-		} catch( Exception $e ) {
402
-			EE_Error::add_error( $e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine() );
401
+		} catch (Exception $e) {
402
+			EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
403 403
 		}
404 404
 	}
405 405
 
@@ -413,22 +413,22 @@  discard block
 block discarded – undo
413 413
 	 * @return bool
414 414
 	 * @throws \EE_Error
415 415
 	 */
416
-	public function update_registration_after_checkout_or_payment(  EE_Registration $registration, $additional_details = array() ) {
416
+	public function update_registration_after_checkout_or_payment(EE_Registration $registration, $additional_details = array()) {
417 417
 		// set initial REG_Status
418
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
418
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
419 419
 
420 420
 		// if the registration status gets updated, then save the registration
421 421
 		if (
422
-			$this->toggle_registration_status_for_default_approved_events( $registration, false )
423
-			|| $this->toggle_registration_status_if_no_monies_owing( $registration, false, $additional_details )
422
+			$this->toggle_registration_status_for_default_approved_events($registration, false)
423
+			|| $this->toggle_registration_status_if_no_monies_owing($registration, false, $additional_details)
424 424
 		) {
425 425
 			$registration->save();
426 426
 		}
427 427
 
428 428
 		// set new  REG_Status
429
-		$this->set_new_reg_status( $registration->ID(), $registration->status_ID() );
430
-		return $this->reg_status_updated( $registration->ID() )
431
-		       && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
429
+		$this->set_new_reg_status($registration->ID(), $registration->status_ID());
430
+		return $this->reg_status_updated($registration->ID())
431
+		       && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved
432 432
 			? true
433 433
 			: false;
434 434
 	}
@@ -444,20 +444,20 @@  discard block
 block discarded – undo
444 444
 	 * @return void
445 445
 	 * @throws \EE_Error
446 446
 	 */
447
-	public function update_registration_final_prices( $transaction, $save_regs = true ) {
448
-		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $transaction->total_line_item() );
449
-		foreach( $transaction->registrations() as $registration ) {
447
+	public function update_registration_final_prices($transaction, $save_regs = true) {
448
+		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item($transaction->total_line_item());
449
+		foreach ($transaction->registrations() as $registration) {
450 450
 			/** @var EE_Line_Item $line_item */
451
-			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration( $registration );
452
-			if( isset( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] ) ) {
453
-				$registration->set_final_price( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] );
454
-				if( $save_regs ) {
451
+			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
452
+			if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) {
453
+				$registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]);
454
+				if ($save_regs) {
455 455
 					$registration->save();
456 456
 				}
457 457
 			}
458 458
 		}
459 459
 		//and make sure there's no rounding problem
460
-		$this->fix_reg_final_price_rounding_issue( $transaction );
460
+		$this->fix_reg_final_price_rounding_issue($transaction);
461 461
 	}
462 462
 
463 463
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * @return boolean success verifying that there is NO difference after this method is done
478 478
 	 * @throws \EE_Error
479 479
 	 */
480
-	public function fix_reg_final_price_rounding_issue( $transaction ) {
480
+	public function fix_reg_final_price_rounding_issue($transaction) {
481 481
 		$reg_final_price_sum = EEM_Registration::instance()->sum(
482 482
 			array(
483 483
 				array(
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
 			),
487 487
 			'REG_final_price'
488 488
 		);
489
-		$diff =  $transaction->total() - (float) $reg_final_price_sum;
489
+		$diff = $transaction->total() - (float) $reg_final_price_sum;
490 490
 		//ok then, just grab one of the registrations
491
-		if( $diff !== 0 ) {
491
+		if ($diff !== 0) {
492 492
 			$a_reg = EEM_Registration::instance()->get_one(
493 493
 					array(
494 494
 						array(
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 					));
498 498
 			$success = $a_reg instanceof EE_Registration
499 499
 				? $a_reg->save(
500
-					array( 'REG_final_price' => $a_reg->final_price() + $diff )
500
+					array('REG_final_price' => $a_reg->final_price() + $diff)
501 501
 				)
502 502
 				: false;
503 503
 			return $success ? true : false;
@@ -523,16 +523,16 @@  discard block
 block discarded – undo
523 523
 		$update_reg = true
524 524
 	) {
525 525
 		// these reg statuses should not be considered in any calculations involving monies owing
526
-		$closed_reg_statuses = ! empty( $closed_reg_statuses )
526
+		$closed_reg_statuses = ! empty($closed_reg_statuses)
527 527
             ? $closed_reg_statuses
528 528
 			: EEM_Registration::closed_reg_statuses();
529
-		if ( ! in_array( $registration->status_ID(), $closed_reg_statuses, true ) ) {
529
+		if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
530 530
 			return false;
531 531
 		}
532 532
         // release a reserved ticket by decrementing ticket and datetime reserved values
533 533
         $registration->release_reserved_ticket(true);
534 534
         $registration->set_final_price(0);
535
-		if ( $update_reg ) {
535
+		if ($update_reg) {
536 536
 			$registration->save();
537 537
 		}
538 538
 		return true;
@@ -555,23 +555,23 @@  discard block
 block discarded – undo
555 555
 		$update_reg = true
556 556
 	) {
557 557
 		// these reg statuses should not be considered in any calculations involving monies owing
558
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses
558
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
559 559
 			: EEM_Registration::closed_reg_statuses();
560
-		if ( in_array( $registration->status_ID(), $closed_reg_statuses ) ) {
560
+		if (in_array($registration->status_ID(), $closed_reg_statuses)) {
561 561
 			return false;
562 562
 		}
563 563
 		$ticket = $registration->ticket();
564
-		if ( ! $ticket instanceof EE_Ticket ) {
564
+		if ( ! $ticket instanceof EE_Ticket) {
565 565
 			throw new EE_Error(
566 566
 				sprintf(
567
-					__( 'The Ticket for Registration %1$d was not found or is invalid.',
568
-						'event_espresso' ),
567
+					__('The Ticket for Registration %1$d was not found or is invalid.',
568
+						'event_espresso'),
569 569
 					$registration->ticket_ID()
570 570
 				)
571 571
 			);
572 572
 		}
573
-		$registration->set_final_price( $ticket->price() );
574
-		if ( $update_reg ) {
573
+		$registration->set_final_price($ticket->price());
574
+		if ($update_reg) {
575 575
 			$registration->save();
576 576
 		}
577 577
 		return true;
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 		$total_ticket_count = 1
610 610
 	) {
611 611
 		EE_Error::doing_it_wrong(
612
-			__CLASS__ . '::' . __FUNCTION__,
612
+			__CLASS__.'::'.__FUNCTION__,
613 613
 			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
614 614
 				'\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'),
615 615
 			'4.9.1',
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 	public function generate_reg_url_link($att_nmbr, $item)
653 653
 	{
654 654
 		EE_Error::doing_it_wrong(
655
-			__CLASS__ . '::' . __FUNCTION__,
655
+			__CLASS__.'::'.__FUNCTION__,
656 656
 			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
657 657
 				'EventEspresso\core\domain\entities\RegUrlLink'),
658 658
 			'4.9.1',
@@ -672,11 +672,11 @@  discard block
 block discarded – undo
672 672
 	 * @return string
673 673
 	 * @throws \EE_Error
674 674
 	 */
675
-	public function generate_reg_code( EE_Registration $registration ) {
675
+	public function generate_reg_code(EE_Registration $registration) {
676 676
 		EE_Error::doing_it_wrong(
677
-			__CLASS__ . '::' . __FUNCTION__,
677
+			__CLASS__.'::'.__FUNCTION__,
678 678
 			sprintf(
679
-				__( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ),
679
+				__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
680 680
 				'EventEspresso\core\domain\entities\RegCode'
681 681
 			),
682 682
 			'4.9.1',
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
 		return apply_filters(
686 686
 			'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
687 687
 			new RegCode(
688
-				RegUrlLink::fromRegistration( $registration ),
688
+				RegUrlLink::fromRegistration($registration),
689 689
 				$registration->transaction(),
690 690
 				$registration->ticket()
691 691
 			),
Please login to merge, or discard this patch.
core/domain/services/registration/CreateRegistrationService.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\exceptions\UnexpectedEntityException;
8 8
 
9 9
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
-    exit('No direct script access allowed');
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 
@@ -24,101 +24,101 @@  discard block
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * @param \EE_Event       $event
29
-     * @param \EE_Transaction $transaction
30
-     * @param \EE_Ticket      $ticket
31
-     * @param \EE_Line_Item   $ticket_line_item
32
-     * @param                 $reg_count
33
-     * @param                 $reg_group_size
34
-     * @return \EE_Registration
35
-     * @throws \EE_Error
36
-     * @throws UnexpectedEntityException
37
-     */
38
-    public function create(
39
-        \EE_Event $event,
40
-        \EE_Transaction $transaction,
41
-        \EE_Ticket $ticket,
42
-        \EE_Line_Item $ticket_line_item,
43
-        $reg_count,
44
-        $reg_group_size
45
-    ) {
46
-        $registrations = $transaction->registrations();
47
-        $reg_count = $reg_count ? $reg_count : count($registrations) + 1;
48
-        $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item);
49
-        $reg_code = new RegCode($reg_url_link, $transaction, $ticket);
50
-        // generate new EE_Registration
51
-        $registration = \EE_Registration::new_instance(
52
-            array(
53
-                'EVT_ID'          => $event->ID(),
54
-                'TXN_ID'          => $transaction->ID(),
55
-                'TKT_ID'          => $ticket->ID(),
56
-                'STS_ID'          => \EEM_Registration::status_id_incomplete,
57
-                'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item),
58
-                'REG_session'     => \EE_Registry::instance()->SSN->id(),
59
-                'REG_count'       => $reg_count,
60
-                'REG_group_size'  => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations),
61
-                'REG_url_link'    => $reg_url_link,
62
-                'REG_code'        => $reg_code,
63
-            )
64
-        );
65
-        if ( ! $registration instanceof \EE_Registration) {
66
-            throw new UnexpectedEntityException($registration, 'EE_Registration');
67
-        }
68
-        // save registration so that we have an ID
69
-        $registration->save();
70
-        // track reservation on reg but don't adjust ticket and datetime reserved counts
71
-        // because that is done as soon as the tickets are added/removed from the cart
72
-        $registration->reserve_ticket();
73
-        $registration->_add_relation_to($event, 'Event', array(), $event->ID());
74
-        $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID());
75
-        $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID());
76
-        $registration->save();
77
-        return $registration;
78
-    }
27
+	/**
28
+	 * @param \EE_Event       $event
29
+	 * @param \EE_Transaction $transaction
30
+	 * @param \EE_Ticket      $ticket
31
+	 * @param \EE_Line_Item   $ticket_line_item
32
+	 * @param                 $reg_count
33
+	 * @param                 $reg_group_size
34
+	 * @return \EE_Registration
35
+	 * @throws \EE_Error
36
+	 * @throws UnexpectedEntityException
37
+	 */
38
+	public function create(
39
+		\EE_Event $event,
40
+		\EE_Transaction $transaction,
41
+		\EE_Ticket $ticket,
42
+		\EE_Line_Item $ticket_line_item,
43
+		$reg_count,
44
+		$reg_group_size
45
+	) {
46
+		$registrations = $transaction->registrations();
47
+		$reg_count = $reg_count ? $reg_count : count($registrations) + 1;
48
+		$reg_url_link = new RegUrlLink($reg_count, $ticket_line_item);
49
+		$reg_code = new RegCode($reg_url_link, $transaction, $ticket);
50
+		// generate new EE_Registration
51
+		$registration = \EE_Registration::new_instance(
52
+			array(
53
+				'EVT_ID'          => $event->ID(),
54
+				'TXN_ID'          => $transaction->ID(),
55
+				'TKT_ID'          => $ticket->ID(),
56
+				'STS_ID'          => \EEM_Registration::status_id_incomplete,
57
+				'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item),
58
+				'REG_session'     => \EE_Registry::instance()->SSN->id(),
59
+				'REG_count'       => $reg_count,
60
+				'REG_group_size'  => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations),
61
+				'REG_url_link'    => $reg_url_link,
62
+				'REG_code'        => $reg_code,
63
+			)
64
+		);
65
+		if ( ! $registration instanceof \EE_Registration) {
66
+			throw new UnexpectedEntityException($registration, 'EE_Registration');
67
+		}
68
+		// save registration so that we have an ID
69
+		$registration->save();
70
+		// track reservation on reg but don't adjust ticket and datetime reserved counts
71
+		// because that is done as soon as the tickets are added/removed from the cart
72
+		$registration->reserve_ticket();
73
+		$registration->_add_relation_to($event, 'Event', array(), $event->ID());
74
+		$registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID());
75
+		$transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID());
76
+		$registration->save();
77
+		return $registration;
78
+	}
79 79
 
80 80
 
81 81
 
82
-    /**
83
-     * @param \EE_Transaction $transaction
84
-     * @param \EE_Ticket      $ticket
85
-     * @param \EE_Line_Item   $ticket_line_item
86
-     * @return float
87
-     */
88
-    protected function resolveFinalPrice(
89
-        \EE_Transaction $transaction,
90
-        \EE_Ticket $ticket,
91
-        \EE_Line_Item $ticket_line_item
92
-    ) {
93
-        $final_price = \EEH_Line_Item::calculate_final_price_for_ticket_line_item(
94
-            $transaction->total_line_item(),
95
-            $ticket_line_item
96
-        );
97
-        $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes();
98
-        return (float)$final_price;
99
-    }
82
+	/**
83
+	 * @param \EE_Transaction $transaction
84
+	 * @param \EE_Ticket      $ticket
85
+	 * @param \EE_Line_Item   $ticket_line_item
86
+	 * @return float
87
+	 */
88
+	protected function resolveFinalPrice(
89
+		\EE_Transaction $transaction,
90
+		\EE_Ticket $ticket,
91
+		\EE_Line_Item $ticket_line_item
92
+	) {
93
+		$final_price = \EEH_Line_Item::calculate_final_price_for_ticket_line_item(
94
+			$transaction->total_line_item(),
95
+			$ticket_line_item
96
+		);
97
+		$final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes();
98
+		return (float)$final_price;
99
+	}
100 100
 
101 101
 
102 102
 
103
-    /**
104
-     * @param  \EE_Registration[] $registrations
105
-     * @param  boolean            $update_existing_registrations
106
-     * @return int
107
-     * @throws \EE_Error
108
-     */
109
-    protected function incrementRegCount(array $registrations, $update_existing_registrations = true)
110
-    {
111
-        $new_reg_count = count($registrations) + 1;
112
-        if ($update_existing_registrations) {
113
-            foreach ($registrations as $registration) {
114
-                if ($registration instanceof \EE_Registration) {
115
-                    $registration->set_count($new_reg_count);
116
-                    $registration->save();
117
-                }
118
-            }
119
-        }
120
-        return $new_reg_count;
121
-    }
103
+	/**
104
+	 * @param  \EE_Registration[] $registrations
105
+	 * @param  boolean            $update_existing_registrations
106
+	 * @return int
107
+	 * @throws \EE_Error
108
+	 */
109
+	protected function incrementRegCount(array $registrations, $update_existing_registrations = true)
110
+	{
111
+		$new_reg_count = count($registrations) + 1;
112
+		if ($update_existing_registrations) {
113
+			foreach ($registrations as $registration) {
114
+				if ($registration instanceof \EE_Registration) {
115
+					$registration->set_count($new_reg_count);
116
+					$registration->save();
117
+				}
118
+			}
119
+		}
120
+		return $new_reg_count;
121
+	}
122 122
 
123 123
 
124 124
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Model_Field_Base.php 1 patch
Indentation   +634 added lines, -635 removed lines patch added patch discarded remove patch
@@ -21,639 +21,638 @@
 block discarded – undo
21 21
  */
22 22
 abstract class EE_Model_Field_Base implements HasSchemaInterface
23 23
 {
24
-    /**
25
-     * The alias for the table the column belongs to.
26
-     * @var string
27
-     */
28
-    protected $_table_alias;
29
-
30
-    /**
31
-     * The actual db column name for the table
32
-     * @var string
33
-     */
34
-    protected $_table_column;
35
-
36
-
37
-    /**
38
-     * The authoritative name for the table column (used by client code to reference the field).
39
-     * @var string
40
-     */
41
-    protected $_name;
42
-
43
-
44
-    /**
45
-     * A description for the field.
46
-     * @var string
47
-     */
48
-    protected $_nicename;
49
-
50
-
51
-    /**
52
-     * Whether the field is nullable or not
53
-     * @var bool
54
-     */
55
-    protected $_nullable;
56
-
57
-
58
-    /**
59
-     * What the default value for the field should be.
60
-     * @var mixed
61
-     */
62
-    protected $_default_value;
63
-
64
-
65
-    /**
66
-     * Other configuration for the field
67
-     * @var mixed
68
-     */
69
-    protected $_other_config;
70
-
71
-
72
-    /**
73
-     * The name of the model this field is instantiated for.
74
-     * @var string
75
-     */
76
-    protected $_model_name;
77
-
78
-
79
-    /**
80
-     * This should be a json-schema valid data type for the field.
81
-     * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
82
-     * @var string
83
-     */
84
-    private $_schema_type = 'string';
85
-
86
-
87
-    /**
88
-     * If the schema has a defined format then it should be defined via this property.
89
-     * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
90
-     * @var string
91
-     */
92
-    private $_schema_format = '';
93
-
94
-
95
-    /**
96
-     * Indicates that the value of the field is managed exclusively by the server/model and not something
97
-     * settable by client code.
98
-     * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4
99
-     * @var bool
100
-     */
101
-    private $_schema_readonly = false;
102
-
103
-
104
-    /**
105
-     * @param string $table_column
106
-     * @param string $nicename
107
-     * @param bool   $nullable
108
-     * @param null   $default_value
109
-     */
110
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
111
-    {
112
-        $this->_table_column  = $table_column;
113
-        $this->_nicename      = $nicename;
114
-        $this->_nullable      = $nullable;
115
-        $this->_default_value = $default_value;
116
-    }
117
-
118
-
119
-    /**
120
-     * @param $table_alias
121
-     * @param $name
122
-     * @param $model_name
123
-     */
124
-    public function _construct_finalize($table_alias, $name, $model_name)
125
-    {
126
-        $this->_table_alias = $table_alias;
127
-        $this->_name        = $name;
128
-        $this->_model_name  = $model_name;
129
-        /**
130
-         * allow for changing the defaults
131
-         */
132
-        $this->_nicename      = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename',
133
-            $this->_nicename, $this);
134
-        $this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value',
135
-            $this->_default_value, $this);
136
-    }
137
-
138
-    public function get_table_alias()
139
-    {
140
-        return $this->_table_alias;
141
-    }
142
-
143
-    public function get_table_column()
144
-    {
145
-        return $this->_table_column;
146
-    }
147
-
148
-    /**
149
-     * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime'
150
-     *
151
-     * @return string
152
-     */
153
-    public function get_model_name()
154
-    {
155
-        return $this->_model_name;
156
-    }
157
-
158
-    /**
159
-     * @throws \EE_Error
160
-     * @return string
161
-     */
162
-    public function get_name()
163
-    {
164
-        if ($this->_name) {
165
-            return $this->_name;
166
-        } else {
167
-            throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?",
168
-                "event_espresso"), get_class($this)));
169
-        }
170
-    }
171
-
172
-    public function get_nicename()
173
-    {
174
-        return $this->_nicename;
175
-    }
176
-
177
-    public function is_nullable()
178
-    {
179
-        return $this->_nullable;
180
-    }
181
-
182
-    /**
183
-     * returns whether this field is an auto-increment field or not. If it is, then
184
-     * on insertion it can be null. However, on updates it must be present.
185
-     *
186
-     * @return boolean
187
-     */
188
-    public function is_auto_increment()
189
-    {
190
-        return false;
191
-    }
192
-
193
-    /**
194
-     * The default value in the model object's value domain. See lengthy comment about
195
-     * value domains at the top of EEM_Base
196
-     *
197
-     * @return mixed
198
-     */
199
-    public function get_default_value()
200
-    {
201
-        return $this->_default_value;
202
-    }
203
-
204
-    /**
205
-     * Returns the table alias joined to the table column, however this isn't the right
206
-     * table alias if the aliased table is being joined to. In that case, you can use
207
-     * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias
208
-     * in the current query
209
-     *
210
-     * @return string
211
-     */
212
-    public function get_qualified_column()
213
-    {
214
-        return $this->get_table_alias() . "." . $this->get_table_column();
215
-    }
216
-
217
-    /**
218
-     * When get() is called on a model object (eg EE_Event), before returning its value,
219
-     * call this function on it, allowing us to customize the returned value based on
220
-     * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default,
221
-     * we simply return it.
222
-     *
223
-     * @param mixed $value_of_field_on_model_object
224
-     * @return mixed
225
-     */
226
-    public function prepare_for_get($value_of_field_on_model_object)
227
-    {
228
-        return $value_of_field_on_model_object;
229
-    }
230
-
231
-    /**
232
-     * When inserting or updating a field on a model object, run this function on each
233
-     * value to prepare it for insertion into the db. We may want to add slashes, serialize it, etc.
234
-     * By default, we do nothing.
235
-     *
236
-     * @param mixed $value_of_field_on_model_object
237
-     * @return mixed
238
-     */
239
-    public function prepare_for_use_in_db($value_of_field_on_model_object)
240
-    {
241
-        return $value_of_field_on_model_object;
242
-    }
243
-
244
-    /**
245
-     * When creating a brand-new model object, or setting a particular value for one of its fields, this function
246
-     * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc.
247
-     * By default, we do nothing.
248
-     *
249
-     * @param mixed $value_inputted_for_field_on_model_object
250
-     * @return mixed
251
-     */
252
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
253
-    {
254
-        return $value_inputted_for_field_on_model_object;
255
-    }
256
-
257
-
258
-    /**
259
-     * When instantiating a model object from DB results, this function is called before setting each field.
260
-     * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that
261
-     * is the one child classes will most often define.
262
-     *
263
-     * @param mixed $value_found_in_db_for_model_object
264
-     * @return mixed
265
-     */
266
-    public function prepare_for_set_from_db($value_found_in_db_for_model_object)
267
-    {
268
-        return $this->prepare_for_set($value_found_in_db_for_model_object);
269
-    }
270
-
271
-    /**
272
-     * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a
273
-     * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12,
274
-     * 2013, at 3:23pm" instead of
275
-     * "8765678632", or any other modifications to how the value should be displayed, but not modified itself.
276
-     *
277
-     * @param mixed $value_on_field_to_be_outputted
278
-     * @return mixed
279
-     */
280
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
281
-    {
282
-        return $value_on_field_to_be_outputted;
283
-    }
284
-
285
-
286
-    /**
287
-     * Returns whatever is set as the nicename for the object.
288
-     * @return string
289
-     */
290
-    public function getSchemaDescription()
291
-    {
292
-        return $this->get_nicename();
293
-    }
294
-
295
-
296
-    /**
297
-     * Returns whatever is set as the $_schema_type property for the object.
298
-     * Note: this will automatically add 'null' to the schema if the object is_nullable()
299
-     * @return string|array
300
-     */
301
-    public function getSchemaType()
302
-    {
303
-        if ($this->is_nullable()) {
304
-            $this->_schema_type = (array) $this->_schema_type;
305
-            if (! in_array('null', $this->_schema_type)) {
306
-                $this->_schema_type[] = 'null';
307
-            };
308
-        }
309
-        return $this->_schema_type;
310
-    }
311
-
312
-
313
-    /**
314
-     * Sets the _schema_type property.  Child classes should call this in their constructors to override the default state
315
-     * for this property.
316
-     * @param string|array $type
317
-     * @throws InvalidArgumentException
318
-     */
319
-    protected function setSchemaType($type)
320
-    {
321
-        $this->validateSchemaType($type);
322
-        $this->_schema_type = $type;
323
-    }
324
-
325
-
326
-    /**
327
-     * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
328
-     * this method and return the properties for the schema.
329
-     *
330
-     * The reason this is not a property on the class is because there may be filters set on the values for the property
331
-     * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
332
-     *
333
-     * @return array
334
-     */
335
-    public function getSchemaProperties()
336
-    {
337
-        return array();
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     * By default this returns the scalar default value that was sent in on the class prepped according to the class type
344
-     * as the default.  However, when there are schema properties, then the default property is setup to mirror the
345
-     * property keys and correctly prepare the default according to that expected property value.
346
-     * The getSchema method validates whether the schema for default is setup correctly or not according to the schema type
347
-     *
348
-     * @return mixed
349
-     */
350
-    public function getSchemaDefault()
351
-    {
352
-        $default_value = $this->prepare_for_use_in_db($this->prepare_for_set($this->get_default_value()));
353
-        $schema_properties = $this->getSchemaProperties();
354
-
355
-        //if this schema has properties than shape the default value to match the properties shape.
356
-        if ($schema_properties) {
357
-            $value_to_return = array();
358
-            foreach ($schema_properties as $property_key => $property_schema) {
359
-                switch ($property_key) {
360
-                    case 'pretty':
361
-                    case 'rendered':
362
-                        $value_to_return[$property_key] = $this->prepare_for_pretty_echoing($this->prepare_for_set($default_value));
363
-                        break;
364
-                    default:
365
-                        $value_to_return[$property_key] = $default_value;
366
-                        break;
367
-                }
368
-            }
369
-            $default_value = $value_to_return;
370
-        }
371
-        return $default_value;
372
-    }
373
-
374
-
375
-
376
-
377
-    /**
378
-     * If a child class has enum values, they should override this method and provide a simple array
379
-     * of the enum values.
380
-
381
-     * The reason this is not a property on the class is because there may be filterable enum values that
382
-     * are set on the instantiated object that could be filtered after construct.
383
-     *
384
-     * @return array
385
-     */
386
-    public function getSchemaEnum()
387
-    {
388
-        return array();
389
-    }
390
-
391
-
392
-    /**
393
-     * This returns the value of the $_schema_format property on the object.
394
-     * @return string
395
-     */
396
-    public function getSchemaFormat()
397
-    {
398
-        return $this->_schema_format;
399
-    }
400
-
401
-
402
-    /**
403
-     * Sets the schema format property.
404
-     * @throws InvalidArgumentException
405
-     * @param string $format
406
-     */
407
-    protected function setSchemaFormat($format)
408
-    {
409
-        $this->validateSchemaFormat($format);
410
-        $this->_schema_format = $format;
411
-    }
412
-
413
-
414
-    /**
415
-     * This returns the value of the $_schema_readonly property on the object.
416
-     * @return bool
417
-     */
418
-    public function getSchemaReadonly()
419
-    {
420
-        return $this->_schema_readonly;
421
-    }
422
-
423
-
424
-    /**
425
-     * This sets the value for the $_schema_readonly property.
426
-     * @param bool $readonly  (only explicit boolean values are accepted)
427
-     */
428
-    protected function setSchemaReadOnly($readonly)
429
-    {
430
-        if (! is_bool($readonly)) {
431
-            throw new InvalidArgumentException(
432
-                sprintf(
433
-                    esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'),
434
-                    print_r($readonly, true)
435
-                )
436
-            );
437
-        }
438
-
439
-        $this->_schema_readonly = $readonly;
440
-    }
441
-
442
-
443
-
444
-
445
-    /**
446
-     * Return `%d`, `%s` or `%f` to indicate the data type for the field.
447
-     * @uses _get_wpdb_data_type()
448
-     *
449
-     * @return string
450
-     */
451
-    public function get_wpdb_data_type()
452
-    {
453
-        return $this->_get_wpdb_data_type();
454
-    }
455
-
456
-
457
-    /**
458
-     * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries.
459
-     * @param string $type  Included if a specific type is requested.
460
-     * @uses get_schema_type()
461
-     * @return string
462
-     */
463
-    protected function _get_wpdb_data_type($type='')
464
-    {
465
-        $type = empty($type) ? $this->getSchemaType() : $type;
466
-
467
-        //if type is an array, then different parsing is required.
468
-        if (is_array($type)) {
469
-            return $this->_get_wpdb_data_type_for_type_array($type);
470
-        }
471
-
472
-        $wpdb_type = '%s';
473
-        switch ($type) {
474
-            case 'number':
475
-                $wpdb_type = '%f';
476
-                break;
477
-            case 'integer':
478
-            case 'boolean':
479
-                $wpdb_type = '%d';
480
-                break;
481
-            case 'object':
482
-                $properties = $this->getSchemaProperties();
483
-                if (isset($properties['raw'], $properties['raw']['type'])) {
484
-                    $wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']);
485
-                }
486
-                break; //leave at default
487
-        }
488
-        return $wpdb_type;
489
-    }
490
-
491
-
492
-
493
-    protected function _get_wpdb_data_type_for_type_array($type)
494
-    {
495
-        $type = (array) $type;
496
-        //first let's flip because then we can do a faster key check
497
-        $type = array_flip($type);
498
-
499
-        //check for things that mean '%s'
500
-        if (isset($type['string'],$type['object'],$type['array'])) {
501
-            return '%s';
502
-        }
503
-
504
-        //if makes it past the above condition and there's float in the array
505
-        //then the type is %f
506
-        if (isset($type['number'])) {
507
-            return '%f';
508
-        }
509
-
510
-        //if it makes it above the above conditions and there is an integer in the array
511
-        //then the type is %d
512
-        if (isset($type['integer'])) {
513
-            return '%d';
514
-        }
515
-
516
-        //anything else is a string
517
-        return '%s';
518
-    }
519
-
520
-
521
-    /**
522
-     * This returns elements used to represent this field in the json schema.
523
-     *
524
-     * @link http://json-schema.org/
525
-     * @return array
526
-     */
527
-    public function getSchema()
528
-    {
529
-        $schema = array(
530
-            'description' => $this->getSchemaDescription(),
531
-            'type' => $this->getSchemaType(),
532
-            'readonly' => $this->getSchemaReadonly(),
533
-            'default' => $this->getSchemaDefault()
534
-        );
535
-
536
-        //optional properties of the schema
537
-        $enum = $this->getSchemaEnum();
538
-        $properties = $this->getSchemaProperties();
539
-        $format = $this->getSchemaFormat();
540
-        if ($enum) {
541
-            $schema['enum'] = $enum;
542
-        }
543
-
544
-        if ($properties) {
545
-            $schema['properties'] = $properties;
546
-        }
547
-
548
-        if ($format) {
549
-            $schema['format'] = $format;
550
-        }
551
-        return $schema;
552
-    }
553
-
554
-    /**
555
-     * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part
556
-     * of the model objects (ie, client code shouldn't care to ever see their value... if client code does
557
-     * want to see their value, then they shouldn't be db-only fields!)
558
-     * Eg, when doing events as custom post types, querying the post_type is essential, but
559
-     * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event').
560
-     * By default, all fields aren't db-only.
561
-     *
562
-     * @return boolean
563
-     */
564
-    public function is_db_only_field()
565
-    {
566
-        return false;
567
-    }
568
-
569
-
570
-    /**
571
-     * Validates the incoming string|array to ensure its an allowable type.
572
-     * @throws InvalidArgumentException
573
-     * @param string|array $type
574
-     */
575
-    private function validateSchemaType($type)
576
-    {
577
-        if (! (is_string($type) || is_array($type))) {
578
-            throw new InvalidArgumentException(
579
-                sprintf(
580
-                    esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'),
581
-                    print_r($type, true)
582
-                )
583
-            );
584
-        }
585
-
586
-        //validate allowable types.
587
-        //@link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
588
-        $allowable_types = array_flip(
589
-            array(
590
-                'string',
591
-                'number',
592
-                'null',
593
-                'object',
594
-                'array',
595
-                'boolean',
596
-                'integer'
597
-            )
598
-        );
599
-
600
-        if (is_array($type)) {
601
-            foreach ($type as $item_in_type) {
602
-                $this->validateSchemaType($item_in_type);
603
-            }
604
-            return;
605
-        }
606
-
607
-        if (! isset($allowable_types[$type])) {
608
-            throw new InvalidArgumentException(
609
-                sprintf(
610
-                    esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'),
611
-                    $type,
612
-                    implode(',', array_flip($allowable_types))
613
-                )
614
-            );
615
-        }
616
-    }
617
-
618
-
619
-    /**
620
-     * Validates that the incoming format is an allowable string to use for the _schema_format property
621
-     * @throws InvalidArgumentException
622
-     * @param $format
623
-     */
624
-    private function validateSchemaFormat($format)
625
-    {
626
-        if (! is_string($format)) {
627
-            throw new InvalidArgumentException(
628
-                sprintf(
629
-                    esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'),
630
-                    print_r($format, true)
631
-                )
632
-            );
633
-        }
634
-
635
-        //validate allowable format values
636
-        //@link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
637
-        $allowable_formats = array_flip(
638
-            array(
639
-                'date-time',
640
-                'email',
641
-                'hostname',
642
-                'ipv4',
643
-                'ipv6',
644
-                'uri',
645
-                'uriref'
646
-            )
647
-        );
648
-
649
-        if (! isset($allowable_formats[$format])) {
650
-            throw new InvalidArgumentException(
651
-                sprintf(
652
-                    esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'),
653
-                    $format,
654
-                    implode(',', array_flip($allowable_formats))
655
-                )
656
-            );
657
-        }
658
-    }
24
+	/**
25
+	 * The alias for the table the column belongs to.
26
+	 * @var string
27
+	 */
28
+	protected $_table_alias;
29
+
30
+	/**
31
+	 * The actual db column name for the table
32
+	 * @var string
33
+	 */
34
+	protected $_table_column;
35
+
36
+
37
+	/**
38
+	 * The authoritative name for the table column (used by client code to reference the field).
39
+	 * @var string
40
+	 */
41
+	protected $_name;
42
+
43
+
44
+	/**
45
+	 * A description for the field.
46
+	 * @var string
47
+	 */
48
+	protected $_nicename;
49
+
50
+
51
+	/**
52
+	 * Whether the field is nullable or not
53
+	 * @var bool
54
+	 */
55
+	protected $_nullable;
56
+
57
+
58
+	/**
59
+	 * What the default value for the field should be.
60
+	 * @var mixed
61
+	 */
62
+	protected $_default_value;
63
+
64
+
65
+	/**
66
+	 * Other configuration for the field
67
+	 * @var mixed
68
+	 */
69
+	protected $_other_config;
70
+
71
+
72
+	/**
73
+	 * The name of the model this field is instantiated for.
74
+	 * @var string
75
+	 */
76
+	protected $_model_name;
77
+
78
+
79
+	/**
80
+	 * This should be a json-schema valid data type for the field.
81
+	 * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
82
+	 * @var string
83
+	 */
84
+	private $_schema_type = 'string';
85
+
86
+
87
+	/**
88
+	 * If the schema has a defined format then it should be defined via this property.
89
+	 * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
90
+	 * @var string
91
+	 */
92
+	private $_schema_format = '';
93
+
94
+
95
+	/**
96
+	 * Indicates that the value of the field is managed exclusively by the server/model and not something
97
+	 * settable by client code.
98
+	 * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4
99
+	 * @var bool
100
+	 */
101
+	private $_schema_readonly = false;
102
+
103
+
104
+	/**
105
+	 * @param string $table_column
106
+	 * @param string $nicename
107
+	 * @param bool   $nullable
108
+	 * @param null   $default_value
109
+	 */
110
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
111
+	{
112
+		$this->_table_column  = $table_column;
113
+		$this->_nicename      = $nicename;
114
+		$this->_nullable      = $nullable;
115
+		$this->_default_value = $default_value;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param $table_alias
121
+	 * @param $name
122
+	 * @param $model_name
123
+	 */
124
+	public function _construct_finalize($table_alias, $name, $model_name)
125
+	{
126
+		$this->_table_alias = $table_alias;
127
+		$this->_name        = $name;
128
+		$this->_model_name  = $model_name;
129
+		/**
130
+		 * allow for changing the defaults
131
+		 */
132
+		$this->_nicename      = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename',
133
+			$this->_nicename, $this);
134
+		$this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value',
135
+			$this->_default_value, $this);
136
+	}
137
+
138
+	public function get_table_alias()
139
+	{
140
+		return $this->_table_alias;
141
+	}
142
+
143
+	public function get_table_column()
144
+	{
145
+		return $this->_table_column;
146
+	}
147
+
148
+	/**
149
+	 * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime'
150
+	 *
151
+	 * @return string
152
+	 */
153
+	public function get_model_name()
154
+	{
155
+		return $this->_model_name;
156
+	}
157
+
158
+	/**
159
+	 * @throws \EE_Error
160
+	 * @return string
161
+	 */
162
+	public function get_name()
163
+	{
164
+		if ($this->_name) {
165
+			return $this->_name;
166
+		} else {
167
+			throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?",
168
+				"event_espresso"), get_class($this)));
169
+		}
170
+	}
171
+
172
+	public function get_nicename()
173
+	{
174
+		return $this->_nicename;
175
+	}
176
+
177
+	public function is_nullable()
178
+	{
179
+		return $this->_nullable;
180
+	}
181
+
182
+	/**
183
+	 * returns whether this field is an auto-increment field or not. If it is, then
184
+	 * on insertion it can be null. However, on updates it must be present.
185
+	 *
186
+	 * @return boolean
187
+	 */
188
+	public function is_auto_increment()
189
+	{
190
+		return false;
191
+	}
192
+
193
+	/**
194
+	 * The default value in the model object's value domain. See lengthy comment about
195
+	 * value domains at the top of EEM_Base
196
+	 *
197
+	 * @return mixed
198
+	 */
199
+	public function get_default_value()
200
+	{
201
+		return $this->_default_value;
202
+	}
203
+
204
+	/**
205
+	 * Returns the table alias joined to the table column, however this isn't the right
206
+	 * table alias if the aliased table is being joined to. In that case, you can use
207
+	 * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias
208
+	 * in the current query
209
+	 *
210
+	 * @return string
211
+	 */
212
+	public function get_qualified_column()
213
+	{
214
+		return $this->get_table_alias() . "." . $this->get_table_column();
215
+	}
216
+
217
+	/**
218
+	 * When get() is called on a model object (eg EE_Event), before returning its value,
219
+	 * call this function on it, allowing us to customize the returned value based on
220
+	 * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default,
221
+	 * we simply return it.
222
+	 *
223
+	 * @param mixed $value_of_field_on_model_object
224
+	 * @return mixed
225
+	 */
226
+	public function prepare_for_get($value_of_field_on_model_object)
227
+	{
228
+		return $value_of_field_on_model_object;
229
+	}
230
+
231
+	/**
232
+	 * When inserting or updating a field on a model object, run this function on each
233
+	 * value to prepare it for insertion into the db. We may want to add slashes, serialize it, etc.
234
+	 * By default, we do nothing.
235
+	 *
236
+	 * @param mixed $value_of_field_on_model_object
237
+	 * @return mixed
238
+	 */
239
+	public function prepare_for_use_in_db($value_of_field_on_model_object)
240
+	{
241
+		return $value_of_field_on_model_object;
242
+	}
243
+
244
+	/**
245
+	 * When creating a brand-new model object, or setting a particular value for one of its fields, this function
246
+	 * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc.
247
+	 * By default, we do nothing.
248
+	 *
249
+	 * @param mixed $value_inputted_for_field_on_model_object
250
+	 * @return mixed
251
+	 */
252
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
253
+	{
254
+		return $value_inputted_for_field_on_model_object;
255
+	}
256
+
257
+
258
+	/**
259
+	 * When instantiating a model object from DB results, this function is called before setting each field.
260
+	 * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that
261
+	 * is the one child classes will most often define.
262
+	 *
263
+	 * @param mixed $value_found_in_db_for_model_object
264
+	 * @return mixed
265
+	 */
266
+	public function prepare_for_set_from_db($value_found_in_db_for_model_object)
267
+	{
268
+		return $this->prepare_for_set($value_found_in_db_for_model_object);
269
+	}
270
+
271
+	/**
272
+	 * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a
273
+	 * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12,
274
+	 * 2013, at 3:23pm" instead of
275
+	 * "8765678632", or any other modifications to how the value should be displayed, but not modified itself.
276
+	 *
277
+	 * @param mixed $value_on_field_to_be_outputted
278
+	 * @return mixed
279
+	 */
280
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
281
+	{
282
+		return $value_on_field_to_be_outputted;
283
+	}
284
+
285
+
286
+	/**
287
+	 * Returns whatever is set as the nicename for the object.
288
+	 * @return string
289
+	 */
290
+	public function getSchemaDescription()
291
+	{
292
+		return $this->get_nicename();
293
+	}
294
+
295
+
296
+	/**
297
+	 * Returns whatever is set as the $_schema_type property for the object.
298
+	 * Note: this will automatically add 'null' to the schema if the object is_nullable()
299
+	 * @return string|array
300
+	 */
301
+	public function getSchemaType()
302
+	{
303
+		if ($this->is_nullable()) {
304
+			$this->_schema_type = (array) $this->_schema_type;
305
+			if (! in_array('null', $this->_schema_type)) {
306
+				$this->_schema_type[] = 'null';
307
+			};
308
+		}
309
+		return $this->_schema_type;
310
+	}
311
+
312
+
313
+	/**
314
+	 * Sets the _schema_type property.  Child classes should call this in their constructors to override the default state
315
+	 * for this property.
316
+	 * @param string|array $type
317
+	 * @throws InvalidArgumentException
318
+	 */
319
+	protected function setSchemaType($type)
320
+	{
321
+		$this->validateSchemaType($type);
322
+		$this->_schema_type = $type;
323
+	}
324
+
325
+
326
+	/**
327
+	 * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
328
+	 * this method and return the properties for the schema.
329
+	 *
330
+	 * The reason this is not a property on the class is because there may be filters set on the values for the property
331
+	 * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
332
+	 *
333
+	 * @return array
334
+	 */
335
+	public function getSchemaProperties()
336
+	{
337
+		return array();
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 * By default this returns the scalar default value that was sent in on the class prepped according to the class type
344
+	 * as the default.  However, when there are schema properties, then the default property is setup to mirror the
345
+	 * property keys and correctly prepare the default according to that expected property value.
346
+	 * The getSchema method validates whether the schema for default is setup correctly or not according to the schema type
347
+	 *
348
+	 * @return mixed
349
+	 */
350
+	public function getSchemaDefault()
351
+	{
352
+		$default_value = $this->prepare_for_use_in_db($this->prepare_for_set($this->get_default_value()));
353
+		$schema_properties = $this->getSchemaProperties();
354
+
355
+		//if this schema has properties than shape the default value to match the properties shape.
356
+		if ($schema_properties) {
357
+			$value_to_return = array();
358
+			foreach ($schema_properties as $property_key => $property_schema) {
359
+				switch ($property_key) {
360
+					case 'pretty':
361
+					case 'rendered':
362
+						$value_to_return[$property_key] = $this->prepare_for_pretty_echoing($this->prepare_for_set($default_value));
363
+						break;
364
+					default:
365
+						$value_to_return[$property_key] = $default_value;
366
+						break;
367
+				}
368
+			}
369
+			$default_value = $value_to_return;
370
+		}
371
+		return $default_value;
372
+	}
373
+
374
+
375
+
376
+
377
+	/**
378
+	 * If a child class has enum values, they should override this method and provide a simple array
379
+	 * of the enum values.
380
+	 * The reason this is not a property on the class is because there may be filterable enum values that
381
+	 * are set on the instantiated object that could be filtered after construct.
382
+	 *
383
+	 * @return array
384
+	 */
385
+	public function getSchemaEnum()
386
+	{
387
+		return array();
388
+	}
389
+
390
+
391
+	/**
392
+	 * This returns the value of the $_schema_format property on the object.
393
+	 * @return string
394
+	 */
395
+	public function getSchemaFormat()
396
+	{
397
+		return $this->_schema_format;
398
+	}
399
+
400
+
401
+	/**
402
+	 * Sets the schema format property.
403
+	 * @throws InvalidArgumentException
404
+	 * @param string $format
405
+	 */
406
+	protected function setSchemaFormat($format)
407
+	{
408
+		$this->validateSchemaFormat($format);
409
+		$this->_schema_format = $format;
410
+	}
411
+
412
+
413
+	/**
414
+	 * This returns the value of the $_schema_readonly property on the object.
415
+	 * @return bool
416
+	 */
417
+	public function getSchemaReadonly()
418
+	{
419
+		return $this->_schema_readonly;
420
+	}
421
+
422
+
423
+	/**
424
+	 * This sets the value for the $_schema_readonly property.
425
+	 * @param bool $readonly  (only explicit boolean values are accepted)
426
+	 */
427
+	protected function setSchemaReadOnly($readonly)
428
+	{
429
+		if (! is_bool($readonly)) {
430
+			throw new InvalidArgumentException(
431
+				sprintf(
432
+					esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'),
433
+					print_r($readonly, true)
434
+				)
435
+			);
436
+		}
437
+
438
+		$this->_schema_readonly = $readonly;
439
+	}
440
+
441
+
442
+
443
+
444
+	/**
445
+	 * Return `%d`, `%s` or `%f` to indicate the data type for the field.
446
+	 * @uses _get_wpdb_data_type()
447
+	 *
448
+	 * @return string
449
+	 */
450
+	public function get_wpdb_data_type()
451
+	{
452
+		return $this->_get_wpdb_data_type();
453
+	}
454
+
455
+
456
+	/**
457
+	 * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries.
458
+	 * @param string $type  Included if a specific type is requested.
459
+	 * @uses get_schema_type()
460
+	 * @return string
461
+	 */
462
+	protected function _get_wpdb_data_type($type='')
463
+	{
464
+		$type = empty($type) ? $this->getSchemaType() : $type;
465
+
466
+		//if type is an array, then different parsing is required.
467
+		if (is_array($type)) {
468
+			return $this->_get_wpdb_data_type_for_type_array($type);
469
+		}
470
+
471
+		$wpdb_type = '%s';
472
+		switch ($type) {
473
+			case 'number':
474
+				$wpdb_type = '%f';
475
+				break;
476
+			case 'integer':
477
+			case 'boolean':
478
+				$wpdb_type = '%d';
479
+				break;
480
+			case 'object':
481
+				$properties = $this->getSchemaProperties();
482
+				if (isset($properties['raw'], $properties['raw']['type'])) {
483
+					$wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']);
484
+				}
485
+				break; //leave at default
486
+		}
487
+		return $wpdb_type;
488
+	}
489
+
490
+
491
+
492
+	protected function _get_wpdb_data_type_for_type_array($type)
493
+	{
494
+		$type = (array) $type;
495
+		//first let's flip because then we can do a faster key check
496
+		$type = array_flip($type);
497
+
498
+		//check for things that mean '%s'
499
+		if (isset($type['string'],$type['object'],$type['array'])) {
500
+			return '%s';
501
+		}
502
+
503
+		//if makes it past the above condition and there's float in the array
504
+		//then the type is %f
505
+		if (isset($type['number'])) {
506
+			return '%f';
507
+		}
508
+
509
+		//if it makes it above the above conditions and there is an integer in the array
510
+		//then the type is %d
511
+		if (isset($type['integer'])) {
512
+			return '%d';
513
+		}
514
+
515
+		//anything else is a string
516
+		return '%s';
517
+	}
518
+
519
+
520
+	/**
521
+	 * This returns elements used to represent this field in the json schema.
522
+	 *
523
+	 * @link http://json-schema.org/
524
+	 * @return array
525
+	 */
526
+	public function getSchema()
527
+	{
528
+		$schema = array(
529
+			'description' => $this->getSchemaDescription(),
530
+			'type' => $this->getSchemaType(),
531
+			'readonly' => $this->getSchemaReadonly(),
532
+			'default' => $this->getSchemaDefault()
533
+		);
534
+
535
+		//optional properties of the schema
536
+		$enum = $this->getSchemaEnum();
537
+		$properties = $this->getSchemaProperties();
538
+		$format = $this->getSchemaFormat();
539
+		if ($enum) {
540
+			$schema['enum'] = $enum;
541
+		}
542
+
543
+		if ($properties) {
544
+			$schema['properties'] = $properties;
545
+		}
546
+
547
+		if ($format) {
548
+			$schema['format'] = $format;
549
+		}
550
+		return $schema;
551
+	}
552
+
553
+	/**
554
+	 * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part
555
+	 * of the model objects (ie, client code shouldn't care to ever see their value... if client code does
556
+	 * want to see their value, then they shouldn't be db-only fields!)
557
+	 * Eg, when doing events as custom post types, querying the post_type is essential, but
558
+	 * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event').
559
+	 * By default, all fields aren't db-only.
560
+	 *
561
+	 * @return boolean
562
+	 */
563
+	public function is_db_only_field()
564
+	{
565
+		return false;
566
+	}
567
+
568
+
569
+	/**
570
+	 * Validates the incoming string|array to ensure its an allowable type.
571
+	 * @throws InvalidArgumentException
572
+	 * @param string|array $type
573
+	 */
574
+	private function validateSchemaType($type)
575
+	{
576
+		if (! (is_string($type) || is_array($type))) {
577
+			throw new InvalidArgumentException(
578
+				sprintf(
579
+					esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'),
580
+					print_r($type, true)
581
+				)
582
+			);
583
+		}
584
+
585
+		//validate allowable types.
586
+		//@link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
587
+		$allowable_types = array_flip(
588
+			array(
589
+				'string',
590
+				'number',
591
+				'null',
592
+				'object',
593
+				'array',
594
+				'boolean',
595
+				'integer'
596
+			)
597
+		);
598
+
599
+		if (is_array($type)) {
600
+			foreach ($type as $item_in_type) {
601
+				$this->validateSchemaType($item_in_type);
602
+			}
603
+			return;
604
+		}
605
+
606
+		if (! isset($allowable_types[$type])) {
607
+			throw new InvalidArgumentException(
608
+				sprintf(
609
+					esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'),
610
+					$type,
611
+					implode(',', array_flip($allowable_types))
612
+				)
613
+			);
614
+		}
615
+	}
616
+
617
+
618
+	/**
619
+	 * Validates that the incoming format is an allowable string to use for the _schema_format property
620
+	 * @throws InvalidArgumentException
621
+	 * @param $format
622
+	 */
623
+	private function validateSchemaFormat($format)
624
+	{
625
+		if (! is_string($format)) {
626
+			throw new InvalidArgumentException(
627
+				sprintf(
628
+					esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'),
629
+					print_r($format, true)
630
+				)
631
+			);
632
+		}
633
+
634
+		//validate allowable format values
635
+		//@link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
636
+		$allowable_formats = array_flip(
637
+			array(
638
+				'date-time',
639
+				'email',
640
+				'hostname',
641
+				'ipv4',
642
+				'ipv6',
643
+				'uri',
644
+				'uriref'
645
+			)
646
+		);
647
+
648
+		if (! isset($allowable_formats[$format])) {
649
+			throw new InvalidArgumentException(
650
+				sprintf(
651
+					esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'),
652
+					$format,
653
+					implode(',', array_flip($allowable_formats))
654
+				)
655
+			);
656
+		}
657
+	}
659 658
 }
660 659
\ No newline at end of file
Please login to merge, or discard this patch.
caffeinated/payment_methods/Aim/EE_PMT_Aim.pm.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
 	public function __construct($pm_instance = NULL) {
23 23
 		$this->_setup_properties();
24 24
 		parent::__construct($pm_instance);
25
-        $this->_gateway->set_unsupported_character_remover(new \EventEspresso\core\services\formatters\Windows1252());
25
+		$this->_gateway->set_unsupported_character_remover(new \EventEspresso\core\services\formatters\Windows1252());
26 26
 	}
27 27
 	
28 28
 	/**
Please login to merge, or discard this patch.