@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function __construct() { |
28 | 28 | global $wpdb; |
29 | - $this->_pretty_name = __( 'Question Types', 'event_espresso' ); |
|
29 | + $this->_pretty_name = __('Question Types', 'event_espresso'); |
|
30 | 30 | $this->_old_table = $wpdb->prefix.'esp_question'; |
31 | 31 | $this->_question_type_conversions = array( |
32 | 32 | 'MULTIPLE' => 'CHECKBOX', |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | //when fetching rows, because we automatically use a limit and offset |
36 | 36 | //rows counted before migrating any rows, need to ALSO be counted after a bunch of rows were counted |
37 | 37 | //so we need to include both the migrated rows as well as the non-migrated rows |
38 | - $QST_types_to_count = array_merge( array_keys( $this->_question_type_conversions ), $this->_question_type_conversions ); |
|
39 | - $this->_extra_where_sql = "WHERE QST_type IN ('" . implode( "', '", $QST_types_to_count ) . "')" ; |
|
38 | + $QST_types_to_count = array_merge(array_keys($this->_question_type_conversions), $this->_question_type_conversions); |
|
39 | + $this->_extra_where_sql = "WHERE QST_type IN ('".implode("', '", $QST_types_to_count)."')"; |
|
40 | 40 | parent::__construct(); |
41 | 41 | } |
42 | 42 | |
@@ -44,21 +44,21 @@ discard block |
||
44 | 44 | * @param array $question an associative array where keys are column names and values are their values. |
45 | 45 | * @return null |
46 | 46 | */ |
47 | - protected function _migrate_old_row( $question ) { |
|
47 | + protected function _migrate_old_row($question) { |
|
48 | 48 | global $wpdb; |
49 | - if ( $question['QST_ID'] && isset( $this->_question_type_conversions[ $question['QST_type'] ] )) { |
|
49 | + if ($question['QST_ID'] && isset($this->_question_type_conversions[$question['QST_type']])) { |
|
50 | 50 | $success = $wpdb->update( |
51 | 51 | $this->_old_table, |
52 | - array( 'QST_type' => $this->_question_type_conversions[ $question['QST_type'] ] ), // data |
|
53 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
54 | - array( '%s' ), // data format |
|
55 | - array( '%d' ) // where format |
|
52 | + array('QST_type' => $this->_question_type_conversions[$question['QST_type']]), // data |
|
53 | + array('QST_ID' => $question['QST_ID']), // where |
|
54 | + array('%s'), // data format |
|
55 | + array('%d') // where format |
|
56 | 56 | ); |
57 | - if ( ! $success ) { |
|
57 | + if ( ! $success) { |
|
58 | 58 | $this->add_error( |
59 | 59 | sprintf( |
60 | - __( 'Could not update question type %1$s for question ID=%2$d because "%3$s"', 'event_espresso' ), |
|
61 | - wp_json_encode( $question['QST_type'] ), |
|
60 | + __('Could not update question type %1$s for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
61 | + wp_json_encode($question['QST_type']), |
|
62 | 62 | $question['QST_ID'], |
63 | 63 | $wpdb->last_error |
64 | 64 | ) |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @author Brent Christensen |
14 | 14 | * |
15 | 15 | */ |
16 | -class EE_DMS_4_6_0_country_system_question extends EE_Data_Migration_Script_Stage_Table{ |
|
16 | +class EE_DMS_4_6_0_country_system_question extends EE_Data_Migration_Script_Stage_Table { |
|
17 | 17 | |
18 | 18 | |
19 | 19 | |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct() { |
26 | 26 | global $wpdb; |
27 | - $this->_pretty_name = __( 'Country - System Question', 'event_espresso' ); |
|
27 | + $this->_pretty_name = __('Country - System Question', 'event_espresso'); |
|
28 | 28 | $this->_old_table = $wpdb->prefix.'esp_question'; |
29 | 29 | $this->_extra_where_sql = "WHERE QST_system = 'country'"; |
30 | 30 | parent::__construct(); |
@@ -37,21 +37,21 @@ discard block |
||
37 | 37 | * @param array $question an associative array where keys are column names and values are their values. |
38 | 38 | * @return null |
39 | 39 | */ |
40 | - protected function _migrate_old_row( $question ) { |
|
41 | - if ( $question['QST_ID'] && $question['QST_system'] == 'country' ) { |
|
40 | + protected function _migrate_old_row($question) { |
|
41 | + if ($question['QST_ID'] && $question['QST_system'] == 'country') { |
|
42 | 42 | global $wpdb; |
43 | 43 | $success = $wpdb->update( |
44 | 44 | $this->_old_table, |
45 | - array( 'QST_type' => 'COUNTRY' ), // data |
|
46 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
47 | - array( '%s' ), // data format |
|
48 | - array( '%d' ) // where format |
|
45 | + array('QST_type' => 'COUNTRY'), // data |
|
46 | + array('QST_ID' => $question['QST_ID']), // where |
|
47 | + array('%s'), // data format |
|
48 | + array('%d') // where format |
|
49 | 49 | ); |
50 | - if ( ! $success ) { |
|
50 | + if ( ! $success) { |
|
51 | 51 | $this->add_error( |
52 | 52 | sprintf( |
53 | - __( 'Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso' ), |
|
54 | - wp_json_encode( $question['QST_system'] ), |
|
53 | + __('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
54 | + wp_json_encode($question['QST_system']), |
|
55 | 55 | $question['QST_ID'], |
56 | 56 | $wpdb->last_error |
57 | 57 | ) |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * Migrates 4.1-4.5-style gateway settings (which were stores in EE_Config) |
15 | 15 | * to 4.6-style payment methods (which have their database table) |
16 | 16 | */ |
17 | -class EE_DMS_4_6_0_gateways extends EE_Data_Migration_Script_Stage{ |
|
17 | +class EE_DMS_4_6_0_gateways extends EE_Data_Migration_Script_Stage { |
|
18 | 18 | |
19 | 19 | protected $_new_table_name; |
20 | 20 | protected $_extra_meta_table_name; |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | */ |
74 | 74 | protected function _migration_step($num_items_to_migrate = 50) { |
75 | 75 | $items_actually_migrated = 0; |
76 | - $gateways_to_deal_with = array_slice(EE_Config::instance()->gateway->payment_settings,$this->count_records_migrated(),$num_items_to_migrate); |
|
77 | - foreach($gateways_to_deal_with as $old_gateway_slug => $old_gateway_settings){ |
|
76 | + $gateways_to_deal_with = array_slice(EE_Config::instance()->gateway->payment_settings, $this->count_records_migrated(), $num_items_to_migrate); |
|
77 | + foreach ($gateways_to_deal_with as $old_gateway_slug => $old_gateway_settings) { |
|
78 | 78 | |
79 | - if( in_array( $old_gateway_slug, $this->_gateway_we_know_to_migrate ) ) { |
|
80 | - if( ! $old_gateway_settings){ |
|
79 | + if (in_array($old_gateway_slug, $this->_gateway_we_know_to_migrate)) { |
|
80 | + if ( ! $old_gateway_settings) { |
|
81 | 81 | //no settings existed for this gateway anyways... weird... |
82 | 82 | $items_actually_migrated++; |
83 | 83 | continue; |
@@ -86,16 +86,16 @@ discard block |
||
86 | 86 | $success = $this->_convert_gateway_settings( |
87 | 87 | $old_gateway_slug, |
88 | 88 | $old_gateway_settings, |
89 | - isset( EE_Config::instance()->gateway->active_gateways[ $old_gateway_slug ] ) ); |
|
90 | - if( $success ) { |
|
91 | - EE_Config::instance()->gateway->payment_settings[ $old_gateway_slug ] = 'Deprecated'; |
|
89 | + isset(EE_Config::instance()->gateway->active_gateways[$old_gateway_slug]) ); |
|
90 | + if ($success) { |
|
91 | + EE_Config::instance()->gateway->payment_settings[$old_gateway_slug] = 'Deprecated'; |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | $items_actually_migrated++; |
95 | 95 | } |
96 | 96 | |
97 | - EE_Config::instance()->update_espresso_config(false,false); |
|
98 | - if($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()){ |
|
97 | + EE_Config::instance()->update_espresso_config(false, false); |
|
98 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
99 | 99 | $this->set_completed(); |
100 | 100 | } |
101 | 101 | return $items_actually_migrated; |
@@ -108,22 +108,22 @@ discard block |
||
108 | 108 | * @param boolean $active indicates the gateway is currently active |
109 | 109 | * @return boolean success |
110 | 110 | */ |
111 | - protected function _convert_gateway_settings($old_gateway_slug,$old_gateway_settings,$active){ |
|
112 | - switch($old_gateway_slug){ |
|
111 | + protected function _convert_gateway_settings($old_gateway_slug, $old_gateway_settings, $active) { |
|
112 | + switch ($old_gateway_slug) { |
|
113 | 113 | case 'Aim': |
114 | 114 | $extra_meta_key_values = array( |
115 | 115 | 'login_id'=>$old_gateway_settings['authnet_aim_login_id'], |
116 | 116 | 'transaction_key'=>$old_gateway_settings['authnet_aim_transaction_key'], |
117 | 117 | 'test_transactions'=>$old_gateway_settings['test_transactions'] |
118 | 118 | ); |
119 | - $desc = __( 'Please provide the following billing information.', 'event_espresso' ); |
|
119 | + $desc = __('Please provide the following billing information.', 'event_espresso'); |
|
120 | 120 | break; |
121 | 121 | case 'Bank': |
122 | 122 | $extra_meta_key_values = array( |
123 | 123 | 'page_title'=>$old_gateway_settings['page_title'], |
124 | 124 | 'payment_instructions'=> |
125 | - sprintf( __('%1$s<br/>Name on Bank Account: %2$s<br/>Bank Account Number: %3$s<br/>Bank Name: %4$s<br/>Bank Address:%5$s', 'event_espresso'), $old_gateway_settings['bank_instructions'] , $old_gateway_settings['account_name'], $old_gateway_settings['account_number'], $old_gateway_settings['bank_name'], $old_gateway_settings['bank_address'] ) ); |
|
126 | - $desc = __( 'Make payment using an electronic funds transfer from your bank.', 'event_espresso' ); |
|
125 | + sprintf(__('%1$s<br/>Name on Bank Account: %2$s<br/>Bank Account Number: %3$s<br/>Bank Name: %4$s<br/>Bank Address:%5$s', 'event_espresso'), $old_gateway_settings['bank_instructions'], $old_gateway_settings['account_name'], $old_gateway_settings['account_number'], $old_gateway_settings['bank_name'], $old_gateway_settings['bank_address']) ); |
|
126 | + $desc = __('Make payment using an electronic funds transfer from your bank.', 'event_espresso'); |
|
127 | 127 | break; |
128 | 128 | case 'Check': |
129 | 129 | $extra_meta_key_values = array( |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | 'payment_instructions'=>$old_gateway_settings['check_instructions'], |
132 | 132 | 'address_to_send_payment'=>$old_gateway_settings['payment_address'] |
133 | 133 | ); |
134 | - $desc = __( 'On the next page you will be given instructions on how to make a payment by check.', 'event_espresso' ); |
|
134 | + $desc = __('On the next page you will be given instructions on how to make a payment by check.', 'event_espresso'); |
|
135 | 135 | break; |
136 | 136 | case 'Invoice': |
137 | 137 | $extra_meta_key_values = array( |
@@ -139,23 +139,23 @@ discard block |
||
139 | 139 | 'pdf_payee_email' => $old_gateway_settings['template_invoice_email'], |
140 | 140 | 'pdf_payee_tax_number' => $old_gateway_settings['template_invoice_tax_number'], |
141 | 141 | 'pdf_payee_address' => $old_gateway_settings['template_invoice_address'], |
142 | - 'pdf_instructions' => $old_gateway_settings[ 'template_payment_instructions' ], |
|
143 | - 'pdf_logo_image' => $old_gateway_settings[ 'invoice_logo_url' ], |
|
144 | - 'page_confirmation_text' => isset( $old_gateway_settings[ 'page_instructions' ] ) ? $old_gateway_settings[ 'page_instructions' ] : '', |
|
145 | - 'page_extra_info' => isset( $old_gateway_settings[ 'payment_address' ] ) ? $old_gateway_settings[ 'payment_address' ] : '', |
|
142 | + 'pdf_instructions' => $old_gateway_settings['template_payment_instructions'], |
|
143 | + 'pdf_logo_image' => $old_gateway_settings['invoice_logo_url'], |
|
144 | + 'page_confirmation_text' => isset($old_gateway_settings['page_instructions']) ? $old_gateway_settings['page_instructions'] : '', |
|
145 | + 'page_extra_info' => isset($old_gateway_settings['payment_address']) ? $old_gateway_settings['payment_address'] : '', |
|
146 | 146 | 'legacy_invoice_css' => $old_gateway_settings['invoice_css'] |
147 | 147 | ); |
148 | 148 | //if they didnt want the invoiec gateway to show, pretend it was inactive |
149 | - if( ! $old_gateway_settings['show'] ){ |
|
149 | + if ( ! $old_gateway_settings['show']) { |
|
150 | 150 | $active = FALSE; |
151 | 151 | } |
152 | - $desc = __( 'On the next page you will be able to access your invoice and instructions on how to pay it.', 'event_espresso' ); |
|
152 | + $desc = __('On the next page you will be able to access your invoice and instructions on how to pay it.', 'event_espresso'); |
|
153 | 153 | break; |
154 | 154 | case 'Mijireh': |
155 | 155 | $extra_meta_key_values = array( |
156 | - 'access_key' => $old_gateway_settings[ 'access_key' ] |
|
156 | + 'access_key' => $old_gateway_settings['access_key'] |
|
157 | 157 | ); |
158 | - $desc = __( 'On the next page you will be able to enter your billing information to make the payment.', 'event_espresso' ); |
|
158 | + $desc = __('On the next page you will be able to enter your billing information to make the payment.', 'event_espresso'); |
|
159 | 159 | break; |
160 | 160 | case 'Paypal_Pro': |
161 | 161 | $extra_meta_key_values = array( |
@@ -164,31 +164,31 @@ discard block |
||
164 | 164 | 'signature'=>$old_gateway_settings['signature'], |
165 | 165 | 'credit_card_types'=>$old_gateway_settings['credit_cards'], |
166 | 166 | ); |
167 | - $desc = __( 'Please provide the following billing information.', 'event_espresso' ); |
|
167 | + $desc = __('Please provide the following billing information.', 'event_espresso'); |
|
168 | 168 | break; |
169 | 169 | case 'Paypal_Standard': |
170 | 170 | $extra_meta_key_values = array( |
171 | - 'paypal_id' => $old_gateway_settings[ 'paypal_id' ], |
|
172 | - 'image_url' => $old_gateway_settings[ 'image_url' ], |
|
173 | - 'shipping_details' => isset( $old_gateway_settings[ 'no_shipping' ] ) ? $old_gateway_settings[ 'no_shipping' ] : false, |
|
171 | + 'paypal_id' => $old_gateway_settings['paypal_id'], |
|
172 | + 'image_url' => $old_gateway_settings['image_url'], |
|
173 | + 'shipping_details' => isset($old_gateway_settings['no_shipping']) ? $old_gateway_settings['no_shipping'] : false, |
|
174 | 174 | |
175 | 175 | ); |
176 | - $desc = sprintf( __( 'After clicking \'Finalize Registration\', you will be forwarded to PayPal to make your payment. Make sure you return to this site in order to properly finalize your registration.', 'event_espresso' ), '<strong>','</strong>' ); |
|
176 | + $desc = sprintf(__('After clicking \'Finalize Registration\', you will be forwarded to PayPal to make your payment. Make sure you return to this site in order to properly finalize your registration.', 'event_espresso'), '<strong>', '</strong>'); |
|
177 | 177 | break; |
178 | 178 | default: |
179 | 179 | //if we don't recognize the payment method, just put everything in it into extra meta. At least this way its preserved somewhere |
180 | 180 | $extra_meta_key_values = $old_gateway_settings; |
181 | 181 | $desc = ''; |
182 | 182 | } |
183 | - $pretty_name = isset( $old_gateway_settings[ 'display_name' ] ) ? $old_gateway_settings[ 'display_name' ] : $old_gateway_slug; |
|
184 | - $offline_gateways = array( 'Bank', 'Check', 'Invoice' ); |
|
185 | - if( $active && in_array( $old_gateway_slug, $offline_gateways ) ) { |
|
186 | - $scope = array( 'CART', 'ADMIN'); |
|
187 | - }elseif( $active && ! in_array( $old_gateway_slug, $offline_gateways ) ) { |
|
188 | - $scope = array( 'CART' ); |
|
189 | - }elseif( ! $active && in_array($old_gateway_slug,$offline_gateways ) ) { |
|
190 | - $scope = array( 'ADMIN' ); |
|
191 | - }else{ |
|
183 | + $pretty_name = isset($old_gateway_settings['display_name']) ? $old_gateway_settings['display_name'] : $old_gateway_slug; |
|
184 | + $offline_gateways = array('Bank', 'Check', 'Invoice'); |
|
185 | + if ($active && in_array($old_gateway_slug, $offline_gateways)) { |
|
186 | + $scope = array('CART', 'ADMIN'); |
|
187 | + }elseif ($active && ! in_array($old_gateway_slug, $offline_gateways)) { |
|
188 | + $scope = array('CART'); |
|
189 | + }elseif ( ! $active && in_array($old_gateway_slug, $offline_gateways)) { |
|
190 | + $scope = array('ADMIN'); |
|
191 | + } else { |
|
192 | 192 | $scope = array(); |
193 | 193 | } |
194 | 194 | $payment_method_col_values = array( |
@@ -196,25 +196,25 @@ discard block |
||
196 | 196 | 'PMD_name' => $pretty_name, |
197 | 197 | 'PMD_desc' => $desc, |
198 | 198 | 'PMD_admin_name' => $pretty_name, |
199 | - 'PMD_slug' => sanitize_key( $old_gateway_slug ), |
|
200 | - 'PMD_debug_mode' => isset( $old_gateway_settings[ 'use_sandbox' ] ) ? $old_gateway_settings['use_sandbox'] : FALSE, |
|
201 | - 'PMD_button_url' => isset( $old_gateway_settings[ 'button_url' ] ) ? $old_gateway_settings[ 'button_url' ] : NULL, |
|
202 | - 'PMD_scope' => serialize( $scope ) |
|
199 | + 'PMD_slug' => sanitize_key($old_gateway_slug), |
|
200 | + 'PMD_debug_mode' => isset($old_gateway_settings['use_sandbox']) ? $old_gateway_settings['use_sandbox'] : FALSE, |
|
201 | + 'PMD_button_url' => isset($old_gateway_settings['button_url']) ? $old_gateway_settings['button_url'] : NULL, |
|
202 | + 'PMD_scope' => serialize($scope) |
|
203 | 203 | ); |
204 | 204 | $db_types = array( |
205 | - '%s',//PMD_type |
|
206 | - '%s',//PMD_name |
|
207 | - '%s',//PMD_desc |
|
208 | - '%s',//PMD_admin_name |
|
209 | - '%s',//PMD_slug |
|
210 | - '%d',//PMD_debug_mode |
|
211 | - '%s',//PMD_button_url |
|
212 | - '%s',//PMD_scope |
|
205 | + '%s', //PMD_type |
|
206 | + '%s', //PMD_name |
|
207 | + '%s', //PMD_desc |
|
208 | + '%s', //PMD_admin_name |
|
209 | + '%s', //PMD_slug |
|
210 | + '%d', //PMD_debug_mode |
|
211 | + '%s', //PMD_button_url |
|
212 | + '%s', //PMD_scope |
|
213 | 213 | ); |
214 | 214 | global $wpdb; |
215 | 215 | //first: check if it already exists |
216 | - $id = $wpdb->get_var( $wpdb->prepare( "SELECT PMD_ID FROM {$this->_new_table_name} WHERE PMD_slug=%s", $payment_method_col_values[ 'PMD_slug' ] ) ); |
|
217 | - if( $id ){ |
|
216 | + $id = $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM {$this->_new_table_name} WHERE PMD_slug=%s", $payment_method_col_values['PMD_slug'])); |
|
217 | + if ($id) { |
|
218 | 218 | //just update that payment method instead of creating a new one |
219 | 219 | $success = $wpdb->update( |
220 | 220 | $this->_new_table_name, |
@@ -224,27 +224,27 @@ discard block |
||
224 | 224 | ), |
225 | 225 | $db_types, |
226 | 226 | array( |
227 | - '%d',//PMD_ID |
|
227 | + '%d', //PMD_ID |
|
228 | 228 | )); |
229 | - if( ! $success ){ |
|
230 | - $this->add_error(sprintf(__('Could not update payment method %d with properties %s because %s', "event_espresso"),$id,wp_json_encode($payment_method_col_values),$wpdb->last_error)); |
|
229 | + if ( ! $success) { |
|
230 | + $this->add_error(sprintf(__('Could not update payment method %d with properties %s because %s', "event_espresso"), $id, wp_json_encode($payment_method_col_values), $wpdb->last_error)); |
|
231 | 231 | } |
232 | - }else{ |
|
232 | + } else { |
|
233 | 233 | $success = $wpdb->insert( |
234 | 234 | $this->_new_table_name, |
235 | 235 | $payment_method_col_values, |
236 | 236 | $db_types); |
237 | - if ( ! $success ) { |
|
237 | + if ( ! $success) { |
|
238 | 238 | $this->add_error($wpdb->last_error); |
239 | 239 | return false; |
240 | - }else{ |
|
240 | + } else { |
|
241 | 241 | $id = $wpdb->insert_id; |
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
245 | - if( $id ){ |
|
246 | - $this->_convert_extra_meta_values( $id, $extra_meta_key_values ); |
|
247 | - $this->get_migration_script()->set_mapping( 'EE_Gateway_Config', $old_gateway_slug, $this->_new_table_name, $id ); |
|
245 | + if ($id) { |
|
246 | + $this->_convert_extra_meta_values($id, $extra_meta_key_values); |
|
247 | + $this->get_migration_script()->set_mapping('EE_Gateway_Config', $old_gateway_slug, $this->_new_table_name, $id); |
|
248 | 248 | return true; |
249 | 249 | } |
250 | 250 | return false; |
@@ -258,26 +258,26 @@ discard block |
||
258 | 258 | * @param int $id |
259 | 259 | * @param array $extra_meta_key_values |
260 | 260 | */ |
261 | - private function _convert_extra_meta_values($id,$extra_meta_key_values){ |
|
261 | + private function _convert_extra_meta_values($id, $extra_meta_key_values) { |
|
262 | 262 | global $wpdb; |
263 | - foreach( $extra_meta_key_values as $key => $value ){ |
|
263 | + foreach ($extra_meta_key_values as $key => $value) { |
|
264 | 264 | $exm_args = array( |
265 | 265 | 'OBJ_ID'=>$id, |
266 | 266 | 'EXM_type'=>'Payment_Method', |
267 | 267 | 'EXM_key'=>$key, |
268 | - 'EXM_value'=> maybe_serialize($value ) |
|
268 | + 'EXM_value'=> maybe_serialize($value) |
|
269 | 269 | ); |
270 | 270 | $success = $wpdb->insert( |
271 | 271 | $this->_extra_meta_table_name, |
272 | 272 | $exm_args, |
273 | 273 | array( |
274 | - '%d',//OBJ_ID |
|
275 | - '%s',//EXM_type |
|
276 | - '%s',//EXM_key |
|
277 | - '%s',//EXM_value |
|
274 | + '%d', //OBJ_ID |
|
275 | + '%s', //EXM_type |
|
276 | + '%s', //EXM_key |
|
277 | + '%s', //EXM_value |
|
278 | 278 | )); |
279 | - if( ! $success ){ |
|
280 | - $this->add_error(sprintf(__('Could not insert extra meta key with values %s. %s', "event_espresso"),wp_json_encode($exm_args),$wpdb->last_error)); |
|
279 | + if ( ! $success) { |
|
280 | + $this->add_error(sprintf(__('Could not insert extra meta key with values %s. %s', "event_espresso"), wp_json_encode($exm_args), $wpdb->last_error)); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | } |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | $offline_gateways = array( 'Bank', 'Check', 'Invoice' ); |
185 | 185 | if( $active && in_array( $old_gateway_slug, $offline_gateways ) ) { |
186 | 186 | $scope = array( 'CART', 'ADMIN'); |
187 | - }elseif( $active && ! in_array( $old_gateway_slug, $offline_gateways ) ) { |
|
187 | + } elseif( $active && ! in_array( $old_gateway_slug, $offline_gateways ) ) { |
|
188 | 188 | $scope = array( 'CART' ); |
189 | - }elseif( ! $active && in_array($old_gateway_slug,$offline_gateways ) ) { |
|
189 | + } elseif( ! $active && in_array($old_gateway_slug,$offline_gateways ) ) { |
|
190 | 190 | $scope = array( 'ADMIN' ); |
191 | - }else{ |
|
191 | + } else{ |
|
192 | 192 | $scope = array(); |
193 | 193 | } |
194 | 194 | $payment_method_col_values = array( |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | if( ! $success ){ |
230 | 230 | $this->add_error(sprintf(__('Could not update payment method %d with properties %s because %s', "event_espresso"),$id,wp_json_encode($payment_method_col_values),$wpdb->last_error)); |
231 | 231 | } |
232 | - }else{ |
|
232 | + } else{ |
|
233 | 233 | $success = $wpdb->insert( |
234 | 234 | $this->_new_table_name, |
235 | 235 | $payment_method_col_values, |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | if ( ! $success ) { |
238 | 238 | $this->add_error($wpdb->last_error); |
239 | 239 | return false; |
240 | - }else{ |
|
240 | + } else{ |
|
241 | 241 | $id = $wpdb->insert_id; |
242 | 242 | } |
243 | 243 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @author Brent Christensen |
14 | 14 | * |
15 | 15 | */ |
16 | -class EE_DMS_4_9_0_Email_System_Question extends EE_Data_Migration_Script_Stage_Table{ |
|
16 | +class EE_DMS_4_9_0_Email_System_Question extends EE_Data_Migration_Script_Stage_Table { |
|
17 | 17 | |
18 | 18 | |
19 | 19 | |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct() { |
26 | 26 | global $wpdb; |
27 | - $this->_pretty_name = __( 'Email - System Question', 'event_espresso' ); |
|
27 | + $this->_pretty_name = __('Email - System Question', 'event_espresso'); |
|
28 | 28 | $this->_old_table = $wpdb->prefix.'esp_question'; |
29 | 29 | $this->_extra_where_sql = "WHERE QST_system = 'email'"; |
30 | 30 | parent::__construct(); |
@@ -37,21 +37,21 @@ discard block |
||
37 | 37 | * @param array $question an associative array where keys are column names and values are their values. |
38 | 38 | * @return null |
39 | 39 | */ |
40 | - protected function _migrate_old_row( $question ) { |
|
41 | - if ( $question['QST_ID'] && $question['QST_system'] == 'email' ) { |
|
40 | + protected function _migrate_old_row($question) { |
|
41 | + if ($question['QST_ID'] && $question['QST_system'] == 'email') { |
|
42 | 42 | global $wpdb; |
43 | 43 | $success = $wpdb->update( |
44 | 44 | $this->_old_table, |
45 | - array( 'QST_type' => 'EMAIL' ), // data |
|
46 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
47 | - array( '%s' ), // data format |
|
48 | - array( '%d' ) // where format |
|
45 | + array('QST_type' => 'EMAIL'), // data |
|
46 | + array('QST_ID' => $question['QST_ID']), // where |
|
47 | + array('%s'), // data format |
|
48 | + array('%d') // where format |
|
49 | 49 | ); |
50 | - if ( ! $success ) { |
|
50 | + if ( ! $success) { |
|
51 | 51 | $this->add_error( |
52 | 52 | sprintf( |
53 | - __( 'Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso' ), |
|
54 | - wp_json_encode( $question['QST_system'] ), |
|
53 | + __('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
54 | + wp_json_encode($question['QST_system']), |
|
55 | 55 | $question['QST_ID'], |
56 | 56 | $wpdb->last_error |
57 | 57 | ) |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | |
2 | 2 | <div class="misc-pub-section"> |
3 | 3 | <span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20"></span> |
4 | - <a href="<?php echo $view_approved_reg_url;?>"> |
|
5 | - <?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence') ); ?> |
|
4 | + <a href="<?php echo $view_approved_reg_url; ?>"> |
|
5 | + <?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence')); ?> |
|
6 | 6 | </a>: |
7 | 7 | <?php echo $approved_regs; ?> |
8 | 8 | </div> |
9 | 9 | <div class="misc-pub-section"> |
10 | 10 | <span class="dashicons dashicons-groups ee-icon-color-ee-blue ee-icon-size-20"></span> |
11 | - <a href="<?php echo $view_pending_payment_reg_url;?>"> |
|
12 | - <?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence') ); ?> |
|
11 | + <a href="<?php echo $view_pending_payment_reg_url; ?>"> |
|
12 | + <?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence')); ?> |
|
13 | 13 | </a>: |
14 | 14 | <?php echo $pending_payment_regs; ?> |
15 | 15 | </div> |
16 | 16 | <div class="misc-pub-section"> |
17 | 17 | <span class="dashicons dashicons-groups ee-icon-color-ee-orange ee-icon-size-20"></span> |
18 | - <a href="<?php echo $view_not_approved_reg_url;?>"> |
|
19 | - <?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence') ); ?> |
|
18 | + <a href="<?php echo $view_not_approved_reg_url; ?>"> |
|
19 | + <?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence')); ?> |
|
20 | 20 | </a>: |
21 | 21 | <?php echo $not_approved_regs; ?> |
22 | 22 | </div> |
@@ -29,5 +29,5 @@ discard block |
||
29 | 29 | </a> |
30 | 30 | </div> /**/ ?> |
31 | 31 | |
32 | -<?php echo $event_editor_overview_add;?> |
|
32 | +<?php echo $event_editor_overview_add; ?> |
|
33 | 33 | <br/> |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | <?php else : ?> |
18 | 18 | <p class="clearfix"> |
19 | 19 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name', |
20 | - 'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
20 | + 'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
21 | 21 | </p> |
22 | 22 | <p class="clearfix"> |
23 | 23 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | </p> |
26 | 26 | <p class="clearfix"> |
27 | 27 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Phone #', |
28 | - 'event_espresso'); ?></span><?php echo $prime_reg_phone; ?> |
|
28 | + 'event_espresso'); ?></span><?php echo $prime_reg_phone; ?> |
|
29 | 29 | </p> |
30 | 30 | <p class="clearfix"> |
31 | 31 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Address', 'event_espresso'); ?></span> |
@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | </div> <!-- end #admin-side-mbox-primary-registrant-dv --> |
37 | 37 | |
38 | 38 | <?php |
39 | - /** only show if logged in user has access */ |
|
40 | - if ( EE_Registry::instance()->CAP->current_user_can( |
|
41 | - 'ee_edit_contact', |
|
42 | - 'view_or_edit_contact_button', |
|
43 | - $ATT_ID |
|
44 | - ) |
|
45 | - ) : ?> |
|
39 | + /** only show if logged in user has access */ |
|
40 | + if ( EE_Registry::instance()->CAP->current_user_can( |
|
41 | + 'ee_edit_contact', |
|
42 | + 'view_or_edit_contact_button', |
|
43 | + $ATT_ID |
|
44 | + ) |
|
45 | + ) : ?> |
|
46 | 46 | <p style="text-align:right;"> |
47 | 47 | <a class="button button-small" href="<?php echo $edit_attendee_url; ?>" |
48 | 48 | title="<?php esc_attr_e('View details for this contact.', 'event_espresso'); ?>"> |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | <?php else : ?> |
18 | 18 | <p class="clearfix"> |
19 | 19 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name', |
20 | - 'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
20 | + 'event_espresso'); ?></span><?php echo $prime_reg_fname.' '.$prime_reg_lname; ?> |
|
21 | 21 | </p> |
22 | 22 | <p class="clearfix"> |
23 | 23 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | <?php |
39 | 39 | /** only show if logged in user has access */ |
40 | - if ( EE_Registry::instance()->CAP->current_user_can( |
|
40 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
41 | 41 | 'ee_edit_contact', |
42 | 42 | 'view_or_edit_contact_button', |
43 | 43 | $ATT_ID |
@@ -50,4 +50,4 @@ discard block |
||
50 | 50 | </a> |
51 | 51 | </p> |
52 | 52 | <?php endif; ?> |
53 | -<?php endif; //end no attendee check?> |
|
53 | +<?php endif; //end no attendee check?> |
@@ -14,10 +14,13 @@ |
||
14 | 14 | <?php echo $no_attendee_message; ?> |
15 | 15 | </p> |
16 | 16 | </div> <!-- end #admin-side-mbox-primary-registrant-dv --> |
17 | -<?php else : ?> |
|
17 | +<?php else { |
|
18 | + : ?> |
|
18 | 19 | <p class="clearfix"> |
19 | 20 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name', |
20 | - 'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
21 | + 'event_espresso'); |
|
22 | +} |
|
23 | +?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
21 | 24 | </p> |
22 | 25 | <p class="clearfix"> |
23 | 26 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a |
@@ -529,7 +529,7 @@ |
||
529 | 529 | /** |
530 | 530 | * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
531 | 531 | * |
532 | - * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
532 | + * @param string[] $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
533 | 533 | * stati you want counts for as values in the array. An empty array returns counts |
534 | 534 | * for all valid stati. |
535 | 535 | * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -14,657 +14,657 @@ discard block |
||
14 | 14 | class EEM_Datetime extends EEM_Soft_Delete_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @var EEM_Datetime $_instance |
|
19 | - */ |
|
20 | - protected static $_instance; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * private constructor to prevent direct creation |
|
25 | - * |
|
26 | - * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
27 | - * (and any incoming timezone data that gets saved). |
|
28 | - * Note this just sends the timezone info to the date time model field objects. |
|
29 | - * Default is NULL |
|
30 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
31 | - * @throws EE_Error |
|
32 | - * @throws InvalidArgumentException |
|
33 | - * @throws InvalidArgumentException |
|
34 | - */ |
|
35 | - protected function __construct($timezone) |
|
36 | - { |
|
37 | - $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
38 | - $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
39 | - $this->_tables = array( |
|
40 | - 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
41 | - ); |
|
42 | - $this->_fields = array( |
|
43 | - 'Datetime' => array( |
|
44 | - 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
45 | - 'DTT_ID', |
|
46 | - esc_html__('Datetime ID', 'event_espresso') |
|
47 | - ), |
|
48 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
49 | - 'EVT_ID', |
|
50 | - esc_html__('Event ID', 'event_espresso'), |
|
51 | - false, |
|
52 | - 0, |
|
53 | - 'Event' |
|
54 | - ), |
|
55 | - 'DTT_name' => new EE_Plain_Text_Field( |
|
56 | - 'DTT_name', |
|
57 | - esc_html__('Datetime Name', 'event_espresso'), |
|
58 | - false, |
|
59 | - '' |
|
60 | - ), |
|
61 | - 'DTT_description' => new EE_Post_Content_Field( |
|
62 | - 'DTT_description', |
|
63 | - esc_html__('Description for Datetime', 'event_espresso'), |
|
64 | - false, |
|
65 | - '' |
|
66 | - ), |
|
67 | - 'DTT_EVT_start' => new EE_Datetime_Field( |
|
68 | - 'DTT_EVT_start', |
|
69 | - esc_html__('Start time/date of Event', 'event_espresso'), |
|
70 | - false, |
|
71 | - EE_Datetime_Field::now, |
|
72 | - $timezone |
|
73 | - ), |
|
74 | - 'DTT_EVT_end' => new EE_Datetime_Field( |
|
75 | - 'DTT_EVT_end', |
|
76 | - esc_html__('End time/date of Event', 'event_espresso'), |
|
77 | - false, |
|
78 | - EE_Datetime_Field::now, |
|
79 | - $timezone |
|
80 | - ), |
|
81 | - 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
82 | - 'DTT_reg_limit', |
|
83 | - esc_html__('Registration Limit for this time', 'event_espresso'), |
|
84 | - true, |
|
85 | - EE_INF |
|
86 | - ), |
|
87 | - 'DTT_sold' => new EE_Integer_Field( |
|
88 | - 'DTT_sold', |
|
89 | - esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
90 | - true, |
|
91 | - 0 |
|
92 | - ), |
|
93 | - 'DTT_reserved' => new EE_Integer_Field( |
|
94 | - 'DTT_reserved', |
|
95 | - esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
96 | - false, |
|
97 | - 0 |
|
98 | - ), |
|
99 | - 'DTT_is_primary' => new EE_Boolean_Field( |
|
100 | - 'DTT_is_primary', |
|
101 | - esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
102 | - false, |
|
103 | - false |
|
104 | - ), |
|
105 | - 'DTT_order' => new EE_Integer_Field( |
|
106 | - 'DTT_order', |
|
107 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
108 | - false, |
|
109 | - 0 |
|
110 | - ), |
|
111 | - 'DTT_parent' => new EE_Integer_Field( |
|
112 | - 'DTT_parent', |
|
113 | - esc_html__('Indicates what DTT_ID is the parent of this DTT_ID'), |
|
114 | - true, |
|
115 | - 0 |
|
116 | - ), |
|
117 | - 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
118 | - 'DTT_deleted', |
|
119 | - esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
120 | - false, |
|
121 | - false |
|
122 | - ), |
|
123 | - ), |
|
124 | - ); |
|
125 | - $this->_model_relations = array( |
|
126 | - 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
127 | - 'Event' => new EE_Belongs_To_Relation(), |
|
128 | - 'Checkin' => new EE_Has_Many_Relation(), |
|
129 | - ); |
|
130 | - $this->_model_chain_to_wp_user = 'Event'; |
|
131 | - //this model is generally available for reading |
|
132 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
133 | - 'Event' |
|
134 | - ); |
|
135 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
136 | - 'Event' |
|
137 | - ); |
|
138 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
139 | - 'Event' |
|
140 | - ); |
|
141 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
142 | - 'Event', |
|
143 | - EEM_Base::caps_edit |
|
144 | - ); |
|
145 | - parent::__construct($timezone); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * create new blank datetime |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
154 | - * @throws EE_Error |
|
155 | - */ |
|
156 | - public function create_new_blank_datetime() |
|
157 | - { |
|
158 | - //makes sure timezone is always set. |
|
159 | - $timezone_string = $this->get_timezone(); |
|
160 | - $blank_datetime = EE_Datetime::new_instance( |
|
161 | - array( |
|
162 | - 'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS, |
|
163 | - 'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS, |
|
164 | - 'DTT_order' => 1, |
|
165 | - 'DTT_reg_limit' => EE_INF, |
|
166 | - ), |
|
167 | - $timezone_string |
|
168 | - ); |
|
169 | - $blank_datetime->set_start_time( |
|
170 | - $this->convert_datetime_for_query( |
|
171 | - 'DTT_EVT_start', |
|
172 | - '8am', |
|
173 | - 'ga', |
|
174 | - $timezone_string |
|
175 | - ) |
|
176 | - ); |
|
177 | - $blank_datetime->set_end_time( |
|
178 | - $this->convert_datetime_for_query( |
|
179 | - 'DTT_EVT_end', |
|
180 | - '5pm', |
|
181 | - 'ga', |
|
182 | - $timezone_string |
|
183 | - ) |
|
184 | - ); |
|
185 | - return array($blank_datetime); |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * get event start date from db |
|
191 | - * |
|
192 | - * @access public |
|
193 | - * @param int $EVT_ID |
|
194 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
195 | - * @throws EE_Error |
|
196 | - */ |
|
197 | - public function get_all_event_dates($EVT_ID = 0) |
|
198 | - { |
|
199 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
200 | - return $this->create_new_blank_datetime(); |
|
201 | - } |
|
202 | - $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
203 | - if (empty($results)) { |
|
204 | - return $this->create_new_blank_datetime(); |
|
205 | - } |
|
206 | - return $results; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * get all datetimes attached to an event ordered by the DTT_order field |
|
212 | - * |
|
213 | - * @public |
|
214 | - * @param int $EVT_ID event id |
|
215 | - * @param boolean $include_expired |
|
216 | - * @param boolean $include_deleted |
|
217 | - * @param int $limit If included then limit the count of results by |
|
218 | - * the given number |
|
219 | - * @return EE_Datetime[] |
|
220 | - * @throws EE_Error |
|
221 | - */ |
|
222 | - public function get_datetimes_for_event_ordered_by_DTT_order( |
|
223 | - $EVT_ID, |
|
224 | - $include_expired = true, |
|
225 | - $include_deleted = true, |
|
226 | - $limit = null |
|
227 | - ) { |
|
228 | - //sanitize EVT_ID |
|
229 | - $EVT_ID = absint($EVT_ID); |
|
230 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
231 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
232 | - $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
233 | - $query_params = ! empty($limit) |
|
234 | - ? array( |
|
235 | - $where_params, |
|
236 | - 'limit' => $limit, |
|
237 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
238 | - 'default_where_conditions' => 'none', |
|
239 | - ) |
|
240 | - : array( |
|
241 | - $where_params, |
|
242 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
243 | - 'default_where_conditions' => 'none', |
|
244 | - ); |
|
245 | - if (! $include_expired) { |
|
246 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
247 | - } |
|
248 | - if ($include_deleted) { |
|
249 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
250 | - } |
|
251 | - /** @var EE_Datetime[] $result */ |
|
252 | - $result = $this->get_all($query_params); |
|
253 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
254 | - return $result; |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
260 | - * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
261 | - * and then the earlier datetimes are the most important. |
|
262 | - * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
263 | - * |
|
264 | - * @param int $EVT_ID |
|
265 | - * @param int $limit |
|
266 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
267 | - * @throws EE_Error |
|
268 | - */ |
|
269 | - public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
270 | - { |
|
271 | - return $this->get_all( |
|
272 | - array( |
|
273 | - array('Event.EVT_ID' => $EVT_ID), |
|
274 | - 'limit' => $limit, |
|
275 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
276 | - 'default_where_conditions' => 'none', |
|
277 | - ) |
|
278 | - ); |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * @param int $EVT_ID |
|
284 | - * @param boolean $include_expired |
|
285 | - * @param boolean $include_deleted |
|
286 | - * @return EE_Datetime |
|
287 | - * @throws EE_Error |
|
288 | - */ |
|
289 | - public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
290 | - { |
|
291 | - $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
292 | - $EVT_ID, |
|
293 | - $include_expired, |
|
294 | - $include_deleted, |
|
295 | - 1 |
|
296 | - ); |
|
297 | - if ($results) { |
|
298 | - return array_shift($results); |
|
299 | - } |
|
300 | - return null; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Gets the 'primary' datetime for an event. |
|
306 | - * |
|
307 | - * @param int $EVT_ID |
|
308 | - * @param bool $try_to_exclude_expired |
|
309 | - * @param bool $try_to_exclude_deleted |
|
310 | - * @return \EE_Datetime |
|
311 | - * @throws EE_Error |
|
312 | - */ |
|
313 | - public function get_primary_datetime_for_event( |
|
314 | - $EVT_ID, |
|
315 | - $try_to_exclude_expired = true, |
|
316 | - $try_to_exclude_deleted = true |
|
317 | - ) { |
|
318 | - if ($try_to_exclude_expired) { |
|
319 | - $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
320 | - if ($non_expired) { |
|
321 | - return $non_expired; |
|
322 | - } |
|
323 | - } |
|
324 | - if ($try_to_exclude_deleted) { |
|
325 | - $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
326 | - if ($expired_even) { |
|
327 | - return $expired_even; |
|
328 | - } |
|
329 | - } |
|
330 | - return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
336 | - * only by start date |
|
337 | - * |
|
338 | - * @param int $EVT_ID |
|
339 | - * @param boolean $include_expired |
|
340 | - * @param boolean $include_deleted |
|
341 | - * @param int $limit |
|
342 | - * @return EE_Datetime[] |
|
343 | - * @throws EE_Error |
|
344 | - */ |
|
345 | - public function get_datetimes_for_event_ordered_by_start_time( |
|
346 | - $EVT_ID, |
|
347 | - $include_expired = true, |
|
348 | - $include_deleted = true, |
|
349 | - $limit = null |
|
350 | - ) { |
|
351 | - //sanitize EVT_ID |
|
352 | - $EVT_ID = absint($EVT_ID); |
|
353 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
354 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
355 | - $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
356 | - if (! $include_expired) { |
|
357 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
358 | - } |
|
359 | - if ($include_deleted) { |
|
360 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
361 | - } |
|
362 | - if ($limit) { |
|
363 | - $query_params['limit'] = $limit; |
|
364 | - } |
|
365 | - /** @var EE_Datetime[] $result */ |
|
366 | - $result = $this->get_all($query_params); |
|
367 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
368 | - return $result; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
374 | - * only by start date |
|
375 | - * |
|
376 | - * @param int $TKT_ID |
|
377 | - * @param boolean $include_expired |
|
378 | - * @param boolean $include_deleted |
|
379 | - * @param int $limit |
|
380 | - * @return EE_Datetime[] |
|
381 | - * @throws EE_Error |
|
382 | - */ |
|
383 | - public function get_datetimes_for_ticket_ordered_by_start_time( |
|
384 | - $TKT_ID, |
|
385 | - $include_expired = true, |
|
386 | - $include_deleted = true, |
|
387 | - $limit = null |
|
388 | - ) { |
|
389 | - //sanitize TKT_ID |
|
390 | - $TKT_ID = absint($TKT_ID); |
|
391 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
392 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
393 | - $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
394 | - if (! $include_expired) { |
|
395 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
396 | - } |
|
397 | - if ($include_deleted) { |
|
398 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
399 | - } |
|
400 | - if ($limit) { |
|
401 | - $query_params['limit'] = $limit; |
|
402 | - } |
|
403 | - /** @var EE_Datetime[] $result */ |
|
404 | - $result = $this->get_all($query_params); |
|
405 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
406 | - return $result; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
412 | - * datetimes. |
|
413 | - * |
|
414 | - * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
415 | - * @param boolean $include_expired whether to include expired datetimes or not |
|
416 | - * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
417 | - * @param int|null $limit if null, no limit, if int then limit results by |
|
418 | - * that number |
|
419 | - * @return EE_Datetime[] |
|
420 | - * @throws EE_Error |
|
421 | - */ |
|
422 | - public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
423 | - $TKT_ID, |
|
424 | - $include_expired = true, |
|
425 | - $include_deleted = true, |
|
426 | - $limit = null |
|
427 | - ) { |
|
428 | - //sanitize id. |
|
429 | - $TKT_ID = absint($TKT_ID); |
|
430 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
431 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
432 | - $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
433 | - $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
434 | - if (! $include_expired) { |
|
435 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
436 | - } |
|
437 | - if ($include_deleted) { |
|
438 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
439 | - } |
|
440 | - if ($limit) { |
|
441 | - $query_params['limit'] = $limit; |
|
442 | - } |
|
443 | - /** @var EE_Datetime[] $result */ |
|
444 | - $result = $this->get_all($query_params); |
|
445 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
446 | - return $result; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
452 | - * reason it doesn't exist, we consider the earliest event the most important) |
|
453 | - * |
|
454 | - * @param int $EVT_ID |
|
455 | - * @return EE_Datetime |
|
456 | - * @throws EE_Error |
|
457 | - */ |
|
458 | - public function get_most_important_datetime_for_event($EVT_ID) |
|
459 | - { |
|
460 | - $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
461 | - if ($results) { |
|
462 | - return array_shift($results); |
|
463 | - } |
|
464 | - return null; |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
470 | - * grouped by month and year. |
|
471 | - * |
|
472 | - * @param array $where_params Array of query_params as described in the comments for EEM_Base::get_all() |
|
473 | - * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
474 | - * Can be: |
|
475 | - * - '' = no filter |
|
476 | - * - upcoming = Published events with at least one upcoming datetime. |
|
477 | - * - expired = Events with all datetimes expired. |
|
478 | - * - active = Events that are published and have at least one datetime that |
|
479 | - * starts before now and ends after now. |
|
480 | - * - inactive = Events that are either not published. |
|
481 | - * @return EE_Base_Class[] |
|
482 | - * @throws EE_Error |
|
483 | - * @throws InvalidArgumentException |
|
484 | - * @throws InvalidArgumentException |
|
485 | - */ |
|
486 | - public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
487 | - { |
|
488 | - $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
489 | - $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
490 | - switch ($evt_active_status) { |
|
491 | - case 'upcoming' : |
|
492 | - $where_params['Event.status'] = 'publish'; |
|
493 | - //if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
494 | - if (isset($where_params['DTT_EVT_start'])) { |
|
495 | - $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
496 | - } |
|
497 | - $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
498 | - break; |
|
499 | - case 'expired' : |
|
500 | - if (isset($where_params['Event.status'])) { |
|
501 | - unset($where_params['Event.status']); |
|
502 | - } |
|
503 | - //get events to exclude |
|
504 | - $exclude_query[0] = array_merge($where_params, |
|
505 | - array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))); |
|
506 | - //first get all events that have datetimes where its not expired. |
|
507 | - $event_ids = $this->_get_all_wpdb_results( |
|
508 | - $exclude_query, |
|
509 | - OBJECT_K, |
|
510 | - 'Datetime.EVT_ID' |
|
511 | - ); |
|
512 | - $event_ids = array_keys($event_ids); |
|
513 | - if (isset($where_params['DTT_EVT_end'])) { |
|
514 | - $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
515 | - } |
|
516 | - $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
517 | - $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
518 | - break; |
|
519 | - case 'active' : |
|
520 | - $where_params['Event.status'] = 'publish'; |
|
521 | - if (isset($where_params['DTT_EVT_start'])) { |
|
522 | - $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
523 | - } |
|
524 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
525 | - $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
526 | - } |
|
527 | - $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
528 | - $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
529 | - break; |
|
530 | - case 'inactive' : |
|
531 | - if (isset($where_params['Event.status'])) { |
|
532 | - unset($where_params['Event.status']); |
|
533 | - } |
|
534 | - if (isset($where_params['OR'])) { |
|
535 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
536 | - } |
|
537 | - if (isset($where_params['DTT_EVT_end'])) { |
|
538 | - $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
539 | - unset($where_params['DTT_EVT_end']); |
|
540 | - } |
|
541 | - if (isset($where_params['DTT_EVT_start'])) { |
|
542 | - $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
543 | - unset($where_params['DTT_EVT_start']); |
|
544 | - } |
|
545 | - $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
546 | - break; |
|
547 | - } |
|
548 | - $query_params[0] = $where_params; |
|
549 | - $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
550 | - $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
551 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), |
|
552 | - 'DTT_EVT_start'); |
|
553 | - $columns_to_select = array( |
|
554 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
555 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
556 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
557 | - ); |
|
558 | - return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
564 | - * for the tickets for each datetime) |
|
565 | - * |
|
566 | - * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
567 | - * @throws EE_Error |
|
568 | - */ |
|
569 | - public function update_sold($datetimes) |
|
570 | - { |
|
571 | - EE_Error::doing_it_wrong( |
|
572 | - __FUNCTION__, |
|
573 | - esc_html__( |
|
574 | - 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
575 | - 'event_espresso' |
|
576 | - ), |
|
577 | - '4.9.32.rc.005' |
|
578 | - ); |
|
579 | - foreach ($datetimes as $datetime) { |
|
580 | - $datetime->update_sold(); |
|
581 | - } |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * Gets the total number of tickets available at a particular datetime |
|
587 | - * (does NOT take into account the datetime's spaces available) |
|
588 | - * |
|
589 | - * @param int $DTT_ID |
|
590 | - * @param array $query_params |
|
591 | - * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
592 | - * tickets attached to datetime then FALSE is returned. |
|
593 | - */ |
|
594 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array()) |
|
595 | - { |
|
596 | - $datetime = $this->get_one_by_ID($DTT_ID); |
|
597 | - if ($datetime instanceof EE_Datetime) { |
|
598 | - return $datetime->tickets_remaining($query_params); |
|
599 | - } |
|
600 | - return 0; |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
606 | - * |
|
607 | - * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
608 | - * stati you want counts for as values in the array. An empty array returns counts |
|
609 | - * for all valid stati. |
|
610 | - * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
611 | - * only for Datetimes connected to a specific event, or specific ticket. |
|
612 | - * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
613 | - * @throws EE_Error |
|
614 | - * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
615 | - * EE_Datetime::expired |
|
616 | - */ |
|
617 | - public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array()) |
|
618 | - { |
|
619 | - //only accept where conditions for this query. |
|
620 | - $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
621 | - $status_query_args = array( |
|
622 | - EE_Datetime::active => array_merge( |
|
623 | - $_where, |
|
624 | - array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
625 | - ), |
|
626 | - EE_Datetime::upcoming => array_merge( |
|
627 | - $_where, |
|
628 | - array('DTT_EVT_start' => array('>', time())) |
|
629 | - ), |
|
630 | - EE_Datetime::expired => array_merge( |
|
631 | - $_where, |
|
632 | - array('DTT_EVT_end' => array('<', time())) |
|
633 | - ), |
|
634 | - ); |
|
635 | - if (! empty($stati_to_include)) { |
|
636 | - foreach (array_keys($status_query_args) as $status) { |
|
637 | - if (! in_array($status, $stati_to_include, true)) { |
|
638 | - unset($status_query_args[ $status ]); |
|
639 | - } |
|
640 | - } |
|
641 | - } |
|
642 | - //loop through and query counts for each stati. |
|
643 | - $status_query_results = array(); |
|
644 | - foreach ($status_query_args as $status => $status_where_conditions) { |
|
645 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
646 | - array($status_where_conditions), |
|
647 | - 'DTT_ID', |
|
648 | - true |
|
649 | - ); |
|
650 | - } |
|
651 | - return $status_query_results; |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - /** |
|
656 | - * Returns the specific count for a given Datetime status matching any given query_params. |
|
657 | - * |
|
658 | - * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
659 | - * @param array $query_params |
|
660 | - * @return int |
|
661 | - * @throws EE_Error |
|
662 | - */ |
|
663 | - public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
|
664 | - { |
|
665 | - $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
666 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
667 | - } |
|
17 | + /** |
|
18 | + * @var EEM_Datetime $_instance |
|
19 | + */ |
|
20 | + protected static $_instance; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * private constructor to prevent direct creation |
|
25 | + * |
|
26 | + * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
27 | + * (and any incoming timezone data that gets saved). |
|
28 | + * Note this just sends the timezone info to the date time model field objects. |
|
29 | + * Default is NULL |
|
30 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
31 | + * @throws EE_Error |
|
32 | + * @throws InvalidArgumentException |
|
33 | + * @throws InvalidArgumentException |
|
34 | + */ |
|
35 | + protected function __construct($timezone) |
|
36 | + { |
|
37 | + $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
38 | + $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
39 | + $this->_tables = array( |
|
40 | + 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
41 | + ); |
|
42 | + $this->_fields = array( |
|
43 | + 'Datetime' => array( |
|
44 | + 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
45 | + 'DTT_ID', |
|
46 | + esc_html__('Datetime ID', 'event_espresso') |
|
47 | + ), |
|
48 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
49 | + 'EVT_ID', |
|
50 | + esc_html__('Event ID', 'event_espresso'), |
|
51 | + false, |
|
52 | + 0, |
|
53 | + 'Event' |
|
54 | + ), |
|
55 | + 'DTT_name' => new EE_Plain_Text_Field( |
|
56 | + 'DTT_name', |
|
57 | + esc_html__('Datetime Name', 'event_espresso'), |
|
58 | + false, |
|
59 | + '' |
|
60 | + ), |
|
61 | + 'DTT_description' => new EE_Post_Content_Field( |
|
62 | + 'DTT_description', |
|
63 | + esc_html__('Description for Datetime', 'event_espresso'), |
|
64 | + false, |
|
65 | + '' |
|
66 | + ), |
|
67 | + 'DTT_EVT_start' => new EE_Datetime_Field( |
|
68 | + 'DTT_EVT_start', |
|
69 | + esc_html__('Start time/date of Event', 'event_espresso'), |
|
70 | + false, |
|
71 | + EE_Datetime_Field::now, |
|
72 | + $timezone |
|
73 | + ), |
|
74 | + 'DTT_EVT_end' => new EE_Datetime_Field( |
|
75 | + 'DTT_EVT_end', |
|
76 | + esc_html__('End time/date of Event', 'event_espresso'), |
|
77 | + false, |
|
78 | + EE_Datetime_Field::now, |
|
79 | + $timezone |
|
80 | + ), |
|
81 | + 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
82 | + 'DTT_reg_limit', |
|
83 | + esc_html__('Registration Limit for this time', 'event_espresso'), |
|
84 | + true, |
|
85 | + EE_INF |
|
86 | + ), |
|
87 | + 'DTT_sold' => new EE_Integer_Field( |
|
88 | + 'DTT_sold', |
|
89 | + esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
90 | + true, |
|
91 | + 0 |
|
92 | + ), |
|
93 | + 'DTT_reserved' => new EE_Integer_Field( |
|
94 | + 'DTT_reserved', |
|
95 | + esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
96 | + false, |
|
97 | + 0 |
|
98 | + ), |
|
99 | + 'DTT_is_primary' => new EE_Boolean_Field( |
|
100 | + 'DTT_is_primary', |
|
101 | + esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
102 | + false, |
|
103 | + false |
|
104 | + ), |
|
105 | + 'DTT_order' => new EE_Integer_Field( |
|
106 | + 'DTT_order', |
|
107 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
108 | + false, |
|
109 | + 0 |
|
110 | + ), |
|
111 | + 'DTT_parent' => new EE_Integer_Field( |
|
112 | + 'DTT_parent', |
|
113 | + esc_html__('Indicates what DTT_ID is the parent of this DTT_ID'), |
|
114 | + true, |
|
115 | + 0 |
|
116 | + ), |
|
117 | + 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
118 | + 'DTT_deleted', |
|
119 | + esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
120 | + false, |
|
121 | + false |
|
122 | + ), |
|
123 | + ), |
|
124 | + ); |
|
125 | + $this->_model_relations = array( |
|
126 | + 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
127 | + 'Event' => new EE_Belongs_To_Relation(), |
|
128 | + 'Checkin' => new EE_Has_Many_Relation(), |
|
129 | + ); |
|
130 | + $this->_model_chain_to_wp_user = 'Event'; |
|
131 | + //this model is generally available for reading |
|
132 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
133 | + 'Event' |
|
134 | + ); |
|
135 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
136 | + 'Event' |
|
137 | + ); |
|
138 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
139 | + 'Event' |
|
140 | + ); |
|
141 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
142 | + 'Event', |
|
143 | + EEM_Base::caps_edit |
|
144 | + ); |
|
145 | + parent::__construct($timezone); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * create new blank datetime |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
154 | + * @throws EE_Error |
|
155 | + */ |
|
156 | + public function create_new_blank_datetime() |
|
157 | + { |
|
158 | + //makes sure timezone is always set. |
|
159 | + $timezone_string = $this->get_timezone(); |
|
160 | + $blank_datetime = EE_Datetime::new_instance( |
|
161 | + array( |
|
162 | + 'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS, |
|
163 | + 'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS, |
|
164 | + 'DTT_order' => 1, |
|
165 | + 'DTT_reg_limit' => EE_INF, |
|
166 | + ), |
|
167 | + $timezone_string |
|
168 | + ); |
|
169 | + $blank_datetime->set_start_time( |
|
170 | + $this->convert_datetime_for_query( |
|
171 | + 'DTT_EVT_start', |
|
172 | + '8am', |
|
173 | + 'ga', |
|
174 | + $timezone_string |
|
175 | + ) |
|
176 | + ); |
|
177 | + $blank_datetime->set_end_time( |
|
178 | + $this->convert_datetime_for_query( |
|
179 | + 'DTT_EVT_end', |
|
180 | + '5pm', |
|
181 | + 'ga', |
|
182 | + $timezone_string |
|
183 | + ) |
|
184 | + ); |
|
185 | + return array($blank_datetime); |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * get event start date from db |
|
191 | + * |
|
192 | + * @access public |
|
193 | + * @param int $EVT_ID |
|
194 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
195 | + * @throws EE_Error |
|
196 | + */ |
|
197 | + public function get_all_event_dates($EVT_ID = 0) |
|
198 | + { |
|
199 | + if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
200 | + return $this->create_new_blank_datetime(); |
|
201 | + } |
|
202 | + $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
203 | + if (empty($results)) { |
|
204 | + return $this->create_new_blank_datetime(); |
|
205 | + } |
|
206 | + return $results; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * get all datetimes attached to an event ordered by the DTT_order field |
|
212 | + * |
|
213 | + * @public |
|
214 | + * @param int $EVT_ID event id |
|
215 | + * @param boolean $include_expired |
|
216 | + * @param boolean $include_deleted |
|
217 | + * @param int $limit If included then limit the count of results by |
|
218 | + * the given number |
|
219 | + * @return EE_Datetime[] |
|
220 | + * @throws EE_Error |
|
221 | + */ |
|
222 | + public function get_datetimes_for_event_ordered_by_DTT_order( |
|
223 | + $EVT_ID, |
|
224 | + $include_expired = true, |
|
225 | + $include_deleted = true, |
|
226 | + $limit = null |
|
227 | + ) { |
|
228 | + //sanitize EVT_ID |
|
229 | + $EVT_ID = absint($EVT_ID); |
|
230 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
231 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
232 | + $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
233 | + $query_params = ! empty($limit) |
|
234 | + ? array( |
|
235 | + $where_params, |
|
236 | + 'limit' => $limit, |
|
237 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
238 | + 'default_where_conditions' => 'none', |
|
239 | + ) |
|
240 | + : array( |
|
241 | + $where_params, |
|
242 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
243 | + 'default_where_conditions' => 'none', |
|
244 | + ); |
|
245 | + if (! $include_expired) { |
|
246 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
247 | + } |
|
248 | + if ($include_deleted) { |
|
249 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
250 | + } |
|
251 | + /** @var EE_Datetime[] $result */ |
|
252 | + $result = $this->get_all($query_params); |
|
253 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
254 | + return $result; |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
260 | + * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
261 | + * and then the earlier datetimes are the most important. |
|
262 | + * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
263 | + * |
|
264 | + * @param int $EVT_ID |
|
265 | + * @param int $limit |
|
266 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
267 | + * @throws EE_Error |
|
268 | + */ |
|
269 | + public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
270 | + { |
|
271 | + return $this->get_all( |
|
272 | + array( |
|
273 | + array('Event.EVT_ID' => $EVT_ID), |
|
274 | + 'limit' => $limit, |
|
275 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
276 | + 'default_where_conditions' => 'none', |
|
277 | + ) |
|
278 | + ); |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * @param int $EVT_ID |
|
284 | + * @param boolean $include_expired |
|
285 | + * @param boolean $include_deleted |
|
286 | + * @return EE_Datetime |
|
287 | + * @throws EE_Error |
|
288 | + */ |
|
289 | + public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
290 | + { |
|
291 | + $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
292 | + $EVT_ID, |
|
293 | + $include_expired, |
|
294 | + $include_deleted, |
|
295 | + 1 |
|
296 | + ); |
|
297 | + if ($results) { |
|
298 | + return array_shift($results); |
|
299 | + } |
|
300 | + return null; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Gets the 'primary' datetime for an event. |
|
306 | + * |
|
307 | + * @param int $EVT_ID |
|
308 | + * @param bool $try_to_exclude_expired |
|
309 | + * @param bool $try_to_exclude_deleted |
|
310 | + * @return \EE_Datetime |
|
311 | + * @throws EE_Error |
|
312 | + */ |
|
313 | + public function get_primary_datetime_for_event( |
|
314 | + $EVT_ID, |
|
315 | + $try_to_exclude_expired = true, |
|
316 | + $try_to_exclude_deleted = true |
|
317 | + ) { |
|
318 | + if ($try_to_exclude_expired) { |
|
319 | + $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
320 | + if ($non_expired) { |
|
321 | + return $non_expired; |
|
322 | + } |
|
323 | + } |
|
324 | + if ($try_to_exclude_deleted) { |
|
325 | + $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
326 | + if ($expired_even) { |
|
327 | + return $expired_even; |
|
328 | + } |
|
329 | + } |
|
330 | + return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
336 | + * only by start date |
|
337 | + * |
|
338 | + * @param int $EVT_ID |
|
339 | + * @param boolean $include_expired |
|
340 | + * @param boolean $include_deleted |
|
341 | + * @param int $limit |
|
342 | + * @return EE_Datetime[] |
|
343 | + * @throws EE_Error |
|
344 | + */ |
|
345 | + public function get_datetimes_for_event_ordered_by_start_time( |
|
346 | + $EVT_ID, |
|
347 | + $include_expired = true, |
|
348 | + $include_deleted = true, |
|
349 | + $limit = null |
|
350 | + ) { |
|
351 | + //sanitize EVT_ID |
|
352 | + $EVT_ID = absint($EVT_ID); |
|
353 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
354 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
355 | + $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
356 | + if (! $include_expired) { |
|
357 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
358 | + } |
|
359 | + if ($include_deleted) { |
|
360 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
361 | + } |
|
362 | + if ($limit) { |
|
363 | + $query_params['limit'] = $limit; |
|
364 | + } |
|
365 | + /** @var EE_Datetime[] $result */ |
|
366 | + $result = $this->get_all($query_params); |
|
367 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
368 | + return $result; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
374 | + * only by start date |
|
375 | + * |
|
376 | + * @param int $TKT_ID |
|
377 | + * @param boolean $include_expired |
|
378 | + * @param boolean $include_deleted |
|
379 | + * @param int $limit |
|
380 | + * @return EE_Datetime[] |
|
381 | + * @throws EE_Error |
|
382 | + */ |
|
383 | + public function get_datetimes_for_ticket_ordered_by_start_time( |
|
384 | + $TKT_ID, |
|
385 | + $include_expired = true, |
|
386 | + $include_deleted = true, |
|
387 | + $limit = null |
|
388 | + ) { |
|
389 | + //sanitize TKT_ID |
|
390 | + $TKT_ID = absint($TKT_ID); |
|
391 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
392 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
393 | + $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
394 | + if (! $include_expired) { |
|
395 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
396 | + } |
|
397 | + if ($include_deleted) { |
|
398 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
399 | + } |
|
400 | + if ($limit) { |
|
401 | + $query_params['limit'] = $limit; |
|
402 | + } |
|
403 | + /** @var EE_Datetime[] $result */ |
|
404 | + $result = $this->get_all($query_params); |
|
405 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
406 | + return $result; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
412 | + * datetimes. |
|
413 | + * |
|
414 | + * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
415 | + * @param boolean $include_expired whether to include expired datetimes or not |
|
416 | + * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
417 | + * @param int|null $limit if null, no limit, if int then limit results by |
|
418 | + * that number |
|
419 | + * @return EE_Datetime[] |
|
420 | + * @throws EE_Error |
|
421 | + */ |
|
422 | + public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
423 | + $TKT_ID, |
|
424 | + $include_expired = true, |
|
425 | + $include_deleted = true, |
|
426 | + $limit = null |
|
427 | + ) { |
|
428 | + //sanitize id. |
|
429 | + $TKT_ID = absint($TKT_ID); |
|
430 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
431 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
432 | + $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
433 | + $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
434 | + if (! $include_expired) { |
|
435 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
436 | + } |
|
437 | + if ($include_deleted) { |
|
438 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
439 | + } |
|
440 | + if ($limit) { |
|
441 | + $query_params['limit'] = $limit; |
|
442 | + } |
|
443 | + /** @var EE_Datetime[] $result */ |
|
444 | + $result = $this->get_all($query_params); |
|
445 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
446 | + return $result; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
452 | + * reason it doesn't exist, we consider the earliest event the most important) |
|
453 | + * |
|
454 | + * @param int $EVT_ID |
|
455 | + * @return EE_Datetime |
|
456 | + * @throws EE_Error |
|
457 | + */ |
|
458 | + public function get_most_important_datetime_for_event($EVT_ID) |
|
459 | + { |
|
460 | + $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
461 | + if ($results) { |
|
462 | + return array_shift($results); |
|
463 | + } |
|
464 | + return null; |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
470 | + * grouped by month and year. |
|
471 | + * |
|
472 | + * @param array $where_params Array of query_params as described in the comments for EEM_Base::get_all() |
|
473 | + * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
474 | + * Can be: |
|
475 | + * - '' = no filter |
|
476 | + * - upcoming = Published events with at least one upcoming datetime. |
|
477 | + * - expired = Events with all datetimes expired. |
|
478 | + * - active = Events that are published and have at least one datetime that |
|
479 | + * starts before now and ends after now. |
|
480 | + * - inactive = Events that are either not published. |
|
481 | + * @return EE_Base_Class[] |
|
482 | + * @throws EE_Error |
|
483 | + * @throws InvalidArgumentException |
|
484 | + * @throws InvalidArgumentException |
|
485 | + */ |
|
486 | + public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
487 | + { |
|
488 | + $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
489 | + $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
490 | + switch ($evt_active_status) { |
|
491 | + case 'upcoming' : |
|
492 | + $where_params['Event.status'] = 'publish'; |
|
493 | + //if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
494 | + if (isset($where_params['DTT_EVT_start'])) { |
|
495 | + $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
496 | + } |
|
497 | + $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
498 | + break; |
|
499 | + case 'expired' : |
|
500 | + if (isset($where_params['Event.status'])) { |
|
501 | + unset($where_params['Event.status']); |
|
502 | + } |
|
503 | + //get events to exclude |
|
504 | + $exclude_query[0] = array_merge($where_params, |
|
505 | + array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))); |
|
506 | + //first get all events that have datetimes where its not expired. |
|
507 | + $event_ids = $this->_get_all_wpdb_results( |
|
508 | + $exclude_query, |
|
509 | + OBJECT_K, |
|
510 | + 'Datetime.EVT_ID' |
|
511 | + ); |
|
512 | + $event_ids = array_keys($event_ids); |
|
513 | + if (isset($where_params['DTT_EVT_end'])) { |
|
514 | + $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
515 | + } |
|
516 | + $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
517 | + $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
518 | + break; |
|
519 | + case 'active' : |
|
520 | + $where_params['Event.status'] = 'publish'; |
|
521 | + if (isset($where_params['DTT_EVT_start'])) { |
|
522 | + $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
523 | + } |
|
524 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
525 | + $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
526 | + } |
|
527 | + $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
528 | + $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
529 | + break; |
|
530 | + case 'inactive' : |
|
531 | + if (isset($where_params['Event.status'])) { |
|
532 | + unset($where_params['Event.status']); |
|
533 | + } |
|
534 | + if (isset($where_params['OR'])) { |
|
535 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
536 | + } |
|
537 | + if (isset($where_params['DTT_EVT_end'])) { |
|
538 | + $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
539 | + unset($where_params['DTT_EVT_end']); |
|
540 | + } |
|
541 | + if (isset($where_params['DTT_EVT_start'])) { |
|
542 | + $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
543 | + unset($where_params['DTT_EVT_start']); |
|
544 | + } |
|
545 | + $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
546 | + break; |
|
547 | + } |
|
548 | + $query_params[0] = $where_params; |
|
549 | + $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
550 | + $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
551 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), |
|
552 | + 'DTT_EVT_start'); |
|
553 | + $columns_to_select = array( |
|
554 | + 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
555 | + 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
556 | + 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
557 | + ); |
|
558 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
564 | + * for the tickets for each datetime) |
|
565 | + * |
|
566 | + * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
567 | + * @throws EE_Error |
|
568 | + */ |
|
569 | + public function update_sold($datetimes) |
|
570 | + { |
|
571 | + EE_Error::doing_it_wrong( |
|
572 | + __FUNCTION__, |
|
573 | + esc_html__( |
|
574 | + 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
575 | + 'event_espresso' |
|
576 | + ), |
|
577 | + '4.9.32.rc.005' |
|
578 | + ); |
|
579 | + foreach ($datetimes as $datetime) { |
|
580 | + $datetime->update_sold(); |
|
581 | + } |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * Gets the total number of tickets available at a particular datetime |
|
587 | + * (does NOT take into account the datetime's spaces available) |
|
588 | + * |
|
589 | + * @param int $DTT_ID |
|
590 | + * @param array $query_params |
|
591 | + * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
592 | + * tickets attached to datetime then FALSE is returned. |
|
593 | + */ |
|
594 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array()) |
|
595 | + { |
|
596 | + $datetime = $this->get_one_by_ID($DTT_ID); |
|
597 | + if ($datetime instanceof EE_Datetime) { |
|
598 | + return $datetime->tickets_remaining($query_params); |
|
599 | + } |
|
600 | + return 0; |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
606 | + * |
|
607 | + * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
608 | + * stati you want counts for as values in the array. An empty array returns counts |
|
609 | + * for all valid stati. |
|
610 | + * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
611 | + * only for Datetimes connected to a specific event, or specific ticket. |
|
612 | + * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
613 | + * @throws EE_Error |
|
614 | + * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
615 | + * EE_Datetime::expired |
|
616 | + */ |
|
617 | + public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array()) |
|
618 | + { |
|
619 | + //only accept where conditions for this query. |
|
620 | + $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
621 | + $status_query_args = array( |
|
622 | + EE_Datetime::active => array_merge( |
|
623 | + $_where, |
|
624 | + array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
625 | + ), |
|
626 | + EE_Datetime::upcoming => array_merge( |
|
627 | + $_where, |
|
628 | + array('DTT_EVT_start' => array('>', time())) |
|
629 | + ), |
|
630 | + EE_Datetime::expired => array_merge( |
|
631 | + $_where, |
|
632 | + array('DTT_EVT_end' => array('<', time())) |
|
633 | + ), |
|
634 | + ); |
|
635 | + if (! empty($stati_to_include)) { |
|
636 | + foreach (array_keys($status_query_args) as $status) { |
|
637 | + if (! in_array($status, $stati_to_include, true)) { |
|
638 | + unset($status_query_args[ $status ]); |
|
639 | + } |
|
640 | + } |
|
641 | + } |
|
642 | + //loop through and query counts for each stati. |
|
643 | + $status_query_results = array(); |
|
644 | + foreach ($status_query_args as $status => $status_where_conditions) { |
|
645 | + $status_query_results[ $status ] = EEM_Datetime::count( |
|
646 | + array($status_where_conditions), |
|
647 | + 'DTT_ID', |
|
648 | + true |
|
649 | + ); |
|
650 | + } |
|
651 | + return $status_query_results; |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + /** |
|
656 | + * Returns the specific count for a given Datetime status matching any given query_params. |
|
657 | + * |
|
658 | + * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
659 | + * @param array $query_params |
|
660 | + * @return int |
|
661 | + * @throws EE_Error |
|
662 | + */ |
|
663 | + public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
|
664 | + { |
|
665 | + $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
666 | + return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
667 | + } |
|
668 | 668 | } |
669 | 669 | // End of file EEM_Datetime.model.php |
670 | 670 | // Location: /includes/models/EEM_Datetime.model.php |
@@ -1,4 +1,4 @@ discard block |
||
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 | |
@@ -122,23 +122,23 @@ discard block |
||
122 | 122 | ), |
123 | 123 | ), |
124 | 124 | ); |
125 | - $this->_model_relations = array( |
|
125 | + $this->_model_relations = array( |
|
126 | 126 | 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
127 | 127 | 'Event' => new EE_Belongs_To_Relation(), |
128 | 128 | 'Checkin' => new EE_Has_Many_Relation(), |
129 | 129 | ); |
130 | 130 | $this->_model_chain_to_wp_user = 'Event'; |
131 | 131 | //this model is generally available for reading |
132 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
132 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
133 | 133 | 'Event' |
134 | 134 | ); |
135 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
135 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected( |
|
136 | 136 | 'Event' |
137 | 137 | ); |
138 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
138 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
139 | 139 | 'Event' |
140 | 140 | ); |
141 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
141 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected( |
|
142 | 142 | 'Event', |
143 | 143 | EEM_Base::caps_edit |
144 | 144 | ); |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function get_all_event_dates($EVT_ID = 0) |
198 | 198 | { |
199 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
199 | + if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
200 | 200 | return $this->create_new_blank_datetime(); |
201 | 201 | } |
202 | 202 | $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | 'order_by' => array('DTT_order' => 'ASC'), |
243 | 243 | 'default_where_conditions' => 'none', |
244 | 244 | ); |
245 | - if (! $include_expired) { |
|
245 | + if ( ! $include_expired) { |
|
246 | 246 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
247 | 247 | } |
248 | 248 | if ($include_deleted) { |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
354 | 354 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
355 | 355 | $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
356 | - if (! $include_expired) { |
|
356 | + if ( ! $include_expired) { |
|
357 | 357 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
358 | 358 | } |
359 | 359 | if ($include_deleted) { |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
392 | 392 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
393 | 393 | $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
394 | - if (! $include_expired) { |
|
394 | + if ( ! $include_expired) { |
|
395 | 395 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
396 | 396 | } |
397 | 397 | if ($include_deleted) { |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
432 | 432 | $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
433 | 433 | $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
434 | - if (! $include_expired) { |
|
434 | + if ( ! $include_expired) { |
|
435 | 435 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
436 | 436 | } |
437 | 437 | if ($include_deleted) { |
@@ -551,9 +551,9 @@ discard block |
||
551 | 551 | $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), |
552 | 552 | 'DTT_EVT_start'); |
553 | 553 | $columns_to_select = array( |
554 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
555 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
556 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
554 | + 'dtt_year' => array('YEAR('.$query_interval.')', '%s'), |
|
555 | + 'dtt_month' => array('MONTHNAME('.$query_interval.')', '%s'), |
|
556 | + 'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'), |
|
557 | 557 | ); |
558 | 558 | return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
559 | 559 | } |
@@ -632,17 +632,17 @@ discard block |
||
632 | 632 | array('DTT_EVT_end' => array('<', time())) |
633 | 633 | ), |
634 | 634 | ); |
635 | - if (! empty($stati_to_include)) { |
|
635 | + if ( ! empty($stati_to_include)) { |
|
636 | 636 | foreach (array_keys($status_query_args) as $status) { |
637 | - if (! in_array($status, $stati_to_include, true)) { |
|
638 | - unset($status_query_args[ $status ]); |
|
637 | + if ( ! in_array($status, $stati_to_include, true)) { |
|
638 | + unset($status_query_args[$status]); |
|
639 | 639 | } |
640 | 640 | } |
641 | 641 | } |
642 | 642 | //loop through and query counts for each stati. |
643 | 643 | $status_query_results = array(); |
644 | 644 | foreach ($status_query_args as $status => $status_where_conditions) { |
645 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
645 | + $status_query_results[$status] = EEM_Datetime::count( |
|
646 | 646 | array($status_where_conditions), |
647 | 647 | 'DTT_ID', |
648 | 648 | true |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
664 | 664 | { |
665 | 665 | $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
666 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
666 | + return ! empty($count[$status]) ? $count[$status] : 0; |
|
667 | 667 | } |
668 | 668 | } |
669 | 669 | // End of file EEM_Datetime.model.php |
@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | 2 | //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>'; |
3 | 3 | |
4 | -if ( is_single() || ( is_archive() && espresso_display_datetimes_in_event_list() ) ) : |
|
4 | +if (is_single() || (is_archive() && espresso_display_datetimes_in_event_list())) : |
|
5 | 5 | global $post; |
6 | -do_action( 'AHEE_event_details_before_event_date', $post ); |
|
6 | +do_action('AHEE_event_details_before_event_date', $post); |
|
7 | 7 | ?> |
8 | 8 | <div class="event-datetimes"> |
9 | - <?php espresso_list_of_event_dates( $post->ID );?> |
|
9 | + <?php espresso_list_of_event_dates($post->ID); ?> |
|
10 | 10 | </div> |
11 | 11 | <!-- .event-datetimes --> |
12 | 12 | <?php |
13 | -do_action( 'AHEE_event_details_after_event_date', $post ); |
|
13 | +do_action('AHEE_event_details_after_event_date', $post); |
|
14 | 14 | endif; |
15 | 15 | ?> |
16 | 16 | \ No newline at end of file |
@@ -9,164 +9,164 @@ |
||
9 | 9 | abstract class EE_Table_Base |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * This holds the table_name without the table prefix. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - var $_table_name; |
|
18 | - |
|
19 | - |
|
20 | - /** |
|
21 | - * This holds what is used as the alias for the table in queries. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - var $_table_alias; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Table's private key column |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $_pk_column; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * Whether this table is a global table (in multisite) or specific to site. |
|
38 | - * |
|
39 | - * @var bool |
|
40 | - */ |
|
41 | - protected $_global; |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @global wpdb $wpdb |
|
47 | - * @param string $table_name with or without wpdb prefix |
|
48 | - * @param string $pk_column |
|
49 | - * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite |
|
50 | - * install, or whether each site on a multisite install has a copy of this table |
|
51 | - */ |
|
52 | - function __construct($table_name, $pk_column, $global = false) |
|
53 | - { |
|
54 | - $this->_global = $global; |
|
55 | - $prefix = $this->get_table_prefix(); |
|
56 | - //if they added the prefix, let's remove it because we delay adding the prefix until right when its needed. |
|
57 | - if (strpos($table_name, $prefix) === 0) { |
|
58 | - $table_name = ltrim($table_name, $prefix); |
|
59 | - } |
|
60 | - $this->_table_name = $table_name; |
|
61 | - $this->_pk_column = $pk_column; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * This returns the table prefix for the current model state. |
|
68 | - * |
|
69 | - * @global wpdb $wpdb |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function get_table_prefix() |
|
73 | - { |
|
74 | - global $wpdb; |
|
75 | - if ($this->_global) { |
|
76 | - $prefix = $wpdb->base_prefix; |
|
77 | - } else { |
|
78 | - $prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id()); |
|
79 | - } |
|
80 | - return $prefix; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Used to set the table_alias property |
|
87 | - * |
|
88 | - * @param string $table_alias |
|
89 | - */ |
|
90 | - function _construct_finalize_with_alias($table_alias) |
|
91 | - { |
|
92 | - $this->_table_alias = $table_alias; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Returns the fully qualified table name for the database (includes the table prefix current for the blog). |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function get_table_name() |
|
103 | - { |
|
104 | - return $this->get_table_prefix() . $this->_table_name; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * Provides what is currently set as the alias for the table to be used in queries. |
|
111 | - * |
|
112 | - * @return string |
|
113 | - * @throws EE_Error |
|
114 | - */ |
|
115 | - function get_table_alias() |
|
116 | - { |
|
117 | - if ( ! $this->_table_alias) { |
|
118 | - throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
|
119 | - } |
|
120 | - return $this->_table_alias; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string name of column of PK |
|
127 | - */ |
|
128 | - function get_pk_column() |
|
129 | - { |
|
130 | - return $this->_pk_column; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * returns a string with the table alias, a period, and the private key's column. |
|
137 | - * |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - function get_fully_qualified_pk_column() |
|
141 | - { |
|
142 | - $sql = $this->get_table_alias() . "." . $this->get_pk_column(); |
|
143 | - return $sql; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * returns the special sql for a inner select with a limit. |
|
150 | - * |
|
151 | - * @return string SQL select |
|
152 | - */ |
|
153 | - public function get_select_join_limit($limit) |
|
154 | - { |
|
155 | - $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit; |
|
156 | - $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
157 | - return $SQL; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Returns whether or not htis is a global table (ie, on multisite there's |
|
164 | - * only one of these tables, on the main blog) |
|
165 | - * |
|
166 | - * @return boolean |
|
167 | - */ |
|
168 | - public function is_global() |
|
169 | - { |
|
170 | - return $this->_global; |
|
171 | - } |
|
12 | + /** |
|
13 | + * This holds the table_name without the table prefix. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + var $_table_name; |
|
18 | + |
|
19 | + |
|
20 | + /** |
|
21 | + * This holds what is used as the alias for the table in queries. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + var $_table_alias; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Table's private key column |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $_pk_column; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * Whether this table is a global table (in multisite) or specific to site. |
|
38 | + * |
|
39 | + * @var bool |
|
40 | + */ |
|
41 | + protected $_global; |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @global wpdb $wpdb |
|
47 | + * @param string $table_name with or without wpdb prefix |
|
48 | + * @param string $pk_column |
|
49 | + * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite |
|
50 | + * install, or whether each site on a multisite install has a copy of this table |
|
51 | + */ |
|
52 | + function __construct($table_name, $pk_column, $global = false) |
|
53 | + { |
|
54 | + $this->_global = $global; |
|
55 | + $prefix = $this->get_table_prefix(); |
|
56 | + //if they added the prefix, let's remove it because we delay adding the prefix until right when its needed. |
|
57 | + if (strpos($table_name, $prefix) === 0) { |
|
58 | + $table_name = ltrim($table_name, $prefix); |
|
59 | + } |
|
60 | + $this->_table_name = $table_name; |
|
61 | + $this->_pk_column = $pk_column; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * This returns the table prefix for the current model state. |
|
68 | + * |
|
69 | + * @global wpdb $wpdb |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function get_table_prefix() |
|
73 | + { |
|
74 | + global $wpdb; |
|
75 | + if ($this->_global) { |
|
76 | + $prefix = $wpdb->base_prefix; |
|
77 | + } else { |
|
78 | + $prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id()); |
|
79 | + } |
|
80 | + return $prefix; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Used to set the table_alias property |
|
87 | + * |
|
88 | + * @param string $table_alias |
|
89 | + */ |
|
90 | + function _construct_finalize_with_alias($table_alias) |
|
91 | + { |
|
92 | + $this->_table_alias = $table_alias; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Returns the fully qualified table name for the database (includes the table prefix current for the blog). |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function get_table_name() |
|
103 | + { |
|
104 | + return $this->get_table_prefix() . $this->_table_name; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * Provides what is currently set as the alias for the table to be used in queries. |
|
111 | + * |
|
112 | + * @return string |
|
113 | + * @throws EE_Error |
|
114 | + */ |
|
115 | + function get_table_alias() |
|
116 | + { |
|
117 | + if ( ! $this->_table_alias) { |
|
118 | + throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
|
119 | + } |
|
120 | + return $this->_table_alias; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string name of column of PK |
|
127 | + */ |
|
128 | + function get_pk_column() |
|
129 | + { |
|
130 | + return $this->_pk_column; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * returns a string with the table alias, a period, and the private key's column. |
|
137 | + * |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + function get_fully_qualified_pk_column() |
|
141 | + { |
|
142 | + $sql = $this->get_table_alias() . "." . $this->get_pk_column(); |
|
143 | + return $sql; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * returns the special sql for a inner select with a limit. |
|
150 | + * |
|
151 | + * @return string SQL select |
|
152 | + */ |
|
153 | + public function get_select_join_limit($limit) |
|
154 | + { |
|
155 | + $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit; |
|
156 | + $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
157 | + return $SQL; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Returns whether or not htis is a global table (ie, on multisite there's |
|
164 | + * only one of these tables, on the main blog) |
|
165 | + * |
|
166 | + * @return boolean |
|
167 | + */ |
|
168 | + public function is_global() |
|
169 | + { |
|
170 | + return $this->_global; |
|
171 | + } |
|
172 | 172 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | function get_table_name() |
103 | 103 | { |
104 | - return $this->get_table_prefix() . $this->_table_name; |
|
104 | + return $this->get_table_prefix().$this->_table_name; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | function get_fully_qualified_pk_column() |
141 | 141 | { |
142 | - $sql = $this->get_table_alias() . "." . $this->get_pk_column(); |
|
142 | + $sql = $this->get_table_alias().".".$this->get_pk_column(); |
|
143 | 143 | return $sql; |
144 | 144 | } |
145 | 145 | |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function get_select_join_limit($limit) |
154 | 154 | { |
155 | - $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit; |
|
156 | - $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
155 | + $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit; |
|
156 | + $SQL = SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias; |
|
157 | 157 | return $SQL; |
158 | 158 | } |
159 | 159 |