Completed
Branch BUG-10381-asset-loading (361215)
by
unknown
158:58 queued 146:07
created
modules/mijireh_payment_checker/EED_Mijireh_Payment_Checker.module.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -45,23 +45,23 @@
 block discarded – undo
45 45
 
46 46
 
47 47
 
48
-    /**
49
-     * If the transaction has pending mijireh payments, we check with mijireh to see if they've been completed.
50
-     * @param EE_Transaction $transaction
51
-     * @throws EE_Error if a model is misconfigured
52
-     */
48
+	/**
49
+	 * If the transaction has pending mijireh payments, we check with mijireh to see if they've been completed.
50
+	 * @param EE_Transaction $transaction
51
+	 * @throws EE_Error if a model is misconfigured
52
+	 */
53 53
 	public static function check_for_payment_update_on_transaction( $transaction ) {
54 54
 		if( $transaction instanceof EE_Transaction ) {
55 55
 			//are there pending Mijireh payments on this transaction?
56
-            $a_mijireh_payment = EEM_Payment::instance()->get_one(
57
-                array(
58
-                    array(
59
-                        'TXN_ID' => $transaction->ID(),
60
-                        'STS_ID' => EEM_Payment::status_id_pending,
61
-                        'Payment_Method.PMD_type' => 'Mijireh',
62
-                    )
63
-                )
64
-            );
56
+			$a_mijireh_payment = EEM_Payment::instance()->get_one(
57
+				array(
58
+					array(
59
+						'TXN_ID' => $transaction->ID(),
60
+						'STS_ID' => EEM_Payment::status_id_pending,
61
+						'Payment_Method.PMD_type' => 'Mijireh',
62
+					)
63
+				)
64
+			);
65 65
 			if($a_mijireh_payment instanceof EE_Payment) {
66 66
 				add_action(
67 67
 					'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
3
-	exit( 'No direct script access allowed' );
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  * @author				Mike Nelson
20 20
  *
21 21
  */
22
-class EED_Mijireh_Payment_Checker extends EED_Module{
22
+class EED_Mijireh_Payment_Checker extends EED_Module {
23 23
 
24 24
 	/**
25 25
 	 * 	set_hooks - for hooking into EE Core, other modules, etc
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 *  @return 	void
41 41
 	 */
42 42
 	public static function set_hooks_admin() {
43
-		add_action( 'AHEE__Transactions_Admin_Page__transaction_details__start', array( 'EED_Mijireh_Payment_Checker', 'check_for_payment_update_on_transaction' ), 10, 1 );
43
+		add_action('AHEE__Transactions_Admin_Page__transaction_details__start', array('EED_Mijireh_Payment_Checker', 'check_for_payment_update_on_transaction'), 10, 1);
44 44
 	}
45 45
 
46 46
 
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
      * @param EE_Transaction $transaction
51 51
      * @throws EE_Error if a model is misconfigured
52 52
      */
53
-	public static function check_for_payment_update_on_transaction( $transaction ) {
54
-		if( $transaction instanceof EE_Transaction ) {
53
+	public static function check_for_payment_update_on_transaction($transaction) {
54
+		if ($transaction instanceof EE_Transaction) {
55 55
 			//are there pending Mijireh payments on this transaction?
56 56
             $a_mijireh_payment = EEM_Payment::instance()->get_one(
57 57
                 array(
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
                     )
63 63
                 )
64 64
             );
65
-			if($a_mijireh_payment instanceof EE_Payment) {
65
+			if ($a_mijireh_payment instanceof EE_Payment) {
66 66
 				add_action(
67 67
 					'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
68
-					array( 'EED_Mijireh_Payment_Checker', 'send_notifications_after_mijireh_ipn' ),
68
+					array('EED_Mijireh_Payment_Checker', 'send_notifications_after_mijireh_ipn'),
69 69
 					5, 2
70 70
 				);
71
-				EE_Payment_Processor::instance()->process_ipn( array(), $transaction, $a_mijireh_payment->payment_method() );
71
+				EE_Payment_Processor::instance()->process_ipn(array(), $transaction, $a_mijireh_payment->payment_method());
72 72
 			}
73 73
 		}
74 74
 	}
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
 	 * @param EE_Registration $registration
85 85
 	 * @param array $additional_details
86 86
 	 */
87
-	public static function send_notifications_after_mijireh_ipn( $registration, $additional_details ) {
88
-		$last_payment = isset( $additional_details[ 'last_payment' ] ) ? $additional_details[ 'last_payment' ] : null;
89
-		if ( ! $last_payment instanceof EE_Payment || $last_payment->status() != EEM_Payment::status_id_approved ) {
90
-			add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15 );
87
+	public static function send_notifications_after_mijireh_ipn($registration, $additional_details) {
88
+		$last_payment = isset($additional_details['last_payment']) ? $additional_details['last_payment'] : null;
89
+		if ( ! $last_payment instanceof EE_Payment || $last_payment->status() != EEM_Payment::status_id_approved) {
90
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
91 91
 		}
92 92
 	}
93 93
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 * @access    public
100 100
 	 * @param WP_Query $WP_Query
101 101
 	 */
102
-	public function run( $WP_Query = null ) {
102
+	public function run($WP_Query = null) {
103 103
 	}
104 104
 }
105 105
 
Please login to merge, or discard this patch.
caffeinated/payment_methods/Mijireh/EEG_Mijireh.gateway.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -111,45 +111,45 @@  discard block
 block discarded – undo
111 111
 			'body'=>  wp_json_encode($order)
112 112
 		);
113 113
 		$response = wp_remote_post( $this->_mijireh_api_orders_url, $args );
114
-                $problems_string = false;
114
+				$problems_string = false;
115 115
 		$this->log(array('get checkout url request_args' => $args, 'response' => $response ), $payment);
116 116
 		if( ! $response instanceof WP_Error ){
117 117
 			$response_body = json_decode($response['body']);
118 118
 			if($response_body && isset($response_body->checkout_url)){
119
-                            $payment->set_redirect_url($response_body->checkout_url);
120
-                            $payment->set_txn_id_chq_nmbr($response_body->order_number);
121
-                            $payment->set_details($response['body']);
119
+							$payment->set_redirect_url($response_body->checkout_url);
120
+							$payment->set_txn_id_chq_nmbr($response_body->order_number);
121
+							$payment->set_details($response['body']);
122 122
 			} else {
123
-                           if( is_array( $response_body ) || is_object( $response_body)){
124
-                                    $response_body_as_array = (array)$response_body;
125
-                                    foreach($response_body_as_array as $problem_parameter => $problems){
126
-                                            $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems));
127
-                                    }
128
-                            }else{
129
-                                    $problems_string = $response['body'];
130
-                            }
131
-                            if( ! $problems_string ) {
132
-                                //no message to show? wack
133
-                                if( isset( $response[ 'headers' ][ 'status' ] ) ){
134
-                                        $problems_string = $response[ 'headers' ][ 'status' ];
135
-                                }else{
136
-                                        $problems_string = __( 'No response from Mijireh', 'event_espresso' );
137
-                                }
138
-                            }
139
-                        }
123
+						   if( is_array( $response_body ) || is_object( $response_body)){
124
+									$response_body_as_array = (array)$response_body;
125
+									foreach($response_body_as_array as $problem_parameter => $problems){
126
+											$problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems));
127
+									}
128
+							}else{
129
+									$problems_string = $response['body'];
130
+							}
131
+							if( ! $problems_string ) {
132
+								//no message to show? wack
133
+								if( isset( $response[ 'headers' ][ 'status' ] ) ){
134
+										$problems_string = $response[ 'headers' ][ 'status' ];
135
+								}else{
136
+										$problems_string = __( 'No response from Mijireh', 'event_espresso' );
137
+								}
138
+							}
139
+						}
140 140
 		}else{
141
-                    $problems_string = implode( ",", $response->get_error_messages() );
141
+					$problems_string = implode( ",", $response->get_error_messages() );
142 142
 		}
143 143
                 
144
-                if( $problems_string ) {
145
-                    $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) );
146
-                    $payment->set_details( $response );
147
-                    $payment->set_redirect_url( null );
148
-                    //even though the payment's status is failed at this point anyways,
149
-                    //let's be explicit about it. The fact that the redirect url is null
150
-                    //should be enough to client code that they can't redirect the user
151
-                    $payment->set_status( $this->_pay_model->failed_status() );
152
-                }
144
+				if( $problems_string ) {
145
+					$payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) );
146
+					$payment->set_details( $response );
147
+					$payment->set_redirect_url( null );
148
+					//even though the payment's status is failed at this point anyways,
149
+					//let's be explicit about it. The fact that the redirect url is null
150
+					//should be enough to client code that they can't redirect the user
151
+					$payment->set_status( $this->_pay_model->failed_status() );
152
+				}
153 153
 		return $payment;
