@@ -99,45 +99,45 @@ |
||
99 | 99 | 'body'=> json_encode($order) |
100 | 100 | ); |
101 | 101 | $response = wp_remote_post( $this->_mijireh_api_orders_url, $args ); |
102 | - $problems_string = false; |
|
102 | + $problems_string = false; |
|
103 | 103 | $this->log(array('get checkout url request_args' => $args, 'response' => $response ), $payment); |
104 | 104 | if( ! $response instanceof WP_Error ){ |
105 | 105 | $response_body = json_decode($response['body']); |
106 | 106 | if($response_body && isset($response_body->checkout_url)){ |
107 | - $payment->set_redirect_url($response_body->checkout_url); |
|
108 | - $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
109 | - $payment->set_details($response['body']); |
|
107 | + $payment->set_redirect_url($response_body->checkout_url); |
|
108 | + $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
109 | + $payment->set_details($response['body']); |
|
110 | 110 | } else { |
111 | - if( is_array( $response_body ) || is_object( $response_body)){ |
|
112 | - $response_body_as_array = (array)$response_body; |
|
113 | - foreach($response_body_as_array as $problem_parameter => $problems){ |
|
114 | - $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
115 | - } |
|
116 | - }else{ |
|
117 | - $problems_string = $response['body']; |
|
118 | - } |
|
119 | - if( ! $problems_string ) { |
|
120 | - //no message to show? wack |
|
121 | - if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
122 | - $problems_string = $response[ 'headers' ][ 'status' ]; |
|
123 | - }else{ |
|
124 | - $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
111 | + if( is_array( $response_body ) || is_object( $response_body)){ |
|
112 | + $response_body_as_array = (array)$response_body; |
|
113 | + foreach($response_body_as_array as $problem_parameter => $problems){ |
|
114 | + $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
115 | + } |
|
116 | + }else{ |
|
117 | + $problems_string = $response['body']; |
|
118 | + } |
|
119 | + if( ! $problems_string ) { |
|
120 | + //no message to show? wack |
|
121 | + if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
122 | + $problems_string = $response[ 'headers' ][ 'status' ]; |
|
123 | + }else{ |
|
124 | + $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | 128 | }else{ |
129 | - $problems_string = implode( ",", $response->get_error_messages() ); |
|
129 | + $problems_string = implode( ",", $response->get_error_messages() ); |
|
130 | 130 | } |
131 | 131 | |
132 | - if( $problems_string ) { |
|
133 | - $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
134 | - $payment->set_details( $response ); |
|
135 | - $payment->set_redirect_url( null ); |
|
136 | - //even though the payment's status is failed at this point anyways, |
|
137 | - //let's be explicit about it. The fact that the redirect url is null |
|
138 | - //should be enough to client code that they can't redirect the user |
|
139 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
140 | - } |
|
132 | + if( $problems_string ) { |
|
133 | + $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
134 | + $payment->set_details( $response ); |
|
135 | + $payment->set_redirect_url( null ); |
|
136 | + //even though the payment's status is failed at this point anyways, |
|
137 | + //let's be explicit about it. The fact that the redirect url is null |
|
138 | + //should be enough to client code that they can't redirect the user |
|
139 | + $payment->set_status( $this->_pay_model->failed_status() ); |
|
140 | + } |
|
141 | 141 | return $payment; |
142 | 142 | } |
143 | 143 |
@@ -8,7 +8,7 @@ discard block |
||
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,10 +37,10 @@ discard block |
||
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'=>$line_item->name(), |
46 | 46 | 'price'=>$this->format_currency($line_item->unit_price()), |
@@ -48,11 +48,11 @@ discard block |
||
48 | 48 | 'quantity'=>$line_item->quantity() |
49 | 49 | ); |
50 | 50 | } |
51 | - }else{//its a partial payment |
|
51 | + } else {//its a partial payment |
|
52 | 52 | $tax_total = 0; |
53 | 53 | //partial payment, so just add 1 item |
54 | 54 | $items[] = array( |
55 | - 'name'=> sprintf(__("Partial payment for registration %s", 'event_espresso'),$primary_registrant->reg_code()), |
|
55 | + 'name'=> sprintf(__("Partial payment for registration %s", 'event_espresso'), $primary_registrant->reg_code()), |
|
56 | 56 | 'price'=> $this->format_currency($payment->amount()), |
57 | 57 | 'sku'=>$primary_registrant->reg_code(), |
58 | 58 | 'quantity'=>1 |
@@ -61,18 +61,18 @@ discard block |
||
61 | 61 | $order = array( |
62 | 62 | 'total'=>$this->format_currency($payment->amount()), |
63 | 63 | 'return_url'=>$return_url, |
64 | - 'items'=>$this->_prepare_for_mijireh( $items ), |
|
64 | + 'items'=>$this->_prepare_for_mijireh($items), |
|
65 | 65 | 'email'=>$primary_attendee->email(), |
66 | 66 | 'first_name'=>$primary_attendee->fname(), |
67 | 67 | 'last_name'=>$primary_attendee->lname(), |
68 | 68 | 'tax'=>$this->format_currency($tax_total), |
69 | 69 | 'partner_id'=>'ee'); |
70 | 70 | //setup address? |
71 | - if( $primary_attendee->address() && |
|
72 | - $primary_attendee->city() && |
|
73 | - $primary_attendee->state_ID() && |
|
74 | - $primary_attendee->country_ID() && |
|
75 | - $primary_attendee->zip() ){ |
|
71 | + if ($primary_attendee->address() && |
|
72 | + $primary_attendee->city() && |
|
73 | + $primary_attendee->state_ID() && |
|
74 | + $primary_attendee->country_ID() && |
|
75 | + $primary_attendee->zip()) { |
|
76 | 76 | $shipping_address = array( |
77 | 77 | 'first_name'=>$primary_attendee->fname(), |
78 | 78 | 'last_name'=>$primary_attendee->lname(), |
@@ -82,61 +82,61 @@ discard block |
||
82 | 82 | 'zip_code' => $primary_attendee->zip(), |
83 | 83 | 'country' => $primary_attendee->country_ID() |
84 | 84 | ); |
85 | - if( $primary_attendee->address2() ){ |
|
86 | - $shipping_address[ 'apt_suite' ] = $primary_attendee->address2(); |
|
85 | + if ($primary_attendee->address2()) { |
|
86 | + $shipping_address['apt_suite'] = $primary_attendee->address2(); |
|
87 | 87 | } |
88 | - if( $primary_attendee->phone() ){ |
|
89 | - $shipping_address[ 'phone' ] = $primary_attendee->phone(); |
|
88 | + if ($primary_attendee->phone()) { |
|
89 | + $shipping_address['phone'] = $primary_attendee->phone(); |
|
90 | 90 | } |
91 | - $order[ 'shipping_address' ] = $shipping_address; |
|
91 | + $order['shipping_address'] = $shipping_address; |
|
92 | 92 | } |
93 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this)) ); |
|
93 | + do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this))); |
|
94 | 94 | $args = array( |
95 | 95 | 'headers' => array( |
96 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
96 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
97 | 97 | 'Accept'=>'application/json' |
98 | 98 | ), |
99 | 99 | 'body'=> json_encode($order) |
100 | 100 | ); |
101 | - $response = wp_remote_post( $this->_mijireh_api_orders_url, $args ); |
|
101 | + $response = wp_remote_post($this->_mijireh_api_orders_url, $args); |
|
102 | 102 | $problems_string = false; |
103 | - $this->log(array('get checkout url request_args' => $args, 'response' => $response ), $payment); |
|
104 | - if( ! $response instanceof WP_Error ){ |
|
103 | + $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment); |
|
104 | + if ( ! $response instanceof WP_Error) { |
|
105 | 105 | $response_body = json_decode($response['body']); |
106 | - if($response_body && isset($response_body->checkout_url)){ |
|
106 | + if ($response_body && isset($response_body->checkout_url)) { |
|
107 | 107 | $payment->set_redirect_url($response_body->checkout_url); |
108 | 108 | $payment->set_txn_id_chq_nmbr($response_body->order_number); |
109 | 109 | $payment->set_details($response['body']); |
110 | 110 | } else { |
111 | - if( is_array( $response_body ) || is_object( $response_body)){ |
|
112 | - $response_body_as_array = (array)$response_body; |
|
113 | - foreach($response_body_as_array as $problem_parameter => $problems){ |
|
114 | - $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
111 | + if (is_array($response_body) || is_object($response_body)) { |
|
112 | + $response_body_as_array = (array) $response_body; |
|
113 | + foreach ($response_body_as_array as $problem_parameter => $problems) { |
|
114 | + $problems_string .= sprintf(__('\nProblems with %s: %s', 'event_espresso'), $problem_parameter, implode(", ", $problems)); |
|
115 | 115 | } |
116 | - }else{ |
|
116 | + } else { |
|
117 | 117 | $problems_string = $response['body']; |
118 | 118 | } |
119 | - if( ! $problems_string ) { |
|
119 | + if ( ! $problems_string) { |
|
120 | 120 | //no message to show? wack |
121 | - if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
122 | - $problems_string = $response[ 'headers' ][ 'status' ]; |
|
123 | - }else{ |
|
124 | - $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
121 | + if (isset($response['headers']['status'])) { |
|
122 | + $problems_string = $response['headers']['status']; |
|
123 | + } else { |
|
124 | + $problems_string = __('No response from Mijireh', 'event_espresso'); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
128 | - }else{ |
|
129 | - $problems_string = implode( ",", $response->get_error_messages() ); |
|
128 | + } else { |
|
129 | + $problems_string = implode(",", $response->get_error_messages()); |
|
130 | 130 | } |
131 | 131 | |
132 | - if( $problems_string ) { |
|
133 | - $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
134 | - $payment->set_details( $response ); |
|
135 | - $payment->set_redirect_url( null ); |
|
132 | + if ($problems_string) { |
|
133 | + $payment->set_gateway_response(sprintf(__('Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string)); |
|
134 | + $payment->set_details($response); |
|
135 | + $payment->set_redirect_url(null); |
|
136 | 136 | //even though the payment's status is failed at this point anyways, |
137 | 137 | //let's be explicit about it. The fact that the redirect url is null |
138 | 138 | //should be enough to client code that they can't redirect the user |
139 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
139 | + $payment->set_status($this->_pay_model->failed_status()); |
|
140 | 140 | } |
141 | 141 | return $payment; |
142 | 142 | } |
@@ -149,16 +149,16 @@ discard block |
||
149 | 149 | * @param mixed $data |
150 | 150 | * @return mixed same type as $data |
151 | 151 | */ |
152 | - private function _prepare_for_mijireh( $data ){ |
|
153 | - if( is_array( $data ) ){ |
|
152 | + private function _prepare_for_mijireh($data) { |
|
153 | + if (is_array($data)) { |
|
154 | 154 | $prepared_data = array(); |
155 | - foreach($data as $key => $datum ){ |
|
156 | - $prepared_data[ $key ] = $this->_prepare_for_mijireh( $datum ); |
|
155 | + foreach ($data as $key => $datum) { |
|
156 | + $prepared_data[$key] = $this->_prepare_for_mijireh($datum); |
|
157 | 157 | } |
158 | 158 | return $prepared_data; |
159 | - }elseif(is_string( $data ) ){ |
|
160 | - return str_replace( '%', 'percent', $data ); |
|
161 | - }else{ |
|
159 | + }elseif (is_string($data)) { |
|
160 | + return str_replace('%', 'percent', $data); |
|
161 | + } else { |
|
162 | 162 | return $data; |
163 | 163 | } |
164 | 164 | } |
@@ -179,30 +179,30 @@ discard block |
||
179 | 179 | |
180 | 180 | $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
181 | 181 | |
182 | - if ( ! $payment instanceof EEI_Payment ){ |
|
183 | - throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) ); |
|
182 | + if ( ! $payment instanceof EEI_Payment) { |
|
183 | + throw new EE_Error(sprintf(__("Could not find Mijireh payment for transaction %s", 'event_espresso'), $transaction->ID())); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | $request_args = array( |
187 | 187 | 'headers' => array( |
188 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
188 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
189 | 189 | 'Accept'=>'application/json' |
190 | 190 | ) |
191 | 191 | ); |
192 | 192 | |
193 | 193 | $response = wp_remote_get( |
194 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
194 | + $this->_mijireh_api_orders_url.'/'.$payment->txn_id_chq_nmbr(), |
|
195 | 195 | $request_args |
196 | 196 | ); |
197 | 197 | |
198 | 198 | $this->log( |
199 | - array( 'get payment status request_args' => $request_args, 'response' => $response ), |
|
199 | + array('get payment status request_args' => $request_args, 'response' => $response), |
|
200 | 200 | $payment |
201 | 201 | ); |
202 | 202 | // validate response |
203 | - $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : ''; |
|
204 | - if( $response && $response_body ){ |
|
205 | - switch( $response_body->status ){ |
|
203 | + $response_body = isset($response['body']) ? json_decode($response['body']) : ''; |
|
204 | + if ($response && $response_body) { |
|
205 | + switch ($response_body->status) { |
|
206 | 206 | case 'paid': |
207 | 207 | $payment->set_status($this->_pay_model->approved_status()); |
208 | 208 | break; |
@@ -214,9 +214,9 @@ discard block |
||
214 | 214 | } |
215 | 215 | |
216 | 216 | } else { |
217 | - $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) ); |
|
218 | - $payment->set_details( $response ); |
|
219 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
217 | + $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso')); |
|
218 | + $payment->set_details($response); |
|
219 | + $payment->set_status($this->_pay_model->failed_status()); |
|
220 | 220 | } |
221 | 221 | // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
222 | 222 | // $payment->set_status( $this->_pay_model->pending_status() ); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | 'quantity'=>$line_item->quantity() |
49 | 49 | ); |
50 | 50 | } |
51 | - }else{//its a partial payment |
|
51 | + } else{//its a partial payment |
|
52 | 52 | $tax_total = 0; |
53 | 53 | //partial payment, so just add 1 item |
54 | 54 | $items[] = array( |
@@ -113,19 +113,19 @@ discard block |
||
113 | 113 | foreach($response_body_as_array as $problem_parameter => $problems){ |
114 | 114 | $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
115 | 115 | } |
116 | - }else{ |
|
116 | + } else{ |
|
117 | 117 | $problems_string = $response['body']; |
118 | 118 | } |
119 | 119 | if( ! $problems_string ) { |
120 | 120 | //no message to show? wack |
121 | 121 | if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
122 | 122 | $problems_string = $response[ 'headers' ][ 'status' ]; |
123 | - }else{ |
|
123 | + } else{ |
|
124 | 124 | $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
128 | - }else{ |
|
128 | + } else{ |
|
129 | 129 | $problems_string = implode( ",", $response->get_error_messages() ); |
130 | 130 | } |
131 | 131 | |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | $prepared_data[ $key ] = $this->_prepare_for_mijireh( $datum ); |
157 | 157 | } |
158 | 158 | return $prepared_data; |
159 | - }elseif(is_string( $data ) ){ |
|
159 | + } elseif(is_string( $data ) ){ |
|
160 | 160 | return str_replace( '%', 'percent', $data ); |
161 | - }else{ |
|
161 | + } else{ |
|
162 | 162 | return $data; |
163 | 163 | } |
164 | 164 | } |
@@ -1,11 +1,11 @@ discard block |
||
1 | -<h3><?php _e( 'Mijireh', 'event_espresso' ); ?></h3> |
|
1 | +<h3><?php _e('Mijireh', 'event_espresso'); ?></h3> |
|
2 | 2 | <p> |
3 | - <?php _e( 'Adjust the settings for the Mijireh payment gateway.', 'event_espresso' ); ?> |
|
3 | + <?php _e('Adjust the settings for the Mijireh payment gateway.', 'event_espresso'); ?> |
|
4 | 4 | </p> |
5 | 5 | <p> |
6 | 6 | <?php |
7 | 7 | printf( |
8 | - __( 'Mijireh is basically a middle-man between Event Espresso and over 90 payment gateways. Most of the configuration occurs on %1$sMijireh\' website%2$s, where you configure your Mijireh store with the %3$spayment gateway of your choice%4$s.', 'event_espresso' ), |
|
8 | + __('Mijireh is basically a middle-man between Event Espresso and over 90 payment gateways. Most of the configuration occurs on %1$sMijireh\' website%2$s, where you configure your Mijireh store with the %3$spayment gateway of your choice%4$s.', 'event_espresso'), |
|
9 | 9 | '<a href="http://www.mijireh.com/" target="_blank">', |
10 | 10 | '</a>', |
11 | 11 | '<a href="http://www.mijireh.com/docs/payment-gateways/" target="_blank">', |
@@ -14,26 +14,26 @@ discard block |
||
14 | 14 | ?> |
15 | 15 | </p> |
16 | 16 | <p> |
17 | - <?php _e( 'For information on what currencies you can use with Mijireh, please consult the payment gateway Mijireh is setup to use.', 'event_espresso' ) ?> |
|
17 | + <?php _e('For information on what currencies you can use with Mijireh, please consult the payment gateway Mijireh is setup to use.', 'event_espresso') ?> |
|
18 | 18 | </p> |
19 | 19 | <ul> |
20 | 20 | <li> |
21 | - <strong><?php _e( 'Mijireh Access Key', 'event_espresso' ); ?></strong><br/> |
|
21 | + <strong><?php _e('Mijireh Access Key', 'event_espresso'); ?></strong><br/> |
|
22 | 22 | <?php |
23 | 23 | printf( |
24 | - __( 'Enter your Access Key for Mijireh. Your Access Key can be found in your %1$sMijireh account dashboard%2$s.', 'event_espresso' ), |
|
24 | + __('Enter your Access Key for Mijireh. Your Access Key can be found in your %1$sMijireh account dashboard%2$s.', 'event_espresso'), |
|
25 | 25 | '<a href="https://secure.mijireh.com/login" target="_blank">', |
26 | 26 | '</a>' |
27 | 27 | ); |
28 | 28 | ?> |
29 | 29 | </li> |
30 | 30 | <li> |
31 | - <strong><?php _e( 'Button Image URL', 'event_espresso' ); ?></strong><br/> |
|
32 | - <?php _e( 'Change the image that is used for this payment gateway.', 'event_espresso' ); ?> |
|
31 | + <strong><?php _e('Button Image URL', 'event_espresso'); ?></strong><br/> |
|
32 | + <?php _e('Change the image that is used for this payment gateway.', 'event_espresso'); ?> |
|
33 | 33 | </li> |
34 | 34 | </ul> |
35 | -<h3><?php _e( 'Mijireh Checkout Page Design', 'event_espresso' ); ?></h3> |
|
35 | +<h3><?php _e('Mijireh Checkout Page Design', 'event_espresso'); ?></h3> |
|
36 | 36 | <p> |
37 | - <?php _e( "As you are probably aware, when users pay with Mijireh Payment Method, they are taken to a secure offsite page, hosted by Mijireh. This page can easily be made to have the look-and-feel of your website through a process called 'slurping', where Mijireh 'slurps' up your website's design and uses it on their checkout page.", 'event_espresso' ); ?> |
|
38 | - <?php printf( __( "In order to do this, we automatically create a new WordPress page which is designed to be slurped by Mijireh. You can customize the page like any other, but the page must contain Mijireh's special '{{mijireh-checkout-form}}' shortcode. Once you have finished designing the page, publish it, and %s then click the special 'slurp now' button%s. Mijireh may take several minutes to slurp the page. Once Mijireh is finished slurping, you can delete the page, or mark it as a draft.", 'event_espresso' ), '<a href="http://ee-screenshots.s3.amazonaws.com/ee4/event-espresso-mijireh-slurp-page-example.jpg" target="_blank">', '</a>' ); ?> |
|
37 | + <?php _e("As you are probably aware, when users pay with Mijireh Payment Method, they are taken to a secure offsite page, hosted by Mijireh. This page can easily be made to have the look-and-feel of your website through a process called 'slurping', where Mijireh 'slurps' up your website's design and uses it on their checkout page.", 'event_espresso'); ?> |
|
38 | + <?php printf(__("In order to do this, we automatically create a new WordPress page which is designed to be slurped by Mijireh. You can customize the page like any other, but the page must contain Mijireh's special '{{mijireh-checkout-form}}' shortcode. Once you have finished designing the page, publish it, and %s then click the special 'slurp now' button%s. Mijireh may take several minutes to slurp the page. Once Mijireh is finished slurping, you can delete the page, or mark it as a draft.", 'event_espresso'), '<a href="http://ee-screenshots.s3.amazonaws.com/ee4/event-espresso-mijireh-slurp-page-example.jpg" target="_blank">', '</a>'); ?> |
|
39 | 39 | </p> |
40 | 40 | \ No newline at end of file |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php if (!defined('EVENT_ESPRESSO_VERSION')) |
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | /** |
4 | - * mijireh_settings_after_form |
|
5 | - * |
|
6 | - * @package Event Espresso |
|
7 | - * @subpackage |
|
8 | - * @author Mike Nelson |
|
9 | - */ |
|
4 | + * mijireh_settings_after_form |
|
5 | + * |
|
6 | + * @package Event Espresso |
|
7 | + * @subpackage |
|
8 | + * @author Mike Nelson |
|
9 | + */ |
|
10 | 10 | do_action('AHEE__EE_Mijireh__settings_end'); |
11 | 11 | ?><br/><?php |
12 | 12 | // End of file mijireh_settings_after_form.template.php |
13 | 13 | \ No newline at end of file |
@@ -1,4 +1,4 @@ |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | /** |
4 | 4 | * mijireh_settings_after_form |
@@ -1,5 +1,6 @@ |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) |
|
1 | +<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | +} |
|
3 | 4 | /** |
4 | 5 | * mijireh_settings_after_form |
5 | 6 | * |
@@ -156,7 +156,7 @@ |
||
156 | 156 | * @param int $PAY_ID |
157 | 157 | */ |
158 | 158 | public static function setup_update_for_transaction_with_payment( $TXN_ID = 0, $PAY_ID = 0 ) { |
159 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID' ); |
|
159 | + do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID' ); |
|
160 | 160 | if ( absint( $TXN_ID )) { |
161 | 161 | self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
162 | 162 | add_action( |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @return EE_Cron_Tasks |
29 | 29 | */ |
30 | 30 | public static function instance() { |
31 | - if ( ! self::$_instance instanceof EE_Cron_Tasks ) { |
|
31 | + if ( ! self::$_instance instanceof EE_Cron_Tasks) { |
|
32 | 32 | self::$_instance = new self(); |
33 | 33 | } |
34 | 34 | return self::$_instance; |
@@ -41,28 +41,28 @@ discard block |
||
41 | 41 | * @return EE_Cron_Tasks |
42 | 42 | */ |
43 | 43 | private function __construct() { |
44 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__ ); |
|
44 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
45 | 45 | // UPDATE TRANSACTION WITH PAYMENT |
46 | 46 | add_action( |
47 | 47 | 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
48 | - array( 'EE_Cron_Tasks', 'setup_update_for_transaction_with_payment' ), |
|
48 | + array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
49 | 49 | 10, 2 |
50 | 50 | ); |
51 | 51 | // FINALIZE ABANDONED TRANSACTIONS |
52 | 52 | add_action( |
53 | 53 | 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
54 | - array( 'EE_Cron_Tasks', 'check_for_abandoned_transactions' ), |
|
54 | + array('EE_Cron_Tasks', 'check_for_abandoned_transactions'), |
|
55 | 55 | 10, 1 |
56 | 56 | ); |
57 | 57 | // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
58 | 58 | add_action( |
59 | 59 | 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
60 | - array( 'EE_Cron_Tasks', 'clean_out_junk_transactions' ) |
|
60 | + array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
61 | 61 | ); |
62 | 62 | // logging |
63 | 63 | add_action( |
64 | 64 | 'AHEE__EE_System__load_core_configuration__complete', |
65 | - array( 'EE_Cron_Tasks', 'log_scheduled_ee_crons' ) |
|
65 | + array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
66 | 66 | ); |
67 | 67 | } |
68 | 68 | |
@@ -78,17 +78,17 @@ discard block |
||
78 | 78 | 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
79 | 79 | 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
80 | 80 | ); |
81 | - $crons = get_option( 'cron' ); |
|
82 | - if ( ! is_array( $crons ) ) { |
|
81 | + $crons = get_option('cron'); |
|
82 | + if ( ! is_array($crons)) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | - foreach ( $crons as $timestamp => $cron ) { |
|
86 | - foreach ( $ee_crons as $ee_cron ) { |
|
87 | - if ( isset( $cron[ $ee_cron ] ) ) { |
|
88 | - foreach ( $cron[ $ee_cron ] as $ee_cron_details ) { |
|
89 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron' ); |
|
90 | - if ( ! empty( $ee_cron_details[ 'args' ] )) { |
|
91 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, print_r( $ee_cron_details[ 'args' ], true ), "$ee_cron args" ); |
|
85 | + foreach ($crons as $timestamp => $cron) { |
|
86 | + foreach ($ee_crons as $ee_cron) { |
|
87 | + if (isset($cron[$ee_cron])) { |
|
88 | + foreach ($cron[$ee_cron] as $ee_cron_details) { |
|
89 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
90 | + if ( ! empty($ee_cron_details['args'])) { |
|
91 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, print_r($ee_cron_details['args'], true), "$ee_cron args"); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | } |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | $TXN_ID, |
126 | 126 | $PAY_ID |
127 | 127 | ) { |
128 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__ ); |
|
128 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
129 | 129 | // validate $TXN_ID and $timestamp |
130 | - $TXN_ID = absint( $TXN_ID ); |
|
131 | - $timestamp = absint( $timestamp ); |
|
132 | - if ( $TXN_ID && $timestamp ) { |
|
130 | + $TXN_ID = absint($TXN_ID); |
|
131 | + $timestamp = absint($timestamp); |
|
132 | + if ($TXN_ID && $timestamp) { |
|
133 | 133 | wp_schedule_single_event( |
134 | 134 | $timestamp, |
135 | 135 | 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
136 | - array( $TXN_ID, $PAY_ID ) |
|
136 | + array($TXN_ID, $PAY_ID) |
|
137 | 137 | ); |
138 | 138 | } |
139 | 139 | } |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | * @param int $TXN_ID |
156 | 156 | * @param int $PAY_ID |
157 | 157 | */ |
158 | - public static function setup_update_for_transaction_with_payment( $TXN_ID = 0, $PAY_ID = 0 ) { |
|
159 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID' ); |
|
160 | - if ( absint( $TXN_ID )) { |
|
161 | - self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
158 | + public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) { |
|
159 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
160 | + if (absint($TXN_ID)) { |
|
161 | + self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID; |
|
162 | 162 | add_action( |
163 | 163 | 'shutdown', |
164 | - array( 'EE_Cron_Tasks', 'update_transaction_with_payment' ), |
|
164 | + array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
165 | 165 | 5 |
166 | 166 | ); |
167 | 167 | } |
@@ -178,18 +178,18 @@ discard block |
||
178 | 178 | * returning from an off-site payment gateway |
179 | 179 | */ |
180 | 180 | public static function update_transaction_with_payment() { |
181 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__ ); |
|
181 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
182 | 182 | // are there any TXNs that need cleaning up ? |
183 | - if ( ! empty( self::$_update_transactions_with_payment ) ) { |
|
183 | + if ( ! empty(self::$_update_transactions_with_payment)) { |
|
184 | 184 | /** @type EE_Payment_Processor $payment_processor */ |
185 | - $payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' ); |
|
185 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
186 | 186 | // set revisit flag for payment processor |
187 | - $payment_processor->set_revisit( false ); |
|
187 | + $payment_processor->set_revisit(false); |
|
188 | 188 | // load EEM_Transaction |
189 | - EE_Registry::instance()->load_model( 'Transaction' ); |
|
190 | - foreach ( self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID ) { |
|
189 | + EE_Registry::instance()->load_model('Transaction'); |
|
190 | + foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
191 | 191 | // reschedule the cron if we can't hit the db right now |
192 | - if ( ! EE_Maintenance_Mode::instance()->models_can_query() ) { |
|
192 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
193 | 193 | // reset cron job for updating the TXN |
194 | 194 | EE_Cron_Tasks::schedule_update_transaction_with_payment( |
195 | 195 | time() + EE_Cron_Tasks::reschedule_timeout, |
@@ -198,15 +198,15 @@ discard block |
||
198 | 198 | ); |
199 | 199 | continue; |
200 | 200 | } |
201 | - $transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
202 | - $payment = EEM_Payment::instance()->get_one_by_ID( $PAY_ID ); |
|
201 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
202 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
203 | 203 | // verify transaction |
204 | - if ( $transaction instanceof EE_Transaction && |
|
205 | - $payment instanceof EE_Payment ) { |
|
204 | + if ($transaction instanceof EE_Transaction && |
|
205 | + $payment instanceof EE_Payment) { |
|
206 | 206 | // now try to update the TXN with any payments |
207 | - $payment_processor->update_txn_based_on_payment( $transaction, $payment, true, true ); |
|
207 | + $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
208 | 208 | } |
209 | - unset( self::$_update_transactions_with_payment[ $TXN_ID ] ); |
|
209 | + unset(self::$_update_transactions_with_payment[$TXN_ID]); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | } |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | $TXN_ID |
244 | 244 | ) { |
245 | 245 | // validate $TXN_ID and $timestamp |
246 | - $TXN_ID = absint( $TXN_ID ); |
|
247 | - $timestamp = absint( $timestamp ); |
|
248 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID' ); |
|
249 | - if ( $TXN_ID && $timestamp ) { |
|
246 | + $TXN_ID = absint($TXN_ID); |
|
247 | + $timestamp = absint($timestamp); |
|
248 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
249 | + if ($TXN_ID && $timestamp) { |
|
250 | 250 | wp_schedule_single_event( |
251 | 251 | $timestamp, |
252 | 252 | 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
253 | - array( $TXN_ID ) |
|
253 | + array($TXN_ID) |
|
254 | 254 | ); |
255 | 255 | } |
256 | 256 | } |
@@ -272,13 +272,13 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @param int $TXN_ID |
274 | 274 | */ |
275 | - public static function check_for_abandoned_transactions( $TXN_ID = 0 ) { |
|
276 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID' ); |
|
277 | - if ( absint( $TXN_ID )) { |
|
278 | - self::$_abandoned_transactions[] = $TXN_ID; |
|
275 | + public static function check_for_abandoned_transactions($TXN_ID = 0) { |
|
276 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
277 | + if (absint($TXN_ID)) { |
|
278 | + self::$_abandoned_transactions[] = $TXN_ID; |
|
279 | 279 | add_action( |
280 | 280 | 'shutdown', |
281 | - array( 'EE_Cron_Tasks', 'finalize_abandoned_transactions' ), |
|
281 | + array('EE_Cron_Tasks', 'finalize_abandoned_transactions'), |
|
282 | 282 | 5 |
283 | 283 | ); |
284 | 284 | } |
@@ -295,21 +295,21 @@ discard block |
||
295 | 295 | * returning from an off-site payment gateway |
296 | 296 | */ |
297 | 297 | public static function finalize_abandoned_transactions() { |
298 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__ ); |
|
298 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
299 | 299 | // are there any TXNs that need cleaning up ? |
300 | - if ( ! empty( self::$_abandoned_transactions ) ) { |
|
300 | + if ( ! empty(self::$_abandoned_transactions)) { |
|
301 | 301 | /** @type EE_Transaction_Processor $transaction_processor */ |
302 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
302 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
303 | 303 | // set revisit flag for txn processor |
304 | - $transaction_processor->set_revisit( false ); |
|
304 | + $transaction_processor->set_revisit(false); |
|
305 | 305 | /** @type EE_Payment_Processor $payment_processor */ |
306 | - $payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' ); |
|
306 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
307 | 307 | // load EEM_Transaction |
308 | - EE_Registry::instance()->load_model( 'Transaction' ); |
|
309 | - foreach ( self::$_abandoned_transactions as $TXN_ID ) { |
|
310 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID' ); |
|
308 | + EE_Registry::instance()->load_model('Transaction'); |
|
309 | + foreach (self::$_abandoned_transactions as $TXN_ID) { |
|
310 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
311 | 311 | // reschedule the cron if we can't hit the db right now |
312 | - if ( ! EE_Maintenance_Mode::instance()->models_can_query() ) { |
|
312 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
313 | 313 | // reset cron job for finalizing the TXN |
314 | 314 | EE_Cron_Tasks::schedule_finalize_abandoned_transactions_check( |
315 | 315 | time() + EE_Cron_Tasks::reschedule_timeout, |
@@ -317,17 +317,17 @@ discard block |
||
317 | 317 | ); |
318 | 318 | continue; |
319 | 319 | } |
320 | - $transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
320 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
321 | 321 | // verify transaction |
322 | - if ( $transaction instanceof EE_Transaction ) { |
|
322 | + if ($transaction instanceof EE_Transaction) { |
|
323 | 323 | // don't finalize the TXN if it has already been completed |
324 | - if ( $transaction_processor->all_reg_steps_completed( $transaction ) === true ) { |
|
324 | + if ($transaction_processor->all_reg_steps_completed($transaction) === true) { |
|
325 | 325 | continue; |
326 | 326 | } |
327 | 327 | // let's simulate an IPN here which will trigger any notifications that need to go out |
328 | - $payment_processor->update_txn_based_on_payment( $transaction, $transaction->last_payment(), true, true ); |
|
328 | + $payment_processor->update_txn_based_on_payment($transaction, $transaction->last_payment(), true, true); |
|
329 | 329 | } |
330 | - unset( self::$_abandoned_transactions[ $TXN_ID ] ); |
|
330 | + unset(self::$_abandoned_transactions[$TXN_ID]); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | //when a transaction is initially made, schedule this check. |
344 | 344 | //if it has NO REG data by the time it has expired, forget about it |
345 | 345 | public static function clean_out_junk_transactions() { |
346 | - if( EE_Maintenance_Mode::instance()->models_can_query() ) { |
|
346 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
347 | 347 | EEM_Transaction::instance('')->delete_junk_transactions(); |
348 | 348 | EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
349 | 349 | EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
@@ -47,25 +47,25 @@ discard block |
||
47 | 47 | |
48 | 48 | |
49 | 49 | /** |
50 | - * date format |
|
51 | - * |
|
52 | - * pattern or format for displaying dates |
|
53 | - * |
|
54 | - * @access protected |
|
55 | - * @var string |
|
56 | - */ |
|
50 | + * date format |
|
51 | + * |
|
52 | + * pattern or format for displaying dates |
|
53 | + * |
|
54 | + * @access protected |
|
55 | + * @var string |
|
56 | + */ |
|
57 | 57 | protected $_dt_frmt; |
58 | 58 | |
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * time format |
|
63 | - * |
|
64 | - * pattern or format for displaying time |
|
65 | - * |
|
66 | - * @access protected |
|
67 | - * @var string |
|
68 | - */ |
|
61 | + /** |
|
62 | + * time format |
|
63 | + * |
|
64 | + * pattern or format for displaying time |
|
65 | + * |
|
66 | + * @access protected |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | protected $_tm_frmt; |
70 | 70 | |
71 | 71 | |
@@ -205,12 +205,12 @@ discard block |
||
205 | 205 | |
206 | 206 | |
207 | 207 | /** |
208 | - * Gets the field's original value when this object was constructed during this request. |
|
209 | - * This can be helpful when determining if a model object has changed or not |
|
210 | - * |
|
211 | - * @param string $field_name |
|
212 | - * @return mixed|null |
|
213 | - */ |
|
208 | + * Gets the field's original value when this object was constructed during this request. |
|
209 | + * This can be helpful when determining if a model object has changed or not |
|
210 | + * |
|
211 | + * @param string $field_name |
|
212 | + * @return mixed|null |
|
213 | + */ |
|
214 | 214 | public function get_original( $field_name ){ |
215 | 215 | if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
216 | 216 | $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
@@ -1273,7 +1273,7 @@ discard block |
||
1273 | 1273 | */ |
1274 | 1274 | do_action( 'AHEE__EE_Base_Class__delete__before', $this ); |
1275 | 1275 | $result = $this->get_model()->delete_by_ID( $this->ID() ); |
1276 | - $this->refresh_cache_of_related_objects(); |
|
1276 | + $this->refresh_cache_of_related_objects(); |
|
1277 | 1277 | /** |
1278 | 1278 | * Called just after deleting a model object |
1279 | 1279 | * @param EE_Base_Class $model_object that was just 'deleted' |
@@ -1293,35 +1293,35 @@ discard block |
||
1293 | 1293 | $model=$this->get_model(); |
1294 | 1294 | if($model instanceof EEM_Soft_Delete_Base){ |
1295 | 1295 | $result=$model->delete_permanently_by_ID($this->ID()); |
1296 | - $this->refresh_cache_of_related_objects(); |
|
1296 | + $this->refresh_cache_of_related_objects(); |
|
1297 | 1297 | }else{ |
1298 | 1298 | $result = $this->delete(); |
1299 | 1299 | } |
1300 | 1300 | return $result ? true : false; |
1301 | 1301 | } |
1302 | 1302 | |
1303 | - /** |
|
1304 | - * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
1305 | - * related model objects |
|
1306 | - */ |
|
1307 | - public function refresh_cache_of_related_objects() { |
|
1308 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
1309 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
1310 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
1311 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
1312 | - //this relation only stores a single model object, not an array |
|
1313 | - //but let's make it consistent |
|
1314 | - $related_objects = array( $related_objects ); |
|
1315 | - } |
|
1316 | - foreach( $related_objects as $related_object ) { |
|
1317 | - //only refresh their cache if they're in memory |
|
1318 | - if( $related_object instanceof EE_Base_Class ) { |
|
1303 | + /** |
|
1304 | + * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
1305 | + * related model objects |
|
1306 | + */ |
|
1307 | + public function refresh_cache_of_related_objects() { |
|
1308 | + foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
1309 | + if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
1310 | + $related_objects = $this->_model_relations[ $relation_name ]; |
|
1311 | + if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
1312 | + //this relation only stores a single model object, not an array |
|
1313 | + //but let's make it consistent |
|
1314 | + $related_objects = array( $related_objects ); |
|
1315 | + } |
|
1316 | + foreach( $related_objects as $related_object ) { |
|
1317 | + //only refresh their cache if they're in memory |
|
1318 | + if( $related_object instanceof EE_Base_Class ) { |
|
1319 | 1319 | $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
1320 | - } |
|
1321 | - } |
|
1322 | - } |
|
1323 | - } |
|
1324 | - } |
|
1320 | + } |
|
1321 | + } |
|
1322 | + } |
|
1323 | + } |
|
1324 | + } |
|
1325 | 1325 | |
1326 | 1326 | |
1327 | 1327 | |
@@ -1671,9 +1671,9 @@ discard block |
||
1671 | 1671 | $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
1672 | 1672 | //clear cache so future get_many_related and get_first_related() return new results. |
1673 | 1673 | $this->clear_cache( $relationName, $otherObject, TRUE ); |
1674 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1675 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1676 | - } |
|
1674 | + if( $otherObject instanceof EE_Base_Class ) { |
|
1675 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1676 | + } |
|
1677 | 1677 | } else { |
1678 | 1678 | //this thing doesn't exist in the DB, so just cache it |
1679 | 1679 | if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
@@ -1687,18 +1687,18 @@ discard block |
||
1687 | 1687 | } |
1688 | 1688 | $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
1689 | 1689 | } |
1690 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1691 | - //fix the reciprocal relation too |
|
1692 | - if( $otherObject->ID() ) { |
|
1693 | - //its saved so assumed relations exist in the DB, so we can just |
|
1694 | - //clear the cache so future queries use the updated info in the DB |
|
1695 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
1696 | - } else { |
|
1697 | - |
|
1698 | - //it's not saved, so it caches relations like this |
|
1699 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
1700 | - } |
|
1701 | - } |
|
1690 | + if( $otherObject instanceof EE_Base_Class ) { |
|
1691 | + //fix the reciprocal relation too |
|
1692 | + if( $otherObject->ID() ) { |
|
1693 | + //its saved so assumed relations exist in the DB, so we can just |
|
1694 | + //clear the cache so future queries use the updated info in the DB |
|
1695 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
1696 | + } else { |
|
1697 | + |
|
1698 | + //it's not saved, so it caches relations like this |
|
1699 | + $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
1700 | + } |
|
1701 | + } |
|
1702 | 1702 | return $otherObject; |
1703 | 1703 | } |
1704 | 1704 | |
@@ -1728,9 +1728,9 @@ discard block |
||
1728 | 1728 | //this doesn't exist in the DB, just remove it from the cache |
1729 | 1729 | $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
1730 | 1730 | } |
1731 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1732 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1733 | - } |
|
1731 | + if( $otherObject instanceof EE_Base_Class ) { |
|
1732 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1733 | + } |
|
1734 | 1734 | return $otherObject; |
1735 | 1735 | } |
1736 | 1736 | |
@@ -1749,11 +1749,11 @@ discard block |
||
1749 | 1749 | //this doesn't exist in the DB, just remove it from the cache |
1750 | 1750 | $otherObjects = $this->clear_cache( $relationName, null, true ); |
1751 | 1751 | } |
1752 | - if( is_array( $otherObjects ) ) { |
|
1753 | - foreach ( $otherObjects as $otherObject ) { |
|
1754 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1755 | - } |
|
1756 | - } |
|
1752 | + if( is_array( $otherObjects ) ) { |
|
1753 | + foreach ( $otherObjects as $otherObject ) { |
|
1754 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1755 | + } |
|
1756 | + } |
|
1757 | 1757 | return $otherObjects; |
1758 | 1758 | } |
1759 | 1759 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | -do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | +do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * Event Espresso |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * ------------------------------------------------------------------------ |
25 | 25 | */ |
26 | 26 | |
27 | -abstract class EE_Base_Class{ |
|
27 | +abstract class EE_Base_Class { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * This is an array of the original properties and values provided during construction |
@@ -117,60 +117,60 @@ discard block |
||
117 | 117 | * @throws EE_Error |
118 | 118 | * @return \EE_Base_Class |
119 | 119 | */ |
120 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array() ){ |
|
120 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array()) { |
|
121 | 121 | |
122 | - $className=get_class($this); |
|
122 | + $className = get_class($this); |
|
123 | 123 | |
124 | - do_action("AHEE__{$className}__construct",$this,$fieldValues); |
|
125 | - $model=$this->get_model(); |
|
126 | - $model_fields = $model->field_settings( FALSE ); |
|
124 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
125 | + $model = $this->get_model(); |
|
126 | + $model_fields = $model->field_settings(FALSE); |
|
127 | 127 | // ensure $fieldValues is an array |
128 | - $fieldValues = is_array( $fieldValues ) ? $fieldValues : array( $fieldValues ); |
|
128 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
129 | 129 | // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
130 | 130 | // verify client code has not passed any invalid field names |
131 | - foreach($fieldValues as $field_name=> $field_value){ |
|
132 | - if( ! isset( $model_fields[ $field_name] ) ){ |
|
133 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"),$field_name,get_class($this),implode(", ",array_keys($model_fields)))); |
|
131 | + foreach ($fieldValues as $field_name=> $field_value) { |
|
132 | + if ( ! isset($model_fields[$field_name])) { |
|
133 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
137 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
138 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
137 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
138 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
139 | 139 | |
140 | - if ( ! empty( $date_formats ) && is_array( $date_formats ) ) { |
|
140 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
141 | 141 | $this->_dt_frmt = $date_formats[0]; |
142 | 142 | $this->_tm_frmt = $date_formats[1]; |
143 | 143 | } else { |
144 | 144 | //set default formats for date and time |
145 | - $this->_dt_frmt = get_option( 'date_format' ); |
|
146 | - $this->_tm_frmt = get_option( 'time_format' ); |
|
145 | + $this->_dt_frmt = get_option('date_format'); |
|
146 | + $this->_tm_frmt = get_option('time_format'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | //if db model is instantiating |
150 | - if ( $bydb ){ |
|
150 | + if ($bydb) { |
|
151 | 151 | //client code has indicated these field values are from the database |
152 | - foreach( $model_fields as $fieldName => $field ){ |
|
153 | - $this->set_from_db( $fieldName, isset( $fieldValues[ $fieldName] ) ? $fieldValues[ $fieldName ] : null ); |
|
152 | + foreach ($model_fields as $fieldName => $field) { |
|
153 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
154 | 154 | } |
155 | 155 | } else { |
156 | 156 | //we're constructing a brand |
157 | 157 | //new instance of the model object. Generally, this means we'll need to do more field validation |
158 | - foreach( $model_fields as $fieldName => $field ){ |
|
159 | - $this->set( $fieldName, isset( $fieldValues[ $fieldName ] ) ? $fieldValues[ $fieldName ] : null, true ); |
|
158 | + foreach ($model_fields as $fieldName => $field) { |
|
159 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | //remember what values were passed to this constructor |
164 | 164 | $this->_props_n_values_provided_in_constructor = $fieldValues; |
165 | 165 | //remember in entity mapper |
166 | - if($model->has_primary_key_field() && $this->ID() && ! $bydb ){ |
|
166 | + if ($model->has_primary_key_field() && $this->ID() && ! $bydb) { |
|
167 | 167 | $model->add_to_entity_map($this); |
168 | 168 | } |
169 | 169 | //setup all the relations |
170 | - foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
|
171 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
170 | + foreach ($this->get_model()->relation_settings() as $relation_name=>$relation_obj) { |
|
171 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
172 | 172 | $this->_model_relations[$relation_name] = NULL; |
173 | - }else{ |
|
173 | + } else { |
|
174 | 174 | $this->_model_relations[$relation_name] = array(); |
175 | 175 | } |
176 | 176 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * Action done at the end of each model object construction |
179 | 179 | * @param EE_Base_Class $this the model object just created |
180 | 180 | */ |
181 | - do_action( 'AHEE__EE_Base_Class__construct__finished', $this ); |
|
181 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @param boolean $allow_persist |
199 | 199 | * @return boolean |
200 | 200 | */ |
201 | - function set_allow_persist( $allow_persist ) { |
|
201 | + function set_allow_persist($allow_persist) { |
|
202 | 202 | return $this->_allow_persist = $allow_persist; |
203 | 203 | } |
204 | 204 | |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | * @param string $field_name |
212 | 212 | * @return mixed|null |
213 | 213 | */ |
214 | - public function get_original( $field_name ){ |
|
215 | - if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
|
216 | - $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
|
217 | - return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
|
218 | - }else{ |
|
214 | + public function get_original($field_name) { |
|
215 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) && |
|
216 | + $field_settings = $this->get_Model()->field_settings_for($field_name)) { |
|
217 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
218 | + } else { |
|
219 | 219 | return NULL; |
220 | 220 | } |
221 | 221 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param EE_Base_Class $obj |
226 | 226 | * @return string |
227 | 227 | */ |
228 | - public function get_class($obj){ |
|
228 | + public function get_class($obj) { |
|
229 | 229 | return get_class($obj); |
230 | 230 | } |
231 | 231 | |
@@ -238,19 +238,19 @@ discard block |
||
238 | 238 | * @param mixed $field_value |
239 | 239 | * @param bool $use_default |
240 | 240 | */ |
241 | - public function set( $field_name, $field_value, $use_default = FALSE ){ |
|
242 | - $field_obj = $this->get_model()->field_settings_for( $field_name ); |
|
243 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
241 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
242 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
243 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
244 | 244 | // if ( method_exists( $field_obj, 'set_timezone' )) { |
245 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
246 | - $field_obj->set_timezone( $this->_timezone ); |
|
247 | - $field_obj->set_date_format( $this->_dt_frmt ); |
|
248 | - $field_obj->set_time_format( $this->_tm_frmt ); |
|
245 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
246 | + $field_obj->set_timezone($this->_timezone); |
|
247 | + $field_obj->set_date_format($this->_dt_frmt); |
|
248 | + $field_obj->set_time_format($this->_tm_frmt); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | $holder_of_value = $field_obj->prepare_for_set($field_value); |
252 | 252 | //should the value be null? |
253 | - if( ($field_value === NULL || $holder_of_value === NULL || $holder_of_value ==='') && $use_default){ |
|
253 | + if (($field_value === NULL || $holder_of_value === NULL || $holder_of_value === '') && $use_default) { |
|
254 | 254 | $this->_fields[$field_name] = $field_obj->get_default_value(); |
255 | 255 | |
256 | 256 | /** |
@@ -260,19 +260,19 @@ discard block |
||
260 | 260 | * object. |
261 | 261 | * @since 4.6.10+ |
262 | 262 | */ |
263 | - if ( $field_obj instanceof EE_Datetime_Field && ! is_null( $this->_fields[$field_name] ) && ! $this->_fields[$field_name] instanceof DateTime ) { |
|
264 | - empty( $this->_fields[$field_name] ) ? $this->set( $field_name, time() ) : $this->set( $field_name, $this->_fields[$field_name] ); |
|
263 | + if ($field_obj instanceof EE_Datetime_Field && ! is_null($this->_fields[$field_name]) && ! $this->_fields[$field_name] instanceof DateTime) { |
|
264 | + empty($this->_fields[$field_name]) ? $this->set($field_name, time()) : $this->set($field_name, $this->_fields[$field_name]); |
|
265 | 265 | } |
266 | 266 | |
267 | - }else{ |
|
267 | + } else { |
|
268 | 268 | $this->_fields[$field_name] = $holder_of_value; |
269 | 269 | } |
270 | 270 | |
271 | 271 | //if we're not in the constructor... |
272 | 272 | //now check if what we set was a primary key |
273 | - if($this->_props_n_values_provided_in_constructor && //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
273 | + if ($this->_props_n_values_provided_in_constructor && //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
274 | 274 | $field_name == $this->_get_primary_key_name(get_class($this)) && |
275 | - $field_value){ |
|
275 | + $field_value) { |
|
276 | 276 | //if so, we want all this object's fields to be filled either with |
277 | 277 | //what we've explicitly set on this model |
278 | 278 | //or what we have in the db |
@@ -280,20 +280,20 @@ discard block |
||
280 | 280 | $fields_on_model = $this->_get_model(get_class($this))->field_settings(); |
281 | 281 | |
282 | 282 | $obj_in_db = $this->_get_model(get_class($this))->get_one_by_ID($field_value); |
283 | - foreach($fields_on_model as $field_obj){ |
|
284 | - if( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
285 | - && $field_obj->get_name() != $field_name ){ |
|
283 | + foreach ($fields_on_model as $field_obj) { |
|
284 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
285 | + && $field_obj->get_name() != $field_name) { |
|
286 | 286 | |
287 | - $this->set($field_obj->get_name(),$obj_in_db->get($field_obj->get_name())); |
|
287 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | //oh this model object has an ID? well make sure its in the entity mapper |
291 | 291 | $this->get_model()->add_to_entity_map($this); |
292 | 292 | } |
293 | 293 | //let's unset any cache for this field_name from the $_cached_properties property. |
294 | - $this->_clear_cached_property( $field_name ); |
|
295 | - }else{ |
|
296 | - throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name ) ); |
|
294 | + $this->_clear_cached_property($field_name); |
|
295 | + } else { |
|
296 | + throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name)); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | } |
@@ -312,14 +312,14 @@ discard block |
||
312 | 312 | * @param mixed $field_value The value to set. |
313 | 313 | * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
314 | 314 | */ |
315 | - public function set_field_or_extra_meta( $field_name, $field_value ) { |
|
316 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
317 | - $this->set( $field_name, $field_value ); |
|
315 | + public function set_field_or_extra_meta($field_name, $field_value) { |
|
316 | + if ($this->get_model()->has_field($field_name)) { |
|
317 | + $this->set($field_name, $field_value); |
|
318 | 318 | return true; |
319 | 319 | } else { |
320 | 320 | //ensure this object is saved first so that extra meta can be properly related. |
321 | 321 | $this->save(); |
322 | - return $this->update_extra_meta( $field_name, $field_value ); |
|
322 | + return $this->update_extra_meta($field_name, $field_value); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
@@ -343,12 +343,12 @@ discard block |
||
343 | 343 | * @param string $field_name expecting the fully qualified field name. |
344 | 344 | * @return mixed|null value for the field if found. null if not found. |
345 | 345 | */ |
346 | - public function get_field_or_extra_meta( $field_name ) { |
|
347 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
348 | - $column_value = $this->get( $field_name ); |
|
346 | + public function get_field_or_extra_meta($field_name) { |
|
347 | + if ($this->get_model()->has_field($field_name)) { |
|
348 | + $column_value = $this->get($field_name); |
|
349 | 349 | } else { |
350 | 350 | //This isn't a column in the main table, let's see if it is in the extra meta. |
351 | - $column_value = $this->get_extra_meta( $field_name, true, null ); |
|
351 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
352 | 352 | } |
353 | 353 | return $column_value; |
354 | 354 | } |
@@ -367,19 +367,19 @@ discard block |
||
367 | 367 | * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
368 | 368 | * @return void |
369 | 369 | */ |
370 | - public function set_timezone( $timezone = '' ) { |
|
370 | + public function set_timezone($timezone = '') { |
|
371 | 371 | EE_Registry::instance()->load_helper('DTT_Helper'); |
372 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
372 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
373 | 373 | //make sure we clear all cached properties because they won't be relevant now |
374 | 374 | $this->_clear_cached_properties(); |
375 | 375 | |
376 | 376 | //make sure we update field settings and the date for all EE_Datetime_Fields |
377 | - $model_fields = $this->get_model()->field_settings( false ); |
|
378 | - foreach ( $model_fields as $field_name => $field_obj ) { |
|
379 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
380 | - $field_obj->set_timezone( $this->_timezone ); |
|
381 | - if ( isset( $this->_fields[$field_name] ) && $this->_fields[$field_name] instanceof DateTime ) { |
|
382 | - $this->_fields[$field_name]->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
377 | + $model_fields = $this->get_model()->field_settings(false); |
|
378 | + foreach ($model_fields as $field_name => $field_obj) { |
|
379 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
380 | + $field_obj->set_timezone($this->_timezone); |
|
381 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
382 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | } |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | * |
409 | 409 | * @param string $format should be a format recognizable by PHP date() functions. |
410 | 410 | */ |
411 | - public function set_date_format( $format ) { |
|
411 | + public function set_date_format($format) { |
|
412 | 412 | $this->_dt_frmt = $format; |
413 | 413 | //clear cached_properties because they won't be relevant now. |
414 | 414 | $this->_clear_cached_properties(); |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * @since 4.6 |
425 | 425 | * @param string $format should be a format recognizable by PHP date() functions. |
426 | 426 | */ |
427 | - public function set_time_format( $format ) { |
|
427 | + public function set_time_format($format) { |
|
428 | 428 | $this->_tm_frmt = $format; |
429 | 429 | //clear cached_properties because they won't be relevant now. |
430 | 430 | $this->_clear_cached_properties(); |
@@ -441,8 +441,8 @@ discard block |
||
441 | 441 | * |
442 | 442 | * @return mixed string|array |
443 | 443 | */ |
444 | - public function get_format( $full = true ) { |
|
445 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array( $this->_dt_frmt, $this->_tm_frmt ); |
|
444 | + public function get_format($full = true) { |
|
445 | + return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | |
@@ -460,17 +460,17 @@ discard block |
||
460 | 460 | * @throws EE_Error |
461 | 461 | * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array) |
462 | 462 | */ |
463 | - public function cache( $relationName = '', $object_to_cache = NULL, $cache_id = NULL ){ |
|
463 | + public function cache($relationName = '', $object_to_cache = NULL, $cache_id = NULL) { |
|
464 | 464 | // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
465 | - if ( ! $object_to_cache instanceof EE_Base_Class ) { |
|
465 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
466 | 466 | return FALSE; |
467 | 467 | } |
468 | 468 | // also get "how" the object is related, or throw an error |
469 | - if( ! $relationship_to_model = $this->get_model()->related_settings_for( $relationName )) { |
|
470 | - throw new EE_Error( sprintf( __( 'There is no relationship to %s on a %s. Cannot cache it', 'event_espresso' ), $relationName, get_class( $this ))); |
|
469 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
470 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this))); |
|
471 | 471 | } |
472 | 472 | // how many things are related ? |
473 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ){ |
|
473 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
474 | 474 | // if it's a "belongs to" relationship, then there's only one related model object eg, if this is a registration, there's only 1 attendee for it |
475 | 475 | // so for these model objects just set it to be cached |
476 | 476 | $this->_model_relations[$relationName] = $object_to_cache; |
@@ -478,26 +478,26 @@ discard block |
||
478 | 478 | } else { |
479 | 479 | // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type. |
480 | 480 | // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
481 | - if( ! is_array( $this->_model_relations[$relationName] )) { |
|
481 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
482 | 482 | // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
483 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array( $this->_model_relations[$relationName] ) : array(); |
|
483 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array(); |
|
484 | 484 | } |
485 | 485 | // first check for a cache_id which is normally empty |
486 | - if ( ! empty( $cache_id )) { |
|
486 | + if ( ! empty($cache_id)) { |
|
487 | 487 | // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on |
488 | - $this->_model_relations[$relationName][ $cache_id ] = $object_to_cache; |
|
488 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
489 | 489 | $return = $cache_id; |
490 | - } elseif ( $object_to_cache->ID() ) { |
|
490 | + } elseif ($object_to_cache->ID()) { |
|
491 | 491 | // OR the cached object originally came from the db, so let's just use it's PK for an ID |
492 | - $this->_model_relations[$relationName][ $object_to_cache->ID() ] = $object_to_cache; |
|
492 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
493 | 493 | $return = $object_to_cache->ID(); |
494 | 494 | } else { |
495 | 495 | // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
496 | 496 | $this->_model_relations[$relationName][] = $object_to_cache; |
497 | 497 | // move the internal pointer to the end of the array |
498 | - end( $this->_model_relations[$relationName] ); |
|
498 | + end($this->_model_relations[$relationName]); |
|
499 | 499 | // and grab the key so that we can return it |
500 | - $return = key( $this->_model_relations[$relationName] ); |
|
500 | + $return = key($this->_model_relations[$relationName]); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | } |
@@ -515,11 +515,11 @@ discard block |
||
515 | 515 | * @param null $cache_type |
516 | 516 | * @return void |
517 | 517 | */ |
518 | - protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
|
518 | + protected function _set_cached_property($fieldname, $value, $cache_type = NULL) { |
|
519 | 519 | //first make sure this property exists |
520 | 520 | $this->get_model()->field_settings_for($fieldname); |
521 | 521 | |
522 | - $cache_type = empty( $cache_type ) ? 'standard' : $cache_type; |
|
522 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
523 | 523 | $this->_cached_properties[$fieldname][$cache_type] = $value; |
524 | 524 | } |
525 | 525 | |
@@ -534,34 +534,34 @@ discard block |
||
534 | 534 | * It can also accept certain pre-defined "schema" strings to define how to output the property. see the field's prepare_for_pretty_echoing for what strings can be used |
535 | 535 | * @return mixed whatever the value for the property is we're retrieving |
536 | 536 | */ |
537 | - protected function _get_cached_property( $fieldname, $pretty = FALSE, $extra_cache_ref = NULL ) { |
|
537 | + protected function _get_cached_property($fieldname, $pretty = FALSE, $extra_cache_ref = NULL) { |
|
538 | 538 | //verify the field exists |
539 | 539 | $this->get_model()->field_settings_for($fieldname); |
540 | 540 | |
541 | 541 | $cache_type = $pretty ? 'pretty' : 'standard'; |
542 | - $cache_type .= !empty( $extra_cache_ref ) ? '_' . $extra_cache_ref : ''; |
|
542 | + $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : ''; |
|
543 | 543 | |
544 | - if ( isset( $this->_cached_properties[$fieldname][$cache_type] ) ) { |
|
544 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
545 | 545 | return $this->_cached_properties[$fieldname][$cache_type]; |
546 | 546 | } |
547 | 547 | |
548 | 548 | $field_obj = $this->get_model()->field_settings_for($fieldname); |
549 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
549 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
550 | 550 | /** |
551 | 551 | * maybe this is EE_Datetime_Field. If so we need to make sure timezone and |
552 | 552 | * formats are correct. |
553 | 553 | */ |
554 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
555 | - $field_obj->set_timezone( $this->_timezone ); |
|
556 | - $field_obj->set_date_format( $this->_dt_frmt, $pretty ); |
|
557 | - $field_obj->set_time_format( $this->_tm_frmt, $pretty ); |
|
554 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
555 | + $field_obj->set_timezone($this->_timezone); |
|
556 | + $field_obj->set_date_format($this->_dt_frmt, $pretty); |
|
557 | + $field_obj->set_time_format($this->_tm_frmt, $pretty); |
|
558 | 558 | } |
559 | 559 | |
560 | - if( ! isset($this->_fields[$fieldname])){ |
|
560 | + if ( ! isset($this->_fields[$fieldname])) { |
|
561 | 561 | $this->_fields[$fieldname] = NULL; |
562 | 562 | } |
563 | - $value = $pretty ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) : $field_obj->prepare_for_get($this->_fields[$fieldname] ); |
|
564 | - $this->_set_cached_property( $fieldname, $value, $cache_type ); |
|
563 | + $value = $pretty ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
564 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
565 | 565 | return $value; |
566 | 566 | } |
567 | 567 | return FALSE; |
@@ -587,9 +587,9 @@ discard block |
||
587 | 587 | * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
588 | 588 | * @return void |
589 | 589 | */ |
590 | - protected function _clear_cached_property( $property_name ) { |
|
591 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) |
|
592 | - unset( $this->_cached_properties[ $property_name ] ); |
|
590 | + protected function _clear_cached_property($property_name) { |
|
591 | + if (isset($this->_cached_properties[$property_name])) |
|
592 | + unset($this->_cached_properties[$property_name]); |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | * @param string $model_name name of the related thing, eg 'Attendee', |
601 | 601 | * @return EE_Base_Class |
602 | 602 | */ |
603 | - protected function ensure_related_thing_is_model_obj($object_or_id,$model_name){ |
|
603 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) { |
|
604 | 604 | $other_model_instance = self::_get_model_instance_with_name(self::_get_model_classname($model_name), $this->_timezone); |
605 | 605 | $model_obj = $other_model_instance->ensure_is_obj($object_or_id); |
606 | 606 | return $model_obj; |
@@ -620,55 +620,55 @@ discard block |
||
620 | 620 | * @throws EE_Error |
621 | 621 | * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
622 | 622 | */ |
623 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE){ |
|
623 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE) { |
|
624 | 624 | $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
625 | 625 | $index_in_cache = ''; |
626 | - if( ! $relationship_to_model){ |
|
627 | - throw new EE_Error(sprintf(__("There is no relationship to %s on a %s. Cannot clear that cache",'event_espresso'),$relationName,get_class($this))); |
|
626 | + if ( ! $relationship_to_model) { |
|
627 | + throw new EE_Error(sprintf(__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), $relationName, get_class($this))); |
|
628 | 628 | } |
629 | - if($clear_all){ |
|
629 | + if ($clear_all) { |
|
630 | 630 | $obj_removed = true; |
631 | 631 | $this->_model_relations[$relationName] = null; |
632 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
632 | + }elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
633 | 633 | $obj_removed = $this->_model_relations[$relationName]; |
634 | 634 | $this->_model_relations[$relationName] = null; |
635 | - }else{ |
|
636 | - if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
|
635 | + } else { |
|
636 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) { |
|
637 | 637 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
638 | - if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
|
638 | + if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
639 | 639 | $index_found_at = NULL; |
640 | 640 | //find this object in the array even though it has a different key |
641 | - foreach($this->_model_relations[$relationName] as $index=>$obj){ |
|
642 | - if( $obj instanceof EE_Base_Class && ( $obj == $object_to_remove_or_index_into_array || $obj->ID() == $object_to_remove_or_index_into_array->ID() )) { |
|
641 | + foreach ($this->_model_relations[$relationName] as $index=>$obj) { |
|
642 | + if ($obj instanceof EE_Base_Class && ($obj == $object_to_remove_or_index_into_array || $obj->ID() == $object_to_remove_or_index_into_array->ID())) { |
|
643 | 643 | $index_found_at = $index; |
644 | 644 | break; |
645 | 645 | } |
646 | 646 | } |
647 | - if($index_found_at){ |
|
647 | + if ($index_found_at) { |
|
648 | 648 | $index_in_cache = $index_found_at; |
649 | - }else{ |
|
649 | + } else { |
|
650 | 650 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
651 | 651 | //if it wasn't in it to begin with. So we're done |
652 | 652 | return $object_to_remove_or_index_into_array; |
653 | 653 | } |
654 | 654 | } |
655 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
655 | + }elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
656 | 656 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
657 | - foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
|
658 | - if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
|
657 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
658 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
659 | 659 | $index_in_cache = $index; |
660 | 660 | } |
661 | 661 | } |
662 | - }else{ |
|
662 | + } else { |
|
663 | 663 | $index_in_cache = $object_to_remove_or_index_into_array; |
664 | 664 | } |
665 | 665 | //supposedly we've found it. But it could just be that the client code |
666 | 666 | //provided a bad index/object |
667 | - if(isset( $this->_model_relations[$relationName]) && |
|
668 | - isset( $this->_model_relations[$relationName][$index_in_cache])){ |
|
667 | + if (isset($this->_model_relations[$relationName]) && |
|
668 | + isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
669 | 669 | $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
670 | 670 | unset($this->_model_relations[$relationName][$index_in_cache]); |
671 | - }else{ |
|
671 | + } else { |
|
672 | 672 | //that thing was never cached anyways. |
673 | 673 | $obj_removed = NULL; |
674 | 674 | } |
@@ -687,24 +687,24 @@ discard block |
||
687 | 687 | * @param string $current_cache_id - the ID that was used when originally caching the object |
688 | 688 | * @return boolean TRUE on success, FALSE on fail |
689 | 689 | */ |
690 | - public function update_cache_after_object_save( $relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
690 | + public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
691 | 691 | // verify that incoming object is of the correct type |
692 | - $obj_class = 'EE_' . $relationName; |
|
693 | - if ( $newly_saved_object instanceof $obj_class ) { |
|
692 | + $obj_class = 'EE_'.$relationName; |
|
693 | + if ($newly_saved_object instanceof $obj_class) { |
|
694 | 694 | /* @type EE_Base_Class $newly_saved_object*/ |
695 | 695 | // now get the type of relation |
696 | - $relationship_to_model = $this->get_model()->related_settings_for( $relationName ); |
|
696 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
697 | 697 | // if this is a 1:1 relationship |
698 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ) { |
|
698 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
699 | 699 | // then just replace the cached object with the newly saved object |
700 | 700 | $this->_model_relations[$relationName] = $newly_saved_object; |
701 | 701 | return TRUE; |
702 | 702 | // or if it's some kind of sordid feral polyamorous relationship... |
703 | - } elseif ( is_array( $this->_model_relations[$relationName] ) && isset( $this->_model_relations[$relationName][ $current_cache_id ] )) { |
|
703 | + } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) { |
|
704 | 704 | // then remove the current cached item |
705 | - unset( $this->_model_relations[$relationName][ $current_cache_id ] ); |
|
705 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
706 | 706 | // and cache the newly saved object using it's new ID |
707 | - $this->_model_relations[$relationName][ $newly_saved_object->ID() ] = $newly_saved_object; |
|
707 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
708 | 708 | return TRUE; |
709 | 709 | } |
710 | 710 | } |
@@ -720,11 +720,11 @@ discard block |
||
720 | 720 | * @param string $relationName |
721 | 721 | * @return EE_Base_Class |
722 | 722 | */ |
723 | - public function get_one_from_cache($relationName){ |
|
724 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
|
725 | - if(is_array($cached_array_or_object)){ |
|
723 | + public function get_one_from_cache($relationName) { |
|
724 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null; |
|
725 | + if (is_array($cached_array_or_object)) { |
|
726 | 726 | return array_shift($cached_array_or_object); |
727 | - }else{ |
|
727 | + } else { |
|
728 | 728 | return $cached_array_or_object; |
729 | 729 | } |
730 | 730 | } |
@@ -739,14 +739,14 @@ discard block |
||
739 | 739 | * @throws \EE_Error |
740 | 740 | * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
741 | 741 | */ |
742 | - public function get_all_from_cache($relationName){ |
|
743 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
|
744 | - if(is_array($cached_array_or_object)){ |
|
742 | + public function get_all_from_cache($relationName) { |
|
743 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
744 | + if (is_array($cached_array_or_object)) { |
|
745 | 745 | $objects = $cached_array_or_object; |
746 | - }elseif($cached_array_or_object){ |
|
746 | + }elseif ($cached_array_or_object) { |
|
747 | 747 | //if the result is not an array, but exists, make it an array |
748 | 748 | $objects = array($cached_array_or_object); |
749 | - }else{ |
|
749 | + } else { |
|
750 | 750 | //if nothing was found, return an empty array |
751 | 751 | $objects = array(); |
752 | 752 | } |
@@ -754,15 +754,15 @@ discard block |
||
754 | 754 | //basically, if this model object was stored in the session, and these cached model objects |
755 | 755 | //already have IDs, let's make sure they're in their model's entity mapper |
756 | 756 | //otherwise we will have duplicates next time we call EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
757 | - foreach( $objects as $model_object ){ |
|
758 | - $model = EE_Registry::instance()->load_model( $relationName ); |
|
759 | - if( $model instanceof EEM_Base && $model_object instanceof EE_Base_Class ){ |
|
757 | + foreach ($objects as $model_object) { |
|
758 | + $model = EE_Registry::instance()->load_model($relationName); |
|
759 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
760 | 760 | //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
761 | - if( $model_object->ID() ){ |
|
762 | - $model->add_to_entity_map( $model_object ); |
|
761 | + if ($model_object->ID()) { |
|
762 | + $model->add_to_entity_map($model_object); |
|
763 | 763 | } |
764 | - }else{ |
|
765 | - throw new EE_Error( sprintf( __( 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso' ), $relationName, gettype( $model_object ))); |
|
764 | + } else { |
|
765 | + throw new EE_Error(sprintf(__('Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso'), $relationName, gettype($model_object))); |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | return $objects; |
@@ -781,13 +781,13 @@ discard block |
||
781 | 781 | * |
782 | 782 | * @return array|EE_Base_Class[] |
783 | 783 | */ |
784 | - public function next_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
785 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
786 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
787 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
784 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
785 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
786 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
787 | + if (empty($field) || empty($current_value)) { |
|
788 | 788 | return array(); |
789 | 789 | } |
790 | - return $this->get_model()->next_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
790 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | |
@@ -806,13 +806,13 @@ discard block |
||
806 | 806 | * |
807 | 807 | * @return array|EE_Base_Class[] |
808 | 808 | */ |
809 | - public function previous_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
810 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
811 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
812 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
809 | + public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
810 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
811 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
812 | + if (empty($field) || empty($current_value)) { |
|
813 | 813 | return array(); |
814 | 814 | } |
815 | - return $this->get_model()->previous_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
815 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
816 | 816 | } |
817 | 817 | |
818 | 818 | |
@@ -830,13 +830,13 @@ discard block |
||
830 | 830 | * |
831 | 831 | * @return array|EE_Base_Class |
832 | 832 | */ |
833 | - public function next( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
834 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
835 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
836 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
833 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
834 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
835 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
836 | + if (empty($field) || empty($current_value)) { |
|
837 | 837 | return array(); |
838 | 838 | } |
839 | - return $this->get_model()->next( $current_value, $field, $query_params, $columns_to_select ); |
|
839 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | |
@@ -855,13 +855,13 @@ discard block |
||
855 | 855 | * |
856 | 856 | * @return array|EE_Base_Class |
857 | 857 | */ |
858 | - public function previous( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
859 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
860 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
861 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
858 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
859 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
860 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
861 | + if (empty($field) || empty($current_value)) { |
|
862 | 862 | return array(); |
863 | 863 | } |
864 | - return $this->get_model()->previous( $current_value, $field, $query_params, $columns_to_select ); |
|
864 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | |
@@ -875,25 +875,25 @@ discard block |
||
875 | 875 | * @param string $field_name |
876 | 876 | * @param mixed $field_value_from_db |
877 | 877 | */ |
878 | - public function set_from_db($field_name,$field_value_from_db){ |
|
878 | + public function set_from_db($field_name, $field_value_from_db) { |
|
879 | 879 | $field_obj = $this->get_model()->field_settings_for($field_name); |
880 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
880 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
881 | 881 | //you would think the DB has no NULLs for non-null label fields right? wrong! |
882 | 882 | //eg, a CPT model object could have an entry in the posts table, but no |
883 | 883 | //entry in the meta table. Meaning that all its columns in the meta table |
884 | 884 | //are null! yikes! so when we find one like that, use defaults for its meta columns |
885 | - if($field_value_from_db === NULL ){ |
|
886 | - if( $field_obj->is_nullable()){ |
|
885 | + if ($field_value_from_db === NULL) { |
|
886 | + if ($field_obj->is_nullable()) { |
|
887 | 887 | //if the field allows nulls, then let it be null |
888 | 888 | $field_value = NULL; |
889 | - }else{ |
|
889 | + } else { |
|
890 | 890 | $field_value = $field_obj->get_default_value(); |
891 | 891 | } |
892 | - }else{ |
|
893 | - $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
|
892 | + } else { |
|
893 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
894 | 894 | } |
895 | 895 | $this->_fields[$field_name] = $field_value; |
896 | - $this->_clear_cached_property( $field_name ); |
|
896 | + $this->_clear_cached_property($field_name); |
|
897 | 897 | } |
898 | 898 | } |
899 | 899 | |
@@ -905,8 +905,8 @@ discard block |
||
905 | 905 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
906 | 906 | * @return boolean |
907 | 907 | */ |
908 | - public function get($field_name, $extra_cache_ref = NULL ){ |
|
909 | - return $this->_get_cached_property( $field_name, FALSE, $extra_cache_ref ); |
|
908 | + public function get($field_name, $extra_cache_ref = NULL) { |
|
909 | + return $this->_get_cached_property($field_name, FALSE, $extra_cache_ref); |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | |
@@ -936,11 +936,11 @@ discard block |
||
936 | 936 | * just null is returned (because that indicates that likely |
937 | 937 | * this field is nullable). |
938 | 938 | */ |
939 | - public function get_DateTime_object( $field_name ) { |
|
940 | - $field_settings = $this->get_model()->field_settings_for( $field_name ); |
|
939 | + public function get_DateTime_object($field_name) { |
|
940 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
941 | 941 | |
942 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
943 | - EE_Error::add_error( sprintf( __('The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', 'event_espresso' ), $field_name ), __FILE__, __FUNCTION__, __LINE__ ); |
|
942 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
943 | + EE_Error::add_error(sprintf(__('The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', 'event_espresso'), $field_name), __FILE__, __FUNCTION__, __LINE__); |
|
944 | 944 | return false; |
945 | 945 | } |
946 | 946 | |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
957 | 957 | * @return void |
958 | 958 | */ |
959 | - public function e($field_name, $extra_cache_ref = NULL){ |
|
959 | + public function e($field_name, $extra_cache_ref = NULL) { |
|
960 | 960 | echo $this->get_pretty($field_name, $extra_cache_ref); |
961 | 961 | } |
962 | 962 | /** |
@@ -965,8 +965,8 @@ discard block |
||
965 | 965 | * @param string $field_name |
966 | 966 | * @return void |
967 | 967 | */ |
968 | - public function f($field_name){ |
|
969 | - $this->e($field_name,'form_input'); |
|
968 | + public function f($field_name) { |
|
969 | + $this->e($field_name, 'form_input'); |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | /** |
@@ -975,8 +975,8 @@ discard block |
||
975 | 975 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
976 | 976 | * @return mixed |
977 | 977 | */ |
978 | - public function get_pretty($field_name, $extra_cache_ref = NULL){ |
|
979 | - return $this->_get_cached_property( $field_name, TRUE, $extra_cache_ref ); |
|
978 | + public function get_pretty($field_name, $extra_cache_ref = NULL) { |
|
979 | + return $this->_get_cached_property($field_name, TRUE, $extra_cache_ref); |
|
980 | 980 | } |
981 | 981 | |
982 | 982 | |
@@ -993,37 +993,37 @@ discard block |
||
993 | 993 | * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
994 | 994 | * @return void | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
995 | 995 | */ |
996 | - protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
|
996 | + protected function _get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE) { |
|
997 | 997 | |
998 | - $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
998 | + $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
999 | 999 | $in_tm_frmt = empty($tm_frmt) ? $this->_tm_frmt : $tm_frmt; |
1000 | 1000 | |
1001 | 1001 | //validate field for datetime and returns field settings if valid. |
1002 | - $field = $this->_get_dtt_field_settings( $field_name ); |
|
1002 | + $field = $this->_get_dtt_field_settings($field_name); |
|
1003 | 1003 | |
1004 | 1004 | //clear cached property if either formats are not null. |
1005 | - if( $dt_frmt !== null || $tm_frmt !== null ) { |
|
1006 | - $this->_clear_cached_property( $field_name ); |
|
1005 | + if ($dt_frmt !== null || $tm_frmt !== null) { |
|
1006 | + $this->_clear_cached_property($field_name); |
|
1007 | 1007 | //reset format properties because they are used in get() |
1008 | 1008 | $this->_dt_frmt = $in_dt_frmt; |
1009 | 1009 | $this->_tm_frmt = $in_tm_frmt; |
1010 | 1010 | } |
1011 | 1011 | |
1012 | - if ( $echo ) |
|
1013 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
1012 | + if ($echo) |
|
1013 | + $field->set_pretty_date_format($in_dt_frmt); |
|
1014 | 1014 | else |
1015 | - $field->set_date_format( $in_dt_frmt ); |
|
1015 | + $field->set_date_format($in_dt_frmt); |
|
1016 | 1016 | |
1017 | - if ( $echo ) |
|
1018 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
1017 | + if ($echo) |
|
1018 | + $field->set_pretty_time_format($in_tm_frmt); |
|
1019 | 1019 | else |
1020 | - $field->set_time_format( $in_tm_frmt ); |
|
1020 | + $field->set_time_format($in_tm_frmt); |
|
1021 | 1021 | |
1022 | 1022 | //set timezone in field object |
1023 | - $field->set_timezone( $this->_timezone ); |
|
1023 | + $field->set_timezone($this->_timezone); |
|
1024 | 1024 | |
1025 | 1025 | //set the output returned |
1026 | - switch ( $date_or_time ) { |
|
1026 | + switch ($date_or_time) { |
|
1027 | 1027 | |
1028 | 1028 | case 'D' : |
1029 | 1029 | $field->set_date_time_output('date'); |
@@ -1038,11 +1038,11 @@ discard block |
||
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | |
1041 | - if ( $echo ) { |
|
1042 | - $this->e( $field_name, $date_or_time ); |
|
1041 | + if ($echo) { |
|
1042 | + $this->e($field_name, $date_or_time); |
|
1043 | 1043 | return ''; |
1044 | 1044 | } |
1045 | - return $this->get( $field_name, $date_or_time ); |
|
1045 | + return $this->get($field_name, $date_or_time); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | |
@@ -1052,8 +1052,8 @@ discard block |
||
1052 | 1052 | * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
1053 | 1053 | * @return string datetime value formatted |
1054 | 1054 | */ |
1055 | - public function get_date( $field_name, $format = NULL ) { |
|
1056 | - return $this->_get_datetime( $field_name, $format, NULL, 'D' ); |
|
1055 | + public function get_date($field_name, $format = NULL) { |
|
1056 | + return $this->_get_datetime($field_name, $format, NULL, 'D'); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | |
@@ -1062,8 +1062,8 @@ discard block |
||
1062 | 1062 | * @param $field_name |
1063 | 1063 | * @param null $format |
1064 | 1064 | */ |
1065 | - public function e_date( $field_name, $format = NULL ) { |
|
1066 | - $this->_get_datetime( $field_name, $format, NULL, 'D', TRUE ); |
|
1065 | + public function e_date($field_name, $format = NULL) { |
|
1066 | + $this->_get_datetime($field_name, $format, NULL, 'D', TRUE); |
|
1067 | 1067 | } |
1068 | 1068 | |
1069 | 1069 | |
@@ -1073,8 +1073,8 @@ discard block |
||
1073 | 1073 | * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
1074 | 1074 | * @return string datetime value formatted |
1075 | 1075 | */ |
1076 | - public function get_time( $field_name, $format = NULL ) { |
|
1077 | - return $this->_get_datetime( $field_name, NULL, $format, 'T' ); |
|
1076 | + public function get_time($field_name, $format = NULL) { |
|
1077 | + return $this->_get_datetime($field_name, NULL, $format, 'T'); |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | |
@@ -1083,8 +1083,8 @@ discard block |
||
1083 | 1083 | * @param $field_name |
1084 | 1084 | * @param null $format |
1085 | 1085 | */ |
1086 | - public function e_time( $field_name, $format = NULL ) { |
|
1087 | - $this->_get_datetime( $field_name, NULL, $format, 'T', TRUE ); |
|
1086 | + public function e_time($field_name, $format = NULL) { |
|
1087 | + $this->_get_datetime($field_name, NULL, $format, 'T', TRUE); |
|
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
1098 | 1098 | * @return string datetime value formatted |
1099 | 1099 | */ |
1100 | - public function get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
1101 | - return $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt ); |
|
1100 | + public function get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
1101 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | |
@@ -1108,8 +1108,8 @@ discard block |
||
1108 | 1108 | * @param null $dt_frmt |
1109 | 1109 | * @param null $tm_frmt |
1110 | 1110 | */ |
1111 | - public function e_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
1112 | - $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
1111 | + public function e_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
1112 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | |
@@ -1124,10 +1124,10 @@ discard block |
||
1124 | 1124 | * @return string Date and time string in set locale or false if no field exists for the given |
1125 | 1125 | * field name. |
1126 | 1126 | */ |
1127 | - public function get_i18n_datetime( $field_name, $format = NULL ) { |
|
1128 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1129 | - $format = empty( $format ) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
1130 | - return date_i18n( $format, EEH_DTT_Helper::get_timestamp_with_offset( $this->get_raw( $field_name ), $this->_timezone ) ); |
|
1127 | + public function get_i18n_datetime($field_name, $format = NULL) { |
|
1128 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1129 | + $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format; |
|
1130 | + return date_i18n($format, EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | |
@@ -1139,14 +1139,14 @@ discard block |
||
1139 | 1139 | * @throws EE_Error |
1140 | 1140 | * @return EE_Datetime_Field |
1141 | 1141 | */ |
1142 | - protected function _get_dtt_field_settings( $field_name ) { |
|
1142 | + protected function _get_dtt_field_settings($field_name) { |
|
1143 | 1143 | $field = $this->get_model()->field_settings_for($field_name); |
1144 | 1144 | |
1145 | 1145 | //check if field is dtt |
1146 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1146 | + if ($field instanceof EE_Datetime_Field) { |
|
1147 | 1147 | return $field; |
1148 | 1148 | } else { |
1149 | - throw new EE_Error( sprintf( __('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname( get_class($this) ) ) ); |
|
1149 | + throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
1150 | 1150 | } |
1151 | 1151 | } |
1152 | 1152 | |
@@ -1167,8 +1167,8 @@ discard block |
||
1167 | 1167 | * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
1168 | 1168 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
1169 | 1169 | */ |
1170 | - protected function _set_time_for( $time, $fieldname ) { |
|
1171 | - $this->_set_date_time( 'T', $time, $fieldname ); |
|
1170 | + protected function _set_time_for($time, $fieldname) { |
|
1171 | + $this->_set_date_time('T', $time, $fieldname); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | |
@@ -1182,8 +1182,8 @@ discard block |
||
1182 | 1182 | * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
1183 | 1183 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
1184 | 1184 | */ |
1185 | - protected function _set_date_for( $date, $fieldname ) { |
|
1186 | - $this->_set_date_time( 'D', $date, $fieldname ); |
|
1185 | + protected function _set_date_for($date, $fieldname) { |
|
1186 | + $this->_set_date_time('D', $date, $fieldname); |
|
1187 | 1187 | } |
1188 | 1188 | |
1189 | 1189 | |
@@ -1199,21 +1199,21 @@ discard block |
||
1199 | 1199 | * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
1200 | 1200 | * @param string $fieldname the name of the field the date OR time is being set on (must match a EE_Datetime_Field property) |
1201 | 1201 | */ |
1202 | - protected function _set_date_time( $what = 'T', $datetime_value, $fieldname ) { |
|
1203 | - $field = $this->_get_dtt_field_settings( $fieldname ); |
|
1204 | - $field->set_timezone( $this->_timezone ); |
|
1205 | - $field->set_date_format( $this->_dt_frmt ); |
|
1206 | - $field->set_time_format( $this->_tm_frmt ); |
|
1202 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) { |
|
1203 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
1204 | + $field->set_timezone($this->_timezone); |
|
1205 | + $field->set_date_format($this->_dt_frmt); |
|
1206 | + $field->set_time_format($this->_tm_frmt); |
|
1207 | 1207 | |
1208 | - switch ( $what ) { |
|
1208 | + switch ($what) { |
|
1209 | 1209 | case 'T' : |
1210 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( $datetime_value, $this->_fields[$fieldname] ); |
|
1210 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time($datetime_value, $this->_fields[$fieldname]); |
|
1211 | 1211 | break; |
1212 | 1212 | case 'D' : |
1213 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( $datetime_value, $this->_fields[$fieldname] ); |
|
1213 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date($datetime_value, $this->_fields[$fieldname]); |
|
1214 | 1214 | break; |
1215 | 1215 | case 'B' : |
1216 | - $this->_fields[$fieldname] = $field->prepare_for_set( $datetime_value ); |
|
1216 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
1217 | 1217 | break; |
1218 | 1218 | } |
1219 | 1219 | |
@@ -1236,25 +1236,25 @@ discard block |
||
1236 | 1236 | * @throws EE_Error |
1237 | 1237 | * @return string timestamp |
1238 | 1238 | */ |
1239 | - public function display_in_my_timezone( $field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '' ) { |
|
1239 | + public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '') { |
|
1240 | 1240 | EE_Registry::instance()->load_helper('DTT_Helper'); |
1241 | 1241 | $timezone = EEH_DTT_Helper::get_timezone(); |
1242 | 1242 | |
1243 | - if ( $timezone == $this->_timezone ) |
|
1243 | + if ($timezone == $this->_timezone) |
|
1244 | 1244 | return ''; |
1245 | 1245 | |
1246 | 1246 | $original_timezone = $this->_timezone; |
1247 | - $this->set_timezone( $timezone ); |
|
1247 | + $this->set_timezone($timezone); |
|
1248 | 1248 | |
1249 | 1249 | $fn = (array) $field_name; |
1250 | - $args = array_merge( $fn, (array) $args ); |
|
1250 | + $args = array_merge($fn, (array) $args); |
|
1251 | 1251 | |
1252 | - if ( !method_exists( $this, $callback ) ) |
|
1253 | - throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1252 | + if ( ! method_exists($this, $callback)) |
|
1253 | + throw new EE_Error(sprintf(__('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback)); |
|
1254 | 1254 | $args = (array) $args; |
1255 | - $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
|
1255 | + $return = $prepend.call_user_func_array(array($this, $callback), $args).$append; |
|
1256 | 1256 | |
1257 | - $this->set_timezone( $original_timezone ); |
|
1257 | + $this->set_timezone($original_timezone); |
|
1258 | 1258 | return $return; |
1259 | 1259 | } |
1260 | 1260 | |
@@ -1265,21 +1265,21 @@ discard block |
||
1265 | 1265 | * Deletes this model object. That may mean just 'soft deleting' it though. |
1266 | 1266 | * @return boolean | int |
1267 | 1267 | */ |
1268 | - public function delete(){ |
|
1268 | + public function delete() { |
|
1269 | 1269 | /** |
1270 | 1270 | * Called just before deleting a model object |
1271 | 1271 | * |
1272 | 1272 | * @param EE_Base_Class $model_object about to be 'deleted' |
1273 | 1273 | */ |
1274 | - do_action( 'AHEE__EE_Base_Class__delete__before', $this ); |
|
1275 | - $result = $this->get_model()->delete_by_ID( $this->ID() ); |
|
1274 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
1275 | + $result = $this->get_model()->delete_by_ID($this->ID()); |
|
1276 | 1276 | $this->refresh_cache_of_related_objects(); |
1277 | 1277 | /** |
1278 | 1278 | * Called just after deleting a model object |
1279 | 1279 | * @param EE_Base_Class $model_object that was just 'deleted' |
1280 | 1280 | * @param boolean $result |
1281 | 1281 | */ |
1282 | - do_action( 'AHEE__EE_Base_Class__delete__end', $this, $result ); |
|
1282 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
1283 | 1283 | return $result; |
1284 | 1284 | } |
1285 | 1285 | |
@@ -1289,12 +1289,12 @@ discard block |
||
1289 | 1289 | * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error) |
1290 | 1290 | * @return bool |
1291 | 1291 | */ |
1292 | - public function delete_permanently(){ |
|
1293 | - $model=$this->get_model(); |
|
1294 | - if($model instanceof EEM_Soft_Delete_Base){ |
|
1295 | - $result=$model->delete_permanently_by_ID($this->ID()); |
|
1292 | + public function delete_permanently() { |
|
1293 | + $model = $this->get_model(); |
|
1294 | + if ($model instanceof EEM_Soft_Delete_Base) { |
|
1295 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
1296 | 1296 | $this->refresh_cache_of_related_objects(); |
1297 | - }else{ |
|
1297 | + } else { |
|
1298 | 1298 | $result = $this->delete(); |
1299 | 1299 | } |
1300 | 1300 | return $result ? true : false; |
@@ -1305,18 +1305,18 @@ discard block |
||
1305 | 1305 | * related model objects |
1306 | 1306 | */ |
1307 | 1307 | public function refresh_cache_of_related_objects() { |
1308 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
1309 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
1310 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
1311 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
1308 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1309 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
1310 | + $related_objects = $this->_model_relations[$relation_name]; |
|
1311 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
1312 | 1312 | //this relation only stores a single model object, not an array |
1313 | 1313 | //but let's make it consistent |
1314 | - $related_objects = array( $related_objects ); |
|
1314 | + $related_objects = array($related_objects); |
|
1315 | 1315 | } |
1316 | - foreach( $related_objects as $related_object ) { |
|
1316 | + foreach ($related_objects as $related_object) { |
|
1317 | 1317 | //only refresh their cache if they're in memory |
1318 | - if( $related_object instanceof EE_Base_Class ) { |
|
1319 | - $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1318 | + if ($related_object instanceof EE_Base_Class) { |
|
1319 | + $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1320 | 1320 | } |
1321 | 1321 | } |
1322 | 1322 | } |
@@ -1336,17 +1336,17 @@ discard block |
||
1336 | 1336 | * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
1337 | 1337 | * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
1338 | 1338 | */ |
1339 | - public function save($set_cols_n_values=array()) { |
|
1339 | + public function save($set_cols_n_values = array()) { |
|
1340 | 1340 | /** |
1341 | 1341 | * Filters the fields we're about to save on the model object |
1342 | 1342 | * |
1343 | 1343 | * @param array $set_cols_n_values |
1344 | 1344 | * @param EE_Base_Class $model_object |
1345 | 1345 | */ |
1346 | - $set_cols_n_values = apply_filters( 'FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this ); |
|
1346 | + $set_cols_n_values = apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
1347 | 1347 | //set attributes as provided in $set_cols_n_values |
1348 | - foreach($set_cols_n_values as $column=>$value){ |
|
1349 | - $this->set($column,$value); |
|
1348 | + foreach ($set_cols_n_values as $column=>$value) { |
|
1349 | + $this->set($column, $value); |
|
1350 | 1350 | } |
1351 | 1351 | /** |
1352 | 1352 | * Saving a model object. |
@@ -1354,8 +1354,8 @@ discard block |
||
1354 | 1354 | * Before we perform a save, this action is fired. |
1355 | 1355 | * @param EE_Base_Class $model_object the model object about to be saved. |
1356 | 1356 | */ |
1357 | - do_action( 'AHEE__EE_Base_Class__save__begin', $this ); |
|
1358 | - if( ! $this->allow_persist() ) { |
|
1357 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
1358 | + if ( ! $this->allow_persist()) { |
|
1359 | 1359 | return 0; |
1360 | 1360 | } |
1361 | 1361 | //now get current attribute values |
@@ -1365,61 +1365,61 @@ discard block |
||
1365 | 1365 | $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object(); |
1366 | 1366 | $this->get_model()->assume_values_already_prepared_by_model_object(true); |
1367 | 1367 | //does this model have an autoincrement PK? |
1368 | - if($this->get_model()->has_primary_key_field()){ |
|
1369 | - if($this->get_model()->get_primary_key_field()->is_auto_increment()){ |
|
1368 | + if ($this->get_model()->has_primary_key_field()) { |
|
1369 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
1370 | 1370 | //ok check if it's set, if so: update; if not, insert |
1371 | - if ( ! empty( $save_cols_n_values[self::_get_primary_key_name( get_class($this) )] ) ){ |
|
1372 | - $results = $this->get_model()->update_by_ID ( $save_cols_n_values, $this->ID() ); |
|
1371 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
1372 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
1373 | 1373 | } else { |
1374 | - unset($save_cols_n_values[self::_get_primary_key_name( get_class( $this) )]); |
|
1375 | - $results = $this->get_model()->insert( $save_cols_n_values, true); |
|
1376 | - if($results){ |
|
1374 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
1375 | + $results = $this->get_model()->insert($save_cols_n_values, true); |
|
1376 | + if ($results) { |
|
1377 | 1377 | //if successful, set the primary key |
1378 | 1378 | //but don't use the normal SET method, because it will check if |
1379 | 1379 | //an item with the same ID exists in the mapper & db, then |
1380 | 1380 | //will find it in the db (because we just added it) and THAT object |
1381 | 1381 | //will get added to the mapper before we can add this one! |
1382 | 1382 | //but if we just avoid using the SET method, all that headache can be avoided |
1383 | - $pk_field_name =self::_get_primary_key_name( get_class($this)); |
|
1383 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
1384 | 1384 | $this->_fields[$pk_field_name] = $results; |
1385 | 1385 | $this->_clear_cached_property($pk_field_name); |
1386 | - $this->get_model()->add_to_entity_map( $this ); |
|
1386 | + $this->get_model()->add_to_entity_map($this); |
|
1387 | 1387 | $this->_update_cached_related_model_objs_fks(); |
1388 | 1388 | } |
1389 | 1389 | } |
1390 | - }else{//PK is NOT auto-increment |
|
1390 | + } else {//PK is NOT auto-increment |
|
1391 | 1391 | //so check if one like it already exists in the db |
1392 | - if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
|
1393 | - if( ! $this->in_entity_map() && WP_DEBUG ){ |
|
1392 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
1393 | + if ( ! $this->in_entity_map() && WP_DEBUG) { |
|
1394 | 1394 | throw new EE_Error( |
1395 | 1395 | sprintf( |
1396 | - __( 'Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso' ), |
|
1396 | + __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso'), |
|
1397 | 1397 | get_class($this), |
1398 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
1399 | - get_class( $this->get_model() ) . '::instance()->get_one_by_ID()', |
|
1398 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
1399 | + get_class($this->get_model()).'::instance()->get_one_by_ID()', |
|
1400 | 1400 | '<br />' |
1401 | 1401 | ) |
1402 | 1402 | ); |
1403 | 1403 | } |
1404 | 1404 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
1405 | - }else{ |
|
1405 | + } else { |
|
1406 | 1406 | $results = $this->get_model()->insert($save_cols_n_values); |
1407 | 1407 | $this->_update_cached_related_model_objs_fks(); |
1408 | 1408 | } |
1409 | 1409 | } |
1410 | - }else{//there is NO primary key |
|
1410 | + } else {//there is NO primary key |
|
1411 | 1411 | $already_in_db = false; |
1412 | - foreach($this->get_model()->unique_indexes() as $index){ |
|
1412 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
1413 | 1413 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
1414 | - if($this->get_model()->exists(array($uniqueness_where_params))){ |
|
1414 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
1415 | 1415 | $already_in_db = true; |
1416 | 1416 | } |
1417 | 1417 | } |
1418 | - if( $already_in_db ){ |
|
1419 | - $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
|
1420 | - $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
|
1421 | - }else{ |
|
1422 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
1418 | + if ($already_in_db) { |
|
1419 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields()); |
|
1420 | + $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
1421 | + } else { |
|
1422 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
1423 | 1423 | } |
1424 | 1424 | } |
1425 | 1425 | //restore the old assumption about values being prepared by the model object |
@@ -1432,7 +1432,7 @@ discard block |
||
1432 | 1432 | * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
1433 | 1433 | * the new ID (or 0 if an error occurred and it wasn't updated) |
1434 | 1434 | */ |
1435 | - do_action( 'AHEE__EE_Base_Class__save__end', $this, $results ); |
|
1435 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
1436 | 1436 | return $results; |
1437 | 1437 | } |
1438 | 1438 | |
@@ -1444,13 +1444,13 @@ discard block |
||
1444 | 1444 | * and we want to let its cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether or not they exist in the DB (if they do, their DB records will be automatically updated) |
1445 | 1445 | * @return void |
1446 | 1446 | */ |
1447 | - protected function _update_cached_related_model_objs_fks(){ |
|
1448 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ){ |
|
1449 | - if( $relation_obj instanceof EE_Has_Many_Relation ){ |
|
1450 | - foreach( $this->get_all_from_cache( $relation_name ) as $related_model_obj_in_cache) { |
|
1451 | - $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( $this->get_model()->get_this_model_name() ); |
|
1452 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID() ); |
|
1453 | - if( $related_model_obj_in_cache->ID() ){ |
|
1447 | + protected function _update_cached_related_model_objs_fks() { |
|
1448 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1449 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
1450 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
1451 | + $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to($this->get_model()->get_this_model_name()); |
|
1452 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
1453 | + if ($related_model_obj_in_cache->ID()) { |
|
1454 | 1454 | $related_model_obj_in_cache->save(); |
1455 | 1455 | } |
1456 | 1456 | } |
@@ -1466,21 +1466,21 @@ discard block |
||
1466 | 1466 | * and this object and properly setup |
1467 | 1467 | * @return int ID of new model object on save; 0 on failure+ |
1468 | 1468 | */ |
1469 | - public function save_new_cached_related_model_objs(){ |
|
1469 | + public function save_new_cached_related_model_objs() { |
|
1470 | 1470 | //make sure this has been saved |
1471 | - if( ! $this->ID()){ |
|
1471 | + if ( ! $this->ID()) { |
|
1472 | 1472 | $id = $this->save(); |
1473 | - }else{ |
|
1473 | + } else { |
|
1474 | 1474 | $id = $this->ID(); |
1475 | 1475 | } |
1476 | 1476 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
1477 | - foreach($this->get_model()->relation_settings() as $relationName => $relationObj){ |
|
1477 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
1478 | 1478 | |
1479 | 1479 | |
1480 | - if($this->_model_relations[$relationName]){ |
|
1480 | + if ($this->_model_relations[$relationName]) { |
|
1481 | 1481 | //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
1482 | 1482 | //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
1483 | - if($relationObj instanceof EE_Belongs_To_Relation){ |
|
1483 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
1484 | 1484 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1485 | 1485 | //but ONLY if it DOES NOT exist in the DB |
1486 | 1486 | /* @var $related_model_obj EE_Base_Class */ |
@@ -1489,8 +1489,8 @@ discard block |
||
1489 | 1489 | $this->_add_relation_to($related_model_obj, $relationName); |
1490 | 1490 | $related_model_obj->save_new_cached_related_model_objs(); |
1491 | 1491 | // } |
1492 | - }else{ |
|
1493 | - foreach($this->_model_relations[$relationName] as $related_model_obj){ |
|
1492 | + } else { |
|
1493 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
1494 | 1494 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1495 | 1495 | //but ONLY if it DOES NOT exist in the DB |
1496 | 1496 | // if( ! $related_model_obj->ID()){ |
@@ -1511,8 +1511,8 @@ discard block |
||
1511 | 1511 | * @return \EEM_Base | \EEM_CPT_Base |
1512 | 1512 | */ |
1513 | 1513 | public function get_model() { |
1514 | - $modelName = self::_get_model_classname( get_class($this) ); |
|
1515 | - return self::_get_model_instance_with_name($modelName, $this->_timezone ); |
|
1514 | + $modelName = self::_get_model_classname(get_class($this)); |
|
1515 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
1516 | 1516 | } |
1517 | 1517 | |
1518 | 1518 | |
@@ -1522,10 +1522,10 @@ discard block |
||
1522 | 1522 | * @param $classname |
1523 | 1523 | * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
1524 | 1524 | */ |
1525 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname){ |
|
1525 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) { |
|
1526 | 1526 | //TODO: will not work for Term_Relationships because they have no PK! |
1527 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
1528 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
1527 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1528 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1529 | 1529 | $id = $props_n_values[$primary_id_ref]; |
1530 | 1530 | return self::_get_model($classname)->get_from_entity_map($id); |
1531 | 1531 | } |
@@ -1542,24 +1542,24 @@ discard block |
||
1542 | 1542 | * @param null $timezone |
1543 | 1543 | * @return mixed (EE_Base_Class|bool) |
1544 | 1544 | */ |
1545 | - protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL ) { |
|
1546 | - if( self::_get_model( $classname )->has_primary_key_field()){ |
|
1547 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
1545 | + protected static function _check_for_object($props_n_values, $classname, $timezone = NULL) { |
|
1546 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
1547 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1548 | 1548 | |
1549 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
1550 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( $props_n_values[$primary_id_ref] ); |
|
1551 | - }else{ |
|
1549 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1550 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID($props_n_values[$primary_id_ref]); |
|
1551 | + } else { |
|
1552 | 1552 | $existing = null; |
1553 | 1553 | } |
1554 | - }elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1554 | + }elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
1555 | 1555 | //no primary key on this model, but there's still a matching item in the DB |
1556 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( self::_get_model($classname, $timezone)->get_index_primary_key_string( $props_n_values ) ); |
|
1557 | - }else{ |
|
1556 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID(self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)); |
|
1557 | + } else { |
|
1558 | 1558 | $existing = null; |
1559 | 1559 | } |
1560 | - if ( $existing ) { |
|
1561 | - foreach ( $props_n_values as $property => $field_value ) { |
|
1562 | - $existing->set( $property, $field_value ); |
|
1560 | + if ($existing) { |
|
1561 | + foreach ($props_n_values as $property => $field_value) { |
|
1562 | + $existing->set($property, $field_value); |
|
1563 | 1563 | } |
1564 | 1564 | return $existing; |
1565 | 1565 | } else { |
@@ -1577,13 +1577,13 @@ discard block |
||
1577 | 1577 | * @throws EE_Error |
1578 | 1578 | * @return EEM_Base |
1579 | 1579 | */ |
1580 | - protected static function _get_model( $classname, $timezone = NULL ){ |
|
1580 | + protected static function _get_model($classname, $timezone = NULL) { |
|
1581 | 1581 | //find model for this class |
1582 | - if( ! $classname ){ |
|
1583 | - throw new EE_Error(sprintf(__("What were you thinking calling _get_model(%s)?? You need to specify the class name", "event_espresso"),$classname)); |
|
1582 | + if ( ! $classname) { |
|
1583 | + throw new EE_Error(sprintf(__("What were you thinking calling _get_model(%s)?? You need to specify the class name", "event_espresso"), $classname)); |
|
1584 | 1584 | } |
1585 | - $modelName=self::_get_model_classname($classname); |
|
1586 | - return self::_get_model_instance_with_name($modelName, $timezone ); |
|
1585 | + $modelName = self::_get_model_classname($classname); |
|
1586 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
1587 | 1587 | } |
1588 | 1588 | |
1589 | 1589 | |
@@ -1594,10 +1594,10 @@ discard block |
||
1594 | 1594 | * @param null $timezone |
1595 | 1595 | * @return EEM_Base |
1596 | 1596 | */ |
1597 | - protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
|
1598 | - $model_classname = str_replace( 'EEM_', '', $model_classname ); |
|
1599 | - $model = EE_Registry::instance()->load_model( $model_classname ); |
|
1600 | - $model->set_timezone( $timezone ); |
|
1597 | + protected static function _get_model_instance_with_name($model_classname, $timezone = NULL) { |
|
1598 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
1599 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
1600 | + $model->set_timezone($timezone); |
|
1601 | 1601 | return $model; |
1602 | 1602 | } |
1603 | 1603 | |
@@ -1609,10 +1609,10 @@ discard block |
||
1609 | 1609 | * @param null $model_name |
1610 | 1610 | * @return string like EEM_Attendee |
1611 | 1611 | */ |
1612 | - private static function _get_model_classname( $model_name = null){ |
|
1613 | - if(strpos($model_name,"EE_")===0){ |
|
1614 | - $model_classname=str_replace("EE_","EEM_",$model_name); |
|
1615 | - }else{ |
|
1612 | + private static function _get_model_classname($model_name = null) { |
|
1613 | + if (strpos($model_name, "EE_") === 0) { |
|
1614 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
1615 | + } else { |
|
1616 | 1616 | $model_classname = "EEM_".$model_name; |
1617 | 1617 | } |
1618 | 1618 | return $model_classname; |
@@ -1626,11 +1626,11 @@ discard block |
||
1626 | 1626 | * @throws EE_Error |
1627 | 1627 | * @return string |
1628 | 1628 | */ |
1629 | - protected static function _get_primary_key_name( $classname = NULL ){ |
|
1630 | - if( ! $classname){ |
|
1631 | - throw new EE_Error(sprintf(__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),$classname)); |
|
1629 | + protected static function _get_primary_key_name($classname = NULL) { |
|
1630 | + if ( ! $classname) { |
|
1631 | + throw new EE_Error(sprintf(__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), $classname)); |
|
1632 | 1632 | } |
1633 | - return self::_get_model( $classname )->get_primary_key_field()->get_name(); |
|
1633 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
1634 | 1634 | } |
1635 | 1635 | |
1636 | 1636 | |
@@ -1642,12 +1642,12 @@ discard block |
||
1642 | 1642 | * Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
1643 | 1643 | * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
1644 | 1644 | */ |
1645 | - public function ID(){ |
|
1645 | + public function ID() { |
|
1646 | 1646 | //now that we know the name of the variable, use a variable variable to get its value and return its |
1647 | - if( $this->get_model()->has_primary_key_field() ) { |
|
1648 | - return $this->_fields[self::_get_primary_key_name( get_class($this) )]; |
|
1649 | - }else{ |
|
1650 | - return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
|
1647 | + if ($this->get_model()->has_primary_key_field()) { |
|
1648 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
1649 | + } else { |
|
1650 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
1651 | 1651 | } |
1652 | 1652 | } |
1653 | 1653 | |
@@ -1665,38 +1665,38 @@ discard block |
||
1665 | 1665 | * @throws EE_Error |
1666 | 1666 | * @return EE_Base_Class the object the relation was added to |
1667 | 1667 | */ |
1668 | - public function _add_relation_to( $otherObjectModelObjectOrID,$relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL ){ |
|
1668 | + public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL) { |
|
1669 | 1669 | //if this thing exists in the DB, save the relation to the DB |
1670 | - if( $this->ID() ){ |
|
1671 | - $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
|
1670 | + if ($this->ID()) { |
|
1671 | + $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values); |
|
1672 | 1672 | //clear cache so future get_many_related and get_first_related() return new results. |
1673 | - $this->clear_cache( $relationName, $otherObject, TRUE ); |
|
1674 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1675 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1673 | + $this->clear_cache($relationName, $otherObject, TRUE); |
|
1674 | + if ($otherObject instanceof EE_Base_Class) { |
|
1675 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1676 | 1676 | } |
1677 | 1677 | } else { |
1678 | 1678 | //this thing doesn't exist in the DB, so just cache it |
1679 | - if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
|
1680 | - throw new EE_Error( sprintf( |
|
1681 | - __( 'Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso' ), |
|
1679 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
1680 | + throw new EE_Error(sprintf( |
|
1681 | + __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'), |
|
1682 | 1682 | $otherObjectModelObjectOrID, |
1683 | - get_class( $this ) |
|
1683 | + get_class($this) |
|
1684 | 1684 | )); |
1685 | 1685 | } else { |
1686 | 1686 | $otherObject = $otherObjectModelObjectOrID; |
1687 | 1687 | } |
1688 | - $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
|
1688 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
1689 | 1689 | } |
1690 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1690 | + if ($otherObject instanceof EE_Base_Class) { |
|
1691 | 1691 | //fix the reciprocal relation too |
1692 | - if( $otherObject->ID() ) { |
|
1692 | + if ($otherObject->ID()) { |
|
1693 | 1693 | //its saved so assumed relations exist in the DB, so we can just |
1694 | 1694 | //clear the cache so future queries use the updated info in the DB |
1695 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
1695 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
1696 | 1696 | } else { |
1697 | 1697 | |
1698 | 1698 | //it's not saved, so it caches relations like this |
1699 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
1699 | + $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
1700 | 1700 | } |
1701 | 1701 | } |
1702 | 1702 | return $otherObject; |
@@ -1719,17 +1719,17 @@ discard block |
||
1719 | 1719 | * Also remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is created in the join table. |
1720 | 1720 | * @return EE_Base_Class the relation was removed from |
1721 | 1721 | */ |
1722 | - public function _remove_relation_to($otherObjectModelObjectOrID,$relationName, $where_query = array() ){ |
|
1723 | - if ( $this->ID() ) { |
|
1722 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) { |
|
1723 | + if ($this->ID()) { |
|
1724 | 1724 | //if this exists in the DB, save the relation change to the DB too |
1725 | - $otherObject = $this->get_model()->remove_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $where_query ); |
|
1726 | - $this->clear_cache( $relationName, $otherObject ); |
|
1725 | + $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
1726 | + $this->clear_cache($relationName, $otherObject); |
|
1727 | 1727 | } else { |
1728 | 1728 | //this doesn't exist in the DB, just remove it from the cache |
1729 | - $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
|
1729 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
1730 | 1730 | } |
1731 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1732 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1731 | + if ($otherObject instanceof EE_Base_Class) { |
|
1732 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1733 | 1733 | } |
1734 | 1734 | return $otherObject; |
1735 | 1735 | } |
@@ -1740,18 +1740,18 @@ discard block |
||
1740 | 1740 | * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
1741 | 1741 | * @return EE_Base_Class |
1742 | 1742 | */ |
1743 | - public function _remove_relations($relationName,$where_query_params = array()){ |
|
1744 | - if ( $this->ID() ) { |
|
1743 | + public function _remove_relations($relationName, $where_query_params = array()) { |
|
1744 | + if ($this->ID()) { |
|
1745 | 1745 | //if this exists in the DB, save the relation change to the DB too |
1746 | - $otherObjects = $this->get_model()->remove_relations( $this, $relationName, $where_query_params ); |
|
1747 | - $this->clear_cache( $relationName, null, true ); |
|
1746 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
1747 | + $this->clear_cache($relationName, null, true); |
|
1748 | 1748 | } else { |
1749 | 1749 | //this doesn't exist in the DB, just remove it from the cache |
1750 | - $otherObjects = $this->clear_cache( $relationName, null, true ); |
|
1750 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
1751 | 1751 | } |
1752 | - if( is_array( $otherObjects ) ) { |
|
1753 | - foreach ( $otherObjects as $otherObject ) { |
|
1754 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1752 | + if (is_array($otherObjects)) { |
|
1753 | + foreach ($otherObjects as $otherObject) { |
|
1754 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1755 | 1755 | } |
1756 | 1756 | } |
1757 | 1757 | return $otherObjects; |
@@ -1769,26 +1769,26 @@ discard block |
||
1769 | 1769 | * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
1770 | 1770 | * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs |
1771 | 1771 | */ |
1772 | - public function get_many_related($relationName,$query_params = array()){ |
|
1773 | - if($this->ID()){//this exists in the DB, so get the related things from either the cache or the DB |
|
1772 | + public function get_many_related($relationName, $query_params = array()) { |
|
1773 | + if ($this->ID()) {//this exists in the DB, so get the related things from either the cache or the DB |
|
1774 | 1774 | //if there are query parameters, forget about caching the related model objects. |
1775 | - if( $query_params ){ |
|
1775 | + if ($query_params) { |
|
1776 | 1776 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1777 | - }else{ |
|
1777 | + } else { |
|
1778 | 1778 | //did we already cache the result of this query? |
1779 | 1779 | $cached_results = $this->get_all_from_cache($relationName); |
1780 | - if ( ! $cached_results ){ |
|
1780 | + if ( ! $cached_results) { |
|
1781 | 1781 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1782 | 1782 | //if no query parameters were passed, then we got all the related model objects |
1783 | 1783 | //for that relation. We can cache them then. |
1784 | - foreach($related_model_objects as $related_model_object){ |
|
1784 | + foreach ($related_model_objects as $related_model_object) { |
|
1785 | 1785 | $this->cache($relationName, $related_model_object); |
1786 | 1786 | } |
1787 | - }else{ |
|
1787 | + } else { |
|
1788 | 1788 | $related_model_objects = $cached_results; |
1789 | 1789 | } |
1790 | 1790 | } |
1791 | - }else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1791 | + } else {//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1792 | 1792 | $related_model_objects = $this->get_all_from_cache($relationName); |
1793 | 1793 | } |
1794 | 1794 | return $related_model_objects; |
@@ -1805,8 +1805,8 @@ discard block |
||
1805 | 1805 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
1806 | 1806 | * @return int |
1807 | 1807 | */ |
1808 | - public function count_related($relation_name, $query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1809 | - return $this->get_model()->count_related($this,$relation_name,$query_params,$field_to_count,$distinct); |
|
1808 | + public function count_related($relation_name, $query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1809 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
1810 | 1810 | } |
1811 | 1811 | |
1812 | 1812 | |
@@ -1820,7 +1820,7 @@ discard block |
||
1820 | 1820 | * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
1821 | 1821 | * @return int |
1822 | 1822 | */ |
1823 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null){ |
|
1823 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) { |
|
1824 | 1824 | return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
1825 | 1825 | } |
1826 | 1826 | |
@@ -1832,34 +1832,34 @@ discard block |
||
1832 | 1832 | * @param array $query_params like EEM_Base::get_all |
1833 | 1833 | * @return EE_Base_Class (not an array, a single object) |
1834 | 1834 | */ |
1835 | - public function get_first_related($relationName,$query_params = array()){ |
|
1836 | - if($this->ID()){//this exists in the DB, get from the cache OR the DB |
|
1835 | + public function get_first_related($relationName, $query_params = array()) { |
|
1836 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
1837 | 1837 | |
1838 | 1838 | //if they've provided some query parameters, don't bother trying to cache the result |
1839 | 1839 | //also make sure we're not caching the result of get_first_related |
1840 | 1840 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
1841 | - if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
1842 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1843 | - }else{ |
|
1841 | + if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
1842 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1843 | + } else { |
|
1844 | 1844 | //first, check if we've already cached the result of this query |
1845 | 1845 | $cached_result = $this->get_one_from_cache($relationName); |
1846 | - if ( ! $cached_result ){ |
|
1846 | + if ( ! $cached_result) { |
|
1847 | 1847 | |
1848 | 1848 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1849 | - $this->cache($relationName,$related_model_object); |
|
1850 | - }else{ |
|
1849 | + $this->cache($relationName, $related_model_object); |
|
1850 | + } else { |
|
1851 | 1851 | $related_model_object = $cached_result; |
1852 | 1852 | } |
1853 | 1853 | } |
1854 | - }else{ |
|
1854 | + } else { |
|
1855 | 1855 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
1856 | - if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
1857 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1858 | - }else{ |
|
1856 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
1857 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1858 | + } else { |
|
1859 | 1859 | $related_model_object = null; |
1860 | 1860 | } |
1861 | 1861 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
1862 | - if( ! $related_model_object){ |
|
1862 | + if ( ! $related_model_object) { |
|
1863 | 1863 | $related_model_object = $this->get_one_from_cache($relationName); |
1864 | 1864 | } |
1865 | 1865 | |
@@ -1878,12 +1878,12 @@ discard block |
||
1878 | 1878 | * @param array $query_params like EEM_Base::get_all's |
1879 | 1879 | * @return int how many deleted |
1880 | 1880 | */ |
1881 | - public function delete_related($relationName,$query_params = array()){ |
|
1882 | - if($this->ID()){ |
|
1883 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
1884 | - }else{ |
|
1881 | + public function delete_related($relationName, $query_params = array()) { |
|
1882 | + if ($this->ID()) { |
|
1883 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
1884 | + } else { |
|
1885 | 1885 | $count = count($this->get_all_from_cache($relationName)); |
1886 | - $this->clear_cache($relationName,NULL,TRUE); |
|
1886 | + $this->clear_cache($relationName, NULL, TRUE); |
|
1887 | 1887 | } |
1888 | 1888 | return $count; |
1889 | 1889 | } |
@@ -1898,13 +1898,13 @@ discard block |
||
1898 | 1898 | * @param array $query_params like EEM_Base::get_all's |
1899 | 1899 | * @return int how many deleted (including those soft deleted) |
1900 | 1900 | */ |
1901 | - public function delete_related_permanently($relationName,$query_params = array()){ |
|
1902 | - if($this->ID()){ |
|
1903 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
1904 | - }else{ |
|
1901 | + public function delete_related_permanently($relationName, $query_params = array()) { |
|
1902 | + if ($this->ID()) { |
|
1903 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
1904 | + } else { |
|
1905 | 1905 | $count = count($this->get_all_from_cache($relationName)); |
1906 | 1906 | } |
1907 | - $this->clear_cache($relationName,NULL,TRUE); |
|
1907 | + $this->clear_cache($relationName, NULL, TRUE); |
|
1908 | 1908 | return $count; |
1909 | 1909 | } |
1910 | 1910 | |
@@ -1920,7 +1920,7 @@ discard block |
||
1920 | 1920 | * @param string $field_name property to check |
1921 | 1921 | * @return bool TRUE if existing,FALSE if not. |
1922 | 1922 | */ |
1923 | - public function is_set( $field_name ) { |
|
1923 | + public function is_set($field_name) { |
|
1924 | 1924 | return isset($this->_fields[$field_name]); |
1925 | 1925 | } |
1926 | 1926 | |
@@ -1932,12 +1932,12 @@ discard block |
||
1932 | 1932 | * @throws EE_Error |
1933 | 1933 | * @return bool TRUE if existing, throw EE_Error if not. |
1934 | 1934 | */ |
1935 | - protected function _property_exists( $properties ) { |
|
1935 | + protected function _property_exists($properties) { |
|
1936 | 1936 | |
1937 | - foreach ( (array) $properties as $property_name ) { |
|
1937 | + foreach ((array) $properties as $property_name) { |
|
1938 | 1938 | //first make sure this property exists |
1939 | - if ( ! $this->_fields[ $property_name ] ) |
|
1940 | - throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1939 | + if ( ! $this->_fields[$property_name]) |
|
1940 | + throw new EE_Error(sprintf(__('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name)); |
|
1941 | 1941 | } |
1942 | 1942 | |
1943 | 1943 | return TRUE; |
@@ -1954,7 +1954,7 @@ discard block |
||
1954 | 1954 | $fields = $this->get_model()->field_settings(FALSE); |
1955 | 1955 | $properties = array(); |
1956 | 1956 | //remove prepended underscore |
1957 | - foreach ( $fields as $field_name => $settings ) { |
|
1957 | + foreach ($fields as $field_name => $settings) { |
|
1958 | 1958 | $properties[$field_name] = $this->get($field_name); |
1959 | 1959 | } |
1960 | 1960 | return $properties; |
@@ -1984,14 +1984,14 @@ discard block |
||
1984 | 1984 | * @throws EE_Error |
1985 | 1985 | * @return mixed whatever the plugin which calls add_filter decides |
1986 | 1986 | */ |
1987 | - public function __call($methodName,$args){ |
|
1988 | - $className=get_class($this); |
|
1989 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
1990 | - if(!has_filter($tagName)){ |
|
1991 | - throw new EE_Error(sprintf(__("Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}","event_espresso"), |
|
1992 | - $methodName,$className,$tagName)); |
|
1987 | + public function __call($methodName, $args) { |
|
1988 | + $className = get_class($this); |
|
1989 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
1990 | + if ( ! has_filter($tagName)) { |
|
1991 | + throw new EE_Error(sprintf(__("Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}", "event_espresso"), |
|
1992 | + $methodName, $className, $tagName)); |
|
1993 | 1993 | } |
1994 | - return apply_filters($tagName,null,$this,$args); |
|
1994 | + return apply_filters($tagName, null, $this, $args); |
|
1995 | 1995 | } |
1996 | 1996 | |
1997 | 1997 | |
@@ -2006,22 +2006,22 @@ discard block |
||
2006 | 2006 | * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
2007 | 2007 | * NOTE: if the values haven't changed, returns 0 |
2008 | 2008 | */ |
2009 | - public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL){ |
|
2010 | - $query_params = array(array( |
|
2009 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL) { |
|
2010 | + $query_params = array(array( |
|
2011 | 2011 | 'EXM_key'=>$meta_key, |
2012 | 2012 | 'OBJ_ID'=>$this->ID(), |
2013 | 2013 | 'EXM_type'=>$this->get_model()->get_this_model_name())); |
2014 | - if($previous_value !== NULL){ |
|
2014 | + if ($previous_value !== NULL) { |
|
2015 | 2015 | $query_params[0]['EXM_value'] = $meta_value; |
2016 | 2016 | } |
2017 | 2017 | $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
2018 | - if( ! $existing_rows_like_that){ |
|
2018 | + if ( ! $existing_rows_like_that) { |
|
2019 | 2019 | return $this->add_extra_meta($meta_key, $meta_value); |
2020 | - }else{ |
|
2021 | - foreach( $existing_rows_like_that as $existing_row){ |
|
2022 | - $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
|
2020 | + } else { |
|
2021 | + foreach ($existing_rows_like_that as $existing_row) { |
|
2022 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
2023 | 2023 | } |
2024 | - return count( $existing_rows_like_that ); |
|
2024 | + return count($existing_rows_like_that); |
|
2025 | 2025 | } |
2026 | 2026 | } |
2027 | 2027 | |
@@ -2034,10 +2034,10 @@ discard block |
||
2034 | 2034 | * @param boolean $unique |
2035 | 2035 | * @return boolean |
2036 | 2036 | */ |
2037 | - public function add_extra_meta($meta_key,$meta_value,$unique = false){ |
|
2038 | - if($unique){ |
|
2039 | - $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(array(array('EXM_key'=>$meta_key,'OBJ_ID'=>$this->ID(),'EXM_type'=>$this->_get_model_classname(get_class($this))))); |
|
2040 | - if($existing_extra_meta){ |
|
2037 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) { |
|
2038 | + if ($unique) { |
|
2039 | + $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(array(array('EXM_key'=>$meta_key, 'OBJ_ID'=>$this->ID(), 'EXM_type'=>$this->_get_model_classname(get_class($this))))); |
|
2040 | + if ($existing_extra_meta) { |
|
2041 | 2041 | return false; |
2042 | 2042 | } |
2043 | 2043 | } |
@@ -2057,12 +2057,12 @@ discard block |
||
2057 | 2057 | * @param string $meta_value |
2058 | 2058 | * @return int number of extra meta rows deleted |
2059 | 2059 | */ |
2060 | - public function delete_extra_meta($meta_key,$meta_value = NULL){ |
|
2061 | - $query_params = array(array( |
|
2060 | + public function delete_extra_meta($meta_key, $meta_value = NULL) { |
|
2061 | + $query_params = array(array( |
|
2062 | 2062 | 'EXM_key'=>$meta_key, |
2063 | 2063 | 'OBJ_ID'=>$this->ID(), |
2064 | 2064 | 'EXM_type'=>$this->get_model()->get_this_model_name())); |
2065 | - if($meta_value !== NULL){ |
|
2065 | + if ($meta_value !== NULL) { |
|
2066 | 2066 | $query_params[0]['EXM_value'] = $meta_value; |
2067 | 2067 | } |
2068 | 2068 | $count_deleted = EEM_Extra_Meta::instance()->delete($query_params); |
@@ -2078,25 +2078,25 @@ discard block |
||
2078 | 2078 | * @param mixed $default if we don't find anything, what should we return? |
2079 | 2079 | * @return mixed single value if $single; array if ! $single |
2080 | 2080 | */ |
2081 | - public function get_extra_meta($meta_key,$single = FALSE,$default = NULL){ |
|
2082 | - if($single){ |
|
2083 | - $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
2084 | - if ( $result instanceof EE_Extra_Meta ){ |
|
2081 | + public function get_extra_meta($meta_key, $single = FALSE, $default = NULL) { |
|
2082 | + if ($single) { |
|
2083 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
2084 | + if ($result instanceof EE_Extra_Meta) { |
|
2085 | 2085 | return $result->value(); |
2086 | - }else{ |
|
2086 | + } else { |
|
2087 | 2087 | return $default; |
2088 | 2088 | } |
2089 | - }else{ |
|
2090 | - $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
2091 | - if($results){ |
|
2089 | + } else { |
|
2090 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
2091 | + if ($results) { |
|
2092 | 2092 | $values = array(); |
2093 | - foreach($results as $result){ |
|
2094 | - if ( $result instanceof EE_Extra_Meta ){ |
|
2093 | + foreach ($results as $result) { |
|
2094 | + if ($result instanceof EE_Extra_Meta) { |
|
2095 | 2095 | $values[$result->ID()] = $result->value(); |
2096 | 2096 | } |
2097 | 2097 | } |
2098 | 2098 | return $values; |
2099 | - }else{ |
|
2099 | + } else { |
|
2100 | 2100 | return $default; |
2101 | 2101 | } |
2102 | 2102 | } |
@@ -2113,20 +2113,20 @@ discard block |
||
2113 | 2113 | * @param boolean $one_of_each_key |
2114 | 2114 | * @return array |
2115 | 2115 | */ |
2116 | - public function all_extra_meta_array($one_of_each_key = true){ |
|
2116 | + public function all_extra_meta_array($one_of_each_key = true) { |
|
2117 | 2117 | $return_array = array(); |
2118 | - if($one_of_each_key){ |
|
2118 | + if ($one_of_each_key) { |
|
2119 | 2119 | $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by'=>'EXM_key')); |
2120 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
2121 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
2120 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2121 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2122 | 2122 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
2123 | 2123 | } |
2124 | 2124 | } |
2125 | - }else{ |
|
2125 | + } else { |
|
2126 | 2126 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
2127 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
2128 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
2129 | - if( ! isset($return_array[$extra_meta_obj->key()])){ |
|
2127 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2128 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2129 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
2130 | 2130 | $return_array[$extra_meta_obj->key()] = array(); |
2131 | 2131 | } |
2132 | 2132 | $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
@@ -2139,19 +2139,19 @@ discard block |
||
2139 | 2139 | * Gets a pretty nice displayable nice for this model object. Often overridden |
2140 | 2140 | * @return string |
2141 | 2141 | */ |
2142 | - public function name(){ |
|
2142 | + public function name() { |
|
2143 | 2143 | //find a field that's not a text field |
2144 | 2144 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
2145 | - if($field_we_can_use){ |
|
2145 | + if ($field_we_can_use) { |
|
2146 | 2146 | return $this->get($field_we_can_use->get_name()); |
2147 | - }else{ |
|
2147 | + } else { |
|
2148 | 2148 | $first_few_properties = $this->model_field_array(); |
2149 | - $first_few_properties = array_slice($first_few_properties,0,3); |
|
2149 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
2150 | 2150 | $name_parts = array(); |
2151 | - foreach( $first_few_properties as $name=> $value ){ |
|
2151 | + foreach ($first_few_properties as $name=> $value) { |
|
2152 | 2152 | $name_parts[] = "$name:$value"; |
2153 | 2153 | } |
2154 | - return implode(",",$name_parts); |
|
2154 | + return implode(",", $name_parts); |
|
2155 | 2155 | } |
2156 | 2156 | } |
2157 | 2157 | |
@@ -2160,11 +2160,11 @@ discard block |
||
2160 | 2160 | * Checks if this model object has been proven to already be in the entity map |
2161 | 2161 | * @return boolean |
2162 | 2162 | */ |
2163 | - public function in_entity_map(){ |
|
2164 | - if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
|
2163 | + public function in_entity_map() { |
|
2164 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
2165 | 2165 | //well, if we looked, did we find it in the entity map? |
2166 | 2166 | return TRUE; |
2167 | - }else{ |
|
2167 | + } else { |
|
2168 | 2168 | return FALSE; |
2169 | 2169 | } |
2170 | 2170 | } |
@@ -2175,21 +2175,21 @@ discard block |
||
2175 | 2175 | * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
2176 | 2176 | * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
2177 | 2177 | */ |
2178 | - public function refresh_from_db(){ |
|
2179 | - if( $this->ID() && $this->in_entity_map() ){ |
|
2180 | - $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
|
2181 | - }else{ |
|
2178 | + public function refresh_from_db() { |
|
2179 | + if ($this->ID() && $this->in_entity_map()) { |
|
2180 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
2181 | + } else { |
|
2182 | 2182 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
2183 | 2183 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
2184 | 2184 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
2185 | 2185 | //absolutely nothing in it for this ID |
2186 | - if( WP_DEBUG ) { |
|
2186 | + if (WP_DEBUG) { |
|
2187 | 2187 | throw new EE_Error( |
2188 | 2188 | sprintf( |
2189 | - __( 'Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso' ), |
|
2189 | + __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso'), |
|
2190 | 2190 | $this->ID(), |
2191 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
2192 | - get_class( $this->get_model() ) . '::instance()->refresh_entity_map()' |
|
2191 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
2192 | + get_class($this->get_model()).'::instance()->refresh_entity_map()' |
|
2193 | 2193 | ) |
2194 | 2194 | ); |
2195 | 2195 | } |
@@ -2201,8 +2201,8 @@ discard block |
||
2201 | 2201 | * (probably a bad assumption they have made, oh well) |
2202 | 2202 | * @return string |
2203 | 2203 | */ |
2204 | - public function __toString(){ |
|
2205 | - return sprintf( '%s (%s)', $this->name(), $this->ID() ); |
|
2204 | + public function __toString() { |
|
2205 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
2206 | 2206 | } |
2207 | 2207 | |
2208 | 2208 | /** |
@@ -2234,16 +2234,16 @@ discard block |
||
2234 | 2234 | * @return array |
2235 | 2235 | */ |
2236 | 2236 | public function __sleep() { |
2237 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
2238 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
2239 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
2240 | - if( $this->get_one_from_cache( $relation_name ) instanceof $classname && |
|
2241 | - $this->get_one_from_cache( $relation_name )->ID() ) { |
|
2242 | - $this->clear_cache( $relation_name, $this->get_one_from_cache( $relation_name )->ID() ); |
|
2237 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
2238 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
2239 | + $classname = 'EE_'.$this->get_model()->get_this_model_name(); |
|
2240 | + if ($this->get_one_from_cache($relation_name) instanceof $classname && |
|
2241 | + $this->get_one_from_cache($relation_name)->ID()) { |
|
2242 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
2243 | 2243 | } |
2244 | 2244 | } |
2245 | 2245 | } |
2246 | - return array_keys( get_object_vars( $this ) ); |
|
2246 | + return array_keys(get_object_vars($this)); |
|
2247 | 2247 | } |
2248 | 2248 | |
2249 | 2249 |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
3 | 5 | /** |
4 | 6 | * |
@@ -170,7 +172,7 @@ discard block |
||
170 | 172 | foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
171 | 173 | if($relation_obj instanceof EE_Belongs_To_Relation){ |
172 | 174 | $this->_model_relations[$relation_name] = NULL; |
173 | - }else{ |
|
175 | + } else{ |
|
174 | 176 | $this->_model_relations[$relation_name] = array(); |
175 | 177 | } |
176 | 178 | } |
@@ -215,7 +217,7 @@ discard block |
||
215 | 217 | if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
216 | 218 | $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
217 | 219 | return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
218 | - }else{ |
|
220 | + } else{ |
|
219 | 221 | return NULL; |
220 | 222 | } |
221 | 223 | } |
@@ -264,7 +266,7 @@ discard block |
||
264 | 266 | empty( $this->_fields[$field_name] ) ? $this->set( $field_name, time() ) : $this->set( $field_name, $this->_fields[$field_name] ); |
265 | 267 | } |
266 | 268 | |
267 | - }else{ |
|
269 | + } else{ |
|
268 | 270 | $this->_fields[$field_name] = $holder_of_value; |
269 | 271 | } |
270 | 272 | |
@@ -292,7 +294,7 @@ discard block |
||
292 | 294 | } |
293 | 295 | //let's unset any cache for this field_name from the $_cached_properties property. |
294 | 296 | $this->_clear_cached_property( $field_name ); |
295 | - }else{ |
|
297 | + } else{ |
|
296 | 298 | throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name ) ); |
297 | 299 | } |
298 | 300 | |
@@ -588,8 +590,9 @@ discard block |
||
588 | 590 | * @return void |
589 | 591 | */ |
590 | 592 | protected function _clear_cached_property( $property_name ) { |
591 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) |
|
592 | - unset( $this->_cached_properties[ $property_name ] ); |
|
593 | + if ( isset( $this->_cached_properties[ $property_name ] ) ) { |
|
594 | + unset( $this->_cached_properties[ $property_name ] ); |
|
595 | + } |
|
593 | 596 | } |
594 | 597 | |
595 | 598 | |
@@ -629,10 +632,10 @@ discard block |
||
629 | 632 | if($clear_all){ |
630 | 633 | $obj_removed = true; |
631 | 634 | $this->_model_relations[$relationName] = null; |
632 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
635 | + } elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
633 | 636 | $obj_removed = $this->_model_relations[$relationName]; |
634 | 637 | $this->_model_relations[$relationName] = null; |
635 | - }else{ |
|
638 | + } else{ |
|
636 | 639 | if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
637 | 640 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
638 | 641 | if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
@@ -646,20 +649,20 @@ discard block |
||
646 | 649 | } |
647 | 650 | if($index_found_at){ |
648 | 651 | $index_in_cache = $index_found_at; |
649 | - }else{ |
|
652 | + } else{ |
|
650 | 653 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
651 | 654 | //if it wasn't in it to begin with. So we're done |
652 | 655 | return $object_to_remove_or_index_into_array; |
653 | 656 | } |
654 | 657 | } |
655 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
658 | + } elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
656 | 659 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
657 | 660 | foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
658 | 661 | if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
659 | 662 | $index_in_cache = $index; |
660 | 663 | } |
661 | 664 | } |
662 | - }else{ |
|
665 | + } else{ |
|
663 | 666 | $index_in_cache = $object_to_remove_or_index_into_array; |
664 | 667 | } |
665 | 668 | //supposedly we've found it. But it could just be that the client code |
@@ -668,7 +671,7 @@ discard block |
||
668 | 671 | isset( $this->_model_relations[$relationName][$index_in_cache])){ |
669 | 672 | $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
670 | 673 | unset($this->_model_relations[$relationName][$index_in_cache]); |
671 | - }else{ |
|
674 | + } else{ |
|
672 | 675 | //that thing was never cached anyways. |
673 | 676 | $obj_removed = NULL; |
674 | 677 | } |
@@ -724,7 +727,7 @@ discard block |
||
724 | 727 | $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
725 | 728 | if(is_array($cached_array_or_object)){ |
726 | 729 | return array_shift($cached_array_or_object); |
727 | - }else{ |
|
730 | + } else{ |
|
728 | 731 | return $cached_array_or_object; |
729 | 732 | } |
730 | 733 | } |
@@ -743,10 +746,10 @@ discard block |
||
743 | 746 | $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
744 | 747 | if(is_array($cached_array_or_object)){ |
745 | 748 | $objects = $cached_array_or_object; |
746 | - }elseif($cached_array_or_object){ |
|
749 | + } elseif($cached_array_or_object){ |
|
747 | 750 | //if the result is not an array, but exists, make it an array |
748 | 751 | $objects = array($cached_array_or_object); |
749 | - }else{ |
|
752 | + } else{ |
|
750 | 753 | //if nothing was found, return an empty array |
751 | 754 | $objects = array(); |
752 | 755 | } |
@@ -761,7 +764,7 @@ discard block |
||
761 | 764 | if( $model_object->ID() ){ |
762 | 765 | $model->add_to_entity_map( $model_object ); |
763 | 766 | } |
764 | - }else{ |
|
767 | + } else{ |
|
765 | 768 | throw new EE_Error( sprintf( __( 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso' ), $relationName, gettype( $model_object ))); |
766 | 769 | } |
767 | 770 | } |
@@ -886,10 +889,10 @@ discard block |
||
886 | 889 | if( $field_obj->is_nullable()){ |
887 | 890 | //if the field allows nulls, then let it be null |
888 | 891 | $field_value = NULL; |
889 | - }else{ |
|
892 | + } else{ |
|
890 | 893 | $field_value = $field_obj->get_default_value(); |
891 | 894 | } |
892 | - }else{ |
|
895 | + } else{ |
|
893 | 896 | $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
894 | 897 | } |
895 | 898 | $this->_fields[$field_name] = $field_value; |
@@ -1009,15 +1012,17 @@ discard block |
||
1009 | 1012 | $this->_tm_frmt = $in_tm_frmt; |
1010 | 1013 | } |
1011 | 1014 | |
1012 | - if ( $echo ) |
|
1013 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
1014 | - else |
|
1015 | - $field->set_date_format( $in_dt_frmt ); |
|
1015 | + if ( $echo ) { |
|
1016 | + $field->set_pretty_date_format( $in_dt_frmt ); |
|
1017 | + } else { |
|
1018 | + $field->set_date_format( $in_dt_frmt ); |
|
1019 | + } |
|
1016 | 1020 | |
1017 | - if ( $echo ) |
|
1018 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
1019 | - else |
|
1020 | - $field->set_time_format( $in_tm_frmt ); |
|
1021 | + if ( $echo ) { |
|
1022 | + $field->set_pretty_time_format( $in_tm_frmt ); |
|
1023 | + } else { |
|
1024 | + $field->set_time_format( $in_tm_frmt ); |
|
1025 | + } |
|
1021 | 1026 | |
1022 | 1027 | //set timezone in field object |
1023 | 1028 | $field->set_timezone( $this->_timezone ); |
@@ -1240,8 +1245,9 @@ discard block |
||
1240 | 1245 | EE_Registry::instance()->load_helper('DTT_Helper'); |
1241 | 1246 | $timezone = EEH_DTT_Helper::get_timezone(); |
1242 | 1247 | |
1243 | - if ( $timezone == $this->_timezone ) |
|
1244 | - return ''; |
|
1248 | + if ( $timezone == $this->_timezone ) { |
|
1249 | + return ''; |
|
1250 | + } |
|
1245 | 1251 | |
1246 | 1252 | $original_timezone = $this->_timezone; |
1247 | 1253 | $this->set_timezone( $timezone ); |
@@ -1249,8 +1255,9 @@ discard block |
||
1249 | 1255 | $fn = (array) $field_name; |
1250 | 1256 | $args = array_merge( $fn, (array) $args ); |
1251 | 1257 | |
1252 | - if ( !method_exists( $this, $callback ) ) |
|
1253 | - throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1258 | + if ( !method_exists( $this, $callback ) ) { |
|
1259 | + throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1260 | + } |
|
1254 | 1261 | $args = (array) $args; |
1255 | 1262 | $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
1256 | 1263 | |
@@ -1294,7 +1301,7 @@ discard block |
||
1294 | 1301 | if($model instanceof EEM_Soft_Delete_Base){ |
1295 | 1302 | $result=$model->delete_permanently_by_ID($this->ID()); |
1296 | 1303 | $this->refresh_cache_of_related_objects(); |
1297 | - }else{ |
|
1304 | + } else{ |
|
1298 | 1305 | $result = $this->delete(); |
1299 | 1306 | } |
1300 | 1307 | return $result ? true : false; |
@@ -1387,7 +1394,7 @@ discard block |
||
1387 | 1394 | $this->_update_cached_related_model_objs_fks(); |
1388 | 1395 | } |
1389 | 1396 | } |
1390 | - }else{//PK is NOT auto-increment |
|
1397 | + } else{//PK is NOT auto-increment |
|
1391 | 1398 | //so check if one like it already exists in the db |
1392 | 1399 | if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
1393 | 1400 | if( ! $this->in_entity_map() && WP_DEBUG ){ |
@@ -1402,12 +1409,12 @@ discard block |
||
1402 | 1409 | ); |
1403 | 1410 | } |
1404 | 1411 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
1405 | - }else{ |
|
1412 | + } else{ |
|
1406 | 1413 | $results = $this->get_model()->insert($save_cols_n_values); |
1407 | 1414 | $this->_update_cached_related_model_objs_fks(); |
1408 | 1415 | } |
1409 | 1416 | } |
1410 | - }else{//there is NO primary key |
|
1417 | + } else{//there is NO primary key |
|
1411 | 1418 | $already_in_db = false; |
1412 | 1419 | foreach($this->get_model()->unique_indexes() as $index){ |
1413 | 1420 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
@@ -1418,7 +1425,7 @@ discard block |
||
1418 | 1425 | if( $already_in_db ){ |
1419 | 1426 | $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
1420 | 1427 | $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
1421 | - }else{ |
|
1428 | + } else{ |
|
1422 | 1429 | $results = $this->get_model()->insert( $save_cols_n_values ); |
1423 | 1430 | } |
1424 | 1431 | } |
@@ -1470,7 +1477,7 @@ discard block |
||
1470 | 1477 | //make sure this has been saved |
1471 | 1478 | if( ! $this->ID()){ |
1472 | 1479 | $id = $this->save(); |
1473 | - }else{ |
|
1480 | + } else{ |
|
1474 | 1481 | $id = $this->ID(); |
1475 | 1482 | } |
1476 | 1483 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
@@ -1489,7 +1496,7 @@ discard block |
||
1489 | 1496 | $this->_add_relation_to($related_model_obj, $relationName); |
1490 | 1497 | $related_model_obj->save_new_cached_related_model_objs(); |
1491 | 1498 | // } |
1492 | - }else{ |
|
1499 | + } else{ |
|
1493 | 1500 | foreach($this->_model_relations[$relationName] as $related_model_obj){ |
1494 | 1501 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1495 | 1502 | //but ONLY if it DOES NOT exist in the DB |
@@ -1548,13 +1555,13 @@ discard block |
||
1548 | 1555 | |
1549 | 1556 | if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
1550 | 1557 | $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( $props_n_values[$primary_id_ref] ); |
1551 | - }else{ |
|
1558 | + } else{ |
|
1552 | 1559 | $existing = null; |
1553 | 1560 | } |
1554 | - }elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1561 | + } elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1555 | 1562 | //no primary key on this model, but there's still a matching item in the DB |
1556 | 1563 | $existing = self::_get_model($classname, $timezone)->get_one_by_ID( self::_get_model($classname, $timezone)->get_index_primary_key_string( $props_n_values ) ); |
1557 | - }else{ |
|
1564 | + } else{ |
|
1558 | 1565 | $existing = null; |
1559 | 1566 | } |
1560 | 1567 | if ( $existing ) { |
@@ -1612,7 +1619,7 @@ discard block |
||
1612 | 1619 | private static function _get_model_classname( $model_name = null){ |
1613 | 1620 | if(strpos($model_name,"EE_")===0){ |
1614 | 1621 | $model_classname=str_replace("EE_","EEM_",$model_name); |
1615 | - }else{ |
|
1622 | + } else{ |
|
1616 | 1623 | $model_classname = "EEM_".$model_name; |
1617 | 1624 | } |
1618 | 1625 | return $model_classname; |
@@ -1646,7 +1653,7 @@ discard block |
||
1646 | 1653 | //now that we know the name of the variable, use a variable variable to get its value and return its |
1647 | 1654 | if( $this->get_model()->has_primary_key_field() ) { |
1648 | 1655 | return $this->_fields[self::_get_primary_key_name( get_class($this) )]; |
1649 | - }else{ |
|
1656 | + } else{ |
|
1650 | 1657 | return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
1651 | 1658 | } |
1652 | 1659 | } |
@@ -1774,7 +1781,7 @@ discard block |
||
1774 | 1781 | //if there are query parameters, forget about caching the related model objects. |
1775 | 1782 | if( $query_params ){ |
1776 | 1783 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1777 | - }else{ |
|
1784 | + } else{ |
|
1778 | 1785 | //did we already cache the result of this query? |
1779 | 1786 | $cached_results = $this->get_all_from_cache($relationName); |
1780 | 1787 | if ( ! $cached_results ){ |
@@ -1784,11 +1791,11 @@ discard block |
||
1784 | 1791 | foreach($related_model_objects as $related_model_object){ |
1785 | 1792 | $this->cache($relationName, $related_model_object); |
1786 | 1793 | } |
1787 | - }else{ |
|
1794 | + } else{ |
|
1788 | 1795 | $related_model_objects = $cached_results; |
1789 | 1796 | } |
1790 | 1797 | } |
1791 | - }else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1798 | + } else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1792 | 1799 | $related_model_objects = $this->get_all_from_cache($relationName); |
1793 | 1800 | } |
1794 | 1801 | return $related_model_objects; |
@@ -1840,22 +1847,22 @@ discard block |
||
1840 | 1847 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
1841 | 1848 | if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
1842 | 1849 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1843 | - }else{ |
|
1850 | + } else{ |
|
1844 | 1851 | //first, check if we've already cached the result of this query |
1845 | 1852 | $cached_result = $this->get_one_from_cache($relationName); |
1846 | 1853 | if ( ! $cached_result ){ |
1847 | 1854 | |
1848 | 1855 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1849 | 1856 | $this->cache($relationName,$related_model_object); |
1850 | - }else{ |
|
1857 | + } else{ |
|
1851 | 1858 | $related_model_object = $cached_result; |
1852 | 1859 | } |
1853 | 1860 | } |
1854 | - }else{ |
|
1861 | + } else{ |
|
1855 | 1862 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
1856 | 1863 | if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
1857 | 1864 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1858 | - }else{ |
|
1865 | + } else{ |
|
1859 | 1866 | $related_model_object = null; |
1860 | 1867 | } |
1861 | 1868 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
@@ -1881,7 +1888,7 @@ discard block |
||
1881 | 1888 | public function delete_related($relationName,$query_params = array()){ |
1882 | 1889 | if($this->ID()){ |
1883 | 1890 | $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
1884 | - }else{ |
|
1891 | + } else{ |
|
1885 | 1892 | $count = count($this->get_all_from_cache($relationName)); |
1886 | 1893 | $this->clear_cache($relationName,NULL,TRUE); |
1887 | 1894 | } |
@@ -1901,7 +1908,7 @@ discard block |
||
1901 | 1908 | public function delete_related_permanently($relationName,$query_params = array()){ |
1902 | 1909 | if($this->ID()){ |
1903 | 1910 | $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
1904 | - }else{ |
|
1911 | + } else{ |
|
1905 | 1912 | $count = count($this->get_all_from_cache($relationName)); |
1906 | 1913 | } |
1907 | 1914 | $this->clear_cache($relationName,NULL,TRUE); |
@@ -1936,8 +1943,9 @@ discard block |
||
1936 | 1943 | |
1937 | 1944 | foreach ( (array) $properties as $property_name ) { |
1938 | 1945 | //first make sure this property exists |
1939 | - if ( ! $this->_fields[ $property_name ] ) |
|
1940 | - throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1946 | + if ( ! $this->_fields[ $property_name ] ) { |
|
1947 | + throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1948 | + } |
|
1941 | 1949 | } |
1942 | 1950 | |
1943 | 1951 | return TRUE; |
@@ -2017,7 +2025,7 @@ discard block |
||
2017 | 2025 | $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
2018 | 2026 | if( ! $existing_rows_like_that){ |
2019 | 2027 | return $this->add_extra_meta($meta_key, $meta_value); |
2020 | - }else{ |
|
2028 | + } else{ |
|
2021 | 2029 | foreach( $existing_rows_like_that as $existing_row){ |
2022 | 2030 | $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
2023 | 2031 | } |
@@ -2083,10 +2091,10 @@ discard block |
||
2083 | 2091 | $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
2084 | 2092 | if ( $result instanceof EE_Extra_Meta ){ |
2085 | 2093 | return $result->value(); |
2086 | - }else{ |
|
2094 | + } else{ |
|
2087 | 2095 | return $default; |
2088 | 2096 | } |
2089 | - }else{ |
|
2097 | + } else{ |
|
2090 | 2098 | $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
2091 | 2099 | if($results){ |
2092 | 2100 | $values = array(); |
@@ -2096,7 +2104,7 @@ discard block |
||
2096 | 2104 | } |
2097 | 2105 | } |
2098 | 2106 | return $values; |
2099 | - }else{ |
|
2107 | + } else{ |
|
2100 | 2108 | return $default; |
2101 | 2109 | } |
2102 | 2110 | } |
@@ -2122,7 +2130,7 @@ discard block |
||
2122 | 2130 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
2123 | 2131 | } |
2124 | 2132 | } |
2125 | - }else{ |
|
2133 | + } else{ |
|
2126 | 2134 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
2127 | 2135 | foreach($extra_meta_objs as $extra_meta_obj){ |
2128 | 2136 | if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
@@ -2144,7 +2152,7 @@ discard block |
||
2144 | 2152 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
2145 | 2153 | if($field_we_can_use){ |
2146 | 2154 | return $this->get($field_we_can_use->get_name()); |
2147 | - }else{ |
|
2155 | + } else{ |
|
2148 | 2156 | $first_few_properties = $this->model_field_array(); |
2149 | 2157 | $first_few_properties = array_slice($first_few_properties,0,3); |
2150 | 2158 | $name_parts = array(); |
@@ -2164,7 +2172,7 @@ discard block |
||
2164 | 2172 | if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
2165 | 2173 | //well, if we looked, did we find it in the entity map? |
2166 | 2174 | return TRUE; |
2167 | - }else{ |
|
2175 | + } else{ |
|
2168 | 2176 | return FALSE; |
2169 | 2177 | } |
2170 | 2178 | } |
@@ -2178,7 +2186,7 @@ discard block |
||
2178 | 2186 | public function refresh_from_db(){ |
2179 | 2187 | if( $this->ID() && $this->in_entity_map() ){ |
2180 | 2188 | $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
2181 | - }else{ |
|
2189 | + } else{ |
|
2182 | 2190 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
2183 | 2191 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
2184 | 2192 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * @access protected |
511 | 511 | * @param string $fieldname the property item the corresponding value is for. |
512 | 512 | * @param mixed $value The value we are caching. |
513 | - * @param null $cache_type |
|
513 | + * @param string $cache_type |
|
514 | 514 | * @return void |
515 | 515 | */ |
516 | 516 | protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | * |
824 | 824 | * @param null $field_to_order_by What field is being used as the reference point. |
825 | 825 | * @param array $query_params Any additional conditions on the query. |
826 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
826 | + * @param string $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
827 | 827 | * you can indicate just the columns you want returned |
828 | 828 | * |
829 | 829 | * @return array|EE_Base_Class |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | * |
849 | 849 | * @param null $field_to_order_by What field is being used as the reference point. |
850 | 850 | * @param array $query_params Any additional conditions on the query. |
851 | - * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
851 | + * @param string $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
852 | 852 | * you can indicate just the column you want returned |
853 | 853 | * |
854 | 854 | * @return array|EE_Base_Class |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | /** |
912 | 912 | * This method simply returns the RAW unprocessed value for the given property in this class |
913 | 913 | * @param string $field_name A valid fieldname |
914 | - * @return mixed Whatever the raw value stored on the property is. |
|
914 | + * @return integer|null Whatever the raw value stored on the property is. |
|
915 | 915 | * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
916 | 916 | */ |
917 | 917 | public function get_raw($field_name) { |
@@ -985,11 +985,11 @@ discard block |
||
985 | 985 | * |
986 | 986 | * @access protected |
987 | 987 | * @param string $field_name Field on the instantiated EE_Base_Class child object |
988 | - * @param null $dt_frmt valid datetime format used for date (if '' then we just use the default on the field, if NULL we use the last-used format) |
|
989 | - * @param null $tm_frmt Same as above except this is for time format |
|
988 | + * @param string|null $dt_frmt valid datetime format used for date (if '' then we just use the default on the field, if NULL we use the last-used format) |
|
989 | + * @param null|string $tm_frmt Same as above except this is for time format |
|
990 | 990 | * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
991 | 991 | * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
992 | - * @return void | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
|
992 | + * @return string|boolean | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
|
993 | 993 | */ |
994 | 994 | protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
995 | 995 | |
@@ -1162,7 +1162,7 @@ discard block |
||
1162 | 1162 | * sets the time on a datetime property |
1163 | 1163 | * |
1164 | 1164 | * @access protected |
1165 | - * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
1165 | + * @param string $time a valid time string for php datetime functions (or DateTime object) |
|
1166 | 1166 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
1167 | 1167 | */ |
1168 | 1168 | protected function _set_time_for( $time, $fieldname ) { |
@@ -1177,7 +1177,7 @@ discard block |
||
1177 | 1177 | * sets the date on a datetime property |
1178 | 1178 | * |
1179 | 1179 | * @access protected |
1180 | - * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
1180 | + * @param string $date a valid date string for php datetime functions ( or DateTime object) |
|
1181 | 1181 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
1182 | 1182 | */ |
1183 | 1183 | protected function _set_date_for( $date, $fieldname ) { |
@@ -1506,7 +1506,7 @@ discard block |
||
1506 | 1506 | |
1507 | 1507 | /** |
1508 | 1508 | * for getting a model while instantiated. |
1509 | - * @return \EEM_Base | \EEM_CPT_Base |
|
1509 | + * @return boolean | \EEM_CPT_Base |
|
1510 | 1510 | */ |
1511 | 1511 | public function get_model() { |
1512 | 1512 | $modelName = self::_get_model_classname( get_class($this) ); |
@@ -1537,7 +1537,7 @@ discard block |
||
1537 | 1537 | * If there is a key in the incoming array that matches the primary key for the model AND it is not null, then we check the db. If there's a an object we return it. If not we return false. |
1538 | 1538 | * @param array $props_n_values incoming array of properties and their values |
1539 | 1539 | * @param string $classname the classname of the child class |
1540 | - * @param null $timezone |
|
1540 | + * @param null|string $timezone |
|
1541 | 1541 | * @return mixed (EE_Base_Class|bool) |
1542 | 1542 | */ |
1543 | 1543 | protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL ) { |
@@ -1573,7 +1573,7 @@ discard block |
||
1573 | 1573 | * @param $classname |
1574 | 1574 | * @param null $timezone |
1575 | 1575 | * @throws EE_Error |
1576 | - * @return EEM_Base |
|
1576 | + * @return boolean |
|
1577 | 1577 | */ |
1578 | 1578 | protected static function _get_model( $classname, $timezone = NULL ){ |
1579 | 1579 | //find model for this class |
@@ -1589,8 +1589,8 @@ discard block |
||
1589 | 1589 | /** |
1590 | 1590 | * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
1591 | 1591 | * @param string $model_classname |
1592 | - * @param null $timezone |
|
1593 | - * @return EEM_Base |
|
1592 | + * @param string|null $timezone |
|
1593 | + * @return boolean |
|
1594 | 1594 | */ |
1595 | 1595 | protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
1596 | 1596 | $model_classname = str_replace( 'EEM_', '', $model_classname ); |
@@ -125,14 +125,14 @@ |
||
125 | 125 | public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){ |
126 | 126 | $field_name = NULL; |
127 | 127 | $value = NULL; |
128 | - //backward compat: we still want to find the question's ID |
|
129 | - if( is_numeric( $question_system_id ) ) { |
|
130 | - //find this question's QST_system value |
|
131 | - $question_id = $question_system_id; |
|
132 | - $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); |
|
133 | - } else { |
|
134 | - $question_id = intval( EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ) ); |
|
135 | - } |
|
128 | + //backward compat: we still want to find the question's ID |
|
129 | + if( is_numeric( $question_system_id ) ) { |
|
130 | + //find this question's QST_system value |
|
131 | + $question_id = $question_system_id; |
|
132 | + $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); |
|
133 | + } else { |
|
134 | + $question_id = intval( EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ) ); |
|
135 | + } |
|
136 | 136 | //only bother checking if the registration has an attendee |
137 | 137 | if( $registration->attendee() instanceof EE_Attendee ) { |
138 | 138 | $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id ); |
@@ -51,18 +51,18 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * constructor |
53 | 53 | */ |
54 | - protected function __construct( $timezone = NULL ){ |
|
55 | - $this->singular_item = __('Answer','event_espresso'); |
|
56 | - $this->plural_item = __('Answers','event_espresso'); |
|
54 | + protected function __construct($timezone = NULL) { |
|
55 | + $this->singular_item = __('Answer', 'event_espresso'); |
|
56 | + $this->plural_item = __('Answers', 'event_espresso'); |
|
57 | 57 | $this->_tables = array( |
58 | 58 | 'Answer'=> new EE_Primary_Table('esp_answer', 'ANS_ID') |
59 | 59 | ); |
60 | 60 | $this->_fields = array( |
61 | 61 | 'Answer'=>array( |
62 | - 'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID','event_espresso')), |
|
63 | - 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID','event_espresso'), false, 0, 'Registration'), |
|
64 | - 'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID','event_espresso'), false, 0, 'Question'), |
|
65 | - 'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value','event_espresso'), false, '') |
|
62 | + 'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')), |
|
63 | + 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
64 | + 'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
65 | + 'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '') |
|
66 | 66 | )); |
67 | 67 | $this->_model_relations = array( |
68 | 68 | 'Registration'=>new EE_Belongs_To_Relation(), |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ); |
71 | 71 | $this->_model_chain_to_wp_user = 'Registration.Event'; |
72 | 72 | $this->_caps_slug = 'registrations'; |
73 | - parent::__construct( $timezone ); |
|
73 | + parent::__construct($timezone); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | |
@@ -83,19 +83,19 @@ discard block |
||
83 | 83 | * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value' |
84 | 84 | * @return string |
85 | 85 | */ |
86 | - public function get_answer_value_to_question( EE_Registration $registration, $question_id = NULL,$pretty_answer = FALSE ){ |
|
87 | - $value = $this->get_attendee_property_answer_value( $registration, $question_id, $pretty_answer ); |
|
88 | - if ( $value === NULL ){ |
|
89 | - $answer_obj = $this->get_registration_question_answer_object( $registration, $question_id, $pretty_answer ); |
|
90 | - if( $answer_obj instanceof EE_Answer ){ |
|
91 | - if($pretty_answer){ |
|
86 | + public function get_answer_value_to_question(EE_Registration $registration, $question_id = NULL, $pretty_answer = FALSE) { |
|
87 | + $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer); |
|
88 | + if ($value === NULL) { |
|
89 | + $answer_obj = $this->get_registration_question_answer_object($registration, $question_id, $pretty_answer); |
|
90 | + if ($answer_obj instanceof EE_Answer) { |
|
91 | + if ($pretty_answer) { |
|
92 | 92 | $value = $answer_obj->pretty_value(); |
93 | - }else{ |
|
93 | + } else { |
|
94 | 94 | $value = $answer_obj->value(); |
95 | 95 | } |
96 | 96 | } |
97 | 97 | } |
98 | - return apply_filters( 'FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id ); |
|
98 | + return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param int $question_id |
107 | 107 | * @return EE_Answer |
108 | 108 | */ |
109 | - public function get_registration_question_answer_object( EE_Registration $registration, $question_id = NULL){ |
|
110 | - $answer_obj = $this->get_one( array( array( 'QST_ID'=>$question_id, 'REG_ID'=>$registration->ID() ))); |
|
111 | - return apply_filters( 'FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id ); |
|
109 | + public function get_registration_question_answer_object(EE_Registration $registration, $question_id = NULL) { |
|
110 | + $answer_obj = $this->get_one(array(array('QST_ID'=>$question_id, 'REG_ID'=>$registration->ID()))); |
|
111 | + return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | |
@@ -122,39 +122,39 @@ discard block |
||
122 | 122 | * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for |
123 | 123 | * a question corresponding to an attendee field, returns null) |
124 | 124 | */ |
125 | - public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){ |
|
125 | + public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE) { |
|
126 | 126 | $field_name = NULL; |
127 | 127 | $value = NULL; |
128 | 128 | //backward compat: we still want to find the question's ID |
129 | - if( is_numeric( $question_system_id ) ) { |
|
129 | + if (is_numeric($question_system_id)) { |
|
130 | 130 | //find this question's QST_system value |
131 | 131 | $question_id = $question_system_id; |
132 | - $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); |
|
132 | + $question_system_id = EEM_Question::instance()->get_var(array(array('QST_ID' => $question_system_id)), 'QST_system'); |
|
133 | 133 | } else { |
134 | - $question_id = intval( EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ) ); |
|
134 | + $question_id = intval(EEM_Question::instance()->get_var(array(array('QST_system' => $question_system_id)), 'QST_ID')); |
|
135 | 135 | } |
136 | 136 | //only bother checking if the registration has an attendee |
137 | - if( $registration->attendee() instanceof EE_Attendee ) { |
|
138 | - $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id ); |
|
139 | - if( $field_name ) { |
|
140 | - if( $pretty_answer ) { |
|
141 | - if( $field_name == 'STA_ID' ) { |
|
137 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
138 | + $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id); |
|
139 | + if ($field_name) { |
|
140 | + if ($pretty_answer) { |
|
141 | + if ($field_name == 'STA_ID') { |
|
142 | 142 | $state = $registration->attendee()->state_obj(); |
143 | - $value = $state instanceof EE_State ? $state->name() : sprintf( __('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID() ); |
|
144 | - } else if($field_name == 'CNT_ISO') { |
|
143 | + $value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID()); |
|
144 | + } else if ($field_name == 'CNT_ISO') { |
|
145 | 145 | $country = $registration->attendee()->country_obj(); |
146 | - $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"),$registration->attendee()->country_ID()); |
|
146 | + $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID()); |
|
147 | 147 | } else { |
148 | - $value = $registration->attendee()->get_pretty( $field_name ); |
|
148 | + $value = $registration->attendee()->get_pretty($field_name); |
|
149 | 149 | } |
150 | 150 | //if field name is blank, leave the value as null too |
151 | - }else{ |
|
152 | - $value = $registration->attendee()->get( $field_name ); |
|
151 | + } else { |
|
152 | + $value = $registration->attendee()->get($field_name); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | //if no field was found, leave value blank |
156 | 156 | } |
157 | - return apply_filters( 'FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id ); |
|
157 | + return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |
@@ -90,7 +92,7 @@ discard block |
||
90 | 92 | if( $answer_obj instanceof EE_Answer ){ |
91 | 93 | if($pretty_answer){ |
92 | 94 | $value = $answer_obj->pretty_value(); |
93 | - }else{ |
|
95 | + } else{ |
|
94 | 96 | $value = $answer_obj->value(); |
95 | 97 | } |
96 | 98 | } |
@@ -148,7 +150,7 @@ discard block |
||
148 | 150 | $value = $registration->attendee()->get_pretty( $field_name ); |
149 | 151 | } |
150 | 152 | //if field name is blank, leave the value as null too |
151 | - }else{ |
|
153 | + } else{ |
|
152 | 154 | $value = $registration->attendee()->get( $field_name ); |
153 | 155 | } |
154 | 156 | } |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * |
22 | 22 | * ------------------------------------------------------------------------ |
23 | 23 | */ |
24 | -require_once ( EE_MODELS . 'EEM_Soft_Delete_Base.model.php' ); |
|
25 | -require_once ( EE_CLASSES . 'EE_Ticket.class.php' ); |
|
24 | +require_once (EE_MODELS.'EEM_Soft_Delete_Base.model.php'); |
|
25 | +require_once (EE_CLASSES.'EE_Ticket.class.php'); |
|
26 | 26 | |
27 | 27 | class EEM_Ticket extends EEM_Soft_Delete_Base { |
28 | 28 | |
@@ -35,35 +35,35 @@ discard block |
||
35 | 35 | * @access private |
36 | 36 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
37 | 37 | */ |
38 | - protected function __construct( $timezone ) { |
|
39 | - $this->singular_item = __('Ticket','event_espresso'); |
|
40 | - $this->plural_item = __('Tickets','event_espresso'); |
|
38 | + protected function __construct($timezone) { |
|
39 | + $this->singular_item = __('Ticket', 'event_espresso'); |
|
40 | + $this->plural_item = __('Tickets', 'event_espresso'); |
|
41 | 41 | |
42 | 42 | $this->_tables = array( |
43 | 43 | 'Ticket'=> new EE_Primary_Table('esp_ticket', 'TKT_ID') |
44 | 44 | ); |
45 | 45 | $this->_fields = array( |
46 | 46 | 'Ticket'=>array( |
47 | - 'TKT_ID'=> new EE_Primary_Key_Int_Field('TKT_ID', __('Ticket ID','event_espresso')), |
|
48 | - 'TTM_ID'=>new EE_Foreign_Key_Int_Field('TTM_ID', __('Ticket Template ID','event_espresso'), false, 0, 'Ticket_Template'), |
|
47 | + 'TKT_ID'=> new EE_Primary_Key_Int_Field('TKT_ID', __('Ticket ID', 'event_espresso')), |
|
48 | + 'TTM_ID'=>new EE_Foreign_Key_Int_Field('TTM_ID', __('Ticket Template ID', 'event_espresso'), false, 0, 'Ticket_Template'), |
|
49 | 49 | 'TKT_name'=>new EE_Plain_Text_Field('TKT_name', __('Ticket Name', 'event_espresso'), false, ''), |
50 | - 'TKT_description'=>new EE_Full_HTML_Field('TKT_description', __('Description of Ticket', 'event_espresso'), false, '' ), |
|
51 | - 'TKT_start_date'=>new EE_Datetime_Field('TKT_start_date', __('Start time/date of Ticket','event_espresso'), false, time(), $timezone ), |
|
52 | - 'TKT_end_date'=>new EE_Datetime_Field('TKT_end_date', __('End time/date of Ticket','event_espresso'), false, time(), $timezone ), |
|
53 | - 'TKT_min'=>new EE_Integer_Field('TKT_min', __('Minimum quantity of this ticket that must be purchased', 'event_espresso'), false, 0 ), |
|
54 | - 'TKT_max'=>new EE_Infinite_Integer_Field('TKT_max', __('Maximum quantity of this ticket that can be purchased in one transaction', 'event_espresso'), false, EE_INF ), |
|
50 | + 'TKT_description'=>new EE_Full_HTML_Field('TKT_description', __('Description of Ticket', 'event_espresso'), false, ''), |
|
51 | + 'TKT_start_date'=>new EE_Datetime_Field('TKT_start_date', __('Start time/date of Ticket', 'event_espresso'), false, time(), $timezone), |
|
52 | + 'TKT_end_date'=>new EE_Datetime_Field('TKT_end_date', __('End time/date of Ticket', 'event_espresso'), false, time(), $timezone), |
|
53 | + 'TKT_min'=>new EE_Integer_Field('TKT_min', __('Minimum quantity of this ticket that must be purchased', 'event_espresso'), false, 0), |
|
54 | + 'TKT_max'=>new EE_Infinite_Integer_Field('TKT_max', __('Maximum quantity of this ticket that can be purchased in one transaction', 'event_espresso'), false, EE_INF), |
|
55 | 55 | 'TKT_price'=> new EE_Money_Field('TKT_price', 'Final calculated price for ticket', false, 0), |
56 | 56 | 'TKT_sold' => new EE_Integer_Field('TKT_sold', __('Number of this ticket sold', 'event_espresso'), false, 0), |
57 | - 'TKT_qty'=>new EE_Infinite_Integer_Field('TKT_qty', __('Quantity of this ticket that is available','event_espresso'), false, EE_INF), |
|
58 | - 'TKT_uses'=>new EE_Infinite_Integer_Field('TKT_uses', __('Number of datetimes this ticket can be used at', 'event_espresso'), false, EE_INF ), |
|
59 | - 'TKT_required'=>new EE_Boolean_Field('TKT_required', __("Flag indicating whether this ticket must be purchased with a transaction", "event_espresso"), false, false ), |
|
60 | - 'TKT_taxable'=>new EE_Boolean_Field('TKT_taxable', __("Flag indicating whether there is tax applied on this ticket", "event_espresso"), false,false), |
|
61 | - 'TKT_is_default'=>new EE_Boolean_Field('TKT_is_default', __('Flag indicating that this ticket is a default ticket', 'event_espresso'), false, false ), |
|
57 | + 'TKT_qty'=>new EE_Infinite_Integer_Field('TKT_qty', __('Quantity of this ticket that is available', 'event_espresso'), false, EE_INF), |
|
58 | + 'TKT_uses'=>new EE_Infinite_Integer_Field('TKT_uses', __('Number of datetimes this ticket can be used at', 'event_espresso'), false, EE_INF), |
|
59 | + 'TKT_required'=>new EE_Boolean_Field('TKT_required', __("Flag indicating whether this ticket must be purchased with a transaction", "event_espresso"), false, false), |
|
60 | + 'TKT_taxable'=>new EE_Boolean_Field('TKT_taxable', __("Flag indicating whether there is tax applied on this ticket", "event_espresso"), false, false), |
|
61 | + 'TKT_is_default'=>new EE_Boolean_Field('TKT_is_default', __('Flag indicating that this ticket is a default ticket', 'event_espresso'), false, false), |
|
62 | 62 | 'TKT_order' => new EE_Integer_Field('TKT_order', __('The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', 'event_espresso'), false, 0), |
63 | - 'TKT_row' => new EE_Integer_Field('TKT_row', __('How tickets are displayed in the ui', 'event_espresso'), false, 0 ), |
|
63 | + 'TKT_row' => new EE_Integer_Field('TKT_row', __('How tickets are displayed in the ui', 'event_espresso'), false, 0), |
|
64 | 64 | 'TKT_deleted' => new EE_Trashed_Flag_Field('TKT_deleted', __('Flag indicating if this has been archived or not', 'event_espresso'), false, false), |
65 | - 'TKT_wp_user' => new EE_WP_User_Field('TKT_wp_user', __('Ticket Creator ID', 'event_espresso'), FALSE ), |
|
66 | - 'TKT_parent' => new EE_Integer_Field('TKT_parent', __('Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)'), true, 0 ) |
|
65 | + 'TKT_wp_user' => new EE_WP_User_Field('TKT_wp_user', __('Ticket Creator ID', 'event_espresso'), FALSE), |
|
66 | + 'TKT_parent' => new EE_Integer_Field('TKT_parent', __('Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)'), true, 0) |
|
67 | 67 | )); |
68 | 68 | $this->_model_relations = array( |
69 | 69 | 'Datetime'=>new EE_HABTM_Relation('Datetime_Ticket'), |
@@ -75,12 +75,12 @@ discard block |
||
75 | 75 | ); |
76 | 76 | |
77 | 77 | //this model is generally available for reading |
78 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('TKT_is_default', 'Datetime.Event'); |
|
78 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('TKT_is_default', 'Datetime.Event'); |
|
79 | 79 | //account for default tickets in the caps |
80 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected( 'TKT_is_default', 'Datetime.Event' ); |
|
81 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( 'TKT_is_default', 'Datetime.Event' ); |
|
82 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( 'TKT_is_default', 'Datetime.Event' ); |
|
83 | - parent::__construct( $timezone ); |
|
80 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('TKT_is_default', 'Datetime.Event'); |
|
81 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('TKT_is_default', 'Datetime.Event'); |
|
82 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('TKT_is_default', 'Datetime.Event'); |
|
83 | + parent::__construct($timezone); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function get_all_default_tickets() { |
93 | 93 | /** @type EE_Ticket[] $tickets */ |
94 | - $tickets = $this->get_all( array( array('TKT_is_default' => 1), 'order_by' => array('TKT_order' => 'ASC')) ); |
|
94 | + $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_order' => 'ASC'))); |
|
95 | 95 | //we need to set the start date and end date to today's date and the start of the default dtt |
96 | - return $this->_set_default_dates( $tickets ); |
|
96 | + return $this->_set_default_dates($tickets); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | * @param EE_Ticket[] $tickets |
104 | 104 | * @return EE_Ticket[] |
105 | 105 | */ |
106 | - private function _set_default_dates( $tickets ) { |
|
107 | - foreach ( $tickets as $ticket ) { |
|
108 | - $ticket->set('TKT_start_date', $this->current_time_for_query('TKT_start_date', true) ); |
|
109 | - $ticket->set('TKT_end_date', $this->current_time_for_query( 'TKT_end_date', true ) + (60 * 60 * 24 * 30 ) ); |
|
110 | - $ticket->set_end_time( $this->convert_datetime_for_query( 'TKT_end_date', '11:59 pm', 'g:i a', $this->_timezone ) ); |
|
106 | + private function _set_default_dates($tickets) { |
|
107 | + foreach ($tickets as $ticket) { |
|
108 | + $ticket->set('TKT_start_date', $this->current_time_for_query('TKT_start_date', true)); |
|
109 | + $ticket->set('TKT_end_date', $this->current_time_for_query('TKT_end_date', true) + (60 * 60 * 24 * 30)); |
|
110 | + $ticket->set_end_time($this->convert_datetime_for_query('TKT_end_date', '11:59 pm', 'g:i a', $this->_timezone)); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | return $tickets; |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @param array $query_params |
123 | 123 | * @return int |
124 | 124 | */ |
125 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()){ |
|
126 | - return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime( $DTT_ID, $query_params ); |
|
125 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) { |
|
126 | + return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | * @param EE_Ticket[] $tickets |
134 | 134 | * @return void |
135 | 135 | */ |
136 | - public function update_tickets_sold($tickets){ |
|
137 | - foreach($tickets as $ticket){ |
|
136 | + public function update_tickets_sold($tickets) { |
|
137 | + foreach ($tickets as $ticket) { |
|
138 | 138 | /* @var $ticket EE_Ticket */ |
139 | 139 | $ticket->update_tickets_sold(); |
140 | 140 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once( EE_MODELS . 'fields/EE_Text_Field_Base.php' ); |
|
2 | +require_once(EE_MODELS.'fields/EE_Text_Field_Base.php'); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * Class EE_Enum_Text_Field |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param mixed $default_value |
24 | 24 | * @param array $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed |
25 | 25 | */ |
26 | - function __construct($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values){ |
|
26 | + function __construct($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) { |
|
27 | 27 | $this->_allowed_enum_values = $allowed_enum_values; |
28 | 28 | parent::__construct($table_column, $nice_name, $nullable, $default_value); |
29 | 29 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | * @return string |
38 | 38 | * @throws EE_Error |
39 | 39 | */ |
40 | - function prepare_for_set( $value_inputted_for_field_on_model_object ) { |
|
41 | - if( |
|
40 | + function prepare_for_set($value_inputted_for_field_on_model_object) { |
|
41 | + if ( |
|
42 | 42 | $value_inputted_for_field_on_model_object !== null |
43 | - && ! array_key_exists( $value_inputted_for_field_on_model_object, $this->_allowed_enum_values ) |
|
44 | - ){ |
|
45 | - if( defined( 'WP_DEBUG' ) && WP_DEBUG ){ |
|
43 | + && ! array_key_exists($value_inputted_for_field_on_model_object, $this->_allowed_enum_values) |
|
44 | + ) { |
|
45 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
46 | 46 | $msg = sprintf( |
47 | - __('System is assigning incompatible value "%1$s" to field "%2$s"','event_espresso'), |
|
47 | + __('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'), |
|
48 | 48 | $value_inputted_for_field_on_model_object, |
49 | 49 | $this->_name |
50 | 50 | ); |
51 | 51 | $msg2 = sprintf( |
52 | - __('Allowed values for "%1$s" are "%2$s". You provided: "%3$s"','event_espresso'), |
|
52 | + __('Allowed values for "%1$s" are "%2$s". You provided: "%3$s"', 'event_espresso'), |
|
53 | 53 | $this->_name, |
54 | - implode( ", ", array_keys( $this->_allowed_enum_values ) ), |
|
54 | + implode(", ", array_keys($this->_allowed_enum_values)), |
|
55 | 55 | $value_inputted_for_field_on_model_object |
56 | 56 | ); |
57 | - EE_Error::add_error( "$msg||$msg2", __FILE__, __FUNCTION__, __LINE__ ); |
|
57 | + EE_Error::add_error("$msg||$msg2", __FILE__, __FUNCTION__, __LINE__); |
|
58 | 58 | } |
59 | 59 | return $this->get_default_value(); |
60 | 60 |
@@ -3,18 +3,18 @@ |
||
3 | 3 | * Field to only allow tags that are normally allowed on post_content: |
4 | 4 | * address,a,abbr,acronym,area,article,aside,b,big,blockquote,br,button,caption,cite,code,col,del,dd,dfn,details,div,dl,dt,em,fieldset,figure,figcaption,font,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,img,ins,kbd,label,legend,li,map,mark,menu,nav,p,pre,q,s,samp,span,section,small,strike,strong,sub,summary,sup,table,tbody,td,textarea,tfoot,th,thead,title,tr,tt,u,ul,ol,var |
5 | 5 | */ |
6 | -class EE_Post_Content_Field extends EE_Text_Field_Base{ |
|
6 | +class EE_Post_Content_Field extends EE_Text_Field_Base { |
|
7 | 7 | /** |
8 | 8 | * removes all tags which a WP Post wouldn't allow in its content normally |
9 | 9 | * @param string $value_inputted_for_field_on_model_object |
10 | 10 | * @return string |
11 | 11 | */ |
12 | 12 | function prepare_for_set($value_inputted_for_field_on_model_object) { |
13 | - $value_with_select_tags = wp_kses("$value_inputted_for_field_on_model_object",wp_kses_allowed_html( 'post' )); |
|
13 | + $value_with_select_tags = wp_kses("$value_inputted_for_field_on_model_object", wp_kses_allowed_html('post')); |
|
14 | 14 | return parent::prepare_for_set($value_with_select_tags); |
15 | 15 | } |
16 | 16 | |
17 | - function prepare_for_set_from_db($value_found_in_db_for_model_object){ |
|
17 | + function prepare_for_set_from_db($value_found_in_db_for_model_object) { |
|
18 | 18 | return $value_found_in_db_for_model_object; |
19 | 19 | } |
20 | 20 | } |
21 | 21 | \ No newline at end of file |