154 154
 	}
155 155
 
@@ -186,70 +186,70 @@  discard block
 block discarded – undo
186 186
 	 * @param array $update_info unused. We just use the $transaction
187 187
 	 * @param EEI_Transaction $transaction
188 188
 	 * @return \EEI_Payment
189
-     * @throws EE_Error
189
+	 * @throws EE_Error
190 190
 	 */
191 191
 	public function handle_payment_update($update_info, $transaction) {
192
-        foreach( $transaction->pending_payments() as $payment){
193
-		    $payment = $this->check_payment_in_mijireh($payment);
194
-            if( $payment->status() === $this->_pay_model->approved_status()){
195
-                return $payment;
196
-            }
197
-        }
198
-        $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL;
192
+		foreach( $transaction->pending_payments() as $payment){
193
+			$payment = $this->check_payment_in_mijireh($payment);
194
+			if( $payment->status() === $this->_pay_model->approved_status()){
195
+				return $payment;
196
+			}
197
+		}
198
+		$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL;
199 199
 
200
-        if ( ! $payment instanceof EEI_Payment ){
201
-            throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) );
202
-        }
203
-        return $payment;
200
+		if ( ! $payment instanceof EEI_Payment ){
201
+			throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) );
202
+		}
203
+		return $payment;
204 204
 	}
205 205
 
206 206
 
207 207
 
208
-    /**
209
-     * Checks the payment's status in Mijireh for this specific payment
210
-     * @param \EEI_Payment $payment
211
-     * @return \EEI_Payment
212
-     */
208
+	/**
209
+	 * Checks the payment's status in Mijireh for this specific payment
210
+	 * @param \EEI_Payment $payment
211
+	 * @return \EEI_Payment
212
+	 */
213 213
 	public function check_payment_in_mijireh( EEI_Payment $payment ){
214
-        $request_args = array(
215
-            'headers' => array(
216
-                'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ),
217
-                'Accept'=>'application/json'
218
-            )
219
-        );
214
+		$request_args = array(
215
+			'headers' => array(
216
+				'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ),
217
+				'Accept'=>'application/json'
218
+			)
219
+		);
220 220
 
221
-        $response = wp_remote_get(
222
-            $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(),
223
-            $request_args
224
-        );
221
+		$response = wp_remote_get(
222
+			$this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(),
223
+			$request_args
224
+		);
225 225
 
226
-        $this->log(
227
-            array( 'get payment status request_args' => $request_args, 'response' => $response ),
228
-            $payment
229
-        );
230
-        // validate response
231
-        $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : '';
232
-        if( $response && $response_body ){
233
-            switch( $response_body->status ){
234
-                case 'paid':
235
-                    $payment->set_status($this->_pay_model->approved_status());
236
-                    break;
237
-                case 'pending':
238
-                    $payment->set_status($this->_pay_model->pending_status());
239
-                    break;
240
-                default:
241
-                    $payment->set_status($this->_pay_model->declined_status());
242
-            }
226
+		$this->log(
227
+			array( 'get payment status request_args' => $request_args, 'response' => $response ),
228
+			$payment
229
+		);
230
+		// validate response
231
+		$response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : '';
232
+		if( $response && $response_body ){
233
+			switch( $response_body->status ){
234
+				case 'paid':
235
+					$payment->set_status($this->_pay_model->approved_status());
236
+					break;
237
+				case 'pending':
238
+					$payment->set_status($this->_pay_model->pending_status());
239
+					break;
240
+				default:
241
+					$payment->set_status($this->_pay_model->declined_status());
242
+			}
243 243
 
244
-        } else {
245
-            $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) );
246
-            $payment->set_details( $response );
247
-            $payment->set_status( $this->_pay_model->failed_status() );
248
-        }
249
-        // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage
244
+		} else {
245
+			$payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) );
246
+			$payment->set_details( $response );
247
+			$payment->set_status( $this->_pay_model->failed_status() );
248
+		}
249
+		// the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage
250 250
 //		$payment->set_status( $this->_pay_model->pending_status() );
251
-        return $payment;
252
-    }
251
+		return $payment;
252
+	}
253 253
 
254 254
 }
255 255
 
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @author				Mike Nelson
9 9
  *
10 10
  */
11
-class EEG_Mijireh extends EE_Offsite_Gateway{
11
+class EEG_Mijireh extends EE_Offsite_Gateway {
12 12
 
13 13
 	protected $_access_key;
14 14
 
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
 		$primary_attendee = $primary_registrant->attendee();
38 38
 		$items = array();
39 39
 		//if we're are charging for the full amount, show the normal line items
40
-		if( $this->_can_easily_itemize_transaction_for( $payment )){
40
+		if ($this->_can_easily_itemize_transaction_for($payment)) {
41 41
 			$total_line_item = $transaction->total_line_item();
42 42
 			$tax_total = $total_line_item->get_total_tax();
43
-			foreach($total_line_item->get_items() as $line_item){
43
+			foreach ($total_line_item->get_items() as $line_item) {
44 44
 				$items[] = array(
45 45
 					'name'=>apply_filters(
46 46
 						'FHEE__EEG_Mijireh__set_redirection_info__full_amount_line_item_name',
47
-						$this->_format_line_item_name( $line_item, $payment ),
47
+						$this->_format_line_item_name($line_item, $payment),
48 48
 						$line_item,
49 49
 						$payment,
50 50
 						$primary_registrant
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
 					'quantity'=>$line_item->quantity()
55 55
 				);
56 56
 			}
57
-		}else{//its a partial payment
57
+		} else {//its a partial payment
58 58
 			$tax_total = 0;
59 59
 			//partial payment, so just add 1 item
60 60
 			$items[] = array(
61 61
 				'name'=> apply_filters(
62 62
 					'FHEE__EEG_Mijireh__set_redirection_info__partial_amount_line_item_name',
63
-					$this->_format_partial_payment_line_item_name( $payment ),
63
+					$this->_format_partial_payment_line_item_name($payment),
64 64
 					$payment,
65 65
 					$primary_registrant
66 66
 				),
@@ -72,18 +72,18 @@  discard block
 block discarded – undo
72 72
 		$order = array(
73 73
 			'total'=>$this->format_currency($payment->amount()),
74 74
 			'return_url'=>$return_url,
75
-			'items'=>$this->_prepare_for_mijireh( $items ),
75
+			'items'=>$this->_prepare_for_mijireh($items),
76 76
 			'email'=>$primary_attendee->email(),
77 77
 			'first_name'=>$primary_attendee->fname(),
78 78
 			'last_name'=>$primary_attendee->lname(),
79 79
 			'tax'=>$this->format_currency($tax_total),
80 80
 			'partner_id'=>'ee');
81 81
 		//setup address?
82
-		if(		$primary_attendee->address()  &&
83
-				$primary_attendee->city()  &&
84
-				$primary_attendee->state_ID()  &&
85
-				$primary_attendee->country_ID()  &&
86
-				$primary_attendee->zip()  ){
82
+		if ($primary_attendee->address() &&
83
+				$primary_attendee->city() &&
84
+				$primary_attendee->state_ID() &&
85
+				$primary_attendee->country_ID() &&
86
+				$primary_attendee->zip()) {
87 87
 			$shipping_address = array(
88 88
 				'first_name'=>$primary_attendee->fname(),
89 89
 				'last_name'=>$primary_attendee->lname(),
@@ -93,62 +93,62 @@  discard block
 block discarded – undo
93 93
 				'zip_code' => $primary_attendee->zip(),
94 94
 				'country' => $primary_attendee->country_ID()
95 95
 			);
96
-			if( $primary_attendee->address2() ){
97
-				$shipping_address[ 'apt_suite' ] = $primary_attendee->address2();
96
+			if ($primary_attendee->address2()) {
97
+				$shipping_address['apt_suite'] = $primary_attendee->address2();
98 98
 			}
99
-			if( $primary_attendee->phone() ){
100
-				$shipping_address[ 'phone' ] = $primary_attendee->phone();
99
+			if ($primary_attendee->phone()) {
100
+				$shipping_address['phone'] = $primary_attendee->phone();
101 101
 			}
102
-			$order[ 'shipping_address' ] = $shipping_address;
102
+			$order['shipping_address'] = $shipping_address;
103 103
 		}
104
-		$order = apply_filters( 'FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant );
105
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this)) );
104
+		$order = apply_filters('FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant);
105
+		do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this)));
106 106
 		$args = array(
107 107
 			'headers' => array(
108
-				'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ),
108
+				'Authorization' => 'Basic '.base64_encode($this->_access_key.':'),
109 109
 				'Accept'=>'application/json'
110 110
 			),
111 111
 			'body'=>  wp_json_encode($order)
112 112
 		);
113
-		$response = wp_remote_post( $this->_mijireh_api_orders_url, $args );
113
+		$response = wp_remote_post($this->_mijireh_api_orders_url, $args);
114 114
                 $problems_string = false;
115
-		$this->log(array('get checkout url request_args' => $args, 'response' => $response ), $payment);
116
-		if( ! $response instanceof WP_Error ){
115
+		$this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment);
116
+		if ( ! $response instanceof WP_Error) {
117 117
 			$response_body = json_decode($response['body']);
118
-			if($response_body && isset($response_body->checkout_url)){
118
+			if ($response_body && isset($response_body->checkout_url)) {
119 119
                             $payment->set_redirect_url($response_body->checkout_url);
120 120
                             $payment->set_txn_id_chq_nmbr($response_body->order_number);
121 121
                             $payment->set_details($response['body']);
122 122
 			} else {
123
-                           if( is_array( $response_body ) || is_object( $response_body)){
124
-                                    $response_body_as_array = (array)$response_body;
125
-                                    foreach($response_body_as_array as $problem_parameter => $problems){
126
-                                            $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems));
123
+                           if (is_array($response_body) || is_object($response_body)) {
124
+                                    $response_body_as_array = (array) $response_body;
125
+                                    foreach ($response_body_as_array as $problem_parameter => $problems) {
126
+                                            $problems_string .= sprintf(__('\nProblems with %s: %s', 'event_espresso'), $problem_parameter, implode(", ", $problems));
127 127
                                     }
128
-                            }else{
128
+                            } else {
129 129
                                     $problems_string = $response['body'];
130 130
                             }
131
-                            if( ! $problems_string ) {
131
+                            if ( ! $problems_string) {
132 132
                                 //no message to show? wack
133
-                                if( isset( $response[ 'headers' ][ 'status' ] ) ){
134
-                                        $problems_string = $response[ 'headers' ][ 'status' ];
135
-                                }else{
136
-                                        $problems_string = __( 'No response from Mijireh', 'event_espresso' );
133
+                                if (isset($response['headers']['status'])) {
134
+                                        $problems_string = $response['headers']['status'];
135
+                                } else {
136
+                                        $problems_string = __('No response from Mijireh', 'event_espresso');
137 137
                                 }
138 138
                             }
139 139
                         }
140
-		}else{
141
-                    $problems_string = implode( ",", $response->get_error_messages() );
140
+		} else {
141
+                    $problems_string = implode(",", $response->get_error_messages());
142 142
 		}
143 143
                 
144
-                if( $problems_string ) {
145
-                    $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) );
146
-                    $payment->set_details( $response );
147
-                    $payment->set_redirect_url( null );
144
+                if ($problems_string) {
145
+                    $payment->set_gateway_response(sprintf(__('Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string));
146
+                    $payment->set_details($response);
147
+                    $payment->set_redirect_url(null);
148 148
                     //even though the payment's status is failed at this point anyways,
149 149
                     //let's be explicit about it. The fact that the redirect url is null
150 150
                     //should be enough to client code that they can't redirect the user
151
-                    $payment->set_status( $this->_pay_model->failed_status() );
151
+                    $payment->set_status($this->_pay_model->failed_status());
152 152
                 }
153 153
 		return $payment;
154 154
 	}
@@ -161,16 +161,16 @@  discard block
 block discarded – undo
161 161
 	 * @param mixed $data
162 162
 	 * @return mixed same type as $data
163 163
 	 */
164
-	private function _prepare_for_mijireh( $data ){
165
-		if( is_array( $data ) ){
164
+	private function _prepare_for_mijireh($data) {
165
+		if (is_array($data)) {
166 166
 			$prepared_data = array();
167
-			foreach($data as $key => $datum ){
168
-				$prepared_data[ $key ] = $this->_prepare_for_mijireh( $datum );
167
+			foreach ($data as $key => $datum) {
168
+				$prepared_data[$key] = $this->_prepare_for_mijireh($datum);
169 169
 			}
170 170
 			return $prepared_data;
171
-		}elseif(is_string( $data ) ){
172
-			return str_replace( '%', 'percent', $data );
173
-		}else{
171
+		}elseif (is_string($data)) {
172
+			return str_replace('%', 'percent', $data);
173
+		} else {
174 174
 			return $data;
175 175
 		}
176 176
 	}
@@ -189,16 +189,16 @@  discard block
 block discarded – undo
189 189
      * @throws EE_Error
190 190
 	 */
191 191
 	public function handle_payment_update($update_info, $transaction) {
192
-        foreach( $transaction->pending_payments() as $payment){
192
+        foreach ($transaction->pending_payments() as $payment) {
193 193
 		    $payment = $this->check_payment_in_mijireh($payment);
194
-            if( $payment->status() === $this->_pay_model->approved_status()){
194
+            if ($payment->status() === $this->_pay_model->approved_status()) {
195 195
                 return $payment;
196 196
             }
197 197
         }
198 198
         $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL;
199 199
 
200
-        if ( ! $payment instanceof EEI_Payment ){
201
-            throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) );
200
+        if ( ! $payment instanceof EEI_Payment) {
201
+            throw new EE_Error(sprintf(__("Could not find Mijireh payment for transaction %s", 'event_espresso'), $transaction->ID()));
202 202
         }
203 203
         return $payment;
204 204
 	}
@@ -210,27 +210,27 @@  discard block
 block discarded – undo
210 210
      * @param \EEI_Payment $payment
211 211
      * @return \EEI_Payment
212 212
      */
213
-	public function check_payment_in_mijireh( EEI_Payment $payment ){
213
+	public function check_payment_in_mijireh(EEI_Payment $payment) {
214 214
         $request_args = array(
215 215
             'headers' => array(
216
-                'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ),
216
+                'Authorization' => 'Basic '.base64_encode($this->_access_key.':'),
217 217
                 'Accept'=>'application/json'
218 218
             )
219 219
         );
220 220
 
221 221
         $response = wp_remote_get(
222
-            $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(),
222
+            $this->_mijireh_api_orders_url.'/'.$payment->txn_id_chq_nmbr(),
223 223
             $request_args
224 224
         );
225 225
 
226 226
         $this->log(
227
-            array( 'get payment status request_args' => $request_args, 'response' => $response ),
227
+            array('get payment status request_args' => $request_args, 'response' => $response),
228 228
             $payment
229 229
         );
230 230
         // validate response
231
-        $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : '';
232
-        if( $response && $response_body ){
233
-            switch( $response_body->status ){
231
+        $response_body = isset($response['body']) ? json_decode($response['body']) : '';
232
+        if ($response && $response_body) {
233
+            switch ($response_body->status) {
234 234
                 case 'paid':
235 235
                     $payment->set_status($this->_pay_model->approved_status());
236 236
                     break;
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
             }
243 243
 
244 244
         } else {
245
-            $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) );
246
-            $payment->set_details( $response );
247
-            $payment->set_status( $this->_pay_model->failed_status() );
245
+            $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso'));
246
+            $payment->set_details($response);
247
+            $payment->set_status($this->_pay_model->failed_status());
248 248
         }
249 249
         // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage
250 250
 //		$payment->set_status( $this->_pay_model->pending_status() );
Please login to merge, or discard this patch.
core/libraries/iframe_display/EventListIframeEmbedButton.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -15,21 +15,21 @@  discard block
 block discarded – undo
15 15
 class EventListIframeEmbedButton extends IframeEmbedButton
16 16
 {
17 17
 
18
-    /**
19
-     * EventListIframeEmbedButton constructor.
20
-     */
21
-    public function __construct()
22
-    {
23
-        parent::__construct(
24
-            esc_html__( 'Upcoming Event List', 'event_espresso' ),
25
-            'event_list'
26
-        );
27
-    }
18
+	/**
19
+	 * EventListIframeEmbedButton constructor.
20
+	 */
21
+	public function __construct()
22
+	{
23
+		parent::__construct(
24
+			esc_html__( 'Upcoming Event List', 'event_espresso' ),
25
+			'event_list'
26
+		);
27
+	}
28 28
 
29 29
 
30 30
 
31 31
 	public function addEmbedButton() {
32
-        add_filter(
32
+		add_filter(
33 33
 			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
34 34
 			array( $this, 'addEventListIframeEmbedButtonSection' )
35 35
 		);
@@ -49,18 +49,18 @@  discard block
 block discarded – undo
49 49
 	 * @param array $after_list_table
50 50
 	 * @return array
51 51
 	 */
52
-    public function addEventListIframeEmbedButtonSection( array $after_list_table )
53
-    {
54
-        return \EEH_Array::insert_into_array(
55
-    		$after_list_table,
56
-		    array(
57
-			    'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection(
58
-				    array( 'event_list' => $this->embedButtonHtml() )
59
-			    )
60
-		    ),
61
-		    'legend'
62
-	    );
63
-    }
52
+	public function addEventListIframeEmbedButtonSection( array $after_list_table )
53
+	{
54
+		return \EEH_Array::insert_into_array(
55
+			$after_list_table,
56
+			array(
57
+				'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection(
58
+					array( 'event_list' => $this->embedButtonHtml() )
59
+				)
60
+			),
61
+			'legend'
62
+		);
63
+	}
64 64
 
65 65
 
66 66
 
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\iframe_display;
3 3
 
4
-defined( 'ABSPATH' ) || exit;
4
+defined('ABSPATH') || exit;
5 5
 
6 6
 
7 7
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
     public function __construct()
22 22
     {
23 23
         parent::__construct(
24
-            esc_html__( 'Upcoming Event List', 'event_espresso' ),
24
+            esc_html__('Upcoming Event List', 'event_espresso'),
25 25
             'event_list'
26 26
         );
27 27
     }
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
 	public function addEmbedButton() {
32 32
         add_filter(
33 33
 			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
34
-			array( $this, 'addEventListIframeEmbedButtonSection' )
34
+			array($this, 'addEventListIframeEmbedButtonSection')
35 35
 		);
36 36
 		add_action(
37 37
 			'admin_enqueue_scripts',
38
-			array( $this, 'embedButtonAssets' ),
38
+			array($this, 'embedButtonAssets'),
39 39
 			10
40 40
 		);
41 41
 	}
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
 	 * @param array $after_list_table
50 50
 	 * @return array
51 51
 	 */
52
-    public function addEventListIframeEmbedButtonSection( array $after_list_table )
52
+    public function addEventListIframeEmbedButtonSection(array $after_list_table)
53 53
     {
54 54
         return \EEH_Array::insert_into_array(
55 55
     		$after_list_table,
56 56
 		    array(
57 57
 			    'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection(
58
-				    array( 'event_list' => $this->embedButtonHtml() )
58
+				    array('event_list' => $this->embedButtonHtml())
59 59
 			    )
60 60
 		    ),
61 61
 		    'legend'
Please login to merge, or discard this patch.
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_Transaction_Processor.class.php 2 patches
Indentation   +36 added lines, -37 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
  * the interaction of EE_Transaction and EE_Registration model objects
8 8
  * Provides methods for manipulating and processing changes to an EE_Transaction
9 9
  * and it's related EE_Registrations with regards to the checkout/registration process
10
-
11
-*
10
+ *
12 11
 *@package     Event Espresso
13 12
  * @subpackage 	core
14 13
  * @author      Brent Christensen
@@ -177,24 +176,24 @@  discard block
 block discarded – undo
177 176
 
178 177
 
179 178
 
180
-    /**
181
-     * update_transaction_and_registrations_after_checkout_or_payment
182
-     * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
183
-     *
184
-     * @param EE_Transaction $transaction
185
-     * @param \EE_Payment | NULL $payment
186
-     * @param array              $registration_query_params    array of query WHERE params to use
187
-     *                                                         when retrieving cached registrations from a transaction
188
-     * @param bool $trigger_notifications                      whether or not to call
189
-     *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
190
-     * @return array
191
-     * @throws \EE_Error
192
-     */
179
+	/**
180
+	 * update_transaction_and_registrations_after_checkout_or_payment
181
+	 * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
182
+	 *
183
+	 * @param EE_Transaction $transaction
184
+	 * @param \EE_Payment | NULL $payment
185
+	 * @param array              $registration_query_params    array of query WHERE params to use
186
+	 *                                                         when retrieving cached registrations from a transaction
187
+	 * @param bool $trigger_notifications                      whether or not to call
188
+	 *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
189
+	 * @return array
190
+	 * @throws \EE_Error
191
+	 */
193 192
 	public function update_transaction_and_registrations_after_checkout_or_payment(
194 193
 		EE_Transaction $transaction,
195 194
 		$payment = null,
196 195
 		$registration_query_params = array(),
197
-        $trigger_notifications = true
196
+		$trigger_notifications = true
198 197
 	) {
199 198
 		// make sure some query params are set for retrieving registrations
200 199
 		$this->_set_registration_query_params( $registration_query_params );
@@ -224,15 +223,15 @@  discard block
 block discarded – undo
224 223
 			$update_params
225 224
 		);
226 225
 		if ($trigger_notifications) {
227
-            // send messages
228
-            /** @type EE_Registration_Processor $registration_processor */
229
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
230
-            $registration_processor->trigger_registration_update_notifications(
231
-                $transaction->primary_registration(),
232
-                $update_params
233
-            );
234
-        }
235
-        do_action(
226
+			// send messages
227
+			/** @type EE_Registration_Processor $registration_processor */
228
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
229
+			$registration_processor->trigger_registration_update_notifications(
230
+				$transaction->primary_registration(),
231
+				$update_params
232
+			);
233
+		}
234
+		do_action(
236 235
 			'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment',
237 236
 			$transaction,
238 237
 			$update_params
@@ -242,17 +241,17 @@  discard block
 block discarded – undo
242 241
 
243 242
 
244 243
 
245
-    /**
246
-     * update_transaction_after_registration_reopened
247
-     * readjusts TXN and Line Item totals after a registration is changed from
248
-     * cancelled or declined to another reg status such as pending payment or approved
249
-     *
250
-     * @param \EE_Registration $registration
251
-     * @param array            $closed_reg_statuses
252
-     * @param bool             $update_txn
253
-     * @return bool
254
-     * @throws \EE_Error
255
-     */
244
+	/**
245
+	 * update_transaction_after_registration_reopened
246
+	 * readjusts TXN and Line Item totals after a registration is changed from
247
+	 * cancelled or declined to another reg status such as pending payment or approved
248
+	 *
249
+	 * @param \EE_Registration $registration
250
+	 * @param array            $closed_reg_statuses
251
+	 * @param bool             $update_txn
252
+	 * @return bool
253
+	 * @throws \EE_Error
254
+	 */
256 255
 	public function update_transaction_after_reinstating_canceled_registration(
257 256
 		EE_Registration $registration,
258 257
 		$closed_reg_statuses = array(),
@@ -523,7 +522,7 @@  discard block
 block discarded – undo
523 522
 						foreach ( $available_payment_methods as $available_payment_method ) {
524 523
 							if (
525 524
 								$available_payment_method instanceof EE_Payment_Method
526
-							    && $available_payment_method->open_by_default()
525
+								&& $available_payment_method->open_by_default()
527 526
 							) {
528 527
 								$PMD_ID = $available_payment_method->ID();
529 528
 								break;
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2
-EE_Registry::instance()->load_class( 'Processor_Base' );
2
+EE_Registry::instance()->load_class('Processor_Base');
3 3
 
4 4
 /**
5 5
  * Class EE_Transaction_Processor
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 	 * @param array $registration_query_params
51 51
 	 *@return EE_Transaction_Processor instance
52 52
 	 */
53
-	public static function instance( $registration_query_params = array() ) {
53
+	public static function instance($registration_query_params = array()) {
54 54
 		// check if class object is instantiated
55
-		if ( ! self::$_instance instanceof EE_Transaction_Processor ) {
56
-			self::$_instance = new self( $registration_query_params );
55
+		if ( ! self::$_instance instanceof EE_Transaction_Processor) {
56
+			self::$_instance = new self($registration_query_params);
57 57
 		}
58 58
 		return self::$_instance;
59 59
 	}
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 	/**
64 64
 	 * @param array $registration_query_params
65 65
 	 */
66
-	private function __construct( $registration_query_params = array() ) {
66
+	private function __construct($registration_query_params = array()) {
67 67
 		// make sure some query params are set for retrieving registrations
68
-		$this->_set_registration_query_params( $registration_query_params );
68
+		$this->_set_registration_query_params($registration_query_params);
69 69
 	}
70 70
 
71 71
 
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 * @access private
75 75
 	 * @param array $registration_query_params
76 76
 	 */
77
-	private function _set_registration_query_params( $registration_query_params ) {
78
-		$this->_registration_query_params = ! empty( $registration_query_params ) ? $registration_query_params : array( 'order_by' => array( 'REG_count' => 'ASC' ));
77
+	private function _set_registration_query_params($registration_query_params) {
78
+		$this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params : array('order_by' => array('REG_count' => 'ASC'));
79 79
 	}
80 80
 
81 81
 
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
 		);
105 105
 		// send messages
106 106
 		/** @type EE_Registration_Processor $registration_processor */
107
-		$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
107
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
108 108
 		$registration_processor->trigger_registration_update_notifications(
109 109
 			$transaction->primary_registration(),
110
-			array( 'manually_updated' 	=> true )
110
+			array('manually_updated' 	=> true)
111 111
 		);
112 112
 		do_action(
113 113
 			'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
         $trigger_notifications = true
198 198
 	) {
199 199
 		// make sure some query params are set for retrieving registrations
200
-		$this->_set_registration_query_params( $registration_query_params );
200
+		$this->_set_registration_query_params($registration_query_params);
201 201
 		// get final reg step status
202 202
 		$finalized = $transaction->final_reg_step_completed();
203 203
 		// if the 'finalize_registration' step has been initiated (has a timestamp)
204 204
 		// but has not yet been fully completed (TRUE)
205
-		if ( is_int( $finalized ) && $finalized !== false && $finalized !== true ) {
206
-			$transaction->set_reg_step_completed( 'finalize_registration' );
205
+		if (is_int($finalized) && $finalized !== false && $finalized !== true) {
206
+			$transaction->set_reg_step_completed('finalize_registration');
207 207
 			$finalized = true;
208 208
 		}
209 209
 		$transaction->save();
@@ -259,22 +259,22 @@  discard block
 block discarded – undo
259 259
 		$update_txn = true
260 260
 	) {
261 261
 		// these reg statuses should not be considered in any calculations involving monies owing
262
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
263
-		if ( in_array( $registration->status_ID(), $closed_reg_statuses, true ) ) {
262
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
263
+		if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
264 264
 			return false;
265 265
 		}
266 266
 		try {
267
-			$transaction = $this->get_transaction_for_registration( $registration );
267
+			$transaction = $this->get_transaction_for_registration($registration);
268 268
 			$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
269 269
 				$transaction,
270 270
 				$registration
271 271
 			);
272 272
 			// un-cancel the ticket
273
-			$success = EEH_Line_Item::reinstate_canceled_ticket_line_item( $ticket_line_item );
274
-		} catch ( EE_Error $e ) {
273
+			$success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item);
274
+		} catch (EE_Error $e) {
275 275
 			EE_Error::add_error(
276 276
 				sprintf(
277
-					__( 'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', 'event_espresso' ),
277
+					__('The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', 'event_espresso'),
278 278
 					$registration->ID(),
279 279
 					'<br />',
280 280
 					$e->getMessage()
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 			);
284 284
 			return false;
285 285
 		}
286
-		if ( $update_txn ) {
286
+		if ($update_txn) {
287 287
 			return $transaction->save() ? $success : false;
288 288
 		}
289 289
 		return $success;
@@ -307,18 +307,18 @@  discard block
 block discarded – undo
307 307
 		$update_txn = true
308 308
 	) {
309 309
 		// these reg statuses should not be considered in any calculations involving monies owing
310
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
311
-		if ( ! in_array( $registration->status_ID(), $closed_reg_statuses, true ) ) {
310
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
311
+		if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
312 312
 			return false;
313 313
 		}
314 314
 		try {
315
-			$transaction = $this->get_transaction_for_registration( $registration );
316
-			$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( $transaction, $registration );
317
-			EEH_Line_Item::cancel_ticket_line_item( $ticket_line_item );
318
-		} catch ( EE_Error $e ) {
315
+			$transaction = $this->get_transaction_for_registration($registration);
316
+			$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration($transaction, $registration);
317
+			EEH_Line_Item::cancel_ticket_line_item($ticket_line_item);
318
+		} catch (EE_Error $e) {
319 319
 			EE_Error::add_error(
320 320
 				sprintf(
321
-					__( 'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', 'event_espresso' ),
321
+					__('The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', 'event_espresso'),
322 322
 					$registration->ID(),
323 323
 					'<br />',
324 324
 					$e->getMessage()
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 			);
328 328
 			return false;
329 329
 		}
330
-		if ( $update_txn ) {
330
+		if ($update_txn) {
331 331
 			return $transaction->save() ? true : false;
332 332
 		}
333 333
 		return true;
@@ -343,12 +343,12 @@  discard block
 block discarded – undo
343 343
 	 * @return 	EE_Transaction
344 344
 	 * @throws 	EE_Error
345 345
 	 */
346
-	public function get_transaction_for_registration( EE_Registration $registration ) {
346
+	public function get_transaction_for_registration(EE_Registration $registration) {
347 347
 		$transaction = $registration->transaction();
348
-		if ( ! $transaction instanceof EE_Transaction ) {
348
+		if ( ! $transaction instanceof EE_Transaction) {
349 349
 			throw new EE_Error(
350 350
 				sprintf(
351
-					__( 'The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso' ),
351
+					__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
352 352
 					$registration->ID()
353 353
 				)
354 354
 			);
@@ -371,16 +371,16 @@  discard block
 block discarded – undo
371 371
 		EE_Transaction $transaction,
372 372
 		EE_Registration $registration
373 373
 	) {
374
-		EE_Registry::instance()->load_helper( 'Line_Item' );
374
+		EE_Registry::instance()->load_helper('Line_Item');
375 375
 		$ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction(
376 376
 			$transaction->ID(),
377 377
 			$registration->ticket_ID()
378 378
 		);
379
-		if ( ! $ticket_line_item instanceof EE_Line_Item ) {
379
+		if ( ! $ticket_line_item instanceof EE_Line_Item) {
380 380
 			throw new EE_Error(
381 381
 				sprintf(
382
-					__( 'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
383
-						'event_espresso' ),
382
+					__('The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
383
+						'event_espresso'),
384 384
 					$transaction->ID(),
385 385
 					$registration->ticket_ID()
386 386
 				)
@@ -413,22 +413,22 @@  discard block
 block discarded – undo
413 413
 		$update_txn = true
414 414
 	) {
415 415
 		// make sure some query params are set for retrieving registrations
416
-		$this->_set_registration_query_params( $registration_query_params );
416
+		$this->_set_registration_query_params($registration_query_params);
417 417
 		// these reg statuses should not be considered in any calculations involving monies owing
418
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
418
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
419 419
 		// loop through cached registrations
420
-		foreach ( $transaction->registrations( $this->_registration_query_params ) as $registration ) {
420
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
421 421
 			if (
422 422
 				$registration instanceof EE_Registration
423
-				&& ! in_array( $registration->status_ID(), $closed_reg_statuses )
423
+				&& ! in_array($registration->status_ID(), $closed_reg_statuses)
424 424
 			) {
425 425
 				return false;
426 426
 			}
427 427
 		}
428
-		if ( in_array( $new_TXN_status, EEM_Transaction::txn_status_array() ) ) {
429
-			$transaction->set_status( $new_TXN_status );
428
+		if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) {
429
+			$transaction->set_status($new_TXN_status);
430 430
 		}
431
-		if ( $update_txn ) {
431
+		if ($update_txn) {
432 432
 			return $transaction->save() ? true : false;
433 433
 		}
434 434
 		return true;
@@ -457,22 +457,22 @@  discard block
 block discarded – undo
457 457
 	) {
458 458
 		$response = false;
459 459
 		/** @type EE_Registration_Processor $registration_processor */
460
-		$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
460
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
461 461
 		// check that method exists
462
-		if ( ! method_exists( $registration_processor, $method_name )) {
463
-			throw new EE_Error( __( 'Method does not exist.', 'event_espresso' ));
462
+		if ( ! method_exists($registration_processor, $method_name)) {
463
+			throw new EE_Error(__('Method does not exist.', 'event_espresso'));
464 464
 		}
465 465
 		// make sure some query params are set for retrieving registrations
466
-		$this->_set_registration_query_params( $registration_query_params );
466
+		$this->_set_registration_query_params($registration_query_params);
467 467
 		// loop through cached registrations
468
-		foreach ( $transaction->registrations( $this->_registration_query_params ) as $registration ) {
469
-			if ( $registration instanceof EE_Registration ) {
470
-				if ( $additional_param ) {
471
-					$response = $registration_processor->{$method_name}( $registration, $additional_param )
468
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
469
+			if ($registration instanceof EE_Registration) {
470
+				if ($additional_param) {
471
+					$response = $registration_processor->{$method_name}($registration, $additional_param)
472 472
 						? true
473 473
 						: $response;
474 474
 				} else {
475
-					$response = $registration_processor->{$method_name}( $registration )
475
+					$response = $registration_processor->{$method_name}($registration)
476 476
 						? true
477 477
 						: $response;
478 478
 				}
@@ -499,28 +499,28 @@  discard block
 block discarded – undo
499 499
 	public function set_transaction_payment_method_based_on_registration_statuses(
500 500
 		EE_Registration $edited_registration
501 501
 	) {
502
-		if ( $edited_registration instanceof EE_Registration ) {
502
+		if ($edited_registration instanceof EE_Registration) {
503 503
 			$transaction = $edited_registration->transaction();
504
-			if ( $transaction instanceof EE_Transaction ) {
504
+			if ($transaction instanceof EE_Transaction) {
505 505
 				$all_not_approved = true;
506
-				foreach ( $transaction->registrations() as $registration ) {
507
-					if ( $registration instanceof EE_Registration ) {
506
+				foreach ($transaction->registrations() as $registration) {
507
+					if ($registration instanceof EE_Registration) {
508 508
 						// if any REG != "Not Approved" then toggle to false
509 509
 						$all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
510 510
 					}
511 511
 				}
512 512
 				// if ALL Registrations are "Not Approved"
513
-				if ( $all_not_approved ) {
514
-					$transaction->set_payment_method_ID( null );
513
+				if ($all_not_approved) {
514
+					$transaction->set_payment_method_ID(null);
515 515
 					$transaction->save();
516 516
 				} else {
517 517
 					$available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
518 518
 						$transaction,
519 519
 						EEM_Payment_Method::scope_cart
520 520
 					);
521
-					if ( ! empty( $available_payment_methods ) ) {
521
+					if ( ! empty($available_payment_methods)) {
522 522
 						$PMD_ID = 0;
523
-						foreach ( $available_payment_methods as $available_payment_method ) {
523
+						foreach ($available_payment_methods as $available_payment_method) {
524 524
 							if (
525 525
 								$available_payment_method instanceof EE_Payment_Method
526 526
 							    && $available_payment_method->open_by_default()
@@ -529,22 +529,22 @@  discard block
 block discarded – undo
529 529
 								break;
530 530
 							}
531 531
 						}
532
-						if ( ! $PMD_ID ) {
533
-							$first_payment_method = reset( $available_payment_methods );
534
-							if ( $first_payment_method instanceof EE_Payment_Method ) {
532
+						if ( ! $PMD_ID) {
533
+							$first_payment_method = reset($available_payment_methods);
534
+							if ($first_payment_method instanceof EE_Payment_Method) {
535 535
 								$PMD_ID = $first_payment_method->ID();
536 536
 							} else {
537 537
 								EE_Error::add_error(
538
-									__( 'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso' ),
538
+									__('A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso'),
539 539
 									__FILE__, __LINE__, __FUNCTION__
540 540
 								);
541 541
 							}
542 542
 						}
543
-						$transaction->set_payment_method_ID( $PMD_ID );
543
+						$transaction->set_payment_method_ID($PMD_ID);
544 544
 						$transaction->save();
545 545
 					} else {
546 546
 						EE_Error::add_error(
547
-							__( 'Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso' ),
547
+							__('Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso'),
548 548
 							__FILE__, __LINE__, __FUNCTION__
549 549
 						);
550 550
 					}
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 	 * @deprecated 4.9.12
582 582
 	 * @param string $old_txn_status
583 583
 	 */
584
-	public function set_old_txn_status( $old_txn_status ) {
584
+	public function set_old_txn_status($old_txn_status) {
585 585
 		EE_Error::doing_it_wrong(
586 586
 			__METHOD__,
587 587
 			esc_html__(
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 			'4.9.12'
592 592
 		);
593 593
 		// only set the first time
594
-		if ( $this->_old_txn_status === null ) {
594
+		if ($this->_old_txn_status === null) {
595 595
 			$this->_old_txn_status = $old_txn_status;
596 596
 		}
597 597
 	}
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
 	 * @deprecated 4.9.12
621 621
 	 * @param string $new_txn_status
622 622
 	 */
623
-	public function set_new_txn_status( $new_txn_status ) {
623
+	public function set_new_txn_status($new_txn_status) {
624 624
 		EE_Error::doing_it_wrong(
625 625
 			__METHOD__,
626 626
 			esc_html__(
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 	 * @param EE_Transaction $transaction
665 665
 	 * @return boolean
666 666
 	 */
667
-	public function all_reg_steps_completed( EE_Transaction $transaction ) {
667
+	public function all_reg_steps_completed(EE_Transaction $transaction) {
668 668
 		EE_Error::doing_it_wrong(
669 669
 			__METHOD__,
670 670
 			esc_html__(
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 	 * @param string         $exception
692 692
 	 * @return boolean
693 693
 	 */
694
-	public function all_reg_steps_completed_except( EE_Transaction $transaction, $exception = '' ) {
694
+	public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '') {
695 695
 		EE_Error::doing_it_wrong(
696 696
 			__METHOD__,
697 697
 			esc_html__(
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
 			'4.9.12',
702 702
 			'5.0.0'
703 703
 		);
704
-		return $transaction->all_reg_steps_completed_except( $exception );
704
+		return $transaction->all_reg_steps_completed_except($exception);
705 705
 	}
706 706
 
707 707
 
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
 	 * @param EE_Transaction $transaction
718 718
 	 * @return boolean
719 719
 	 */
720
-	public function all_reg_steps_completed_except_final_step( EE_Transaction $transaction ) {
720
+	public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction) {
721 721
 		EE_Error::doing_it_wrong(
722 722
 			__METHOD__,
723 723
 			esc_html__(
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 	 * @param string         $reg_step_slug
745 745
 	 * @return boolean | int
746 746
 	 */
747
-	public function reg_step_completed( EE_Transaction $transaction, $reg_step_slug ) {
747
+	public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug) {
748 748
 		EE_Error::doing_it_wrong(
749 749
 			__METHOD__,
750 750
 			esc_html__(
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 			'4.9.12',
755 755
 			'5.0.0'
756 756
 		);
757
-		return $transaction->reg_step_completed( $reg_step_slug );
757
+		return $transaction->reg_step_completed($reg_step_slug);
758 758
 	}
759 759
 
760 760
 
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
 	 * @param EE_Transaction $transaction
771 771
 	 * @return boolean | int
772 772
 	 */
773
-	public function final_reg_step_completed( EE_Transaction $transaction ) {
773
+	public function final_reg_step_completed(EE_Transaction $transaction) {
774 774
 		EE_Error::doing_it_wrong(
775 775
 			__METHOD__,
776 776
 			esc_html__(
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
 	 * @return boolean
797 797
 	 * @throws \EE_Error
798 798
 	 */
799
-	public function set_reg_step_initiated( EE_Transaction $transaction, $reg_step_slug ) {
799
+	public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug) {
800 800
 		EE_Error::doing_it_wrong(
801 801
 			__METHOD__,
802 802
 			esc_html__(
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
 			'4.9.12',
807 807
 			'5.0.0'
808 808
 		);
809
-		return $transaction->set_reg_step_initiated( $reg_step_slug );
809
+		return $transaction->set_reg_step_initiated($reg_step_slug);
810 810
 	}
811 811
 
812 812
 
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
 	 * @return boolean
823 823
 	 * @throws \EE_Error
824 824
 	 */
825
-	public function set_reg_step_completed( EE_Transaction $transaction, $reg_step_slug ) {
825
+	public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug) {
826 826
 		EE_Error::doing_it_wrong(
827 827
 			__METHOD__,
828 828
 			esc_html__(
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 			'4.9.12',
833 833
 			'5.0.0'
834 834
 		);
835
-		return $transaction->set_reg_step_completed( $reg_step_slug );
835
+		return $transaction->set_reg_step_completed($reg_step_slug);
836 836
 	}
837 837
 
838 838
 
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	 * @return boolean
849 849
 	 * @throws \EE_Error
850 850
 	 */
851
-	public function set_reg_step_not_completed( EE_Transaction $transaction, $reg_step_slug ) {
851
+	public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug) {
852 852
 		EE_Error::doing_it_wrong(
853 853
 			__METHOD__,
854 854
 			esc_html__(
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 			'4.9.12',
859 859
 			'5.0.0'
860 860
 		);
861
-		return $transaction->set_reg_step_not_completed( $reg_step_slug );
861
+		return $transaction->set_reg_step_not_completed($reg_step_slug);
862 862
 	}
863 863
 
864 864
 
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
 	 * @param string          $reg_step_slug
876 876
 	 * @return void
877 877
 	 */
878
-	public function remove_reg_step( EE_Transaction $transaction, $reg_step_slug ) {
878
+	public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug) {
879 879
 		EE_Error::doing_it_wrong(
880 880
 			__METHOD__,
881 881
 			esc_html__(
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 			'4.9.12',
886 886
 			'5.0.0'
887 887
 		);
888
-		$transaction->remove_reg_step( $reg_step_slug );
888
+		$transaction->remove_reg_step($reg_step_slug);
889 889
 	}
890 890
 
891 891
 
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
 	 * @return    boolean
902 902
 	 * @throws \EE_Error
903 903
 	 */
904
-	public function toggle_failed_transaction_status( EE_Transaction $transaction ) {
904
+	public function toggle_failed_transaction_status(EE_Transaction $transaction) {
905 905
 		EE_Error::doing_it_wrong(
906 906
 			__METHOD__,
907 907
 			esc_html__(
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 	 * @param  EE_Transaction $transaction
926 926
 	 * @return boolean
927 927
 	 */
928
-	public function toggle_abandoned_transaction_status( EE_Transaction $transaction ) {
928
+	public function toggle_abandoned_transaction_status(EE_Transaction $transaction) {
929 929
 		EE_Error::doing_it_wrong(
930 930
 			__METHOD__,
931 931
 			esc_html__(
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/libraries/rest_api/changes/Changes_In_4_8_36.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -16,28 +16,28 @@  discard block
 block discarded – undo
16 16
 		//set a hook to remove the "calculate" query param
17 17
 		add_filter(
18 18
 			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
19
-			array( $this, 'remove_calculate_query_param' ),
19
+			array($this, 'remove_calculate_query_param'),
20 20
 			10,
21 21
 			3
22 22
 		);
23 23
 		//don't add the _calculated_fields either
24 24
 		add_filter(
25 25
 			'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
26
-			array( $this, 'remove_calculated_fields_from_response' ),
26
+			array($this, 'remove_calculated_fields_from_response'),
27 27
 			10,
28 28
 			5
29 29
 		);
30 30
 		//and also don't add the count headers
31 31
 		add_filter(
32 32
 			'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
33
-			array( $this, 'remove_headers_new_in_this_version' ),
33
+			array($this, 'remove_headers_new_in_this_version'),
34 34
 			10,
35 35
 			3
36 36
 		);
37 37
 		//remove the old featured_image part of the response...
38 38
 		add_filter(
39 39
 			'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models',
40
-			array( $this, 'add_old_featured_image_part_of_cpt_entities' ),
40
+			array($this, 'add_old_featured_image_part_of_cpt_entities'),
41 41
 			10,
42 42
 			5
43 43
 		);
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		//before this, infinity was -1, now it's null
48 48
 		add_filter(
49 49
 			'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
50
-			array( $this, 'use_negative_one_for_infinity_before_this_version' ),
50
+			array($this, 'use_negative_one_for_infinity_before_this_version'),
51 51
 			10,
52 52
 			4
53 53
 		);
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
 	 * @param string $version
61 61
 	 * @return array
62 62
 	 */
63
-	public function remove_calculate_query_param( $query_params, \EEM_Base $model, $version ) {
64
-		if( $this->applies_to_version( $version ) ) {
65
-			unset( $query_params[ 'calculate' ] );
63
+	public function remove_calculate_query_param($query_params, \EEM_Base $model, $version) {
64
+		if ($this->applies_to_version($version)) {
65
+			unset($query_params['calculate']);
66 66
 		}
67 67
 		return $query_params;
68 68
 	}
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 		\WP_REST_Request $request,
84 84
 		Read $controller
85 85
 	) {
86
-		if( $this->applies_to_version( $controller->get_model_version_info()->requested_version() ) ) {
87
-			unset( $entity_response_array[ '_calculated_fields' ] );
86
+		if ($this->applies_to_version($controller->get_model_version_info()->requested_version())) {
87
+			unset($entity_response_array['_calculated_fields']);
88 88
 		}
89 89
 		return $entity_response_array;
90 90
 	}
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
 		Controller_Base $controller,
102 102
 		$version
103 103
 	) {
104
-		if( $this->applies_to_version( $version ) ) {
104
+		if ($this->applies_to_version($version)) {
105 105
 			$headers = array_diff_key(
106 106
 				$headers,
107 107
 				array_flip(
108 108
 					array(
109
-						Base::header_prefix_for_wp . 'Total',
110
-						Base::header_prefix_for_wp . 'TotalPages',
111
-						Base::header_prefix_for_wp . 'PageSize'
109
+						Base::header_prefix_for_wp.'Total',
110
+						Base::header_prefix_for_wp.'TotalPages',
111
+						Base::header_prefix_for_wp.'PageSize'
112 112
 					)));
113 113
 		}
114 114
 		return $headers;
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
 		\WP_REST_Request $request,
131 131
 		Read $controller
132 132
 	) {
133
-		if( $this->applies_to_version( $controller->get_model_version_info()->requested_version() )
133
+		if ($this->applies_to_version($controller->get_model_version_info()->requested_version())
134 134
 			&& $model instanceof \EEM_CPT_Base
135 135
 		) {
136 136
 			$attachment = wp_get_attachment_image_src(
137
-				get_post_thumbnail_id( $entity_response_array[ $model->primary_key_name() ] ),
137
+				get_post_thumbnail_id($entity_response_array[$model->primary_key_name()]),
138 138
 				'full'
139 139
 			);
140
-			$entity_response_array[ 'featured_image_url' ] = !empty( $attachment ) ? $attachment[ 0 ] : null;
140
+			$entity_response_array['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null;
141 141
 		}
142 142
 		return $entity_response_array;
143 143
 	}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 * @param string $requested_value
153 153
 	 * @return mixed
154 154
 	 */
155
-	public function use_negative_one_for_infinity_before_this_version( $new_value, $field_obj, $original_value, $requested_value ) {
156
-		if( $this->applies_to_version( $requested_value )
157
-			&& $original_value === EE_INF ) {
155
+	public function use_negative_one_for_infinity_before_this_version($new_value, $field_obj, $original_value, $requested_value) {
156
+		if ($this->applies_to_version($requested_value)
157
+			&& $original_value === EE_INF) {
158 158
 			//return the old representation of infinity in the JSON
159 159
 			return -1;
160 160
 		}
Please login to merge, or discard this patch.